All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: selftests: Create one VM with many vCPUs for each major PMU counters test
Date: Tue, 04 Aug 2026 17:46:15 +0000	[thread overview]
Message-ID: <20260804174616.465821F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260804173437.3339269-3-seanjc@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] In `test_gp_counters`, the refactoring incorrectly configures every vCPU with the maximum number of GP counters, losing test coverage for intermediate values.
- [Low] The `vcpus` pointer array is allocated using the size of `struct kvm_vcpu` rather than the size of a pointer.
--

--- Patch [2]: [PATCH 2/2] KVM: selftests: Create one VM with many vCPUs for each major PMU counters test ---
commit f846c14eae6ee2689b438ef9a6cdf2439244aee5
Author: Sean Christopherson <seanjc@google.com>

KVM: selftests: Create one VM with many vCPUs for each major PMU counters test

This commit refactors the PMU counters test to create a single VM per 
test category (arch events, GP PMCs, fixed PMCs) and provisions multiple
vCPUs within that VM. This drastically reduces the test runtime by
avoiding repeated VM creation overhead.

> diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c
> --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c
> +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c
[ ... ]
> -static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu,
> -						  void *guest_code,
> -						  u8 pmu_version,
> -						  u64 perf_capabilities)
> +static struct kvm_vm *pmu_vm_create_with_vcpus(u32 nr_vcpus, void *guest_code,
> +					       u8 pmu_version,
> +					       u64 perf_capabilities,
> +					       struct kvm_vcpu **__vcpus[])
>  {
> +	struct kvm_vcpu **vcpus = calloc(nr_vcpus, sizeof(struct kvm_vcpu));

[Severity: Low]
Is this allocating the correct size?

It looks like vcpus is an array of pointers, so this might need to be
sizeof(struct kvm_vcpu *) instead of sizeof(struct kvm_vcpu). While it
just results in a minor memory over-allocation here, it could be slightly
confusing.

[ ... ]
> -static void test_gp_counters(u8 pmu_version, u64 perf_capabilities,
> -			     u8 nr_gp_counters)
> +static void test_gp_counters(u8 pmu_version, u64 perf_capabilities)
>  {
> -	struct kvm_vcpu *vcpu;
> +	u8 nr_gp_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS);
> +	struct kvm_vcpu **vcpus;
>  	struct kvm_vm *vm;
> +	u8 j;
>  
> -	vm = pmu_vm_create_with_one_vcpu(&vcpu, guest_test_gp_counters,
> -					 pmu_version, perf_capabilities);
> +	pr_info("Testing %u GP counters, PMU version %u, perf_caps = %lx\n",
> +		nr_gp_counters, pmu_version, perf_capabilities);
>  
> -	vcpu_set_cpuid_property(vcpu, X86_PROPERTY_PMU_NR_GP_COUNTERS,
> -				nr_gp_counters);
> +	vm = pmu_vm_create_with_vcpus(nr_gp_counters + 1, guest_test_gp_counters,
> +				      pmu_version, perf_capabilities, &vcpus);
>  
> -	run_vcpu(vcpu);
> +	for (j = 0; j <= nr_gp_counters; j++) {
> +		vcpu_set_cpuid_property(vcpus[j], X86_PROPERTY_PMU_NR_GP_COUNTERS,
> +					nr_gp_counters);

[Severity: Medium]
Does this inadvertently lose test coverage for the intermediate counter values?

By setting X86_PROPERTY_PMU_NR_GP_COUNTERS to the loop upper bound 
(nr_gp_counters) instead of the loop variable (j), we end up configuring
every vCPU with the maximum number of GP counters. This seems to bypass
testing edge cases like 0 GP counters entirely. Should this be passing j
instead of nr_gp_counters?

>  
> -	kvm_vm_free(vm);
> +		run_vcpu(vcpus[j]);
> +	}
> +
> +	pmu_vm_free(vm, vcpus);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804173437.3339269-1-seanjc@google.com?part=2

  reply	other threads:[~2026-08-04 17:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 17:34 [PATCH 0/2] KVM: selftests: Reduce PMC test runtime by ~17x Sean Christopherson
2026-08-04 17:34 ` [PATCH 1/2] KVM: selftests: Test one random GP counter in PMU arch events testcase Sean Christopherson
2026-08-04 17:34 ` [PATCH 2/2] KVM: selftests: Create one VM with many vCPUs for each major PMU counters test Sean Christopherson
2026-08-04 17:46   ` sashiko-bot [this message]
2026-08-04 20:33     ` 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=20260804174616.465821F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.