Skip to content

Commit 19e6e08

Browse files
committed
KVM: nVMX: Always forward XSAVES/XRSTORS exits from L2 to L1
Unconditionally forward XSAVES/XRSTORS VM-Exits from L2 to L1, as KVM doesn't utilize the XSS-bitmap (KVM relies on controlling the XSS value in hardware to prevent unauthorized access to XSAVES state). KVM always loads vmcs02 with vmcs12's bitmap, and so any exit _must_ be due to vmcs12's XSS-bitmap. Drop the comment about XSS never being non-zero in anticipation of enabling CET_KERNEL and CET_USER support. Opportunistically WARN if XSAVES is not enabled for L2, as the CPU is supposed to generate #UD before checking the XSS-bitmap. Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Reviewed-by: Chao Gao <chao.gao@intel.com> Link: https://lore.kernel.org/r/20250919223258.1604852-25-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b3744c5 commit 19e6e08

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6570,14 +6570,17 @@ static bool nested_vmx_l1_wants_exit(struct kvm_vcpu *vcpu,
65706570
return nested_cpu_has2(vmcs12, SECONDARY_EXEC_WBINVD_EXITING);
65716571
case EXIT_REASON_XSETBV:
65726572
return true;
6573-
case EXIT_REASON_XSAVES: case EXIT_REASON_XRSTORS:
6573+
case EXIT_REASON_XSAVES:
6574+
case EXIT_REASON_XRSTORS:
65746575
/*
6575-
* This should never happen, since it is not possible to
6576-
* set XSS to a non-zero value---neither in L1 nor in L2.
6577-
* If if it were, XSS would have to be checked against
6578-
* the XSS exit bitmap in vmcs12.
6576+
* Always forward XSAVES/XRSTORS to L1 as KVM doesn't utilize
6577+
* XSS-bitmap, and always loads vmcs02 with vmcs12's XSS-bitmap
6578+
* verbatim, i.e. any exit is due to L1's bitmap. WARN if
6579+
* XSAVES isn't enabled, as the CPU is supposed to inject #UD
6580+
* in that case, before consulting the XSS-bitmap.
65796581
*/
6580-
return nested_cpu_has2(vmcs12, SECONDARY_EXEC_ENABLE_XSAVES);
6582+
WARN_ON_ONCE(!nested_cpu_has2(vmcs12, SECONDARY_EXEC_ENABLE_XSAVES));
6583+
return true;
65816584
case EXIT_REASON_UMWAIT:
65826585
case EXIT_REASON_TPAUSE:
65836586
return nested_cpu_has2(vmcs12,

0 commit comments

Comments
 (0)