tracing: Updates for 7.5
Subsystems (27)
cover tracing: Updates for 7.5
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/for-next
Head SHA1: 1e443753bfddcd9d34bfb672be26245c4deca2d0
Cao Ruichuang (1):
tracing: Export live module tracepoint strings in printk_formats
Leizhen Zhang (2):
tracing/scripts: Check the section end before reading a string in tracing-update tracing/scripts: Do not reuse section pointers from a previous file in tracing-update
Masami Hiramatsu (Google) (8):
tracing: Override the same name trace_instance= by latter one selftests/ftrace: Add test case for overriding trace_instance parameter tracing/filters: Report parse error on all -EINVAL paths in filter parsing tracing/filters: Fix quoted operand parsing in function event filter tracing/filters: Reject empty unquoted operand in function event filter tracing/filters: Reject unsupported field sizes in parse_pred() tracing/filters: Check for trailing characters after newline in filter string tracing/filters: Reject stray quotes and parentheses in unquoted function event operand
Steven Rostedt (4):
tracing: Do not clean up hiter in mmiotrace read function
lockdep: Add #include <linux/instruction_pointer.h> to lockdep.h
tracing: Move non-trace_printk prototypes into trace_controls.h
tracing: Remove trace_printk.h from kernel.h
----
Documentation/admin-guide/kernel-parameters.txt | 7 + Documentation/trace/debugging.rst | 15 +++ arch/powerpc/kvm/book3s_xics.c | 1 + arch/powerpc/xmon/xmon.c | 1 + arch/s390/kernel/ipl.c | 1 + arch/s390/kernel/machine_kexec.c | 1 + drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + drivers/gpu/drm/i915/i915_gem.h | 2 + drivers/hwtracing/stm/dummy_stm.c | 1 + drivers/infiniband/hw/hfi1/trace_dbg.h | 1 + drivers/tty/sysrq.c | 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/lockdep.h | 1 + include/linux/module.h | 2 + include/linux/sunrpc/debug.h | 1 + include/linux/trace_controls.h | 54 ++++++++ include/linux/trace_printk.h | 56 +------- include/linux/tracepoint.h | 9 +- include/trace/trace_events.h | 2 + kernel/debug/debug_core.c | 1 + kernel/module/main.c | 4 + kernel/panic.c | 1 + kernel/rcu/rcu.h | 1 + kernel/rcu/rcutorture.c | 1 + kernel/trace/ring_buffer_benchmark.c | 1 + kernel/trace/trace.c | 150 ++++++++++++++++----- kernel/trace/trace.h | 1 + kernel/trace/trace_benchmark.c | 1 + kernel/trace/trace_events_filter.c | 94 +++++++++++-- kernel/trace/trace_mmiotrace.c | 14 +- kernel/trace/trace_printk.c | 111 +++++++++++++-- lib/sys_info.c | 1 + samples/fprobe/fprobe_example.c | 1 + samples/ftrace/ftrace-direct-too.c | 1 - samples/trace_events/trace-events-sample.c | 3 + samples/trace_events/trace-events-sample.h | 17 +++ samples/trace_printk/trace-printk.c | 1 + scripts/tracepoint-update.c | 6 +- .../cmdline-07-trace-instance-override.bconf | 4 + .../cmdline-07-trace-instance-override.cmdline | 1 + .../selftests/ftrace/boottime/run_boottime_test.sh | 2 + .../tests/cmdline-07-trace-instance-override.sh | 148 ++++++++++++++++++++ .../ftrace/test.d/event/tracepoint_string.tc | 47 +++++++ 46 files changed, 642 insertions(+), 132 deletions(-) create mode 100644 include/linux/trace_controls.h 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 create mode 100644 tools/testing/selftests/ftrace/test.d/event/tracepoint_string.tc
PATCH 1/15 tracing: Do not clean up hiter in mmiotrace read function
From: Steven Rostedt <[email protected]>
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.
--- kernel/trace/trace_mmiotrace.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
kernel/trace/trace_mmiotrace.c +3 -11
@@ -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; }
Signature · 1 line
2.53.0
PATCH 2/15 lockdep: Add #include <linux/instruction_pointer.h> to lockdep.h
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
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.
--- include/linux/lockdep.h | 1 + 1 file changed, 1 insertion(+)
include/linux/lockdep.h +1 -0
@@ -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)
Signature · 1 line
2.53.0
PATCH 3/15 tracing: Move non-trace_printk prototypes into trace_controls.h
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
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.
--- 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
arch/powerpc/xmon/xmon.c +1 -0
@@ -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>
arch/s390/kernel/ipl.c +1 -0
@@ -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>
arch/s390/kernel/machine_kexec.c +1 -0
@@ -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>
drivers/gpu/drm/i915/i915_gem.h +1 -0
@@ -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__); \
drivers/tty/sysrq.c +1 -0
@@ -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)
include/linux/trace_controls.h new file +54 -0
54 lines not on this page · raw message
include/linux/trace_printk.h +0 -51
77 lines not on this page · raw message
kernel/debug/debug_core.c +1 -0
@@ -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>
kernel/panic.c +1 -0
@@ -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>
kernel/rcu/rcu.h +1 -0
@@ -12,6 +12,7 @@#include <linux/slab.h> #include <trace/events/rcu.h> +#include <linux/trace_controls.h> /* * Grace-period counter management.
kernel/rcu/rcutorture.c +1 -0
@@ -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>
kernel/trace/trace.h +1 -0
@@ -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"
kernel/trace/trace_benchmark.c +1 -0
@@ -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"
lib/sys_info.c +1 -0
@@ -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>
Signature · 1 line
2.53.0
PATCH 4/15 tracing: Remove trace_printk.h from kernel.h
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
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.
--- 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(-)
arch/powerpc/kvm/book3s_xics.c +1 -0
@@ -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
drivers/gpu/drm/i915/gt/intel_gtt.h +1 -0
@@ -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 (...)
drivers/gpu/drm/i915/i915_gem.h +1 -0
@@ -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__); \
drivers/hwtracing/stm/dummy_stm.c +1 -0
@@ -8,6 +8,7 @@*/ #undef DEBUG +#include <linux/trace_printk.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h>
drivers/infiniband/hw/hfi1/trace_dbg.h +1 -0
@@ -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
drivers/usb/early/xhci-dbc.c +1 -0
@@ -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, ...) { }
fs/ext4/inline.c +1 -0
@@ -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) {
include/linux/ftrace.h +2 -0
@@ -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>
include/linux/kernel.h +0 -1
@@ -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>
include/linux/sunrpc/debug.h +1 -0
@@ -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__)
include/linux/trace_printk.h +3 -2
@@ -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
include/trace/trace_events.h +2 -0
@@ -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
kernel/trace/ring_buffer_benchmark.c +1 -0
@@ -5,6 +5,7 @@* Copyright (C) 2009 Steven Rostedt <[email protected]> */ #include <linux/ring_buffer.h> +#include <linux/trace_printk.h> #include <linux/completion.h> #include <linux/kthread.h> #include <uapi/linux/sched/types.h>
samples/fprobe/fprobe_example.c +1 -0
@@ -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>
samples/ftrace/ftrace-direct-too.c +0 -1
@@ -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 )
samples/trace_printk/trace-printk.c +1 -0
@@ -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>
Signature · 1 line
2.53.0
PATCH 5/15 tracing: Override the same name trace_instance= by latter one
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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.
--- .../admin-guide/kernel-parameters.txt | 7 + Documentation/trace/debugging.rst | 15 ++ kernel/trace/trace.c | 150 +++++++++++++----- 3 files changed, 135 insertions(+), 37 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -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
Documentation/trace/debugging.rst +15 -0
@@ -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 +
kernel/trace/trace.c +113 -37
244 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 6/15 selftests/ftrace: Add test case for overriding trace_instance parameter
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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.
--- .../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
tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf new file +4 -0
@@ -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"
tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline new file +1 -0
@@ -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=,
tools/testing/selftests/ftrace/boottime/run_boottime_test.sh +2 -0
@@ -46,6 +46,8 @@ BUSYBOX_APPLETS=( grep sleep sed + dmesg + basename ) usage() {
tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 7/15 tracing/scripts: Check the section end before reading a string in tracing-update
In reply to Steven RostedtFrom: Leizhen Zhang <[email protected]>
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.
--- scripts/tracepoint-update.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/tracepoint-update.c +1 -1
@@ -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)
Signature · 1 line
2.53.0
PATCH 8/15 tracing/scripts: Do not reuse section pointers from a previous file in tracing-update
In reply to Steven RostedtFrom: Leizhen Zhang <[email protected]>
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.
--- scripts/tracepoint-update.c | 4 ++++ 1 file changed, 4 insertions(+)
scripts/tracepoint-update.c +4 -0
@@ -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);
Signature · 1 line
2.53.0
PATCH 9/15 tracing/filters: Report parse error on all -EINVAL paths in filter parsing
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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.
--- kernel/trace/trace_events_filter.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
kernel/trace/trace_events_filter.c +10 -3
@@ -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);
Signature · 1 line
2.53.0
PATCH 10/15 tracing/filters: Fix quoted operand parsing in function event filter
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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.
--- kernel/trace/trace_events_filter.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
kernel/trace/trace_events_filter.c +12 -7
@@ -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;
Signature · 1 line
2.53.0
PATCH 11/15 tracing/filters: Reject empty unquoted operand in function event filter
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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.
--- kernel/trace/trace_events_filter.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/trace/trace_events_filter.c +4 -0
@@ -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;
Signature · 1 line
2.53.0
PATCH 12/15 tracing/filters: Reject unsupported field sizes in parse_pred()
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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
--- kernel/trace/trace_events_filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/trace/trace_events_filter.c +8 -0
@@ -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 ; }
Signature · 1 line
2.53.0
PATCH 13/15 tracing/filters: Check for trailing characters after newline in filter string
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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.
--- kernel/trace/trace_events_filter.c | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
kernel/trace/trace_events_filter.c +36 -0
@@ -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);
Signature · 1 line
2.53.0
PATCH 14/15 tracing/filters: Reject stray quotes and parentheses in unquoted function event operand
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
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.
--- kernel/trace/trace_events_filter.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
kernel/trace/trace_events_filter.c +11 -3
@@ -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);
Signature · 1 line
2.53.0
PATCH 15/15 tracing: Export live module tracepoint strings in printk_formats
In reply to Steven RostedtFrom: Cao Ruichuang <[email protected]>
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.
--- 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
include/linux/module.h +2 -0
@@ -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;
include/linux/tracepoint.h +4 -5
@@ -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) \ ({ \
kernel/module/main.c +4 -0
@@ -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 */
kernel/trace/trace_printk.c +101 -10
182 lines not on this page · raw message
samples/trace_events/trace-events-sample.c +3 -0
@@ -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)
samples/trace_events/trace-events-sample.h +17 -0
@@ -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. *****/
tools/testing/selftests/ftrace/test.d/event/tracepoint_string.tc new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.53.0