Re: [PATCH v2] selftests/ftrace: Account for 8-byte aligned trace_marker_raw events

From: Steven Rostedt

Date: Tue Nov 24 2026 - 10:51:03 EST


On Sun, 11 Oct 2026 01:46:45 +0200
Sarah Emery <sarah.emery@xxxxxxxxxxxxx> wrote:

> trace_marker_raw.tc expects the length of each raw event to be rounded
> up to a multiple of 4 bytes. That is not the case when the ring buffer
> forces 8-byte alignment of events (CONFIG_HAVE_64BIT_ALIGNED_ACCESS):
> the id plus the data is rounded up to a multiple of 8 bytes instead, so
> trace_pipe shows 8 * N + 4 items. This was seen on riscv64.
>
> Make the test accept either rounding.
>
> Fixes: 37f46601383a ("selftests/tracing: Add basic test for trace_marker_raw file")
> Reported-by: Hui Wang <hui.wang@xxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/20260607072431.125633-3-hui.wang@xxxxxxxxxxxxx/

The Closes tag is for bug reports not previous version of patches.

Do you have the link to the email that shows riscv64 fails? That would be
what you would add to the closes line.

> Signed-off-by: Sarah Emery <sarah.emery@xxxxxxxxxxxxx>
> ---
> Original v1 patch from Hui Wang was posted in June and only patch 1/2
> was merged (commit c37e0a4b79a6).
> This is a v2 for commit 2/2, addressing reviews.
>
> Changes since v1:
> - Drop kconfig_enabled() and the CONFIG_HAVE_64BIT_ALIGNED_ACCESS
> lookup. The review of v1 objected that it depends on the kernel config
> being readable from the test environment. The test now accepts the
> 4 and 8 byte roundings based on what trace_pipe prints.
> - The expected length for the 8 byte case is unchanged (8 * N + 4).
> - Rebase on 65f26d15f7db ("selftests/ftrace: Fix trace_marker_raw test
> on 64K page kernels"), which changed how the test writes its events.
>
> diff --git a/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
> index f985ff391463..dd2b94be0947 100644
> --- a/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
> +++ b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
> @@ -67,7 +67,8 @@ test_multiple_writes() {
> # add a little buffer
> echo stop > trace_marker
>
> - # Check to make sure the number of entries is the id (rounded up by 4)
> + # Check to make sure the number of entries is the id (rounded up by 4,
> + # or by 8 on architectures forcing 8 byte alignment of ring buffer events)
> awk '/.*: # [0-9a-f]* / {
> print;
> cnt = -1;
> @@ -77,9 +78,12 @@ test_multiple_writes() {
> i++;
> cnt = strtonum("0x" $i);
> num = NF - (i + 1);
> - # The number of items is always rounded up by 4
> + # The number of items is rounded up by 4
> - cnt2 = int((cnt + 3) / 4) * 4;
> + cnt4 = int((cnt + 3) / 4) * 4;
> - if (cnt2 != num) {
> + # With forced 8 byte alignment, the id (4 bytes) plus the data
> + # is rounded up to a multiple of 8, and the id is not counted
> + cnt8 = int((cnt + 3) / 8) * 8 + 4;

Instead of doing both checks, it should check 4bytes first and then 8 if
that fails. Although, it would be better if it knew it was running on an
architecture that doesn't support 4 byte alignment.

-- Steve


> + if (num != cnt4 && num != cnt8) {
> exit 1;
> }
> break;