tracing: Fixes for v6.18
Subsystems (3)
cover tracing: Fixes for v6.18
Fixes for tracing:
- Check for reader catching up in ring_buffer_map_get_reader()
If the reader catches up to the writer in the memory mapped ring buffer then calling rb_get_reader_page() will return NULL as there's no pages left. But this isn't checked for before calling rb_get_reader_page() and the return of NULL causes a warning.
If it is detected that the reader caught up to the writer, then simply exit the routine.
- Fix memory leak in histogram create_field_var()
The couple of the error paths in create_field_var() did not properly clean up what was allocated. Make sure everything is freed properly on error.
- Fix help message of tools latency_collector
The help message incorrectly stated that "-t" was the same as "--threads" whereas "--threads" is actually represented by "-e".
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/fixes
Head SHA1: 53afec2c8fb2a562222948cb1c2aac48598578c9
Steven Rostedt (1):
ring-buffer: Do not warn in ring_buffer_map_get_reader() when reader catches up
Zhang Chujun (1):
tracing/tools: Fix incorrcet short option in usage text for --threads
Zilin Guan (1):
tracing: Fix memory leaks in create_field_var()
----
kernel/trace/ring_buffer.c | 4 ++++ kernel/trace/trace_events_hist.c | 6 ++++-- tools/tracing/latency/latency-collector.c | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-)
PATCH 1/3 ring-buffer: Do not warn in ring_buffer_map_get_reader() when reader catches up
From: Steven Rostedt <[email protected]>
The function ring_buffer_map_get_reader() is a bit more strict than the other get reader functions, and except for certain situations the rb_get_reader_page() should not return NULL. If it does, it triggers a warning.
This warning was triggering but after looking at why, it was because another acceptable situation was happening and it wasn't checked for.
If the reader catches up to the writer and there's still data to be read on the reader page, then the rb_get_reader_page() will return NULL as there's no new page to get.
In this situation, the reader page should not be updated and no warning should trigger.
--- kernel/trace/ring_buffer.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/trace/ring_buffer.c +4 -0
@@ -7344,6 +7344,10 @@ int ring_buffer_map_get_reader(struct trace_buffer *buffer, int cpu) goto out; } +/* Did the reader catch up with the writer? */ +if (cpu_buffer->reader_page == cpu_buffer->commit_page) + goto out; + reader =rb_get_reader_page (cpu_buffer);if (WARN_ON (!reader)) goto out;
Signature · 1 line
2.51.0
PATCH 2/3 tracing: Fix memory leaks in create_field_var()
In reply to Steven RostedtFrom: Zilin Guan <[email protected]>
The function create_field_var() allocates memory for 'val' through create_hist_field() inside parse_atom(), and for 'var' through create_var(), which in turn allocates var->type and var->var.name internally. Simply calling kfree() to release these structures will result in memory leaks.
Use destroy_hist_field() to properly free 'val', and explicitly release the memory of var->type and var->var.name before freeing 'var' itself.
--- kernel/trace/trace_events_hist.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +4 -2
@@ -3272,14 +3272,16 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data, var =create_var (hist_data, file, field_name, val->size, val->type);if (IS_ERR (var)) {hist_err (tr,HIST_ERR_VAR_CREATE_FIND_FAIL ,errpos (field_name)); -kfree (val); +destroy_hist_field (val,0 ); ret =PTR_ERR (var); goto err; } field_var =kzalloc (sizeof (struct field_var ),GFP_KERNEL );if (!field_var) { -kfree (val); +destroy_hist_field (val,0 ); +kfree_const (var->type); +kfree (var->var.name);kfree (var); ret = -ENOMEM ; goto err;
Signature · 1 line
2.51.0
PATCH 3/3 tracing/tools: Fix incorrcet short option in usage text for --threads
In reply to Steven RostedtFrom: Zhang Chujun <[email protected]>
The help message incorrectly listed '-t' as the short option for --threads, but the actual getopt_long configuration uses '-e'. This mismatch can confuse users and lead to incorrect command-line usage. This patch updates the usage string to correctly show:
"-e, --threads NRTHR"
to match the implementation.
Note: checkpatch.pl reports a false-positive spelling warning on 'Run', which is intentional.
--- tools/tracing/latency/latency-collector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/tracing/latency/latency-collector.c +1 -1
@@ -1725,7 +1725,7 @@ static void show_usage(void)"-n, --notrace\t\tIf latency is detected, do not print out the content of\n" "\t\t\tthe trace file to standard output\n\n" -"-t, --threads NRTHR\tRun NRTHR threads for printing. Default is %d.\n\n" +"-e, --threads NRTHR\tRun NRTHR threads for printing. Default is %d.\n\n" "-r, --random\t\tArbitrarily sleep a certain amount of time, default\n" "\t\t\t%ld ms, before reading the trace file. The\n"
Signature · 1 line
2.51.0
Mathieu Desnoyers
reviewerRe: [for-linus][PATCH 3/3] tracing/tools: Fix incorrcet short option in usage text for --threads
On 2025-11-07 08:07, Steven Rostedt wrote:
Nit: Subject: incorrcet -> incorrect
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Steven Rostedt
maintainerRe: [for-linus][PATCH 3/3] tracing/tools: Fix incorrcet short option in usage text for --threads
Quoted 3 lines · Mathieu Desnoyers
On 2025-11-07 08:07, Steven Rostedt wrote:
Nit: Subject: incorrcet -> incorrect
I saw that just as I did the pull request but figured it wasn't big enough to stop the request.
-- Steve
Quoted 5 lines
Thanks,
Mathieu