* Re: [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit
[not found] <"20261130104035.GJ861809@e132581.arm.com">
@ 2026-11-30 13:17 ` Ping Li
0 siblings, 0 replies; 3+ messages in thread
From: Ping Li @ 2026-11-30 13:17 UTC (permalink / raw)
To: leo.yan
Cc: leeonion.muyu, will, mark.rutland, robh, james.clark,
linux-arm-kernel, linux-perf-users, linux-kernel
From: leeonion.muyu@gmail.com
Hi Leo,
Thanks for looking at this. I actually spent quite a while on the
direction when Sashiko first flagged it, so let me lay out my
reasoning with a concrete config - happy to reshape if I have
something wrong.
Assume an implementation where PMSDSFR_EL1 implements bits 0-7 and
bits 8-63 are RAZ/WI. Probing gives:
write 0xffffffffffffffff, read back 0x00000000000000ff
pmsdsfr_res0 = 0xffffffffffffff00
so bits 8-63 ignore writes and always read 0. Per DDI 0487 D17.5.4,
a sampled load with data source DS is "recorded only if
PMSDSFR_EL1[UInt(DS[5:0])] is 1", so while the filter is enabled,
sources 8-63 are never recorded.
Example: inv_data_src_filter=0x8 (exclude source 3, keep the rest)
config4 = 0x0000000000000008
written to PMSDSFR_EL1 = ~config4 = 0xfffffffffffffff7
reg & pmsdsfr_res0 = 0xfffffffffffffff7 & 0xffffffffffffff00
= 0xffffffffffffff00 != 0
-> current check rejects: perf_event_open() fails with
-EOPNOTSUPP
~reg & pmsdsfr_res0 = 0x0000000000000008 & 0xffffffffffffff00
= 0x0000000000000000 == 0
-> proposed check passes: the session runs, source 3 is
excluded as requested, but sources 8-63 are silently
missing although the config asked to include them
The crux is the bits the user never explicitly set: with the
inverted ABI, a cleared bit asks for the source to be included, so
inv_data_src_filter=0x8 also asks for sources 8-63 to be included,
and their bits are not implemented. That is what reg & pmsdsfr_res0
rejects, so the user knows up front instead of finding those
sources missing afterwards. (A set bit is always honoured for free,
and on a full implementation both checks are vacuous.)
What do you think about exposing ~pmsdsfr_res0 as a caps entry, as
you did for the event filter with caps/event_filter? The rejected
config then becomes actionable:
cat caps/data_src_filter # 0x00000000000000ff
perf record -e arm_spe_0/inv_data_src_filter=0xffffffffffffff08/
with 0xffffffffffffff08 = 0x8 | ~0xff - excluding source 3 and the
unfilterable sources, so it passes the check.
Happy to go with your preference if you see it differently.
Thanks,
Ping
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit
2026-11-30 6:13 ` [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li
@ 2026-11-30 10:40 ` Leo Yan
0 siblings, 0 replies; 3+ messages in thread
From: Leo Yan @ 2026-11-30 10:40 UTC (permalink / raw)
To: Ping Li
Cc: will, mark.rutland, robh, james.clark, linux-arm-kernel,
linux-perf-users, linux-kernel
On Mon, Nov 30, 2026 at 02:13:31PM +0800, Ping Li wrote:
[...]
> @@ -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;
Sashiko's comment seems reasonable:
"When userspace excludes a supported data source such as
inv_data_src_filter=0x1, bits 1..63 are 0 in config4 and 1 in reg, so
arm_spe_pmu_event_init() fails with -EOPNOTSUPP on any CPU with
unimplemented bits in PMSDSFR_EL1, and spe_pmu->pmsdsfr_res0 is not
exposed in sysfs caps/ for userspace to mask out. Conversely, a non-zero
config4 that only sets unimplemented RAZ/WI bits clears those bits in reg
and passes this check while enabling PMSFCR_EL1.FDS as a no-op filter.
Should this validate config4 (or ~reg) against spe_pmu->pmsdsfr_res0
instead?"
So, I'd update code and put comment directly above it:
/*
* Each set bit in config4 (~reg) requests a data source
* exclusion. Check for bits that lack filter support.
*/
if (~reg & spe_pmu->pmsdsfr_res0)
return -EOPNOTSUPP;
Thanks,
Leo
^ permalink raw reply [flat|nested] 3+ 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 ` Ping Li
2026-11-30 10:40 ` Leo Yan
0 siblings, 1 reply; 3+ 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 [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-30 13:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <"20261130104035.GJ861809@e132581.arm.com">
2026-11-30 13:17 ` [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li
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 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li
2026-11-30 10:40 ` Leo Yan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®