tracing: Tracing fixes for 5.8-rc1
Subsystems (6)
Steven Rostedt
maintainerLinus,
A few fixes and small cleanups for tracing:
- Have recordmcount work with > 64K sections (to support LTO)
- kprobe RCU fixes
- Correct a kprobe critical section with missing mutex
- Remove redundant arch_disarm_kprobe() call
- Fix lockup when kretprobe triggers within kprobe_flush_task()
- Fix memory leak in fetch_op_data operations
- Fix sleep in atomic in ftrace trace array sample code
- Free up memory on failure in sample trace array code
- Fix incorrect reporting of function_graph fields in format file
- Fix quote within quote parsing in bootconfig
- Fix return value of bootconfig tool
- Add testcases for bootconfig tool
- Fix maybe uninitialized warning in ftrace pid file code
- Remove unused variable in tracing_iter_reset()
- Fix some typos
Please pull the latest trace-v5.8-rc1 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v5.8-rc1
Tag SHA1: 51ce53ae395e2df3e879e63985e4c9a3b989c8f5 Head SHA1: 026bb845b0fff6dec91fe24511dad7d3067dc3ed
Jiri Olsa (1):
kretprobe: Prevent triggering kretprobe from within kprobe_flush_task
Kaitao Cheng (1):
ftrace: Fix maybe-uninitialized compiler warning
Kefeng Wang (2):
sample-trace-array: Fix sleeping function called from invalid context
sample-trace-array: Remove trace_array 'sample-instance'
Masami Hiramatsu (8):
kprobes: Suppress the suspicious RCU warning on kprobes
kprobes: Use non RCU traversal APIs on kprobe_tables if possible
kprobes: Fix to protect kick_kprobe_optimizer() by kprobe_mutex
kprobes: Remove redundant arch_disarm_kprobe() call proc/bootconfig: Fix to use correct quotes for value tools/bootconfig: Fix to use correct quotes for value tools/bootconfig: Fix to return 0 if succeeded to show the bootconfig tools/bootconfig: Add testcase for show-command and quotes test
Sami Tolvanen (1):
recordmcount: support >64k sections
Steven Rostedt (VMware) (1):
tracing: Make ftrace packed events have align of 1
Vamshi K Sthambamkadi (1):
tracing/probe: Fix memleak in fetch_op_data operations
Wei Yang (1):
trace: Fix typo in allocate_ftrace_ops()'s comment
YangHui (1):
tracing: Remove unused event variable in tracing_iter_reset
----
arch/x86/kernel/kprobes/core.c | 16 ++---- fs/proc/bootconfig.c | 15 ++++-- include/linux/kprobes.h | 4 ++ kernel/kprobes.c | 61 ++++++++++++++++++----- kernel/trace/ftrace.c | 12 ++++- kernel/trace/trace.c | 3 +- kernel/trace/trace.h | 3 ++ kernel/trace/trace_entries.h | 14 +++--- kernel/trace/trace_export.c | 16 ++++++ kernel/trace/trace_functions.c | 2 +- kernel/trace/trace_probe.c | 4 +- samples/ftrace/sample-trace-array.c | 24 ++++++--- scripts/recordmcount.h | 98 ++++++++++++++++++++++++++++++++++--- tools/bootconfig/main.c | 24 +++++---- tools/bootconfig/test-bootconfig.sh | 10 ++++ 15 files changed, 239 insertions(+), 67 deletions(-)
---------------------------
arch/x86/kernel/kprobes/core.c +3 -13
@@ -753,16 +753,11 @@ asm(NOKPROBE_SYMBOL (kretprobe_trampoline);STACK_FRAME_NON_STANDARD (kretprobe_trampoline); -static struct kprobe kretprobe_kprobe = { - .addr = (void *)kretprobe_trampoline, -}; -/* * Called from kretprobe_trampoline */ __used __visible void *trampoline_handler(struct pt_regs *regs) { -struct kprobe_ctlblk *kcb;struct kretprobe_instance *ri =NULL ;struct hlist_head *head, empty_rp;struct hlist_node *tmp;
@@ -772,16 +767,12 @@ __used __visible void *trampoline_handler(struct pt_regs *regs)void *frame_pointer;bool skipped = false; -preempt_disable (); -/* * Set a dummy kprobe for avoiding kretprobe recursion. * Since kretprobe never run in kprobe handler, kprobe must not * be running at this point. */ - kcb =get_kprobe_ctlblk (); -__this_cpu_write (current_kprobe, &kretprobe_kprobe); - kcb->kprobe_status =KPROBE_HIT_ACTIVE ; +kprobe_busy_begin ();INIT_HLIST_HEAD (&empty_rp);kretprobe_hash_lock (current, &head, &flags);
@@ -857,7 +848,7 @@ __used __visible void *trampoline_handler(struct pt_regs *regs)__this_cpu_write (current_kprobe, &ri->rp->kp); ri->ret_addr = correct_ret_addr; ri->rp->handler (ri, regs); -__this_cpu_write (current_kprobe, &kretprobe_kprobe); +__this_cpu_write (current_kprobe, &kprobe_busy); }recycle_rp_inst (ri, &empty_rp);
@@ -873,8 +864,7 @@ __used __visible void *trampoline_handler(struct pt_regs *regs)kretprobe_hash_unlock (current, &flags); -__this_cpu_write (current_kprobe,NULL ); -preempt_enable (); +kprobe_busy_end ();hlist_for_each_entry_safe (ri, tmp, &empty_rp, hlist) {hlist_del (&ri->hlist);
fs/proc/bootconfig.c +10 -5
@@ -26,8 +26,9 @@ static int boot_config_proc_show(struct seq_file *m, void *v)static int __init copy_xbc_key_value_list (char *dst,size_t size) {struct xbc_node *leaf, *vnode; -const char *val;char *key, *end = dst + size; +const char *val; +char q;int ret =0 ; key =kzalloc (XBC_KEYLEN_MAX ,GFP_KERNEL );
@@ -41,16 +42,20 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size)break ; dst += ret; vnode =xbc_node_get_child (leaf); -if (vnode &&xbc_node_is_array (vnode)) { +if (vnode) {xbc_array_for_each_value (vnode, val) { - ret =snprintf (dst,rest (dst, end),"\"%s\"%s" , - val, vnode->next ?", " :"\n" ); +if (strchr (val,'"' )) + q ='\'' ; +else + q ='"' ; + ret =snprintf (dst,rest (dst, end),"%c%s%c%s" , + q, val, q, vnode->next ?", " :"\n" );if (ret <0 ) goto out; dst += ret; } }else { - ret =snprintf (dst,rest (dst, end),"\"%s\"\n" , val); + ret =snprintf (dst,rest (dst, end),"\"\"\n" );if (ret <0 )break ; dst += ret;
include/linux/kprobes.h +4 -0
@@ -350,6 +350,10 @@ static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)return this_cpu_ptr (&kprobe_ctlblk); } +extern struct kprobe kprobe_busy; +void kprobe_busy_begin (void ); +void kprobe_busy_end (void ); +kprobe_opcode_t *kprobe_lookup_name (const char *name,unsigned int offset);int register_kprobe (struct kprobe *p);void unregister_kprobe (struct kprobe *p);
kernel/kprobes.c +48 -13
172 lines not on this page · raw message
kernel/trace/ftrace.c +10 -2
@@ -2260,7 +2260,7 @@ ftrace_find_tramp_ops_next(struct dyn_ftrace *rec,if (hash_contains_ip (ip, op->func_hash))return op; - } + }return NULL ; }
@@ -3599,7 +3599,7 @@ static int t_show(struct seq_file *m, void *v)if (direct)seq_printf (m,"\n\tdirect-->%pS" , (void *)direct); } - } + }seq_putc (m,'\n' );
@@ -7151,6 +7151,10 @@ static int pid_open(struct inode *inode, struct file *file, int type)case TRACE_NO_PIDS : seq_ops = &ftrace_no_pid_sops;break ; +default : +trace_array_put (tr); +WARN_ON_ONCE (1 ); +return -EINVAL ; } ret =seq_open (file, seq_ops);
@@ -7229,6 +7233,10 @@ pid_write(struct file *filp, const char __user *ubuf, other_pids =rcu_dereference_protected (tr->function_pids,lockdep_is_held (&ftrace_lock));break ; +default : + ret = -EINVAL ; +WARN_ON_ONCE (1 ); + goto out; } ret =trace_pid_write (filtered_pids, &pid_list, ubuf, cnt);
kernel/trace/trace.c +1 -2
@@ -3570,7 +3570,6 @@ static void *s_next(struct seq_file *m, void *v, loff_t *pos)void tracing_iter_reset (struct trace_iterator *iter,int cpu) { -struct ring_buffer_event *event;struct ring_buffer_iter *buf_iter;unsigned long entries =0 ;u64 ts;
@@ -3588,7 +3587,7 @@ void tracing_iter_reset(struct trace_iterator *iter, int cpu)* that a reset never took place on a cpu. This is evident * by the timestamp being before the start of the buffer. */ -while ((event =ring_buffer_iter_peek (buf_iter, &ts))) { +while (ring_buffer_iter_peek (buf_iter, &ts)) {if (ts >= iter->array_buffer->time_start)break ; entries++;
kernel/trace/trace.h +3 -0
@@ -61,6 +61,9 @@ enum trace_type {#undef __field_desc#define __field_desc (type, container, item) +#undef __field_packed +#define __field_packed (type, container, item) +#undef __array#define __array (type, item, size) type item[size];
kernel/trace/trace_entries.h +7 -7
@@ -78,8 +78,8 @@ FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry, F_STRUCT( __field_struct( struct ftrace_graph_ent, graph_ent ) - __field_desc( unsigned long, graph_ent, func ) - __field_desc( int, graph_ent, depth ) + __field_packed( unsigned long, graph_ent, func ) + __field_packed( int, graph_ent, depth ) ), F_printk("--> %ps (%d)", (void *)__entry->func, __entry->depth)
@@ -92,11 +92,11 @@ FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry, F_STRUCT( __field_struct( struct ftrace_graph_ret, ret ) - __field_desc( unsigned long, ret, func ) - __field_desc( unsigned long, ret, overrun ) - __field_desc( unsigned long long, ret, calltime) - __field_desc( unsigned long long, ret, rettime ) - __field_desc( int, ret, depth ) + __field_packed( unsigned long, ret, func ) + __field_packed( unsigned long, ret, overrun ) + __field_packed( unsigned long long, ret, calltime) + __field_packed( unsigned long long, ret, rettime ) + __field_packed( int, ret, depth ) ), F_printk("<-- %ps (%d) (start: %llx end: %llx) over: %d",
kernel/trace/trace_export.c +16 -0
@@ -45,6 +45,9 @@ static int ftrace_event_register(struct trace_event_call *call,#undef __field_desc#define __field_desc (type, container, item) type item; +#undef __field_packed +#define __field_packed (type, container, item) type item; +#undef __array#define __array (type, item, size) type item[size];
@@ -85,6 +88,13 @@ static void __always_unused ____ftrace_check_##name(void) \ .size = sizeof(_type), .align = __alignof__(_type), \ is_signed_type(_type), .filter_type = _filter_type }, + +#undef __field_ext_packed +#define __field_ext_packed (_type, _item, _filter_type) { \ + .type = #_type, .name = #_item, \ + .size = sizeof(_type), .align = 1, \ + is_signed_type(_type), .filter_type = _filter_type }, +#undef __field#define __field (_type, _item) __field_ext(_type, _item, FILTER_OTHER)
@@ -94,6 +104,9 @@ static void __always_unused ____ftrace_check_##name(void) \#undef __field_desc#define __field_desc (_type, _container, _item) __field_ext(_type, _item, FILTER_OTHER) +#undef __field_packed +#define __field_packed (_type, _container, _item) __field_ext_packed(_type, _item, FILTER_OTHER) +#undef __array#define __array (_type, _item, _len) { \ .type = #_type"["__stringify(_len)"]", .name = #_item, \
@@ -129,6 +142,9 @@ static struct trace_event_fields ftrace_event_fields_##name[] = { \#undef __field_desc#define __field_desc (type, container, item) +#undef __field_packed +#define __field_packed (type, container, item) +#undef __array#define __array (type, item, len)
kernel/trace/trace_functions.c +1 -1
@@ -42,7 +42,7 @@ static int allocate_ftrace_ops(struct trace_array *tr)if (!ops)return -ENOMEM ; -/* Currently only the non stack verision is supported */ +/* Currently only the non stack version is supported */ ops->func = function_trace_call; ops->flags =FTRACE_OPS_FL_RECURSION_SAFE |FTRACE_OPS_FL_PID ;
kernel/trace/trace_probe.c +2 -2
@@ -639,8 +639,8 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size, ret = -EINVAL ; goto fail; } -if ((code->op ==FETCH_OP_IMM || code->op ==FETCH_OP_COMM ) || - parg->count) { +if ((code->op ==FETCH_OP_IMM || code->op ==FETCH_OP_COMM || + code->op ==FETCH_OP_DATA ) || parg->count) {/* * IMM, DATA and COMM is pointing actual address, those * must be kept, and if parg->count != 0, this is an
samples/ftrace/sample-trace-array.c +18 -6
@@ -6,6 +6,7 @@#include <linux/timer.h> #include <linux/err.h> #include <linux/jiffies.h> +#include <linux/workqueue.h> /* * Any file that uses trace points, must include the header.
@@ -20,6 +21,16 @@ struct trace_array *tr;static void mytimer_handler (struct timer_list *unused);static struct task_struct *simple_tsk; +static void trace_work_fn (struct work_struct *work) +{ +/* +* Disable tracing for event "sample_event". +*/ +trace_array_set_clr_event (tr,"sample-subsystem" ,"sample_event" , + false); +} +static DECLARE_WORK(trace_work, trace_work_fn); +/* * mytimer: Timer setup to disable tracing for event "sample_event". This * timer is only for the purposes of the sample module to demonstrate access of
@@ -29,11 +40,7 @@ static DEFINE_TIMER(mytimer, mytimer_handler);static void mytimer_handler (struct timer_list *unused) { -/* -* Disable tracing for event "sample_event". -*/ -trace_array_set_clr_event (tr,"sample-subsystem" ,"sample_event" , - false); +schedule_work (&trace_work); }static void simple_thread_func (int count)
@@ -76,6 +83,7 @@ static int simple_thread(void *arg)simple_thread_func (count++);del_timer (&mytimer); +cancel_work_sync (&trace_work);/* * trace_array_put() decrements the reference counter associated with
@@ -107,8 +115,12 @@ static int __init sample_trace_array_init(void)trace_printk_init_buffers (); simple_tsk =kthread_run (simple_thread,NULL ,"sample-instance" ); -if (IS_ERR (simple_tsk)) +if (IS_ERR (simple_tsk)) { +trace_array_put (tr); +trace_array_destroy (tr);return -1 ; + } +return 0 ; }
scripts/recordmcount.h +92 -6
185 lines not on this page · raw message
tools/bootconfig/main.c +14 -10
@@ -14,13 +14,18 @@#include <linux/kernel.h> #include <linux/bootconfig.h> -static int xbc_show_array (struct xbc_node *node) +static int xbc_show_value (struct xbc_node *node) {const char *val; +char q;int i =0 ;xbc_array_for_each_value (node, val) { -printf ("\"%s\"%s" , val, node->next ?", " :";\n" ); +if (strchr (val,'"' )) + q ='\'' ; +else + q ='"' ; +printf ("%c%s%c%s" , q, val, q, node->next ?", " :";\n" ); i++; }return i;
@@ -48,10 +53,7 @@ static void xbc_show_compact_tree(void)continue ; }else if (cnode &&xbc_node_is_value (cnode)) {printf ("%s = " ,xbc_node_get_data (node)); -if (cnode->next) -xbc_show_array (cnode); -else -printf ("\"%s\";\n" ,xbc_node_get_data (cnode)); +xbc_show_value (cnode); }else {printf ("%s;\n" ,xbc_node_get_data (node)); }
@@ -205,11 +207,13 @@ int show_xbc(const char *path) } ret =load_xbc_from_initrd (fd, &buf); -if (ret <0 ) +if (ret <0 ) {pr_err ("Failed to load a boot config from initrd: %d\n" , ret); -else -xbc_show_compact_tree (); - + goto out; + } +xbc_show_compact_tree (); + ret =0 ; +out:close (fd);free (buf);
tools/bootconfig/test-bootconfig.sh +10 -0
@@ -55,6 +55,9 @@ echo "Apply command test" xpass $BOOTCONF -a $TEMPCONF $INITRD new_size=$(stat -c %s $INITRD) +echo "Show command test" +xpass $BOOTCONF $INITRD + echo "File size check" xpass test $new_size -eq $(expr $bconf_size + $initrd_size + 9 + 12)
@@ -114,6 +117,13 @@ xpass grep -q "bar" $OUTFILE xpass grep -q "baz" $OUTFILE xpass grep -q "qux" $OUTFILE +echo "Double/single quotes test" +echo "key = '\"string\"';" > $TEMPCONF +$BOOTCONF -a $TEMPCONF $INITRD +$BOOTCONF $INITRD > $TEMPCONF +cat $TEMPCONF +xpass grep \'\"string\"\' $TEMPCONF + echo "=== expected failure cases ===" for i in samples/bad-* ; do xfail $BOOTCONF -a $i $INITRD
The pull request you sent on Fri, 19 Jun 2020 21:24:27 -0400:
The pull request you sent on Fri, 19 Jun 2020 21:24:27 -0400:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.gittrace-v5.8-rc1
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/8b6ddd10d678bebec32381f71b6b420bafc43ad0
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.wiki.kernel.org/userdoc/prtracker