From nobody Tue Feb 10 22:00:09 2026 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A952531A576 for ; Mon, 9 Feb 2026 22:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770676856; cv=none; b=Qy/k1FPklC9NhV0nLvVldvnlt4U3Ibd/ha0wUuPikRciXfPl2z9NeqSUK5ASfagTeDTdhJI/qwqQTlrR8LKZfIwnA6j/JMrxg/3dXy8c7JMEzCOhauDRm0RIuZC12Ml8Dbt45NqjvUhCyG9bhN5E6ygCRlm2vh8j0zQqiMa4D+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770676856; c=relaxed/simple; bh=B9HZV/XvGCtJKEIzSCyXAxqSnw0EEFic83RP1XipC3Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ri179eBtk91rMIgYwso4F1fnV2mI8fJioSDznrgZv8MCyaT47fCCrTT+eugDkzIj1bnWjmzunxizWW3t9HAGqIswpTOkiL/K3I8TNDKdtbd+x8IccBeQ4selLV55k478Dyu4u0oRDd8UfnfjWsR7AP1IOCoLo6hvI2ldhwoEzz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NnzDkZsd; arc=none smtp.client-ip=209.85.210.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NnzDkZsd" Received: by mail-ot1-f74.google.com with SMTP id 46e09a7af769-7d496d080d8so1811611a34.0 for ; Mon, 09 Feb 2026 14:40:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770676852; x=1771281652; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nily0rEh3mmY4uvAeTjqDVW7kEcYRK1QYtsSJT+aPhk=; b=NnzDkZsdRLMTlHa1swP5Z/JorSQFqooN1864sOw2+uAjnPSBEswKJaMg8TA+qw52ye MpOnat3IAmj/gBBsPdM1dBaEvdKS32+Dm80ECCaL1tcby+2ksjylQ9XIAXYbIiDbBu5X 7JzB+lgSgl4NPkMD+Qj3odeKBGp6FjqhzJ8hYlOhnwUbeUNoVZ/k+AbYveWeMCOlkcqF KprLqhMyPqQt9DAr7O8cZod1P0vLamAuVywNZyX958GK0fVU8U0igL4u9uVFjl+wcQrI eS1mZ159iT2LPJXOKSJhbYP9d+giiwI4/IrgteNWXIC8OF13nOLeA0VgDm1fFZ5A2Bwa dUeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770676852; x=1771281652; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nily0rEh3mmY4uvAeTjqDVW7kEcYRK1QYtsSJT+aPhk=; b=PlJSV2VLZecJfDRPp3M4krNPJriCpR9aHzrbYu4B+ReGG4o+k9Ssm0YR5s6FZoUF2X B2QWV3MHkLuGcv6UQaWRmNChHn6zUCMNNo7m51z3fVnVe8nAwQXaTPUvpD/A8YmrrwBx g0DmtvHit6oX/FGHJk+8H9IHzV9DmEaN0oI2xkjMyJPa8JjcTbsWzxG9YwY+/I5xGD8F cL7PU+eNhptGCaBHf5ANdHZCFNHicI1qFHtIJYfcz6UAf9+cA+66KMVjmSDdv0Lwcuzh d6ZSUn/j3e9S2pPAhkdmEFh4CdlWwPu9Pd2OeVZvrA17PrgIiz3jvIoQ/0Af7MPQ5LUi oE6Q== X-Forwarded-Encrypted: i=1; AJvYcCXwpBwAyE8PIF4S4HEU9IOZyJlYucpCNHmovOOmEgkekjuB+mHGQ57jg81jdqslfBvGwsUr3k6LPDYrBS0=@vger.kernel.org X-Gm-Message-State: AOJu0YxClcNU083xZEVSdYEsFI6dVZ0TzveJPXN5gfiGVAw0D1cE3PjK HyRB0N2ex4zDNMBWGgXEDTOJXEXr0lGJ4g/MhcMY7e0SqT6VyDo+qtmX0Eb2svBBjGquojrDSRl AVV36J44c83Pj2NKDBE5iRJ1mow== X-Received: from iobbx7.prod.google.com ([2002:a05:6602:4187:b0:957:50e1:3858]) (user=coltonlewis job=prod-delivery.src-stubby-dispatcher) by 2002:a4a:e902:0:b0:66f:6d5e:76c3 with SMTP id 006d021491bc7-672fff0af95mr60439eaf.42.1770676852384; Mon, 09 Feb 2026 14:40:52 -0800 (PST) Date: Mon, 9 Feb 2026 22:14:03 +0000 In-Reply-To: <20260209221414.2169465-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260209221414.2169465-1-coltonlewis@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260209221414.2169465-9-coltonlewis@google.com> Subject: [PATCH v6 08/19] KVM: arm64: Define access helpers for PMUSERENR and PMSELR From: Colton Lewis To: kvm@vger.kernel.org Cc: Alexandru Elisei , Paolo Bonzini , Jonathan Corbet , Russell King , Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Mingwei Zhang , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Mark Rutland , Shuah Khan , Ganapatrao Kulkarni , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, Colton Lewis Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to ensure register permission checks will have consistent results whether or not the PMU is partitioned, define some access helpers for PMUSERENR and PMSELR that always return the canonical value for those registers, whether it lives in a physical or virtual register. Signed-off-by: Colton Lewis --- arch/arm64/kvm/pmu.c | 16 ++++++++++++++++ arch/arm64/kvm/sys_regs.c | 6 +++--- include/kvm/arm_pmu.h | 12 ++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/pmu.c b/arch/arm64/kvm/pmu.c index 74a5d35edb244..344ed9d8329a6 100644 --- a/arch/arm64/kvm/pmu.c +++ b/arch/arm64/kvm/pmu.c @@ -885,3 +885,19 @@ u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu) =20 return u64_replace_bits(pmcr, n, ARMV8_PMU_PMCR_N); } + +u64 kvm_vcpu_read_pmselr(struct kvm_vcpu *vcpu) +{ + if (kvm_vcpu_pmu_is_partitioned(vcpu)) + return read_sysreg(pmselr_el0); + else + return __vcpu_sys_reg(vcpu, PMSELR_EL0); +} + +u64 kvm_vcpu_read_pmuserenr(struct kvm_vcpu *vcpu) +{ + if (kvm_vcpu_pmu_is_partitioned(vcpu)) + return read_sysreg(pmuserenr_el0); + else + return __vcpu_sys_reg(vcpu, PMUSERENR_EL0); +} diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index a460e93b1ad0a..9e893859a41c9 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -987,7 +987,7 @@ static u64 reset_pmcr(struct kvm_vcpu *vcpu, const stru= ct sys_reg_desc *r) =20 static bool check_pmu_access_disabled(struct kvm_vcpu *vcpu, u64 flags) { - u64 reg =3D __vcpu_sys_reg(vcpu, PMUSERENR_EL0); + u64 reg =3D kvm_vcpu_read_pmuserenr(vcpu); bool enabled =3D (reg & flags) || vcpu_mode_priv(vcpu); =20 if (!enabled) @@ -1141,7 +1141,7 @@ static bool access_pmu_evcntr(struct kvm_vcpu *vcpu, return false; =20 idx =3D SYS_FIELD_GET(PMSELR_EL0, SEL, - __vcpu_sys_reg(vcpu, PMSELR_EL0)); + kvm_vcpu_read_pmselr(vcpu)); } else if (r->Op2 =3D=3D 0) { /* PMCCNTR_EL0 */ if (pmu_access_cycle_counter_el0_disabled(vcpu)) @@ -1191,7 +1191,7 @@ static bool access_pmu_evtyper(struct kvm_vcpu *vcpu,= struct sys_reg_params *p, =20 if (r->CRn =3D=3D 9 && r->CRm =3D=3D 13 && r->Op2 =3D=3D 1) { /* PMXEVTYPER_EL0 */ - idx =3D SYS_FIELD_GET(PMSELR_EL0, SEL, __vcpu_sys_reg(vcpu, PMSELR_EL0)); + idx =3D SYS_FIELD_GET(PMSELR_EL0, SEL, kvm_vcpu_read_pmselr(vcpu)); reg =3D PMEVTYPER0_EL0 + idx; } else if (r->CRn =3D=3D 14 && (r->CRm & 12) =3D=3D 12) { idx =3D ((r->CRm & 3) << 3) | (r->Op2 & 7); diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 50983cdbec045..f21439000129b 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -130,6 +130,8 @@ int kvm_arm_set_default_pmu(struct kvm *kvm); u8 kvm_arm_pmu_get_max_counters(struct kvm *kvm); =20 u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu); +u64 kvm_vcpu_read_pmselr(struct kvm_vcpu *vcpu); +u64 kvm_vcpu_read_pmuserenr(struct kvm_vcpu *vcpu); bool kvm_pmu_counter_is_hyp(struct kvm_vcpu *vcpu, unsigned int idx); void kvm_pmu_nested_transition(struct kvm_vcpu *vcpu); #else @@ -250,6 +252,16 @@ static inline u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *= vcpu) return 0; } =20 +static inline u64 kvm_vcpu_read_pmselr(struct kvm_vcpu *vcpu) +{ + return 0; +} + +static u64 kvm_vcpu_read_pmuserenr(struct kvm_vcpu *vcpu) +{ + return 0; +} + static inline bool kvm_pmu_counter_is_hyp(struct kvm_vcpu *vcpu, unsigned = int idx) { return false; --=20 2.53.0.rc2.204.g2597b5adb4-goog