[PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit

Ping Li leeonion.muyu at gmail.com
Mon Nov 30 05:17:48 PST 2026


From: leeonion.muyu at 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



More information about the linux-arm-kernel mailing list