From: sashiko-bot@kernel.org
To: "Athira Rajeev" <atrajeev@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH V5 4/6] powerpc/perf: Capture the HTM memory configuration as part of perf data
Date: Fri, 07 Aug 2026 14:51:25 +0000 [thread overview]
Message-ID: <20260807145126.57FAC1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260807143734.1224-5-atrajeev@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] The fallback logic for draining memory configuration records uses an uninitialized stack variable `handle` when `perf_aux_output_begin()` fails, leading to a wild pointer dereference and a kernel crash.
- [High] The `HTM_MEM_BUF_SIZE` calculation assumes a worst-case fixed overhead of 92 bytes, failing to account for dynamic sample sizes when `PERF_SAMPLE_READ` is combined with `PERF_FORMAT_GROUP`. This allows the sample size to exceed 65535, overflowing `perf_event_header.size` and corrupting the ring buffer.
--
--- Patch [4]: [PATCH V5 4/6] powerpc/perf: Capture the HTM memory configuration as part of perf data ---
commit 46bf60d42ede8a36ee43812e6bfd3aeda1d041a9
Author: Athira Rajeev <atrajeev@linux.ibm.com>
powerpc/perf: Capture the HTM memory configuration as part of perf data
This commit captures the HTM system memory configuration during AUX trace
dumps and emits it as raw perf sample data. It adds a staging buffer for
the hypervisor call and handles drain iteration alongside the AUX data path.
> diff --git a/arch/powerpc/perf/htm-perf.c b/arch/powerpc/perf/htm-perf.c
> index 90d26a721616b..7e8ae35269852 100644
> --- a/arch/powerpc/perf/htm-perf.c
> +++ b/arch/powerpc/perf/htm-perf.c
[ ... ]
> @@ -203,6 +206,168 @@ static ssize_t htm_return_check(int rc)
[ ... ]
> + * 65440 = 32 + 2043 * 32 is the largest multiple of 32 satisfying all
> + * constraints:
> + * - total record: 65440 + 92 = 65532 < 65535 (3-byte u16 margin)
> + *
> + * HTM_MEM_MAX_ENTRIES is derived from HTM_MEM_BUF_SIZE — not the other
> + * way around — so the hcall is always given the true buffer size and
> + * the WARN_ON_ONCE(to_copy > HTM_MEM_BUF_SIZE) guard is a genuine
> + * impossibility check rather than a post-overflow assertion.
> + */
> +#define HTM_MEM_BUF_SIZE 65440U
> +#define HTM_MEM_MAX_ENTRIES ((HTM_MEM_BUF_SIZE - 32) / 32) /* 2043 */
[Severity: High]
Does this buffer size properly account for dynamic sample sizes when
PERF_SAMPLE_READ is combined with PERF_FORMAT_GROUP?
If a large group of siblings is configured, the read format payload can
scale up significantly. When htm_collect_memory_config() emits a memory
configuration sample, could the computed size (65440 bytes plus the read
format overhead) exceed 65535?
If it exceeds 65535, wouldn't this overflow the u16 perf_event_header.size,
causing perf_output_begin() to reserve much less space than
perf_output_sample() actually writes, resulting in ring buffer corruption?
[ ... ]
> @@ -594,10 +759,25 @@ static ssize_t htm_dump_sample_data(struct perf_event *event)
> * NMI reentrancy from corrupting an outer transaction's handle.
> */
> aux_buf = perf_aux_output_begin(&handle, event);
> - if (!aux_buf)
> + if (!aux_buf) {
> + /*
> + * AUX ring buffer is full: perf_aux_output_begin() returned NULL.
> + * If the AUX trace dump is already complete but memory
> + * configuration collection is still in progress, we must not
> + * return 0 here — that would signal EOF to htm_event_read() and
> + * permanently abandon the mem config drain. Memory config
> + * records go to the main ring buffer via perf_event_overflow(),
> + * which is entirely independent of the AUX ring. Retrieve the
> + * aux_buf from the ring's aux_private and call directly.
> + */
> + struct htm_pmu_buf *fb = perf_get_aux(&handle);
[Severity: Critical]
If perf_aux_output_begin() returns NULL (for instance, if the user didn't
mmap an AUX buffer), does this leave the stack variable handle
uninitialized?
If handle is uninitialized, wouldn't perf_get_aux(&handle) dereference
uninitialized stack memory when it reads handle.event and
handle.rb->aux_priv?
> +
> + if (fb && !fb->collect_htm_trace && fb->collect_htm_mem)
> + return htm_collect_memory_config(event, fb);
> return 0;
> + }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260807143734.1224-1-atrajeev@linux.ibm.com?part=4
next prev parent reply other threads:[~2026-08-07 14:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 14:37 [PATCH V5 0/6] powerpc/perf: Add HTM PMU driver and perf AUX support Athira Rajeev
2026-08-07 14:37 ` [PATCH V5 1/6] powerpc/perf: Add HTM PMU driver to expose Hardware Trace Macro data Athira Rajeev
2026-08-07 14:58 ` sashiko-bot
2026-08-07 14:37 ` [PATCH V5 2/6] powerpc/perf: Reject duplicate HTM target reservations Athira Rajeev
2026-08-07 14:37 ` [PATCH V5 3/6] powerpc/perf: Add AUX buffer management to capture HTM trace data Athira Rajeev
2026-08-07 14:57 ` sashiko-bot
2026-08-07 14:37 ` [PATCH V5 4/6] powerpc/perf: Capture the HTM memory configuration as part of perf data Athira Rajeev
2026-08-07 14:51 ` sashiko-bot [this message]
2026-08-07 14:37 ` [PATCH V5 5/6] docs: ABI: sysfs-bus-event_source-devices-htm: Document sysfs event format entries for htm pmu Athira Rajeev
2026-08-07 14:37 ` [PATCH V5 6/6] powerpc/perf/htm: Add documentation for Hardware Trace Macro PMU Athira Rajeev
2026-08-07 14:45 ` 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=20260807145126.57FAC1F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=atrajeev@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.