From: sashiko-bot@kernel.org
To: "Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
kvm@vger.kernel.org, "Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v8 09/11] KVM: arm64: PMU: Implement fixed-counters-only emulation
Date: Fri, 10 Jul 2026 11:48:56 +0000 [thread overview]
Message-ID: <20260710114856.D10951F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260710-hybrid-v8-9-621409f3a592@rsg.ci.i.u-tokyo.ac.jp>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Host-userspace-reachable WARN_ON_ONCE(!arm_pmu) when a VCPU is migrated to a physical CPU without an ARM PMU.
--
--- Patch [9]: [PATCH v8 09/11] KVM: arm64: PMU: Implement fixed-counters-only emulation ---
commit 9fc8926767402baf798832c66340a34d9fea3673
Author: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
KVM: arm64: PMU: Implement fixed-counters-only emulation
This patch implements fixed-counters-only mode for PMUv3 emulation. It
restricts KVM to reporting only the cycle counter, and introduces a reload
mechanism if the vCPU migrates to a different physical CPU.
> diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
> index 2e7a0a427ddde..477852e8ddfe7 100644
> --- a/arch/arm64/kvm/pmu-emul.c
> +++ b/arch/arm64/kvm/pmu-emul.c
[ ... ]
> @@ -767,6 +773,29 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
> pmc->perf_event = event;
> }
>
> +/**
> + * kvm_pmu_create_perf_event - create a perf event for a counter
> + * @pmc: Counter context
> + */
> +static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
> +{
> + struct kvm_vcpu *vcpu = kvm_pmc_to_vcpu(pmc);
> + struct arm_pmu *arm_pmu = vcpu->kvm->arch.arm_pmu;
> +
> + if (kvm_pmu_fixed_counters_only(vcpu->kvm)) {
> + do {
> + arm_pmu = kvm_pmu_probe_armpmu(READ_ONCE(vcpu->cpu));
> +
> + if (WARN_ON_ONCE(!arm_pmu))
[Severity: High]
Can host userspace trigger this warning by migrating a VCPU thread to a
physical CPU that does not have a registered ARM PMU?
If host userspace uses sched_setaffinity to migrate a VCPU thread,
kvm_vcpu_load_pmu() detects the change and requests KVM_REQ_RELOAD_PMU.
When this request is handled before guest entry, it calls
kvm_pmu_create_perf_event(). In fixed-counters-only mode,
kvm_pmu_probe_armpmu() would return NULL, immediately hitting this
assertion.
This allows an unprivileged host userspace process to trigger a kernel
warning, which leads to a host kernel panic if panic_on_warn is enabled.
> + return;
> +
> + kvm_pmu_create_perf_event_with_pmu(pmc, arm_pmu);
> + } while (!cpumask_test_cpu(READ_ONCE(vcpu->cpu), &arm_pmu->supported_cpus));
> + } else {
> + kvm_pmu_create_perf_event_with_pmu(pmc, arm_pmu);
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260710-hybrid-v8-0-621409f3a592@rsg.ci.i.u-tokyo.ac.jp?part=9
next prev parent reply other threads:[~2026-07-10 11:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 11:14 [PATCH v8 00/11] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
2026-07-10 11:14 ` [PATCH v8 01/11] KVM: arm64: Serialize userspace MDCR_EL2 access Akihiko Odaki
2026-07-10 11:36 ` sashiko-bot
2026-07-10 11:14 ` [PATCH v8 02/11] tools headers: Sync bitfield.h with the kernel Akihiko Odaki
2026-07-10 11:14 ` [PATCH v8 03/11] KVM: arm64: selftests: Cover PMU state in MDCR_EL2 Akihiko Odaki
2026-07-10 11:14 ` [PATCH v8 04/11] arm64: errata: Require Apple IMPDEF PMUv3 traps on all CPUs Akihiko Odaki
2026-07-10 11:40 ` sashiko-bot
2026-07-10 11:14 ` [PATCH v8 05/11] KVM: arm64: Don't clear vcpu->cpu in kvm_arch_vcpu_put() Akihiko Odaki
2026-07-10 11:15 ` [PATCH v8 06/11] KVM: arm64: PMU: Protect the list of PMUs with RCU Akihiko Odaki
2026-07-10 11:15 ` [PATCH v8 07/11] KVM: arm64: PMU: Pass the pPMU to kvm_map_pmu_event() Akihiko Odaki
2026-07-10 11:15 ` [PATCH v8 08/11] KVM: arm64: PMU: Pass the target CPU to kvm_pmu_probe_armpmu() Akihiko Odaki
2026-07-10 11:15 ` [PATCH v8 09/11] KVM: arm64: PMU: Implement fixed-counters-only emulation Akihiko Odaki
2026-07-10 11:48 ` sashiko-bot [this message]
2026-07-10 11:15 ` [PATCH v8 10/11] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY Akihiko Odaki
2026-07-10 11:15 ` [PATCH v8 11/11] KVM: arm64: selftests: Test PMU_V3_FIXED_COUNTERS_ONLY Akihiko Odaki
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=20260710114856.D10951F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--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