Skip to content

Commit 1f66590

Browse files
committed
KVM: x86: Update OS{XSAVE,PKE} bits in guest CPUID irrespective of host support
When making runtime CPUID updates, change OSXSAVE and OSPKE even if their respective base features (XSAVE, PKU) are not supported by the host. KVM already incorporates host support in the vCPU's effective reserved CR4 bits. I.e. OSXSAVE and OSPKE can be set if and only if the host supports them. And conversely, since KVM's ABI is that KVM owns the dynamic OS feature flags, clearing them when they obviously aren't supported and thus can't be enabled is arguably a fix. Reviewed-by: Maxim Levitsky <[email protected]> Reviewed-by: Binbin Wu <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent cfd1574 commit 1f66590

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,8 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
297297

298298
best = kvm_find_cpuid_entry(vcpu, 1);
299299
if (best) {
300-
/* Update OSXSAVE bit */
301-
if (boot_cpu_has(X86_FEATURE_XSAVE))
302-
cpuid_entry_change(best, X86_FEATURE_OSXSAVE,
303-
kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE));
300+
cpuid_entry_change(best, X86_FEATURE_OSXSAVE,
301+
kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE));
304302

305303
cpuid_entry_change(best, X86_FEATURE_APIC,
306304
vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE);
@@ -312,7 +310,7 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
312310
}
313311

314312
best = kvm_find_cpuid_entry_index(vcpu, 7, 0);
315-
if (best && boot_cpu_has(X86_FEATURE_PKU))
313+
if (best)
316314
cpuid_entry_change(best, X86_FEATURE_OSPKE,
317315
kvm_is_cr4_bit_set(vcpu, X86_CR4_PKE));
318316

0 commit comments

Comments
 (0)