Skip to content

Commit 139f742

Browse files
committed
kvm: x86: Use KVM CPU capabilities to determine CR4 reserved bits
Using CPUID data can be useful for the processor compatibility check, but that's it. Using it to compute guest-reserved bits can have both false positives (such as LA57 and UMIP which we are already handling) and false negatives: in particular, with this patch we don't allow anymore a KVM guest to set CR4.PKE when CR4.PKE is clear on the host. Fixes: b9dd21e ("KVM: x86: simplify handling of PKRU") Reported-by: Jim Mattson <[email protected]> Tested-by: Jim Mattson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c7cb2d6 commit 139f742

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

arch/x86/kvm/x86.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -926,19 +926,6 @@ EXPORT_SYMBOL_GPL(kvm_set_xcr);
926926
__reserved_bits; \
927927
})
928928

929-
static u64 kvm_host_cr4_reserved_bits(struct cpuinfo_x86 *c)
930-
{
931-
u64 reserved_bits = __cr4_reserved_bits(cpu_has, c);
932-
933-
if (kvm_cpu_cap_has(X86_FEATURE_LA57))
934-
reserved_bits &= ~X86_CR4_LA57;
935-
936-
if (kvm_cpu_cap_has(X86_FEATURE_UMIP))
937-
reserved_bits &= ~X86_CR4_UMIP;
938-
939-
return reserved_bits;
940-
}
941-
942929
static int kvm_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
943930
{
944931
if (cr4 & cr4_reserved_bits)
@@ -9675,7 +9662,9 @@ int kvm_arch_hardware_setup(void *opaque)
96759662
if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
96769663
supported_xss = 0;
96779664

9678-
cr4_reserved_bits = kvm_host_cr4_reserved_bits(&boot_cpu_data);
9665+
#define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
9666+
cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
9667+
#undef __kvm_cpu_cap_has
96799668

96809669
if (kvm_has_tsc_control) {
96819670
/*
@@ -9707,7 +9696,8 @@ int kvm_arch_check_processor_compat(void *opaque)
97079696

97089697
WARN_ON(!irqs_disabled());
97099698

9710-
if (kvm_host_cr4_reserved_bits(c) != cr4_reserved_bits)
9699+
if (__cr4_reserved_bits(cpu_has, c) !=
9700+
__cr4_reserved_bits(cpu_has, &boot_cpu_data))
97119701
return -EIO;
97129702

97139703
return ops->check_processor_compatibility();

0 commit comments

Comments
 (0)