]> git.itanic.dy.fi Git - linux-stable/commit
KVM: x86: Inject #UD on emulated XSETBV if XSAVES isn't enabled
authorSean Christopherson <seanjc@google.com>
Wed, 24 Aug 2022 03:30:57 +0000 (03:30 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Sep 2022 09:11:44 +0000 (11:11 +0200)
commit2427a04bce8648a2ec47bf9e3f57253926a5ce9d
treecac5733ee1bcf99519fcccebbcb976a0a356cf22
parent61703b248be993eb4997b00ae5d3318e6d8f3c5b
KVM: x86: Inject #UD on emulated XSETBV if XSAVES isn't enabled

commit 50b2d49bafa16e6311ab2da82f5aafc5f9ada99b upstream.

Inject #UD when emulating XSETBV if CR4.OSXSAVE is not set.  This also
covers the "XSAVE not supported" check, as setting CR4.OSXSAVE=1 #GPs if
XSAVE is not supported (and userspace gets to keep the pieces if it
forces incoherent vCPU state).

Add a comment to kvm_emulate_xsetbv() to call out that the CPU checks
CR4.OSXSAVE before checking for intercepts.  AMD'S APM implies that #UD
has priority (says that intercepts are checked before #GP exceptions),
while Intel's SDM says nothing about interception priority.  However,
testing on hardware shows that both AMD and Intel CPUs prioritize the #UD
over interception.

Fixes: 02d4160fbd76 ("x86: KVM: add xsetbv to the emulator")
Cc: stable@vger.kernel.org
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20220824033057.3576315-4-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c