mirror of
https://github.com/torvalds/linux.git
synced 2024-11-07 04:32:03 +00:00
KVM: x86: fix KVM_SET_XCRS for CPUs that do not support XSAVE
The KVM_SET_XCRS ioctl must accept anything that KVM_GET_XCRS could return. XCR0's bit 0 is always 1 in real processors with XSAVE, and KVM_GET_XCRS will always leave bit 0 set even if the emulated processor does not have XSAVE. So, KVM_SET_XCRS must ignore that bit when checking for attempts to enable unsupported save states. Reviewed-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
e0f0bbc527
commit
46c34cb059
@ -577,6 +577,7 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu)
|
|||||||
int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
|
int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
|
||||||
{
|
{
|
||||||
u64 xcr0;
|
u64 xcr0;
|
||||||
|
u64 valid_bits;
|
||||||
|
|
||||||
/* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now */
|
/* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now */
|
||||||
if (index != XCR_XFEATURE_ENABLED_MASK)
|
if (index != XCR_XFEATURE_ENABLED_MASK)
|
||||||
@ -586,8 +587,16 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
|
|||||||
return 1;
|
return 1;
|
||||||
if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE))
|
if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE))
|
||||||
return 1;
|
return 1;
|
||||||
if (xcr0 & ~vcpu->arch.guest_supported_xcr0)
|
|
||||||
|
/*
|
||||||
|
* Do not allow the guest to set bits that we do not support
|
||||||
|
* saving. However, xcr0 bit 0 is always set, even if the
|
||||||
|
* emulated CPU does not support XSAVE (see fx_init).
|
||||||
|
*/
|
||||||
|
valid_bits = vcpu->arch.guest_supported_xcr0 | XSTATE_FP;
|
||||||
|
if (xcr0 & ~valid_bits)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
kvm_put_guest_xcr0(vcpu);
|
kvm_put_guest_xcr0(vcpu);
|
||||||
vcpu->arch.xcr0 = xcr0;
|
vcpu->arch.xcr0 = xcr0;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user