tracing: Final clean ups for v6.17
Subsystems (2)
cover tracing: Final clean ups for v6.17
Last minute changes for v6.17
- Remove unneeded goto out statements
Over time, the logic was restructured but left a "goto out" where the out label simply did a "return ret;". Instead of jumping to this out label, simply return immediately and remove the out label.
- Clean up the tracing code with guard() and __free() logic
There were several locations that were prime candidates for using guard() and __free() helpers. Switch them over to use them.
- Fix output of function argument traces for unsigned int values
The function tracer with "func-args" option set will record up to 6 argument registers and then use BTF to format them for human consumption when the trace file is read. There's several arguments that are "unsigned long" and even "unsigned int" that are either and address or a mask. It is easier to understand if they were printed using hexadecimal instead of decimal. The old method just printed all non-pointer values as signed integers, which made it even worse for unsigned integers.
For instance, instead of:
__local_bh_disable_ip(ip=-2127311112, cnt=256) <-handle_softirqs
Show:
__local_bh_disable_ip(ip=0xffffffff8133cef8, cnt=0x100) <-handle_softirqs
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/for-next
Head SHA1: 3ca824369b71d4b441e1fdcdee8e66bcb05510a9
Steven Rostedt (6):
tracing: Remove unneeded goto out logic
tracing: Add guard(ring_buffer_nest)
tracing: Add guard() around locks and mutexes in trace.c
tracing: Use __free(kfree) in trace.c to remove gotos
ring-buffer: Convert ring_buffer_write() to use guard(preempt_notrace)
tracing: Have unsigned int function args displayed as hexadecimal
----
include/linux/ring_buffer.h | 3 + kernel/trace/ring_buffer.c | 16 +-- kernel/trace/trace.c | 287 ++++++++++++++------------------------ kernel/trace/trace_events_synth.c | 6 +- kernel/trace/trace_output.c | 8 +- 5 files changed, 120 insertions(+), 200 deletions(-)
PATCH 1/6 tracing: Remove unneeded goto out logic
From: Steven Rostedt <[email protected]>
Several places in the trace.c file there's a goto out where the out is simply a return. There's no reason to jump to the out label if it's not doing any more logic but simply returning from the function.
Replace the goto outs with a return and remove the out labels.
--- kernel/trace/trace.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-)
kernel/trace/trace.c +15 -23
@@ -1841,7 +1841,7 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf, ret =get_user (ch, ubuf++);if (ret) - goto out; +return ret; read++; cnt--;
@@ -1855,7 +1855,7 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,while (cnt &&isspace (ch)) { ret =get_user (ch, ubuf++);if (ret) - goto out; +return ret; read++; cnt--; }
@@ -1865,8 +1865,7 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,/* only spaces were written */ if (isspace (ch) || !ch) { *ppos += read; - ret = read; - goto out; +return read; } }
@@ -1874,13 +1873,12 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,while (cnt && !isspace (ch) && ch) {if (parser->idx < parser->size -1 ) parser->buffer[parser->idx++] = ch; -else { - ret = -EINVAL ; - goto out; - } +else +return -EINVAL ; + ret =get_user (ch, ubuf++);if (ret) - goto out; +return ret; read++; cnt--; }
@@ -1895,15 +1893,11 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,/* Make sure the parsed string always terminates with '\0'. */ parser->buffer[parser->idx] =0 ; }else { - ret = -EINVAL ; - goto out; +return -EINVAL ; } *ppos += read; - ret = read; - -out: -return ret; +return read; }/* TODO add a seq_buf_to_buffer() */
@@ -2405,10 +2399,10 @@ int __init register_tracer(struct tracer *type)mutex_unlock (&trace_types_lock);if (ret || !default_bootup_tracer) - goto out_unlock; +return ret;if (strncmp (default_bootup_tracer, type->name,MAX_TRACER_SIZE )) - goto out_unlock; +return 0 ;printk (KERN_INFO "Starting tracer '%s'\n" , type->name);/* Do we want this tracer to start on bootup? */
@@ -2420,8 +2414,7 @@ int __init register_tracer(struct tracer *type)/* disable other selftests, since this will break it. */ disable_tracing_selftest ("running a tracer" ); - out_unlock: -return ret; +return 0 ; }static void tracing_reset_cpu (struct array_buffer *buf,int cpu)
@@ -8963,12 +8956,12 @@ ftrace_trace_snapshot_callback(struct trace_array *tr, struct ftrace_hash *hash, out_reg: ret =tracing_arm_snapshot (tr);if (ret <0 ) - goto out; +return ret; ret =register_ftrace_function_probe (glob, tr, ops, count);if (ret <0 )tracing_disarm_snapshot (tr); - out: +return ret <0 ? ret :0 ; }
@@ -11070,7 +11063,7 @@ __init static int tracer_alloc_buffers(void)BUILD_BUG_ON (TRACE_ITER_LAST_BIT >TRACE_FLAGS_MAX_SIZE );if (!alloc_cpumask_var (&tracing_buffer_mask,GFP_KERNEL )) - goto out; +return -ENOMEM ;if (!alloc_cpumask_var (&global_trace.tracing_cpumask,GFP_KERNEL )) goto out_free_buffer_mask;
@@ -11188,7 +11181,6 @@ __init static int tracer_alloc_buffers(void)free_cpumask_var (global_trace.tracing_cpumask); out_free_buffer_mask:free_cpumask_var (tracing_buffer_mask); -out:return ret; }
Signature · 1 line
2.47.2
PATCH 2/6 tracing: Add guard(ring_buffer_nest)
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Some calls to the tracing ring buffer can happen when the ring buffer is already being written to by the same context (for example, a trace_printk() in between a ring_buffer_lock_reserve() and a ring_buffer_unlock_commit()).
In order to not trigger the recursion detection, these functions use ring_buffer_nest_start() and ring_buffer_nest_end(). Create a guard() for these functions so that their use cases can be simplified and not need to use goto for the release.
--- include/linux/ring_buffer.h | 3 ++ kernel/trace/trace.c | 69 +++++++++++++------------------ kernel/trace/trace_events_synth.c | 6 +-- 3 files changed, 34 insertions(+), 44 deletions(-)
include/linux/ring_buffer.h +3 -0
@@ -144,6 +144,9 @@ int ring_buffer_write(struct trace_buffer *buffer,void ring_buffer_nest_start (struct trace_buffer *buffer);void ring_buffer_nest_end (struct trace_buffer *buffer); +DEFINE_GUARD(ring_buffer_nest, struct trace_buffer *, + ring_buffer_nest_start(_T), ring_buffer_nest_end(_T)) +struct ring_buffer_event *ring_buffer_peek (struct trace_buffer *buffer,int cpu,u64 *ts,unsigned long *lost_events);
kernel/trace/trace.c +29 -40
119 lines not on this page · raw message
kernel/trace/trace_events_synth.c +2 -4
@@ -536,12 +536,12 @@ static notrace void trace_event_raw_event_synth(void *__data,* is being performed within another event. */ buffer = trace_file->tr->array_buffer.buffer; -ring_buffer_nest_start (buffer); +guard (ring_buffer_nest)(buffer); entry =trace_event_buffer_reserve (&fbuffer, trace_file,sizeof (*entry) + fields_size);if (!entry) - goto out; +return ;for (i =0 , n_u64 =0 ; i < event->n_fields; i++) { val_idx = var_ref_idx[i];
@@ -584,8 +584,6 @@ static notrace void trace_event_raw_event_synth(void *__data, }trace_event_buffer_commit (&fbuffer); -out: -ring_buffer_nest_end (buffer); }static void free_synth_event_print_fmt (struct trace_event_call *call)
Signature · 1 line
2.47.2
PATCH 3/6 tracing: Add guard() around locks and mutexes in trace.c
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
There's several locations in trace.c that can be simplified by using guards around raw_spin_lock_irqsave, mutexes and preempt disabling.
--- kernel/trace/trace.c | 144 ++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 98 deletions(-)
kernel/trace/trace.c +46 -98
@@ -432,15 +432,13 @@ static void ftrace_exports(struct ring_buffer_event *event, int flag) {struct trace_export *export; -preempt_disable_notrace (); +guard (preempt_notrace)(); export =rcu_dereference_raw_check (ftrace_exports_list);while (export) {trace_process_export (export, event, flag); export =rcu_dereference_raw_check (export->next); } - -preempt_enable_notrace (); } static inline void
@@ -497,27 +495,18 @@ int register_ftrace_export(struct trace_export *export)if (WARN_ON_ONCE (!export->write))return -1 ; -mutex_lock (&ftrace_export_lock); +guard (mutex)(&ftrace_export_lock);add_ftrace_export (&ftrace_exports_list, export); -mutex_unlock (&ftrace_export_lock); -return 0 ; }EXPORT_SYMBOL_GPL (register_ftrace_export);int unregister_ftrace_export (struct trace_export *export) { -int ret; - -mutex_lock (&ftrace_export_lock); - - ret =rm_ftrace_export (&ftrace_exports_list, export); - -mutex_unlock (&ftrace_export_lock); - -return ret; +guard (mutex)(&ftrace_export_lock); +return rm_ftrace_export (&ftrace_exports_list, export); }EXPORT_SYMBOL_GPL (unregister_ftrace_export);
@@ -640,9 +629,8 @@ void trace_array_put(struct trace_array *this_tr)if (!this_tr)return ; -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock);__trace_array_put (this_tr); -mutex_unlock (&trace_types_lock); }EXPORT_SYMBOL_GPL (trace_array_put);
@@ -1424,13 +1412,8 @@ static int tracing_arm_snapshot_locked(struct trace_array *tr)int tracing_arm_snapshot (struct trace_array *tr) { -int ret; - -mutex_lock (&trace_types_lock); - ret =tracing_arm_snapshot_locked (tr); -mutex_unlock (&trace_types_lock); - -return ret; +guard (mutex)(&trace_types_lock); +return tracing_arm_snapshot_locked (tr); }void tracing_disarm_snapshot (struct trace_array *tr)
@@ -2483,9 +2466,8 @@ void tracing_reset_all_online_cpus_unlocked(void)void tracing_reset_all_online_cpus (void ) { -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock);tracing_reset_all_online_cpus_unlocked (); -mutex_unlock (&trace_types_lock); }int is_tracing_stopped (void )
@@ -2496,18 +2478,17 @@ int is_tracing_stopped(void)static void tracing_start_tr (struct trace_array *tr) {struct trace_buffer *buffer; -unsigned long flags;if (tracing_disabled)return ; -raw_spin_lock_irqsave (&tr->start_lock, flags); +guard (raw_spinlock_irqsave)(&tr->start_lock);if (--tr->stop_count) {if (WARN_ON_ONCE (tr->stop_count <0 )) {/* Someone screwed up their debugging */ tr->stop_count =0 ; } - goto out; +return ; }/* Prevent the buffers from switching */
@@ -2524,9 +2505,6 @@ static void tracing_start_tr(struct trace_array *tr)#endif arch_spin_unlock (&tr->max_lock); - - out: -raw_spin_unlock_irqrestore (&tr->start_lock, flags); }/**
@@ -2544,11 +2522,10 @@ void tracing_start(void)static void tracing_stop_tr (struct trace_array *tr) {struct trace_buffer *buffer; -unsigned long flags; -raw_spin_lock_irqsave (&tr->start_lock, flags); +guard (raw_spinlock_irqsave)(&tr->start_lock);if (tr->stop_count++) - goto out; +return ;/* Prevent the buffers from switching */ arch_spin_lock (&tr->max_lock);
@@ -2564,9 +2541,6 @@ static void tracing_stop_tr(struct trace_array *tr)#endif arch_spin_unlock (&tr->max_lock); - - out: -raw_spin_unlock_irqrestore (&tr->start_lock, flags); }/**
@@ -2679,12 +2653,12 @@ void trace_buffered_event_enable(void)per_cpu (trace_buffered_event, cpu) = event; -preempt_disable (); -if (cpu ==smp_processor_id () && -__this_cpu_read (trace_buffered_event) != -per_cpu (trace_buffered_event, cpu)) -WARN_ON_ONCE (1 ); -preempt_enable (); + scoped_guard(preempt,) { + if (cpu == smp_processor_id() && + __this_cpu_read(trace_buffered_event) != + per_cpu(trace_buffered_event, cpu)) + WARN_ON_ONCE(1); + } } }
@@ -3029,7 +3003,7 @@ static void __ftrace_trace_stack(struct trace_array *tr, skip++;#endif -preempt_disable_notrace (); +guard (preempt_notrace)(); stackidx =__this_cpu_inc_return (ftrace_stack_reserve) -1 ;
@@ -3087,8 +3061,6 @@ static void __ftrace_trace_stack(struct trace_array *tr,/* Again, don't let gcc optimize things here */ barrier ();__this_cpu_dec (ftrace_stack_reserve); -preempt_enable_notrace (); - } static inline void ftrace_trace_stack(struct trace_array *tr,
@@ -3171,9 +3143,9 @@ ftrace_trace_userstack(struct trace_array *tr,* prevent recursion, since the user stack tracing may * trigger other kernel events. */ -preempt_disable (); +guard (preempt)();if (__this_cpu_read (user_stack_count)) - goto out; +return ;__this_cpu_inc (user_stack_count);
@@ -3191,8 +3163,6 @@ ftrace_trace_userstack(struct trace_array *tr, out_drop_count:__this_cpu_dec (user_stack_count); - out: -preempt_enable (); }#else /* CONFIG_USER_STACKTRACE_SUPPORT */ static void ftrace_trace_userstack(struct trace_array *tr,
@@ -3374,7 +3344,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)pause_graph_tracing (); trace_ctx =tracing_gen_ctx (); -preempt_disable_notrace (); +guard (preempt_notrace)(); tbuffer =get_trace_buf ();if (!tbuffer) {
@@ -3406,7 +3376,6 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)put_trace_buf (); out_nobuffer: -preempt_enable_notrace ();unpause_graph_tracing ();return len;
@@ -3430,7 +3399,7 @@ int __trace_array_vprintk(struct trace_buffer *buffer,pause_graph_tracing (); trace_ctx =tracing_gen_ctx (); -preempt_disable_notrace (); +guard (preempt_notrace)(); tbuffer =get_trace_buf ();
@@ -3458,7 +3427,6 @@ int __trace_array_vprintk(struct trace_buffer *buffer,put_trace_buf (); out_nobuffer: -preempt_enable_notrace ();unpause_graph_tracing ();return len;
@@ -4788,20 +4756,16 @@ int tracing_open_file_tr(struct inode *inode, struct file *filp)if (ret)return ret; -mutex_lock (&event_mutex); +guard (mutex)(&event_mutex);/* Fail if the file is marked for removal */ if (file->flags &EVENT_FILE_FL_FREED ) {trace_array_put (file->tr); - ret = -ENODEV ; +return -ENODEV ; }else {event_file_get (file); } -mutex_unlock (&event_mutex); -if (ret) -return ret; - filp->private_data = inode->i_private;return 0 ;
@@ -5945,9 +5909,9 @@ tracing_set_trace_read(struct file *filp, char __user *ubuf,char buf[MAX_TRACER_SIZE +2 ];int r; -mutex_lock (&trace_types_lock); - r =sprintf (buf,"%s\n" , tr->current_trace->name); -mutex_unlock (&trace_types_lock); + scoped_guard(mutex, &trace_types_lock) { + r =sprintf (buf,"%s\n" , tr->current_trace->name); + }return simple_read_from_buffer (ubuf, cnt, ppos, buf, r); }
@@ -6249,15 +6213,13 @@ int tracing_update_buffers(struct trace_array *tr) {int ret =0 ; -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock);update_last_data (tr);if (!tr->ring_buffer_expanded) ret =__tracing_resize_ring_buffer (tr, trace_buf_size,RING_BUFFER_ALL_CPUS ); -mutex_unlock (&trace_types_lock); -return ret; }
@@ -6554,7 +6516,7 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)if (ret)return ret; -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock); cpu =tracing_get_cpu (inode); ret =open_pipe_on_cpu (tr, cpu);if (ret)
@@ -6598,7 +6560,6 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp) tr->trace_ref++; -mutex_unlock (&trace_types_lock);return ret; fail:
@@ -6607,7 +6568,6 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)close_pipe_on_cpu (tr, cpu); fail_pipe_on_cpu:__trace_array_put (tr); -mutex_unlock (&trace_types_lock);return ret; }
@@ -6616,14 +6576,13 @@ static int tracing_release_pipe(struct inode *inode, struct file *file)struct trace_iterator *iter = file->private_data;struct trace_array *tr = inode->i_private; -mutex_lock (&trace_types_lock); + scoped_guard(mutex, &trace_types_lock) { + tr->trace_ref--; - tr->trace_ref--; - -if (iter->trace->pipe_close) - iter->trace->pipe_close (iter); -close_pipe_on_cpu (tr, iter->cpu_file); -mutex_unlock (&trace_types_lock); +if (iter->trace->pipe_close) + iter->trace->pipe_close (iter); +close_pipe_on_cpu (tr, iter->cpu_file); + }free_trace_iter_content (iter);kfree (iter);
@@ -7426,7 +7385,7 @@ int tracing_set_clock(struct trace_array *tr, const char *clockstr)if (i ==ARRAY_SIZE (trace_clocks))return -EINVAL ; -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock); tr->clock_id = i;
@@ -7450,8 +7409,6 @@ int tracing_set_clock(struct trace_array *tr, const char *clockstr) tscratch->clock_id = i; } -mutex_unlock (&trace_types_lock); -return 0 ; }
@@ -7503,15 +7460,13 @@ static int tracing_time_stamp_mode_show(struct seq_file *m, void *v) {struct trace_array *tr = m->private; -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock);if (ring_buffer_time_stamp_abs (tr->array_buffer.buffer))seq_puts (m,"delta [absolute]\n" );else seq_puts (m,"[delta] absolute\n" ); -mutex_unlock (&trace_types_lock); -return 0 ; }
@@ -8099,14 +8054,14 @@ static void clear_tracing_err_log(struct trace_array *tr) {struct tracing_log_err *err, *next; -mutex_lock (&tracing_err_log_lock); +guard (mutex)(&tracing_err_log_lock); +list_for_each_entry_safe (err, next, &tr->err_log, list) {list_del (&err->list);free_tracing_log_err (err); } tr->n_err_log_entries =0 ; -mutex_unlock (&tracing_err_log_lock); }static void *tracing_err_log_seq_start (struct seq_file *m,loff_t *pos)
@@ -8377,7 +8332,7 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)struct ftrace_buffer_info *info = file->private_data;struct trace_iterator *iter = &info->iter; -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock); iter->tr->trace_ref--;
@@ -8388,8 +8343,6 @@ static int tracing_buffers_release(struct inode *inode, struct file *file) info->spare_cpu, info->spare);kvfree (info); -mutex_unlock (&trace_types_lock); -return 0 ; }
@@ -8597,14 +8550,13 @@ static long tracing_buffers_ioctl(struct file *file, unsigned int cmd, unsigned* An ioctl call with cmd 0 to the ring buffer file will wake up all * waiters */ -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock);/* Make sure the waiters see the new wait_index */ (void )atomic_fetch_inc_release (&iter->wait_index);ring_buffer_wake_waiters (iter->array_buffer->buffer, iter->cpu_file); -mutex_unlock (&trace_types_lock);return 0 ; }
@@ -9094,10 +9046,9 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,return -EINVAL ;if (!!(topt->flags->val & topt->opt->bit) != val) { -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock); ret =__set_tracer_option (topt->tr, topt->flags, topt->opt, !val); -mutex_unlock (&trace_types_lock);if (ret)return ret; }
@@ -9406,7 +9357,7 @@ rb_simple_write(struct file *filp, const char __user *ubuf,return ret;if (buffer) { -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock);if (!!val ==tracer_tracing_is_on (tr)) { val =0 ;/* do nothing */ }else if (val) {
@@ -9420,7 +9371,6 @@ rb_simple_write(struct file *filp, const char __user *ubuf,/* Wake up any waiters */ ring_buffer_wake_waiters (buffer,RING_BUFFER_ALL_CPUS ); } -mutex_unlock (&trace_types_lock); } (*ppos)++;
@@ -9804,10 +9754,9 @@ static void __update_tracer_options(struct trace_array *tr)static void update_tracer_options (struct trace_array *tr) { -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock); tracer_options_updated = true;__update_tracer_options (tr); -mutex_unlock (&trace_types_lock); }/* Must have trace_types_lock held */
@@ -9829,11 +9778,10 @@ struct trace_array *trace_array_find_get(const char *instance) {struct trace_array *tr; -mutex_lock (&trace_types_lock); +guard (mutex)(&trace_types_lock); tr =trace_array_find (instance);if (tr) tr->ref++; -mutex_unlock (&trace_types_lock);return tr; }
Signature · 1 line
2.47.2
PATCH 4/6 tracing: Use __free(kfree) in trace.c to remove gotos
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
There's a couple of locations that have goto out in trace.c for the only purpose of freeing a variable that was allocated. These can be replaced with __free(kfree).
--- kernel/trace/trace.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
kernel/trace/trace.c +12 -24
@@ -5042,7 +5042,7 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf, size_t count, loff_t *ppos) { struct trace_array *tr = file_inode(filp)->i_private; -char *mask_str; + char *mask_str __free(kfree) = NULL;int len; len = snprintf(NULL, 0, "%*pb\n",
@@ -5053,16 +5053,10 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf, len =snprintf (mask_str, len,"%*pb\n" ,cpumask_pr_args (tr->tracing_cpumask)); -if (len >= count) { - count = -EINVAL ; - goto out_err; - } - count =simple_read_from_buffer (ubuf, count, ppos, mask_str, len); - -out_err: -kfree (mask_str); +if (len >= count) +return -EINVAL ; -return count; +return simple_read_from_buffer (ubuf, count, ppos, mask_str, len); } int tracing_set_cpumask(struct trace_array *tr,
@@ -10739,7 +10733,8 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer, size_t count, loff_t *ppos, int (*createfn)(const char *)) { - char *kbuf, *buf, *tmp; + char *kbuf __free(kfree) = NULL; +char *buf, *tmp;int ret =0 ;size_t done =0 ;size_t size;
@@ -10754,10 +10749,9 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,if (size >=WRITE_BUFSIZE ) size =WRITE_BUFSIZE -1 ; -if (copy_from_user (kbuf, buffer + done, size)) { - ret = -EFAULT ; - goto out; - } +if (copy_from_user (kbuf, buffer + done, size)) +return -EFAULT ; + kbuf[size] ='\0' ; buf = kbuf; do {
@@ -10773,8 +10767,7 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,/* This can accept WRITE_BUFSIZE - 2 ('\n' + '\0') */ pr_warn ("Line length is too long: Should be less than %d\n" ,WRITE_BUFSIZE -2 ); - ret = -EINVAL ; - goto out; +return -EINVAL ; } } done += size;
@@ -10787,17 +10780,12 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer, ret =createfn (buf);if (ret) - goto out; +return ret; buf += size; }while (done < count); } - ret = done; - -out: -kfree (kbuf); - -return ret; +return done; }#ifdef CONFIG_TRACER_MAX_TRACE
Signature · 1 line
2.47.2
PATCH 5/6 ring-buffer: Convert ring_buffer_write() to use guard(preempt_notrace)
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The function ring_buffer_write() has a goto out to only do a preempt_enable_notrace(). This can be replaced by a guard.
--- kernel/trace/ring_buffer.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
kernel/trace/ring_buffer.c +6 -10
@@ -4714,26 +4714,26 @@ int ring_buffer_write(struct trace_buffer *buffer,int ret = -EBUSY ;int cpu; -preempt_disable_notrace (); +guard (preempt_notrace)();if (atomic_read (&buffer->record_disabled)) - goto out; +return -EBUSY ; cpu =raw_smp_processor_id ();if (!cpumask_test_cpu (cpu, buffer->cpumask)) - goto out; +return -EBUSY ; cpu_buffer = buffer->buffers[cpu];if (atomic_read (&cpu_buffer->record_disabled)) - goto out; +return -EBUSY ;if (length > buffer->max_data_size) - goto out; +return -EBUSY ;if (unlikely (trace_recursive_lock (cpu_buffer))) - goto out; +return -EBUSY ; event =rb_reserve_next_event (buffer, cpu_buffer, length);if (!event)
@@ -4751,10 +4751,6 @@ int ring_buffer_write(struct trace_buffer *buffer, out_unlock:trace_recursive_unlock (cpu_buffer); - - out: -preempt_enable_notrace (); -return ret; }EXPORT_SYMBOL_GPL (ring_buffer_write);
Signature · 1 line
2.47.2
PATCH 6/6 tracing: Have unsigned int function args displayed as hexadecimal
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Most function arguments that are passed in as unsigned int or unsigned long are better displayed as hexadecimal than normal integer. For example, the functions:
static void __create_object(unsigned long ptr, size_t size,
int min_count, gfp_t gfp, unsigned int objflags);
static bool stack_access_ok(struct unwind_state *state, unsigned long _addr,
size_t len);
void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
Show up in the trace as:
__create_object(ptr=-131387050520576, size=4096, min_count=1, gfp=3264, objflags=0) <-kmem_cache_alloc_noprof
stack_access_ok(state=0xffffc9000233fc98, _addr=-60473102566256, len=8) <-unwind_next_frame
__local_bh_disable_ip(ip=-2127311112, cnt=256) <-handle_softirqsInstead, by displaying unsigned as hexadecimal, they look more like this:
__create_object(ptr=0xffff8881028d2080, size=0x280, min_count=1, gfp=0x82820, objflags=0x0) <-kmem_cache_alloc_node_noprof
stack_access_ok(state=0xffffc90000003938, _addr=0xffffc90000003930, len=0x8) <-unwind_next_frame
__local_bh_disable_ip(ip=0xffffffff8133cef8, cnt=0x100) <-handle_softirqsWhich is much easier to understand as most unsigned longs are usually just pointers. Even the "unsigned int cnt" in __local_bh_disable_ip() looks better as hexadecimal as a lot of flags are passed as unsigned.
Changes since v2: https://lore.kernel.org/[email protected]
- Use btf_int_encoding() instead of open coding it (Martin KaFai Lau)
--- kernel/trace/trace_output.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/trace/trace_output.c +7 -1
@@ -701,6 +701,7 @@ void print_function_args(struct trace_seq *s, unsigned long *args,struct btf *btf;s32 tid, nr =0 ;int a, p, x; +u16 encode;trace_seq_printf (s,"(" );
@@ -744,7 +745,12 @@ void print_function_args(struct trace_seq *s, unsigned long *args,trace_seq_printf (s,"0x%lx" , arg);break ;case BTF_KIND_INT : -trace_seq_printf (s,"%ld" , arg); + encode =btf_int_encoding (t); +/* Print unsigned ints as hex */ +if (encode &BTF_INT_SIGNED ) +trace_seq_printf (s,"%ld" , arg); +else +trace_seq_printf (s,"0x%lx" , arg);break ;case BTF_KIND_ENUM :trace_seq_printf (s,"%ld" , arg);
Signature · 1 line
2.47.2
Steven Rostedt
maintainer[ Adding Masami and Mathieu ]
Oops, I accidentally used the RTLA script to send these.
Sorry Tomas and John ;-)
-- Steve
Quoted 52 lines · On Sat, 02 Aug 2025 12:27:34 -0400 Steven Rostedt <[email protected]> wrote:
Last minute changes for v6.17
- Remove unneeded goto out statements
Over time, the logic was restructured but left a "goto out" where the out label simply did a "return ret;". Instead of jumping to this out label, simply return immediately and remove the out label.
- Clean up the tracing code with
guard()and__free()logicThere were several locations that were prime candidates for using
guard()and__free()helpers. Switch them over to use them.- Fix output of function argument traces for unsigned int values
The function tracer with "func-args" option set will record up to 6 argument registers and then use BTF to format them for human consumption when the trace file is read. There's several arguments that are "unsigned long" and even "unsigned int" that are either and address or a mask. It is easier to understand if they were printed using hexadecimal instead of decimal. The old method just printed all non-pointer values as signed integers, which made it even worse for unsigned integers.
For instance, instead of:
__local_bh_disable_ip(ip=-2127311112, cnt=256) <-handle_softirqsShow:
__local_bh_disable_ip(ip=0xffffffff8133cef8, cnt=0x100) <-handle_softirqs
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/for-nextHead SHA1:
3ca824369b71d4b441e1fdcdee8e66bcb05510a9Steven Rostedt (6):
tracing: Remove unneeded goto out logic
tracing: Addguard(ring_buffer_nest)
tracing: Addguard()around locks and mutexes intrace.c
tracing: Use__free(kfree)intrace.cto remove gotos
ring-buffer: Convertring_buffer_write()to useguard(preempt_notrace)
tracing: Have unsigned int function args displayed as hexadecimal----
include/linux/ring_buffer.h | 3 + kernel/trace/ring_buffer.c | 16 +-- kernel/trace/trace.c | 287 ++++++++++++++------------------------ kernel/trace/trace_events_synth.c | 6 +- kernel/trace/trace_output.c | 8 +- 5 files changed, 120 insertions(+), 200 deletions(-)