Re: [PATCH v1 1/2] x86/kvm/fpu: Mask guest fpstate->xfeatures with guest_supported_xcr0

From: Paolo Bonzini
Date: Mon Feb 07 2022 - 16:00:39 EST


On 2/7/22 21:24, Leonardo Bras Soares Passos wrote:
With this patch,
we have to reason about the effect of calling KVM_SET_CPUID2 twice calls
back to back. I think an "&=" would be wrong in that case.

So, you suggest something like this ?

vcpu->arch.guest_fpu.fpstate->xfeatures =
fpu_user_cfg.default_features & vcpu->arch.guest_supported_xcr0;


Yes, but you need to change user_xfeatures instead of xfeatures. KVM_GET_XSAVE and KVM_SET_XSAVE will take it into account automatically:

- KVM_GET_XSAVE: fpu_copy_guest_fpstate_to_uabi -> __copy_xstate_to_uabi_buf

- KVM_SET_XSAVE: fpu_copy_uabi_to_guest_fpstate -> copy_uabi_from_kernel_to_xstate -> copy_uabi_to_xstate -> validate_user_xstate_buffer

Paolo