tracing: Preserve repeated boot-time parameters and drain deferred trigger frees
v4 cover tracing: Preserve repeated boot-time parameters and drain deferred trigger frees
Patch 1 preserves repeated boot-time tracing parameters by appending to the existing parser buffers instead of overwriting earlier values, so repeated command-line entries and Bootconfig array expansions work with the delimited formats the parsers already consume.
Patch 2 fixes the deferred event-trigger free path so queued frees are still drained if the cleanup kthread never comes up after boot.
v4:
- drop the kernel-parameters.txt update from patch 1
- move trace_append_boot_param() into trace.c and keep only the prototype in trace.h
- capitalize the tracing patch subjects
- rename trigger_start_kthread_locked() to trigger_create_kthread_locked()
- change the failure comment to say "creation failed"
Wesley Atwell (2):
tracing: Preserve repeated boot-time tracing parameters
tracing: Drain deferred trigger frees if kthread creation fails
kernel/trace/ftrace.c | 12 +++-- kernel/trace/trace.c | 31 ++++++++++- kernel/trace/trace.h | 2 + kernel/trace/trace_events.c | 26 ++++++++-- kernel/trace/trace_events_trigger.c | 79 ++++++++++++++++++++++++----- kernel/trace/trace_kprobe.c | 3 +- 6 files changed, 131 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/2 tracing: Preserve repeated boot-time tracing parameters
Some tracing boot parameters already accept delimited value lists, but their __setup() handlers keep only the last instance seen at boot. Make repeated instances append to the same boot-time buffer in the format each parser already consumes.
Use a shared trace_append_boot_param() helper for the ftrace filters, trace_options, and kprobe_event boot parameters. trace_trigger= tokenizes its backing storage in place, so keep a running offset and only parse the newly appended chunk into bootup_triggers[].
This also lets Bootconfig array values work naturally when they expand to repeated param=value entries.
--- kernel/trace/ftrace.c | 12 ++++++++---- kernel/trace/trace.c | 31 ++++++++++++++++++++++++++++++- kernel/trace/trace.h | 2 ++ kernel/trace/trace_events.c | 26 +++++++++++++++++++++++--- kernel/trace/trace_kprobe.c | 3 ++- 5 files changed, 65 insertions(+), 9 deletions(-)
kernel/trace/ftrace.c +8 -4
@@ -6841,7 +6841,8 @@ bool ftrace_filter_param __initdata;static int __init set_ftrace_notrace (char *str) { ftrace_filter_param = true; -strscpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_notrace_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_notrace=" , set_ftrace_notrace);
@@ -6849,7 +6850,8 @@ __setup("ftrace_notrace=", set_ftrace_notrace);static int __init set_ftrace_filter (char *str) { ftrace_filter_param = true; -strscpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_filter_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_filter=" , set_ftrace_filter);
@@ -6861,14 +6863,16 @@ static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);static int __init set_graph_function (char *str) { -strscpy (ftrace_graph_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_graph_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_filter=" , set_graph_function);static int __init set_graph_notrace_function (char *str) { -strscpy (ftrace_graph_notrace_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_graph_notrace_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_notrace=" , set_graph_notrace_function);
kernel/trace/trace.c +30 -1
@@ -228,6 +228,34 @@ static int boot_instance_index;static char boot_snapshot_info[COMMAND_LINE_SIZE ]__initdata ;static int boot_snapshot_index; +/* +* Repeated boot parameters, including Bootconfig array expansions, need +* to stay in the delimiter form that the existing parser consumes. +*/ +void __init trace_append_boot_param (char *buf,const char *str,char sep, +size_t size) +{ +size_t len, str_len; + +if (!buf[0 ]) { +strscpy (buf, str, size); +return ; + } + + str_len =strlen (str); +if (!str_len) +return ; + + len =strlen (buf); +if (len >= size -1 ) +return ; +if (str_len >= size - len -1 ) +return ; + + buf[len] = sep; +strscpy (buf + len +1 , str, size - len -1 ); +} +static int __init set_cmdline_ftrace (char *str) {strscpy (bootup_tracer_buf, str,MAX_TRACER_SIZE );
@@ -329,7 +357,8 @@ static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;static int __init set_trace_boot_options (char *str) { -strscpy (trace_boot_options_buf, str,MAX_TRACER_SIZE ); +trace_append_boot_param (trace_boot_options_buf, str,',' , +MAX_TRACER_SIZE );return 1 ; }__setup ("trace_options=" , set_trace_boot_options);
kernel/trace/trace.h +2 -0
@@ -863,6 +863,8 @@ extern int DYN_FTRACE_TEST_NAME(void);extern int DYN_FTRACE_TEST_NAME2 (void );extern void trace_set_ring_buffer_expanded (struct trace_array *tr); +void __init trace_append_boot_param (char *buf,const char *str, +char sep,size_t size);extern bool tracing_selftest_disabled;#ifdef CONFIG_FTRACE_STARTUP_TEST
kernel/trace/trace_events.c +23 -3
@@ -3679,20 +3679,40 @@ static struct boot_triggers { } bootup_triggers[MAX_BOOT_TRIGGERS ];static char bootup_trigger_buf[COMMAND_LINE_SIZE ]; +static size_t bootup_trigger_buf_len;static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) {char *trigger;char *buf; +size_t start, str_len;int i; -strscpy (bootup_trigger_buf, str,COMMAND_LINE_SIZE ); +if (bootup_trigger_buf_len >=COMMAND_LINE_SIZE ) +return 1 ; + + start = bootup_trigger_buf_len; +if (start && !*str) +return 1 ; + + str_len =strlen (str); +if (start && str_len >=COMMAND_LINE_SIZE - start) +return 1 ; + +/* +* trace_trigger= parsing tokenizes the backing storage in place. +* Copy each repeated parameter into fresh space and only parse that +* newly copied chunk here. +*/ +trace_append_boot_param (bootup_trigger_buf + start, str,'\0' , +COMMAND_LINE_SIZE - start); + bootup_trigger_buf_len +=strlen (bootup_trigger_buf + start) +1 ;trace_set_ring_buffer_expanded (NULL );disable_tracing_selftest ("running event triggers" ); - buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { + buf = bootup_trigger_buf + start; +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) { trigger =strsep (&buf,"," );if (!trigger)break ;
kernel/trace/trace_kprobe.c +2 -1
@@ -31,7 +31,8 @@ static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata;static int __init set_kprobe_boot_events (char *str) { -strscpy (kprobe_boot_events_buf, str,COMMAND_LINE_SIZE ); +trace_append_boot_param (kprobe_boot_events_buf, str,';' , +COMMAND_LINE_SIZE );disable_tracing_selftest ("running kprobe events" );return 1 ;
Signature · 1 line
2.43.0
Steven Rostedt
maintainerRe: [PATCH v4 1/2] tracing: Preserve repeated boot-time tracing parameters
kernel/trace/trace.c static int boot_instance_index; · line 238
Quoted 13 lines · On Tue, 24 Mar 2026 16:13:25 -0600 Wesley Atwell <[email protected]> wrote:
+++
b/kernel/trace/trace.ckernel/trace/trace.c +8
-0@@ -228,6 +228,34 @@ static int boot_instance_index;static char boot_snapshot_info[COMMAND_LINE_SIZE ]__initdata ;static int boot_snapshot_index; +/* +* Repeated boot parameters, including Bootconfig array expansions, need +* to stay in the delimiter form that the existing parser consumes. +*/ +void __init trace_append_boot_param (char *buf,const char *str,char sep, +size_t size) +{ +size_t len, str_len;
Why use the "size_t" type? Just use int. Then you don't need to play games about unsigned types in the if statements below. The boot cmdline will never come close to being 2GB in size.
kernel/trace/trace.c static int boot_instance_index; · line 240
Quoted 2 lines
kernel/trace/trace.c +2
-0+ +if (!buf[0 ]) {
Should we check for size here? Perhaps just remove this part (see below)
Quoted 5 lines
kernel/trace/trace.c +5
-0+strscpy (buf, str, size); +return ; + } + + str_len =strlen (str);
kernel/trace/trace.c static int boot_instance_index; · line 253
Quoted 10 lines
kernel/trace/trace.c +8
-0+if (!str_len) +return ; + + len =strlen (buf); +if (len >= size -1 ) +return ; +if (str_len >= size - len -1 ) +return ;
Instead of the above, have:
/* Plus 2 for ",\0" */ if (str_len + len + 2 > size) return;
Review static int boot_instance_index; · line 257
Quoted 2 lines
(quoted diff) +2
-0+ + buf[len] = sep;
If we remove the first check, here we can have:
if (len) buf[len++] = sep;
By adding one to length, it makes the strscpy() a bit more readable.
strscpy(buf + len, str, size - len);
kernel/trace/trace.c static int boot_instance_index; · line 258
Quoted 4 lines
kernel/trace/trace.c +3
-0+strscpy (buf + len +1 , str, size - len -1 ); +} +
-- Steve
PATCH v5 1/1 tracing: Preserve repeated boot-time tracing parameters
In reply to Wesley AtwellSome tracing boot parameters already accept delimited value lists, but their __setup() handlers keep only the last instance seen at boot. Make repeated instances append to the same boot-time buffer in the format each parser already consumes.
Use a shared trace_append_boot_param() helper for the ftrace filters, trace_options, and kprobe_event boot parameters. trace_trigger= tokenizes its backing storage in place, so keep a running offset and only parse the newly appended chunk into bootup_triggers[].
This also lets Bootconfig array values work naturally when they expand to repeated param=value entries.
Validated by booting with repeated ftrace_filter=, ftrace_notrace=, ftrace_graph_filter=, ftrace_graph_notrace=, trace_options=, kprobe_event=, and trace_trigger= parameters and confirming that the resulting tracefs state preserved every requested entry. Before this change, only the last instance from each repeated parameter survived boot.
---
v5:
- use int sizes in the shared append helper and trace_trigger bookkeeping
- keep a single bounded append path that only inserts the separator after the first entry
- only advance the trace_trigger buffer offset after a successful append
kernel/trace/ftrace.c | 12 ++++++++---- kernel/trace/trace.c | 29 ++++++++++++++++++++++++++++- kernel/trace/trace.h | 2 ++ kernel/trace/trace_events.c | 23 ++++++++++++++++++++--- kernel/trace/trace_kprobe.c | 3 ++- 5 files changed, 60 insertions(+), 9 deletions(-)
kernel/trace/ftrace.c +8 -4
@@ -6841,7 +6841,8 @@ bool ftrace_filter_param __initdata;static int __init set_ftrace_notrace (char *str) { ftrace_filter_param = true; -strscpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_notrace_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_notrace=" , set_ftrace_notrace);
@@ -6849,7 +6850,8 @@ __setup("ftrace_notrace=", set_ftrace_notrace);static int __init set_ftrace_filter (char *str) { ftrace_filter_param = true; -strscpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_filter_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_filter=" , set_ftrace_filter);
@@ -6861,14 +6863,16 @@ static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);static int __init set_graph_function (char *str) { -strscpy (ftrace_graph_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_graph_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_filter=" , set_graph_function);static int __init set_graph_notrace_function (char *str) { -strscpy (ftrace_graph_notrace_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_graph_notrace_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_notrace=" , set_graph_notrace_function);
kernel/trace/trace.c +28 -1
@@ -228,6 +228,32 @@ static int boot_instance_index;static char boot_snapshot_info[COMMAND_LINE_SIZE ]__initdata ;static int boot_snapshot_index; +/* +* Repeated boot parameters, including Bootconfig array expansions, need +* to stay in the delimiter form that the existing parser consumes. +*/ +void __init trace_append_boot_param (char *buf,const char *str,char sep, +int size) +{ +int len, needed, str_len; + +if (!*str) +return ; + + len =strlen (buf); + str_len =strlen (str); + needed = len + str_len +1 ; +if (len) + needed++; +if (needed > size) +return ; + +if (len) + buf[len++] = sep; + +strscpy (buf + len, str, size - len); +} +static int __init set_cmdline_ftrace (char *str) {strscpy (bootup_tracer_buf, str,MAX_TRACER_SIZE );
@@ -329,7 +355,8 @@ static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;static int __init set_trace_boot_options (char *str) { -strscpy (trace_boot_options_buf, str,MAX_TRACER_SIZE ); +trace_append_boot_param (trace_boot_options_buf, str,',' , +MAX_TRACER_SIZE );return 1 ; }__setup ("trace_options=" , set_trace_boot_options);
kernel/trace/trace.h +2 -0
@@ -863,6 +863,8 @@ extern int DYN_FTRACE_TEST_NAME(void);extern int DYN_FTRACE_TEST_NAME2 (void );extern void trace_set_ring_buffer_expanded (struct trace_array *tr); +void __init trace_append_boot_param (char *buf,const char *str, +char sep,int size);extern bool tracing_selftest_disabled;#ifdef CONFIG_FTRACE_STARTUP_TEST
kernel/trace/trace_events.c +20 -3
@@ -3679,20 +3679,37 @@ static struct boot_triggers { } bootup_triggers[MAX_BOOT_TRIGGERS ];static char bootup_trigger_buf[COMMAND_LINE_SIZE ]; +static int bootup_trigger_buf_len;static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) { +char *slot;char *trigger;char *buf;int i; -strscpy (bootup_trigger_buf, str,COMMAND_LINE_SIZE ); +if (bootup_trigger_buf_len >=COMMAND_LINE_SIZE ) +return 1 ; + + slot = bootup_trigger_buf + bootup_trigger_buf_len; + +/* +* trace_trigger= parsing tokenizes the backing storage in place. +* Copy each repeated parameter into fresh space and only parse that +* newly copied chunk here. +*/ +trace_append_boot_param (slot, str,'\0' , +COMMAND_LINE_SIZE - bootup_trigger_buf_len); +if (!*slot) +return 1 ; + + bootup_trigger_buf_len +=strlen (slot) +1 ;trace_set_ring_buffer_expanded (NULL );disable_tracing_selftest ("running event triggers" ); - buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { + buf = slot; +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) { trigger =strsep (&buf,"," );if (!trigger)break ;
kernel/trace/trace_kprobe.c +2 -1
@@ -31,7 +31,8 @@ static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata;static int __init set_kprobe_boot_events (char *str) { -strscpy (kprobe_boot_events_buf, str,COMMAND_LINE_SIZE ); +trace_append_boot_param (kprobe_boot_events_buf, str,';' , +COMMAND_LINE_SIZE );disable_tracing_selftest ("running kprobe events" );return 1 ;
Signature · 1 line
2.43.0
Steven Rostedt
maintainerRe: [PATCH v5] tracing: Preserve repeated boot-time tracing parameters
Quoted 20 lines · On Sat, 28 Mar 2026 14:18:42 -0600 Wesley Atwell <[email protected]> wrote:
Some tracing boot parameters already accept delimited value lists, but their
__setup()handlers keep only the last instance seen at boot. Make repeated instances append to the same boot-time buffer in the format each parser already consumes.Use a shared
trace_append_boot_param()helper for the ftrace filters,trace_options, andkprobe_eventboot parameters. trace_trigger= tokenizes its backing storage in place, so keep a running offset and only parse the newly appended chunk into bootup_triggers[].This also lets Bootconfig array values work naturally when they expand to repeated param=value entries.
Validated by booting with repeated ftrace_filter=, ftrace_notrace=, ftrace_graph_filter=, ftrace_graph_notrace=, trace_options=, kprobe_event=, and trace_trigger= parameters and confirming that the resulting tracefs state preserved every requested entry. Before this change, only the last instance from each repeated parameter survived boot.
Quoted 3 lines
Signed-off-by Wesley Atwell <[email protected]>---
v5:
FYI, it's nice to have a daisy chain connection of previous versions. I suggest instead of just saying "v5:" use:
Changes since v4: https://lore.kernel.org/all/[email protected]/
Quoted 13 lines
- use int sizes in the shared append helper and
trace_triggerbookkeeping
- keep a single bounded append path that only inserts the separator after the first entry
- only advance thetrace_triggerbuffer offset after a successful appendkernel/trace/ftrace.c | 12 ++++++++---- kernel/trace/trace.c | 29 ++++++++++++++++++++++++++++- kernel/trace/trace.h | 2 ++ kernel/trace/trace_events.c | 23 ++++++++++++++++++++--- kernel/trace/trace_kprobe.c | 3 ++- 5 files changed, 60 insertions(+), 9 deletions(-)
kernel/trace/trace.c static int boot_instance_index; · line 237
Quoted 7 lines
kernel/trace/trace.c +7
-0+/* +* Repeated boot parameters, including Bootconfig array expansions, need +* to stay in the delimiter form that the existing parser consumes. +*/ +void __init trace_append_boot_param (char *buf,const char *str,char sep, +int size) +{
This is much better.
kernel/trace/trace.c static int boot_instance_index; · line 245
Quoted 8 lines
kernel/trace/trace.c +8
-0+int len, needed, str_len; + +if (!*str) +return ; + + len =strlen (buf); + str_len =strlen (str); + needed = len + str_len +1 ;
Perhaps add a comment:
/* For continuation, account for separator */
Quoted 27 lines
kernel/trace/trace.c +11
-0+if (len) + needed++; +if (needed > size) +return ; + +if (len) + buf[len++] = sep; + +strscpy (buf + len, str, size - len); +} +static int __init set_cmdline_ftrace (char *str) {strscpy (bootup_tracer_buf, str,MAX_TRACER_SIZE );kernel/trace/trace_events.c +1
-0@@ -3679,20 +3679,37 @@ static struct boot_triggers { } bootup_triggers[MAX_BOOT_TRIGGERS ];static char bootup_trigger_buf[COMMAND_LINE_SIZE ]; +static int bootup_trigger_buf_len;static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) {
kernel/trace/trace_events.c static struct boot_triggers { · line 3695
Quoted 10 lines
kernel/trace/trace_events.c +5
-1+char *slot;char *trigger;char *buf;int i; -strscpy (bootup_trigger_buf, str,COMMAND_LINE_SIZE ); +if (bootup_trigger_buf_len >=COMMAND_LINE_SIZE ) +return 1 ; + + slot = bootup_trigger_buf + bootup_trigger_buf_len;
The bootup_trigger_buf is a temporary buffer for this function only. It works fine as is. There's no reason to modify this function.
-- Steve
Quoted 22 lines
kernel/trace/trace_events.c +14
-2+ +/* +* trace_trigger= parsing tokenizes the backing storage in place. +* Copy each repeated parameter into fresh space and only parse that +* newly copied chunk here. +*/ +trace_append_boot_param (slot, str,'\0' , +COMMAND_LINE_SIZE - bootup_trigger_buf_len); +if (!*slot) +return 1 ; + + bootup_trigger_buf_len +=strlen (slot) +1 ;trace_set_ring_buffer_expanded (NULL );disable_tracing_selftest ("running event triggers" ); - buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { + buf = slot; +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) { trigger =strsep (&buf,"," );if (!trigger)break ;
PATCH v6 1/1 tracing: Preserve repeated boot-time tracing parameters
In reply to Wesley AtwellSome tracing boot parameters already accept delimited value lists, but their __setup() handlers keep only the last instance seen at boot. Make repeated instances append to the same boot-time buffer in the format each parser already consumes.
Use a shared trace_append_boot_param() helper for the ftrace filters, trace_options, and kprobe_event boot parameters. trace_trigger= still tokenizes a temporary parse buffer in place, but now copies each parsed event/trigger pair into boot-time storage so repeated instances do not overwrite earlier ones.
This also lets Bootconfig array values work naturally when they expand to repeated param=value entries.
Before this change, only the last instance from each repeated parameter survived boot.
---
Changes since v5: https://lore.kernel.org/all/[email protected]/
- add the separator accounting comment in trace_append_boot_param()
- keep the existing trace_trigger= temporary buffer and copy each
parsed event/trigger pair into boot-time storage instead of tracking
a running offset inside that buffer
kernel/trace/ftrace.c | 12 ++++++++---- kernel/trace/trace.c | 30 +++++++++++++++++++++++++++++- kernel/trace/trace.h | 2 ++ kernel/trace/trace_events.c | 24 +++++++++++++++++++++--- kernel/trace/trace_kprobe.c | 3 ++- 5 files changed, 62 insertions(+), 9 deletions(-)
kernel/trace/ftrace.c +8 -4
@@ -6841,7 +6841,8 @@ bool ftrace_filter_param __initdata;static int __init set_ftrace_notrace (char *str) { ftrace_filter_param = true; -strscpy (ftrace_notrace_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_notrace_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_notrace=" , set_ftrace_notrace);
@@ -6849,7 +6850,8 @@ __setup("ftrace_notrace=", set_ftrace_notrace);static int __init set_ftrace_filter (char *str) { ftrace_filter_param = true; -strscpy (ftrace_filter_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_filter_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_filter=" , set_ftrace_filter);
@@ -6861,14 +6863,16 @@ static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);static int __init set_graph_function (char *str) { -strscpy (ftrace_graph_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_graph_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_filter=" , set_graph_function);static int __init set_graph_notrace_function (char *str) { -strscpy (ftrace_graph_notrace_buf, str,FTRACE_FILTER_SIZE ); +trace_append_boot_param (ftrace_graph_notrace_buf, str,',' , +FTRACE_FILTER_SIZE );return 1 ; }__setup ("ftrace_graph_notrace=" , set_graph_notrace_function);
kernel/trace/trace.c +29 -1
@@ -228,6 +228,33 @@ static int boot_instance_index;static char boot_snapshot_info[COMMAND_LINE_SIZE ]__initdata ;static int boot_snapshot_index; +/* +* Repeated boot parameters, including Bootconfig array expansions, need +* to stay in the delimiter form that the existing parser consumes. +*/ +void __init trace_append_boot_param (char *buf,const char *str,char sep, +int size) +{ +int len, needed, str_len; + +if (!*str) +return ; + + len =strlen (buf); + str_len =strlen (str); + needed = len + str_len +1 ; +/* For continuation, account for the separator. */ +if (len) + needed++; +if (needed > size) +return ; + +if (len) + buf[len++] = sep; + +strscpy (buf + len, str, size - len); +} +static int __init set_cmdline_ftrace (char *str) {strscpy (bootup_tracer_buf, str,MAX_TRACER_SIZE );
@@ -329,7 +356,8 @@ static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;static int __init set_trace_boot_options (char *str) { -strscpy (trace_boot_options_buf, str,MAX_TRACER_SIZE ); +trace_append_boot_param (trace_boot_options_buf, str,',' , +MAX_TRACER_SIZE );return 1 ; }__setup ("trace_options=" , set_trace_boot_options);
kernel/trace/trace.h +2 -0
@@ -863,6 +863,8 @@ extern int DYN_FTRACE_TEST_NAME(void);extern int DYN_FTRACE_TEST_NAME2 (void );extern void trace_set_ring_buffer_expanded (struct trace_array *tr); +void __init trace_append_boot_param (char *buf,const char *str, +char sep,int size);extern bool tracing_selftest_disabled;#ifdef CONFIG_FTRACE_STARTUP_TEST
kernel/trace/trace_events.c +21 -3
@@ -17,6 +17,7 @@#include <linux/kthread.h> #include <linux/tracefs.h> #include <linux/uaccess.h> +#include <linux/memblock.h> #include <linux/module.h> #include <linux/ctype.h> #include <linux/sort.h>
@@ -3674,7 +3675,7 @@ trace_create_new_event(struct trace_event_call *call,#define MAX_BOOT_TRIGGERS 32static struct boot_triggers { -const char *event; +char *event;char *trigger; } bootup_triggers[MAX_BOOT_TRIGGERS ];
@@ -3683,6 +3684,7 @@ static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) { +char *event;char *trigger;char *buf;int i;
@@ -3692,14 +3694,30 @@ static __init int setup_trace_triggers(char *str)disable_tracing_selftest ("running event triggers" ); buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) { trigger =strsep (&buf,"," );if (!trigger)break ; - bootup_triggers[i].event =strsep (&trigger,"." ); + event =strsep (&trigger,"." ); bootup_triggers[i].trigger = trigger;if (!bootup_triggers[i].trigger)break ; + +/* +* Keep each parsed trigger outside the temporary setup +* buffer so repeated trace_trigger= entries do not +* overwrite earlier ones. +*/ + bootup_triggers[i].event = +memblock_alloc_or_panic (strlen (event) +1 , +SMP_CACHE_BYTES ); +strscpy (bootup_triggers[i].event, event, +strlen (event) +1 ); + bootup_triggers[i].trigger = +memblock_alloc_or_panic (strlen (trigger) +1 , +SMP_CACHE_BYTES ); +strscpy (bootup_triggers[i].trigger, trigger, +strlen (trigger) +1 ); } nr_boot_triggers = i;
kernel/trace/trace_kprobe.c +2 -1
@@ -31,7 +31,8 @@ static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata;static int __init set_kprobe_boot_events (char *str) { -strscpy (kprobe_boot_events_buf, str,COMMAND_LINE_SIZE ); +trace_append_boot_param (kprobe_boot_events_buf, str,';' , +COMMAND_LINE_SIZE );disable_tracing_selftest ("running kprobe events" );return 1 ;
Signature · 1 line
2.43.0
Steven Rostedt
maintainerRe: [PATCH v6] tracing: Preserve repeated boot-time tracing parameters
On Sun, 29 Mar 2026 12:42:54 -0600
Wesley Atwell <[email protected]> wrote:
BTW, please do not reply to old versions of a patch with new versions. It makes it much more difficult for maintainers to find what is the last patch.
New versions of a patch should *always* be a start of a new thread!
Quoted 14 lines
Some tracing boot parameters already accept delimited value lists, but their
__setup()handlers keep only the last instance seen at boot. Make repeated instances append to the same boot-time buffer in the format each parser already consumes.Use a shared
trace_append_boot_param()helper for the ftrace filters,trace_options, andkprobe_eventboot parameters. trace_trigger= still tokenizes a temporary parse buffer in place, but now copies each parsed event/trigger pair into boot-time storage so repeated instances do not overwrite earlier ones.This also lets Bootconfig array values work naturally when they expand to repeated param=value entries.
Quoted 6 lines
Before this change, only the last instance from each repeated parameter survived boot.
Signed-off-by Wesley Atwell <[email protected]>---
Changes since v5: https://lore.kernel.org/all/[email protected]/
This is also why I suggested using the above link. The link shows how to find the old version of the patch, without relying on "In-Reply-To" header.
Quoted 24 lines
- add the separator accounting comment in
trace_append_boot_param()
- keep the existing trace_trigger= temporary buffer and copy each parsed event/trigger pair into boot-time storage instead of tracking a running offset inside that bufferkernel/trace/ftrace.c | 12 ++++++++---- kernel/trace/trace.c | 30 +++++++++++++++++++++++++++++- kernel/trace/trace.h | 2 ++ kernel/trace/trace_events.c | 24 +++++++++++++++++++++--- kernel/trace/trace_kprobe.c | 3 ++- 5 files changed, 62 insertions(+), 9 deletions(-)kernel/trace/trace.c +5
-0@@ -228,6 +228,33 @@ static int boot_instance_index;static char boot_snapshot_info[COMMAND_LINE_SIZE ]__initdata ;static int boot_snapshot_index; +/* +* Repeated boot parameters, including Bootconfig array expansions, need +* to stay in the delimiter form that the existing parser consumes. +*/ +void __init trace_append_boot_param(char *buf, const char *str, char sep,
kernel/trace/trace.c static int boot_instance_index; · line 245
Quoted 10 lines
kernel/trace/trace.c +10
-0+ int size) +{ +int len, needed, str_len; + +if (!*str) +return ; + + len =strlen (buf); + str_len =strlen (str); + needed = len + str_len +1 ;
Nit, but it would be nice to have a blank line here.
Quoted 68 lines
kernel/trace/trace.c +14
-1+/* For continuation, account for the separator. */ +if (len) + needed++; +if (needed > size) +return ; + +if (len) + buf[len++] = sep; + +strscpy (buf + len, str, size - len); +} +static int __init set_cmdline_ftrace (char *str) {strscpy (bootup_tracer_buf, str,MAX_TRACER_SIZE );@@ -329,7 +356,8 @@ static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;static int __init set_trace_boot_options (char *str) { -strscpy (trace_boot_options_buf, str,MAX_TRACER_SIZE ); +trace_append_boot_param (trace_boot_options_buf, str,',' , +MAX_TRACER_SIZE );return 1 ; }__setup ("trace_options=" , set_trace_boot_options);kernel/trace/trace.h +2
-0@@ -863,6 +863,8 @@ extern int DYN_FTRACE_TEST_NAME(void);extern int DYN_FTRACE_TEST_NAME2 (void );extern void trace_set_ring_buffer_expanded (struct trace_array *tr); +void __init trace_append_boot_param (char *buf,const char *str, +char sep,int size);extern bool tracing_selftest_disabled;#ifdef CONFIG_FTRACE_STARTUP_TEST kernel/trace/trace_events.c +3
-1@@ -17,6 +17,7 @@#include <linux/kthread.h> #include <linux/tracefs.h> #include <linux/uaccess.h> +#include <linux/memblock.h> #include <linux/module.h> #include <linux/ctype.h> #include <linux/sort.h> @@ -3674,7 +3675,7 @@ trace_create_new_event(struct trace_event_call *call,#define MAX_BOOT_TRIGGERS 32static struct boot_triggers { -const char *event; +char *event;char *trigger; } bootup_triggers[MAX_BOOT_TRIGGERS ];@@ -3683,6 +3684,7 @@ static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) { +char *event;char *trigger;char *buf;int i;
kernel/trace/trace_events.c static __init int setup_trace_triggers(char *str) · line 3697
Quoted 5 lines
kernel/trace/trace_events.c +1
-1@@ -3692,14 +3694,30 @@ static __init int setup_trace_triggers(char *str)disable_tracing_selftest ("running event triggers" ); buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) {
Let's not make this so complex.
This function isn't the same as the other functions. It doesn't need to add separators to the temp buffer. It only needs to append it.
Quoted 15 lines
kernel/trace/trace_events.c +8
-1trigger =strsep (&buf,"," );if (!trigger)break ; - bootup_triggers[i].event =strsep (&trigger,"." ); + event =strsep (&trigger,"." ); bootup_triggers[i].trigger = trigger;if (!bootup_triggers[i].trigger)break ; + +/* +* Keep each parsed trigger outside the temporary setup +* buffer so repeated trace_trigger= entries do not +* overwrite earlier ones. +*/ + bootup_triggers[i].event =
kernel/trace/trace_events.c static __init int setup_trace_triggers(char *str) · line 3721
Quoted 10 lines
kernel/trace/trace_events.c +9
-0+memblock_alloc_or_panic (strlen (event) +1 , +SMP_CACHE_BYTES ); +strscpy (bootup_triggers[i].event, event, +strlen (event) +1 ); + bootup_triggers[i].trigger = +memblock_alloc_or_panic (strlen (trigger) +1 , +SMP_CACHE_BYTES ); +strscpy (bootup_triggers[i].trigger, trigger, +strlen (trigger) +1 ); }
I believe all you need for the boot triggers is this:
(Not even compiled tested)
kernel/trace/trace_events.c +7 -3
@@ -3677,20 +3677,24 @@ static struct boot_triggers { } bootup_triggers[MAX_BOOT_TRIGGERS ];static char bootup_trigger_buf[COMMAND_LINE_SIZE ]; +static int boot_trigger_buf_len;static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) {char *trigger;char *buf; +int len = boot_trigger_buf_len;int i; -strscpy (bootup_trigger_buf, str,COMMAND_LINE_SIZE ); +strscpy (bootup_trigger_buf + len , str,COMMAND_LINE_SIZE - len);trace_set_ring_buffer_expanded (NULL );disable_tracing_selftest ("running event triggers" ); - buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { + buf = bootup_trigger_buf + len; + boot_trigger_buf_len +=strlen (buf); + +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) { trigger =strsep (&buf,"," );if (!trigger)break ;
Steven Rostedt
maintainerRe: [PATCH v6] tracing: Preserve repeated boot-time tracing parameters
Quoted 17 lines · On Mon, 30 Mar 2026 10:43:22 -0400 Steven Rostedt <[email protected]> wrote:
kernel/trace/trace_events.c +2
-0@@ -3677,20 +3677,24 @@ static struct boot_triggers { } bootup_triggers[MAX_BOOT_TRIGGERS ];static char bootup_trigger_buf[COMMAND_LINE_SIZE ]; +static int boot_trigger_buf_len;static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) {char *trigger;char *buf; +int len = boot_trigger_buf_len;int i;
kernel/trace/trace_events.c static struct boot_triggers { · line 3695
Quoted 10 lines
kernel/trace/trace_events.c +3
-3-strscpy (bootup_trigger_buf, str,COMMAND_LINE_SIZE ); +strscpy (bootup_trigger_buf + len , str,COMMAND_LINE_SIZE - len);trace_set_ring_buffer_expanded (NULL );disable_tracing_selftest ("running event triggers" ); - buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { + buf = bootup_trigger_buf + len; + boot_trigger_buf_len +=strlen (buf);
The above needs to skip the '\0' too:
boot_trigger_buf_len += strlen(buf) + 1;
Quoted 5 lines
kernel/trace/trace_events.c +2
-0+ +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) { trigger =strsep (&buf,"," );if (!trigger)break ;
Steven Rostedt
maintainerRe: [PATCH v6] tracing: Preserve repeated boot-time tracing parameters
Quoted 26 lines · On Mon, 30 Mar 2026 12:37:43 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 23 lines · On Mon, 30 Mar 2026 10:43:22 -0400 Steven Rostedt <[email protected]> wrote:
kernel/trace/trace_events.c +3
-1@@ -3677,20 +3677,24 @@ static struct boot_triggers { } bootup_triggers[MAX_BOOT_TRIGGERS ];static char bootup_trigger_buf[COMMAND_LINE_SIZE ]; +static int boot_trigger_buf_len;static int nr_boot_triggers;static __init int setup_trace_triggers (char *str) {char *trigger;char *buf; +int len = boot_trigger_buf_len;int i; -strscpy (bootup_trigger_buf, str,COMMAND_LINE_SIZE ); +strscpy (bootup_trigger_buf + len , str,COMMAND_LINE_SIZE - len);trace_set_ring_buffer_expanded (NULL );disable_tracing_selftest ("running event triggers" );
Quoted 9 lines
kernel/trace/trace_events.c static struct boot_triggers { · line 3695
Quoted 4 lines
kernel/trace/trace_events.c +2
-2- buf = bootup_trigger_buf; -for (i =0 ; i <MAX_BOOT_TRIGGERS ; i++) { + buf = bootup_trigger_buf + len; + boot_trigger_buf_len +=strlen (buf);The above needs to skip the '\0' too:
boot_trigger_buf_len += strlen(buf) + 1;
And since this option is different from the rest, lets make it a separate patch.
-- Steve
Quoted 7 lines
Quoted 6 lines
kernel/trace/trace_events.c +2
-0+ +for (i = nr_boot_triggers; i <MAX_BOOT_TRIGGERS ; i++) { trigger =strsep (&buf,"," );if (!trigger)break ;
PATCH v4 2/2 tracing: Drain deferred trigger frees if kthread creation fails
In reply to Wesley AtwellBoot-time trigger registration can fail before the trigger-data cleanup kthread exists. Deferring those frees until late init is fine, but the post-boot fallback must still drain the deferred list if kthread creation never succeeds.
Otherwise, boot-deferred nodes can accumulate on trigger_data_free_list, later frees fall back to synchronously freeing only the current object, and the older queued entries are leaked forever.
Keep the deferred boot-time behavior, but when kthread creation fails, drain the whole queued list synchronously. Do the same in the late-init drain path so queued entries are not stranded there either.
--- kernel/trace/trace_events_trigger.c | 79 ++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 13 deletions(-)
kernel/trace/trace_events_trigger.c +66 -13
@@ -22,6 +22,39 @@ static struct task_struct *trigger_kthread;static struct llist_head trigger_data_free_list;static DEFINE_MUTEX (trigger_data_kthread_mutex); +static int trigger_kthread_fn (void *ignore); + +static void trigger_create_kthread_locked (void ) +{ +lockdep_assert_held (&trigger_data_kthread_mutex); + +if (!trigger_kthread) { +struct task_struct *kthread; + + kthread =kthread_create (trigger_kthread_fn,NULL , +"trigger_data_free" ); +if (!IS_ERR (kthread)) +WRITE_ONCE (trigger_kthread, kthread); + } +} + +static void trigger_data_free_queued_locked (void ) +{ +struct event_trigger_data *data, *tmp; +struct llist_node *llnodes; + +lockdep_assert_held (&trigger_data_kthread_mutex); + + llnodes =llist_del_all (&trigger_data_free_list); +if (!llnodes) +return ; + +tracepoint_synchronize_unregister (); + +llist_for_each_entry_safe (data, tmp, llnodes, llist) +kfree (data); +} +/* Bulk garbage collection of event_trigger_data elements */ static int trigger_kthread_fn (void *ignore) {
@@ -56,30 +89,50 @@ void trigger_data_free(struct event_trigger_data *data)if (data->cmd_ops->set_filter) data->cmd_ops->set_filter (NULL , data,NULL ); +/* +* Boot-time trigger registration can fail before kthread creation +* works. Keep the deferred-free semantics during boot and let late +* init start the kthread to drain the list. +*/ +if (system_state ==SYSTEM_BOOTING && !trigger_kthread) { +llist_add (&data->llist, &trigger_data_free_list); +return ; + } +if (unlikely (!trigger_kthread)) {guard (mutex)(&trigger_data_kthread_mutex); + +trigger_create_kthread_locked ();/* Check again after taking mutex */ if (!trigger_kthread) { -struct task_struct *kthread; - - kthread =kthread_create (trigger_kthread_fn,NULL , -"trigger_data_free" ); -if (!IS_ERR (kthread)) -WRITE_ONCE (trigger_kthread, kthread); +llist_add (&data->llist, &trigger_data_free_list); +/* Drain the queued frees synchronously if creation failed. */ +trigger_data_free_queued_locked (); +return ; } } -if (!trigger_kthread) { -/* Do it the slow way */ -tracepoint_synchronize_unregister (); -kfree (data); -return ; - } -llist_add (&data->llist, &trigger_data_free_list);wake_up_process (trigger_kthread); } +static int __init trigger_data_free_init (void ) +{ +guard (mutex)(&trigger_data_kthread_mutex); + +if (llist_empty (&trigger_data_free_list)) +return 0 ; + +trigger_create_kthread_locked (); +if (trigger_kthread) +wake_up_process (trigger_kthread); +else +trigger_data_free_queued_locked (); + +return 0 ; +} +late_initcall (trigger_data_free_init); +static inline void data_ops_trigger (struct event_trigger_data *data,struct trace_buffer *buffer,void *rec,struct ring_buffer_event *event)
Signature · 1 line
2.43.0
Steven Rostedt
maintainerRe: [PATCH v4 2/2] tracing: Drain deferred trigger frees if kthread creation fails
Quoted 10 lines · On Tue, 24 Mar 2026 16:13:26 -0600 Wesley Atwell <[email protected]> wrote:
Boot-time trigger registration can fail before the trigger-data cleanup kthread exists. Deferring those frees until late init is fine, but the post-boot fallback must still drain the deferred list if kthread creation never succeeds.
Otherwise, boot-deferred nodes can accumulate on
trigger_data_free_list, later frees fall back to synchronously freeing only the current object, and the older queued entries are leaked forever.
Quoted 7 lines
Keep the deferred boot-time behavior, but when kthread creation fails, drain the whole queued list synchronously. Do the same in the late-init drain path so queued entries are not stranded there either.
Fixes 61d445af0a7c ("tracing: Add bulk garbage collection of freeing event_trigger_data")Signed-off-by Wesley Atwell <[email protected]>---
Do you have a test case (kernel command line) that will make trigger_data_free() get called at boot up?
-- Steve
Re: [PATCH v4 2/2] tracing: Drain deferred trigger frees if kthread creation fails
Yes,
This kernel command line reliably reaches trigger_data_free() during boot:
trace_event=sched:sched_switch trace_trigger=sched_switch.traceon,sched_switch.traceon
On an unpatched tree, that crashes during early boot before userspace. The call trace goes through:
trigger_data_free()__kthread_create_on_node()try_to_wake_up()
The stack also shows the boot-time trigger registration path:
event_trigger_parse()trigger_process_regex()__trace_early_add_events()
With v4 applied, the same command line boots successfully. The guest log shows:
Failed to register trigger 'traceon' on event sched_switch
And /sys/kernel/tracing/events/sched/sched_switch/trigger contains:
traceon:unlimited
I also verified patch 1 with repeated trace_trigger= parameters:
before the patch, only the last parameter was preserved; after the patch, both triggers were installed.
Thanks,
Wesley Atwell
Steven Rostedt
maintainerRe: [PATCH v4 2/2] tracing: Drain deferred trigger frees if kthread creation fails
Quoted 14 lines · On Fri, 27 Mar 2026 16:41:52 -0600 Wesley Atwell <[email protected]> wrote:
Yes,
This kernel command line reliably reaches
trigger_data_free()during boot:trace_event=sched:sched_switch trace_trigger=sched_switch.traceon,sched_switch.traceon
On an unpatched tree, that crashes during early boot before userspace. The call trace goes through:
trigger_data_free()__kthread_create_on_node()try_to_wake_up()
Quoted 5 lines
The stack also shows the boot-time trigger registration path:
event_trigger_parse()trigger_process_regex()__trace_early_add_events()
Thanks for this. I can reproduce the crash. I'm also going to add this to the change log as it is useful (I'll even add it to one of my regression tests). I'll take this patch separately (this didn't need to be a patch series, as the two patches do not depend on each other).
-- Steve
Re: [PATCH v4 2/2] tracing: Drain deferred trigger frees if kthread creation fails
Hi Steve,
I'm glad the test case was helpful. I'll include similar testing details in future commit messages and avoid grouping unrelated patches.
Thanks,
Wesley Atwell