From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E79B1A238C for ; Fri, 17 Jan 2025 17:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737135408; cv=none; b=iWt5LFD0v7GZy7hJOA/dAnRS2/Fl026xt0LVFPiNY5TGi4n+fjTnDa/4KVe/McfeCTWYM8OcxXkxCaAt6auFJamPQbYL9E9bdSU3L1u1YKGerC3ZACiFmejoV7bkgdadJ8Lk+2jsM0elim+OhppCiHbt+gT7HcgDuYlCBQvHzVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737135408; c=relaxed/simple; bh=QBwKeN2Bq2CNE0zF7FaHpH3rztx/oNPKspqXSw64uEU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pd2zGG6XsxCb7/1WIl5p7myBrZeFxIam53phOmYpVUmb6LMrEr1PjQBm58PhDzDCKVWFL7tOPtwZl7pyLcWFzFjg0GtxVUbCu3ucImZ1H5jmxiw/LSoocz+a+yqDZZ0XzTN8B+DxJDFwcHnpALUmYOfpHMqJVlSwFOQYtAltlTc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1idlrbLO; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1idlrbLO" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2f2a9f056a8so4617942a91.2 for ; Fri, 17 Jan 2025 09:36:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737135407; x=1737740207; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YRfr6c2OOb+CwNJOPVVNgs0oQDVr3N04a+EaawYlXZ8=; b=1idlrbLOn60drfCroGR3AaHIQXfdCOAhHyL9/fAvW0ekgnv6mE2z9FsHqSi/BD6oHZ UEl342RyKGOAs+eAAW/EriJ7de/WEgYMYAMdcXQmBX7aQVQZairyHa2Z7O+SOIBIt+7Q 0CUBkbaDClZjf2P8jjB++hnqqSO+3laWcq34+QypcKytnzxI46DI0rbLJidjBLwFZ6MP QYd5vpxYqifFKcQJ7cncEqIBFAPaAYh5JhEy4f4XV1OE8tDaE/lMFwyR7hC+7Hb3nFTM 6XKbznkwqRx3ErjiTVpjPkWsXQHxKLvlSOafMVnJRBG7bG3+2KwFMFg8uOiP5y4Ubu9w dHDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737135407; x=1737740207; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YRfr6c2OOb+CwNJOPVVNgs0oQDVr3N04a+EaawYlXZ8=; b=gzOxn+PFhKqckf2Z+lbJYp7g9LXqPcOSYs8v6eoo0CeXmtixiclF+G2MuyuUMAzxRd Vwce5tkysnTh5/kK4wXrT2bcuOdMD4PEViKSrsY+/ultOtzlvM8mJEHaHlWsceav3YAk yJPOmhh6c5SX2GxVloneBKCEvrDPabm6E90CX5vkbmzUGAPH8QxPI6edLxoXJvMizMM8 eXOKX6s+EdK0uH8dUTyPk00RsZ8ncF8f95/dZyJl7Fix6cc0yf/+GRWK3ZUlmmTTvsOh WoFbQE5ud8E3Rcd4yOAYm/yGRKKMbdcc/Kg3Q10EyZGf0JgKytgk9KzoE8D2vsbADdgA +mSw== X-Forwarded-Encrypted: i=1; AJvYcCXSwEswC8UaVxU6YdxKYG57CP/2nR7mI7QscguyAPrUPVUy/R2UhS5AQQ8sXHqrWuU2QH0y1BEes7CWAUY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0KkfocGsHHUjJuQYorrw5uo/0lg4MAHPFV7/71enNoN/slojX ckDuQp8x2vl3TamAaG4Oi3G7NR72JJ8quyjngiGi3vy3+Ur5PJ4TPD5M89269eSJR/9hJvcSNDK bPA== X-Google-Smtp-Source: AGHT+IGGs8LQpUxnevvozQKUPF97I/qKWdMA+oKhunNgVSModdZKEUVcGoAjf8+j8iPaYyIgj8mqnh9TmN8= X-Received: from pjh8.prod.google.com ([2002:a17:90b:3f88:b0:2e5:5ffc:1c36]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4ed0:b0:2ee:c1d2:bc67 with SMTP id 98e67ed59e1d1-2f782c99704mr5531429a91.16.1737135406699; Fri, 17 Jan 2025 09:36:46 -0800 (PST) Date: Fri, 17 Jan 2025 09:36:45 -0800 In-Reply-To: <87ikqd8krp.fsf@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250113222740.1481934-1-seanjc@google.com> <20250113222740.1481934-4-seanjc@google.com> <87ikqd8krp.fsf@redhat.com> Message-ID: Subject: Re: [PATCH 3/5] KVM: selftests: Explicitly free CPUID array at end of Hyper-V CPUID test From: Sean Christopherson To: Vitaly Kuznetsov Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Dongjie Zou , stable@vger.kernel Content-Type: text/plain; charset="us-ascii" On Fri, Jan 17, 2025, Vitaly Kuznetsov wrote: > 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. 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!