Skip to content

Commit 779ed05

Browse files
yang-weijiangsean-jc
authored andcommitted
KVM: x86: Initialize kvm_caps.supported_xss
Set original kvm_caps.supported_xss to (host_xss & KVM_SUPPORTED_XSS) if XSAVES is supported. host_xss contains the host supported xstate feature bits for thread FPU context switch, KVM_SUPPORTED_XSS includes all KVM enabled XSS feature bits, the resulting value represents the supervisor xstates that are available to guest and are backed by host FPU framework for swapping {guest,host} XSAVE-managed registers/MSRs. [sean: relocate and enhance comment about PT / XSS[8] ] Signed-off-by: Yang Weijiang <[email protected]> Reviewed-by: Maxim Levitsky <[email protected]> Reviewed-by: Chao Gao <[email protected]> Tested-by: Mathias Krause <[email protected]> Tested-by: John Allen <[email protected]> Tested-by: Rick Edgecombe <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Signed-off-by: Chao Gao <[email protected]> Reviewed-by: Binbin Wu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 9622e11 commit 779ed05

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

arch/x86/kvm/x86.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs;
217217
| XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \
218218
| XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE)
219219

220+
/*
221+
* Note, KVM supports exposing PT to the guest, but does not support context
222+
* switching PT via XSTATE (KVM's PT virtualization relies on perf; swapping
223+
* PT via guest XSTATE would clobber perf state), i.e. KVM doesn't support
224+
* IA32_XSS[bit 8] (guests can/must use RDMSR/WRMSR to save/restore PT MSRs).
225+
*/
226+
#define KVM_SUPPORTED_XSS 0
227+
220228
bool __read_mostly allow_smaller_maxphyaddr = 0;
221229
EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr);
222230

@@ -3986,11 +3994,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
39863994
case MSR_IA32_XSS:
39873995
if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVES))
39883996
return KVM_MSR_RET_UNSUPPORTED;
3989-
/*
3990-
* KVM supports exposing PT to the guest, but does not support
3991-
* IA32_XSS[bit 8]. Guests have to use RDMSR/WRMSR rather than
3992-
* XSAVES/XRSTORS to save/restore PT MSRs.
3993-
*/
3997+
39943998
if (data & ~vcpu->arch.guest_supported_xss)
39953999
return 1;
39964000
if (vcpu->arch.ia32_xss == data)
@@ -9822,14 +9826,17 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
98229826
kvm_host.xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK);
98239827
kvm_caps.supported_xcr0 = kvm_host.xcr0 & KVM_SUPPORTED_XCR0;
98249828
}
9829+
9830+
if (boot_cpu_has(X86_FEATURE_XSAVES)) {
9831+
rdmsrq(MSR_IA32_XSS, kvm_host.xss);
9832+
kvm_caps.supported_xss = kvm_host.xss & KVM_SUPPORTED_XSS;
9833+
}
9834+
98259835
kvm_caps.supported_quirks = KVM_X86_VALID_QUIRKS;
98269836
kvm_caps.inapplicable_quirks = KVM_X86_CONDITIONAL_QUIRKS;
98279837

98289838
rdmsrq_safe(MSR_EFER, &kvm_host.efer);
98299839

9830-
if (boot_cpu_has(X86_FEATURE_XSAVES))
9831-
rdmsrq(MSR_IA32_XSS, kvm_host.xss);
9832-
98339840
kvm_init_pmu_capability(ops->pmu_ops);
98349841

98359842
if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES))

0 commit comments

Comments
 (0)