From: Reiji Watanabe <reijiw@google.com>
To: Marc Zyngier <maz@kernel.org>,
Oliver Upton <oliver.upton@linux.dev>,
kvmarm@lists.linux.dev
Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Jing Zhang <jingzhangos@google.com>,
Raghavendra Rao Anata <rananta@google.com>,
Reiji Watanabe <reijiw@google.com>
Subject: [PATCH 1/2] KVM: arm64: PMU: Introduce pmu_v3_is_supported() helper
Date: Fri, 9 Jun 2023 23:15:19 -0700 [thread overview]
Message-ID: <20230610061520.3026530-2-reijiw@google.com> (raw)
In-Reply-To: <20230610061520.3026530-1-reijiw@google.com>
Introduce pmu_v3_is_supported() helper to check if the given
PMUVer supports PMUv3, and use it instead of open coding it.
Signed-off-by: Reiji Watanabe <reijiw@google.com>
---
arch/arm64/kvm/pmu-emul.c | 3 +--
arch/arm64/kvm/sys_regs.c | 2 +-
include/kvm/arm_pmu.h | 8 ++++++++
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 491ca7eb2a4c..5d2903f52a5f 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -672,8 +672,7 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
{
struct arm_pmu_entry *entry;
- if (pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_NI ||
- pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
+ if (!pmu_v3_is_supported(pmu->pmuver))
return;
mutex_lock(&arm_pmus_lock);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 753aa7418149..9200b18127f6 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1408,7 +1408,7 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu,
if ((pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF && pmuver > host_pmuver))
return -EINVAL;
- valid_pmu = (pmuver != 0 && pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF);
+ valid_pmu = pmu_v3_is_supported(pmuver);
/* Make sure view register and PMU support do match */
if (kvm_vcpu_has_pmu(vcpu) != valid_pmu)
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 1a6a695ca67a..eef17de966da 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -12,6 +12,14 @@
#define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1)
+static inline bool pmu_v3_is_supported(int pmuver)
+{
+ WARN_ON_ONCE(pmuver & ~GENMASK_ULL(ARM64_FEATURE_FIELD_BITS - 1, 0));
+
+ return (pmuver != ID_AA64DFR0_EL1_PMUVer_NI) &&
+ (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF);
+}
+
#ifdef CONFIG_HW_PERF_EVENTS
struct kvm_pmc {
--
2.41.0.162.gfafddb0af9-goog
WARNING: multiple messages have this Message-ID (diff)
From: Reiji Watanabe <reijiw@google.com>
To: Marc Zyngier <maz@kernel.org>,
Oliver Upton <oliver.upton@linux.dev>,
kvmarm@lists.linux.dev
Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Jing Zhang <jingzhangos@google.com>,
Raghavendra Rao Anata <rananta@google.com>,
Reiji Watanabe <reijiw@google.com>
Subject: [PATCH 1/2] KVM: arm64: PMU: Introduce pmu_v3_is_supported() helper
Date: Fri, 9 Jun 2023 23:15:19 -0700 [thread overview]
Message-ID: <20230610061520.3026530-2-reijiw@google.com> (raw)
In-Reply-To: <20230610061520.3026530-1-reijiw@google.com>
Introduce pmu_v3_is_supported() helper to check if the given
PMUVer supports PMUv3, and use it instead of open coding it.
Signed-off-by: Reiji Watanabe <reijiw@google.com>
---
arch/arm64/kvm/pmu-emul.c | 3 +--
arch/arm64/kvm/sys_regs.c | 2 +-
include/kvm/arm_pmu.h | 8 ++++++++
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 491ca7eb2a4c..5d2903f52a5f 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -672,8 +672,7 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
{
struct arm_pmu_entry *entry;
- if (pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_NI ||
- pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
+ if (!pmu_v3_is_supported(pmu->pmuver))
return;
mutex_lock(&arm_pmus_lock);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 753aa7418149..9200b18127f6 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1408,7 +1408,7 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu,
if ((pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF && pmuver > host_pmuver))
return -EINVAL;
- valid_pmu = (pmuver != 0 && pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF);
+ valid_pmu = pmu_v3_is_supported(pmuver);
/* Make sure view register and PMU support do match */
if (kvm_vcpu_has_pmu(vcpu) != valid_pmu)
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 1a6a695ca67a..eef17de966da 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -12,6 +12,14 @@
#define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1)
+static inline bool pmu_v3_is_supported(int pmuver)
+{
+ WARN_ON_ONCE(pmuver & ~GENMASK_ULL(ARM64_FEATURE_FIELD_BITS - 1, 0));
+
+ return (pmuver != ID_AA64DFR0_EL1_PMUVer_NI) &&
+ (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF);
+}
+
#ifdef CONFIG_HW_PERF_EVENTS
struct kvm_pmc {
--
2.41.0.162.gfafddb0af9-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-06-10 6:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-10 6:15 [PATCH 0/2] KVM: arm64: PMU: Disallow vPMU on non-uniform PMUVer systems Reiji Watanabe
2023-06-10 6:15 ` Reiji Watanabe
2023-06-10 6:15 ` Reiji Watanabe [this message]
2023-06-10 6:15 ` [PATCH 1/2] KVM: arm64: PMU: Introduce pmu_v3_is_supported() helper Reiji Watanabe
2023-06-11 1:10 ` Oliver Upton
2023-06-10 6:15 ` [PATCH 2/2] KVM: arm64: PMU: Disallow vPMU on non-uniform PMUVer systems Reiji Watanabe
2023-06-10 6:15 ` Reiji Watanabe
2023-06-11 2:32 ` Oliver Upton
2023-06-11 5:03 ` Reiji Watanabe
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=20230610061520.3026530-2-reijiw@google.com \
--to=reijiw@google.com \
--cc=alexandru.elisei@arm.com \
--cc=james.morse@arm.com \
--cc=jingzhangos@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=rananta@google.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.