Re: [PATCH 4/7] KVM: TDX: restore host xsave state when exit from the guest TD
From: Sean Christopherson
Date: Tue Jan 14 2025 - 21:28:37 EST
On Tue, Jan 14, 2025, Adrian Hunter wrote:
> On 10/01/25 19:30, Sean Christopherson wrote:
> >> Currently the KVM selftests expect to be able to set XCR0:
> >>
> >> td_vcpu_add()
> >> vm_vcpu_add()
> >> vm_arch_vcpu_add()
> >> vcpu_init_xcrs()
> >> vcpu_xcrs_set()
> >> vcpu_ioctl(KVM_SET_XCRS)
> >> __TEST_ASSERT_VM_VCPU_IOCTL(!ret)
> >>
> >> Seems like vm->arch.has_protected_state is needed for KVM selftests?
> >
> > I doubt it's truly needed, my guess (without looking at the code) is that selftests
> > are fudging around the fact that KVM doesn't stuff arch.xcr0.
>
> Here is when it was added:
>
> commit 8b14c4d85d031f7700fa4e042aebf99d933971f0
> Author: Sean Christopherson <seanjc@xxxxxxxxxx>
> Date: Thu Oct 3 16:43:31 2024 -0700
>
> KVM: selftests: Configure XCR0 to max supported value by default
>
> To play nice with compilers generating AVX instructions, set CR4.OSXSAVE
> and configure XCR0 by default when creating selftests vCPUs. Some distros
> have switched gcc to '-march=x86-64-v3' by default, and while it's hard to
> find a CPU which doesn't support AVX today, many KVM selftests fail with
Gah, sorry. I misread the callstack the first time around and didn't realize it
was the common code that was writing XCR0.
> Is below OK to avoid it?
Skipping the ioctls to set XCRs and SREGS is definitely ok. I'll hold off on
providing concrete feedback until I review the TDX selftests in its entirety,
as I'm skeptical of having td_vcpu_add() wrap vm_arch_vcpu_add() instead of the
other way around, but I don't want to cause a bunch of noise by reacting to a
sliver of the code.