tracing: Fixes for 5.7
Subsystems (3)
Steven Rostedt
maintainercover tracing: Fixes for 5.7
Masami Hiramatsu (4):
bootconfig: Fix to remove bootconfig data from initrd while boot tracing/kprobes: Fix a double initialization typo tracing/boottime: Fix kprobe event API usage tracing/kprobes: Reject new event if loc is NULL
Steven Rostedt (VMware) (2):
tracing: Wait for preempt irq delay thread to finish
tracing: Add a vmalloc_sync_mappings() for safe measure
Wei Yang (1):
tracing: Fix doc mistakes in trace sample
Yiwei Zhang (1):
gpu/trace: Minor comment updates for gpu_mem_total tracepoint
Zou Wei (1):
tracing: Make tracing_snapshot_instance_cond() static
----
include/trace/events/gpu_mem.h | 2 +- init/main.c | 69 ++++++++++++++++++++++-------- kernel/trace/preemptirq_delay_test.c | 30 ++++++++++--- kernel/trace/trace.c | 16 ++++++- kernel/trace/trace_boot.c | 20 ++++----- kernel/trace/trace_kprobe.c | 8 +++- samples/trace_events/trace-events-sample.h | 2 +- 7 files changed, 108 insertions(+), 39 deletions(-)
Steven Rostedt
maintainerPATCH 1/9 bootconfig: Fix to remove bootconfig data from initrd while boot
From: Masami Hiramatsu <[email protected]>
If there is a bootconfig data in the tail of initrd/initramfs, initrd image sanity check caused an error while decompression stage as follows.
[ 0.883882] Unpacking initramfs... [ 2.696429] Initramfs unpacking failed: invalid magic at start of compressed archive
This error will be ignored if CONFIG_BLK_DEV_RAM=n, but CONFIG_BLK_DEV_RAM=y the kernel failed to mount rootfs and causes a panic.
To fix this issue, shrink down the initrd_end for removing tailing bootconfig data while boot the kernel.
--- init/main.c | 69 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 17 deletions(-)
init/main.c +52 -17
@@ -257,6 +257,47 @@ static int __init loglevel(char *str)early_param ("loglevel" , loglevel); +#ifdef CONFIG_BLK_DEV_INITRD +static void *__init get_boot_config_from_initrd (u32 *_size,u32 *_csum) +{ +u32 size, csum; +char *data; +u32 *hdr; + +if (!initrd_end) +return NULL ; + + data = (char *)initrd_end -BOOTCONFIG_MAGIC_LEN ; +if (memcmp (data,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN )) +return NULL ; + + hdr = (u32 *)(data -8 ); + size = hdr[0 ]; + csum = hdr[1 ]; + + data = ((void *)hdr) - size; +if ((unsigned long )data < initrd_start) { +pr_err ("bootconfig size %d is greater than initrd size %ld\n" , + size, initrd_end - initrd_start); +return NULL ; + } + +/* Remove bootconfig from initramfs/initrd */ + initrd_end = (unsigned long )data; +if (_size) + *_size = size; +if (_csum) + *_csum = csum; + +return data; +} +#else +static void *__init get_boot_config_from_initrd (u32 *_size,u32 *_csum) +{ +return NULL ; +} +#endif +#ifdef CONFIG_BOOT_CONFIG char xbc_namebuf[XBC_KEYLEN_MAX ]__initdata ;
@@ -357,9 +398,12 @@ static void __init setup_boot_config(const char *cmdline)int pos;u32 size, csum;char *data, *copy; -u32 *hdr;int ret; + data =get_boot_config_from_initrd (&size, &csum); +if (!data) + goto not_found; +strlcpy (tmp_cmdline, boot_command_line,COMMAND_LINE_SIZE );parse_args ("bootconfig" , tmp_cmdline,NULL ,0 ,0 ,0 ,NULL , bootconfig_params);
@@ -367,27 +411,12 @@ static void __init setup_boot_config(const char *cmdline)if (!bootconfig_found)return ; -if (!initrd_end) - goto not_found; - - data = (char *)initrd_end -BOOTCONFIG_MAGIC_LEN ; -if (memcmp (data,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN )) - goto not_found; - - hdr = (u32 *)(data -8 ); - size = hdr[0 ]; - csum = hdr[1 ]; -if (size >=XBC_DATA_MAX ) {pr_err ("bootconfig size %d greater than max size %d\n" , size,XBC_DATA_MAX );return ; } - data = ((void *)hdr) - size; -if ((unsigned long )data < initrd_start) - goto not_found; -if (boot_config_checksum ((unsigned char *)data, size) != csum) {pr_err ("bootconfig checksum failed\n" );return ;
@@ -420,8 +449,14 @@ static void __init setup_boot_config(const char *cmdline) not_found: pr_err("'bootconfig' found on command line, but no bootconfig found\n"); } +#else -#define setup_boot_config (cmdline) do { } while (0) + +static void __init setup_boot_config (const char *cmdline) +{ +/* Remove bootconfig data from initrd */ +get_boot_config_from_initrd (NULL ,NULL ); +}static int __init warn_bootconfig (char *str) {
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 2/9 tracing/kprobes: Fix a double initialization typo
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Fix a typo that resulted in an unnecessary double
initialization to addr.
--- kernel/trace/trace_kprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_kprobe.c +1 -1
@@ -453,7 +453,7 @@ static bool __within_notrace_func(unsigned long addr)static bool within_notrace_func (struct trace_kprobe *tk) { -unsigned long addr = addr =trace_kprobe_address (tk); +unsigned long addr =trace_kprobe_address (tk);char symname[KSYM_NAME_LEN ], *p;if (!__within_notrace_func (addr))
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 3/9 tracing/boottime: Fix kprobe event API usage
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Fix boottime kprobe events to use API correctly for multiple events.
For example, when we set a multiprobe kprobe events in bootconfig like below,
ftrace.event.kprobes.myevent {
probes = "vfs_read $arg1 $arg2", "vfs_write $arg1 $arg2"
}This cause an error;
trace_boot: Failed to add probe: p:kprobes/myevent (null) vfs_read $arg1 $arg2 vfs_write $arg1 $arg2
This shows the 1st argument becomes NULL and multiprobes are merged to 1 probe.
--- kernel/trace/trace_boot.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
kernel/trace/trace_boot.c +8 -12
@@ -95,24 +95,20 @@ trace_boot_add_kprobe_event(struct xbc_node *node, const char *event)struct xbc_node *anode;char buf[MAX_BUF_LEN ];const char *val; -int ret; +int ret =0 ; -kprobe_event_cmd_init (&cmd, buf,MAX_BUF_LEN ); +xbc_node_for_each_array_value (node,"probes" , anode, val) { +kprobe_event_cmd_init (&cmd, buf,MAX_BUF_LEN ); - ret =kprobe_event_gen_cmd_start (&cmd, event,NULL ); -if (ret) -return ret; + ret =kprobe_event_gen_cmd_start (&cmd, event, val); +if (ret) +break ; -xbc_node_for_each_array_value (node,"probes" , anode, val) { - ret =kprobe_event_add_field (&cmd, val); + ret =kprobe_event_gen_cmd_end (&cmd);if (ret) -return ret; +pr_err ("Failed to add probe: %s\n" , buf); } - ret =kprobe_event_gen_cmd_end (&cmd); -if (ret) -pr_err ("Failed to add probe: %s\n" , buf); - return ret; }#else
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 4/9 tracing/kprobes: Reject new event if loc is NULL
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Reject the new event which has NULL location for kprobes. For kprobes, user must specify at least the location.
--- kernel/trace/trace_kprobe.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/trace/trace_kprobe.c +6 -0
@@ -940,6 +940,9 @@ EXPORT_SYMBOL_GPL(kprobe_event_cmd_init);* complete command or only the first part of it; in the latter case, * kprobe_event_add_fields() can be used to add more fields following this. * +* Unlikely the synth_event_gen_cmd_start(), @loc must be specified. This +* returns -EINVAL if @loc == NULL. +* * Return: 0 if successful, error otherwise. */ int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe,
@@ -953,6 +956,9 @@ int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe,if (cmd->type !=DYNEVENT_TYPE_KPROBE )return -EINVAL ; +if (!loc) +return -EINVAL ; +if (kretprobe)snprintf (buf,MAX_EVENT_NAME_LEN ,"r:kprobes/%s" , name);else
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 5/9 tracing: Wait for preempt irq delay thread to finish
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Running on a slower machine, it is possible that the preempt delay kernel thread may still be executing if the module was immediately removed after added, and this can cause the kernel to crash as the kernel thread might be executing after its code has been removed.
There's no reason that the caller of the code shouldn't just wait for the delay thread to finish, as the thread can also be created by a trigger in the sysfs code, which also has the same issues.
--- kernel/trace/preemptirq_delay_test.c | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
kernel/trace/preemptirq_delay_test.c +24 -6
@@ -113,22 +113,42 @@ static int preemptirq_delay_run(void *data)for (i =0 ; i < s; i++) (testfuncs[i])(i); + +set_current_state (TASK_INTERRUPTIBLE ); +while (!kthread_should_stop ()) { +schedule (); +set_current_state (TASK_INTERRUPTIBLE ); + } + +__set_current_state (TASK_RUNNING ); +return 0 ; } -static struct task_struct *preemptirq_start_test (void ) +static int preemptirq_run_test (void ) { +struct task_struct *task; +char task_name[50 ];snprintf (task_name,sizeof (task_name),"%s_test" , test_mode); -return kthread_run (preemptirq_delay_run,NULL , task_name); + task =kthread_run (preemptirq_delay_run,NULL , task_name); +if (IS_ERR (task)) +return PTR_ERR (task); +if (task) +kthread_stop (task); +return 0 ; }static ssize_t trigger_store (struct kobject *kobj,struct kobj_attribute *attr,const char *buf,size_t count) { -preemptirq_start_test (); +ssize_t ret; + + ret =preemptirq_run_test (); +if (ret) +return ret;return count; }
@@ -148,11 +168,9 @@ static struct kobject *preemptirq_delay_kobj;static int __init preemptirq_delay_init (void ) { -struct task_struct *test_task;int retval; - test_task =preemptirq_start_test (); - retval =PTR_ERR_OR_ZERO (test_task); + retval =preemptirq_run_test ();if (retval !=0 )return retval;
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 6/9 tracing: Add a vmalloc_sync_mappings() for safe measure
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
x86_64 lazily maps in the vmalloc pages, and the way this works with per_cpu areas can be complex, to say the least. Mappings may happen at boot up, and if nothing synchronizes the page tables, those page mappings may not be synced till they are used. This causes issues for anything that might touch one of those mappings in the path of the page fault handler. When one of those unmapped mappings is touched in the page fault handler, it will cause another page fault, which in turn will cause a page fault, and leave us in a loop of page faults.
Commit 763802b53a42 ("x86/mm: split vmalloc_sync_all()") split vmalloc_sync_all() into vmalloc_sync_unmappings() and vmalloc_sync_mappings(), as on system exit, it did not need to do a full sync on x86_64 (although it still needed to be done on x86_32). By chance, the vmalloc_sync_all() would synchronize the page mappings done at boot up and prevent the per cpu area from being a problem for tracing in the page fault handler. But when that synchronization in the exit of a task became a nop, it caused the problem to appear.
--- kernel/trace/trace.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kernel/trace/trace.c +13 -0
@@ -8525,6 +8525,19 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)*/ allocate_snapshot = false;#endif + +/* +* Because of some magic with the way alloc_percpu() works on +* x86_64, we need to synchronize the pgd of all the tables, +* otherwise the trace events that happen in x86_64 page fault +* handlers can't cope with accessing the chance that a +* alloc_percpu()'d memory might be touched in the page fault trace +* event. Oh, and we need to audit all other alloc_percpu() and vmalloc() +* calls in tracing, because something might get triggered within a +* page fault trace event! +*/ +vmalloc_sync_mappings (); +return 0 ; }
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 7/9 gpu/trace: Minor comment updates for gpu_mem_total tracepoint
In reply to Steven RostedtFrom: Yiwei Zhang <[email protected]>
This change updates the improper comment for the 'size' attribute in the tracepoint definition. Most gfx drivers pre-fault in physical pages instead of making virtual allocations. So we drop the 'Virtual' keyword here and leave this to the implementations.
--- include/trace/events/gpu_mem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/gpu_mem.h +1 -1
@@ -24,7 +24,7 @@* * @pid: Put 0 for global total, while positive pid for process total. * -* @size: Virtual size of the allocation in bytes. +* @size: Size of the allocation in bytes. * */ TRACE_EVENT(gpu_mem_total,
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 8/9 tracing: Fix doc mistakes in trace sample
In reply to Steven RostedtFrom: Wei Yang <[email protected]>
As the example below shows, DECLARE_EVENT_CLASS() is used instead of DEFINE_EVENT_CLASS().
--- samples/trace_events/trace-events-sample.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
samples/trace_events/trace-events-sample.h +1 -1
@@ -416,7 +416,7 @@ TRACE_EVENT_FN(foo_bar_with_fn,* Note, TRACE_EVENT() itself is simply defined as: * * #define TRACE_EVENT(name, proto, args, tstruct, assign, printk) \ -* DEFINE_EVENT_CLASS(name, proto, args, tstruct, assign, printk); \ +* DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, printk); \ * DEFINE_EVENT(name, name, proto, args) * * The DEFINE_EVENT() also can be declared with conditions and reg functions:
Signature · 1 line
2.26.2
Steven Rostedt
maintainerPATCH 9/9 tracing: Make tracing_snapshot_instance_cond() static
In reply to Steven RostedtFrom: Zou Wei <[email protected]>
Fix the following sparse warning:
kernel/trace/trace.c:950:6: warning: symbol 'tracing_snapshot_instance_cond' was not declared. Should it be static?
--- kernel/trace/trace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/trace.c +2 -1
@@ -947,7 +947,8 @@ int __trace_bputs(unsigned long ip, const char *str)EXPORT_SYMBOL_GPL (__trace_bputs);#ifdef CONFIG_TRACER_SNAPSHOT -void tracing_snapshot_instance_cond (struct trace_array *tr,void *cond_data) +static void tracing_snapshot_instance_cond (struct trace_array *tr, +void *cond_data) {struct tracer *tracer = tr->current_trace;unsigned long flags;
Signature · 1 line
2.26.2
Steven Rostedt
maintainer[for-linus][PATCH 10/9] tools/bootconfig: Fix resource leak in apply_xbc()
In reply to Steven RostedtFrom: Yunfeng Ye <[email protected]>
Fix the @data and @fd allocations that are leaked in the error path of apply_xbc().
--- tools/bootconfig/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/bootconfig/main.c +6 -3
@@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path) ret =delete_xbc (path);if (ret <0 ) {pr_err ("Failed to delete previous boot config: %d\n" , ret); +free (data);return ret; }
@@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path) fd =open (path,O_RDWR |O_APPEND );if (fd <0 ) {pr_err ("Failed to open %s: %d\n" , path, fd); +free (data);return fd; }/* TODO: Ensure the @path is initramfs/initrd image */ ret =write (fd, data, size +8 );if (ret <0 ) {pr_err ("Failed to apply a boot config: %d\n" , ret); -return ret; + goto out; }/* Write a magic word of the bootconfig */ ret =write (fd,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN );if (ret <0 ) {pr_err ("Failed to apply a boot config magic: %d\n" , ret); -return ret; + goto out; } +out:close (fd);free (data); -return 0 ; +return ret; }int usage (void )
Signature · 1 line
2.20.1