From: Vincent Donnefort <vdonnefort@google.com>
To: maz@kernel.org, oupton@kernel.org, kvmarm@lists.linux.dev,
linux-arm-kernel@lists.infradead.org
Cc: joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com,
yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org,
kernel-team@android.com, fuad.tabba@linux.dev,
Vincent Donnefort <vdonnefort@google.com>
Subject: [PATCH v1] KVM: arm64: Use the host kvm_host_data for nr_event_counters
Date: Fri, 23 Oct 2026 10:20:07 +0100 [thread overview]
Message-ID: <20261023092007.3918848-1-vdonnefort@google.com> (raw)
nr_event_counters is only used by the host to populate mdcr_el2.
However, host_data_ptr() for pKVM switches between the hypervisor copy
of kvm_host_data before it is deprivileged to the host copy after.
So kvm_init_host_debug_data() initialises nr_event_counters in the
hypervisor's kvm_host_data, while kvm_arm_setup_mdcr_el2() reads the
host copy which is 0. With a HPMN of 0, this stops programmable event
counters from counting a non-protected guest.
Always use the host copy for nr_event_counters.
Fixes: 2417218f2f23 ("KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts")
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
---
arch/arm64/kvm/debug.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
index f4d7b12045e8..a00771339c62 100644
--- a/arch/arm64/kvm/debug.c
+++ b/arch/arm64/kvm/debug.c
@@ -44,7 +44,7 @@ static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu)
* to disable guest access to the profiling and trace buffers
*/
vcpu->arch.mdcr_el2 = FIELD_PREP(MDCR_EL2_HPMN,
- *host_data_ptr(nr_event_counters));
+ __this_cpu_read(kvm_host_data.nr_event_counters));
vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM |
MDCR_EL2_TPMS |
MDCR_EL2_TTRF |
@@ -80,8 +80,8 @@ void kvm_init_host_debug_data(void)
ID_AA64DFR0_EL1_PMUVer_SHIFT);
if (pmuv3_implemented(pmuver))
- *host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
- read_sysreg(pmcr_el0));
+ __this_cpu_write(kvm_host_data.nr_event_counters,
+ FIELD_GET(ARMV8_PMU_PMCR_N, read_sysreg(pmcr_el0)));
*host_data_ptr(debug_brps) = SYS_FIELD_GET(ID_AA64DFR0_EL1, BRPs, dfr0);
*host_data_ptr(debug_wrps) = SYS_FIELD_GET(ID_AA64DFR0_EL1, WRPs, dfr0);
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
--
2.56.0.257.gf7497c7d27-goog
next reply other threads:[~2026-10-23 9:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 9:20 Vincent Donnefort [this message]
2026-10-23 12:29 ` [PATCH v1] KVM: arm64: Use the host kvm_host_data for nr_event_counters Fuad Tabba
2026-10-23 12:43 ` Marc Zyngier
2026-10-23 12:45 ` Fuad Tabba
2026-10-23 12:37 ` Marc Zyngier
2026-10-26 13:08 ` Vincent Donnefort
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261023092007.3918848-1-vdonnefort@google.com \
--to=vdonnefort@google.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox