* [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs
@ 2026-09-20 11:15 Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 01/21] KVM: arm64: Serialize repeated vCPU initialization Akihiko Odaki
` (20 more replies)
0 siblings, 21 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
On a heterogeneous arm64 system, KVM's PMU emulation is based on the
features of a single host PMU instance. When a vCPU is migrated to a
pCPU with an incompatible PMU, counters such as PMCCNTR_EL0 stop
incrementing.
Although this behavior is permitted by the architecture, Windows does
not handle it gracefully and may crash with a division-by-zero error.
The current workaround requires VMMs to pin vCPUs to a set of pCPUs
that share a compatible PMU. This is difficult to implement correctly in
QEMU/libvirt, where pinning occurs after vCPU initialization, and it
also restricts the guest to a subset of available pCPUs.
This patch introduces the KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY
attribute. If set, PMUv3 will be emulated without programmable event
counters. KVM will be able to run VCPUs on any physical CPUs with a
compatible hardware PMU.
This allows Windows guests to run reliably on heterogeneous systems
without crashing, even without vCPU pinning, and enables VMMs to
schedule vCPUs across all available pCPUs, making full use of the host
hardware.
A QEMU patch that demonstrates the usage of the new attribute is
available at:
https://lore.kernel.org/qemu-devel/20260706-kvm-v4-1-089cac8c25c3@rsg.ci.i.u-tokyo.ac.jp/
("[PATCH RFC v4] target/arm/kvm: Choose PMU backend")
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Changes in v11:
- Added patch
"KVM: arm64: PMU: Mask EL2-reserved bits on guest bitmap reads".
- Replaced "KVM: arm64: PMU: Recreate events after reset" with a revert
of "KVM: arm64: PMU: Reload when resetting", restoring event teardown
before system-register reset.
- Moved the shared event-recreation mechanism into
"KVM: arm64: PMU: Recreate events after MDCR_EL2 changes".
- Link to v10: https://patch.msgid.link/20260914-hybrid-v10-0-92788053a691@rsg.ci.i.u-tokyo.ac.jp
Changes in v10:
- Changed fixed-counters-only pPMU migration to request event recreation
instead of relying on an enable-time compatibility check.
- Clarified that fixed-counters-only PMU emulation is unsupported when
a vCPU runs on a CPU without a registered pPMU.
- Checked guest completion after vCPU runs in PMU selftests.
- Added patch
"KVM: arm64: PMU: Preserve EL2 bitmap state during migration".
- Added patch
"KVM: arm64: PMU: Recreate events after reset".
- Added patch
"KVM: arm64: PMU: Recreate events after PMCR_EL0 changes".
- Added patch
"KVM: arm64: PMU: Recreate events after userspace event writes".
- Expanded the explanation of why a late CPU with extra IMPDEF
PMUv3 trap support cannot expose host PMU state.
- Link to v9: https://patch.msgid.link/20260720-hybrid-v9-0-2b713ca1b5dc@rsg.ci.i.u-tokyo.ac.jp
Changes in v9:
- Dropped patch
"KVM: arm64: Disallow vPMU when pPMUs do not cover all CPUs".
- Added patch
"KVM: arm64: PMU: Stop updating MDCR_EL2.HPMN".
- Added patch
"KVM: arm64: selftests: Cover PMU state in MDCR_EL2".
- Added patch
"arm64: errata: Require Apple IMPDEF PMUv3 traps on all CPUs".
- Added patch
"KVM: arm64: Don't clear vcpu->cpu in kvm_arch_vcpu_put()".
- Noted that fixed-counters-only mode avoids relying on the default PMU.
- Clarified why fixed-counters-only mode hides PMCEID.
- Added patch "KVM: arm64: Serialize repeated vCPU initialization".
- Added patch "KVM: arm64: PMU: Freeze counter count after first run".
- Added patch
"KVM: arm64: selftests: Test SET_NR_COUNTERS after first run".
- Added patch "KVM: arm64: PMU: Recreate events after MDCR_EL2 changes".
- Clarified why extra IMPDEF PMUv3 trap support on a late CPU is safe.
- Changed fixed-counters-only emulation to taint the kernel when it
encounters a CPU without a registered pPMU; see the commit message.
- Added patch
"KVM: arm64: PMU: Keep implemented counter mask EL-independent".
- Added a targeted bitfield helper type change to tools headers.
- Link to v8: https://patch.msgid.link/20260710-hybrid-v8-0-621409f3a592@rsg.ci.i.u-tokyo.ac.jp
Changes in v8:
- Added patch
"KVM: arm64: Disallow vPMU when pPMUs do not cover all CPUs".
- Split patch "KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY".
- Documented the FEAT_PMUv3_ICNTR support plan.
- Ensured KVM_ARM_VCPU_PMU_V3_FILTER and
KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY are mutually exclusive.
- Ensured KVM_ARM_VCPU_PMU_V3_SET_PMU and
KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY are mutually exclusive.
- Dropped the code to support KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS for
KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY.
- Added a function to de-duplicate
"test_bit(KVM_ARCH_FLAG_PMU_V3_FIXED_COUNTERS_ONLY, ...)".
- Link to v7: https://lore.kernel.org/r/20260418-hybrid-v7-0-2bf39ad009bf@rsg.ci.i.u-tokyo.ac.jp
Changes in v7:
- Fixed the vCPU run hang in test_fixed_counters_only().
- Link to v6: https://lore.kernel.org/r/20260413-hybrid-v6-0-e79d760f7f1b@rsg.ci.i.u-tokyo.ac.jp
Changes in v6:
- Removed WARN_ON_ONCE() in kvm_pmu_create_perf_event(). It can be
triggered in kvm_arch_vcpu_load() before it checks supported_cpus.
- Removed an extra lockdep assertion in kvm_arm_pmu_v3_get_attr().
- Fixed error messages in test_fixed_counters_only().
- Fixed the vCPU run in test_fixed_counters_only().
- Link to v5: https://lore.kernel.org/r/20260411-hybrid-v5-0-b043b4d9f49e@rsg.ci.i.u-tokyo.ac.jp
Changes in v5:
- Rebased.
- Fixed the order to clear KVM_ARCH_FLAG_PMU_V3_FIXED_COUNTERS_ONLY in
kvm_arm_pmu_v3_set_pmu().
- Fixed the setting of KVM_ARM_VCPU_PMU_V3_IRQ in
test_fixed_counters_only().
- Changed to WARN_ON_ONCE() when kvm_pmu_probe_armpmu() returns NULL in
kvm_pmu_create_perf_event(), which is no longer supposed to happen.
- Link to v4: https://lore.kernel.org/r/20260317-hybrid-v4-0-bd62bcd48644@rsg.ci.i.u-tokyo.ac.jp
Changes in v4:
- Extracted kvm_pmu_enabled_counter_mask() into a separate patch.
- Added patch "KVM: arm64: PMU: Protect the list of PMUs with RCU".
- Merged KVM_REQ_CREATE_PMU into KVM_REQ_RELOAD_PMU.
- Added a check to avoid unnecessary KVM_REQ_RELOAD_PMU requests.
- Dropped the change to avoid setting kvm_arm_set_default_pmu() when
KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY is not set.
- Link to v3: https://lore.kernel.org/r/20260225-hybrid-v3-0-46e8fe220880@rsg.ci.i.u-tokyo.ac.jp
Changes in v3:
- Renamed the attribute to KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY.
- Changed to request the creation of perf counters when loading vCPU.
- Link to v2: https://lore.kernel.org/r/20250806-hybrid-v2-0-0661aec3af8c@rsg.ci.i.u-tokyo.ac.jp
Changes in v2:
- Added the KVM_ARM_VCPU_PMU_V3_COMPOSITION attribute to opt in the
feature.
- Added code to handle overflow.
- Link to v1: https://lore.kernel.org/r/20250319-hybrid-v1-1-4d1ada10e705@daynix.com
---
Akihiko Odaki (20):
KVM: arm64: Serialize repeated vCPU initialization
KVM: arm64: PMU: Stop updating MDCR_EL2.HPMN
KVM: arm64: PMU: Freeze counter count after first run
KVM: arm64: selftests: Test SET_NR_COUNTERS after first run
KVM: arm64: PMU: Mask EL2-reserved bits on guest bitmap reads
KVM: arm64: PMU: Keep implemented counter mask EL-independent
KVM: arm64: PMU: Preserve EL2 bitmap state during migration
Revert "KVM: arm64: PMU: Reload when resetting"
KVM: arm64: PMU: Recreate events after MDCR_EL2 changes
KVM: arm64: PMU: Recreate events after PMCR_EL0 changes
KVM: arm64: PMU: Recreate events after userspace event writes
tools headers: Use u* types for bitfield helpers
KVM: arm64: selftests: Cover PMU state in MDCR_EL2
arm64: errata: Require Apple IMPDEF PMUv3 traps on all CPUs
KVM: arm64: PMU: Protect the list of PMUs with RCU
KVM: arm64: PMU: Pass the pPMU to kvm_map_pmu_event()
KVM: arm64: PMU: Pass the target CPU to kvm_pmu_probe_armpmu()
KVM: arm64: PMU: Implement fixed-counters-only emulation
KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY
KVM: arm64: selftests: Test PMU_V3_FIXED_COUNTERS_ONLY
Oliver Upton (1):
KVM: arm64: Don't clear vcpu->cpu in kvm_arch_vcpu_put()
Documentation/virt/kvm/api.rst | 8 +-
Documentation/virt/kvm/devices/vcpu.rst | 42 ++-
arch/arm64/include/asm/kvm_host.h | 4 +
arch/arm64/include/uapi/asm/kvm.h | 1 +
arch/arm64/kernel/cpu_errata.c | 2 +-
arch/arm64/kvm/arm.c | 18 +-
arch/arm64/kvm/pmu-emul.c | 272 +++++++++++------
arch/arm64/kvm/reset.c | 19 +-
arch/arm64/kvm/sys_regs.c | 52 ++--
include/kvm/arm_pmu.h | 11 +
tools/arch/arm64/include/uapi/asm/kvm.h | 1 +
tools/include/linux/bitfield.h | 26 +-
.../selftests/kvm/arm64/vpmu_counter_access.c | 329 ++++++++++++++++++---
13 files changed, 612 insertions(+), 173 deletions(-)
---
base-commit: 8476ce1f1e949a4eae0c0b8f06cf6ab51a3edfd0
change-id: 20250224-hybrid-01d5ff47edd2
Best regards,
--
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 01/21] KVM: arm64: Serialize repeated vCPU initialization
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 02/21] KVM: arm64: PMU: Stop updating MDCR_EL2.HPMN Akihiko Odaki
` (19 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
The initial KVM_ARM_VCPU_INIT path holds config_lock while resetting the
vCPU, but repeated initialization of an existing vCPU does not. As a
result, reset_mdcr() can race with VM-wide PMU configuration and
overwrite MDCR_EL2 with a stale counter count.
Take config_lock around the repeated-init checks and reset. The vCPU
ioctl already holds vcpu->mutex, matching the established lock ordering.
Fixes: c8823e51b534 ("KVM: arm64: Fix MDCR_EL2.HPMN reset value")
Closes: https://sashiko.dev/#/patchset/20260710-hybrid-v8-0-621409f3a592@rsg.ci.i.u-tokyo.ac.jp?part=1
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/arm.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index b0de4ea7dc39..997f24f5fb91 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1691,29 +1691,26 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
{
unsigned long features = init->features[0];
struct kvm *kvm = vcpu->kvm;
- int ret = -EINVAL;
+ int ret;
- mutex_lock(&kvm->arch.config_lock);
+ lockdep_assert_held(&kvm->arch.config_lock);
if (test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags) &&
kvm_vcpu_init_changed(vcpu, init))
- goto out_unlock;
+ return -EINVAL;
bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES);
ret = kvm_setup_vcpu(vcpu);
if (ret)
- goto out_unlock;
+ return ret;
/* Now we know what it is, we can reset it. */
kvm_reset_vcpu(vcpu);
set_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags);
vcpu_set_flag(vcpu, VCPU_INITIALIZED);
- ret = 0;
-out_unlock:
- mutex_unlock(&kvm->arch.config_lock);
- return ret;
+ return 0;
}
static int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
@@ -1729,6 +1726,8 @@ static int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
if (ret)
return ret;
+ guard(mutex)(&vcpu->kvm->arch.config_lock);
+
if (!kvm_vcpu_initialized(vcpu))
return __kvm_vcpu_set_target(vcpu, init);
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 02/21] KVM: arm64: PMU: Stop updating MDCR_EL2.HPMN
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 01/21] KVM: arm64: Serialize repeated vCPU initialization Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 03/21] KVM: arm64: PMU: Freeze counter count after first run Akihiko Odaki
` (18 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
KVM allows userspace to write any value to MDCR_EL2.HPMN. However,
kvm_arm_set_nr_counters() rewrites HPMN for every vCPU whenever
userspace changes the PMU or its counter count. This can discard a
value previously restored with KVM_SET_ONE_REG.
The architecture only defines HPMN's value on warm reset. Stop
rewriting it after vCPU initialization and update nr_pmu_counters
directly instead. reset_mdcr() continues to initialize HPMN from the
counter count current at KVM_ARM_VCPU_INIT.
Fixes: c8823e51b534 ("KVM: arm64: Fix MDCR_EL2.HPMN reset value")
Closes: https://sashiko.dev/#/patchset/20260706-hybrid-v8-0-de459617b59d%40rsg.ci.i.u-tokyo.ac.jp?part=6
Assisted-by: Codex:gpt-5.5
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 22 ++--------------------
1 file changed, 2 insertions(+), 20 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 5b1af7e2176f..832dd145af2a 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -1035,30 +1035,12 @@ u8 kvm_arm_pmu_get_max_counters(struct kvm *kvm)
return bitmap_weight(arm_pmu->cntr_mask, ARMV8_PMU_MAX_GENERAL_COUNTERS);
}
-static void kvm_arm_set_nr_counters(struct kvm *kvm, unsigned int nr)
-{
- kvm->arch.nr_pmu_counters = nr;
-
- /* Reset MDCR_EL2.HPMN behind the vcpus' back... */
- if (test_bit(KVM_ARM_VCPU_HAS_EL2, kvm->arch.vcpu_features)) {
- struct kvm_vcpu *vcpu;
- unsigned long i;
-
- kvm_for_each_vcpu(i, vcpu, kvm) {
- u64 val = __vcpu_sys_reg(vcpu, MDCR_EL2);
- val &= ~MDCR_EL2_HPMN;
- val |= FIELD_PREP(MDCR_EL2_HPMN, kvm->arch.nr_pmu_counters);
- __vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
- }
- }
-}
-
static void kvm_arm_set_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu)
{
lockdep_assert_held(&kvm->arch.config_lock);
kvm->arch.arm_pmu = arm_pmu;
- kvm_arm_set_nr_counters(kvm, kvm_arm_pmu_get_max_counters(kvm));
+ kvm->arch.nr_pmu_counters = kvm_arm_pmu_get_max_counters(kvm);
}
/**
@@ -1136,7 +1118,7 @@ static int kvm_arm_pmu_v3_set_nr_counters(struct kvm_vcpu *vcpu, unsigned int n)
if (n > kvm_arm_pmu_get_max_counters(kvm))
return -EINVAL;
- kvm_arm_set_nr_counters(kvm, n);
+ kvm->arch.nr_pmu_counters = n;
return 0;
}
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 03/21] KVM: arm64: PMU: Freeze counter count after first run
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 01/21] KVM: arm64: Serialize repeated vCPU initialization Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 02/21] KVM: arm64: PMU: Stop updating MDCR_EL2.HPMN Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 04/21] KVM: arm64: selftests: Test SET_NR_COUNTERS " Akihiko Odaki
` (17 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
PMU configuration is VM-scoped, but SET_NR_COUNTERS can be issued
through any vCPU. Checking only whether that vCPU's PMU has been
initialized allows userspace to change the counter count through an idle
sibling after another vCPU has run.
Reject the attribute once any vCPU has run. This keeps the VM-wide
implemented counter mask and the PMCR_EL0.N value stable after guest
execution begins.
Fixes: b7628c797376 ("KVM: arm64: Allow userspace to limit the number of PMU counters for EL2 VMs")
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 832dd145af2a..950b7a349659 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -1112,6 +1112,9 @@ static int kvm_arm_pmu_v3_set_nr_counters(struct kvm_vcpu *vcpu, unsigned int n)
{
struct kvm *kvm = vcpu->kvm;
+ if (kvm_vm_has_ran_once(kvm))
+ return -EBUSY;
+
if (!kvm->arch.arm_pmu)
return -EINVAL;
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 04/21] KVM: arm64: selftests: Test SET_NR_COUNTERS after first run
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (2 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 03/21] KVM: arm64: PMU: Freeze counter count after first run Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 05/21] KVM: arm64: PMU: Mask EL2-reserved bits on guest bitmap reads Akihiko Odaki
` (16 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Add a regression test that runs one vCPU and then tries to change the
VM-scoped PMU counter count through an idle sibling. Verify that
SET_NR_COUNTERS fails with EBUSY once any vCPU has run.
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
.../selftests/kvm/arm64/vpmu_counter_access.c | 47 ++++++++++++++++++++--
1 file changed, 43 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
index 22223395969e..05135bcdb462 100644
--- a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
+++ b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
@@ -443,11 +443,10 @@ static void destroy_vpmu_vm(void)
kvm_vm_free(vpmu_vm.vm);
}
-static void run_vcpu(struct kvm_vcpu *vcpu, u64 pmcr_n)
+static void run_vcpu(struct kvm_vcpu *vcpu)
{
struct ucall uc;
- vcpu_args_set(vcpu, 1, pmcr_n);
vcpu_run(vcpu);
switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT:
@@ -461,6 +460,11 @@ static void run_vcpu(struct kvm_vcpu *vcpu, u64 pmcr_n)
}
}
+static void guest_code_done(void)
+{
+ GUEST_DONE();
+}
+
static void test_create_vpmu_vm_with_nr_counters(unsigned int nr_counters, bool expect_fail)
{
struct kvm_vcpu *vcpu;
@@ -503,7 +507,8 @@ static void run_access_test(u64 pmcr_n)
/* Save the initial sp to restore them later to run the guest again */
sp = vcpu_get_reg(vcpu, ctxt_reg_alias(vcpu, SYS_SP_EL1));
- run_vcpu(vcpu, pmcr_n);
+ vcpu_args_set(vcpu, 1, pmcr_n);
+ run_vcpu(vcpu);
/*
* Reset and re-initialize the vCPU, and run the guest code again to
@@ -516,7 +521,8 @@ static void run_access_test(u64 pmcr_n)
vcpu_set_reg(vcpu, ctxt_reg_alias(vcpu, SYS_SP_EL1), sp);
vcpu_set_reg(vcpu, ARM64_CORE_REG(regs.pc), (u64)guest_code);
- run_vcpu(vcpu, pmcr_n);
+ vcpu_args_set(vcpu, 1, pmcr_n);
+ run_vcpu(vcpu);
destroy_vpmu_vm();
}
@@ -622,6 +628,37 @@ static bool kvm_supports_nr_counters_attr(void)
return supported;
}
+static void test_set_nr_counters_after_vcpu_run(void)
+{
+ struct kvm_vcpu *running_vcpu, *stopped_vcpu;
+ unsigned int nr_counters = 0;
+ struct kvm_vcpu_init init;
+ struct kvm_vm *vm;
+ int ret;
+ u64 irq = 23;
+
+ vm = vm_create(2);
+ vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init);
+ init.features[0] |= BIT(KVM_ARM_VCPU_PMU_V3);
+ running_vcpu = aarch64_vcpu_add(vm, 0, &init, guest_code_done);
+ stopped_vcpu = aarch64_vcpu_add(vm, 1, &init, guest_code_done);
+ kvm_arch_vm_finalize_vcpus(vm);
+
+ vcpu_device_attr_set(running_vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_IRQ, &irq);
+ vcpu_device_attr_set(running_vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_INIT, NULL);
+ run_vcpu(running_vcpu);
+
+ ret = __vcpu_device_attr_set(stopped_vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS,
+ &nr_counters);
+ TEST_ASSERT(ret == -1 && errno == EBUSY,
+ KVM_IOCTL_ERROR(KVM_SET_DEVICE_ATTR, ret));
+
+ kvm_vm_free(vm);
+}
+
int main(void)
{
u64 i, pmcr_n;
@@ -630,6 +667,8 @@ int main(void)
TEST_REQUIRE(kvm_supports_vgic_v3());
TEST_REQUIRE(kvm_supports_nr_counters_attr());
+ test_set_nr_counters_after_vcpu_run();
+
pmcr_n = get_pmcr_n_limit();
for (i = 0; i <= pmcr_n; i++) {
run_access_test(i);
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 05/21] KVM: arm64: PMU: Mask EL2-reserved bits on guest bitmap reads
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (3 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 04/21] KVM: arm64: selftests: Test SET_NR_COUNTERS " Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 06/21] KVM: arm64: PMU: Keep implemented counter mask EL-independent Akihiko Odaki
` (15 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
MDCR_EL2.HPMN reserves event counters for EL2. Their bits in the PMU
counter-enable, interrupt-enable, and overflow-status registers must
read as zero at lower exception levels. The guest access handlers
already mask writes, but return the raw bitmap on reads, exposing
EL2-reserved state to the nested guest.
Apply the accessible counter mask to reads in all three handlers,
covering both SET and CLR aliases. Leave the stored state and userspace
migration accesses unchanged so EL2-reserved bits remain preserved.
Fixes: 9a1c58cfefb0 ("KVM: arm64: nv: Adjust range of accessible PMCs according to HPMN")
Closes: https://sashiko.dev/#/patchset/20260914-hybrid-v10-0-92788053a691@rsg.ci.i.u-tokyo.ac.jp?part=6
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
arch/arm64/kvm/sys_regs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 40927a4d4409..68339eb8a2bb 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1362,7 +1362,7 @@ static bool access_pmcnten(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
kvm_pmu_reprogram_counter_mask(vcpu, val);
} else {
- p->regval = __vcpu_sys_reg(vcpu, PMCNTENSET_EL0);
+ p->regval = __vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & mask;
}
return true;
@@ -1386,7 +1386,7 @@ static bool access_pminten(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
/* accessing PMINTENCLR_EL1 */
__vcpu_rmw_sys_reg(vcpu, PMINTENSET_EL1, &=, ~val);
} else {
- p->regval = __vcpu_sys_reg(vcpu, PMINTENSET_EL1);
+ p->regval = __vcpu_sys_reg(vcpu, PMINTENSET_EL1) & mask;
}
return true;
@@ -1466,7 +1466,7 @@ static bool access_pmovs(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
/* accessing PMOVSCLR_EL0 */
__vcpu_rmw_sys_reg(vcpu, PMOVSSET_EL0, &=, ~(p->regval & mask));
} else {
- p->regval = __vcpu_sys_reg(vcpu, PMOVSSET_EL0);
+ p->regval = __vcpu_sys_reg(vcpu, PMOVSSET_EL0) & mask;
}
return true;
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 06/21] KVM: arm64: PMU: Keep implemented counter mask EL-independent
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (4 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 05/21] KVM: arm64: PMU: Mask EL2-reserved bits on guest bitmap reads Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 07/21] KVM: arm64: PMU: Preserve EL2 bitmap state during migration Akihiko Odaki
` (14 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
kvm_pmu_implemented_counter_mask() derives the counter count from
kvm_vcpu_read_pmcr(). For a nested vCPU outside EL2, PMCR_EL0.N reflects
MDCR_EL2.HPMN instead of the VM-wide counter count.
Consequently, processing a PMU reload while the saved context is L2 can
clear and fail to recreate state for counters reserved for EL2.
Build the implemented counter mask from nr_pmu_counters instead. Keep
the EL-dependent HPMN restriction in
kvm_pmu_accessible_counter_mask(), where it controls guest access.
Fixes: 600f6fa5c90c ("KVM: arm64: Let kvm_vcpu_read_pmcr() return an EL-dependent value for PMCR_EL0.N")
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 950b7a349659..a5ccb6ae44d5 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -317,12 +317,12 @@ u64 kvm_pmu_accessible_counter_mask(struct kvm_vcpu *vcpu)
u64 kvm_pmu_implemented_counter_mask(struct kvm_vcpu *vcpu)
{
- u64 val = FIELD_GET(ARMV8_PMU_PMCR_N, kvm_vcpu_read_pmcr(vcpu));
+ u64 n = vcpu->kvm->arch.nr_pmu_counters;
- if (val == 0)
+ if (n == 0)
return BIT(ARMV8_PMU_CYCLE_IDX);
else
- return GENMASK(val - 1, 0) | BIT(ARMV8_PMU_CYCLE_IDX);
+ return GENMASK(n - 1, 0) | BIT(ARMV8_PMU_CYCLE_IDX);
}
static void kvm_pmc_enable_perf_event(struct kvm_pmc *pmc)
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 07/21] KVM: arm64: PMU: Preserve EL2 bitmap state during migration
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (5 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 06/21] KVM: arm64: PMU: Keep implemented counter mask EL-independent Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 08/21] Revert "KVM: arm64: PMU: Reload when resetting" Akihiko Odaki
` (13 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
KVM_GET_ONE_REG and KVM_SET_ONE_REG transfer raw vCPU state for
migration. Masking PMU bitmap registers with counters accessible at the
current EL drops EL2-reserved bits when the vCPU is stopped in EL1 or
EL0.
Use the implemented counter mask for these userspace accesses so the
complete bitmap state survives migration. Guest register accesses
continue to use the accessible counter mask.
Assisted-by: Codex:gpt-5.6-sol
Fixes: 9a1c58cfefb0 ("KVM: arm64: nv: Adjust range of accessible PMCs according to HPMN")
Closes: https://sashiko.dev/#/patchset/20260720-hybrid-v9-0-2b713ca1b5dc@rsg.ci.i.u-tokyo.ac.jp?part=5
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
arch/arm64/kvm/sys_regs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 68339eb8a2bb..1481dd5c99a8 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1326,7 +1326,7 @@ static bool access_pmu_evtyper(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
static int set_pmreg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, u64 val)
{
- u64 mask = kvm_pmu_accessible_counter_mask(vcpu);
+ u64 mask = kvm_pmu_implemented_counter_mask(vcpu);
__vcpu_assign_sys_reg(vcpu, r->reg, val & mask);
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
@@ -1336,7 +1336,7 @@ static int set_pmreg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, u64 va
static int get_pmreg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, u64 *val)
{
- u64 mask = kvm_pmu_accessible_counter_mask(vcpu);
+ u64 mask = kvm_pmu_implemented_counter_mask(vcpu);
*val = __vcpu_sys_reg(vcpu, r->reg) & mask;
return 0;
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 08/21] Revert "KVM: arm64: PMU: Reload when resetting"
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (6 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 07/21] KVM: arm64: PMU: Preserve EL2 bitmap state during migration Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-22 6:43 ` Oliver Upton
2026-09-20 11:15 ` [PATCH v11 09/21] KVM: arm64: PMU: Recreate events after MDCR_EL2 changes Akihiko Odaki
` (12 subsequent siblings)
20 siblings, 1 reply; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
This reverts commit fe53538069bb4f625bc8734103ba044a83138fea.
Restore PMU event teardown before system-register reset so existing
perf events cannot retain configuration from the previous run. All
counters are disabled by the reset PMCR_EL0 and MDCR_EL2 values, so
reset does not need to request a PMU reload.
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
arch/arm64/kvm/pmu-emul.c | 14 ++++++++++++++
arch/arm64/kvm/reset.c | 3 +++
arch/arm64/kvm/sys_regs.c | 3 ---
include/kvm/arm_pmu.h | 2 ++
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index a5ccb6ae44d5..14fcdbdb4587 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -258,6 +258,20 @@ void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu)
pmu->pmc[i].idx = i;
}
+/**
+ * kvm_pmu_vcpu_reset - reset pmu state for cpu
+ * @vcpu: The vcpu pointer
+ *
+ */
+void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu)
+{
+ unsigned long mask = kvm_pmu_implemented_counter_mask(vcpu);
+ int i;
+
+ for_each_set_bit(i, &mask, 32)
+ kvm_pmu_stop_counter(kvm_vcpu_idx_to_pmc(vcpu, i));
+}
+
/**
* kvm_pmu_vcpu_destroy - free perf event of PMU for cpu
* @vcpu: The vcpu pointer
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 10eb7249aa9e..adcb460a5287 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -185,6 +185,9 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
vcpu->arch.reset_state.reset = false;
spin_unlock(&vcpu->arch.mp_state_lock);
+ /* Reset PMU outside of the non-preemptible section */
+ kvm_pmu_vcpu_reset(vcpu);
+
preempt_disable();
loaded = (vcpu->cpu != -1);
if (loaded)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 1481dd5c99a8..75624725adf1 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -5388,9 +5388,6 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)
}
set_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags);
-
- if (kvm_vcpu_has_pmu(vcpu))
- kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
}
/**
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 6b4a118d17ca..51f5e4ca3326 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -48,6 +48,7 @@ u64 kvm_pmu_implemented_counter_mask(struct kvm_vcpu *vcpu);
u64 kvm_pmu_accessible_counter_mask(struct kvm_vcpu *vcpu);
u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1);
void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu);
+void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu);
void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu);
void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val);
void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu);
@@ -125,6 +126,7 @@ static inline u64 kvm_pmu_accessible_counter_mask(struct kvm_vcpu *vcpu)
return 0;
}
static inline void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) {}
+static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {}
static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {}
static inline void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val) {}
static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {}
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 09/21] KVM: arm64: PMU: Recreate events after MDCR_EL2 changes
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (7 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 08/21] Revert "KVM: arm64: PMU: Reload when resetting" Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-22 6:54 ` Oliver Upton
2026-09-20 11:15 ` [PATCH v11 10/21] KVM: arm64: PMU: Recreate events after PMCR_EL0 changes Akihiko Odaki
` (11 subsequent siblings)
20 siblings, 1 reply; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
MDCR_EL2.HPMN changes which counters are reserved for EL2 and thus which
enable control, event filter, and overflow width apply. HPMD changes EL2
filtering, while HLP changes the overflow width and sample period.
The existing guest MDCR_EL2 handling only requests a PMU reload for
HPME. Reloading enables or disables existing perf events, but does not
rebuild events whose attributes have become stale. Generic userspace
writes through KVM_SET_ONE_REG do not request a reload at all.
Add a deferred event-recreation request that stops existing events
before reprogramming counters on the vCPU thread.
Use a common helper for guest and userspace writes. Recreate events
after HPMN, HPMD, or HLP changes. This preserves counter values. Defer
event creation to the vCPU thread instead of an arbitrary ioctl thread.
Use a setter-only accessor so register restore gains these side effects
without changing generic reads or rejecting register values.
Fixes: fe827f916662 ("KVM: arm64: nv: Honor MDCR_EL2.HPME")
Fixes: 8a34979030f6 ("KVM: arm64: nv: Apply EL2 event filtering when in hyp context")
Fixes: 16535d55e91f ("KVM: arm64: nv: Honor MDCR_EL2.HLP")
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 29 +++++++++++++++++++++++++++++
arch/arm64/kvm/sys_regs.c | 22 ++++++++++++++--------
include/kvm/arm_pmu.h | 5 +++++
3 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 14fcdbdb4587..a8449e533070 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -585,6 +585,12 @@ void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val)
kvm_pmu_counter_increment(vcpu, val, ARMV8_PMUV3_PERFCTR_SW_INCR);
}
+void kvm_pmu_request_recreate(struct kvm_vcpu *vcpu)
+{
+ vcpu->arch.pmu.events_need_recreate = true;
+ kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
+}
+
/**
* kvm_pmu_handle_pmcr - handle PMCR register
* @vcpu: The vcpu pointer
@@ -620,6 +626,20 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
}
}
+void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val)
+{
+ u64 changed = old ^ val;
+
+ /*
+ * HPMN determines which counters HPMD and HLP apply to. Changes to
+ * these fields require new perf event filters and sample periods.
+ */
+ if (changed & (MDCR_EL2_HPMN | MDCR_EL2_HPMD | MDCR_EL2_HLP))
+ kvm_pmu_request_recreate(vcpu);
+ else if (changed & MDCR_EL2_HPME)
+ kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
+}
+
static bool kvm_pmu_counter_is_enabled(struct kvm_pmc *pmc)
{
struct kvm_vcpu *vcpu = kvm_pmc_to_vcpu(pmc);
@@ -914,7 +934,16 @@ u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
void kvm_vcpu_reload_pmu(struct kvm_vcpu *vcpu)
{
+ struct kvm_pmu *pmu = &vcpu->arch.pmu;
u64 mask = kvm_pmu_implemented_counter_mask(vcpu);
+ int i;
+
+ if (pmu->events_need_recreate) {
+ for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++)
+ kvm_pmu_stop_counter(kvm_vcpu_idx_to_pmc(vcpu, i));
+
+ pmu->events_need_recreate = false;
+ }
__vcpu_rmw_sys_reg(vcpu, PMOVSSET_EL0, &=, mask);
__vcpu_rmw_sys_reg(vcpu, PMINTENSET_EL1, &=, mask);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 75624725adf1..7dd2cafce247 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -3114,17 +3114,22 @@ static bool access_mdcr(struct kvm_vcpu *vcpu,
}
__vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
-
- /*
- * Request a reload of the PMU to enable/disable the counters
- * affected by HPME.
- */
- if ((old ^ val) & MDCR_EL2_HPME)
- kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
+ kvm_pmu_apply_mdcr(vcpu, old, val);
return true;
}
+static int set_mdcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
+ u64 val)
+{
+ u64 old = __vcpu_sys_reg(vcpu, MDCR_EL2);
+
+ __vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
+ kvm_pmu_apply_mdcr(vcpu, old, val);
+
+ return 0;
+}
+
static bool access_ras(struct kvm_vcpu *vcpu,
struct sys_reg_params *p,
const struct sys_reg_desc *r)
@@ -3836,7 +3841,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
EL2_REG_FILTERED(SCTLR2_EL2, access_vm_reg, reset_val, 0,
sctlr2_el2_visibility),
EL2_REG_VNCR(HCR_EL2, reset_hcr, 0),
- EL2_REG(MDCR_EL2, access_mdcr, reset_mdcr, 0),
+ SYS_REG_USER_FILTER(MDCR_EL2, access_mdcr, reset_mdcr, 0,
+ NULL, set_mdcr, el2_visibility),
EL2_REG(CPTR_EL2, access_rw, reset_val, CPTR_NVHE_EL2_RES1),
EL2_REG_VNCR(HSTR_EL2, reset_val, 0),
EL2_REG_VNCR_FILT(HFGRTR_EL2, fgt_visibility),
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 51f5e4ca3326..2fe73ad50e4e 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -32,6 +32,7 @@ struct kvm_pmu {
struct kvm_pmc pmc[KVM_ARMV8_PMU_MAX_COUNTERS];
int irq_num;
bool created;
+ bool events_need_recreate;
};
struct arm_pmu_entry {
@@ -56,7 +57,9 @@ void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu);
bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu);
bool kvm_pmu_update_run(struct kvm_vcpu *vcpu);
void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val);
+void kvm_pmu_request_recreate(struct kvm_vcpu *vcpu);
void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val);
+void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val);
void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
u64 select_idx);
void kvm_vcpu_reload_pmu(struct kvm_vcpu *vcpu);
@@ -137,7 +140,9 @@ static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
}
static inline bool kvm_pmu_update_run(struct kvm_vcpu *vcpu) { return false; }
static inline void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val) {}
+static inline void kvm_pmu_request_recreate(struct kvm_vcpu *vcpu) {}
static inline void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) {}
+static inline void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val) {}
static inline void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu,
u64 data, u64 select_idx) {}
static inline int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu,
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 10/21] KVM: arm64: PMU: Recreate events after PMCR_EL0 changes
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (8 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 09/21] KVM: arm64: PMU: Recreate events after MDCR_EL2 changes Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 11/21] KVM: arm64: PMU: Recreate events after userspace event writes Akihiko Odaki
` (10 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
PMCR_EL0.LC and PMCR_EL0.LP control whether cycle and event counters
overflow at 32 or 64 bits. They therefore determine the sample period
of each backing perf event.
Guest and userspace writes do not recreate existing events. Changing
either bit after an event has been created leaves its old sample period
in place, resulting in an incorrect overflow point.
Request event recreation when either bit changes. Preserve the existing
reload behavior for PMCR_EL0.E and other userspace writes.
Fixes: c82d28cbf1d4 ("KVM: arm64: PMU: Distinguish between 64bit counter and 64bit overflow")
Fixes: 11af4c37165e ("KVM: arm64: PMU: Implement PMUv3p5 long counter support")
Closes: https://sashiko.dev/#/patchset/20260720-hybrid-v9-0-2b713ca1b5dc@rsg.ci.i.u-tokyo.ac.jp?part=6
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
arch/arm64/kvm/pmu-emul.c | 18 ++++++++++++++----
arch/arm64/kvm/sys_regs.c | 3 ++-
include/kvm/arm_pmu.h | 2 ++
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index a8449e533070..86a02fd4cfb8 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -591,6 +591,17 @@ void kvm_pmu_request_recreate(struct kvm_vcpu *vcpu)
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
}
+void kvm_pmu_apply_pmcr(struct kvm_vcpu *vcpu, u64 old, u64 val, bool force_reload)
+{
+ u64 changed = old ^ val;
+
+ /* Reload the PMU if the write affects the backing perf events. */
+ if (changed & (ARMV8_PMU_PMCR_LC | ARMV8_PMU_PMCR_LP))
+ kvm_pmu_request_recreate(vcpu);
+ else if (force_reload || (changed & ARMV8_PMU_PMCR_E))
+ kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
+}
+
/**
* kvm_pmu_handle_pmcr - handle PMCR register
* @vcpu: The vcpu pointer
@@ -598,19 +609,18 @@ void kvm_pmu_request_recreate(struct kvm_vcpu *vcpu)
*/
void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
{
+ u64 old = __vcpu_sys_reg(vcpu, PMCR_EL0);
int i;
/* Fixup PMCR_EL0 to reconcile the PMU version and the LP bit */
if (!kvm_has_feat(vcpu->kvm, ID_AA64DFR0_EL1, PMUVer, V3P5))
val &= ~ARMV8_PMU_PMCR_LP;
- /* Request a reload of the PMU to enable/disable affected counters */
- if ((__vcpu_sys_reg(vcpu, PMCR_EL0) ^ val) & ARMV8_PMU_PMCR_E)
- kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
-
/* The reset bits don't indicate any state, and shouldn't be saved. */
__vcpu_assign_sys_reg(vcpu, PMCR_EL0, (val & ~(ARMV8_PMU_PMCR_C | ARMV8_PMU_PMCR_P)));
+ kvm_pmu_apply_pmcr(vcpu, old, __vcpu_sys_reg(vcpu, PMCR_EL0), false);
+
if (val & ARMV8_PMU_PMCR_C)
kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 7dd2cafce247..6786311e9b7d 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1517,6 +1517,7 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,
{
u8 new_n = FIELD_GET(ARMV8_PMU_PMCR_N, val);
struct kvm *kvm = vcpu->kvm;
+ u64 old = __vcpu_sys_reg(vcpu, r->reg);
mutex_lock(&kvm->arch.config_lock);
@@ -1549,7 +1550,7 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,
val |= ARMV8_PMU_PMCR_LC;
__vcpu_assign_sys_reg(vcpu, r->reg, val);
- kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
+ kvm_pmu_apply_pmcr(vcpu, old, val, true);
return 0;
}
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 2fe73ad50e4e..fca00f7f4c0a 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -58,6 +58,7 @@ bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu);
bool kvm_pmu_update_run(struct kvm_vcpu *vcpu);
void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val);
void kvm_pmu_request_recreate(struct kvm_vcpu *vcpu);
+void kvm_pmu_apply_pmcr(struct kvm_vcpu *vcpu, u64 old, u64 val, bool force_reload);
void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val);
void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val);
void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
@@ -141,6 +142,7 @@ static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
static inline bool kvm_pmu_update_run(struct kvm_vcpu *vcpu) { return false; }
static inline void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val) {}
static inline void kvm_pmu_request_recreate(struct kvm_vcpu *vcpu) {}
+static inline void kvm_pmu_apply_pmcr(struct kvm_vcpu *vcpu, u64 old, u64 val, bool force_reload) {}
static inline void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) {}
static inline void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val) {}
static inline void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu,
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 11/21] KVM: arm64: PMU: Recreate events after userspace event writes
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (9 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 10/21] KVM: arm64: PMU: Recreate events after PMCR_EL0 changes Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 12/21] tools headers: Use u* types for bitfield helpers Akihiko Odaki
` (9 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
KVM_SET_ONE_REG writes to PMEVTYPERn_EL0 and PMCCFILTR_EL0 use the
generic raw system register assignment. If a backing perf event already
exists, it keeps its old event selection and privilege filters.
Add a setter that preserves the raw userspace register value and
requests deferred event recreation. This rebuilds the event on the vCPU
thread without changing values returned by KVM_GET_ONE_REG or applying
guest-write masking.
Fixes: 9feb21ac57d5 ("arm64: KVM: Add access handler for event type register")
Closes: https://sashiko.dev/#/patchset/20260720-hybrid-v9-0-2b713ca1b5dc@rsg.ci.i.u-tokyo.ac.jp?part=6
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
arch/arm64/kvm/sys_regs.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 6786311e9b7d..5a44bd5530ff 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1334,6 +1334,15 @@ static int set_pmreg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, u64 va
return 0;
}
+static int set_pmu_evtyper(struct kvm_vcpu *vcpu,
+ const struct sys_reg_desc *r, u64 val)
+{
+ __vcpu_assign_sys_reg(vcpu, r->reg, val);
+ kvm_pmu_request_recreate(vcpu);
+
+ return 0;
+}
+
static int get_pmreg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, u64 *val)
{
u64 mask = kvm_pmu_implemented_counter_mask(vcpu);
@@ -1584,7 +1593,7 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,
/* Macro to expand the PMEVTYPERn_EL0 register */
#define PMU_PMEVTYPER_EL0(n) \
{ PMU_SYS_REG(PMEVTYPERn_EL0(n)), \
- .reset = reset_pmevtyper, \
+ .reset = reset_pmevtyper, .set_user = set_pmu_evtyper, \
.access = access_pmu_evtyper, .reg = (PMEVTYPER0_EL0 + n), }
/* Macro to expand the AMU counter and type registers*/
@@ -3833,7 +3842,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
* in 32bit mode. Here we choose to reset it as zero for consistency.
*/
{ PMU_SYS_REG(PMCCFILTR_EL0), .access = access_pmu_evtyper,
- .reset = reset_val, .reg = PMCCFILTR_EL0, .val = 0 },
+ .reset = reset_val, .reg = PMCCFILTR_EL0, .val = 0,
+ .set_user = set_pmu_evtyper },
EL2_REG_VNCR(VPIDR_EL2, reset_unknown, 0),
EL2_REG_VNCR(VMPIDR_EL2, reset_unknown, 0),
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 12/21] tools headers: Use u* types for bitfield helpers
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (10 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 11/21] KVM: arm64: PMU: Recreate events after userspace event writes Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 13/21] KVM: arm64: selftests: Cover PMU state in MDCR_EL2 Akihiko Odaki
` (8 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Commit 9486aa387716 ("perf tools: Fix 64 bit integer format strings")
defined the tools-local u64 as uint64_t so that PRI*64 format macros
match its underlying C type. On architectures where uint64_t and __u64
are distinct types, however, ____MAKE_OP() still gives the u64_*
helpers an __u64 interface.
Teach ____MAKE_OP() to accept the helper name and storage type
separately. Keep endian helpers on __le* and __be*, and generate the
native helpers using the tools-local u* types.
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
tools/include/linux/bitfield.h | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/tools/include/linux/bitfield.h b/tools/include/linux/bitfield.h
index ddf81f24956b..1c633343d576 100644
--- a/tools/include/linux/bitfield.h
+++ b/tools/include/linux/bitfield.h
@@ -142,32 +142,32 @@ static __always_inline u64 field_mask(u64 field)
return field / field_multiplier(field);
}
#define field_max(field) ((typeof(field))field_mask(field))
-#define ____MAKE_OP(type,base,to,from) \
-static __always_inline __##type type##_encode_bits(base v, base field) \
+#define ____MAKE_OP(name,type,base,to,from) \
+static __always_inline type name##_encode_bits(base v, base field) \
{ \
if (__builtin_constant_p(v) && (v & ~field_mask(field))) \
__field_overflow(); \
return to((v & field_mask(field)) * field_multiplier(field)); \
} \
-static __always_inline __##type type##_replace_bits(__##type old, \
- base val, base field) \
+static __always_inline type name##_replace_bits(type old, \
+ base val, base field) \
{ \
- return (old & ~to(field)) | type##_encode_bits(val, field); \
+ return (old & ~to(field)) | name##_encode_bits(val, field); \
} \
-static __always_inline void type##p_replace_bits(__##type *p, \
+static __always_inline void name##p_replace_bits(type *p, \
base val, base field) \
{ \
- *p = (*p & ~to(field)) | type##_encode_bits(val, field); \
+ *p = (*p & ~to(field)) | name##_encode_bits(val, field); \
} \
-static __always_inline base type##_get_bits(__##type v, base field) \
+static __always_inline base name##_get_bits(type v, base field) \
{ \
return (from(v) & field)/field_multiplier(field); \
}
-#define __MAKE_OP(size) \
- ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \
- ____MAKE_OP(be##size,u##size,cpu_to_be##size,be##size##_to_cpu) \
- ____MAKE_OP(u##size,u##size,,)
-____MAKE_OP(u8,u8,,)
+#define __MAKE_OP(size) \
+ ____MAKE_OP(le##size,__le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \
+ ____MAKE_OP(be##size,__be##size,u##size,cpu_to_be##size,be##size##_to_cpu) \
+ ____MAKE_OP(u##size,u##size,u##size,,)
+____MAKE_OP(u8,u8,u8,,)
__MAKE_OP(16)
__MAKE_OP(32)
__MAKE_OP(64)
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 13/21] KVM: arm64: selftests: Cover PMU state in MDCR_EL2
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (11 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 12/21] tools headers: Use u* types for bitfield helpers Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 14/21] arm64: errata: Require Apple IMPDEF PMUv3 traps on all CPUs Akihiko Odaki
` (7 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Add MDCR_EL2 coverage to vpmu_counter_access when EL2 is available.
For each configured PMCR_EL0.N value, verify that an arbitrary HPMN
value, including one above the configured counter count, round-trips
through KVM_SET_ONE_REG and survives SET_NR_COUNTERS. Also verify that
HPME can be toggled without disturbing HPMN and that KVM_ARM_VCPU_INIT
resets HPMN from the configured count.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
.../selftests/kvm/arm64/vpmu_counter_access.c | 90 ++++++++++++++++++++--
1 file changed, 85 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
index 05135bcdb462..73b4f1870d3d 100644
--- a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
+++ b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
@@ -25,6 +25,14 @@
/* The cycle counter bit position that's common among the PMU registers */
#define ARMV8_PMU_CYCLE_IDX 31
+#ifndef MDCR_EL2_HPMN
+#define MDCR_EL2_HPMN GENMASK_ULL(4, 0)
+#endif
+
+#ifndef MDCR_EL2_HPME
+#define MDCR_EL2_HPME BIT_ULL(7)
+#endif
+
struct vpmu_vm {
struct kvm_vm *vm;
struct kvm_vcpu *vcpu;
@@ -465,15 +473,12 @@ static void guest_code_done(void)
GUEST_DONE();
}
-static void test_create_vpmu_vm_with_nr_counters(unsigned int nr_counters, bool expect_fail)
+static void set_nr_counters(struct kvm_vcpu *vcpu,
+ unsigned int nr_counters, bool expect_fail)
{
- struct kvm_vcpu *vcpu;
unsigned int prev;
int ret;
- create_vpmu_vm(guest_code);
- vcpu = vpmu_vm.vcpu;
-
prev = get_pmcr_n(vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0)));
ret = __vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
@@ -485,6 +490,17 @@ static void test_create_vpmu_vm_with_nr_counters(unsigned int nr_counters, bool
nr_counters, prev);
else
TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_SET_DEVICE_ATTR, ret));
+}
+
+static void test_create_vpmu_vm_with_nr_counters(unsigned int nr_counters,
+ bool expect_fail)
+{
+ struct kvm_vcpu *vcpu;
+
+ create_vpmu_vm(guest_code);
+ vcpu = vpmu_vm.vcpu;
+
+ set_nr_counters(vcpu, nr_counters, expect_fail);
vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL, KVM_ARM_VCPU_PMU_V3_INIT, NULL);
}
@@ -589,6 +605,69 @@ static void run_pmregs_validity_test(u64 pmcr_n)
destroy_vpmu_vm();
}
+static void run_mdcr_el2_validity_test(u64 pmcr_n)
+{
+ struct kvm_vcpu_init init;
+ struct kvm_vcpu *vcpu;
+ u64 expected_mdcr, mdcr;
+
+ pr_debug("MDCR_EL2 test with pmcr_n %lu\n", pmcr_n);
+
+ create_vpmu_vm(guest_code);
+ if (!vm_supports_el2(vpmu_vm.vm)) {
+ destroy_vpmu_vm();
+ return;
+ }
+
+ vcpu = vpmu_vm.vcpu;
+
+ mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
+ expected_mdcr = u64_replace_bits(mdcr, FIELD_MAX(MDCR_EL2_HPMN),
+ MDCR_EL2_HPMN);
+ vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2),
+ expected_mdcr);
+
+ mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
+ TEST_ASSERT(mdcr == expected_mdcr,
+ "MDCR_EL2 was not properly updated after HPMN write (expected 0x%lx, got 0x%lx)",
+ expected_mdcr, mdcr);
+
+ set_nr_counters(vcpu, pmcr_n, false);
+
+ mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
+ TEST_ASSERT(mdcr == expected_mdcr,
+ "MDCR_EL2 changed after PMU_V3_SET_NR_COUNTERS (expected 0x%lx, got 0x%lx)",
+ expected_mdcr, mdcr);
+
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_INIT, NULL);
+
+ mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
+ TEST_ASSERT(mdcr == expected_mdcr,
+ "MDCR_EL2 changed after PMU_V3_INIT (expected 0x%lx, got 0x%lx)",
+ expected_mdcr, mdcr);
+
+ expected_mdcr = mdcr ^ MDCR_EL2_HPME;
+ vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2),
+ expected_mdcr);
+
+ mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
+ TEST_ASSERT(mdcr == expected_mdcr,
+ "MDCR_EL2 was not properly updated after HPME write (expected 0x%lx, got 0x%lx)",
+ expected_mdcr, mdcr);
+
+ kvm_get_default_vcpu_target(vpmu_vm.vm, &init);
+ init.features[0] |= (1 << KVM_ARM_VCPU_PMU_V3);
+ aarch64_vcpu_setup(vcpu, &init);
+
+ mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
+ TEST_ASSERT(FIELD_GET(MDCR_EL2_HPMN, mdcr) == pmcr_n,
+ "MDCR_EL2.HPMN is not reset after INIT (expected %lu, got %lu)",
+ pmcr_n, FIELD_GET(MDCR_EL2_HPMN, mdcr));
+
+ destroy_vpmu_vm();
+}
+
/*
* Create a guest with one vCPU, and attempt to set the PMCR_EL0.N for
* the vCPU to @pmcr_n, which is larger than the host value.
@@ -673,6 +752,7 @@ int main(void)
for (i = 0; i <= pmcr_n; i++) {
run_access_test(i);
run_pmregs_validity_test(i);
+ run_mdcr_el2_validity_test(i);
}
for (i = pmcr_n + 1; i < ARMV8_PMU_MAX_COUNTERS; i++)
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 14/21] arm64: errata: Require Apple IMPDEF PMUv3 traps on all CPUs
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (12 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 13/21] KVM: arm64: selftests: Cover PMU state in MDCR_EL2 Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 15/21] KVM: arm64: Don't clear vcpu->cpu in kvm_arch_vcpu_put() Akihiko Odaki
` (6 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
KVM relies on ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS as a system-wide
precondition for PMUv3 emulation on affected Apple CPUs. A local CPU
erratum is too weak for that: once the workaround is enabled, a late CPU
that misses it may still be onlined.
Make the workaround an all-early-CPU capability instead. The matcher is
still local because it depends on MIDR_EL1, but the capability is only
advertised if all early CPUs match. A late CPU that misses an advertised
capability is therefore rejected.
Although kept in the errata capability table, this capability describes
optional trap support, not a workaround required for safe CPU operation.
Therefore, a late CPU can safely match the capability even when the
system does not advertise it.
On these CPUs, ID_AA64DFR0_EL1.PMUVer == 0xf means the
Arm-architected PMUv3 is not implemented. Without the system
capability, KVM does not advertise PMUv3, and direct accesses to
architected PMUv3 registers remain UNDEFINED. HACR_EL2[56] only makes
those accesses trap to EL2 so KVM can emulate PMUv3; leaving it clear
does not make them access Apple's native PMU.
The native Apple PMU uses separate implementation-defined system
register encodings, which KVM independently traps with
HCR_EL2.TIDCP. Allowing a late CPU with extra HACR_EL2 trap support
therefore does not expose host PMU state to a guest.
Fixes: bed9b8ec8c71 ("KVM: arm64: Advertise PMUv3 if IMPDEF traps are present")
Assisted-by: Codex:gpt-5.5
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kernel/cpu_errata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index b33dccfafaf8..3dc598a9fdd2 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -1020,7 +1020,7 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
{
.desc = "Apple IMPDEF PMUv3 Traps",
.capability = ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS,
- .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
+ .type = ARM64_CPUCAP_EARLY_LOCAL_CPU_FEATURE,
.matches = has_impdef_pmuv3,
.cpu_enable = cpu_enable_impdef_pmuv3_traps,
},
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 15/21] KVM: arm64: Don't clear vcpu->cpu in kvm_arch_vcpu_put()
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (13 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 14/21] arm64: errata: Require Apple IMPDEF PMUv3 traps on all CPUs Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 16/21] KVM: arm64: PMU: Protect the list of PMUs with RCU Akihiko Odaki
` (5 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
From: Oliver Upton <oupton@kernel.org>
commit e9b152cb957c ("arm/arm64: kvm: Set vcpu->cpu to -1 on vcpu_put")
reset vcpu->cpu in order for the VGIC to determine if there was any vCPU
running at the time of access. The VGIC has gone through an entire
rewrite since then, and with commit 7d450e282171 ("KVM: arm/arm64:
vgic-new: Add userland access to VGIC dist registers") the user
accessors just grab all vCPU mutexes instead.
Drop this remaining vestige such that kvm_arch_vcpu_load() can properly
detect a CPU migration. While at it, rework kvm_reset_vcpu() to do a
much more pedantic check that the provided vCPU is actually what's
running on the present CPU.
Signed-off-by: Oliver Upton <oupton@kernel.org>
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/arm.c | 1 -
arch/arm64/kvm/reset.c | 16 +++++++++++-----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 997f24f5fb91..55b07926ce2e 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -767,7 +767,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
kvm_arm_vmid_clear_active();
vcpu_clear_on_unsupported_cpu(vcpu);
- vcpu->cpu = -1;
}
static void __kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu)
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index adcb460a5287..db794d50fa18 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -178,7 +178,8 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)
void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
{
struct vcpu_reset_state reset_state;
- bool loaded;
+ struct kvm_vcpu *running;
+ bool loaded = false;
spin_lock(&vcpu->arch.mp_state_lock);
reset_state = vcpu->arch.reset_state;
@@ -188,10 +189,16 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
/* Reset PMU outside of the non-preemptible section */
kvm_pmu_vcpu_reset(vcpu);
- preempt_disable();
- loaded = (vcpu->cpu != -1);
- if (loaded)
+ guard(preempt)();
+
+ running = kvm_get_running_vcpu();
+ if (running) {
+ if (KVM_BUG_ON(running != vcpu, vcpu->kvm))
+ return;
+
+ loaded = true;
kvm_arch_vcpu_put(vcpu);
+ }
if (!kvm_arm_vcpu_sve_finalized(vcpu)) {
if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_SVE))
@@ -218,7 +225,6 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
if (loaded)
kvm_arch_vcpu_load(vcpu, smp_processor_id());
- preempt_enable();
}
u32 kvm_get_pa_bits(struct kvm *kvm)
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 16/21] KVM: arm64: PMU: Protect the list of PMUs with RCU
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (14 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 15/21] KVM: arm64: Don't clear vcpu->cpu in kvm_arch_vcpu_put() Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 17/21] KVM: arm64: PMU: Pass the pPMU to kvm_map_pmu_event() Akihiko Odaki
` (4 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Convert the list of PMUs to a RCU-protected list that has primitives to
avoid read-side contention.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 86a02fd4cfb8..335d712cc9c5 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -7,9 +7,9 @@
#include <linux/cpu.h>
#include <linux/kvm.h>
#include <linux/kvm_host.h>
-#include <linux/list.h>
#include <linux/perf_event.h>
#include <linux/perf/arm_pmu.h>
+#include <linux/rculist.h>
#include <linux/uaccess.h>
#include <asm/kvm_emulate.h>
#include <kvm/arm_pmu.h>
@@ -17,6 +17,10 @@
#define PERF_ATTR_CFG1_COUNTER_64BIT BIT(0)
+/*
+ * arm_pmus is append-only. kvm_supports_guest_pmuv3() feeds persistent
+ * VM state, so a true result must remain valid after the check.
+ */
static LIST_HEAD(arm_pmus);
static DEFINE_MUTEX(arm_pmus_lock);
@@ -26,7 +30,6 @@ static bool kvm_pmu_counter_is_enabled(struct kvm_pmc *pmc);
bool kvm_supports_guest_pmuv3(void)
{
- guard(mutex)(&arm_pmus_lock);
return !list_empty(&arm_pmus);
}
@@ -833,7 +836,7 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
return;
entry->arm_pmu = pmu;
- list_add_tail(&entry->entry, &arm_pmus);
+ list_add_tail_rcu(&entry->entry, &arm_pmus);
}
static struct arm_pmu *kvm_pmu_probe_armpmu(void)
@@ -842,7 +845,7 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void)
struct arm_pmu *pmu;
int cpu;
- guard(mutex)(&arm_pmus_lock);
+ guard(rcu)();
/*
* It is safe to use a stale cpu to iterate the list of PMUs so long as
@@ -862,7 +865,7 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void)
* carried here.
*/
cpu = raw_smp_processor_id();
- list_for_each_entry(entry, &arm_pmus, entry) {
+ list_for_each_entry_rcu(entry, &arm_pmus, entry) {
pmu = entry->arm_pmu;
if (cpumask_test_cpu(cpu, &pmu->supported_cpus))
@@ -1128,9 +1131,9 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
int ret = -ENXIO;
lockdep_assert_held(&kvm->arch.config_lock);
- mutex_lock(&arm_pmus_lock);
+ guard(rcu)();
- list_for_each_entry(entry, &arm_pmus, entry) {
+ list_for_each_entry_rcu(entry, &arm_pmus, entry) {
arm_pmu = entry->arm_pmu;
if (arm_pmu->pmu.type == pmu_id) {
if (kvm_vm_has_ran_once(kvm) ||
@@ -1157,7 +1160,6 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
}
}
- mutex_unlock(&arm_pmus_lock);
return ret;
}
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 17/21] KVM: arm64: PMU: Pass the pPMU to kvm_map_pmu_event()
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (15 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 16/21] KVM: arm64: PMU: Protect the list of PMUs with RCU Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 18/21] KVM: arm64: PMU: Pass the target CPU to kvm_pmu_probe_armpmu() Akihiko Odaki
` (3 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Replace the VM argument with the pPMU used for event creation. The
current caller still passes the VM's default pPMU, but this removes the
implicit lookup from kvm_map_pmu_event() so later changes can map events
against the pPMU selected for an individual vCPU.
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 335d712cc9c5..72b042e5c360 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -696,10 +696,8 @@ static bool kvm_pmc_counts_at_el2(struct kvm_pmc *pmc)
return kvm_pmc_read_evtreg(pmc) & ARMV8_PMU_INCLUDE_EL2;
}
-static int kvm_map_pmu_event(struct kvm *kvm, unsigned int eventsel)
+static int kvm_map_pmu_event(struct arm_pmu *pmu, unsigned int eventsel)
{
- struct arm_pmu *pmu = kvm->arch.arm_pmu;
-
/*
* The CPU PMU likely isn't PMUv3; let the driver provide a mapping
* for the guest's PMUv3 event ID.
@@ -751,7 +749,7 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
* Don't create an event if we're running on hardware that requires
* PMUv3 event translation and we couldn't find a valid mapping.
*/
- eventsel = kvm_map_pmu_event(vcpu->kvm, eventsel);
+ eventsel = kvm_map_pmu_event(vcpu->kvm->arch.arm_pmu, eventsel);
if (eventsel < 0)
return;
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 18/21] KVM: arm64: PMU: Pass the target CPU to kvm_pmu_probe_armpmu()
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (16 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 17/21] KVM: arm64: PMU: Pass the pPMU to kvm_map_pmu_event() Akihiko Odaki
@ 2026-09-20 11:15 ` Akihiko Odaki
2026-09-20 11:16 ` [PATCH v11 19/21] KVM: arm64: PMU: Implement fixed-counters-only emulation Akihiko Odaki
` (2 subsequent siblings)
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:15 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
kvm_pmu_probe_armpmu() currently samples the current CPU internally,
which ties the helper to default PMU selection.
Move that policy to kvm_arm_set_default_pmu() by passing
raw_smp_processor_id() from the caller, and make the helper search for
the pPMU covering an explicit CPU. Move the helper above
kvm_pmu_create_perf_event() so later code can reuse it when creating
PMU events for a VCPU's current pCPU.
This preserves the existing default PMU selection behavior while
preparing fixed-counters-only mode to select a pPMU at runtime.
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 72 +++++++++++++++++++++++------------------------
1 file changed, 35 insertions(+), 37 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 72b042e5c360..a303752c5e61 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -708,6 +708,23 @@ static int kvm_map_pmu_event(struct arm_pmu *pmu, unsigned int eventsel)
return eventsel;
}
+static struct arm_pmu *kvm_pmu_probe_armpmu(int cpu)
+{
+ struct arm_pmu_entry *entry;
+ struct arm_pmu *pmu;
+
+ guard(rcu)();
+
+ list_for_each_entry_rcu(entry, &arm_pmus, entry) {
+ pmu = entry->arm_pmu;
+
+ if (cpumask_test_cpu(cpu, &pmu->supported_cpus))
+ return pmu;
+ }
+
+ return NULL;
+}
+
/**
* kvm_pmu_create_perf_event - create a perf event for a counter
* @pmc: Counter context
@@ -837,42 +854,6 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
list_add_tail_rcu(&entry->entry, &arm_pmus);
}
-static struct arm_pmu *kvm_pmu_probe_armpmu(void)
-{
- struct arm_pmu_entry *entry;
- struct arm_pmu *pmu;
- int cpu;
-
- guard(rcu)();
-
- /*
- * It is safe to use a stale cpu to iterate the list of PMUs so long as
- * the same value is used for the entirety of the loop. Given this, and
- * the fact that no percpu data is used for the lookup there is no need
- * to disable preemption.
- *
- * It is still necessary to get a valid cpu, though, to probe for the
- * default PMU instance as userspace is not required to specify a PMU
- * type. In order to uphold the preexisting behavior KVM selects the
- * PMU instance for the core during vcpu init. A dependent use
- * case would be a user with disdain of all things big.LITTLE that
- * affines the VMM to a particular cluster of cores.
- *
- * In any case, userspace should just do the sane thing and use the UAPI
- * to select a PMU type directly. But, be wary of the baggage being
- * carried here.
- */
- cpu = raw_smp_processor_id();
- list_for_each_entry_rcu(entry, &arm_pmus, entry) {
- pmu = entry->arm_pmu;
-
- if (cpumask_test_cpu(cpu, &pmu->supported_cpus))
- return pmu;
- }
-
- return NULL;
-}
-
static u64 __compute_pmceid(struct arm_pmu *pmu, bool pmceid1)
{
u32 hi[2], lo[2];
@@ -1112,7 +1093,24 @@ static void kvm_arm_set_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu)
*/
int kvm_arm_set_default_pmu(struct kvm *kvm)
{
- struct arm_pmu *arm_pmu = kvm_pmu_probe_armpmu();
+ /*
+ * It is safe to use a stale cpu to iterate the list of PMUs so long as
+ * the same value is used for the entirety of the loop. Given this, and
+ * the fact that no percpu data is used for the lookup there is no need
+ * to disable preemption.
+ *
+ * It is still necessary to get a valid cpu, though, to probe for the
+ * default PMU instance as userspace is not required to specify a PMU
+ * type. In order to uphold the preexisting behavior KVM selects the
+ * PMU instance for the core during vcpu init. A dependent use
+ * case would be a user with disdain of all things big.LITTLE that
+ * affines the VMM to a particular cluster of cores.
+ *
+ * In any case, userspace should just do the sane thing and use the UAPI
+ * to select a PMU type directly. But, be wary of the baggage being
+ * carried here.
+ */
+ struct arm_pmu *arm_pmu = kvm_pmu_probe_armpmu(raw_smp_processor_id());
if (!arm_pmu)
return -ENODEV;
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 19/21] KVM: arm64: PMU: Implement fixed-counters-only emulation
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (17 preceding siblings ...)
2026-09-20 11:15 ` [PATCH v11 18/21] KVM: arm64: PMU: Pass the target CPU to kvm_pmu_probe_armpmu() Akihiko Odaki
@ 2026-09-20 11:16 ` Akihiko Odaki
2026-09-20 11:16 ` [PATCH v11 20/21] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY Akihiko Odaki
2026-09-20 11:16 ` [PATCH v11 21/21] KVM: arm64: selftests: Test PMU_V3_FIXED_COUNTERS_ONLY Akihiko Odaki
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:16 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Add internal state for PMUv3 emulation without programmable event
counters. When fixed-counters-only mode is active, KVM reports no
programmable counters and hides PMCEID, avoiding event-counter state
whose behavior can depend on the selected hardware PMU.
The cycle counter still uses a host perf event. Unlike the normal PMU
path, fixed-counters-only mode may create that event from the hardware
PMU attached to the VCPU's current pCPU. If the VCPU later loads on a
pCPU that is not covered by the existing event's PMU, request a PMU
reload so the cycle counter can be recreated against the new pCPU's PMU.
Keep this affinity check limited to fixed-counters-only VMs; the normal
programmable-counter mode continues to use the VM-wide PMU and does not
need per-load reload decisions.
Registered pPMUs must cover every CPU on which fixed-counters-only
emulation runs. On ACPI systems, a CPU brought online after PMU probing
may have an unregistered PMU implementation. Full coverage is also not
guaranteed when ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS is present.
Fixed-counters-only emulation is not supported once a vCPU runs on an
uncovered CPU. If event creation detects such a CPU, warn and add
TAINT_CPU_OUT_OF_SPEC.
Add a separate internal flag for explicit userspace PMU selection. The
UAPI wiring added later will use it to keep explicit PMU selection and
fixed-counters-only mode mutually exclusive while still allowing
fixed-counters-only mode to replace the default PMU selected during
KVM_ARM_VCPU_INIT.
The UAPI wiring that sets the fixed-counters-only flag and records
explicit PMU selection is added later in the series.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
arch/arm64/include/asm/kvm_host.h | 4 +++
arch/arm64/kvm/arm.c | 2 ++
arch/arm64/kvm/pmu-emul.c | 60 ++++++++++++++++++++++++++++++++++-----
include/kvm/arm_pmu.h | 2 ++
4 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 766c5cb32f54..d273bfc4cbaf 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -367,6 +367,10 @@ struct kvm_arch {
#define KVM_ARCH_FLAG_WRITABLE_IMP_ID_REGS 10
/* Unhandled SEAs are taken to userspace */
#define KVM_ARCH_FLAG_EXIT_SEA 11
+ /* PMUv3 is emulated with an explicitly specified hardware PMU */
+#define KVM_ARCH_FLAG_PMU_V3_EXPLICIT 12
+ /* PMUv3 is emulated without programmable event counters */
+#define KVM_ARCH_FLAG_PMU_V3_FIXED_COUNTERS_ONLY 13
unsigned long flags;
/* VM-wide vCPU feature set */
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 55b07926ce2e..4b1f06a36055 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -665,6 +665,7 @@ static bool kvm_vcpu_should_clear_twe(struct kvm_vcpu *vcpu)
void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
{
struct kvm_s2_mmu *mmu;
+ int last_cpu = vcpu->cpu;
int *last_ran;
if (is_protected_kvm_enabled())
@@ -714,6 +715,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
if (has_vhe())
kvm_vcpu_load_vhe(vcpu);
kvm_arch_vcpu_load_fp(vcpu);
+ kvm_vcpu_load_pmu(vcpu, last_cpu);
kvm_vcpu_pmu_restore_guest(vcpu);
if (kvm_arm_is_pvtime_enabled(&vcpu->arch))
kvm_make_request(KVM_REQ_RECORD_STEAL, vcpu);
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index a303752c5e61..9c1e2f3e41db 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -83,6 +83,11 @@ u64 kvm_pmu_evtyper_mask(struct kvm *kvm)
return mask;
}
+static bool kvm_pmu_fixed_counters_only(struct kvm *kvm)
+{
+ return test_bit(KVM_ARCH_FLAG_PMU_V3_FIXED_COUNTERS_ONLY, &kvm->arch.flags);
+}
+
/**
* kvm_pmc_is_64bit - determine if counter is 64bit
* @pmc: counter context
@@ -725,14 +730,10 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(int cpu)
return NULL;
}
-/**
- * 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)
+static void kvm_pmu_create_perf_event_with_pmu(struct kvm_pmc *pmc,
+ struct arm_pmu *arm_pmu)
{
struct kvm_vcpu *vcpu = kvm_pmc_to_vcpu(pmc);
- struct arm_pmu *arm_pmu = vcpu->kvm->arch.arm_pmu;
struct perf_event *event;
struct perf_event_attr attr;
int eventsel;
@@ -766,7 +767,7 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
* Don't create an event if we're running on hardware that requires
* PMUv3 event translation and we couldn't find a valid mapping.
*/
- eventsel = kvm_map_pmu_event(vcpu->kvm->arch.arm_pmu, eventsel);
+ eventsel = kvm_map_pmu_event(arm_pmu, eventsel);
if (eventsel < 0)
return;
@@ -811,6 +812,32 @@ 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 (!arm_pmu) {
+ pr_warn_once("kvm: Unsupported PMU variation detected.\n");
+ add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
+ 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);
+ }
+}
+
/**
* kvm_pmu_set_counter_event_type - set selected counter to monitor some event
* @vcpu: The vcpu pointer
@@ -897,6 +924,13 @@ u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
u64 val, mask = 0;
int base, i, nr_events;
+ /*
+ * Hide the hardware PMU's event set to keep PMCEID stable across
+ * physical CPU migration.
+ */
+ if (kvm_pmu_fixed_counters_only(vcpu->kvm))
+ return 0;
+
if (!pmceid1) {
val = compute_pmceid0(vcpu);
base = 0;
@@ -924,6 +958,15 @@ u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
return val & mask;
}
+void kvm_vcpu_load_pmu(struct kvm_vcpu *vcpu, int last_cpu)
+{
+ if (!kvm_pmu_fixed_counters_only(vcpu->kvm) || vcpu->cpu == last_cpu || last_cpu == -1)
+ return;
+
+ if (kvm_pmu_probe_armpmu(vcpu->cpu) != kvm_pmu_probe_armpmu(last_cpu))
+ kvm_pmu_request_recreate(vcpu);
+}
+
void kvm_vcpu_reload_pmu(struct kvm_vcpu *vcpu)
{
struct kvm_pmu *pmu = &vcpu->arch.pmu;
@@ -1048,6 +1091,9 @@ u8 kvm_arm_pmu_get_max_counters(struct kvm *kvm)
{
struct arm_pmu *arm_pmu = kvm->arch.arm_pmu;
+ if (kvm_pmu_fixed_counters_only(kvm))
+ return 0;
+
/*
* Under KVM_ARM_VCPU_PMU_V3_STRICT no PMU exists until userspace sets
* one, so this can be reached before arm_pmu is set. Report no
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index fca00f7f4c0a..33d81461f5cd 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -63,6 +63,7 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val);
void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val);
void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
u64 select_idx);
+void kvm_vcpu_load_pmu(struct kvm_vcpu *vcpu, int last_cpu);
void kvm_vcpu_reload_pmu(struct kvm_vcpu *vcpu);
int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu,
struct kvm_device_attr *attr);
@@ -176,6 +177,7 @@ static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
static inline void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu) {}
static inline void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) {}
static inline void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) {}
+static inline void kvm_vcpu_load_pmu(struct kvm_vcpu *vcpu, int last_cpu) {}
static inline void kvm_vcpu_reload_pmu(struct kvm_vcpu *vcpu) {}
static inline u8 kvm_arm_pmu_get_pmuver_limit(void)
{
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 20/21] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (18 preceding siblings ...)
2026-09-20 11:16 ` [PATCH v11 19/21] KVM: arm64: PMU: Implement fixed-counters-only emulation Akihiko Odaki
@ 2026-09-20 11:16 ` Akihiko Odaki
2026-09-22 7:11 ` Oliver Upton
2026-09-20 11:16 ` [PATCH v11 21/21] KVM: arm64: selftests: Test PMU_V3_FIXED_COUNTERS_ONLY Akihiko Odaki
20 siblings, 1 reply; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:16 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Introduce the KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY attribute to
create a "fixed-counters-only" PMU.
Much like KVM_ARM_VCPU_PMU_V3_IRQ and other read-write attributes, this
attribute provides a getter that facilitates kernel and userspace
debugging/testing.
Allow strict PMUv3 vCPUs to initialize the PMU after selecting
fixed-counters-only mode, without selecting a VM-wide hardware PMU.
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Documentation/virt/kvm/api.rst | 8 +++++--
Documentation/virt/kvm/devices/vcpu.rst | 42 ++++++++++++++++++++++++++-------
arch/arm64/include/uapi/asm/kvm.h | 1 +
arch/arm64/kvm/pmu-emul.c | 34 ++++++++++++++++++++++----
tools/arch/arm64/include/uapi/asm/kvm.h | 1 +
5 files changed, 71 insertions(+), 15 deletions(-)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 1a90598901c5..a6aef405ef87 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -3531,9 +3531,13 @@ Possible features:
* Userspace must explicitly select a PMU implementation before
initializing the PMU or configuring a PMU event filter
+ (KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY also satisfies the
+ initialization requirement; event filtering remains unavailable
+ in that mode)
- * If the PMU implements FEAT_PMUv3p4, PMMIR_EL1.SLOTS provides the
- hardware value of the underlying implementation
+ * If a hardware PMU is selected and implements FEAT_PMUv3p4,
+ PMMIR_EL1.SLOTS provides its hardware value. In fixed-counters-only
+ mode, PMMIR_EL1 reads as zero
* Writes to PMCR_EL0.N via KVM_SET_ONE_REG are ignored
diff --git a/Documentation/virt/kvm/devices/vcpu.rst b/Documentation/virt/kvm/devices/vcpu.rst
index a3f20a4ee4b1..41f6d708ff43 100644
--- a/Documentation/virt/kvm/devices/vcpu.rst
+++ b/Documentation/virt/kvm/devices/vcpu.rst
@@ -53,9 +53,9 @@ Returns:
======= ======================================================
-EEXIST Interrupt number already used
-ENODEV PMUv3 not supported or GIC not initialized
- -ENXIO PMUv3 not supported, missing VCPU feature, missing
- hardware PMU, or interrupt number not set (non-GICv5
- guests, only)
+ -ENXIO PMUv3 not supported, missing VCPU feature,
+ neither hardware PMU nor FIXED_COUNTERS_ONLY selected,
+ or interrupt number not set (non-GICv5 guests only)
-EBUSY PMUv3 already initialized
======= ======================================================
@@ -64,7 +64,8 @@ virtual GIC implementation, this must be done after initializing the in-kernel
irqchip.
When the KVM_ARM_VCPU_PMU_V3_STRICT vCPU feature is enabled this must be done
-after selecting a hardware PMU.
+after selecting a hardware PMU or enabling
+KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY.
1.3 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FILTER
-----------------------------------------
@@ -78,7 +79,8 @@ after selecting a hardware PMU.
-ENODEV PMUv3 not supported or GIC not initialized
-ENXIO PMUv3 not properly configured or in-kernel irqchip not
configured as required prior to calling this attribute
- -EBUSY PMUv3 already initialized or a VCPU has already run
+ -EBUSY PMUv3 already initialized, a VCPU has already run or
+ FIXED_COUNTERS_ONLY has already been set
-EINVAL Invalid filter range
======= ======================================================
@@ -123,14 +125,14 @@ after selecting a hardware PMU.
:Returns:
- ======= ====================================================
+ ======= ===========================================================
-EBUSY PMUv3 already initialized, a VCPU has already run or
- an event filter has already been set
+ an event filter or FIXED_COUNTERS_ONLY has already been set
-EFAULT Error accessing the PMU identifier
-ENXIO PMU not found
-ENODEV PMUv3 not supported or GIC not initialized
-ENOMEM Could not allocate memory
- ======= ====================================================
+ ======= ===========================================================
Request that the VCPU uses the specified hardware PMU when creating guest events
for the purpose of PMU emulation. The PMU identifier can be read from the "type"
@@ -172,6 +174,30 @@ explicitly selected, or the number of counters is out of range for the
selected PMU. Selecting a new PMU cancels the effect of setting this
attribute.
+1.6 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY
+------------------------------------------------------
+
+:Parameters: no additional parameter in kvm_device_attr.addr
+
+:Returns:
+
+ ======= ==================================================
+ -EBUSY PMUv3 already initialized, a VCPU has already run,
+ an event filter has already been set or
+ a hardware PMU has already been specified
+ -ENXIO Attempted to get before setting
+ -ENODEV Attempted to set while PMUv3 not supported
+ ======= ==================================================
+
+If set, KVM emulates PMUv3 without programmable event counters.
+
+With KVM_ARM_VCPU_PMU_V3_STRICT, enabling this attribute satisfies the
+PMU selection requirement for KVM_ARM_VCPU_PMU_V3_INIT.
+
+When this attribute is enabled, the vCPU can run on any physical CPU
+that has a PMU, regardless of the underlying implementation. This
+attribute is VM-scoped.
+
2. GROUP: KVM_ARM_VCPU_TIMER_CTRL
=================================
diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index 65ee09bd1463..7a6a0af14f5a 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -453,6 +453,7 @@ struct kvm_vgic_v5_ist {
#define KVM_ARM_VCPU_PMU_V3_FILTER 2
#define KVM_ARM_VCPU_PMU_V3_SET_PMU 3
#define KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS 4
+#define KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY 5
#define KVM_ARM_VCPU_TIMER_CTRL 1
#define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0
#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 9c1e2f3e41db..ebb648eabdc6 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -1017,8 +1017,8 @@ int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)
{
- /* Only possible when using KVM_ARM_VCPU_PMU_V3_STRICT */
- if (!vcpu->kvm->arch.arm_pmu)
+ /* Strict PMUv3 requires a hardware PMU or fixed-counters-only mode. */
+ if (!vcpu->kvm->arch.arm_pmu && !kvm_pmu_fixed_counters_only(vcpu->kvm))
return -ENXIO;
if (irqchip_in_kernel(vcpu->kvm)) {
@@ -1153,8 +1153,8 @@ int kvm_arm_set_default_pmu(struct kvm *kvm)
* affines the VMM to a particular cluster of cores.
*
* In any case, userspace should just do the sane thing and use the UAPI
- * to select a PMU type directly. But, be wary of the baggage being
- * carried here.
+ * to select a PMU type directly, or request fixed-counters-only
+ * emulation. But, be wary of the baggage being carried here.
*/
struct arm_pmu *arm_pmu = kvm_pmu_probe_armpmu(raw_smp_processor_id());
@@ -1179,11 +1179,13 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
arm_pmu = entry->arm_pmu;
if (arm_pmu->pmu.type == pmu_id) {
if (kvm_vm_has_ran_once(kvm) ||
+ kvm_pmu_fixed_counters_only(kvm) ||
(kvm->arch.pmu_filter && kvm->arch.arm_pmu != arm_pmu)) {
ret = -EBUSY;
break;
}
+ set_bit(KVM_ARCH_FLAG_PMU_V3_EXPLICIT, &kvm->arch.flags);
kvm_arm_set_pmu(kvm, arm_pmu);
cpumask_copy(kvm->arch.supported_cpus, &arm_pmu->supported_cpus);
@@ -1205,6 +1207,22 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
return ret;
}
+static int kvm_arm_pmu_v3_set_pmu_fixed_counters_only(struct kvm_vcpu *vcpu)
+{
+ struct kvm *kvm = vcpu->kvm;
+
+ lockdep_assert_held(&kvm->arch.config_lock);
+
+ if (kvm_vm_has_ran_once(kvm) || kvm->arch.pmu_filter ||
+ test_bit(KVM_ARCH_FLAG_PMU_V3_EXPLICIT, &kvm->arch.flags))
+ return -EBUSY;
+
+ set_bit(KVM_ARCH_FLAG_PMU_V3_FIXED_COUNTERS_ONLY, &kvm->arch.flags);
+ kvm->arch.nr_pmu_counters = 0;
+
+ return 0;
+}
+
static int kvm_arm_pmu_v3_set_nr_counters(struct kvm_vcpu *vcpu, unsigned int n)
{
struct kvm *kvm = vcpu->kvm;
@@ -1282,7 +1300,7 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
filter.action != KVM_PMU_EVENT_DENY))
return -EINVAL;
- if (kvm_vm_has_ran_once(kvm))
+ if (kvm_vm_has_ran_once(kvm) || kvm_pmu_fixed_counters_only(kvm))
return -EBUSY;
if (!kvm->arch.arm_pmu)
@@ -1330,6 +1348,8 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
return kvm_arm_pmu_v3_set_nr_counters(vcpu, n);
}
+ case KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY:
+ return kvm_arm_pmu_v3_set_pmu_fixed_counters_only(vcpu);
case KVM_ARM_VCPU_PMU_V3_INIT:
return kvm_arm_pmu_v3_init(vcpu);
}
@@ -1356,6 +1376,9 @@ int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
irq = vcpu->arch.pmu.irq_num;
return put_user(irq, uaddr);
}
+ case KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY:
+ if (kvm_pmu_fixed_counters_only(vcpu->kvm))
+ return 0;
}
return -ENXIO;
@@ -1369,6 +1392,7 @@ int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
case KVM_ARM_VCPU_PMU_V3_FILTER:
case KVM_ARM_VCPU_PMU_V3_SET_PMU:
case KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS:
+ case KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY:
if (kvm_vcpu_has_pmu(vcpu))
return 0;
}
diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h
index 9998252ea8ec..ec428d9f4ab4 100644
--- a/tools/arch/arm64/include/uapi/asm/kvm.h
+++ b/tools/arch/arm64/include/uapi/asm/kvm.h
@@ -452,6 +452,7 @@ struct kvm_vgic_v5_ist {
#define KVM_ARM_VCPU_PMU_V3_FILTER 2
#define KVM_ARM_VCPU_PMU_V3_SET_PMU 3
#define KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS 4
+#define KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY 5
#define KVM_ARM_VCPU_TIMER_CTRL 1
#define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0
#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH v11 21/21] KVM: arm64: selftests: Test PMU_V3_FIXED_COUNTERS_ONLY
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
` (19 preceding siblings ...)
2026-09-20 11:16 ` [PATCH v11 20/21] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY Akihiko Odaki
@ 2026-09-20 11:16 ` Akihiko Odaki
20 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-20 11:16 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, Kees Cook,
Gustavo A. R. Silva, Paolo Bonzini, Jonathan Corbet, Shuah Khan,
Shuah Khan, Yury Norov, Rasmus Villemoes, Steffen Eiden,
Andrew Jones, Fuad Tabba, Mark Rutland, Sean Christopherson,
Shannon Zhao, Randy Dunlap, Fuad Tabba
Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-hardening, devel,
kvm, linux-doc, linux-kselftest, Akihiko Odaki
Assert the following:
- FIXED_COUNTERS_ONLY is unset at initialization.
- FIXED_COUNTERS_ONLY can be set.
- Setting an event filter when FIXED_COUNTERS_ONLY has already been set
results in EBUSY.
- Setting FIXED_COUNTERS_ONLY when an event filter has already been set
results in EBUSY.
- Setting FIXED_COUNTERS_ONLY when a VCPU has already run results in
EBUSY.
Also verify that strict PMUv3 initialization requires a PMU selection
and succeeds after selecting fixed-counters-only mode.
Run the existing PMU and MDCR_EL2 tests in fixed-only mode. Verify that
enabling the mode preserves the userspace MDCR_EL2 value until a
subsequent KVM_ARM_VCPU_INIT resets HPMN to zero.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
.../selftests/kvm/arm64/vpmu_counter_access.c | 202 ++++++++++++++++++---
1 file changed, 173 insertions(+), 29 deletions(-)
diff --git a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
index 73b4f1870d3d..637653f7a25b 100644
--- a/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
+++ b/tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
@@ -411,12 +411,7 @@ static void create_vpmu_vm(void *guest_code)
{
struct kvm_vcpu_init init;
u8 pmuver, ec;
- u64 dfr0, irq = 23;
- struct kvm_device_attr irq_attr = {
- .group = KVM_ARM_VCPU_PMU_V3_CTRL,
- .attr = KVM_ARM_VCPU_PMU_V3_IRQ,
- .addr = (u64)&irq,
- };
+ u64 dfr0;
/* The test creates the vpmu_vm multiple times. Ensure a clean state */
memset(&vpmu_vm, 0, sizeof(vpmu_vm));
@@ -442,8 +437,6 @@ static void create_vpmu_vm(void *guest_code)
TEST_ASSERT(pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF &&
pmuver >= ID_AA64DFR0_EL1_PMUVer_IMP,
"Unexpected PMUVER (0x%x) on the vCPU with PMUv3", pmuver);
-
- vcpu_ioctl(vpmu_vm.vcpu, KVM_SET_DEVICE_ATTR, &irq_attr);
}
static void destroy_vpmu_vm(void)
@@ -493,13 +486,22 @@ static void set_nr_counters(struct kvm_vcpu *vcpu,
}
static void test_create_vpmu_vm_with_nr_counters(unsigned int nr_counters,
+ bool fixed_counters_only,
bool expect_fail)
{
struct kvm_vcpu *vcpu;
+ u64 irq = 23;
create_vpmu_vm(guest_code);
vcpu = vpmu_vm.vcpu;
+ if (fixed_counters_only)
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_IRQ, &irq);
+
set_nr_counters(vcpu, nr_counters, expect_fail);
vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL, KVM_ARM_VCPU_PMU_V3_INIT, NULL);
@@ -509,15 +511,15 @@ static void test_create_vpmu_vm_with_nr_counters(unsigned int nr_counters,
* Create a guest with one vCPU, set the PMCR_EL0.N for the vCPU to @pmcr_n,
* and run the test.
*/
-static void run_access_test(u64 pmcr_n)
+static void run_access_test(u64 pmcr_n, bool fixed_counters_only)
{
u64 sp;
struct kvm_vcpu *vcpu;
struct kvm_vcpu_init init;
- pr_debug("Test with pmcr_n %lu\n", pmcr_n);
+ pr_debug("Test with pmcr_n %lu, fixed_counters_only %d\n", pmcr_n, fixed_counters_only);
- test_create_vpmu_vm_with_nr_counters(pmcr_n, false);
+ test_create_vpmu_vm_with_nr_counters(pmcr_n, fixed_counters_only, false);
vcpu = vpmu_vm.vcpu;
/* Save the initial sp to restore them later to run the guest again */
@@ -553,14 +555,14 @@ static struct pmreg_sets validity_check_reg_sets[] = {
* Create a VM, and check if KVM handles the userspace accesses of
* the PMU register sets in @validity_check_reg_sets[] correctly.
*/
-static void run_pmregs_validity_test(u64 pmcr_n)
+static void run_pmregs_validity_test(u64 pmcr_n, bool fixed_counters_only)
{
int i;
struct kvm_vcpu *vcpu;
u64 set_reg_id, clr_reg_id, reg_val;
u64 valid_counters_mask, max_counters_mask;
- test_create_vpmu_vm_with_nr_counters(pmcr_n, false);
+ test_create_vpmu_vm_with_nr_counters(pmcr_n, fixed_counters_only, false);
vcpu = vpmu_vm.vcpu;
valid_counters_mask = get_counters_mask(pmcr_n);
@@ -605,13 +607,15 @@ static void run_pmregs_validity_test(u64 pmcr_n)
destroy_vpmu_vm();
}
-static void run_mdcr_el2_validity_test(u64 pmcr_n)
+static void run_mdcr_el2_validity_test(u64 pmcr_n, bool fixed_counters_only)
{
struct kvm_vcpu_init init;
struct kvm_vcpu *vcpu;
u64 expected_mdcr, mdcr;
+ u64 irq = 23;
- pr_debug("MDCR_EL2 test with pmcr_n %lu\n", pmcr_n);
+ pr_debug("MDCR_EL2 test with pmcr_n %lu, fixed_counters_only %d\n",
+ pmcr_n, fixed_counters_only);
create_vpmu_vm(guest_code);
if (!vm_supports_el2(vpmu_vm.vm)) {
@@ -632,6 +636,16 @@ static void run_mdcr_el2_validity_test(u64 pmcr_n)
"MDCR_EL2 was not properly updated after HPMN write (expected 0x%lx, got 0x%lx)",
expected_mdcr, mdcr);
+ if (fixed_counters_only) {
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+
+ mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
+ TEST_ASSERT(mdcr == expected_mdcr,
+ "MDCR_EL2 changed after PMU_V3_FIXED_COUNTERS_ONLY (expected 0x%lx, got 0x%lx)",
+ expected_mdcr, mdcr);
+ }
+
set_nr_counters(vcpu, pmcr_n, false);
mdcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MDCR_EL2));
@@ -639,6 +653,9 @@ static void run_mdcr_el2_validity_test(u64 pmcr_n)
"MDCR_EL2 changed after PMU_V3_SET_NR_COUNTERS (expected 0x%lx, got 0x%lx)",
expected_mdcr, mdcr);
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_IRQ, &irq);
+
vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
KVM_ARM_VCPU_PMU_V3_INIT, NULL);
@@ -673,11 +690,11 @@ static void run_mdcr_el2_validity_test(u64 pmcr_n)
* the vCPU to @pmcr_n, which is larger than the host value.
* The attempt should fail as @pmcr_n is too big to set for the vCPU.
*/
-static void run_error_test(u64 pmcr_n)
+static void run_error_test(u64 pmcr_n, bool fixed_counters_only)
{
pr_debug("Error test with pmcr_n %lu (larger than the host)\n", pmcr_n);
- test_create_vpmu_vm_with_nr_counters(pmcr_n, true);
+ test_create_vpmu_vm_with_nr_counters(pmcr_n, fixed_counters_only, true);
destroy_vpmu_vm();
}
@@ -738,25 +755,152 @@ static void test_set_nr_counters_after_vcpu_run(void)
kvm_vm_free(vm);
}
-int main(void)
+static void test_config(u64 pmcr_n, bool fixed_counters_only)
+{
+ u64 i;
+
+ for (i = 0; i <= pmcr_n; i++) {
+ run_access_test(i, fixed_counters_only);
+ run_pmregs_validity_test(i, fixed_counters_only);
+ run_mdcr_el2_validity_test(i, fixed_counters_only);
+ }
+
+ for (i = pmcr_n + 1; i < ARMV8_PMU_MAX_COUNTERS; i++)
+ run_error_test(i, fixed_counters_only);
+}
+
+static void test_fixed_counters_only_strict(void)
+{
+ struct kvm_vcpu_init init;
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ u64 irq = 23;
+ int ret;
+
+ if (!kvm_has_cap(KVM_CAP_ARM_PMU_V3_STRICT))
+ return;
+
+ vm = vm_create(1);
+ kvm_get_default_vcpu_target(vm, &init);
+ init.features[0] |= BIT(KVM_ARM_VCPU_PMU_V3) |
+ BIT(KVM_ARM_VCPU_PMU_V3_STRICT);
+ vcpu = aarch64_vcpu_add(vm, 0, &init, guest_code_done);
+ kvm_arch_vm_finalize_vcpus(vm);
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_IRQ, &irq);
+
+ /* STRICT still requires a PMU selection before initialization. */
+ ret = __vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_INIT, NULL);
+ TEST_ASSERT(ret == -1 && errno == ENXIO,
+ KVM_IOCTL_ERROR(KVM_SET_DEVICE_ATTR, ret));
+
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+ vcpu_device_attr_set(vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_INIT, NULL);
+
+ kvm_vm_free(vm);
+}
+
+static void test_fixed_counters_only(void)
{
- u64 i, pmcr_n;
+ struct kvm_pmu_event_filter filter = { .nevents = 0 };
+ struct kvm_vm *vm;
+ struct kvm_vcpu *running_vcpu;
+ struct kvm_vcpu *stopped_vcpu;
+ struct kvm_vcpu_init init;
+ int ret;
+ u64 irq = 23;
+
+ create_vpmu_vm(guest_code);
+ ret = __vcpu_has_device_attr(vpmu_vm.vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY);
+ if (ret) {
+ TEST_ASSERT(ret == -1 && errno == ENXIO,
+ KVM_IOCTL_ERROR(KVM_HAS_DEVICE_ATTR, ret));
+ destroy_vpmu_vm();
+ return;
+ }
+
+ /* Assert that FIXED_COUNTERS_ONLY is unset at initialization. */
+ ret = __vcpu_device_attr_get(vpmu_vm.vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+ TEST_ASSERT(ret == -1 && errno == ENXIO,
+ KVM_IOCTL_ERROR(KVM_GET_DEVICE_ATTR, ret));
+
+ /* Assert that setting FIXED_COUNTERS_ONLY succeeds. */
+ vcpu_device_attr_set(vpmu_vm.vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+
+ /* Assert that FIXED_COUNTERS_ONLY is set. */
+ vcpu_device_attr_get(vpmu_vm.vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+
+ /*
+ * Setting an event filter when FIXED_COUNTERS_ONLY has already been set
+ * results in EBUSY.
+ */
+ ret = __vcpu_device_attr_set(vpmu_vm.vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FILTER, &filter);
+ TEST_ASSERT(ret == -1 && errno == EBUSY,
+ KVM_IOCTL_ERROR(KVM_SET_DEVICE_ATTR, ret));
+
+ destroy_vpmu_vm();
+
+ create_vpmu_vm(guest_code);
+
+ /*
+ * Assert that setting FIXED_COUNTERS_ONLY when an event filter has
+ * already been set results in EBUSY.
+ */
+ vcpu_device_attr_set(vpmu_vm.vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FILTER, &filter);
+
+ ret = __vcpu_device_attr_set(vpmu_vm.vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+ TEST_ASSERT(ret == -1 && errno == EBUSY,
+ KVM_IOCTL_ERROR(KVM_SET_DEVICE_ATTR, ret));
+
+ destroy_vpmu_vm();
+
+ /*
+ * Assert that setting FIXED_COUNTERS_ONLY when a VCPU has already run
+ * results in EBUSY.
+ */
+ vm = vm_create(2);
+ vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init);
+ init.features[0] |= (1 << KVM_ARM_VCPU_PMU_V3);
+ running_vcpu = aarch64_vcpu_add(vm, 0, &init, guest_code_done);
+ stopped_vcpu = aarch64_vcpu_add(vm, 1, &init, guest_code_done);
+ kvm_arch_vm_finalize_vcpus(vm);
+ vcpu_device_attr_set(running_vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_IRQ, &irq);
+ vcpu_device_attr_set(running_vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_INIT, NULL);
+ run_vcpu(running_vcpu);
+
+ ret = __vcpu_device_attr_set(stopped_vcpu, KVM_ARM_VCPU_PMU_V3_CTRL,
+ KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY, NULL);
+ TEST_ASSERT(ret == -1 && errno == EBUSY,
+ KVM_IOCTL_ERROR(KVM_SET_DEVICE_ATTR, ret));
+
+ kvm_vm_free(vm);
+
+ test_fixed_counters_only_strict();
+ test_config(0, true);
+}
+
+int main(void)
+{
TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_PMU_V3));
TEST_REQUIRE(kvm_supports_vgic_v3());
TEST_REQUIRE(kvm_supports_nr_counters_attr());
test_set_nr_counters_after_vcpu_run();
-
- pmcr_n = get_pmcr_n_limit();
- for (i = 0; i <= pmcr_n; i++) {
- run_access_test(i);
- run_pmregs_validity_test(i);
- run_mdcr_el2_validity_test(i);
- }
-
- for (i = pmcr_n + 1; i < ARMV8_PMU_MAX_COUNTERS; i++)
- run_error_test(i);
+ test_config(get_pmcr_n_limit(), false);
+ test_fixed_counters_only();
return 0;
}
--
2.55.0
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH v11 08/21] Revert "KVM: arm64: PMU: Reload when resetting"
2026-09-20 11:15 ` [PATCH v11 08/21] Revert "KVM: arm64: PMU: Reload when resetting" Akihiko Odaki
@ 2026-09-22 6:43 ` Oliver Upton
2026-09-22 7:05 ` Akihiko Odaki
0 siblings, 1 reply; 28+ messages in thread
From: Oliver Upton @ 2026-09-22 6:43 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Catalin Marinas, Will Deacon, Kees Cook, Gustavo A. R. Silva,
Paolo Bonzini, Jonathan Corbet, Shuah Khan, Shuah Khan,
Yury Norov, Rasmus Villemoes, Steffen Eiden, Andrew Jones,
Fuad Tabba, Mark Rutland, Sean Christopherson, Shannon Zhao,
Randy Dunlap, linux-arm-kernel, kvmarm, linux-kernel,
linux-hardening, devel, kvm, linux-doc, linux-kselftest
Hi Akihiko,
On Sun, Sep 20, 2026 at 08:15:49PM +0900, Akihiko Odaki wrote:
> This reverts commit fe53538069bb4f625bc8734103ba044a83138fea.
>
> Restore PMU event teardown before system-register reset so existing
> perf events cannot retain configuration from the previous run. All
> counters are disabled by the reset PMCR_EL0 and MDCR_EL2 values, so
> reset does not need to request a PMU reload.
Sorry, I'm not following the intent here. KVM_REQ_RELOAD_PMU should
already be discarding + recomputing perf events based on the state of
the vPMU. What's the problem?
Thanks,
Oliver
> Assisted-by: Codex:gpt-6-astra
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
> arch/arm64/kvm/pmu-emul.c | 14 ++++++++++++++
> arch/arm64/kvm/reset.c | 3 +++
> arch/arm64/kvm/sys_regs.c | 3 ---
> include/kvm/arm_pmu.h | 2 ++
> 4 files changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
> index a5ccb6ae44d5..14fcdbdb4587 100644
> --- a/arch/arm64/kvm/pmu-emul.c
> +++ b/arch/arm64/kvm/pmu-emul.c
> @@ -258,6 +258,20 @@ void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu)
> pmu->pmc[i].idx = i;
> }
>
> +/**
> + * kvm_pmu_vcpu_reset - reset pmu state for cpu
> + * @vcpu: The vcpu pointer
> + *
> + */
> +void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu)
> +{
> + unsigned long mask = kvm_pmu_implemented_counter_mask(vcpu);
> + int i;
> +
> + for_each_set_bit(i, &mask, 32)
> + kvm_pmu_stop_counter(kvm_vcpu_idx_to_pmc(vcpu, i));
> +}
> +
> /**
> * kvm_pmu_vcpu_destroy - free perf event of PMU for cpu
> * @vcpu: The vcpu pointer
> diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
> index 10eb7249aa9e..adcb460a5287 100644
> --- a/arch/arm64/kvm/reset.c
> +++ b/arch/arm64/kvm/reset.c
> @@ -185,6 +185,9 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
> vcpu->arch.reset_state.reset = false;
> spin_unlock(&vcpu->arch.mp_state_lock);
>
> + /* Reset PMU outside of the non-preemptible section */
> + kvm_pmu_vcpu_reset(vcpu);
> +
> preempt_disable();
> loaded = (vcpu->cpu != -1);
> if (loaded)
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 1481dd5c99a8..75624725adf1 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -5388,9 +5388,6 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)
> }
>
> set_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags);
> -
> - if (kvm_vcpu_has_pmu(vcpu))
> - kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
> }
>
> /**
> diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
> index 6b4a118d17ca..51f5e4ca3326 100644
> --- a/include/kvm/arm_pmu.h
> +++ b/include/kvm/arm_pmu.h
> @@ -48,6 +48,7 @@ u64 kvm_pmu_implemented_counter_mask(struct kvm_vcpu *vcpu);
> u64 kvm_pmu_accessible_counter_mask(struct kvm_vcpu *vcpu);
> u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1);
> void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu);
> +void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu);
> void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu);
> void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val);
> void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu);
> @@ -125,6 +126,7 @@ static inline u64 kvm_pmu_accessible_counter_mask(struct kvm_vcpu *vcpu)
> return 0;
> }
> static inline void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) {}
> +static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {}
> static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {}
> static inline void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val) {}
> static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {}
>
> --
> 2.55.0
>
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH v11 09/21] KVM: arm64: PMU: Recreate events after MDCR_EL2 changes
2026-09-20 11:15 ` [PATCH v11 09/21] KVM: arm64: PMU: Recreate events after MDCR_EL2 changes Akihiko Odaki
@ 2026-09-22 6:54 ` Oliver Upton
2026-09-22 8:51 ` Akihiko Odaki
0 siblings, 1 reply; 28+ messages in thread
From: Oliver Upton @ 2026-09-22 6:54 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Catalin Marinas, Will Deacon, Kees Cook, Gustavo A. R. Silva,
Paolo Bonzini, Jonathan Corbet, Shuah Khan, Shuah Khan,
Yury Norov, Rasmus Villemoes, Steffen Eiden, Andrew Jones,
Fuad Tabba, Mark Rutland, Sean Christopherson, Shannon Zhao,
Randy Dunlap, linux-arm-kernel, kvmarm, linux-kernel,
linux-hardening, devel, kvm, linux-doc, linux-kselftest
On Sun, Sep 20, 2026 at 08:15:50PM +0900, Akihiko Odaki wrote:
> +void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val)
> +{
> + u64 changed = old ^ val;
> +
> + /*
> + * HPMN determines which counters HPMD and HLP apply to. Changes to
> + * these fields require new perf event filters and sample periods.
> + */
> + if (changed & (MDCR_EL2_HPMN | MDCR_EL2_HPMD | MDCR_EL2_HLP))
> + kvm_pmu_request_recreate(vcpu);
> + else if (changed & MDCR_EL2_HPME)
> + kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
> +}
> +
Urgh... I'm not a fan of this. Can you just modify kvm_vcpu_reload_pmu()
to discard all backing perf events and recompute them only for enabled
PMCs? We set KVM_REQ_RELOAD_PMU pretty rarely.
> __vcpu_rmw_sys_reg(vcpu, PMOVSSET_EL0, &=, mask);
> __vcpu_rmw_sys_reg(vcpu, PMINTENSET_EL1, &=, mask);
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 75624725adf1..7dd2cafce247 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -3114,17 +3114,22 @@ static bool access_mdcr(struct kvm_vcpu *vcpu,
> }
>
> __vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
> -
> - /*
> - * Request a reload of the PMU to enable/disable the counters
> - * affected by HPME.
> - */
> - if ((old ^ val) & MDCR_EL2_HPME)
> - kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
> + kvm_pmu_apply_mdcr(vcpu, old, val);
>
> return true;
> }
> +static int set_mdcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
> + u64 val)
> +{
> + u64 old = __vcpu_sys_reg(vcpu, MDCR_EL2);
> +
> + __vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
> + kvm_pmu_apply_mdcr(vcpu, old, val);
> +
> + return 0;
> +}
> +
Just keep the old ^ new test inline for access_mdcr() and set the
request unconditionally from set_mdcr(). In the usual case
KVM_REQ_RELOAD_PMU is already set on a vCPU that userspace is restoring.
Thanks,
Oliver
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH v11 08/21] Revert "KVM: arm64: PMU: Reload when resetting"
2026-09-22 6:43 ` Oliver Upton
@ 2026-09-22 7:05 ` Akihiko Odaki
0 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-22 7:05 UTC (permalink / raw)
To: Oliver Upton
Cc: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Catalin Marinas, Will Deacon, Kees Cook, Gustavo A. R. Silva,
Paolo Bonzini, Jonathan Corbet, Shuah Khan, Shuah Khan,
Yury Norov, Rasmus Villemoes, Steffen Eiden, Andrew Jones,
Fuad Tabba, Mark Rutland, Sean Christopherson, Shannon Zhao,
Randy Dunlap, linux-arm-kernel, kvmarm, linux-kernel,
linux-hardening, devel, kvm, linux-doc, linux-kselftest
On 2026/09/22 15:43, Oliver Upton wrote:
> Hi Akihiko,
>
> On Sun, Sep 20, 2026 at 08:15:49PM +0900, Akihiko Odaki wrote:
>> This reverts commit fe53538069bb4f625bc8734103ba044a83138fea.
>>
>> Restore PMU event teardown before system-register reset so existing
>> perf events cannot retain configuration from the previous run. All
>> counters are disabled by the reset PMCR_EL0 and MDCR_EL2 values, so
>> reset does not need to request a PMU reload.
>
> Sorry, I'm not following the intent here. KVM_REQ_RELOAD_PMU should
> already be discarding + recomputing perf events based on the state of
> the vPMU. What's the problem?
Hi Oliver,
A plain KVM_REQ_RELOAD_PMU does not discard existing perf events.
kvm_pmu_reprogram_counter_mask() enables or disables them, and
kvm_pmc_enable_perf_event() only creates an event if none exists.
For example, an existing cycle-counter event may exclude EL0 counting.
Reset sets PMCCFILTR_EL0 to zero, but the subsequent reload only
disables that event. If the guest then enables cycle counting without
rewriting the filter or counter, the old event is enabled again and
still excludes EL0, despite PMCCFILTR_EL0 reading as zero.
The earlier "Recreate events after reset" patch addressed this by
setting events_need_recreate. Sashiko then pointed out that stopping the
old events after resetting the registers adds their accumulated counts
to the reset counter values:
https://sashiko.dev/#/message/20260914-hybrid-v10-7-92788053a691%40rsg.ci.i.u-tokyo.ac.jp
The revert restores teardown before system-register reset and fixes the
stale configuration.
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH v11 20/21] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY
2026-09-20 11:16 ` [PATCH v11 20/21] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY Akihiko Odaki
@ 2026-09-22 7:11 ` Oliver Upton
2026-09-22 9:13 ` Akihiko Odaki
0 siblings, 1 reply; 28+ messages in thread
From: Oliver Upton @ 2026-09-22 7:11 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Catalin Marinas, Will Deacon, Kees Cook, Gustavo A. R. Silva,
Paolo Bonzini, Jonathan Corbet, Shuah Khan, Shuah Khan,
Yury Norov, Rasmus Villemoes, Steffen Eiden, Andrew Jones,
Fuad Tabba, Mark Rutland, Sean Christopherson, Shannon Zhao,
Randy Dunlap, linux-arm-kernel, kvmarm, linux-kernel,
linux-hardening, devel, kvm, linux-doc, linux-kselftest
On Sun, Sep 20, 2026 at 08:16:01PM +0900, Akihiko Odaki wrote:
> Introduce the KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY attribute to
> create a "fixed-counters-only" PMU.
>
> Much like KVM_ARM_VCPU_PMU_V3_IRQ and other read-write attributes, this
> attribute provides a getter that facilitates kernel and userspace
> debugging/testing.
>
> Allow strict PMUv3 vCPUs to initialize the PMU after selecting
> fixed-counters-only mode, without selecting a VM-wide hardware PMU.
>
> Assisted-by: Codex:gpt-5.6-sol
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
> Documentation/virt/kvm/api.rst | 8 +++++--
> Documentation/virt/kvm/devices/vcpu.rst | 42 ++++++++++++++++++++++++++-------
> arch/arm64/include/uapi/asm/kvm.h | 1 +
> arch/arm64/kvm/pmu-emul.c | 34 ++++++++++++++++++++++----
> tools/arch/arm64/include/uapi/asm/kvm.h | 1 +
> 5 files changed, 71 insertions(+), 15 deletions(-)
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index 1a90598901c5..a6aef405ef87 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -3531,9 +3531,13 @@ Possible features:
>
> * Userspace must explicitly select a PMU implementation before
> initializing the PMU or configuring a PMU event filter
> + (KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY also satisfies the
> + initialization requirement; event filtering remains unavailable
> + in that mode)
>
> - * If the PMU implements FEAT_PMUv3p4, PMMIR_EL1.SLOTS provides the
> - hardware value of the underlying implementation
> + * If a hardware PMU is selected and implements FEAT_PMUv3p4,
> + PMMIR_EL1.SLOTS provides its hardware value. In fixed-counters-only
> + mode, PMMIR_EL1 reads as zero
>
> * Writes to PMCR_EL0.N via KVM_SET_ONE_REG are ignored
>
> diff --git a/Documentation/virt/kvm/devices/vcpu.rst b/Documentation/virt/kvm/devices/vcpu.rst
> index a3f20a4ee4b1..41f6d708ff43 100644
> --- a/Documentation/virt/kvm/devices/vcpu.rst
> +++ b/Documentation/virt/kvm/devices/vcpu.rst
> @@ -53,9 +53,9 @@ Returns:
> ======= ======================================================
> -EEXIST Interrupt number already used
> -ENODEV PMUv3 not supported or GIC not initialized
> - -ENXIO PMUv3 not supported, missing VCPU feature, missing
> - hardware PMU, or interrupt number not set (non-GICv5
> - guests, only)
> + -ENXIO PMUv3 not supported, missing VCPU feature,
> + neither hardware PMU nor FIXED_COUNTERS_ONLY selected,
> + or interrupt number not set (non-GICv5 guests only)
> -EBUSY PMUv3 already initialized
> ======= ======================================================
>
> @@ -64,7 +64,8 @@ virtual GIC implementation, this must be done after initializing the in-kernel
> irqchip.
>
> When the KVM_ARM_VCPU_PMU_V3_STRICT vCPU feature is enabled this must be done
> -after selecting a hardware PMU.
> +after selecting a hardware PMU or enabling
> +KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY.
>
> 1.3 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FILTER
> -----------------------------------------
> @@ -78,7 +79,8 @@ after selecting a hardware PMU.
> -ENODEV PMUv3 not supported or GIC not initialized
> -ENXIO PMUv3 not properly configured or in-kernel irqchip not
> configured as required prior to calling this attribute
> - -EBUSY PMUv3 already initialized or a VCPU has already run
> + -EBUSY PMUv3 already initialized, a VCPU has already run or
> + FIXED_COUNTERS_ONLY has already been set
> -EINVAL Invalid filter range
> ======= ======================================================
>
> @@ -123,14 +125,14 @@ after selecting a hardware PMU.
>
> :Returns:
>
> - ======= ====================================================
> + ======= ===========================================================
> -EBUSY PMUv3 already initialized, a VCPU has already run or
> - an event filter has already been set
> + an event filter or FIXED_COUNTERS_ONLY has already been set
> -EFAULT Error accessing the PMU identifier
> -ENXIO PMU not found
> -ENODEV PMUv3 not supported or GIC not initialized
> -ENOMEM Could not allocate memory
> - ======= ====================================================
> + ======= ===========================================================
>
> Request that the VCPU uses the specified hardware PMU when creating guest events
> for the purpose of PMU emulation. The PMU identifier can be read from the "type"
> @@ -172,6 +174,30 @@ explicitly selected, or the number of counters is out of range for the
> selected PMU. Selecting a new PMU cancels the effect of setting this
> attribute.
>
> +1.6 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY
> +------------------------------------------------------
> +
> +:Parameters: no additional parameter in kvm_device_attr.addr
> +
> +:Returns:
> +
> + ======= ==================================================
> + -EBUSY PMUv3 already initialized, a VCPU has already run,
> + an event filter has already been set or
> + a hardware PMU has already been specified
> + -ENXIO Attempted to get before setting
> + -ENODEV Attempted to set while PMUv3 not supported
> + ======= ==================================================
> +
> +If set, KVM emulates PMUv3 without programmable event counters.
> +
> +With KVM_ARM_VCPU_PMU_V3_STRICT, enabling this attribute satisfies the
> +PMU selection requirement for KVM_ARM_VCPU_PMU_V3_INIT.
> +
> +When this attribute is enabled, the vCPU can run on any physical CPU
> +that has a PMU, regardless of the underlying implementation. This
> +attribute is VM-scoped.
> +
> 2. GROUP: KVM_ARM_VCPU_TIMER_CTRL
> =================================
>
> diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
> index 65ee09bd1463..7a6a0af14f5a 100644
> --- a/arch/arm64/include/uapi/asm/kvm.h
> +++ b/arch/arm64/include/uapi/asm/kvm.h
> @@ -453,6 +453,7 @@ struct kvm_vgic_v5_ist {
> #define KVM_ARM_VCPU_PMU_V3_FILTER 2
> #define KVM_ARM_VCPU_PMU_V3_SET_PMU 3
> #define KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS 4
> +#define KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY 5
> #define KVM_ARM_VCPU_TIMER_CTRL 1
> #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0
> #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
> diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
> index 9c1e2f3e41db..ebb648eabdc6 100644
> --- a/arch/arm64/kvm/pmu-emul.c
> +++ b/arch/arm64/kvm/pmu-emul.c
> @@ -1017,8 +1017,8 @@ int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
>
> static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)
> {
> - /* Only possible when using KVM_ARM_VCPU_PMU_V3_STRICT */
> - if (!vcpu->kvm->arch.arm_pmu)
> + /* Strict PMUv3 requires a hardware PMU or fixed-counters-only mode. */
> + if (!vcpu->kvm->arch.arm_pmu && !kvm_pmu_fixed_counters_only(vcpu->kvm))
> return -ENXIO;
>
> if (irqchip_in_kernel(vcpu->kvm)) {
> @@ -1153,8 +1153,8 @@ int kvm_arm_set_default_pmu(struct kvm *kvm)
> * affines the VMM to a particular cluster of cores.
> *
> * In any case, userspace should just do the sane thing and use the UAPI
> - * to select a PMU type directly. But, be wary of the baggage being
> - * carried here.
> + * to select a PMU type directly, or request fixed-counters-only
> + * emulation. But, be wary of the baggage being carried here.
> */
> struct arm_pmu *arm_pmu = kvm_pmu_probe_armpmu(raw_smp_processor_id());
>
> @@ -1179,11 +1179,13 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
> arm_pmu = entry->arm_pmu;
> if (arm_pmu->pmu.type == pmu_id) {
> if (kvm_vm_has_ran_once(kvm) ||
> + kvm_pmu_fixed_counters_only(kvm) ||
> (kvm->arch.pmu_filter && kvm->arch.arm_pmu != arm_pmu)) {
> ret = -EBUSY;
> break;
> }
>
> + set_bit(KVM_ARCH_FLAG_PMU_V3_EXPLICIT, &kvm->arch.flags);
> kvm_arm_set_pmu(kvm, arm_pmu);
> cpumask_copy(kvm->arch.supported_cpus, &arm_pmu->supported_cpus);
>
> @@ -1205,6 +1207,22 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
> return ret;
> }
>
> +static int kvm_arm_pmu_v3_set_pmu_fixed_counters_only(struct kvm_vcpu *vcpu)
> +{
> + struct kvm *kvm = vcpu->kvm;
> +
> + lockdep_assert_held(&kvm->arch.config_lock);
> +
> + if (kvm_vm_has_ran_once(kvm) || kvm->arch.pmu_filter ||
> + test_bit(KVM_ARCH_FLAG_PMU_V3_EXPLICIT, &kvm->arch.flags))
> + return -EBUSY;
> +
> + set_bit(KVM_ARCH_FLAG_PMU_V3_FIXED_COUNTERS_ONLY, &kvm->arch.flags);
> + kvm->arch.nr_pmu_counters = 0;
> +
> + return 0;
> +}
> +
I'd rather that FIXED_COUNTERS_ONLY depend on the KVM_ARM_VCPU_PMU_V3_STRICT
feature flag. The expectation of that flag is that userspace specifies a
backing PMU implementation; your FIXED_COUNTERS_ONLY could just be seen
as one such PMU implementation.
Thanks,
Oliver
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH v11 09/21] KVM: arm64: PMU: Recreate events after MDCR_EL2 changes
2026-09-22 6:54 ` Oliver Upton
@ 2026-09-22 8:51 ` Akihiko Odaki
0 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-22 8:51 UTC (permalink / raw)
To: Oliver Upton
Cc: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Catalin Marinas, Will Deacon, Kees Cook, Gustavo A. R. Silva,
Paolo Bonzini, Jonathan Corbet, Shuah Khan, Shuah Khan,
Yury Norov, Rasmus Villemoes, Steffen Eiden, Andrew Jones,
Fuad Tabba, Mark Rutland, Sean Christopherson, Shannon Zhao,
Randy Dunlap, linux-arm-kernel, kvmarm, linux-kernel,
linux-hardening, devel, kvm, linux-doc, linux-kselftest
On 2026/09/22 15:54, Oliver Upton wrote:
> On Sun, Sep 20, 2026 at 08:15:50PM +0900, Akihiko Odaki wrote:
>> +void kvm_pmu_apply_mdcr(struct kvm_vcpu *vcpu, u64 old, u64 val)
>> +{
>> + u64 changed = old ^ val;
>> +
>> + /*
>> + * HPMN determines which counters HPMD and HLP apply to. Changes to
>> + * these fields require new perf event filters and sample periods.
>> + */
>> + if (changed & (MDCR_EL2_HPMN | MDCR_EL2_HPMD | MDCR_EL2_HLP))
>> + kvm_pmu_request_recreate(vcpu);
>> + else if (changed & MDCR_EL2_HPME)
>> + kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
>> +}
>> +
>
> Urgh... I'm not a fan of this. Can you just modify kvm_vcpu_reload_pmu()
> to discard all backing perf events and recompute them only for enabled
> PMCs? We set KVM_REQ_RELOAD_PMU pretty rarely.
>
>> __vcpu_rmw_sys_reg(vcpu, PMOVSSET_EL0, &=, mask);
>> __vcpu_rmw_sys_reg(vcpu, PMINTENSET_EL1, &=, mask);
>> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
>> index 75624725adf1..7dd2cafce247 100644
>> --- a/arch/arm64/kvm/sys_regs.c
>> +++ b/arch/arm64/kvm/sys_regs.c
>> @@ -3114,17 +3114,22 @@ static bool access_mdcr(struct kvm_vcpu *vcpu,
>> }
>>
>> __vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
>> -
>> - /*
>> - * Request a reload of the PMU to enable/disable the counters
>> - * affected by HPME.
>> - */
>> - if ((old ^ val) & MDCR_EL2_HPME)
>> - kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
>> + kvm_pmu_apply_mdcr(vcpu, old, val);
>>
>> return true;
>> }
>
>> +static int set_mdcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
>> + u64 val)
>> +{
>> + u64 old = __vcpu_sys_reg(vcpu, MDCR_EL2);
>> +
>> + __vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
>> + kvm_pmu_apply_mdcr(vcpu, old, val);
>> +
>> + return 0;
>> +}
>> +
>
> Just keep the old ^ new test inline for access_mdcr() and set the
> request unconditionally from set_mdcr(). In the usual case
> KVM_REQ_RELOAD_PMU is already set on a vCPU that userspace is restoring.
Hi Oliver,
Thanks for the feedback. I'll make both changes for v2.
I originally tried to preserve existing behavior and keep things
consistent, but I agree that simplicity is much better here given how
rarely KVM_REQ_RELOAD_PMU is set.
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH v11 20/21] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY
2026-09-22 7:11 ` Oliver Upton
@ 2026-09-22 9:13 ` Akihiko Odaki
0 siblings, 0 replies; 28+ messages in thread
From: Akihiko Odaki @ 2026-09-22 9:13 UTC (permalink / raw)
To: Oliver Upton
Cc: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Catalin Marinas, Will Deacon, Kees Cook, Gustavo A. R. Silva,
Paolo Bonzini, Jonathan Corbet, Shuah Khan, Shuah Khan,
Yury Norov, Rasmus Villemoes, Steffen Eiden, Andrew Jones,
Fuad Tabba, Mark Rutland, Sean Christopherson, Shannon Zhao,
Randy Dunlap, linux-arm-kernel, kvmarm, linux-kernel,
linux-hardening, devel, kvm, linux-doc, linux-kselftest
On 2026/09/22 16:11, Oliver Upton wrote:
> On Sun, Sep 20, 2026 at 08:16:01PM +0900, Akihiko Odaki wrote:
>> Introduce the KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY attribute to
>> create a "fixed-counters-only" PMU.
>>
>> Much like KVM_ARM_VCPU_PMU_V3_IRQ and other read-write attributes, this
>> attribute provides a getter that facilitates kernel and userspace
>> debugging/testing.
>>
>> Allow strict PMUv3 vCPUs to initialize the PMU after selecting
>> fixed-counters-only mode, without selecting a VM-wide hardware PMU.
>>
>> Assisted-by: Codex:gpt-5.6-sol
>> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>> ---
>> Documentation/virt/kvm/api.rst | 8 +++++--
>> Documentation/virt/kvm/devices/vcpu.rst | 42 ++++++++++++++++++++++++++-------
>> arch/arm64/include/uapi/asm/kvm.h | 1 +
>> arch/arm64/kvm/pmu-emul.c | 34 ++++++++++++++++++++++----
>> tools/arch/arm64/include/uapi/asm/kvm.h | 1 +
>> 5 files changed, 71 insertions(+), 15 deletions(-)
>>
>> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
>> index 1a90598901c5..a6aef405ef87 100644
>> --- a/Documentation/virt/kvm/api.rst
>> +++ b/Documentation/virt/kvm/api.rst
>> @@ -3531,9 +3531,13 @@ Possible features:
>>
>> * Userspace must explicitly select a PMU implementation before
>> initializing the PMU or configuring a PMU event filter
>> + (KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY also satisfies the
>> + initialization requirement; event filtering remains unavailable
>> + in that mode)
>>
>> - * If the PMU implements FEAT_PMUv3p4, PMMIR_EL1.SLOTS provides the
>> - hardware value of the underlying implementation
>> + * If a hardware PMU is selected and implements FEAT_PMUv3p4,
>> + PMMIR_EL1.SLOTS provides its hardware value. In fixed-counters-only
>> + mode, PMMIR_EL1 reads as zero
>>
>> * Writes to PMCR_EL0.N via KVM_SET_ONE_REG are ignored
>>
>> diff --git a/Documentation/virt/kvm/devices/vcpu.rst b/Documentation/virt/kvm/devices/vcpu.rst
>> index a3f20a4ee4b1..41f6d708ff43 100644
>> --- a/Documentation/virt/kvm/devices/vcpu.rst
>> +++ b/Documentation/virt/kvm/devices/vcpu.rst
>> @@ -53,9 +53,9 @@ Returns:
>> ======= ======================================================
>> -EEXIST Interrupt number already used
>> -ENODEV PMUv3 not supported or GIC not initialized
>> - -ENXIO PMUv3 not supported, missing VCPU feature, missing
>> - hardware PMU, or interrupt number not set (non-GICv5
>> - guests, only)
>> + -ENXIO PMUv3 not supported, missing VCPU feature,
>> + neither hardware PMU nor FIXED_COUNTERS_ONLY selected,
>> + or interrupt number not set (non-GICv5 guests only)
>> -EBUSY PMUv3 already initialized
>> ======= ======================================================
>>
>> @@ -64,7 +64,8 @@ virtual GIC implementation, this must be done after initializing the in-kernel
>> irqchip.
>>
>> When the KVM_ARM_VCPU_PMU_V3_STRICT vCPU feature is enabled this must be done
>> -after selecting a hardware PMU.
>> +after selecting a hardware PMU or enabling
>> +KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY.
>>
>> 1.3 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FILTER
>> -----------------------------------------
>> @@ -78,7 +79,8 @@ after selecting a hardware PMU.
>> -ENODEV PMUv3 not supported or GIC not initialized
>> -ENXIO PMUv3 not properly configured or in-kernel irqchip not
>> configured as required prior to calling this attribute
>> - -EBUSY PMUv3 already initialized or a VCPU has already run
>> + -EBUSY PMUv3 already initialized, a VCPU has already run or
>> + FIXED_COUNTERS_ONLY has already been set
>> -EINVAL Invalid filter range
>> ======= ======================================================
>>
>> @@ -123,14 +125,14 @@ after selecting a hardware PMU.
>>
>> :Returns:
>>
>> - ======= ====================================================
>> + ======= ===========================================================
>> -EBUSY PMUv3 already initialized, a VCPU has already run or
>> - an event filter has already been set
>> + an event filter or FIXED_COUNTERS_ONLY has already been set
>> -EFAULT Error accessing the PMU identifier
>> -ENXIO PMU not found
>> -ENODEV PMUv3 not supported or GIC not initialized
>> -ENOMEM Could not allocate memory
>> - ======= ====================================================
>> + ======= ===========================================================
>>
>> Request that the VCPU uses the specified hardware PMU when creating guest events
>> for the purpose of PMU emulation. The PMU identifier can be read from the "type"
>> @@ -172,6 +174,30 @@ explicitly selected, or the number of counters is out of range for the
>> selected PMU. Selecting a new PMU cancels the effect of setting this
>> attribute.
>>
>> +1.6 ATTRIBUTE: KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY
>> +------------------------------------------------------
>> +
>> +:Parameters: no additional parameter in kvm_device_attr.addr
>> +
>> +:Returns:
>> +
>> + ======= ==================================================
>> + -EBUSY PMUv3 already initialized, a VCPU has already run,
>> + an event filter has already been set or
>> + a hardware PMU has already been specified
>> + -ENXIO Attempted to get before setting
>> + -ENODEV Attempted to set while PMUv3 not supported
>> + ======= ==================================================
>> +
>> +If set, KVM emulates PMUv3 without programmable event counters.
>> +
>> +With KVM_ARM_VCPU_PMU_V3_STRICT, enabling this attribute satisfies the
>> +PMU selection requirement for KVM_ARM_VCPU_PMU_V3_INIT.
>> +
>> +When this attribute is enabled, the vCPU can run on any physical CPU
>> +that has a PMU, regardless of the underlying implementation. This
>> +attribute is VM-scoped.
>> +
>> 2. GROUP: KVM_ARM_VCPU_TIMER_CTRL
>> =================================
>>
>> diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
>> index 65ee09bd1463..7a6a0af14f5a 100644
>> --- a/arch/arm64/include/uapi/asm/kvm.h
>> +++ b/arch/arm64/include/uapi/asm/kvm.h
>> @@ -453,6 +453,7 @@ struct kvm_vgic_v5_ist {
>> #define KVM_ARM_VCPU_PMU_V3_FILTER 2
>> #define KVM_ARM_VCPU_PMU_V3_SET_PMU 3
>> #define KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS 4
>> +#define KVM_ARM_VCPU_PMU_V3_FIXED_COUNTERS_ONLY 5
>> #define KVM_ARM_VCPU_TIMER_CTRL 1
>> #define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0
>> #define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
>> diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
>> index 9c1e2f3e41db..ebb648eabdc6 100644
>> --- a/arch/arm64/kvm/pmu-emul.c
>> +++ b/arch/arm64/kvm/pmu-emul.c
>> @@ -1017,8 +1017,8 @@ int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
>>
>> static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)
>> {
>> - /* Only possible when using KVM_ARM_VCPU_PMU_V3_STRICT */
>> - if (!vcpu->kvm->arch.arm_pmu)
>> + /* Strict PMUv3 requires a hardware PMU or fixed-counters-only mode. */
>> + if (!vcpu->kvm->arch.arm_pmu && !kvm_pmu_fixed_counters_only(vcpu->kvm))
>> return -ENXIO;
>>
>> if (irqchip_in_kernel(vcpu->kvm)) {
>> @@ -1153,8 +1153,8 @@ int kvm_arm_set_default_pmu(struct kvm *kvm)
>> * affines the VMM to a particular cluster of cores.
>> *
>> * In any case, userspace should just do the sane thing and use the UAPI
>> - * to select a PMU type directly. But, be wary of the baggage being
>> - * carried here.
>> + * to select a PMU type directly, or request fixed-counters-only
>> + * emulation. But, be wary of the baggage being carried here.
>> */
>> struct arm_pmu *arm_pmu = kvm_pmu_probe_armpmu(raw_smp_processor_id());
>>
>> @@ -1179,11 +1179,13 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
>> arm_pmu = entry->arm_pmu;
>> if (arm_pmu->pmu.type == pmu_id) {
>> if (kvm_vm_has_ran_once(kvm) ||
>> + kvm_pmu_fixed_counters_only(kvm) ||
>> (kvm->arch.pmu_filter && kvm->arch.arm_pmu != arm_pmu)) {
>> ret = -EBUSY;
>> break;
>> }
>>
>> + set_bit(KVM_ARCH_FLAG_PMU_V3_EXPLICIT, &kvm->arch.flags);
>> kvm_arm_set_pmu(kvm, arm_pmu);
>> cpumask_copy(kvm->arch.supported_cpus, &arm_pmu->supported_cpus);
>>
>> @@ -1205,6 +1207,22 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id)
>> return ret;
>> }
>>
>> +static int kvm_arm_pmu_v3_set_pmu_fixed_counters_only(struct kvm_vcpu *vcpu)
>> +{
>> + struct kvm *kvm = vcpu->kvm;
>> +
>> + lockdep_assert_held(&kvm->arch.config_lock);
>> +
>> + if (kvm_vm_has_ran_once(kvm) || kvm->arch.pmu_filter ||
>> + test_bit(KVM_ARCH_FLAG_PMU_V3_EXPLICIT, &kvm->arch.flags))
>> + return -EBUSY;
>> +
>> + set_bit(KVM_ARCH_FLAG_PMU_V3_FIXED_COUNTERS_ONLY, &kvm->arch.flags);
>> + kvm->arch.nr_pmu_counters = 0;
>> +
>> + return 0;
>> +}
>> +
>
> I'd rather that FIXED_COUNTERS_ONLY depend on the KVM_ARM_VCPU_PMU_V3_STRICT
> feature flag. The expectation of that flag is that userspace specifies a
> backing PMU implementation; your FIXED_COUNTERS_ONLY could just be seen
> as one such PMU implementation.
Hi Oliver,
Agreed. That will make the kernel code simpler by removing the need to
track explicit hardware PMU selection separately with
KVM_ARCH_FLAG_PMU_V3_EXPLICIT, since STRICT does not select a default
PMU. Hopefully, it will also make maintaining the code a bit easier by
reducing possible configuration combinations and encourage userspace to
use STRICT.
I'll make this change for v2.
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2026-09-22 9:14 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20 11:15 [PATCH v11 00/21] KVM: arm64: PMU: Use multiple host PMUs Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 01/21] KVM: arm64: Serialize repeated vCPU initialization Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 02/21] KVM: arm64: PMU: Stop updating MDCR_EL2.HPMN Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 03/21] KVM: arm64: PMU: Freeze counter count after first run Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 04/21] KVM: arm64: selftests: Test SET_NR_COUNTERS " Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 05/21] KVM: arm64: PMU: Mask EL2-reserved bits on guest bitmap reads Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 06/21] KVM: arm64: PMU: Keep implemented counter mask EL-independent Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 07/21] KVM: arm64: PMU: Preserve EL2 bitmap state during migration Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 08/21] Revert "KVM: arm64: PMU: Reload when resetting" Akihiko Odaki
2026-09-22 6:43 ` Oliver Upton
2026-09-22 7:05 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 09/21] KVM: arm64: PMU: Recreate events after MDCR_EL2 changes Akihiko Odaki
2026-09-22 6:54 ` Oliver Upton
2026-09-22 8:51 ` Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 10/21] KVM: arm64: PMU: Recreate events after PMCR_EL0 changes Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 11/21] KVM: arm64: PMU: Recreate events after userspace event writes Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 12/21] tools headers: Use u* types for bitfield helpers Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 13/21] KVM: arm64: selftests: Cover PMU state in MDCR_EL2 Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 14/21] arm64: errata: Require Apple IMPDEF PMUv3 traps on all CPUs Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 15/21] KVM: arm64: Don't clear vcpu->cpu in kvm_arch_vcpu_put() Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 16/21] KVM: arm64: PMU: Protect the list of PMUs with RCU Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 17/21] KVM: arm64: PMU: Pass the pPMU to kvm_map_pmu_event() Akihiko Odaki
2026-09-20 11:15 ` [PATCH v11 18/21] KVM: arm64: PMU: Pass the target CPU to kvm_pmu_probe_armpmu() Akihiko Odaki
2026-09-20 11:16 ` [PATCH v11 19/21] KVM: arm64: PMU: Implement fixed-counters-only emulation Akihiko Odaki
2026-09-20 11:16 ` [PATCH v11 20/21] KVM: arm64: PMU: Introduce FIXED_COUNTERS_ONLY Akihiko Odaki
2026-09-22 7:11 ` Oliver Upton
2026-09-22 9:13 ` Akihiko Odaki
2026-09-20 11:16 ` [PATCH v11 21/21] KVM: arm64: selftests: Test PMU_V3_FIXED_COUNTERS_ONLY Akihiko Odaki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®