From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E29513B59B for ; Fri, 17 Jan 2025 16:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737131490; cv=none; b=kwpBrkfvCedQQMpUWSKFDZEsRd0MSGTHP4D2JeyfTWwKQ2RM0yVpzK+Xc1UxtO+RLKsloCuzBaQaXGnWswyH9VhqxYRRKruCC9fZJEClCsfZLP3wAB+9zbDp8ZA4zxM811UHSncKlEDA903CZzsi4TOVHYKuKuAG5CUa4OwxMpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737131490; c=relaxed/simple; bh=SUzw+Oq73Ti5mrMSVS2BVl5YvYwhL8yTQv6MVPwzzqM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=TrcqYB3fv9cI2nf0vt1v79HUAdAEipP8ddnzj6istu80Z3gfqNHRRPaPgxrk94wML5Y1A2s3iiM6yLc89tFrlz7jT+yNAlIihNAqu5hSVg6FWqO5ozcrLdWM5E37CUvXuEKPEYawXVi1G3fi0+pMBCJDhM5jbWdys2DKJmJGnec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q0XCoXAg; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q0XCoXAg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737131487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5kZSArTqPW7y8wazAkzMJhveaDrun60pF6L1VI/G06I=; b=Q0XCoXAgRuNVYJLFuJVWhbNaMRDqp6JAcY5YoOEst69+LTYrnAAbH03xfLS6iM5D4Fi8KA P9HopPO/AFXXOdpy9BgxDbftVMETOiieD5XN7hFzkjmc5tdzNVEEhkUnmRm+FmWnDauMlq 8bztbTIjXSroUAFjaDXtrWxIOUlzXd8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-490-SohuAMJBPRyndQkG1d_OBQ-1; Fri, 17 Jan 2025 11:31:26 -0500 X-MC-Unique: SohuAMJBPRyndQkG1d_OBQ-1 X-Mimecast-MFC-AGG-ID: SohuAMJBPRyndQkG1d_OBQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43646b453bcso11627995e9.3 for ; Fri, 17 Jan 2025 08:31:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737131485; x=1737736285; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5kZSArTqPW7y8wazAkzMJhveaDrun60pF6L1VI/G06I=; b=mPVWxTdSRCKT1CjhhowpOMLg3WGhZfLRXu+hl0+YsT3cM/xxOKjziSkqDHz3I6sBZE /NF18boJWQURUfT7YxKsSXOF3Rncg2rVOM824dhnnAXxgRs3mwHrI3bQfoKLs8PMei6c fYeaIAa5whphq7KiKBnmUgWb9cC88rLtrmGPU1Yti7+K3m6e46+KcAuS88R7LWErKh05 AL2lpEp34ujCvCl6oQCZw3eQmYxmPbE2hYuLSJhqi1iBUbRYO8S55Rrl9QKa/i0+6A0x 93IQxKht4BTQILFXXnQdA7+l0BKwZU9lH0zl+9hu8DTAUrhcDOtjF6I5ASqUE3+iKolm YFOQ== X-Forwarded-Encrypted: i=1; AJvYcCURd/IJjHaxbXIk9Dh1OTM2HpXCL6QwU0nuQYk0b6+G2CM8UcjTKG8rZbkw1UtN4/9YBNFqMqcy701Qlb0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2DVoQwUffPZWj/s4ELmpa6k2qVcYrM9U2Zzzjcb7MGxNM69pY /skc8VZ5eD89Ya55QOLytzxe7oj8Id68J/d3kDmmmqvFhDlGU/13XZrBOUGGGC3acWHYTcEka7U djhDzYqFre9QPE6aeAjUunEHQgYlAa6EM7EbH+Dd7CAigrVGzK16STIvyhvo/VQDtKu5YqA== X-Gm-Gg: ASbGnctrHkg+g6obgdSWuIQLVQvn9KSHbz18XrVtImFp/cTIC2LWBhBEtafcso5u5IB 31DOImAPdlaFm9GN/iqDP3Ma9OjHMJBOlqIsh6fxSmOMbvB7lWgIBcvVSPmlV8tRnp9339qRKMP XR6GobnoQkHZ355CdPqyAph6vd1IqrMm4OsY6ZiWbHW4ef9vmI3AMTnkBGfxSjap8bbCTOhqQU5 Erz8sd+JG7DWUmewjSGvjCCh5OTu5tQzUWK+45FTvpynnRjyOU= X-Received: by 2002:a05:600c:5486:b0:436:51bb:7a52 with SMTP id 5b1f17b1804b1-438913c9c93mr33958855e9.7.1737131484801; Fri, 17 Jan 2025 08:31:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzybavdrtbNIcjbRCoDzaMdvU1XI2nGM8kEOYRxgMRQWuVVlEmre8BK1gVG96AlnqvHu/htA== X-Received: by 2002:a05:600c:5486:b0:436:51bb:7a52 with SMTP id 5b1f17b1804b1-438913c9c93mr33958405e9.7.1737131484456; Fri, 17 Jan 2025 08:31:24 -0800 (PST) Received: from fedora (g2.ign.cz. [91.219.240.8]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c74c4751sm97808145e9.19.2025.01.17.08.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 08:31:23 -0800 (PST) From: Vitaly Kuznetsov To: Sean Christopherson , Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Dongjie Zou , stable@vger.kernel Subject: Re: [PATCH 3/5] KVM: selftests: Explicitly free CPUID array at end of Hyper-V CPUID test In-Reply-To: <20250113222740.1481934-4-seanjc@google.com> References: <20250113222740.1481934-1-seanjc@google.com> <20250113222740.1481934-4-seanjc@google.com> Date: Fri, 17 Jan 2025 17:31:22 +0100 Message-ID: <87ikqd8krp.fsf@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Sean Christopherson 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 > Signed-off-by: Sean Christopherson > --- > 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