Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit
@ 2026-11-30  6:13 Ping Li
  2026-11-30  6:13 ` [PATCH v2 1/2] perf: arm_spe: Validate the inverse event filter against PMSNEVFR_EL1 Ping Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ping Li @ 2026-11-30  6:13 UTC (permalink / raw)
  To: will, mark.rutland
  Cc: robh, leo.yan, james.clark, linux-arm-kernel, linux-perf-users,
	linux-kernel, Ping Li

Probe the supported filter bits of PMSNEVFR_EL1 and PMSDSFR_EL1
separately instead of reusing the mask probed from PMSEVFR_EL1, and
validate the inverse event filter and the data source filter against
their own masks.

Runtime-tested on Cortex-A78AE (SPEv1.0, which implements neither
FnE nor FDS) and on Cortex-A720AE (SPEv1.2, which implements FnE
but not FDS): the PMU probes cleanly with the per-register
discovery in place, event filter configs are validated per-bit
against the probed masks with unimplemented bits rejected using
-EOPNOTSUPP, and sampling is unaffected. Only the FDS path lacks
coverage on hardware implementing the feature.

Changes in v2:
- Split into two patches so each fix can be backported
  independently (Leo Yan).
- Reword the PMSNEVFR_EL1 motivation: implementations are expected
  to use the same bit positions, the practical benefit of the early
  mask check is reporting the error at the first opportunity when
  FEAT_INV_FILT_EVT is absent (Leo Yan).
- Group the data source filter check with the FDS presence check so
  that config4 is only validated when the filter is in use (Leo
  Yan).
- Drop the Tested-by tag (Leo Yan).

Ping Li (2):
  perf: arm_spe: Validate the inverse event filter against PMSNEVFR_EL1
  perf: arm_spe: Validate the data source filter per-bit

 drivers/perf/arm_spe_pmu.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] perf: arm_spe: Validate the inverse event filter against PMSNEVFR_EL1
  2026-11-30  6:13 [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit Ping Li
@ 2026-11-30  6:13 ` Ping Li
  2026-11-30  6:13 ` [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li
  2026-11-30  6:24 ` [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: Ping Li @ 2026-11-30  6:13 UTC (permalink / raw)
  To: will, mark.rutland
  Cc: robh, leo.yan, james.clark, linux-arm-kernel, linux-perf-users,
	linux-kernel, Ping Li

config3 is validated against the mask probed from PMSEVFR_EL1, even
though it is written verbatim to PMSNEVFR_EL1. Implementations are
expected to use the same bit positions for the two registers, but the
borrowed mask also lets an invalid config pass the early check when
FEAT_INV_FILT_EVT is absent, deferring the error to the later
PMSFCR_EL1.FnE feature check.

Probe the supported filter bits of PMSNEVFR_EL1 separately and
validate config3 against its own mask. Keep a full mask when the
feature is not implemented so that any attempt to use the inverse
event filter is rejected at the earliest opportunity.

Fixes: 8d9190f00a975 ("perf: arm_spe: Add support for SPEv1.2 inverted event filtering")
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/perf/arm_spe_pmu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index 707778c67dab..0b1a088bb7c7 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -92,6 +92,7 @@ struct arm_spe_pmu {
 	u64					features;
 
 	u64					pmsevfr_res0;
+	u64					pmsnevfr_res0;
 	u16					max_record_sz;
 	u16					align;
 	struct perf_output_handle __percpu	*handle;
@@ -818,7 +819,7 @@ static int arm_spe_pmu_event_init(struct perf_event *event)
 	if (arm_spe_event_to_pmsevfr(event) & spe_pmu->pmsevfr_res0)
 		return -EOPNOTSUPP;
 
-	if (arm_spe_event_to_pmsnevfr(event) & spe_pmu->pmsevfr_res0)
+	if (arm_spe_event_to_pmsnevfr(event) & spe_pmu->pmsnevfr_res0)
 		return -EOPNOTSUPP;
 
 	if (arm_spe_event_to_pmsdsfr(event) != U64_MAX &&
@@ -1228,6 +1229,13 @@ static void __arm_spe_pmu_dev_probe(void *info)
 	write_sysreg_s(U64_MAX, SYS_PMSEVFR_EL1);
 	spe_pmu->pmsevfr_res0 = ~read_sysreg_s(SYS_PMSEVFR_EL1);
 
+	if (spe_pmu->features & SPE_PMU_FEAT_INV_FILT_EVT) {
+		write_sysreg_s(U64_MAX, SYS_PMSNEVFR_EL1);
+		spe_pmu->pmsnevfr_res0 = ~read_sysreg_s(SYS_PMSNEVFR_EL1);
+	} else {
+		spe_pmu->pmsnevfr_res0 = U64_MAX;
+	}
+
 	dev_info(dev,
 		 "probed SPEv1.%d for CPUs %*pbl [max_record_sz %u, align %u, features 0x%llx]\n",
 		 spe_pmu->pmsver - 1, cpumask_pr_args(&spe_pmu->supported_cpus),
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit
  2026-11-30  6:13 [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit Ping Li
  2026-11-30  6:13 ` [PATCH v2 1/2] perf: arm_spe: Validate the inverse event filter against PMSNEVFR_EL1 Ping Li
@ 2026-11-30  6:13 ` Ping Li
  2026-11-30  6:24 ` [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: Ping Li @ 2026-11-30  6:13 UTC (permalink / raw)
  To: will, mark.rutland
  Cc: robh, leo.yan, james.clark, linux-arm-kernel, linux-perf-users,
	linux-kernel, Ping Li

The data source filter (config4) is only checked for the presence of
the FDS feature and never validated per-bit, so a config asking to
filter on data sources the hardware does not support is accepted.

PMSDSFR_EL1 is an inclusion mask which the driver exposes inverted:
a set config4 bit requests that a data source is excluded, a cleared
bit requests that it is included. Unsupported filter bits are RAZ/WI
(Arm ARM DDI 0487 M.b, D24.7.10), so they are stuck at 0: exclusion
requests are always honoured, but requests to include an unsupported
data source are silently dropped while the filter is active.

Probe the supported filter bits of PMSDSFR_EL1 when FDS is
implemented and reject configs which ask to include an unsupported
data source. Group the check with the FDS presence check so that
config4 is only validated when the filter is in use. Keep a full
mask when the feature is not implemented so that the field cannot
be misread as 'all bits supported'.

Fixes: e6a27290d800 ("perf: arm_spe: Add support for filtering on data source")
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
 drivers/perf/arm_spe_pmu.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index 0b1a088bb7c7..a0d0caf75145 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -93,6 +93,7 @@ struct arm_spe_pmu {
 
 	u64					pmsevfr_res0;
 	u64					pmsnevfr_res0;
+	u64					pmsdsfr_res0;
 	u16					max_record_sz;
 	u16					align;
 	struct perf_output_handle __percpu	*handle;
@@ -822,9 +823,19 @@ static int arm_spe_pmu_event_init(struct perf_event *event)
 	if (arm_spe_event_to_pmsnevfr(event) & spe_pmu->pmsnevfr_res0)
 		return -EOPNOTSUPP;
 
-	if (arm_spe_event_to_pmsdsfr(event) != U64_MAX &&
-	    !(spe_pmu->features & SPE_PMU_FEAT_FDS))
-		return -EOPNOTSUPP;
+	/*
+	 * The data source filter is exposed inverted, so validate the
+	 * value written to PMSDSFR_EL1 (~config4) rather than config4
+	 * itself.
+	 */
+	reg = arm_spe_event_to_pmsdsfr(event);
+	if (reg != U64_MAX) {
+		if (!(spe_pmu->features & SPE_PMU_FEAT_FDS))
+			return -EOPNOTSUPP;
+
+		if (reg & spe_pmu->pmsdsfr_res0)
+			return -EOPNOTSUPP;
+	}
 
 	if (attr->exclude_idle)
 		return -EOPNOTSUPP;
@@ -1236,6 +1247,13 @@ static void __arm_spe_pmu_dev_probe(void *info)
 		spe_pmu->pmsnevfr_res0 = U64_MAX;
 	}
 
+	if (spe_pmu->features & SPE_PMU_FEAT_FDS) {
+		write_sysreg_s(U64_MAX, SYS_PMSDSFR_EL1);
+		spe_pmu->pmsdsfr_res0 = ~read_sysreg_s(SYS_PMSDSFR_EL1);
+	} else {
+		spe_pmu->pmsdsfr_res0 = U64_MAX;
+	}
+
 	dev_info(dev,
 		 "probed SPEv1.%d for CPUs %*pbl [max_record_sz %u, align %u, features 0x%llx]\n",
 		 spe_pmu->pmsver - 1, cpumask_pr_args(&spe_pmu->supported_cpus),
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit
  2026-11-30  6:13 [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit Ping Li
  2026-11-30  6:13 ` [PATCH v2 1/2] perf: arm_spe: Validate the inverse event filter against PMSNEVFR_EL1 Ping Li
  2026-11-30  6:13 ` [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li
@ 2026-11-30  6:24 ` sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-30  6:24 UTC (permalink / raw)
  To: Ping Li; +Cc: linux-perf-users

Sashiko has finished reviewing this 2-patch series:

- Patch 1: no issues found.
- Patch 2 ("perf: arm_spe: Validate the data source filter per-bit"): 1
  potential issue (1 High)

A detailed review has been sent as a separate reply to patch 2.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130061331.90095-1-leeonion.muyu@gmail.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30  6:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  6:13 [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit Ping Li
2026-11-30  6:13 ` [PATCH v2 1/2] perf: arm_spe: Validate the inverse event filter against PMSNEVFR_EL1 Ping Li
2026-11-30  6:13 ` [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li
2026-11-30  6:24 ` [PATCH v2 0/2] perf: arm_spe: Validate the filter configs per-bit sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox