From: James Clark <james.clark@linaro.org>
To: Ping Li <leeonion.muyu@gmail.com>, Leo Yan <leo.yan@arm.com>
Cc: robh@kernel.org, linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
will@kernel.org, mark.rutland@arm.com
Subject: Re: [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit
Date: Mon, 30 Nov 2026 14:51:17 +0000 [thread overview]
Message-ID: <3dffa952-9430-4947-b2b9-9a826f1cc938@linaro.org> (raw)
In-Reply-To: <20261130061331.90095-3-leeonion.muyu@gmail.com>
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),
next prev parent reply other threads:[~2026-11-30 14:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 10:42 ` James Clark
2026-11-30 10:56 ` Leo Yan
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 message]
[not found] <"20261130104035.GJ861809@e132581.arm.com">
2026-11-30 13:17 ` Ping Li
2026-11-30 14:50 ` Leo Yan
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=3dffa952-9430-4947-b2b9-9a826f1cc938@linaro.org \
--to=james.clark@linaro.org \
--cc=leeonion.muyu@gmail.com \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh@kernel.org \
--cc=will@kernel.org \
/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 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®