From: Oliver Upton <oliver.upton@linux.dev>
To: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Cc: Marc Zyngier <maz@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
devel@daynix.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH RFC v2 1/2] KVM: arm64: PMU: Introduce KVM_ARM_VCPU_PMU_V3_COMPOSITION
Date: Fri, 8 Aug 2025 16:08:18 -0700 [thread overview]
Message-ID: <aJaDYhme_St2b2sM@linux.dev> (raw)
In-Reply-To: <62494f54-13c6-4b9f-86a1-9a19ce58e91f@rsg.ci.i.u-tokyo.ac.jp>
On Thu, Aug 07, 2025 at 11:06:21PM +0900, Akihiko Odaki wrote:
> > The only cross-PMU events we will support are the fixed counters, my
> > strong preference is that we do not reverse-map architectural events to
> > generic perf events for all counters.
>
> I wonder if there is a benefit to special case PERF_COUNT_HW_CPU_CYCLES
> then; the current logic of kvm_map_pmu_event() looks sufficient for me.
I'd rather we just use the generic perf events and let the driver remap
things on our behalf. These are fixed counters, using constant events
feels like the right way to go about that.
kvm_map_pmu_event() is trying to solve a slightly different problem
where we need to map programmable PMUv3 events into a non-PMUv3 event
space, like on the M1 PMU.
> > This isn't what I meant. What I mean is that userspace either can use
> > the SET_PMU ioctl or the COMPOSITION ioctl. Once one of them has been
> > used the other ioctl returns an error.
> >
> > We're really bad at getting ioctl ordering / interleaving right and
> > syzkaller has a habit of finding these mistakes. There's zero practical
> > value in using both of these ioctls on the same VM, let's prevent it.
>
> The corresponding RFC series for QEMU uses KVM_ARM_VCPU_PMU_V3_SET_PMU to
> probe host PMUs, and falls back to KVM_ARM_VCPU_PMU_V3_COMPOSITION if none
> covers all CPUs. Switching between SET_PMU and COMPOSITION is useful during
> such probing.
>
> COMPOSITION is designed to behave like just another host PMU that is set
> with SET_PMU. SET_PMU allows setting a different host PMU even if SET_PMU
> has already been invoked so it is also allowed to set a host PMU even if
> COMPOSITION has already been invoked, maintaining consistency with
> non-composed PMUs.
>
> You can find the QEMU patch at:
> https://lore.kernel.org/qemu-devel/20250806-kvmq-v1-1-d1d50b7058cd@rsg.ci.i.u-tokyo.ac.jp/
>
> (look up KVM_ARM_VCPU_PMU_V3_SET_PMU for the probing code)
Having both of these attributes return success when probed with
KVM_HAS_DEVICE_ATTR is fine; what I mean is that once KVM_SET_DEVICE_ATTR
has been called on an attribute the other fails.
> > On a system that has FEAT_PMUv3_ICNTR, userspace can still use this
> > ioctl and explicitly de-feature ICNTR by writing to the ID register
> > after initialization.
>
> Now I understand better.
>
> Currently, KVM_ARM_VCPU_PMU_V3_COMPOSITION sets supported_cpus to ones that
> have cycle counters compatible with PMU emulation.
>
> If FEAT_PMUv3_ICNTR is set to the ID register, I guess
> KVM_ARM_VCPU_PMU_V3_COMPOSITION will set supported_cpus to ones that have
> compatible cycle and instruction counters. If so, the naming
> KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY indeed makes sense.
Perfect. Ideally SOC vendors do the sensible thing and ensure that
FEAT_PMUv3_ICNTR is consistent on all implementations in a machine. We
will hide the feature in KVM if it is not.
Thanks,
Oliver
next prev parent reply other threads:[~2025-08-08 23:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 9:09 [PATCH RFC v2 0/2] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
2025-08-06 9:09 ` [PATCH RFC v2 1/2] KVM: arm64: PMU: Introduce KVM_ARM_VCPU_PMU_V3_COMPOSITION Akihiko Odaki
2025-08-06 17:20 ` Oliver Upton
2025-08-06 18:24 ` Akihiko Odaki
2025-08-07 2:03 ` Oliver Upton
2025-08-07 14:06 ` Akihiko Odaki
2025-08-08 23:08 ` Oliver Upton [this message]
2025-08-09 6:15 ` Akihiko Odaki
2025-08-06 9:09 ` [PATCH RFC v2 2/2] KVM: arm64: selftests: Test guest PMUv3 composition 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=aJaDYhme_St2b2sM@linux.dev \
--to=oliver.upton@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=devel@daynix.com \
--cc=gustavoars@kernel.org \
--cc=joey.gouly@arm.com \
--cc=kees@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maz@kernel.org \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).