Re: [PATCH 1/2] perf: arm_spe: Order padding before publishing AUX head

From: Will Deacon

Date: Fri Nov 27 2026 - 13:42:57 EST


On Thu, Oct 15, 2026 at 04:51:58PM +0100, Leo Yan wrote:
> The driver fills alignment gaps and calls perf_aux_output_skip(), which
> publishes the new aux_head without a memory barrier. A userspace
> consumer on another CPU can therefore observe the new head before the
> padding stores become visible.
>
> Add smp_wmb() between the padding stores and perf_aux_output_skip().
>
> Fixes: d5d9696b0380 ("drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension")
> Assisted-by: LLM
> Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
> ---
> drivers/perf/arm_spe_pmu.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
> index b70f3fedf0282baba1395ce1116272ec5f961ea8..e105462ec5f38eab4776b0a654ba7c8a84f70f71 100644
> --- a/drivers/perf/arm_spe_pmu.c
> +++ b/drivers/perf/arm_spe_pmu.c
> @@ -487,8 +487,11 @@ static void arm_spe_pmu_pad_buf(struct perf_output_handle *handle, int len)
> u64 head = PERF_IDX2OFF(handle->head, buf);
>
> memset(buf->base + head, ARM_SPE_BUF_PAD_BYTE, len);
> - if (!buf->snapshot)
> + if (!buf->snapshot) {
> + /* Order the padding stores before publishing the new aux_head. */
> + smp_wmb();
> perf_aux_output_skip(handle, len);
> + }

This looks correct to me, but I wonder if it should be handled by
perf_aux_output_skip() instead? arm_spe_pmu_pad_buf() is called from a
bunch of places in the driver, including in conjunction with
perf_aux_output_end(), which looks like it already has the necessary
memory barrier. So doing it here seems weird inconsistent to me.

Will