Skip to content

Commit 3db1348

Browse files
committed
kvm: vmx: Raise #UD on unsupported XSAVES/XRSTORS
A guest may not be configured to support XSAVES/XRSTORS, even when the host does. If the guest does not support XSAVES/XRSTORS, clear the secondary execution control so that the processor will raise #UD. Also clear the "allowed-1" bit for XSAVES/XRSTORS exiting in the IA32_VMX_PROCBASED_CTLS2 MSR, and pass through VMCS12's control in the VMCS02. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 75f4fc8 commit 3db1348

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

arch/x86/kvm/vmx.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,8 +1358,7 @@ static inline int nested_cpu_has_ept(struct vmcs12 *vmcs12)
13581358

13591359
static inline bool nested_cpu_has_xsaves(struct vmcs12 *vmcs12)
13601360
{
1361-
return nested_cpu_has2(vmcs12, SECONDARY_EXEC_XSAVES) &&
1362-
vmx_xsaves_supported();
1361+
return nested_cpu_has2(vmcs12, SECONDARY_EXEC_XSAVES);
13631362
}
13641363

13651364
static inline bool nested_cpu_has_pml(struct vmcs12 *vmcs12)
@@ -2823,8 +2822,7 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx)
28232822
SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
28242823
SECONDARY_EXEC_APIC_REGISTER_VIRT |
28252824
SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
2826-
SECONDARY_EXEC_WBINVD_EXITING |
2827-
SECONDARY_EXEC_XSAVES;
2825+
SECONDARY_EXEC_WBINVD_EXITING;
28282826

28292827
if (enable_ept) {
28302828
/* nested EPT: emulate EPT also to L1 */
@@ -5319,6 +5317,25 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)
53195317
if (!enable_pml)
53205318
exec_control &= ~SECONDARY_EXEC_ENABLE_PML;
53215319

5320+
if (vmx_xsaves_supported()) {
5321+
/* Exposing XSAVES only when XSAVE is exposed */
5322+
bool xsaves_enabled =
5323+
guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
5324+
guest_cpuid_has(vcpu, X86_FEATURE_XSAVES);
5325+
5326+
if (!xsaves_enabled)
5327+
exec_control &= ~SECONDARY_EXEC_XSAVES;
5328+
5329+
if (nested) {
5330+
if (xsaves_enabled)
5331+
vmx->nested.nested_vmx_secondary_ctls_high |=
5332+
SECONDARY_EXEC_XSAVES;
5333+
else
5334+
vmx->nested.nested_vmx_secondary_ctls_high &=
5335+
~SECONDARY_EXEC_XSAVES;
5336+
}
5337+
}
5338+
53225339
if (vmx_rdtscp_supported()) {
53235340
bool rdtscp_enabled = guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP);
53245341
if (!rdtscp_enabled)
@@ -10421,6 +10438,7 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
1042110438
exec_control &= ~(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
1042210439
SECONDARY_EXEC_ENABLE_INVPCID |
1042310440
SECONDARY_EXEC_RDTSCP |
10441+
SECONDARY_EXEC_XSAVES |
1042410442
SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
1042510443
SECONDARY_EXEC_APIC_REGISTER_VIRT |
1042610444
SECONDARY_EXEC_ENABLE_VMFUNC);

0 commit comments

Comments
 (0)