* [PATCH] KVM: x86: Explicitly zero-initialize on-stack CPUID unions
@ 2025-03-15 2:41 Sean Christopherson
2025-03-15 8:59 ` Jim Mattson
2025-04-04 10:42 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Sean Christopherson @ 2025-03-15 2:41 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
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 <seanjc@google.com>
---
arch/x86/kvm/cpuid.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 5e4d4934c0d3..571c906ffcbf 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1427,8 +1427,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
}
break;
case 0xa: { /* Architectural Performance Monitoring */
- union cpuid10_eax eax;
- union cpuid10_edx edx;
+ union cpuid10_eax eax = { };
+ union cpuid10_edx edx = { };
if (!enable_pmu || !static_cpu_has(X86_FEATURE_ARCH_PERFMON)) {
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)
if (kvm_pmu_cap.version)
edx.split.anythread_deprecated = 1;
- edx.split.reserved1 = 0;
- edx.split.reserved2 = 0;
entry->eax = eax.full;
entry->ebx = kvm_pmu_cap.events_mask;
@@ -1763,7 +1761,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
break;
/* AMD Extended Performance Monitoring and Debug */
case 0x80000022: {
- union cpuid_0x80000022_ebx ebx;
+ union cpuid_0x80000022_ebx ebx = { };
entry->ecx = entry->edx = 0;
if (!enable_pmu || !kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2)) {
base-commit: c9ea48bb6ee6b28bbc956c1e8af98044618fed5e
--
2.49.0.rc1.451.g8f38331e32-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Explicitly zero-initialize on-stack CPUID unions
2025-03-15 2:41 [PATCH] KVM: x86: Explicitly zero-initialize on-stack CPUID unions Sean Christopherson
@ 2025-03-15 8:59 ` Jim Mattson
2025-04-04 10:42 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Jim Mattson @ 2025-03-15 8:59 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel
On Fri, Mar 14, 2025 at 7:41 PM Sean Christopherson <seanjc@google.com> wrote:
>
> 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 <seanjc@google.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Explicitly zero-initialize on-stack CPUID unions
2025-03-15 2:41 [PATCH] KVM: x86: Explicitly zero-initialize on-stack CPUID unions Sean Christopherson
2025-03-15 8:59 ` Jim Mattson
@ 2025-04-04 10:42 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2025-04-04 10:42 UTC (permalink / raw)
To: Sean Christopherson; +Cc: kvm, linux-kernel
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-04 10:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-15 2:41 [PATCH] KVM: x86: Explicitly zero-initialize on-stack CPUID unions Sean Christopherson
2025-03-15 8:59 ` Jim Mattson
2025-04-04 10:42 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®