Skip to content

Commit

Permalink
KVM: x86: Do host CPUID at load time to mask KVM cpu caps
Browse files Browse the repository at this point in the history
Mask kvm_cpu_caps based on host CPUID in preparation for overriding the
CPUID results during KVM_GET_SUPPORTED_CPUID instead of doing the
masking at runtime.

Note, masking may or may not be necessary, e.g. the kernel rarely, if
ever, sets real CPUID bits that are not supported by hardware.  But, the
code is cheap and only runs once at load, so an abundance of caution is
warranted.

No functional change intended.

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Mar 16, 2020
1 parent 7ff6c03 commit d8577a4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions arch/x86/kvm/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,16 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,

static __always_inline void kvm_cpu_cap_mask(enum cpuid_leafs leaf, u32 mask)
{
const struct cpuid_reg cpuid = x86_feature_cpuid(leaf * 32);
struct kvm_cpuid_entry2 entry;

reverse_cpuid_check(leaf);
kvm_cpu_caps[leaf] &= mask;

cpuid_count(cpuid.function, cpuid.index,
&entry.eax, &entry.ebx, &entry.ecx, &entry.edx);

kvm_cpu_caps[leaf] &= *__cpuid_entry_get_reg(&entry, &cpuid);
}

void kvm_set_cpu_caps(void)
Expand Down

0 comments on commit d8577a4

Please sign in to comment.