From nobody Thu Dec 18 11:46:01 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 3A3441FA16B for ; Mon, 13 Jan 2025 22:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736807270; cv=none; b=Loyf2ystmV+ZW4jqxaSrybYfZp/BcIoCJ9ni3eF5ivh8/hEiNOx9k58zdU/b+b7UxXdSPIMMF7kJTH8YbOraKwt5gsrWpY6dajKPDTkulWYM6hxlY7zSTj/xxLaPhycJIQ7Lwi2S8RdJaeAJYdzxc+Ur9R/8cKoJ+c2KcMPGVgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736807270; c=relaxed/simple; bh=iZqIiGhqGkDp1l9h+Tl36RWsA0eh5huy0GX52g1XNG8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mFncItMwXcX7quVV4fjCu/1xq1tzLVFc1gL6ktzOHsTq6vEeVF07W7HOidCibs8LrjPU15mMwtTA2XEE3YvXRjP5NIB4yml0cy6Ons9bLl4p7fVLflxhesWWIS23wIkQ97WQUr0TaP3KUIPYSGUNzFwkhDZXU/xaViOqaXzqKww= 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=TuVVz5Bh; arc=none smtp.client-ip=209.85.216.73 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="TuVVz5Bh" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef91d5c863so8610560a91.2 for ; Mon, 13 Jan 2025 14:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736807268; x=1737412068; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=BUiKBnRthtYi8hLYA5ryBjgwDDiPDiUap44/jYe6tjY=; b=TuVVz5Bhx0l2kiKirn3JkyekrSyaOSV6MR5UgfkqoIEg0lbDs8LEUfqR5pB9qXS2bp L90zeE0ir9NlvnXwiYAIfM1Svghro3L+TNFjx05e3tvXSQ8fKzcFoUUIcQkayIK0OlEZ DZOj1CXSi0mKZpwNkJhIhcLknl4e9p4+6wuGAbXUcE/PyBOcYOQhWkwdZmcFlOnqv4rt GpEruq7xhcTw4pv1k0RKBEy4eVf70h8Gt3x73HWGpEUI6n3m7jBvc1tAwFn2HjXVTBOo 4B2EjH2u0AVNaEd+W1CPf7/AkKynQFEYw9sS/RakU1nXj4rQyULGA8bl/pQax4ECHETa LN1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736807268; x=1737412068; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BUiKBnRthtYi8hLYA5ryBjgwDDiPDiUap44/jYe6tjY=; b=V8Mn7jrUH2HW6DqXkRO4i7G59XQ8GrHFZijDE+0i1aTSa2GpuiGK7DlAPz2sHSj05g 4nqNaZ8zlKODP9gthbvxk050yCu9cB3j4hF9GoSBt6wd98DWcBj4LXeex1uwPzqUJcs8 s2+DFaMm7ppSGEQH7bC3sR3XWqaUVp8Ue3b5loM1kD5IoCxgGz/hke/pI3Ph92D5pm1p WxECN509bBR3RF/LfjAr+Ntxxigowg4Ie5L5o++XsEwJgqV3bdWcmlN+lf4mi1wncSM8 JiGM2NSOjPnqM2SY1Zf/cooExbHIr+ylOFu1rntYBND7FrIKRRJUVakijvx+H9EJY+wM OXlA== X-Forwarded-Encrypted: i=1; AJvYcCUF+m4aiWsU3ztWZrIMROcAPyzrbjnQBPHIifRqtoS1v0gZW0vuJ8wvUeS4ZURTI3v/RfTM1CjpQ8xth34=@vger.kernel.org X-Gm-Message-State: AOJu0YzRMtelgoT4AgFsYQMnzin68F99Hn4jG7G7OXR/aBh2YlORxWbS 3XYUOFY+zkLO2LcpBaiNE4wc2YKiGjUKX3rV+WlIqWjUdtDtwHEXss+qgWaGMTzcwcqwP7xQcvu QWg== X-Google-Smtp-Source: AGHT+IHr3YxVY4T6srwZUwxI0ZW6g2YPlW69vv/o0vnwcKqZpomk75DDB0odCx5hUB1kSCPXFWYmf+EoR1o= X-Received: from pjbsd14.prod.google.com ([2002:a17:90b:514e:b0:2ea:5613:4d5d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2588:b0:2ee:c9b6:c26a with SMTP id 98e67ed59e1d1-2f548eae05amr33135273a91.11.1736807268726; Mon, 13 Jan 2025 14:27:48 -0800 (PST) Reply-To: Sean Christopherson Date: Mon, 13 Jan 2025 14:27:39 -0800 In-Reply-To: <20250113222740.1481934-1-seanjc@google.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> X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-goog Message-ID: <20250113222740.1481934-5-seanjc@google.com> Subject: [PATCH 4/5] KVM: selftests: Manage CPUID array in Hyper-V CPUID test's core helper From: Sean Christopherson To: Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Dongjie Zou , stable@vger.kernel Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Cc: Vitaly Kuznetsov Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/hyperv_cpuid.c | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c b/tools/test= ing/selftests/kvm/x86_64/hyperv_cpuid.c index 09f9874d7705..90c44765d584 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c @@ -41,13 +41,18 @@ static bool smt_possible(void) return res; } =20 -static void test_hv_cpuid(const struct kvm_cpuid2 *hv_cpuid_entries, - bool evmcs_expected) +static void test_hv_cpuid(struct kvm_vcpu *vcpu, bool evmcs_expected) { + const struct kvm_cpuid2 *hv_cpuid_entries; int i; int nent_expected =3D 10; u32 test_val; =20 + if (vcpu) + hv_cpuid_entries =3D vcpu_get_supported_hv_cpuid(vcpu); + else + hv_cpuid_entries =3D kvm_get_supported_hv_cpuid(); + TEST_ASSERT(hv_cpuid_entries->nent =3D=3D nent_expected, "KVM_GET_SUPPORTED_HV_CPUID should return %d entries" " (returned %d)", @@ -109,6 +114,7 @@ static void test_hv_cpuid(const struct kvm_cpuid2 *hv_c= puid_entries, * entry->edx); */ } + free((void *)hv_cpuid_entries); } =20 static void test_hv_cpuid_e2big(struct kvm_vm *vm, struct kvm_vcpu *vcpu) @@ -129,7 +135,6 @@ static void test_hv_cpuid_e2big(struct kvm_vm *vm, stru= ct kvm_vcpu *vcpu) int main(int argc, char *argv[]) { struct kvm_vm *vm; - const struct kvm_cpuid2 *hv_cpuid_entries; struct kvm_vcpu *vcpu; =20 TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_CPUID)); @@ -138,10 +143,7 @@ int main(int argc, char *argv[]) =20 /* Test vCPU ioctl version */ test_hv_cpuid_e2big(vm, vcpu); - - hv_cpuid_entries =3D vcpu_get_supported_hv_cpuid(vcpu); - test_hv_cpuid(hv_cpuid_entries, false); - free((void *)hv_cpuid_entries); + test_hv_cpuid(vcpu, false); =20 if (!kvm_cpu_has(X86_FEATURE_VMX) || !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { @@ -149,9 +151,7 @@ int main(int argc, char *argv[]) goto do_sys; } vcpu_enable_evmcs(vcpu); - hv_cpuid_entries =3D vcpu_get_supported_hv_cpuid(vcpu); - test_hv_cpuid(hv_cpuid_entries, true); - free((void *)hv_cpuid_entries); + test_hv_cpuid(vcpu, true); =20 do_sys: /* Test system ioctl version */ @@ -161,10 +161,7 @@ int main(int argc, char *argv[]) } =20 test_hv_cpuid_e2big(vm, NULL); - - hv_cpuid_entries =3D kvm_get_supported_hv_cpuid(); - test_hv_cpuid(hv_cpuid_entries, kvm_cpu_has(X86_FEATURE_VMX)); - free((void *)hv_cpuid_entries); + test_hv_cpuid(NULL, kvm_cpu_has(X86_FEATURE_VMX)); =20 out: kvm_vm_free(vm); --=20 2.47.1.688.g23fc6f90ad-goog