Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fuad Tabba" <fuad.tabba@linux.dev>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
	"Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH 2/2] KVM: arm64: selftests: Test PMU counter overflow in vpmu_counter_access
Date: Fri, 04 Dec 2026 11:06:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-249654@kernel.org> (raw)
In-Reply-To: <20261204104911.2797512-3-fuad.tabba@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] kvm/arm64: missing CPU pinning in run_overflow_test() breaks
  big.LITTLE
- [Low] KVM: arm64: selftests: missing ARMV8_PMU_INCLUDE_EL2 on CHAIN
  counter
--

commit edb981028c9723f221e3d9e0fdc640b53ad0edc4
Author: Fuad Tabba <fuad.tabba@linux.dev>

KVM: arm64: selftests: Test PMU counter overflow in vpmu_counter_access

This commit extends vpmu_counter_access to test PMU cycle counter and chained
event counter overflows, checking overflow status and interrupt delivery both
when the guest waits quietly and when it traps in a loop.

> diff --git a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
> index 22223395969e0..57e2f39863767 100644
> --- a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
> +++ b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c

[ ... ]

> @@ -596,6 +603,209 @@ static void run_error_test(u64 pmcr_n)

[ ... ]

> +static void test_chained_counter_overflow(enum overflow_wait wait)
> +{
> +	u64 high;
> +	int i;
> +
> +	write_pmevtypern(0, ARMV8_PMU_INCLUDE_EL2 | ARMV8_PMUV3_PERFCTR_CPU_CYCLES);
> +	write_pmevtypern(1, ARMV8_PMUV3_PERFCTR_CHAIN);

[Severity: Low]
Should PMEVTYPER1_EL0 also include ARMV8_PMU_INCLUDE_EL2 for the CHAIN event?

On NV-capable hosts the guest runs at EL2, where ARMv8 PMUv3 applies the
PMEVTYPER<n>_EL0 filtering bits (including NSH) to chained odd counters too.
drivers/perf/arm_pmuv3.c:armv8pmu_write_event_type() sets
ARMV8_PMUV3_PERFCTR_CHAIN | ARMV8_PMU_INCLUDE_EL2 for this reason.

This only passes today because kvm_pmu_counter_increment() skips EL filtering
on CHAIN events, so the test will fail if KVM enforces architectural filtering
or backs the counter directly in hardware.

[ ... ]

> +static void run_overflow_test(void)
> +{
> +	struct kvm_vcpu *vcpu;
> +	struct ucall uc;
> +
> +	create_vpmu_vm(guest_overflow_code);
> +	vcpu = vpmu_vm.vcpu;
> +	vm_install_exception_handler(vpmu_vm.vm, VECTOR_IRQ_CURRENT, guest_irq_handler);
> +	vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL, KVM_ARM_VCPU_PMU_V3_INIT, NULL);

[Severity: Medium]
Can run_overflow_test() fail with a timeout on heterogeneous (big.LITTLE)
arm64 hosts when the vCPU thread migrates across PMU clusters?

create_vpmu_vm() relies on kvm_arm_set_default_pmu() ->
kvm_pmu_probe_armpmu(), which binds the VM to whichever arm_pmu covers the
current CPU at vCPU init time without restricting kvm->arch.supported_cpus.

If the scheduler later migrates the spinning vCPU thread to a CPU outside that
PMU's supported_cpus mask, armpmu_filter() and armpmu_add() stop scheduling
the guest's perf event, so the counter stops advancing and wait_for_overflow()
times out.

Pinning the thread with pin_self_to_any_cpu() before create_vpmu_vm() (or
configuring KVM_ARM_VCPU_PMU_V3_SET_PMU with matching CPU affinity) keeps the
vCPU on the bound PMU's cluster.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204104911.2797512-1-fuad.tabba@linux.dev?part=2

  reply	other threads:[~2026-12-04 11:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 10:49 [PATCH 0/2] KVM: arm64: Fix PMU counter overflows for non-protected guests in pKVM Fuad Tabba
2026-12-04 10:49 ` [PATCH 1/2] KVM: arm64: Don't copy the PMU registers between the host and hyp vCPU Fuad Tabba
2026-12-04 10:49 ` [PATCH 2/2] KVM: arm64: selftests: Test PMU counter overflow in vpmu_counter_access Fuad Tabba
2026-12-04 11:06   ` sashiko-bot [this message]
2026-12-04 11:55     ` Fuad Tabba

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=sashiko-outbox-249654@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fuad.tabba@linux.dev \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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