Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@kernel.org>
To: kvmarm@lists.linux.dev
Cc: Marc Zyngier <maz@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Congkai Tan <congkai@amazon.com>,
	Oliver Upton <oupton@kernel.org>
Subject: [PATCH] KVM: arm64: Drop pointless check for EL0 access to PMINTEN*_EL1
Date: Mon,  1 Jun 2026 13:24:56 -0700	[thread overview]
Message-ID: <20260601202456.14513-1-oupton@kernel.org> (raw)

The PMINTEN*_EL1 registers are UNDEF at EL0, meaning that KVM should
never take a trap from guest EL0. Get rid of the pointless check and
rephrase the vaguely-named helper in terms of PMUSERENR.

Signed-off-by: Oliver Upton <oupton@kernel.org>
---
 arch/arm64/kvm/sys_regs.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 148fc3400ea8..51154d8b607c 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1070,35 +1070,36 @@ static u64 reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 	return __vcpu_sys_reg(vcpu, r->reg);
 }
 
-static bool check_pmu_access_disabled(struct kvm_vcpu *vcpu, u64 flags)
+static bool __check_pmuserenr(struct kvm_vcpu *vcpu, u64 flags)
 {
 	u64 reg = __vcpu_sys_reg(vcpu, PMUSERENR_EL0);
-	bool enabled = (reg & flags) || vcpu_mode_priv(vcpu);
 
-	if (!enabled)
-		kvm_inject_undefined(vcpu);
+	/* As the name implies, PMUSERENR_EL0 only applies to accesses from EL0. */
+	if (vcpu_mode_priv(vcpu) || (reg & flags))
+		return false;
 
-	return !enabled;
+	kvm_inject_undefined(vcpu);
+	return true;
 }
 
 static bool pmu_access_el0_disabled(struct kvm_vcpu *vcpu)
 {
-	return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_EN);
+	return __check_pmuserenr(vcpu, ARMV8_PMU_USERENR_EN);
 }
 
 static bool pmu_write_swinc_el0_disabled(struct kvm_vcpu *vcpu)
 {
-	return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_SW | ARMV8_PMU_USERENR_EN);
+	return __check_pmuserenr(vcpu, ARMV8_PMU_USERENR_SW | ARMV8_PMU_USERENR_EN);
 }
 
 static bool pmu_access_cycle_counter_el0_disabled(struct kvm_vcpu *vcpu)
 {
-	return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_CR | ARMV8_PMU_USERENR_EN);
+	return __check_pmuserenr(vcpu, ARMV8_PMU_USERENR_CR | ARMV8_PMU_USERENR_EN);
 }
 
 static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu)
 {
-	return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_ER | ARMV8_PMU_USERENR_EN);
+	return __check_pmuserenr(vcpu, ARMV8_PMU_USERENR_ER | ARMV8_PMU_USERENR_EN);
 }
 
 static bool access_pmcr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
@@ -1351,9 +1352,6 @@ static bool access_pminten(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
 {
 	u64 mask = kvm_pmu_accessible_counter_mask(vcpu);
 
-	if (check_pmu_access_disabled(vcpu, 0))
-		return false;
-
 	if (p->is_write) {
 		u64 val = p->regval & mask;
 

base-commit: 5d6919055dec134de3c40167a490f33c74c12581
-- 
2.47.3


                 reply	other threads:[~2026-06-01 20:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260601202456.14513-1-oupton@kernel.org \
    --to=oupton@kernel.org \
    --cc=congkai@amazon.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --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