Skip to content

Commit af66874

Browse files
sean-jcopsiff
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]> (cherry picked from commit 8cb249d)
1 parent d61df9e commit af66874

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
@@ -1014,8 +1014,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
10141014
}
10151015
break;
10161016
case 0xa: { /* Architectural Performance Monitoring */
1017-
union cpuid10_eax eax;
1018-
union cpuid10_edx edx;
1017+
union cpuid10_eax eax = { };
1018+
union cpuid10_edx edx = { };
10191019

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

10321032
if (kvm_pmu_cap.version)
10331033
edx.split.anythread_deprecated = 1;
1034-
edx.split.reserved1 = 0;
1035-
edx.split.reserved2 = 0;
10361034

10371035
entry->eax = eax.full;
10381036
entry->ebx = kvm_pmu_cap.events_mask;
@@ -1306,7 +1304,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
13061304
break;
13071305
/* AMD Extended Performance Monitoring and Debug */
13081306
case 0x80000022: {
1309-
union cpuid_0x80000022_ebx ebx;
1307+
union cpuid_0x80000022_ebx ebx = { };
13101308

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

0 commit comments

Comments
 (0)