Skip to content

Commit bc52ae0

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Explicitly zero-initialize on-stack CPUID unions
Explicitly zero/empty-initialize the unions used for PMU related CPUID entries, instead of manually zeroing all fields (hopefully), or in the case of 0x80000022, relying on the compiler to clobber the uninitialized bitfields. Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Message-ID: <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 459a351 commit bc52ae0

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
@@ -1427,8 +1427,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
14271427
}
14281428
break;
14291429
case 0xa: { /* Architectural Performance Monitoring */
1430-
union cpuid10_eax eax;
1431-
union cpuid10_edx edx;
1430+
union cpuid10_eax eax = { };
1431+
union cpuid10_edx edx = { };
14321432

14331433
if (!enable_pmu || !static_cpu_has(X86_FEATURE_ARCH_PERFMON)) {
14341434
entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
@@ -1444,8 +1444,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
14441444

14451445
if (kvm_pmu_cap.version)
14461446
edx.split.anythread_deprecated = 1;
1447-
edx.split.reserved1 = 0;
1448-
edx.split.reserved2 = 0;
14491447

14501448
entry->eax = eax.full;
14511449
entry->ebx = kvm_pmu_cap.events_mask;
@@ -1763,7 +1761,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
17631761
break;
17641762
/* AMD Extended Performance Monitoring and Debug */
17651763
case 0x80000022: {
1766-
union cpuid_0x80000022_ebx ebx;
1764+
union cpuid_0x80000022_ebx ebx = { };
17671765

17681766
entry->ecx = entry->edx = 0;
17691767
if (!enable_pmu || !kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2)) {

0 commit comments

Comments
 (0)