* 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 2026-11-30 14:50 ` Leo Yan 0 siblings, 1 reply; 5+ 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] 5+ messages in thread
* Re: [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit 2026-11-30 13:17 ` [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li @ 2026-11-30 14:50 ` Leo Yan 0 siblings, 0 replies; 5+ messages in thread From: Leo Yan @ 2026-11-30 14:50 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 09:17:48PM +0800, Ping Li wrote: [...] > 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. I have different understanding for "inv_data_src_filter=0x8 also asks for sources 8-63 to be included". With 0x8, userspace asks only to exclude data source 3. A clear bit leaves the corresponding source eligible where supported, so I'd validate only the set bits in config4. Thanks, Leo ^ permalink raw reply [flat|nested] 5+ messages in thread
* [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 2/2] perf: arm_spe: Validate the data source filter per-bit Ping Li 0 siblings, 1 reply; 5+ 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] 5+ 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 2026-11-30 14:51 ` James Clark 0 siblings, 2 replies; 5+ 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] 5+ 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 2026-11-30 14:51 ` James Clark 1 sibling, 0 replies; 5+ 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] 5+ 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 @ 2026-11-30 14:51 ` James Clark 1 sibling, 0 replies; 5+ messages in thread From: James Clark @ 2026-11-30 14:51 UTC (permalink / raw) To: Ping Li, Leo Yan Cc: robh, linux-arm-kernel, linux-perf-users, linux-kernel, will, mark.rutland On 30/11/2026 06:13, Ping Li wrote: > 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. I'm not sure changing this this really fixes anything though? Now you're going to start rejecting events based on peoples existing filters, and if a filter bit isn't implemented, surely that must be because that data source value is never used on that CPU, so nobody would see any unexpected behavior anyway? If a CPU emitted a data source whose filter bit was RAZ/WI, enabling data source filtering would always discard that source, with no way to include it. There can't be real hardware with that limitation can there? I'm certain that the RAZ/WI part of the ARM exists because of data source that the CPU never emits, not because filtering them is unsupported. Say a user was doing something simple like excluding data source 3, they'd do filter == (1 << 3), which now gets rejected after inverting it because all the other bits are set, some of which are "unsupported". Publishing the supported data filter mask as a cap _might_ be useful, although nobody has ever asked for it. But this change looks like it's just "technically more correct" but not actually useful. > > 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), ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-30 14:51 UTC | newest]
Thread overview: 5+ 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 14:50 ` Leo Yan
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
2026-11-30 14:51 ` James Clark
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®