[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87ikqd8krp.fsf@redhat.com>
Date: Fri, 17 Jan 2025 17:31:22 +0100
From: Vitaly Kuznetsov <vkuznets@...hat.com>
To: Sean Christopherson <seanjc@...gle.com>, Sean Christopherson
<seanjc@...gle.com>, Paolo Bonzini <pbonzini@...hat.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org, Dongjie Zou
<zoudongjie@...wei.com>, stable@...r.kernel
Subject: Re: [PATCH 3/5] KVM: selftests: Explicitly free CPUID array at end
of Hyper-V CPUID test
Sean Christopherson <seanjc@...gle.com> writes:
> Explicitly free the array of CPUID entries at the end of the Hyper-V CPUID
> test, mainly in anticipation of moving management of the array into the
> main test helper.
>
> Cc: Vitaly Kuznetsov <vkuznets@...hat.com>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> ---
> tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
> index 9a0fcc713350..09f9874d7705 100644
> --- a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
> +++ b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
> @@ -164,6 +164,7 @@ int main(int argc, char *argv[])
>
> hv_cpuid_entries = kvm_get_supported_hv_cpuid();
> test_hv_cpuid(hv_cpuid_entries, kvm_cpu_has(X86_FEATURE_VMX));
> + free((void *)hv_cpuid_entries);
vcpu_get_supported_hv_cpuid() allocates memory for the resulting array
each time, however, kvm_get_supported_hv_cpuid() was designed after
what's now kvm_get_supported_cpuid() (afair) so it has an optimization
to ask KVM just once:
static struct kvm_cpuid2 *cpuid;
int kvm_fd;
if (cpuid)
return cpuid;
cpuid = allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES);
kvm_fd = open_kvm_dev_path_or_exit();
...
and it seems that if we free hv_cpuid_entries here, next time we call
kvm_get_supported_hv_cpuid() an already freed memory will be returned.
This doesn't matter in in this patch as we're about to quit anyway but
with the next one in the series it becomes problematic.
>
> out:
> kvm_vm_free(vm);
--
Vitaly
Powered by blists - more mailing lists