Skip to content

Commit fc4ba91

Browse files
sean-jcgregkh
authored andcommitted
KVM: x86: Explicitly zero-initialize on-stack CPUID unions
commit bc52ae0 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 81b290a commit fc4ba91

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
@@ -1053,8 +1053,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
10531053
}
10541054
break;
10551055
case 0xa: { /* Architectural Performance Monitoring */
1056-
union cpuid10_eax eax;
1057-
union cpuid10_edx edx;
1056+
union cpuid10_eax eax = { };
1057+
union cpuid10_edx edx = { };
10581058

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

10711071
if (kvm_pmu_cap.version)
10721072
edx.split.anythread_deprecated = 1;
1073-
edx.split.reserved1 = 0;
1074-
edx.split.reserved2 = 0;
10751073

10761074
entry->eax = eax.full;
10771075
entry->ebx = kvm_pmu_cap.events_mask;
@@ -1389,7 +1387,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
13891387
break;
13901388
/* AMD Extended Performance Monitoring and Debug */
13911389
case 0x80000022: {
1392-
union cpuid_0x80000022_ebx ebx;
1390+
union cpuid_0x80000022_ebx ebx = { };
13931391

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

0 commit comments

Comments
 (0)