Commit 855c7e9b authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86: Fix BUILD_BUG() in __cpuid_entry_get_reg() w/ CONFIG_UBSAN=y

Take the target reg in __cpuid_entry_get_reg() instead of a pointer to a
struct cpuid_reg.  When building with -fsanitize=alignment (enabled by
CONFIG_UBSAN=y), some versions of gcc get tripped up on the pointer and
trigger the BUILD_BUG().
Reported-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Fixes: d8577a4c ("KVM: x86: Do host CPUID at load time to mask KVM cpu caps")
Fixes: 4c61534a ("KVM: x86: Introduce cpuid_entry_{get,has}() accessors")
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Message-Id: <20200325191259.23559-1-sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 842f4be9
...@@ -269,7 +269,7 @@ static __always_inline void kvm_cpu_cap_mask(enum cpuid_leafs leaf, u32 mask) ...@@ -269,7 +269,7 @@ static __always_inline void kvm_cpu_cap_mask(enum cpuid_leafs leaf, u32 mask)
cpuid_count(cpuid.function, cpuid.index, cpuid_count(cpuid.function, cpuid.index,
&entry.eax, &entry.ebx, &entry.ecx, &entry.edx); &entry.eax, &entry.ebx, &entry.ecx, &entry.edx);
kvm_cpu_caps[leaf] &= *__cpuid_entry_get_reg(&entry, &cpuid); kvm_cpu_caps[leaf] &= *__cpuid_entry_get_reg(&entry, cpuid.reg);
} }
void kvm_set_cpu_caps(void) void kvm_set_cpu_caps(void)
......
...@@ -99,9 +99,9 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned int x86_featu ...@@ -99,9 +99,9 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned int x86_featu
} }
static __always_inline u32 *__cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, static __always_inline u32 *__cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry,
const struct cpuid_reg *cpuid) u32 reg)
{ {
switch (cpuid->reg) { switch (reg) {
case CPUID_EAX: case CPUID_EAX:
return &entry->eax; return &entry->eax;
case CPUID_EBX: case CPUID_EBX:
...@@ -121,7 +121,7 @@ static __always_inline u32 *cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, ...@@ -121,7 +121,7 @@ static __always_inline u32 *cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry,
{ {
const struct cpuid_reg cpuid = x86_feature_cpuid(x86_feature); const struct cpuid_reg cpuid = x86_feature_cpuid(x86_feature);
return __cpuid_entry_get_reg(entry, &cpuid); return __cpuid_entry_get_reg(entry, cpuid.reg);
} }
static __always_inline u32 cpuid_entry_get(struct kvm_cpuid_entry2 *entry, static __always_inline u32 cpuid_entry_get(struct kvm_cpuid_entry2 *entry,
...@@ -189,7 +189,7 @@ static __always_inline u32 *guest_cpuid_get_register(struct kvm_vcpu *vcpu, ...@@ -189,7 +189,7 @@ static __always_inline u32 *guest_cpuid_get_register(struct kvm_vcpu *vcpu,
if (!entry) if (!entry)
return NULL; return NULL;
return __cpuid_entry_get_reg(entry, &cpuid); return __cpuid_entry_get_reg(entry, cpuid.reg);
} }
static __always_inline bool guest_cpuid_has(struct kvm_vcpu *vcpu, static __always_inline bool guest_cpuid_has(struct kvm_vcpu *vcpu,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment