* [PATCH] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels
@ 2026-05-27 9:54 Tianchen Ding
2026-05-27 14:09 ` Steven Rostedt
2026-05-28 2:24 ` [PATCH v2] " Tianchen Ding
0 siblings, 2 replies; 6+ messages in thread
From: Tianchen Ding @ 2026-05-27 9:54 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Shuah Khan
Cc: linux-kernel, linux-trace-kernel, linux-kselftest
On ARM64 kernels with 64K pages, the trace_marker_raw test fails because
bash's printf builtin uses stdio buffering which splits output into
multiple small write() calls to the tracefs file. Since each individual
write is within TRACE_MARKER_MAX_SIZE (4096), they all succeed, causing
the "too big" write test to incorrectly pass.
Fix by piping make_str output through dd with iflag=fullblock to
guarantee a single atomic write() syscall to trace_marker_raw.
Fixes: 37f46601383a ("selftests/tracing: Add basic test for trace_marker_raw file")
Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
---
.../selftests/ftrace/test.d/00basic/trace_marker_raw.tc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
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 8e905d4fe6dd..efd8263e6087 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
@@ -43,8 +43,10 @@ write_buffer() {
id=$1
size=$2
- # write the string into the raw marker
- make_str $id $size > trace_marker_raw
+ # Pipe through dd to ensure a single atomic write() syscall.
+ # Shell's printf builtin uses stdio buffering which may split the
+ # output into multiple writes.
+ make_str $id $size | dd of=trace_marker_raw bs=`expr $size + 4` iflag=fullblock
}
--
2.39.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels
2026-05-27 9:54 [PATCH] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels Tianchen Ding
@ 2026-05-27 14:09 ` Steven Rostedt
2026-05-28 2:24 ` [PATCH v2] " Tianchen Ding
1 sibling, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-05-27 14:09 UTC (permalink / raw)
To: Tianchen Ding
Cc: Masami Hiramatsu, Mathieu Desnoyers, Shuah Khan, linux-kernel,
linux-trace-kernel, linux-kselftest
On Wed, 27 May 2026 17:54:37 +0800
Tianchen Ding <dtcccc@linux.alibaba.com> wrote:
> On ARM64 kernels with 64K pages, the trace_marker_raw test fails because
> bash's printf builtin uses stdio buffering which splits output into
> multiple small write() calls to the tracefs file. Since each individual
> write is within TRACE_MARKER_MAX_SIZE (4096), they all succeed, causing
> the "too big" write test to incorrectly pass.
>
> Fix by piping make_str output through dd with iflag=fullblock to
> guarantee a single atomic write() syscall to trace_marker_raw.
>
> Fixes: 37f46601383a ("selftests/tracing: Add basic test for trace_marker_raw file")
> Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
> ---
> .../selftests/ftrace/test.d/00basic/trace_marker_raw.tc | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> 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 8e905d4fe6dd..efd8263e6087 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
> @@ -43,8 +43,10 @@ write_buffer() {
> id=$1
> size=$2
>
> - # write the string into the raw marker
> - make_str $id $size > trace_marker_raw
> + # Pipe through dd to ensure a single atomic write() syscall.
> + # Shell's printf builtin uses stdio buffering which may split the
> + # output into multiple writes.
Could you comment that this is for architectures with 64K pages too.
Thanks for fixing this,
-- Steve
> + make_str $id $size | dd of=trace_marker_raw bs=`expr $size + 4` iflag=fullblock
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels
2026-05-27 9:54 [PATCH] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels Tianchen Ding
2026-05-27 14:09 ` Steven Rostedt
@ 2026-05-28 2:24 ` Tianchen Ding
2026-05-28 13:13 ` Steven Rostedt
1 sibling, 1 reply; 6+ messages in thread
From: Tianchen Ding @ 2026-05-28 2:24 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Shuah Khan
Cc: linux-kernel, linux-trace-kernel, linux-kselftest
On ARM64 kernels with 64K pages, the trace_marker_raw test fails because
bash's printf builtin uses stdio buffering which splits output into
multiple small write() calls to the tracefs file. Since each individual
write is within TRACE_MARKER_MAX_SIZE (4096), they all succeed, causing
the "too big" write test to incorrectly pass.
Fix by piping make_str output through dd with iflag=fullblock to
guarantee a single atomic write() syscall to trace_marker_raw.
Fixes: 37f46601383a ("selftests/tracing: Add basic test for trace_marker_raw file")
Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
---
v2:
Update comment about 64K pages.
---
.../selftests/ftrace/test.d/00basic/trace_marker_raw.tc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
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 8e905d4fe6dd..f68f1901f65f 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
@@ -43,8 +43,11 @@ write_buffer() {
id=$1
size=$2
- # write the string into the raw marker
- make_str $id $size > trace_marker_raw
+ # Pipe through dd to ensure a single atomic write() syscall
+ # on architectures with 64K pages, where shell's printf builtin
+ # uses stdio buffering which may split the output into multiple
+ # writes.
+ make_str $id $size | dd of=trace_marker_raw bs=`expr $size + 4` iflag=fullblock
}
--
2.39.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels
2026-05-28 2:24 ` [PATCH v2] " Tianchen Ding
@ 2026-05-28 13:13 ` Steven Rostedt
2026-05-29 2:59 ` Tianchen Ding
0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2026-05-28 13:13 UTC (permalink / raw)
To: Tianchen Ding
Cc: Masami Hiramatsu, Mathieu Desnoyers, Shuah Khan, linux-kernel,
linux-trace-kernel, linux-kselftest
On Thu, 28 May 2026 10:24:17 +0800
Tianchen Ding <dtcccc@linux.alibaba.com> wrote:
>
> 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 8e905d4fe6dd..f68f1901f65f 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
> @@ -43,8 +43,11 @@ write_buffer() {
> id=$1
> size=$2
>
> - # write the string into the raw marker
> - make_str $id $size > trace_marker_raw
> + # Pipe through dd to ensure a single atomic write() syscall
> + # on architectures with 64K pages, where shell's printf builtin
> + # uses stdio buffering which may split the output into multiple
> + # writes.
> + make_str $id $size | dd of=trace_marker_raw bs=`expr $size + 4` iflag=fullblock
I was looking at this more, and I'm not comfortable with the hard coded
4 above. I rather use the length of the string. Something like:
str=`make_str $id $size`
len=${#str}
echo "$str" | dd of=trace_marker_raw bs=$len iflag=fullblock
-- Steve
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels
2026-05-28 13:13 ` Steven Rostedt
@ 2026-05-29 2:59 ` Tianchen Ding
2026-05-29 13:15 ` Steven Rostedt
0 siblings, 1 reply; 6+ messages in thread
From: Tianchen Ding @ 2026-05-29 2:59 UTC (permalink / raw)
To: Steven Rostedt
Cc: Masami Hiramatsu, Mathieu Desnoyers, Shuah Khan, linux-kernel,
linux-trace-kernel, linux-kselftest
On 5/28/26 9:13 PM, Steven Rostedt wrote:
> On Thu, 28 May 2026 10:24:17 +0800
> Tianchen Ding <dtcccc@linux.alibaba.com> wrote:
>
>>
>> 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 8e905d4fe6dd..f68f1901f65f 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
>> @@ -43,8 +43,11 @@ write_buffer() {
>> id=$1
>> size=$2
>>
>> - # write the string into the raw marker
>> - make_str $id $size > trace_marker_raw
>> + # Pipe through dd to ensure a single atomic write() syscall
>> + # on architectures with 64K pages, where shell's printf builtin
>> + # uses stdio buffering which may split the output into multiple
>> + # writes.
>> + make_str $id $size | dd of=trace_marker_raw bs=`expr $size + 4` iflag=fullblock
>
> I was looking at this more, and I'm not comfortable with the hard coded
> 4 above. I rather use the length of the string. Something like:
>
> str=`make_str $id $size`
> len=${#str}
> echo "$str" | dd of=trace_marker_raw bs=$len iflag=fullblock
>
> -- Steve
>
Capturing make_str output into a shell variable doesn't work because make_str
outputs raw binary that may contain NUL bytes, and shell command substitution
silently strips them.
However, the val variable inside make_str doesn't hold actual NUL bytes — it
holds the text of escape sequences (e.g., the literal characters
\003\000\000\000). The binary conversion only happens at the final printf
"${val}${data}".
We can take advantage of this by having make_str return the escape-sequence text
instead of binary, and letting write_buffer handle the conversion:
make_str() {
...
printf '%s' "${val}${data}"
}
write_buffer() {
id=$1
size=$2
str=`make_str $id $size`
len=$(printf "$str" | wc -c)
printf "$str" | dd of=trace_marker_raw bs=$len iflag=fullblock
}
This way str holds only printable escape-sequence text (no NUL), printf "$str"
converts it to real binary through the pipe, and wc -c measures the true binary
length.
>> }
>>
>>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels
2026-05-29 2:59 ` Tianchen Ding
@ 2026-05-29 13:15 ` Steven Rostedt
0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-05-29 13:15 UTC (permalink / raw)
To: Tianchen Ding
Cc: Masami Hiramatsu, Mathieu Desnoyers, Shuah Khan, linux-kernel,
linux-trace-kernel, linux-kselftest
On Fri, 29 May 2026 10:59:34 +0800
Tianchen Ding <dtcccc@linux.alibaba.com> wrote:
> We can take advantage of this by having make_str return the escape-sequence text
> instead of binary, and letting write_buffer handle the conversion:
>
> make_str() {
> ...
> printf '%s' "${val}${data}"
> }
>
> write_buffer() {
> id=$1
> size=$2
>
> str=`make_str $id $size`
> len=$(printf "$str" | wc -c)
> printf "$str" | dd of=trace_marker_raw bs=$len iflag=fullblock
> }
>
> This way str holds only printable escape-sequence text (no NUL), printf "$str"
> converts it to real binary through the pipe, and wc -c measures the true binary
> length.
This is quite hacky, but at least it removes the hardcoded assumptions.
OK, you can send a v3 that does that.
Thanks,
-- Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-05-29 13:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 9:54 [PATCH] selftests/ftrace: Fix trace_marker_raw test on 64K page kernels Tianchen Ding
2026-05-27 14:09 ` Steven Rostedt
2026-05-28 2:24 ` [PATCH v2] " Tianchen Ding
2026-05-28 13:13 ` Steven Rostedt
2026-05-29 2:59 ` Tianchen Ding
2026-05-29 13:15 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox