Re: [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit
From: Leo Yan
Date: Mon Nov 30 2026 - 05:40:45 EST
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