* [for-next][PATCH 01/15] tracing: Do not clean up hiter in mmiotrace read function
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 02/15] lockdep: Add #include <linux/instruction_pointer.h> to lockdep.h Steven Rostedt
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: Steven Rostedt <rostedt@goodmis.org>
When the mmiotrace trace was first created, it allocated a descriptor in
its pipe_open() method. Since there was no pipe_close() method when it was
created (in May of 2008, and pipe_close() was added in December of 2009),
it cleaned up the allocated descriptors in the read.
Now that the clean up is in the pipe_close() method that now exists,
remove the clean up from the read as it is no longer needed.
Also simplify the code by inverting the early exit conditional into a
conditional to perform the logic and get rid of the goto.
Link: https://lore.kernel.org/all/20260715143604.14481-1-gaikwad.dcg@gmail.com/
Link: https://lore.kernel.org/all/20260721211143.36dbd559@gandalf.local.home/
Link: https://patch.msgid.link/20260721212010.76e9ed61@gandalf.local.home
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_mmiotrace.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
index 77120d467e11..c49738cdb439 100644
--- a/kernel/trace/trace_mmiotrace.c
+++ b/kernel/trace/trace_mmiotrace.c
@@ -143,21 +143,13 @@ static ssize_t mmio_read(struct trace_iterator *iter, struct file *filp,
if (!overrun_detected)
pr_warn("mmiotrace has lost events\n");
overrun_detected = true;
- goto print_out;
}
- if (!hiter || !hiter->dev)
- return 0;
-
- mmio_print_pcidev(s, hiter->dev);
- hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev);
-
- if (!hiter->dev) {
- destroy_header_iter(hiter);
- iter->private = NULL;
+ if (hiter && hiter->dev) {
+ mmio_print_pcidev(s, hiter->dev);
+ hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev);
}
-print_out:
ret = trace_seq_to_user(s, ubuf, cnt);
return (ret == -EBUSY) ? 0 : ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 02/15] lockdep: Add #include <linux/instruction_pointer.h> to lockdep.h
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 01/15] tracing: Do not clean up hiter in mmiotrace read function Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 03/15] tracing: Move non-trace_printk prototypes into trace_controls.h Steven Rostedt
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
Yury Norov, Peter Zijlstra (Intel)
From: Steven Rostedt <rostedt@goodmis.org>
On 32bit x86, _THIS_IP_ is not defined in asm/linkage.h. It happens to get
included into lockdep.h via kernel.h pulling in trace_printk.h which
includes instruction_pointer.h that has _THIS_IP_ defined when linkage.h
does not.
In order to remove trace_printk.h from kernel.h, have lockdep.h include
instruction_pointer.h directly.
Link: https://patch.msgid.link/20261102202407.305916932@kernel.org
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
include/linux/lockdep.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index a6451ecbbe9a..c6b0168f5fc9 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -22,6 +22,7 @@ struct task_struct;
#include <linux/list.h>
#include <linux/debug_locks.h>
#include <linux/stacktrace.h>
+#include <linux/instruction_pointer.h> /* In case _THIS_IP_ isn't defined */
static inline void lockdep_copy_map(struct lockdep_map *to,
struct lockdep_map *from)
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 03/15] tracing: Move non-trace_printk prototypes into trace_controls.h
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 01/15] tracing: Do not clean up hiter in mmiotrace read function Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 02/15] lockdep: Add #include <linux/instruction_pointer.h> to lockdep.h Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 04/15] tracing: Remove trace_printk.h from kernel.h Steven Rostedt
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
Yury Norov, Yury Norov
From: Steven Rostedt <rostedt@goodmis.org>
Remove the prototypes of the code that is not associated with
trace_printk() from trace_printk.h.
These control functions as well as ftrace_dump() and trace_dump_stack()
are used in cases where things go wrong. The main use case is to do a
trace_dump_stack(); tracing_off(); ftrace_dump(); in a place that detected
that something went wrong, whereas, trace_printk() is added to normal code
during debugging and removed before committing upstream. The dump code is
fine to keep in production.
Link: https://patch.msgid.link/20261102202407.519348871@kernel.org
Suggested-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: Yury Norov <ynorov@nvidia.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
arch/powerpc/xmon/xmon.c | 1 +
arch/s390/kernel/ipl.c | 1 +
arch/s390/kernel/machine_kexec.c | 1 +
drivers/gpu/drm/i915/i915_gem.h | 1 +
drivers/tty/sysrq.c | 1 +
include/linux/trace_controls.h | 54 ++++++++++++++++++++++++++++++++
include/linux/trace_printk.h | 51 ------------------------------
kernel/debug/debug_core.c | 1 +
kernel/panic.c | 1 +
kernel/rcu/rcu.h | 1 +
kernel/rcu/rcutorture.c | 1 +
kernel/trace/trace.h | 1 +
kernel/trace/trace_benchmark.c | 1 +
lib/sys_info.c | 1 +
14 files changed, 66 insertions(+), 51 deletions(-)
create mode 100644 include/linux/trace_controls.h
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 90a8d7a8f42d..5e1336e2cecd 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -27,6 +27,7 @@
#include <linux/highmem.h>
#include <linux/security.h>
#include <linux/debugfs.h>
+#include <linux/trace_controls.h>
#include <asm/ptrace.h>
#include <asm/smp.h>
diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index c441b1357492..3c8b693d3ed7 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -22,6 +22,7 @@
#include <linux/debug_locks.h>
#include <linux/vmalloc.h>
#include <linux/secure_boot.h>
+#include <linux/trace_controls.h>
#include <asm/asm-extable.h>
#include <asm/machine.h>
#include <asm/diag.h>
diff --git a/arch/s390/kernel/machine_kexec.c b/arch/s390/kernel/machine_kexec.c
index baeb3dcfc1c8..33f9a89eb3ad 100644
--- a/arch/s390/kernel/machine_kexec.c
+++ b/arch/s390/kernel/machine_kexec.c
@@ -12,6 +12,7 @@
#include <linux/delay.h>
#include <linux/reboot.h>
#include <linux/ftrace.h>
+#include <linux/trace_controls.h>
#include <linux/debug_locks.h>
#include <linux/cpufeature.h>
#include <asm/guarded_storage.h>
diff --git a/drivers/gpu/drm/i915/i915_gem.h b/drivers/gpu/drm/i915/i915_gem.h
index 80d9758fe684..5ec2ac13a5f0 100644
--- a/drivers/gpu/drm/i915/i915_gem.h
+++ b/drivers/gpu/drm/i915/i915_gem.h
@@ -116,6 +116,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
#endif
#if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
+#include <linux/trace_controls.h>
#define GEM_TRACE(...) trace_printk(__VA_ARGS__)
#define GEM_TRACE_ERR(...) do { \
pr_err(__VA_ARGS__); \
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index f4571d05b496..eb85e6b97f18 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -324,6 +324,7 @@ static const struct sysrq_key_op sysrq_showstate_blocked_op = {
};
#ifdef CONFIG_TRACING
+#include <linux/trace_controls.h>
#include <linux/ftrace.h>
static void sysrq_ftrace_dump(u8 key)
diff --git a/include/linux/trace_controls.h b/include/linux/trace_controls.h
new file mode 100644
index 000000000000..995b97e963b4
--- /dev/null
+++ b/include/linux/trace_controls.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_TRACE_CONTROLS_H
+#define _LINUX_TRACE_CONTROLS_H
+
+
+/*
+ * General tracing related utility functions - trace_printk(),
+ * tracing_on/tracing_off and tracing_start()/tracing_stop
+ *
+ * Use tracing_on/tracing_off when you want to quickly turn on or off
+ * tracing. It simply enables or disables the recording of the trace events.
+ * This also corresponds to the user space /sys/kernel/tracing/tracing_on
+ * file, which gives a means for the kernel and userspace to interact.
+ * Place a tracing_off() in the kernel where you want tracing to end.
+ * From user space, examine the trace, and then echo 1 > tracing_on
+ * to continue tracing.
+ *
+ * tracing_stop/tracing_start has slightly more overhead. It is used
+ * by things like suspend to ram where disabling the recording of the
+ * trace is not enough, but tracing must actually stop because things
+ * like calling smp_processor_id() may crash the system.
+ *
+ * Most likely, you want to use tracing_on/tracing_off.
+ */
+enum ftrace_dump_mode {
+ DUMP_NONE,
+ DUMP_ALL,
+ DUMP_ORIG,
+ DUMP_PARAM,
+};
+
+#ifdef CONFIG_TRACING
+void tracing_on(void);
+void tracing_off(void);
+int tracing_is_on(void);
+void tracing_snapshot(void);
+void tracing_snapshot_alloc(void);
+void tracing_start(void);
+void tracing_stop(void);
+void trace_dump_stack(int skip);
+void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
+#else
+static inline void tracing_start(void) { }
+static inline void tracing_stop(void) { }
+static inline void tracing_on(void) { }
+static inline void tracing_off(void) { }
+static inline int tracing_is_on(void) { return 0; }
+static inline void tracing_snapshot(void) { }
+static inline void tracing_snapshot_alloc(void) { }
+static inline void trace_dump_stack(int skip) { }
+static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
+#endif
+
+#endif /* _LINUX_TRACE_CONTROLS_H */
diff --git a/include/linux/trace_printk.h b/include/linux/trace_printk.h
index 3d54f440dccf..a488ea9e9f85 100644
--- a/include/linux/trace_printk.h
+++ b/include/linux/trace_printk.h
@@ -7,43 +7,7 @@
#include <linux/stddef.h>
#include <linux/stringify.h>
-/*
- * General tracing related utility functions - trace_printk(),
- * tracing_on/tracing_off and tracing_start()/tracing_stop
- *
- * Use tracing_on/tracing_off when you want to quickly turn on or off
- * tracing. It simply enables or disables the recording of the trace events.
- * This also corresponds to the user space /sys/kernel/tracing/tracing_on
- * file, which gives a means for the kernel and userspace to interact.
- * Place a tracing_off() in the kernel where you want tracing to end.
- * From user space, examine the trace, and then echo 1 > tracing_on
- * to continue tracing.
- *
- * tracing_stop/tracing_start has slightly more overhead. It is used
- * by things like suspend to ram where disabling the recording of the
- * trace is not enough, but tracing must actually stop because things
- * like calling smp_processor_id() may crash the system.
- *
- * Most likely, you want to use tracing_on/tracing_off.
- */
-
-enum ftrace_dump_mode {
- DUMP_NONE,
- DUMP_ALL,
- DUMP_ORIG,
- DUMP_PARAM,
-};
-
#ifdef CONFIG_TRACING
-void tracing_on(void);
-void tracing_off(void);
-int tracing_is_on(void);
-void tracing_snapshot(void);
-void tracing_snapshot_alloc(void);
-
-extern void tracing_start(void);
-extern void tracing_stop(void);
-
static inline __printf(1, 2)
void ____trace_printk_check_format(const char *fmt, ...)
{
@@ -149,8 +113,6 @@ int __trace_printk(unsigned long ip, const char *fmt, ...);
extern int __trace_bputs(unsigned long ip, const char *str);
extern int __trace_puts(unsigned long ip, const char *str);
-extern void trace_dump_stack(int skip);
-
/*
* The double __builtin_constant_p is because gcc will give us an error
* if we try to allocate the static variable to fmt if it is not a
@@ -173,19 +135,7 @@ __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
extern __printf(2, 0) int
__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
-
-extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
#else
-static inline void tracing_start(void) { }
-static inline void tracing_stop(void) { }
-static inline void trace_dump_stack(int skip) { }
-
-static inline void tracing_on(void) { }
-static inline void tracing_off(void) { }
-static inline int tracing_is_on(void) { return 0; }
-static inline void tracing_snapshot(void) { }
-static inline void tracing_snapshot_alloc(void) { }
-
static inline __printf(1, 2)
int trace_printk(const char *fmt, ...)
{
@@ -196,7 +146,6 @@ ftrace_vprintk(const char *fmt, va_list ap)
{
return 0;
}
-static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
#endif /* CONFIG_TRACING */
#endif
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 1c9bc705c32c..342a3c1f202f 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -27,6 +27,7 @@
#define pr_fmt(fmt) "KGDB: " fmt
+#include <linux/trace_controls.h>
#include <linux/pid_namespace.h>
#include <linux/clocksource.h>
#include <linux/serial_core.h>
diff --git a/kernel/panic.c b/kernel/panic.c
index 91e48d33b7db..39376f270a9a 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -9,6 +9,7 @@
* This function is used through-out the kernel (including mm and fs)
* to indicate a major problem.
*/
+#include <linux/trace_controls.h>
#include <linux/debug_locks.h>
#include <linux/sched/debug.h>
#include <linux/interrupt.h>
diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h
index d60444bf3a02..e5583337b2f7 100644
--- a/kernel/rcu/rcu.h
+++ b/kernel/rcu/rcu.h
@@ -12,6 +12,7 @@
#include <linux/slab.h>
#include <trace/events/rcu.h>
+#include <linux/trace_controls.h>
/*
* Grace-period counter management.
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 93ca7f06371e..c2b2baa50aa3 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -39,6 +39,7 @@
#include <linux/srcu.h>
#include <linux/slab.h>
#include <linux/trace_clock.h>
+#include <linux/trace_controls.h>
#include <asm/byteorder.h>
#include <linux/torture.h>
#include <linux/vmalloc.h>
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 1fec567e789e..2efb580d7a15 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -22,6 +22,7 @@
#include <linux/ctype.h>
#include <linux/once_lite.h>
#include <linux/ftrace_regs.h>
+#include <linux/trace_controls.h>
#include <linux/llist.h>
#include "pid_list.h"
diff --git a/kernel/trace/trace_benchmark.c b/kernel/trace/trace_benchmark.c
index e19c32f2a938..69cc39008c36 100644
--- a/kernel/trace/trace_benchmark.c
+++ b/kernel/trace/trace_benchmark.c
@@ -3,6 +3,7 @@
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/trace_clock.h>
+#include <linux/trace_controls.h>
#define CREATE_TRACE_POINTS
#include "trace_benchmark.h"
diff --git a/lib/sys_info.c b/lib/sys_info.c
index f32a06ec9ed4..e3c9ca05601b 100644
--- a/lib/sys_info.c
+++ b/lib/sys_info.c
@@ -8,6 +8,7 @@
#include <linux/ftrace.h>
#include <linux/nmi.h>
#include <linux/sched/debug.h>
+#include <linux/trace_controls.h>
#include <linux/string.h>
#include <linux/sysctl.h>
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 04/15] tracing: Remove trace_printk.h from kernel.h
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (2 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 03/15] tracing: Move non-trace_printk prototypes into trace_controls.h Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 05/15] tracing: Override the same name trace_instance= by latter one Steven Rostedt
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
Yury Norov, Yury Norov
From: Steven Rostedt <rostedt@goodmis.org>
There have been complaints about trace_printk.h causing more build time
for being in kernel.h if it changes. There is also an effort to clean up
kernel.h to have it not include unneeded header files. Move trace_printk.h
out of kernel.h and place it in the headers and C files that use it.
Link: https://lore.kernel.org/all/CAHk-=wikCBeVFjVXiY4o-oepdbjAoir5+TcAgtL12c4u1TpZLQ@mail.gmail.com/
Link: https://patch.msgid.link/20261102202407.732929894@kernel.org
Suggested-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: Yury Norov <ynorov@nvidia.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
arch/powerpc/kvm/book3s_xics.c | 1 +
drivers/gpu/drm/i915/gt/intel_gtt.h | 1 +
drivers/gpu/drm/i915/i915_gem.h | 1 +
drivers/hwtracing/stm/dummy_stm.c | 1 +
drivers/infiniband/hw/hfi1/trace_dbg.h | 1 +
drivers/usb/early/xhci-dbc.c | 1 +
fs/ext4/inline.c | 1 +
include/linux/ftrace.h | 2 ++
include/linux/kernel.h | 1 -
include/linux/sunrpc/debug.h | 1 +
include/linux/trace_printk.h | 5 +++--
include/trace/trace_events.h | 2 ++
kernel/trace/ring_buffer_benchmark.c | 1 +
samples/fprobe/fprobe_example.c | 1 +
samples/ftrace/ftrace-direct-too.c | 1 -
samples/trace_printk/trace-printk.c | 1 +
16 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 74a44fa702b0..ef5eb596a56e 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -26,6 +26,7 @@
#if 1
#define XICS_DBG(fmt...) do { } while (0)
#else
+#include <linux/trace_printk.h>
#define XICS_DBG(fmt...) trace_printk(fmt)
#endif
diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h
index b54ee4f25af1..f6f223090760 100644
--- a/drivers/gpu/drm/i915/gt/intel_gtt.h
+++ b/drivers/gpu/drm/i915/gt/intel_gtt.h
@@ -35,6 +35,7 @@
#define I915_GFP_ALLOW_FAIL (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN)
#if IS_ENABLED(CONFIG_DRM_I915_TRACE_GTT)
+#include <linux/trace_printk.h>
#define GTT_TRACE(...) trace_printk(__VA_ARGS__)
#else
#define GTT_TRACE(...)
diff --git a/drivers/gpu/drm/i915/i915_gem.h b/drivers/gpu/drm/i915/i915_gem.h
index 5ec2ac13a5f0..a616ced060bf 100644
--- a/drivers/gpu/drm/i915/i915_gem.h
+++ b/drivers/gpu/drm/i915/i915_gem.h
@@ -117,6 +117,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
#if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
#include <linux/trace_controls.h>
+#include <linux/trace_printk.h>
#define GEM_TRACE(...) trace_printk(__VA_ARGS__)
#define GEM_TRACE_ERR(...) do { \
pr_err(__VA_ARGS__); \
diff --git a/drivers/hwtracing/stm/dummy_stm.c b/drivers/hwtracing/stm/dummy_stm.c
index 38528ffdc0b3..7c5e48ebfb9f 100644
--- a/drivers/hwtracing/stm/dummy_stm.c
+++ b/drivers/hwtracing/stm/dummy_stm.c
@@ -8,6 +8,7 @@
*/
#undef DEBUG
+#include <linux/trace_printk.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
diff --git a/drivers/infiniband/hw/hfi1/trace_dbg.h b/drivers/infiniband/hw/hfi1/trace_dbg.h
index 58304b91380f..30df5e246586 100644
--- a/drivers/infiniband/hw/hfi1/trace_dbg.h
+++ b/drivers/infiniband/hw/hfi1/trace_dbg.h
@@ -103,6 +103,7 @@ __hfi1_trace_def(IOCTL);
*/
#ifdef HFI1_EARLY_DBG
+#include <linux/trace_printk.h>
#define hfi1_dbg_early(fmt, ...) \
trace_printk(fmt, ##__VA_ARGS__)
#else
diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
index 41118bba9197..955c73bd601f 100644
--- a/drivers/usb/early/xhci-dbc.c
+++ b/drivers/usb/early/xhci-dbc.c
@@ -30,6 +30,7 @@ static struct xdbc_state xdbc;
static bool early_console_keep;
#ifdef XDBC_TRACE
+#include <linux/trace_printk.h>
#define xdbc_trace trace_printk
#else
static inline void xdbc_trace(const char *fmt, ...) { }
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index ceee69a66482..8af80d342ecd 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -943,6 +943,7 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
}
#ifdef INLINE_DIR_DEBUG
+#include <linux/trace_printk.h>
void ext4_show_inline_dir(struct inode *dir, struct buffer_head *bh,
void *inline_start, int inline_size)
{
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 1c2056a1a68b..17b4c868b9cc 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -8,6 +8,8 @@
#define _LINUX_FTRACE_H
#include <linux/trace_recursion.h>
+#include <linux/trace_controls.h>
+#include <linux/trace_printk.h>
#include <linux/trace_clock.h>
#include <linux/jump_label.h>
#include <linux/kallsyms.h>
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4b11d1dc0a67..be890c00802a 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -31,7 +31,6 @@
#include <linux/build_bug.h>
#include <linux/sprintf.h>
#include <linux/static_call_types.h>
-#include <linux/trace_printk.h>
#include <linux/util_macros.h>
#include <linux/wordpart.h>
diff --git a/include/linux/sunrpc/debug.h b/include/linux/sunrpc/debug.h
index ab61bed2f7af..7524f5d82fba 100644
--- a/include/linux/sunrpc/debug.h
+++ b/include/linux/sunrpc/debug.h
@@ -29,6 +29,7 @@ extern unsigned int nlm_debug;
# define ifdebug(fac) if (unlikely(rpc_debug & RPCDBG_##fac))
# if IS_ENABLED(CONFIG_SUNRPC_DEBUG_TRACE)
+# include <linux/trace_printk.h>
# define __sunrpc_printk(fmt, ...) trace_printk(fmt, ##__VA_ARGS__)
# else
# define __sunrpc_printk(fmt, ...) printk(KERN_DEFAULT fmt, ##__VA_ARGS__)
diff --git a/include/linux/trace_printk.h b/include/linux/trace_printk.h
index a488ea9e9f85..74ce4f8995c4 100644
--- a/include/linux/trace_printk.h
+++ b/include/linux/trace_printk.h
@@ -1,11 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_TRACE_PRINTK_H
#define _LINUX_TRACE_PRINTK_H
+#if !defined(__ASSEMBLY__) && !defined(__GENKSYMS__) && !defined(BUILD_VDSO)
-#include <linux/compiler_attributes.h>
#include <linux/instruction_pointer.h>
#include <linux/stddef.h>
#include <linux/stringify.h>
+#include <linux/stdarg.h>
#ifdef CONFIG_TRACING
static inline __printf(1, 2)
@@ -147,5 +148,5 @@ ftrace_vprintk(const char *fmt, va_list ap)
return 0;
}
#endif /* CONFIG_TRACING */
-
+#endif /* !defined(__ASSEMBLY__) && !defined(__GENKSYMS__) && !defined(BUILD_VDSO) */
#endif
diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h
index 93011f800d0f..e53273cce141 100644
--- a/include/trace/trace_events.h
+++ b/include/trace/trace_events.h
@@ -18,7 +18,9 @@
* in the structure.
*/
+#include <linux/trace_controls.h>
#include <linux/trace_events.h>
+#include <linux/trace_printk.h>
#include <linux/btf_ids.h>
#ifndef TRACE_SYSTEM_VAR
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index c3d34c0e64e2..61df7861b025 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -5,6 +5,7 @@
* Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
*/
#include <linux/ring_buffer.h>
+#include <linux/trace_printk.h>
#include <linux/completion.h>
#include <linux/kthread.h>
#include <uapi/linux/sched/types.h>
diff --git a/samples/fprobe/fprobe_example.c b/samples/fprobe/fprobe_example.c
index 3b94839b3199..eb6a62eea8ac 100644
--- a/samples/fprobe/fprobe_example.c
+++ b/samples/fprobe/fprobe_example.c
@@ -12,6 +12,7 @@
#define pr_fmt(fmt) "%s: " fmt, __func__
+#include <linux/trace_printk.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fprobe.h>
diff --git a/samples/ftrace/ftrace-direct-too.c b/samples/ftrace/ftrace-direct-too.c
index bf2411aa6fd7..159190f4103f 100644
--- a/samples/ftrace/ftrace-direct-too.c
+++ b/samples/ftrace/ftrace-direct-too.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/module.h>
-
#include <linux/mm.h> /* for handle_mm_fault() */
#include <linux/ftrace.h>
#if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
diff --git a/samples/trace_printk/trace-printk.c b/samples/trace_printk/trace-printk.c
index cfc159580263..ff37aeb8523e 100644
--- a/samples/trace_printk/trace-printk.c
+++ b/samples/trace_printk/trace-printk.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/trace_printk.h>
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/irq_work.h>
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 05/15] tracing: Override the same name trace_instance= by latter one
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (3 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 04/15] tracing: Remove trace_printk.h from kernel.h Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 06/15] selftests/ftrace: Add test case for overriding trace_instance parameter Steven Rostedt
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Override the same name boot instance by the latter parameter.
This allows user to override the trace instance in bootconfig by the
cmdline from bootloader.
For example, set default trace_instance parameter in bootconfig
e.g.:
kernel {
reserve_mem=12M:32M:trace
trace_instance=boot_map@trace
}
This just adds a persistent trace instance.
And when you need to record events, you can override the boot_map
trace instance from bootloader:
trace_instance=boot_map@trace,sched:*
Then the boot_map instance starts tracing sched:* events.
Link: https://patch.msgid.link/179094974235.609715.7085605075646393261.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
.../admin-guide/kernel-parameters.txt | 7 +
Documentation/trace/debugging.rst | 15 ++
kernel/trace/trace.c | 150 +++++++++++++-----
3 files changed, 135 insertions(+), 37 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 176648941aec..b12a172b8a82 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -7829,6 +7829,13 @@ Kernel parameters
NB: Both the mapped address and size must be page aligned for the architecture.
+ Multiple trace_instance= options can be specified to
+ create multiple instances. If the same instance name is
+ specified more than once, the latter one will override
+ any earlier definitions for that instance. This allows
+ overriding an instance configuration that was defined
+ earlier on the command line or via bootconfig.
+
See also Documentation/trace/debugging.rst
diff --git a/Documentation/trace/debugging.rst b/Documentation/trace/debugging.rst
index bca1710d92bf..b66cc070ae79 100644
--- a/Documentation/trace/debugging.rst
+++ b/Documentation/trace/debugging.rst
@@ -178,3 +178,18 @@ instance without stopping the trace.
Note that this "backup" instance is readonly, and will be removed automatically
if you clear the trace data or read out all trace data from the "trace_pipe"
or the "trace_pipe_raw" files.
+
+Overriding trace instances
+--------------------------
+
+Multiple ``trace_instance=`` options can be specified on the kernel command
+line to create multiple instances. If the same instance name is specified
+more than once, the latter definition will override any previous definitions
+for that instance.
+
+This is useful when an instance configuration is defined in bootconfig, but
+needs to be overridden or modified from the bootloader command line (for
+example, to change the enabled events or add flags like ``traceoff``)::
+
+ trace_instance=boot_map^traceoff@trace
+
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 65b9d67647e5..926a2eb247df 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -9754,33 +9754,44 @@ __init static int backup_instance_area(const char *backup,
return 0;
}
-__init static void enable_instances(void)
+struct boot_instance {
+ char *name;
+ char *flag_delim;
+ char *addr_delim;
+ char *backup;
+ char *events;
+};
+
+__init static int parse_boot_instance_info(struct boot_instance *boot_instances,
+ int nr_instances)
{
- struct trace_array *tr;
- bool memmap_area = false;
- char *curr_str;
+ char *flag_delim;
+ char *addr_delim;
+ char *backup;
+ char *events;
char *name;
- char *str;
char *tok;
+ char *str;
+ int idx;
+ int nr = 0;
+ int i;
/* A tab is always appended */
boot_instance_info[boot_instance_index - 1] = '\0';
str = boot_instance_info;
- while ((curr_str = strsep(&str, "\t"))) {
- phys_addr_t start = 0;
- phys_addr_t size = 0;
- unsigned long addr = 0;
- bool traceprintk = false;
- bool traceoff = false;
- char *flag_delim;
- char *addr_delim;
- char *rname __free(kfree) = NULL;
- char *backup;
+ while ((events = strsep(&str, "\t"))) {
+ if (!*events)
+ continue;
- tok = strsep(&curr_str, ",");
+ tok = strsep(&events, ",");
name = strsep(&tok, "=");
+ if (!*name) {
+ pr_warn("Tracing: Empty boot instance name\n");
+ continue;
+ }
+
backup = tok;
flag_delim = strchr(name, '^');
@@ -9792,20 +9803,84 @@ __init static void enable_instances(void)
if (flag_delim)
*flag_delim++ = '\0';
- if (trace_array_find(name)) {
- pr_warn("Tracing: Instance %s already exists\n", name);
- continue;
+ for (idx = 0; idx < nr; idx++) {
+ /* Override by the last defined instance */
+ if (!strcmp(name, boot_instances[idx].name))
+ break;
}
if (backup) {
- if (backup_instance_area(backup, &addr, &size) < 0)
+ /* Check if the backup source instance exists */
+ for (i = 0; i < idx; i++) {
+ if (!strcmp(backup, boot_instances[i].name))
+ break;
+ }
+ if (i == idx) {
+ pr_warn("Tracing: Backup source instance %s is not found for %s\n",
+ backup, name);
continue;
+ }
}
- if (flag_delim) {
+ if (WARN_ON(idx >= nr_instances))
+ break;
+
+ boot_instances[idx].name = name;
+ boot_instances[idx].flag_delim = flag_delim;
+ boot_instances[idx].addr_delim = addr_delim;
+ boot_instances[idx].backup = backup;
+ boot_instances[idx].events = events;
+ if (idx == nr)
+ nr++;
+ }
+
+ return nr;
+}
+
+__init static void enable_instances(void)
+{
+ struct boot_instance *boot_instances __free(kfree) = NULL;
+ struct boot_instance *bi;
+ struct trace_array *tr;
+ int nr_instances = 1;
+ char *tok;
+
+ if (!boot_instance_index)
+ return;
+
+ for (char *p = boot_instance_info; *p; p++) {
+ if (*p == '\t')
+ nr_instances++;
+ }
+
+ /* Parse the instance name to check the overlap */
+ boot_instances = kmalloc_array(nr_instances,
+ sizeof(*boot_instances), GFP_KERNEL);
+ if (!boot_instances)
+ return;
+
+ nr_instances = parse_boot_instance_info(boot_instances, nr_instances);
+
+ for (int i = 0; i < nr_instances; i++) {
+ char *rname __free(kfree) = NULL;
+ phys_addr_t start = 0;
+ phys_addr_t size = 0;
+ unsigned long addr = 0;
+ bool traceprintk = false;
+ bool traceoff = false;
+ bool memmap_area = false;
+
+ bi = &boot_instances[i];
+
+ if (bi->backup) {
+ if (backup_instance_area(bi->backup, &addr, &size) < 0)
+ continue;
+ }
+
+ if (bi->flag_delim) {
char *flag;
- while ((flag = strsep(&flag_delim, "^"))) {
+ while ((flag = strsep(&bi->flag_delim, "^"))) {
if (strcmp(flag, "traceoff") == 0) {
traceoff = true;
} else if ((strcmp(flag, "printk") == 0) ||
@@ -9814,35 +9889,35 @@ __init static void enable_instances(void)
traceprintk = true;
} else {
pr_info("Tracing: Invalid instance flag '%s' for %s\n",
- flag, name);
+ flag, bi->name);
}
}
}
- tok = addr_delim;
+ tok = bi->addr_delim;
if (tok && isdigit(*tok)) {
start = memparse(tok, &tok);
if (!start) {
pr_warn("Tracing: Invalid boot instance address for %s\n",
- name);
+ bi->name);
continue;
}
if (*tok != ':') {
- pr_warn("Tracing: No size specified for instance %s\n", name);
+ pr_warn("Tracing: No size specified for instance %s\n", bi->name);
continue;
}
tok++;
size = memparse(tok, &tok);
if (!size) {
pr_warn("Tracing: Invalid boot instance size for %s\n",
- name);
+ bi->name);
continue;
}
memmap_area = true;
} else if (tok) {
if (!reserve_mem_find_by_name(tok, &start, &size)) {
start = 0;
- pr_warn("Failed to map boot instance %s to %s\n", name, tok);
+ pr_warn("Failed to map boot instance %s to %s\n", bi->name, tok);
continue;
}
rname = kstrdup(tok, GFP_KERNEL);
@@ -9865,20 +9940,20 @@ __init static void enable_instances(void)
addr = (unsigned long)phys_to_virt(start);
if (addr) {
pr_info("Tracing: mapped boot instance %s at physical memory %pa of size 0x%lx\n",
- name, &start, (unsigned long)size);
+ bi->name, &start, (unsigned long)size);
} else {
- pr_warn("Tracing: Failed to map boot instance %s\n", name);
+ pr_warn("Tracing: Failed to map boot instance %s\n", bi->name);
continue;
}
} else {
/* Only non mapped buffers have snapshot buffers */
- do_allocate_snapshot(name);
+ do_allocate_snapshot(bi->name);
}
- tr = trace_array_create_systems(name, NULL, addr, size);
+ tr = trace_array_create_systems(bi->name, NULL, addr, size);
if (IS_ERR(tr)) {
- pr_warn("Tracing: Failed to create instance buffer '%s' (%ld)\n", name,
- PTR_ERR(tr));
+ pr_warn("Tracing: Failed to create instance buffer '%s' (%ld)\n",
+ bi->name, PTR_ERR(tr));
continue;
}
@@ -9899,12 +9974,12 @@ __init static void enable_instances(void)
/*
* Backup buffers can be freed but need vfree().
*/
- if (backup) {
+ if (bi->backup) {
tr->flags |= TRACE_ARRAY_FL_VMALLOC | TRACE_ARRAY_FL_RDONLY;
trace_array_start_autoremove();
}
- if (start || backup) {
+ if (start || bi->backup) {
tr->flags |= TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT;
tr->range_name = no_free_ptr(rname);
}
@@ -9913,11 +9988,12 @@ __init static void enable_instances(void)
* Save the events to start and enabled them after all boot instances
* have been created.
*/
- tr->boot_events = curr_str;
+ tr->boot_events = bi->events;
}
/* Enable the events after all boot instances have been created */
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
+ char *curr_str;
if (!tr->boot_events || !(*tr->boot_events)) {
tr->boot_events = NULL;
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 06/15] selftests/ftrace: Add test case for overriding trace_instance parameter
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (4 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 05/15] tracing: Override the same name trace_instance= by latter one Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 07/15] tracing/scripts: Check the section end before reading a string in tracing-update Steven Rostedt
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Add a boot-time tracing test case to verify that specifying multiple
trace_instance= parameters with the same instance name overrides earlier
definitions:
- Verifies that a kernel command-line trace_instance= parameter
overrides an earlier trace instance defined via bootconfig
(kernel.trace_instance).
- Verifies that a later kernel command-line trace_instance=
parameter overrides an earlier trace_instance= on the same
command line.
- Verifies overriding a memory-mapped trace instance (@trace).
- Verifies overriding a backup trace instance (=source).
- Verifies parsing parameters containing multiple tabs and
gracefully handling empty strings.
- Confirms that the overridden instance has its previous events
disabled, new events enabled, and flags (such as traceoff)
properly applied.
Link: https://patch.msgid.link/179094975229.609715.3664484413379599809.stgit@devnote2
Assisted-by: LLM
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
.../cmdline-07-trace-instance-override.bconf | 4 +
...cmdline-07-trace-instance-override.cmdline | 1 +
.../ftrace/boottime/run_boottime_test.sh | 2 +
.../cmdline-07-trace-instance-override.sh | 148 ++++++++++++++++++
4 files changed, 155 insertions(+)
create mode 100644 tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
create mode 100644 tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
create mode 100755 tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh
diff --git a/tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf b/tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
new file mode 100644
index 000000000000..74d8be54a798
--- /dev/null
+++ b/tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
@@ -0,0 +1,4 @@
+kernel.trace_instance = "boot_map@trace,sched:sched_switch",
+ "bak_to_norm=boot_map",
+ "bak_from_norm,sched:sched_switch",
+ "foo,sched:sched_switch"
diff --git a/tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline b/tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
new file mode 100644
index 000000000000..3c16bb0f3545
--- /dev/null
+++ b/tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
@@ -0,0 +1 @@
+reserve_mem=12M:32M:trace trace_instance=foo^traceoff,sched:sched_waking trace_instance=bar,sched:sched_switch trace_instance=bar^traceoff,irq:irq_handler_entry trace_instance=boot_map^traceoff@trace,sched:sched_waking trace_instance=bak_to_norm^traceoff,irq:irq_handler_entry trace_instance=bak_from_norm=boot_map trace_instance="tab1,sched:sched_switch tab2,sched:sched_switch" trace_instance=tab1^traceoff,sched:sched_waking trace_instance= trace_instance="" trace_instance=,
diff --git a/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh b/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh
index 6e8593d5a2c5..1d30adc388a6 100755
--- a/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh
+++ b/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh
@@ -46,6 +46,8 @@ BUSYBOX_APPLETS=(
grep
sleep
sed
+ dmesg
+ basename
)
usage() {
diff --git a/tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh b/tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh
new file mode 100755
index 000000000000..960a3cf54d97
--- /dev/null
+++ b/tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh
@@ -0,0 +1,148 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2026, Google LLC.
+# Check trace_instance= override with bootconfig and kernel command-line
+TRACEDIR="/sys/kernel/tracing"
+
+if [ -f /proc/bootconfig ] && \
+ grep -q "dump_bconf" /proc/cmdline 2>/dev/null; then
+ echo "=== /proc/bootconfig ==="
+ cat /proc/bootconfig
+ echo "========================"
+fi
+
+check_instance() {
+ instance="$1"
+ old_event="$2"
+ new_event="$3"
+
+ if [ ! -d "$TRACEDIR/instances/$instance" ]; then
+ echo "FAIL: trace instance $instance does not exist"
+ exit 1
+ fi
+
+ if [ -n "$old_event" ] && \
+ [ -f "$TRACEDIR/instances/$instance/events/$old_event/enable" ]; then
+ ENABLE=$(cat "$TRACEDIR/instances/$instance/events/$old_event/enable")
+ if [ "$ENABLE" = "1" ]; then
+ echo "FAIL: overridden event $old_event" \
+ "is still enabled in instance $instance"
+ exit 1
+ fi
+ fi
+
+ if [ -n "$new_event" ]; then
+ if [ ! -d "$TRACEDIR/instances/$instance/events/$new_event" ]; then
+ echo "FAIL: event $new_event does not exist in instance $instance"
+ exit 1
+ fi
+
+ ENABLE=$(cat "$TRACEDIR/instances/$instance/events/$new_event/enable")
+ if [ "$ENABLE" != "1" ]; then
+ echo "FAIL: event $new_event is not enabled in instance $instance ($ENABLE)"
+ exit 1
+ fi
+ fi
+
+ TRACING_ON=$(cat "$TRACEDIR/instances/$instance/tracing_on")
+ if [ "$TRACING_ON" != "0" ]; then
+ echo "FAIL: tracing_on is not 0 in instance $instance ($TRACING_ON)"
+ exit 1
+ fi
+}
+
+check_backup_instance() {
+ instance="$1"
+
+ if [ ! -d "$TRACEDIR/instances/$instance" ]; then
+ echo "FAIL: trace instance $instance does not exist"
+ exit 1
+ fi
+
+ # Backup instances have a trace buffer file
+ if [ ! -f "$TRACEDIR/instances/$instance/trace" ]; then
+ echo "FAIL: backup instance $instance has no trace file"
+ exit 1
+ fi
+
+ # Backup instances are read-only and do not have tracing_on
+ if [ -f "$TRACEDIR/instances/$instance/tracing_on" ]; then
+ echo "FAIL: backup instance $instance unexpectedly has tracing_on"
+ exit 1
+ fi
+
+ # Backup instances do not support enabling events
+ if [ -f \
+ "$TRACEDIR/instances/$instance/events/sched/sched_switch/enable" ]; then
+ echo "FAIL: backup instance $instance unexpectedly has enabled events"
+ exit 1
+ fi
+}
+
+check_mapped_instance() {
+ instance="$1"
+ old_event="$2"
+ new_event="$3"
+
+ check_instance "$instance" "$old_event" "$new_event"
+
+ # Check dmesg to confirm physical mapping occurred
+ if ! dmesg | grep -q "mapped boot instance $instance"; then
+ echo "FAIL: memory-mapped instance $instance was not mapped at boot"
+ exit 1
+ fi
+}
+
+# Test 1: bootconfig trace_instance overridden by cmdline parameter
+check_instance "foo" "sched/sched_switch" "sched/sched_waking"
+
+# Test 2: cmdline trace_instance overridden by subsequent cmdline parameter
+check_instance "bar" "sched/sched_switch" "irq/irq_handler_entry"
+
+# Test 3: memory-mapped (@trace) instance in bootconfig overridden by cmdline
+check_mapped_instance "boot_map" "sched/sched_switch" "sched/sched_waking"
+
+# Test 4a: backup instance in bootconfig overridden by normal
+# instance in cmdline
+check_instance "bak_to_norm" "" "irq/irq_handler_entry"
+
+# Test 4b: normal instance in bootconfig overridden by backup
+# instance in cmdline
+check_backup_instance "bak_from_norm"
+
+# Test 5: instances separated by multiple tabs, where first is overridden
+check_instance "tab1" "sched/sched_switch" "sched/sched_waking"
+# tab2 was not overridden, so its original event should remain enabled
+if [ ! -d "$TRACEDIR/instances/tab2/events/sched/sched_switch" ]; then
+ echo "FAIL: instance tab2 event sched/sched_switch does not exist"
+ exit 1
+fi
+ENABLE=$(cat "$TRACEDIR/instances/tab2/events/sched/sched_switch/enable")
+if [ "$ENABLE" != "1" ]; then
+ echo "FAIL: instance tab2 event sched/sched_switch is not enabled ($ENABLE)"
+ exit 1
+fi
+
+# Test 6: Verify empty strings and malformed entries did not create
+# bogus directories
+for dir in "$TRACEDIR/instances"/*; do
+ [ -d "$dir" ] || continue
+ bname=$(basename "$dir")
+ case "$bname" in
+ foo|bar|boot_map|bak_to_norm|bak_from_norm|tab1|tab2)
+ ;;
+ *)
+ echo "FAIL: unexpected trace instance directory found: $bname"
+ exit 1
+ ;;
+ esac
+done
+
+# Test 7: Verify no kernel warnings or assertion failures were triggered
+if dmesg | grep -q "WARNING: CPU:"; then
+ echo "FAIL: kernel warning triggered during boot"
+ exit 1
+fi
+
+echo "PASS: cmdline-07-trace-instance-override"
+exit 0
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 07/15] tracing/scripts: Check the section end before reading a string in tracing-update
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (5 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 06/15] selftests/ftrace: Add test case for overriding trace_instance parameter Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 08/15] tracing/scripts: Do not reuse section pointers from a previous file " Steven Rostedt
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
Leizhen Zhang
From: Leizhen Zhang <lzsx618@gmail.com>
for_each_shdr_str() evaluates strlen(str) before checking str < end, so
after the last string of the section it calls strlen() on the bytes just
past the section. Check the bound first.
Link: https://patch.msgid.link/20261008164117.3670267-2-lzsx618@gmail.com
Fixes: e30f8e61e251 ("tracing: Add a tracepoint verification check at build time")
Assisted-by: Claude:claude-opus-5-5 ASan
Signed-off-by: Leizhen Zhang <lzsx618@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
scripts/tracepoint-update.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/tracepoint-update.c b/scripts/tracepoint-update.c
index 5cf43c0aac89..c70c0b076554 100644
--- a/scripts/tracepoint-update.c
+++ b/scripts/tracepoint-update.c
@@ -74,7 +74,7 @@ static int add_string(const char *str, const char ***vals, int *count)
#define for_each_shdr_str(len, ehdr, sec) \
for (const char *str = (void *)(ehdr) + shdr_offset(sec), \
*end = str + shdr_size(sec); \
- len = strlen(str), str < end; \
+ str < end && (len = strlen(str), true); \
str += (len) + 1)
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 08/15] tracing/scripts: Do not reuse section pointers from a previous file in tracing-update
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (6 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 07/15] tracing/scripts: Check the section end before reading a string in tracing-update Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 09/15] tracing/filters: Report parse error on all -EINVAL paths in filter parsing Steven Rostedt
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
Leizhen Zhang
From: Leizhen Zhang <lzsx618@gmail.com>
check_data_sec and tracepoint_data_sec are static and set while scanning
the section headers in process_tracepoints(), but are never reset. When
tracepoint-update is given several files and a later file lacks these
sections, the pointers from the previous, already unmapped file are
used, which crashes:
$ scripts/tracepoint-update --module a.o c.o
AddressSanitizer: SEGV ...
Reset both pointers at the start of process_tracepoints().
Kbuild currently passes a single file per invocation, so this does not
affect normal builds.
Link: https://patch.msgid.link/20261008164117.3670267-1-lzsx618@gmail.com
Assisted-by: Claude:claude-opus-5-5 ASan UBSan
Signed-off-by: Leizhen Zhang <lzsx618@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
scripts/tracepoint-update.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/scripts/tracepoint-update.c b/scripts/tracepoint-update.c
index c70c0b076554..ad5f691c150c 100644
--- a/scripts/tracepoint-update.c
+++ b/scripts/tracepoint-update.c
@@ -163,6 +163,10 @@ static int process_tracepoints(bool mod, void *addr, const char *fname)
int idx;
int done = 2;
+ /* Do not use the sections of a previously processed file */
+ check_data_sec = NULL;
+ tracepoint_data_sec = NULL;
+
shdr_start = (Elf_Shdr *)((char *)ehdr + ehdr_shoff(ehdr));
shentsize = ehdr_shentsize(ehdr);
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 09/15] tracing/filters: Report parse error on all -EINVAL paths in filter parsing
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (7 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 08/15] tracing/scripts: Do not reuse section pointers from a previous file " Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 10/15] tracing/filters: Fix quoted operand parsing in function event filter Steven Rostedt
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Several error paths in filter parsing return -EINVAL (or -1) without
calling parse_error() to set pe->lasterr:
1. In parse_pred(), when an invalid token is encountered where a field name
is expected (e.g., "common_pid == 1 || (common_pid == 2 && )"), len is 0
and it returns -1 without calling parse_error().
2. In process_preds(), when !nr_preds (e.g., empty or whitespace-only
filter), it returns -EINVAL before predicate_parse() can set
FILT_ERR_NO_FILTER.
3. In predicate_parse(), when op_stack overflows or the jump target check
fails, it returns -EINVAL without calling parse_error().
Because pe->lasterr remains 0 on these paths, append_filter_err() falls
back to printing an uninformative "Error: (0)" instead of reporting the
diagnostic and error position.
Call parse_error() with the appropriate error code on all of these paths.
Fixes: 80765597bc58 ("tracing: Rewrite filter logic to be simpler and faster")
Link: https://patch.msgid.link/179323788261.740114.13501865461835259995.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index a9d77df3e19a..17064fa4a063 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -514,6 +514,8 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
switch (*next) {
case '(': /* #2 */
if (top - op_stack >= nr_parens - 1) {
+ parse_error(pe, FILT_ERR_TOO_MANY_OPEN,
+ next - str);
ret = -EINVAL;
goto out_free;
}
@@ -637,6 +639,7 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
prog[i].when_to_branch = invert;
/* Make sure the program always moves forward */
if (WARN_ON(prog[i].target <= i)) {
+ parse_error(pe, FILT_ERR_INVALID_FILTER, 0);
ret = -EINVAL;
goto out_free;
}
@@ -1713,8 +1716,10 @@ static int parse_pred(const char *str, void *data,
len = i - s;
- if (!len)
- return -1;
+ if (!len) {
+ parse_error(pe, FILT_ERR_INVALID_FILTER, pos + i);
+ return -EINVAL;
+ }
field_name = kmemdup_nul(str + s, len, GFP_KERNEL);
if (!field_name)
@@ -2317,8 +2322,10 @@ static int process_preds(struct trace_event_call *call,
return ret;
}
- if (!nr_preds)
+ if (!nr_preds) {
+ parse_error(pe, FILT_ERR_NO_FILTER, 0);
return -EINVAL;
+ }
prog = predicate_parse(filter_string, nr_parens, nr_preds,
parse_pred, call, pe);
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 10/15] tracing/filters: Fix quoted operand parsing in function event filter
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (8 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 09/15] tracing/filters: Report parse error on all -EINVAL paths in filter parsing Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 11/15] tracing/filters: Reject empty unquoted operand " Steven Rostedt
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
In parse_pred(), when parsing a quoted operand for function events (e.g.
ip == "schedule"):
1. The loop 'for (i++; str[i]; i++)' breaks when str[i] matches the
closing quote, but 'i' is never incremented past the closing quote.
As a result, parse_pred() returns 'i' pointing at the closing quote,
causing the caller predicate_parse() to immediately re-parse the
closing quote as the start of the next token and fail with
FILT_ERR_TOO_MANY_PREDS.
2. If the closing quote is missing (e.g. ip == "schedule), the loop stops
at the NUL terminator without reporting an error.
3. The loop started with 'i++', which was intended to skip the opening
quote, but also unconditionally skipped the first character of unquoted
function operands.
Fix this by advancing 'i' and setting 's = i' past the opening quote
before the loop, starting the loop at 'i' without unconditional
increment, reporting FILT_ERR_MISSING_QUOTE if the closing quote is
missing, and advancing 'i' past the closing quote.
Fixes: 80765597bc58 ("tracing: Rewrite filter logic to be simpler and faster")
Link: https://patch.msgid.link/179323790096.740114.15868280894145147902.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 17064fa4a063..bce80a2c677a 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1865,22 +1865,27 @@ static int parse_pred(const char *str, void *data,
* Quotes are not required, but if they exist then we need
* to read them till we hit a matching one.
*/
- if (str[i] == '\'' || str[i] == '"')
- q = str[i];
- else
+ if (str[i] == '\'' || str[i] == '"') {
+ q = str[i++];
+ s = i;
+ } else {
q = 0;
+ }
- for (i++; str[i]; i++) {
+ for (; str[i]; i++) {
if (q && str[i] == q)
break;
if (!q && (str[i] == ')' || str[i] == '&' ||
str[i] == '|'))
break;
}
- /* Skip quotes */
- if (q)
- s++;
+ if (q && !str[i]) {
+ parse_error(pe, FILT_ERR_MISSING_QUOTE, pos + i);
+ goto err_free;
+ }
len = i - s;
+ if (q)
+ i++;
if (len >= MAX_FILTER_STR_VAL) {
parse_error(pe, FILT_ERR_OPERAND_TOO_LONG, pos + i);
goto err_free;
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 11/15] tracing/filters: Reject empty unquoted operand in function event filter
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (9 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 10/15] tracing/filters: Fix quoted operand parsing in function event filter Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 12/15] tracing/filters: Reject unsupported field sizes in parse_pred() Steven Rostedt
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
In parse_pred(), when parsing an unquoted operand for function events,
if the filter expression has no operand before a delimiter (e.g.
'(ip == )' or '(ip == && x == 1)'), the loop terminates with len == 0.
While an empty quoted string (e.g. 'ip == ""') is syntactically valid
and denotes an empty pattern, an unquoted empty operand is a syntax
error where an operand was expected before the delimiter. Previously,
this accepted the predicate with an empty pattern.
Reject empty unquoted operands by checking '!q && !len' and reporting
FILT_ERR_INVALID_VALUE.
Fixes: 80765597bc58 ("tracing: Rewrite filter logic to be simpler and faster")
Link: https://patch.msgid.link/179323791027.740114.822862076687011726.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index bce80a2c677a..79eb187be39d 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1886,6 +1886,10 @@ static int parse_pred(const char *str, void *data,
len = i - s;
if (q)
i++;
+ if (!q && !len) {
+ parse_error(pe, FILT_ERR_INVALID_VALUE, pos + i);
+ goto err_free;
+ }
if (len >= MAX_FILTER_STR_VAL) {
parse_error(pe, FILT_ERR_OPERAND_TOO_LONG, pos + i);
goto err_free;
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 12/15] tracing/filters: Reject unsupported field sizes in parse_pred()
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (10 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 11/15] tracing/filters: Reject empty unquoted operand " Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 13/15] tracing/filters: Check for trailing characters after newline in filter string Steven Rostedt
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Prior to commit 80765597bc58 ("tracing: Rewrite filter logic to be simpler
and faster"), parse_pred() checked whether select_comparison_fn() returned
NULL and failed with FILT_ERR_INVALID_OP and -EINVAL. That check was lost
during the rewrite, and commit 3cbec9d7b93d ("tracing/filters: Enable
filtering a scalar field by a cpumask") similarly omitted a default error
case when matching field->size for CPUS{} comparisons.
If a non-string field (FILTER_OTHER) has a size other than 1, 2, 4, or 8
(such as a fixed-size integer array field), pred->fn_num remains
FILTER_PRED_FN_NOP (0) and parse_pred() returns success. Subsequently,
update_preds() rejects FILTER_PRED_FN_NOP via WARN_ON_ONCE() and returns
-EINVAL without setting a parse_error() message, triggering a kernel
warning from user-supplied filter input.
Restore the check for FILTER_PRED_FN_NOP in both the numeric scalar and
CPUS{} branches of parse_pred() and report FILT_ERR_INVALID_OP.
~# cd /sys/kernel/tracing
~# cat events/raw_syscalls/sys_enter/format | grep args
field:unsigned long args[6]; offset:24; size:48; signed:0;
So this event has args[6] array field. So filter needs [] to specify
the element. However,
~# echo 'args == 0' > events/raw_syscalls/sys_enter/filter
~# echo $?
0
This passed, and
~# cat events/raw_syscalls/sys_enter/filter
args == 0
After this update:
~# echo 'args == 0' > events/raw_syscalls/sys_enter/filter
sh: write error: Invalid argument
~# cat error_log
[ 23.864399] event filter parse error: error: Invalid operator
Command: args == 0
Fixes: 80765597bc58 ("tracing: Rewrite filter logic to be simpler and faster")
Fixes: 3cbec9d7b93d ("tracing/filters: Enable filtering a scalar field by a cpumask")
Link: https://patch.msgid.link/179323791927.740114.2174706496595446472.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 79eb187be39d..fcdd4c552569 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -2019,6 +2019,10 @@ static int parse_pred(const char *str, void *data,
break;
}
}
+ if (pred->fn_num == FILTER_PRED_FN_NOP) {
+ parse_error(pe, FILT_ERR_INVALID_OP, pos + i);
+ goto err_free;
+ }
/* This is either a string, or an integer */
} else if (str[i] == '\'' || str[i] == '"') {
@@ -2172,6 +2176,10 @@ static int parse_pred(const char *str, void *data,
else {
pred->fn_num = select_comparison_fn(pred->op, field->size,
field->is_signed);
+ if (pred->fn_num == FILTER_PRED_FN_NOP) {
+ parse_error(pe, FILT_ERR_INVALID_OP, pos + i);
+ goto err_free;
+ }
if (pred->op == OP_NE)
pred->not = 1;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 13/15] tracing/filters: Check for trailing characters after newline in filter string
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (11 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 12/15] tracing/filters: Reject unsupported field sizes in parse_pred() Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 14/15] tracing/filters: Reject stray quotes and parentheses in unquoted function event operand Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 15/15] tracing: Export live module tracepoint strings in printk_formats Steven Rostedt
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Each trace event or subsystem only holds a single filter, and
append_filter_err() / tracing_log_err() caret placement assumes a
single-line filter string. However, apply_event_filter() and
apply_subsystem_event_filter() only called strstrip(), which strips
trailing newlines but leaves embedded newlines intact.
An embedded newline in a filter string (for example inside 'CPUS{0\n"}')
causes cpulist_parse() / bitmap_parselist() to treat '\n' as the end of
the cpulist and ignore trailing characters before '}', desynchronizing
quote tracking between calc_stack() and parse_pred() and misaligning
error_log caret reporting.
Introduce an internal function filter_check_newline() to convert the
first newline to NUL and check that the rest of the input contains no
non-whitespace characters. If any non-whitespace character follows the
newline, report it as an invalid input error (-EINVAL) without modifying
the input string in-place.
Link: https://patch.msgid.link/179323792832.740114.8136681613581516243.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 36 ++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index fcdd4c552569..097b432647fc 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -2445,6 +2445,30 @@ static int process_system_preds(struct trace_subsystem_dir *dir,
return ret;
}
+/*
+ * Check that the rest of the input after the first newline contains no
+ * non-whitespace characters, and convert the newline to '\0'.
+ */
+static int filter_check_newline(char *str)
+{
+ char *nl, *p;
+
+ if (!str)
+ return 0;
+
+ nl = strchr(str, '\n');
+ if (!nl)
+ return 0;
+
+ for (p = nl + 1; *p; p++) {
+ if (!isspace(*p))
+ return -EINVAL;
+ }
+
+ *nl = '\0';
+ return 0;
+}
+
static int create_filter_start(char *filter_string, bool set_str,
struct filter_parse_error **pse,
struct event_filter **filterp)
@@ -2456,6 +2480,10 @@ static int create_filter_start(char *filter_string, bool set_str,
if (WARN_ON_ONCE(*pse || *filterp))
return -EINVAL;
+ err = filter_check_newline(filter_string);
+ if (err)
+ return err;
+
filter = kzalloc_obj(*filter);
if (filter && set_str) {
filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
@@ -2574,6 +2602,10 @@ int apply_event_filter(struct trace_event_file *file, char *filter_string)
if (file->flags & EVENT_FILE_FL_FREED)
return -ENODEV;
+ err = filter_check_newline(filter_string);
+ if (err)
+ return err;
+
if (!strcmp(strstrip(filter_string), "0")) {
filter_disable(file);
filter = event_filter(file);
@@ -2628,6 +2660,10 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
if (!dir->nr_events)
return -ENODEV;
+ err = filter_check_newline(filter_string);
+ if (err)
+ return err;
+
if (!strcmp(strstrip(filter_string), "0")) {
filter_free_subsystem_preds(dir, tr);
remove_filter_string(system->filter);
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 14/15] tracing/filters: Reject stray quotes and parentheses in unquoted function event operand
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (12 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 13/15] tracing/filters: Check for trailing characters after newline in filter string Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 15/15] tracing: Export live module tracepoint strings in printk_formats Steven Rostedt
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
In parse_pred(), when parsing an unquoted operand for function events,
the loop only stops at ')', '&', '|', or the NUL terminator.
However, calc_stack() parses '(', '\'', and '"' independently to
determine stack depth and string boundaries. If an unquoted function
operand contains stray quotes or an open parenthesis (e.g. "ip == foo'bar"
or "ip == foo(bar)"), parse_pred() consumes them as part of the function
name operand, causing parse_pred() and calc_stack() to desynchronize.
Reject unquoted function event operands containing '(', '\'', or '"'
by reporting FILT_ERR_INVALID_VALUE.
Link: https://patch.msgid.link/179323793740.740114.16357488115964317102.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_filter.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 097b432647fc..588215f7252f 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1875,9 +1875,17 @@ static int parse_pred(const char *str, void *data,
for (; str[i]; i++) {
if (q && str[i] == q)
break;
- if (!q && (str[i] == ')' || str[i] == '&' ||
- str[i] == '|'))
- break;
+ if (!q) {
+ if (str[i] == ')' || str[i] == '&' ||
+ str[i] == '|')
+ break;
+ if (str[i] == '(' || str[i] == '\'' ||
+ str[i] == '"') {
+ parse_error(pe, FILT_ERR_INVALID_VALUE,
+ pos + i);
+ goto err_free;
+ }
+ }
}
if (q && !str[i]) {
parse_error(pe, FILT_ERR_MISSING_QUOTE, pos + i);
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [for-next][PATCH 15/15] tracing: Export live module tracepoint strings in printk_formats
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
` (13 preceding siblings ...)
2026-11-26 16:24 ` [for-next][PATCH 14/15] tracing/filters: Reject stray quotes and parentheses in unquoted function event operand Steven Rostedt
@ 2026-11-26 16:24 ` Steven Rostedt
14 siblings, 0 replies; 16+ messages in thread
From: Steven Rostedt @ 2026-11-26 16:24 UTC (permalink / raw)
To: linux-kernel
Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
Petr Pavlu, Cao Ruichuang
From: Cao Ruichuang <create0818@163.com>
tracepoint_string() mappings for built-in strings are exported through
printk_formats, but the module loader does not collect __tracepoint_str.
Consequently, user space cannot resolve these module string pointers.
Collect the module section and expose its live address-to-text mappings.
Serialize registration, removal and the full printk_formats seq_file
iteration with btrace_mutex. Remove the range before module memory is
freed; do not retain strings after unload.
Keep trace_is_tracepoint_string() and event string validation unchanged.
Exporting decoder metadata does not require accepting module pointers in
core or other modules' events, nor does it extend the strings' lifetime.
Count successfully retained unique module trace_printk formats so the
iterator can locate the following module string ranges. These formats
remain retained after unload, so the count is not decremented.
Add a sample TRACE_EVENT and a dedicated selftest for multiple exported
strings, event output and mapping removal. Make unload and every residual
string/read-error check fail explicitly.
Link: https://patch.msgid.link/4b28954d.85c9.1a19b73b227.Coremail.create0818@163.com
Fixes: 102c9323c35a ("tracing: Add __tracepoint_string() to export string pointers")
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217196
Link: https://lore.kernel.org/r/41e81533-0fd6-49f5-b7c1-b4e172affd2a@suse.com
Link: https://lore.kernel.org/r/20261030173049.6656d506@gandalf.local.home
Suggested-by: Petr Pavlu <petr.pavlu@suse.com>
Assisted-by: LLM (GPT-6.1-Sol)
Signed-off-by: Cao Ruichuang <create0818@163.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
include/linux/module.h | 2 +
include/linux/tracepoint.h | 9 +-
kernel/module/main.c | 4 +
kernel/trace/trace_printk.c | 111 ++++++++++++++++--
samples/trace_events/trace-events-sample.c | 3 +
samples/trace_events/trace-events-sample.h | 17 +++
.../ftrace/test.d/event/tracepoint_string.tc | 47 ++++++++
7 files changed, 178 insertions(+), 15 deletions(-)
create mode 100644 tools/testing/selftests/ftrace/test.d/event/tracepoint_string.tc
diff --git a/include/linux/module.h b/include/linux/module.h
index 76f4f3596477..e4c39013f414 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -513,7 +513,9 @@ struct module {
#endif
#ifdef CONFIG_TRACING
unsigned int num_trace_bprintk_fmt;
+ unsigned int num_tracepoint_strings;
const char **trace_bprintk_fmt_start;
+ const char **tracepoint_strings_start;
#endif
#ifdef CONFIG_EVENT_TRACING
struct trace_event_call **trace_events;
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index e0d838c9ce93..7b3ee936a8ca 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -508,11 +508,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
* the ASCII strings they represent.
*
* The @str used must be a constant string and persistent as it would not
- * make sense to show a string that no longer exists. But it is still fine
- * to be used with modules, because when modules are unloaded, if they
- * had tracepoints, the ring buffers are cleared too. As long as the string
- * does not change during the life of the module, it is fine to use
- * tracepoint_string() within a module.
+ * make sense to show a string that no longer exists. For modules, the string
+ * mapping is exported while the module is loaded and removed on unload.
+ * Exporting the mapping does not extend the lifetime of the string. The
+ * existing lifetime requirements for strings referenced by events still apply.
*/
#define tracepoint_string(str) \
({ \
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 34e0204ea37c..630431b1b16c 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2756,6 +2756,10 @@ static int find_module_sections(struct module *mod, struct load_info *info)
mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt",
sizeof(*mod->trace_bprintk_fmt_start),
&mod->num_trace_bprintk_fmt);
+ mod->tracepoint_strings_start =
+ section_objs(info, "__tracepoint_str",
+ sizeof(*mod->tracepoint_strings_start),
+ &mod->num_tracepoint_strings);
#endif
#ifdef CONFIG_DYNAMIC_FTRACE
/* sechdrs[0].sh_size is always zero */
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index 98171a2398e4..d82a62df3de7 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -19,15 +19,23 @@
#include "trace.h"
+/* Counts unique retained formats; module unload does not decrement this. */
+static int trace_bprintk_fmt_cnt;
+
#ifdef CONFIG_MODULES
/*
* modules trace_printk()'s formats are autosaved in struct trace_bprintk_fmt
* which are queued on trace_bprintk_fmt_list.
+ *
+ * modules tracepoint_string() entries are kept as ranges into the owning
+ * module's __tracepoint_str section and are removed again when the module
+ * goes away.
*/
static LIST_HEAD(trace_bprintk_fmt_list);
+static LIST_HEAD(tracepoint_str_list);
-/* serialize accesses to trace_bprintk_fmt_list */
+/* Serialize module list updates and the full printk_formats iteration. */
static DEFINE_MUTEX(btrace_mutex);
struct trace_bprintk_fmt {
@@ -35,6 +43,13 @@ struct trace_bprintk_fmt {
const char *fmt;
};
+struct tracepoint_mod_str {
+ struct list_head list;
+ struct module *mod;
+ const char **start;
+ unsigned int num;
+};
+
static inline struct trace_bprintk_fmt *lookup_format(const char *fmt)
{
struct trace_bprintk_fmt *pos;
@@ -75,6 +90,7 @@ void hold_module_trace_bprintk_format(const char **start, const char **end)
if (fmt) {
list_add_tail(&tb_fmt->list, &trace_bprintk_fmt_list);
tb_fmt->fmt = fmt;
+ trace_bprintk_fmt_cnt++;
} else
kfree(tb_fmt);
}
@@ -84,16 +100,61 @@ void hold_module_trace_bprintk_format(const char **start, const char **end)
mutex_unlock(&btrace_mutex);
}
+static void hold_module_tracepoint_strings(struct module *mod)
+{
+ struct tracepoint_mod_str *tp_str;
+
+ if (!mod->num_tracepoint_strings)
+ return;
+
+ tp_str = kmalloc_obj(*tp_str);
+ if (!tp_str)
+ return;
+
+ tp_str->mod = mod;
+ tp_str->start = mod->tracepoint_strings_start;
+ tp_str->num = mod->num_tracepoint_strings;
+
+ guard(mutex)(&btrace_mutex);
+ list_add_tail(&tp_str->list, &tracepoint_str_list);
+}
+
+static void release_module_tracepoint_strings(struct module *mod)
+{
+ struct tracepoint_mod_str *tp_str, *next;
+
+ if (!mod->num_tracepoint_strings)
+ return;
+
+ guard(mutex)(&btrace_mutex);
+ list_for_each_entry_safe(tp_str, next, &tracepoint_str_list, list) {
+ if (tp_str->mod != mod)
+ continue;
+
+ list_del(&tp_str->list);
+ kfree(tp_str);
+ return;
+ }
+}
+
static int module_trace_bprintk_format_notify(struct notifier_block *self,
unsigned long val, void *data)
{
struct module *mod = data;
- if (mod->num_trace_bprintk_fmt) {
- const char **start = mod->trace_bprintk_fmt_start;
- const char **end = start + mod->num_trace_bprintk_fmt;
- if (val == MODULE_STATE_COMING)
+ switch (val) {
+ case MODULE_STATE_COMING:
+ if (mod->num_trace_bprintk_fmt) {
+ const char **start = mod->trace_bprintk_fmt_start;
+ const char **end = start + mod->num_trace_bprintk_fmt;
+
hold_module_trace_bprintk_format(start, end);
+ }
+ hold_module_tracepoint_strings(mod);
+ break;
+ case MODULE_STATE_GOING:
+ release_module_tracepoint_strings(mod);
+ break;
}
return NOTIFY_OK;
}
@@ -119,7 +180,7 @@ static int module_trace_bprintk_format_notify(struct notifier_block *self,
* next format in the list.
*/
static const char **
-find_next_mod_format(int start_index, void *v, const char **fmt, loff_t *pos)
+find_next_mod_format(loff_t start_index, void *v, const char **fmt, loff_t *pos)
{
struct trace_bprintk_fmt *mod_fmt;
@@ -158,6 +219,25 @@ find_next_mod_format(int start_index, void *v, const char **fmt, loff_t *pos)
return &mod_fmt->fmt;
}
+static const char **
+find_next_mod_tracepoint_str(loff_t start_index, loff_t *pos)
+{
+ struct tracepoint_mod_str *tp_str;
+ loff_t offset = *pos - start_index;
+
+ if (offset < 0)
+ return NULL;
+
+ list_for_each_entry(tp_str, &tracepoint_str_list, list) {
+ if (offset < (loff_t)tp_str->num)
+ return tp_str->start + offset;
+
+ offset -= tp_str->num;
+ }
+
+ return NULL;
+}
+
static void format_mod_start(void)
{
mutex_lock(&btrace_mutex);
@@ -176,10 +256,17 @@ module_trace_bprintk_format_notify(struct notifier_block *self,
return NOTIFY_OK;
}
static inline const char **
-find_next_mod_format(int start_index, void *v, const char **fmt, loff_t *pos)
+find_next_mod_format(loff_t start_index, void *v, const char **fmt, loff_t *pos)
{
return NULL;
}
+
+static inline const char **
+find_next_mod_tracepoint_str(loff_t start_index, loff_t *pos)
+{
+ return NULL;
+}
+
static inline void format_mod_start(void) { }
static inline void format_mod_stop(void) { }
#endif /* CONFIG_MODULES */
@@ -265,8 +352,8 @@ bool trace_is_tracepoint_string(const char *str)
static const char **find_next(void *v, loff_t *pos)
{
const char **fmt = v;
- int start_index;
- int last_index;
+ loff_t start_index;
+ loff_t last_index;
start_index = __stop___trace_bprintk_fmt - __start___trace_bprintk_fmt;
@@ -292,7 +379,11 @@ static const char **find_next(void *v, loff_t *pos)
return __start___tracepoint_str + (*pos - last_index);
start_index += last_index;
- return find_next_mod_format(start_index, v, fmt, pos);
+ if (*pos - start_index < trace_bprintk_fmt_cnt)
+ return find_next_mod_format(start_index, v, fmt, pos);
+
+ start_index += trace_bprintk_fmt_cnt;
+ return find_next_mod_tracepoint_str(start_index, pos);
}
static void *
diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c
index ca5d98c360cb..0164cbdc4263 100644
--- a/samples/trace_events/trace-events-sample.c
+++ b/samples/trace_events/trace-events-sample.c
@@ -51,6 +51,9 @@ static void do_simple_thread_func(int cnt, const char *fmt, ...)
trace_foo_with_template_print("I have to be different", cnt);
trace_foo_rel_loc("Hello __rel_loc", cnt, bitmask, current->cpus_ptr);
+
+ trace_foo_tracepoint_str(tracepoint_string("tracepoint_string_test_module_string_1"));
+ trace_foo_tracepoint_str(tracepoint_string("tracepoint_string_test_module_string_2"));
}
static void simple_thread_func(int cnt)
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index 816848a456a2..021fd0e9d2f5 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -623,6 +623,23 @@ TRACE_EVENT(foo_timer_fn,
TP_printk("name=%s count=%d", __get_str(name), __entry->count)
);
+
+TRACE_EVENT(foo_tracepoint_str,
+
+ TP_PROTO(const char *str),
+
+ TP_ARGS(str),
+
+ TP_STRUCT__entry(
+ __field(const char *, str)
+ ),
+
+ TP_fast_assign(
+ __entry->str = str;
+ ),
+
+ TP_printk("str=%s", __entry->str)
+);
#endif
/***** NOTICE! The #if protection ends here. *****/
diff --git a/tools/testing/selftests/ftrace/test.d/event/tracepoint_string.tc b/tools/testing/selftests/ftrace/test.d/event/tracepoint_string.tc
new file mode 100644
index 000000000000..f0916f34f148
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/event/tracepoint_string.tc
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test tracepoint strings from a module
+# requires: printk_formats
+
+string1=tracepoint_string_test_module_string_1
+string2=tracepoint_string_test_module_string_2
+event=events/sample-trace/foo_tracepoint_str
+
+rmmod trace-events-sample 2>/dev/null ||:
+if ! modprobe trace-events-sample; then
+ echo "No trace-events-sample module - please make CONFIG_SAMPLE_TRACE_EVENTS=m"
+ exit_unresolved
+fi
+trap 'rmmod trace-events-sample >/dev/null 2>&1 ||:' EXIT
+
+grep -Fq "$string1" printk_formats || exit_fail
+grep -Fq "$string2" printk_formats || exit_fail
+
+echo 1 > "$event/enable"
+echo 1 > tracing_on
+
+# The sample thread emits both strings once per second.
+attempts=100
+while [ "$attempts" -gt 0 ]; do
+ if grep -Fq "foo_tracepoint_str: str=$string1" trace &&
+ grep -Fq "foo_tracepoint_str: str=$string2" trace; then
+ break
+ fi
+ sleep 0.1
+ attempts=$((attempts - 1))
+done
+[ "$attempts" -gt 0 ] || exit_fail
+
+echo 0 > "$event/enable"
+rmmod trace-events-sample || exit_fail
+trap - EXIT
+
+for string in "$string1" "$string2"; do
+ if grep -Fq "$string" printk_formats; then
+ echo "Module string remains after unload: $string"
+ exit_fail
+ else
+ # grep returns 1 for no match; a read error must also fail the test.
+ [ "$?" -eq 1 ] || exit_fail
+ fi
+done
--
2.53.0
^ permalink raw reply related [flat|nested] 16+ messages in thread