From: Sean Christopherson <seanjc@google.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Dongjie Zou <zoudongjie@huawei.com>,
stable@vger.kernel
Subject: Re: [PATCH 3/5] KVM: selftests: Explicitly free CPUID array at end of Hyper-V CPUID test
Date: Fri, 17 Jan 2025 09:36:45 -0800 [thread overview]
Message-ID: <Z4qVLU_hhwFHmic9@google.com> (raw)
In-Reply-To: <87ikqd8krp.fsf@redhat.com>
On Fri, Jan 17, 2025, Vitaly Kuznetsov wrote:
> Sean Christopherson <seanjc@google.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@redhat.com>
> > Signed-off-by: Sean Christopherson <seanjc@google.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.
Ow. I totally missed that. I'll drop this patch, and then adjust the next one
to do:
/*
* Note, the CPUID array returned by the system-scoped helper is a one-
* time allocation, i.e. must not be freed.
*/
if (vcpu)
free((void *)hv_cpuid_entries);
I'll post a v2 once I've actually tested.
Thanks!
next prev parent reply other threads:[~2025-01-17 17:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 22:27 [PATCH 0/5] KVM: x86: Hyper-V SEND_IPI fix and partial testcase Sean Christopherson
2025-01-13 22:27 ` [PATCH 1/5] KVM: x86: Reject Hyper-V's SEND_IPI hypercalls if local APIC isn't in-kernel Sean Christopherson
2025-01-13 22:29 ` Sean Christopherson
2025-01-17 16:31 ` Vitaly Kuznetsov
2025-01-13 22:27 ` [PATCH 2/5] KVM: selftests: Mark test_hv_cpuid_e2big() static in Hyper-V CPUID test Sean Christopherson
2025-01-17 16:31 ` Vitaly Kuznetsov
2025-01-13 22:27 ` [PATCH 3/5] KVM: selftests: Explicitly free CPUID array at end of " Sean Christopherson
2025-01-17 16:31 ` Vitaly Kuznetsov
2025-01-17 17:36 ` Sean Christopherson [this message]
2025-01-13 22:27 ` [PATCH 4/5] KVM: selftests: Manage CPUID array in Hyper-V CPUID test's core helper Sean Christopherson
2025-01-17 16:31 ` Vitaly Kuznetsov
2025-01-13 22:27 ` [PATCH 5/5] KVM: selftests: Add CPUID tests for Hyper-V features that need in-kernel APIC Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z4qVLU_hhwFHmic9@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=stable@vger.kernel \
--cc=vkuznets@redhat.com \
--cc=zoudongjie@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox