KVM: selftests: Manage CPUID array in Hyper-V CPUID test's core helper
authorSean Christopherson <seanjc@google.com>
Sat, 18 Jan 2025 00:34:53 +0000 (16:34 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 12 Feb 2025 16:53:59 +0000 (08:53 -0800)
commitcd5a0c2f0faeb4a3fab3b78f6693a2d55ee51efa
tree7d87a24c6bfe70e0cff7e76a2327e61d3f7d1fe6
parent0b6db0dc43eefb4f89181546785c3609fd276524
KVM: selftests: Manage CPUID array in Hyper-V CPUID test's core helper

Allocate, get, and free the CPUID array in the Hyper-V CPUID test in the
test's core helper, instead of copy+pasting code at each call site.  In
addition to deduplicating a small amount of code, restricting visibility
of the array to a single invocation of the core test prevents "leaking" an
array across test cases.  Passing in @vcpu to the helper will also allow
pivoting on VM-scoped information without needing to pass more booleans,
e.g. to conditionally assert on features that require an in-kernel APIC.

To avoid use-after-free bugs due to overzealous and careless developers,
opportunstically add a comment to explain that the system-scoped helper
caches the Hyper-V CPUID entries, i.e. that the caller is not responsible
for freeing the memory.

Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20250118003454.2619573-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/x86/hyperv_cpuid.c