Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dapeng Mi" <dapeng1.mi@linux.intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [Patch v10 05/10] perf regs: Support x86 eGPRs/SSP sampling
Date: Tue, 21 Jul 2026 07:52:09 +0000	[thread overview]
Message-ID: <20260721075209.EC4A41F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260721072707.3787848-6-dapeng1.mi@linux.intel.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Hardcoded 32-byte SIMD header skip in `__evsel__parse_sample` corrupts parsing of future `perf.data` files containing actual SIMD data payloads.
- [High] `perf_event__synthesize_sample` fails to write the SIMD register header, leading to uninitialized memory leaks and corruption of synthesized events.
- [High] Silently substituting requested eGPRs with legacy XMM registers on non-hardware events.
--

--- Patch [5]: [Patch v10 05/10] perf regs: Support x86 eGPRs/SSP sampling ---
commit 8930556b90beb6ec5b6f4e43ddaf5145e6dda06d
Author: Dapeng Mi <dapeng1.mi@linux.intel.com>

perf regs: Support x86 eGPRs/SSP sampling

This commit adds support for sampling x86 extended GP registers (R16-R31)
and the shadow stack pointer (SSP) register. It reclaims the original XMM
registers space in the sampling masks to represent eGPRs and SSP when SIMD
sampling is supported, distinguishing them with a new abi flag.

> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index a5b0687a3a79f..da0ad06446091 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c

[ ... ]

> @@ -1661,12 +1664,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,
>  	if (opts->sample_intr_regs && !evsel->no_aux_samples &&
>  	    !evsel__is_dummy_event(evsel)) {
>  		attr->sample_regs_intr = opts->sample_intr_regs;
> +		attr->sample_simd_regs_enabled = evsel__is_hardware_event(evsel) ?
> +				!!opts->sample_simd_regs_enabled : 0;

[Severity: High]
Does clearing the sample_simd_regs_enabled flag for non-hardware events
cause the kernel to misinterpret the bits as legacy XMM requests?

If a user requests sampling of eGPRs on a software event, this flag is
forcibly cleared, but the opts->sample_intr_regs bitmask is preserved.
Because eGPR definitions alias legacy XMM definitions, wouldn't the kernel
see the bits set alongside sample_simd_regs_enabled = 0 and dump legacy XMM
data instead?

The tool might then read it back without the SIMD ABI flag and print it as
XMM, silently losing the user's intent to capture eGPRs. Should the
aliasing eGPR bits be masked out from the sample_regs mask when clearing
the SIMD flag?

>  		evsel__set_sample_bit(evsel, REGS_INTR);
>  	}
>  
>  	if (opts->sample_user_regs && !evsel->no_aux_samples &&
>  	    !evsel__is_dummy_event(evsel)) {
>  		attr->sample_regs_user |= opts->sample_user_regs;
> +		attr->sample_simd_regs_enabled = evsel__is_hardware_event(evsel) ?
> +				!!opts->sample_simd_regs_enabled : 0;

[Severity: High]
This seems to have the same aliasing issue as above where eGPR requests on
non-hardware events will be silently interpreted as legacy XMM registers.

>  		evsel__set_sample_bit(evsel, REGS_USER);
>  	}

[ ... ]

> @@ -3679,6 +3686,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event,
>  			regs->mask = mask;
>  			regs->regs = (u64 *)array;
>  			array = (void *)array + sz;
> +
> +			if (regs->abi & PERF_SAMPLE_REGS_ABI_SIMD) {
> +				/* Skip SIMD-regs header. */
> +				sz = 4 * sizeof(u64);
> +				OVERFLOW_CHECK(array, sz, max_size);
> +				array = (void *)array + sz;
> +			}
>  		}
>  	}

[Severity: High]
Will this hardcoded 32-byte header skip corrupt parsing for files containing
actual SIMD data payloads?

The parser unconditionally skips exactly 4 u64s for the SIMD header, but it
doesn't dynamically compute and skip the variable-length SIMD payload that
might follow it in future files. This would misalign the array pointer for
subsequent fields like STACK_USER, causing garbage reads and triggering
OVERFLOW_CHECK aborts.

[ ... ]

