From: Fuad Tabba <fuad.tabba@linux.dev>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Vincent Donnefort <vdonnefort@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <shuah@kernel.org>,
James Clark <james.clark@linaro.org>,
Fuad Tabba <tabba@google.com>
Subject: [PATCH 1/2] KVM: arm64: Don't copy the PMU registers between the host and hyp vCPU
Date: Fri, 4 Dec 2026 10:49:10 +0000 [thread overview]
Message-ID: <20261204104911.2797512-2-fuad.tabba@linux.dev> (raw)
In-Reply-To: <20261204104911.2797512-1-fuad.tabba@linux.dev>
The host emulates the PMU of a non-protected guest in pKVM, and EL2
doesn't access the guest's PMU registers in the hyp vCPU. Lazy state
sync copies them anyway.
Since commit 8ee90ca40b10c ("KVM: arm64: Pass the PMU events to the hyp
vCPU of non-protected guests") the guest's counters count, and the perf
overflow handler sets an overflowing counter's bit in the host's copy of
PMOVSSET_EL0 before the host has synced the guest's state. The next sync
overwrites it with the hyp vCPU's stale copy, so the guest takes no
overflow interrupt, or takes it with the overflow bit clear.
Leave the PMU registers out of the copy, like we do for the timer
registers.
Fixes: 734dc8c01c838 ("KVM: arm64: Implement lazy vCPU state sync for non-protected guests")
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 0c023ee0cf42a..2d0401a94246b 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -627,7 +627,7 @@ static void __copy_vcpu_state(const struct kvm_vcpu *from_vcpu,
to_vcpu->arch.ctxt.fp_regs = from_vcpu->arch.ctxt.fp_regs;
/*
- * Copy the sysregs, but don't mess with the timer state which
+ * Copy the sysregs, but don't mess with the timer and PMU state which
* is directly handled by EL1 and is expected to be preserved.
* enum vcpu_sysreg is sparse: VNCR-mapped registers take values
* derived from their VNCR page offset, so the timer registers do
@@ -640,6 +640,16 @@ static void __copy_vcpu_state(const struct kvm_vcpu *from_vcpu,
case CNTV_CTL_EL0:
case CNTP_CVAL_EL0:
case CNTP_CTL_EL0:
+ case PMCR_EL0:
+ case PMSELR_EL0:
+ case PMEVCNTR0_EL0 ... PMEVCNTR30_EL0:
+ case PMCCNTR_EL0:
+ case PMEVTYPER0_EL0 ... PMEVTYPER30_EL0:
+ case PMCCFILTR_EL0:
+ case PMCNTENSET_EL0:
+ case PMINTENSET_EL1:
+ case PMOVSSET_EL0:
+ case PMUSERENR_EL0:
continue;
}
to_vcpu->arch.ctxt.sys_regs[i] = from_vcpu->arch.ctxt.sys_regs[i];
--
2.47.3
next prev parent reply other threads:[~2026-12-04 10:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:49 [PATCH 0/2] KVM: arm64: Fix PMU counter overflows for non-protected guests in pKVM Fuad Tabba
2026-12-04 10:49 ` Fuad Tabba [this message]
2026-12-04 10:49 ` [PATCH 2/2] KVM: arm64: selftests: Test PMU counter overflow in vpmu_counter_access Fuad Tabba
2026-12-04 11:06 ` sashiko-bot
2026-12-04 11:55 ` Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204104911.2797512-2-fuad.tabba@linux.dev \
--to=fuad.tabba@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=james.clark@linaro.org \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=vdonnefort@google.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