> @@ -3736,6 +3750,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event,
>  			regs->mask = mask;
>  			regs->regs = (u64 *)array;
>  			array = (void *)array + sz;
> +
> +			if (regs->abi & PERF_SAMPLE_REGS_ABI_SIMD) {
> +				/* Skip SIMD-regs header. */
> +				sz = 4 * sizeof(u64);
> +				OVERFLOW_CHECK(array, sz, max_size);
> +				array = (void *)array + sz;
> +			}
>  		}
>  	}

[Severity: High]
This appears to have the same issue with skipping the SIMD header without
handling the variable-length payload.

> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index b75f9dcf4dbfe..503a239b0b10f 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -1527,6 +1527,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
>  		if (sample->user_regs && sample->user_regs->abi) {
>  			result += sizeof(u64);
>  			sz = hweight64(sample->user_regs->mask) * sizeof(u64);
> +			if (sample->user_regs->abi & PERF_SAMPLE_REGS_ABI_SIMD)
> +				sz += 4 * sizeof(u64);

[Severity: High]
Does perf_event__synthesize_sample() also need to be updated to write these
32 bytes?

Since perf_event__sample_event_size() allocates 32 extra bytes for the SIMD
header here, if perf_event__synthesize_sample() doesn't write them,
subsequent fields could be written 32 bytes early.

When the malformed event is parsed by __evsel__parse_sample(), the parser
will skip 32 bytes after the registers, completely missing the early-written
subsequent fields and corrupting the stream. The final 32 bytes of the event
buffer would remain uninitialized heap memory, leaking information when
emitted.

>  			result += sz;
>  		} else {
>  			result += sizeof(u64);
> @@ -1555,6 +1557,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
>  		if (sample->intr_regs && sample->intr_regs->abi) {
>  			result += sizeof(u64);
>  			sz = hweight64(sample->intr_regs->mask) * sizeof(u64);
> +			if (sample->intr_regs->abi & PERF_SAMPLE_REGS_ABI_SIMD)
> +				sz += 4 * sizeof(u64);

[Severity: High]
This appears to have the same issue as above, where the allocated SIMD
header bytes might not be written by perf_event__synthesize_sample().

>  			result += sz;
>  		} else {
>  			result += sizeof(u64);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721072707.3787848-1-dapeng1.mi@linux.intel.com?part=5

  reply	other threads:[~2026-07-21  7:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  7:26 [Patch v10 00/10] Perf tools: Support eGPRs/SSP/SIMD registers sampling Dapeng Mi
2026-07-21  7:26 ` [Patch v10 01/10] perf dwarf-regs: Fix DWARF register index bounds check Dapeng Mi
2026-07-21  7:26 ` [Patch v10 02/10] perf util: Add missed fields in _attr__fprintf() and __attr_swap() Dapeng Mi
2026-07-21  7:27 ` [Patch v10 03/10] tools headers: Sync x86 headers with kernel sources Dapeng Mi
2026-07-21  7:39   ` sashiko-bot
2026-07-21  7:27 ` [Patch v10 04/10] perf headers: Sync perf_event.h/perf_regs.h with the kernel headers Dapeng Mi
2026-07-21  7:47   ` sashiko-bot
2026-07-21  7:27 ` [Patch v10 05/10] perf regs: Support x86 eGPRs/SSP sampling Dapeng Mi
2026-07-21  7:52   ` sashiko-bot [this message]
2026-07-21  7:27 ` [Patch v10 06/10] perf regs: Support x86 SIMD registers sampling Dapeng Mi
2026-07-21  7:50   ` sashiko-bot
2026-07-21  7:27 ` [Patch v10 07/10] perf regs: Enable dumping of SIMD registers Dapeng Mi
2026-07-21  7:27 ` [Patch v10 08/10] perf dwarf-regs: Add SIMD/eGPRs support for x86 DWARF registers Dapeng Mi
2026-07-21  7:27 ` [Patch v10 09/10] perf tests: Add x86 eGPRs/SSP registers sampling test Dapeng Mi
2026-07-21  7:42   ` sashiko-bot
2026-07-21  7:27 ` [Patch v10 10/10] perf tests: Add SIMD " Dapeng Mi
2026-07-21  7:48   ` sashiko-bot

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=20260721075209.EC4A41F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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