tracing: My official queue finally passed testing and ready for linux-next
Subsystems (9)
Steven Rostedt
maintainercover tracing: My official queue finally passed testing and ready for linux-next
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: f8a79d5c7ef47c62d97a30e16064caf2ef91f648
Colin Ian King (1):
ftrace: Remove unused pointer ftrace_swapper_pid
Erica Bugden (1):
ftrace: Add missing check for existing hwlat thread
Francis Deslauriers (1):
selftest/ftrace: Move kprobe selftest function to separate compile unit
Gustavo A. R. Silva (1):
ftrace: Use true and false for boolean values in ops_references_rec()
Joel Fernandes (Google) (9):
srcu: Add notrace variant of srcu_dereference tracing/irqsoff: Split reset into separate functions
lib: Add module for testing preemptoff/irqsoff latency tracers
kselftests: Add tests for the preemptoff and irqsoff tracers
lockdep: Use this_cpu_ptr instead of get_cpu_var stats
tracepoint: Make rcuidle tracepoint callers use SRCU
tracing: Centralize preemptirq tracepoints and unify their usage
trace: Use rcu_dereference_raw for hooks from trace-event subsystem
tracing: irqsoff: Account for additional preempt_disable
Masami Hiramatsu (5):
tracing: Remove orphaned function using_ftrace_ops_list_func().
tracing: Remove orphaned function ftrace_nr_registered_ops()
tracing: kprobes: Prohibit probing on notrace function selftests/ftrace: Fix kprobe string testcase to not probe notrace function tracing/kprobes: Fix within_notrace_func() to check only notrace functions
Paul McKenney (1):
srcu: Add notrace variants of srcu_read_{lock,unlock}Steven Rostedt (VMware) (13):
tracing: Make unregister_trigger() static
tracing/kprobes: Simplify the logic of enable_trace_kprobe()
tracing: Do not call start/stop() functions when tracing_on does not change
tracing: Do a WARN_ON() if start_thread() in hwlat is called when thread exists
tracing: Make tracer_tracing_is_on() return bool
ring-buffer: Make ring_buffer_record_is_on() return bool
ring-buffer: Make ring_buffer_record_is_set_on() return bool
tracing: Partial revert of "tracing: Centralize preemptirq tracepoints and unify their usage" tracing/irqsoff: Handle preempt_count for different configs
tracing: More reverting of "tracing: Centralize preemptirq tracepoints and unify their usage"
tracing: Fix synchronizing to event changes with tracepoint_synchronize_unregister()
uprobes: Use synchronize_rcu() not synchronize_sched()
tracepoints: Free early tracepoints after RCU is initialized
Zubin Mithra (1):
tracefs: Annotate tracefs_ops with __ro_after_init
kbuild test robot (1):
tracing: preemptirq_delay_run() can be static
----
fs/tracefs/inode.c | 5 +- include/linux/ftrace.h | 17 +- include/linux/irqflags.h | 15 +- include/linux/lockdep.h | 6 +- include/linux/preempt.h | 2 +- include/linux/ring_buffer.h | 4 +- include/linux/srcu.h | 22 ++ include/linux/tracepoint.h | 40 ++- include/trace/events/preemptirq.h | 23 +- init/main.c | 3 +- kernel/locking/lockdep.c | 35 +-- kernel/sched/core.c | 2 +- kernel/trace/Kconfig | 57 ++++- kernel/trace/Makefile | 8 +- kernel/trace/ftrace.c | 41 +--- kernel/trace/preemptirq_delay_test.c | 72 ++++++ kernel/trace/ring_buffer.c | 4 +- kernel/trace/trace.c | 6 +- kernel/trace/trace.h | 21 +- kernel/trace/trace_events.c | 12 +- kernel/trace/trace_events_filter.c | 15 +- kernel/trace/trace_events_hist.c | 2 +- kernel/trace/trace_events_trigger.c | 12 +- kernel/trace/trace_hwlat.c | 3 + kernel/trace/trace_irqsoff.c | 269 +++++++-------------- kernel/trace/trace_kprobe.c | 103 +++++--- kernel/trace/trace_kprobe_selftest.c | 10 + kernel/trace/trace_kprobe_selftest.h | 7 + kernel/trace/trace_preemptirq.c | 89 +++++++ kernel/trace/trace_uprobe.c | 2 +- kernel/tracepoint.c | 48 +++- tools/testing/selftests/ftrace/config | 3 + .../ftrace/test.d/kprobe/kprobe_args_string.tc | 30 +-- .../selftests/ftrace/test.d/kprobe/probepoint.tc | 2 +- .../ftrace/test.d/preemptirq/irqsoff_tracer.tc | 73 ++++++ 35 files changed, 670 insertions(+), 393 deletions(-) create mode 100644 kernel/trace/preemptirq_delay_test.c create mode 100644 kernel/trace/trace_kprobe_selftest.c create mode 100644 kernel/trace/trace_kprobe_selftest.h create mode 100644 kernel/trace/trace_preemptirq.c create mode 100644 tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
Steven Rostedt
maintainerPATCH 1/34 srcu: Add notrace variants of srcu_read_{lock,unlock}
From: Paul McKenney <[email protected]>
This is needed for a future tracepoint patch that uses srcu, and to make sure it doesn't call into lockdep.
tracepoint code already calls notrace variants for rcu_read_lock_sched so this patch does the same for srcu which will be used in a later patch. Keeps it consistent with rcu-sched.
--- include/linux/srcu.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/linux/srcu.h +17 -0
@@ -195,6 +195,16 @@ static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp)return retval; } +/* Used by tracing, cannot be traced and cannot invoke lockdep. */ +static inline notrace int +srcu_read_lock_notrace (struct srcu_struct *sp)__acquires (sp) +{ +int retval; + + retval =__srcu_read_lock (sp); +return retval; +} +/** * srcu_read_unlock - unregister a old reader from an SRCU-protected structure. * @sp: srcu_struct in which to unregister the old reader.
@@ -209,6 +219,13 @@ static inline void srcu_read_unlock(struct srcu_struct *sp, int idx)__srcu_read_unlock (sp, idx); } +/* Used by tracing, cannot be traced and cannot call lockdep. */ +static inline notrace void +srcu_read_unlock_notrace (struct srcu_struct *sp,int idx)__releases (sp) +{ +__srcu_read_unlock (sp, idx); +} +/** * smp_mb__after_srcu_read_unlock - ensure full ordering after srcu_read_unlock *
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 2/34 srcu: Add notrace variant of srcu_dereference
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
In the last patch in this series, we are making lockdep register hooks onto the irq_{disable,enable} tracepoints. These tracepoints use the _rcuidle tracepoint variant. In this series we switch the _rcuidle tracepoint callers to use SRCU instead of sched-RCU. Inorder to dereference the pointer to the probe functions, we could call srcu_dereference, however this API will call back into lockdep to check if the lock is held *before* the lockdep probe hooks have a chance to run and annotate the IRQ enabled/disabled state.
For this reason we need a notrace variant of srcu_dereference since otherwise we get lockdep splats. This patch adds the needed srcu_dereference_notrace variant.
--- include/linux/srcu.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/srcu.h +5 -0
@@ -169,6 +169,11 @@ static inline int srcu_read_lock_held(const struct srcu_struct *sp)*/ #define srcu_dereference (p, sp) srcu_dereference_check((p), (sp), 0) +/** +* srcu_dereference_notrace - no tracing and no lockdep calls from here +*/ +#define srcu_dereference_notrace (p, sp) srcu_dereference_check((p), (sp), 1) +/** * srcu_read_lock - register a new reader for an SRCU-protected structure. * @sp: srcu_struct in which to register the new reader.
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 3/34 tracing/irqsoff: Split reset into separate functions
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
Split reset functions into seperate functions in preparation of future patches that need to do tracer specific reset.
--- kernel/trace/trace_irqsoff.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
kernel/trace/trace_irqsoff.c +19 -3
@@ -634,7 +634,7 @@ static int __irqsoff_tracer_init(struct trace_array *tr)return 0 ; } -static void irqsoff_tracer_reset (struct trace_array *tr) +static void __irqsoff_tracer_reset (struct trace_array *tr) {int lat_flag = save_flags &TRACE_ITER_LATENCY_FMT ;int overwrite_flag = save_flags &TRACE_ITER_OVERWRITE ;
@@ -665,6 +665,12 @@ static int irqsoff_tracer_init(struct trace_array *tr)return __irqsoff_tracer_init (tr); } + +static void irqsoff_tracer_reset (struct trace_array *tr) +{ +__irqsoff_tracer_reset (tr); +} +static struct tracer irqsoff_tracer__read_mostly = { .name ="irqsoff" ,
@@ -697,11 +703,16 @@ static int preemptoff_tracer_init(struct trace_array *tr)return __irqsoff_tracer_init (tr); } +static void preemptoff_tracer_reset (struct trace_array *tr) +{ +__irqsoff_tracer_reset (tr); +} +static struct tracer preemptoff_tracer__read_mostly = { .name ="preemptoff" , .init = preemptoff_tracer_init, - .reset = irqsoff_tracer_reset, + .reset = preemptoff_tracer_reset, .start = irqsoff_tracer_start, .stop = irqsoff_tracer_stop, .print_max = true,
@@ -731,11 +742,16 @@ static int preemptirqsoff_tracer_init(struct trace_array *tr)return __irqsoff_tracer_init (tr); } +static void preemptirqsoff_tracer_reset (struct trace_array *tr) +{ +__irqsoff_tracer_reset (tr); +} +static struct tracer preemptirqsoff_tracer__read_mostly = { .name ="preemptirqsoff" , .init = preemptirqsoff_tracer_init, - .reset = irqsoff_tracer_reset, + .reset = preemptirqsoff_tracer_reset, .start = irqsoff_tracer_start, .stop = irqsoff_tracer_stop, .print_max = true,
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 4/34 lib: Add module for testing preemptoff/irqsoff latency tracers
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
Here we introduce a test module for introducing a long preempt or irq disable delay in the kernel which the preemptoff or irqsoff tracers can detect. This module is to be used only for test purposes and is default disabled.
Following is the expected output (only briefly shown) that can be parsed to verify that the tracers are working correctly. We will use this from the kselftests in future patches.
For the preemptoff tracer:
echo preemptoff > /d/tracing/current_tracer
sleep 1
insmod ./preemptirq_delay_test.ko test_mode=preempt delay=500000 sleep 1
bash-4.3# cat /d/tracing/trace
preempt -1066 2...2 0us@: preemptirq_delay_run <-preemptirq_delay_run preempt -1066 2...2 500002us : preemptirq_delay_run <-preemptirq_delay_run preempt -1066 2...2 500004us : tracer_preempt_on <-preemptirq_delay_run preempt -1066 2...2 500012us : <stack trace>
=> kthread
=> ret_from_fork
For the irqsoff tracer:
echo irqsoff > /d/tracing/current_tracer
sleep 1
insmod ./preemptirq_delay_test.ko test_mode=irq delay=500000 sleep 1
bash-4.3# cat /d/tracing/trace
irq dis -1069 1d..1 0us@: preemptirq_delay_run irq dis -1069 1d..1 500001us : preemptirq_delay_run irq dis -1069 1d..1 500002us : tracer_hardirqs_on <-preemptirq_delay_run irq dis -1069 1d..1 500005us : <stack trace>
=> ret_from_fork
--- kernel/trace/Kconfig | 15 ++++++ kernel/trace/Makefile | 1 + kernel/trace/preemptirq_delay_test.c | 72 ++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 kernel/trace/preemptirq_delay_test.c
kernel/trace/Kconfig +15 -0
@@ -687,6 +687,21 @@ config RING_BUFFER_STARTUP_TEST If unsure, say N +config PREEMPTIRQ_DELAY_TEST + tristate "Preempt / IRQ disable delay thread to test latency tracers" + depends on m + help + Select this option to build a test module that can help test latency + tracers by executing a preempt or irq disable section with a user + configurable delay. The module busy waits for the duration of the + critical section. + + For example, the following invocation forces a one-time irq-disabled + critical section for 500us: + modprobe preemptirq_delay_test test_mode=irq delay=500000 + + If unsure, say N + config TRACE_EVAL_MAP_FILE bool "Show eval mappings for trace events" depends on TRACING
kernel/trace/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_TRACING) += trace_seq.o obj-$(CONFIG_TRACING) += trace_stat.o obj-$(CONFIG_TRACING) += trace_printk.o obj-$(CONFIG_TRACING_MAP) += tracing_map.o +obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o obj-$(CONFIG_PREEMPTIRQ_EVENTS) += trace_irqsoff.o
kernel/trace/preemptirq_delay_test.c new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 5/34 kselftests: Add tests for the preemptoff and irqsoff tracers
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
Here we add unit tests for the preemptoff and irqsoff tracer by using a kernel module introduced previously to trigger long preempt or irq disabled sections in the kernel.
--- tools/testing/selftests/ftrace/config | 3 + .../test.d/preemptirq/irqsoff_tracer.tc | 73 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc
tools/testing/selftests/ftrace/config +3 -0
@@ -4,3 +4,6 @@ CONFIG_FUNCTION_PROFILER=y CONFIG_TRACER_SNAPSHOT=y CONFIG_STACK_TRACER=y CONFIG_HIST_TRIGGERS=y +CONFIG_PREEMPT_TRACER=y +CONFIG_IRQSOFF_TRACER=y +CONFIG_PREEMPTIRQ_DELAY_TEST=m
tools/testing/selftests/ftrace/test.d/preemptirq/irqsoff_tracer.tc new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 6/34 tracing: Make unregister_trigger() static
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Nothing uses unregister_trigger() outside of trace_events_trigger.c file, thus it should be static. Not sure why this was ever converted, because its counter part, register_trigger(), was always static.
--- kernel/trace/trace.h | 3 --- kernel/trace/trace_events_trigger.c | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-)
kernel/trace/trace.h +0 -3
@@ -1533,9 +1533,6 @@ extern int event_trigger_init(struct event_trigger_ops *ops,extern int trace_event_trigger_enable_disable (struct trace_event_file *file,int trigger_enable);extern void update_cond_flag (struct trace_event_file *file); -extern void unregister_trigger (char *glob,struct event_trigger_ops *ops, -struct event_trigger_data *test, -struct trace_event_file *file);extern int set_trigger_filter (char *filter_str,struct event_trigger_data *trigger_data,struct trace_event_file *file);
kernel/trace/trace_events_trigger.c +3 -3
@@ -579,9 +579,9 @@ static int register_trigger(char *glob, struct event_trigger_ops *ops,* Usually used directly as the @unreg method in event command * implementations. */ -void unregister_trigger (char *glob,struct event_trigger_ops *ops, -struct event_trigger_data *test, -struct trace_event_file *file) +static void unregister_trigger (char *glob,struct event_trigger_ops *ops, +struct event_trigger_data *test, +struct trace_event_file *file) {struct event_trigger_data *data;bool unregistered = false;
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 7/34 tracing: Remove orphaned function using_ftrace_ops_list_func().
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Remove using_ftrace_ops_list_func() since it is no longer used.
Using ftrace_ops_list_func() has been introduced by commit 7eea4fce0246 ("tracing/stack_trace: Skip 4 instead of 3 when using ftrace_ops_list_func") as a helper function, but its caller has been removed by commit 72ac426a5bb0 ("tracing: Clean up stack tracing and fix fentry updates"). So it is not called anymore.
--- kernel/trace/ftrace.c | 5 ----- kernel/trace/trace.h | 1 - 2 files changed, 6 deletions(-)
kernel/trace/ftrace.c +0 -5
@@ -313,11 +313,6 @@ static void update_ftrace_function(void) ftrace_trace_function = func; } -int using_ftrace_ops_list_func (void ) -{ -return ftrace_trace_function == ftrace_ops_list_func; -} -static void add_ftrace_ops (struct ftrace_ops __rcu **list,struct ftrace_ops *ops) {
kernel/trace/trace.h +0 -1
@@ -937,7 +937,6 @@ void ftrace_destroy_function_files(struct trace_array *tr);void ftrace_init_global_array_ops (struct trace_array *tr);void ftrace_init_array_ops (struct trace_array *tr,ftrace_func_t func);void ftrace_reset_array_ops (struct trace_array *tr); -int using_ftrace_ops_list_func (void );void ftrace_init_tracefs (struct trace_array *tr,struct dentry *d_tracer);void ftrace_init_tracefs_toplevel (struct trace_array *tr,struct dentry *d_tracer);
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 8/34 tracing: Remove orphaned function ftrace_nr_registered_ops()
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Remove ftrace_nr_registered_ops() because it is no longer used.
ftrace_nr_registered_ops() has been introduced by commit ea701f11da44 ("ftrace: Add selftest to test function trace recursion protection"), but its caller has been removed by commit 05cbbf643b8e ("tracing: Fix selftest function recursion accounting"). So it is not called anymore.
--- include/linux/ftrace.h | 6 ------ kernel/trace/ftrace.c | 24 ------------------------ 2 files changed, 30 deletions(-)
include/linux/ftrace.h +0 -6
@@ -234,10 +234,6 @@ extern void ftrace_stub(unsigned long a0, unsigned long a1,*/ #define register_ftrace_function (ops) ({ 0; })#define unregister_ftrace_function (ops) ({ 0; }) -static inline int ftrace_nr_registered_ops (void ) -{ -return 0 ; -}static inline void ftrace_kill (void ) { }static inline void ftrace_free_init_mem (void ) { }static inline void ftrace_free_mem (struct module *mod,void *start,void *end) { }
@@ -328,8 +324,6 @@ struct seq_file;extern int ftrace_text_reserved (const void *start,const void *end); -extern int ftrace_nr_registered_ops (void ); -struct ftrace_ops *ftrace_ops_trampoline (unsigned long addr);bool is_ftrace_trampoline (unsigned long addr);
kernel/trace/ftrace.c +0 -24
@@ -157,30 +157,6 @@ static inline void ftrace_ops_init(struct ftrace_ops *ops)#endif } -/** -* ftrace_nr_registered_ops - return number of ops registered -* -* Returns the number of ftrace_ops registered and tracing functions -*/ -int ftrace_nr_registered_ops (void ) -{ -struct ftrace_ops *ops; -int cnt =0 ; - -mutex_lock (&ftrace_lock); - -for (ops =rcu_dereference_protected (ftrace_ops_list, -lockdep_is_held (&ftrace_lock)); - ops != &ftrace_list_end; - ops =rcu_dereference_protected (ops->next, -lockdep_is_held (&ftrace_lock))) - cnt++; - -mutex_unlock (&ftrace_lock); - -return cnt; -} -static void ftrace_pid_func (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct pt_regs *regs) {
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 9/34 tracing/kprobes: Simplify the logic of enable_trace_kprobe()
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.
--- kernel/trace/trace_kprobe.c | 42 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-)
kernel/trace/trace_kprobe.c +24 -18
@@ -393,6 +393,20 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,return NULL ; } +static inline int __enable_trace_kprobe (struct trace_kprobe *tk) +{ +int ret =0 ; + +if (trace_probe_is_registered (&tk->tp) && !trace_kprobe_has_gone (tk)) { +if (trace_kprobe_is_return (tk)) + ret =enable_kretprobe (&tk->rp); +else + ret =enable_kprobe (&tk->rp.kp); + } + +return ret; +} +/* * Enable trace_probe * if the file is NULL, enable "perf" handler, or enable "trace" handler.
@@ -400,7 +414,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,static int enable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { -struct event_file_link *link =NULL ; +struct event_file_link *link;int ret =0 ;if (file) {
@@ -414,26 +428,18 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)list_add_tail_rcu (&link->list, &tk->tp.files); tk->tp.flags |=TP_FLAG_TRACE ; - }else - tk->tp.flags |=TP_FLAG_PROFILE ; - -if (trace_probe_is_registered (&tk->tp) && !trace_kprobe_has_gone (tk)) { -if (trace_kprobe_is_return (tk)) - ret =enable_kretprobe (&tk->rp); -else - ret =enable_kprobe (&tk->rp.kp); - } - -if (ret) { -if (file) { -/* Notice the if is true on not WARN() */ -if (!WARN_ON_ONCE (!link)) -list_del_rcu (&link->list); + ret =__enable_trace_kprobe (tk); +if (ret) { +list_del_rcu (&link->list);kfree (link); tk->tp.flags &= ~TP_FLAG_TRACE ; - }else { - tk->tp.flags &= ~TP_FLAG_PROFILE ; } + + }else { + tk->tp.flags |=TP_FLAG_PROFILE ; + ret =__enable_trace_kprobe (tk); +if (ret) + tk->tp.flags &= ~TP_FLAG_PROFILE ; } out:return ret;
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 10/34 tracing: preemptirq_delay_run() can be static
In reply to Steven RostedtFrom: kbuild test robot <[email protected]>
Automatically found by kbuild test robot.
--- kernel/trace/preemptirq_delay_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/preemptirq_delay_test.c +1 -1
@@ -34,7 +34,7 @@ static void busy_wait(ulong time) }while (ktime_to_ns (ktime_sub (end, start)) < (time *1000 )); } -int preemptirq_delay_run (void *data) +static int preemptirq_delay_run (void *data) {unsigned long flags;
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 11/34 tracing: kprobes: Prohibit probing on notrace function
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Prohibit kprobe-events probing on notrace functions. Since probing on a notrace function can cause a recursive event call. In most cases those are just skipped, but in some cases it falls into an infinite recursive call.
This protection can be disabled by the kconfig CONFIG_KPROBE_EVENTS_ON_NOTRACE=y, but it is highly recommended to keep it "n" for normal kernel builds. Note that this is only available if "kprobes on ftrace" has been implemented on the target arch and CONFIG_KPROBES_ON_FTRACE=y.
--- kernel/trace/Kconfig | 20 ++++++++++++++++ kernel/trace/trace_kprobe.c | 47 ++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 9 deletions(-)
kernel/trace/Kconfig +20 -0
@@ -456,6 +456,26 @@ config KPROBE_EVENTS This option is also required by perf-probe subcommand of perf tools. If you want to use perf tools, this option is strongly recommended. +config KPROBE_EVENTS_ON_NOTRACE + bool "Do NOT protect notrace function from kprobe events" + depends on KPROBE_EVENTS + depends on KPROBES_ON_FTRACE + default n + help + This is only for the developers who want to debug ftrace itself + using kprobe events. + + If kprobes can use ftrace instead of breakpoint, ftrace related + functions are protected from kprobe-events to prevent an infinit + recursion or any unexpected execution path which leads to a kernel + crash. + + This option disables such protection and allows you to put kprobe + events on ftrace functions for debugging ftrace by itself. + Note that this might let you shoot yourself in the foot. + + If unsure, say N. + config UPROBE_EVENTS bool "Enable uprobes-based dynamic events" depends on ARCH_SUPPORTS_UPROBES
kernel/trace/trace_kprobe.c +38 -9
72 lines not on this page · raw message
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 12/34 selftest/ftrace: Move kprobe selftest function to separate compile unit
In reply to Steven RostedtFrom: Francis Deslauriers <[email protected]>
Move selftest function to its own compile unit so it can be compiled with the ftrace cflags (CC_FLAGS_FTRACE) allowing it to be probed during the ftrace startup tests.
--- kernel/trace/Makefile | 5 +++++ kernel/trace/trace_kprobe.c | 12 +----------- kernel/trace/trace_kprobe_selftest.c | 10 ++++++++++ kernel/trace/trace_kprobe_selftest.h | 7 +++++++ 4 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 kernel/trace/trace_kprobe_selftest.c create mode 100644 kernel/trace/trace_kprobe_selftest.h
kernel/trace/Makefile +5 -0
@@ -13,6 +13,11 @@ obj-y += trace_selftest_dynamic.o endif endif +ifdef CONFIG_FTRACE_STARTUP_TEST +CFLAGS_trace_kprobe_selftest.o = $(CC_FLAGS_FTRACE) +obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe_selftest.o +endif + # If unlikely tracing is enabled, do not trace these files ifdef CONFIG_TRACING_BRANCHES KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
kernel/trace/trace_kprobe.c +1 -11
@@ -23,6 +23,7 @@#include <linux/rculist.h> #include <linux/error-injection.h> +#include "trace_kprobe_selftest.h" #include "trace_probe.h" #define KPROBE_EVENT_SYSTEM "kprobes"
@@ -1587,17 +1588,6 @@ fs_initcall(init_kprobe_trace);#ifdef CONFIG_FTRACE_STARTUP_TEST -/* -* The "__used" keeps gcc from removing the function symbol -* from the kallsyms table. 'noinline' makes sure that there -* isn't an inlined version used by the test method below -*/ -static __used __init noinline int -kprobe_trace_selftest_target (int a1,int a2,int a3,int a4,int a5,int a6) -{ -return a1 + a2 + a3 + a4 + a5 + a6; -} -static __init struct trace_event_file *find_trace_probe_file (struct trace_kprobe *tk,struct trace_array *tr) {
kernel/trace/trace_kprobe_selftest.c new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Function used during the kprobe self test. This function is in a separate +* compile unit so it can be compile with CC_FLAGS_FTRACE to ensure that it +* can be probed by the selftests. +*/ +int kprobe_trace_selftest_target (int a1,int a2,int a3,int a4,int a5,int a6) +{ +return a1 + a2 + a3 + a4 + a5 + a6; +}
kernel/trace/trace_kprobe_selftest.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Function used during the kprobe self test. This function is in a separate +* compile unit so it can be compile with CC_FLAGS_FTRACE to ensure that it +* can be probed by the selftests. +*/ +int kprobe_trace_selftest_target (int a1,int a2,int a3,int a4,int a5,int a6);
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 13/34 selftests/ftrace: Fix kprobe string testcase to not probe notrace function
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Fix kprobe string argument testcase to not probe notrace function. Instead, it probes tracefs function which must be available with ftrace.
--- .../test.d/kprobe/kprobe_args_string.tc | 30 ++++++++----------- .../ftrace/test.d/kprobe/probepoint.tc | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc +12 -18
@@ -9,28 +9,22 @@ echo > kprobe_events case `uname -m` in x86_64) - ARG2=%si - OFFS=8 + ARG1=%di ;; i[3456]86) - ARG2=%cx - OFFS=4 + ARG1=%ax ;; aarch64) - ARG2=%x1 - OFFS=8 + ARG1=%x0 ;; arm*) - ARG2=%r1 - OFFS=4 + ARG1=%r0 ;; ppc64*) - ARG2=%r4 - OFFS=8 + ARG1=%r3 ;; ppc*) - ARG2=%r4 - OFFS=4 + ARG1=%r3 ;; *) echo "Please implement other architecture here"
@@ -38,17 +32,17 @@ ppc*) esac : "Test get argument (1)" -echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events +echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events echo 1 > events/kprobes/testprobe/enable -! echo test >> kprobe_events -tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\"" +echo "p:test _do_fork" >> kprobe_events +grep -qe "testprobe.* arg1=\"test\"" trace echo 0 > events/kprobes/testprobe/enable : "Test get argument (2)" -echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events +echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events echo 1 > events/kprobes/testprobe/enable -! echo test1 test2 >> kprobe_events -tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\"" +echo "p:test _do_fork" >> kprobe_events +grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace echo 0 > events/enable echo > kprobe_events
tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc +1 -1
@@ -4,7 +4,7 @@ [ -f kprobe_events ] || exit_unsupported # this is configurable -TARGET_FUNC=create_trace_kprobe +TARGET_FUNC=tracefs_create_dir dec_addr() { # hexaddr printf "%d" "0x"`echo $1 | tail -c 8`
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 14/34 lockdep: Use this_cpu_ptr instead of get_cpu_var stats
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
get_cpu_var disables preemption which has the potential to call into the preemption disable trace points causing some complications. There's also no need to disable preemption in uses of get_lock_stats anyway since preempt is already disabled. So lets simplify the code.
--- kernel/locking/lockdep.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
kernel/locking/lockdep.c +1 -9
@@ -248,12 +248,7 @@ void clear_lock_stats(struct lock_class *class)static struct lock_class_stats *get_lock_stats (struct lock_class *class) { -return &get_cpu_var (cpu_lock_stats)[class - lock_classes]; -} - -static void put_lock_stats (struct lock_class_stats *stats) -{ -put_cpu_var (cpu_lock_stats); +return &this_cpu_ptr (cpu_lock_stats)[class - lock_classes]; }static void lock_release_holdtime (struct held_lock *hlock)
@@ -271,7 +266,6 @@ static void lock_release_holdtime(struct held_lock *hlock)lock_time_inc (&stats->read_holdtime, holdtime); else lock_time_inc(&stats->write_holdtime, holdtime); - put_lock_stats(stats); }#else static inline void lock_release_holdtime (struct held_lock *hlock)
@@ -4090,7 +4084,6 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) stats->contending_point[contending_point]++;if (lock->cpu !=smp_processor_id ()) stats->bounces[bounce_contended + !!hlock->read]++; -put_lock_stats (stats); } static void
@@ -4138,7 +4131,6 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) }if (lock->cpu != cpu) stats->bounces[bounce_acquired + !!hlock->read]++; -put_lock_stats (stats); lock->cpu = cpu; lock->ip = ip;
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 15/34 tracepoint: Make rcuidle tracepoint callers use SRCU
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
In recent tests with IRQ on/off tracepoints, a large performance overhead ~10% is noticed when running hackbench. This is root caused to calls to rcu_irq_enter_irqson and rcu_irq_exit_irqson from the tracepoint code. Following a long discussion on the list [1] about this, we concluded that srcu is a better alternative for use during rcu idle. Although it does involve extra barriers, its lighter than the sched-rcu version which has to do additional RCU calls to notify RCU idle about entry into RCU sections.
In this patch, we change the underlying implementation of the trace_*_rcuidle API to use SRCU. This has shown to improve performance alot for the high frequency irq enable/disable tracepoints.
Test: Tested idle and preempt/irq tracepoints.
Here are some performance numbers:
With a run of the following 30 times on a single core x86 Qemu instance with 1GB memory:
hackbench -g 4 -f 2 -l 3000
Completion times in seconds. CONFIG_PROVE_LOCKING=y.
No patches (without this series)
Mean: 3.048
Median: 3.025
Std Dev: 0.064
With Lockdep using irq tracepoints with RCU implementation:
Mean: 3.451 (-11.66 %)
Median: 3.447 (-12.22%)
Std Dev: 0.049
With Lockdep using irq tracepoints with SRCU implementation (this series):
Mean: 3.020 (I would consider the improvement against the "without
this series" case as just noise).
Median: 3.013
Std Dev: 0.033
[1] https://patchwork.kernel.org/patch/10344297/
[remove rcu_read_lock_sched_notrace as its the equivalent of preempt_disable_notrace and is unnecessary to call in tracepoint code]
--- include/linux/tracepoint.h | 40 ++++++++++++++++++++++++++++++-------- kernel/tracepoint.c | 16 ++++++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-)
include/linux/tracepoint.h +32 -8
@@ -15,6 +15,7 @@*/ #include <linux/smp.h> +#include <linux/srcu.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/cpumask.h>
@@ -33,6 +34,8 @@ struct trace_eval_map {#define TRACEPOINT_DEFAULT_PRIO 10 +extern struct srcu_struct tracepoint_srcu; +extern int tracepoint_probe_register (struct tracepoint *tp,void *probe,void *data); extern int
@@ -75,10 +78,16 @@ int unregister_tracepoint_module_notifier(struct notifier_block *nb)* probe unregistration and the end of module exit to make sure there is no * caller executing a probe when it is freed. */ +#ifdef CONFIG_TRACEPOINTS static inline void tracepoint_synchronize_unregister (void ) { +synchronize_srcu (&tracepoint_srcu);synchronize_sched (); } +#else +static inline void tracepoint_synchronize_unregister (void ) +{ } +#endif #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS extern int syscall_regfunc (void );
@@ -129,18 +138,31 @@ extern void syscall_unregfunc(void);* as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just * "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto". */ -#define __DO_TRACE (tp, proto, args, cond, rcucheck) \ +#define __DO_TRACE (tp, proto, args, cond, rcuidle) \ do { \ struct tracepoint_func *it_func_ptr; \ void *it_func; \ void *__data; \ + int __maybe_unused idx = 0; \ \ if (!(cond)) \ return; \ - if (rcucheck) \ - rcu_irq_enter_irqson(); \ - rcu_read_lock_sched_notrace(); \ - it_func_ptr = rcu_dereference_sched((tp)->funcs); \ + \ +/* srcu can't be used from NMI */ \ +WARN_ON_ONCE (rcuidle &&in_nmi ()); \ + \ +/* keep srcu and sched-rcu usage consistent */ \ +preempt_disable_notrace (); \ + \ +/* \ +* For rcuidle callers, use srcu since sched-rcu \ +* doesn't work from the idle path. \ +*/ \ +if (rcuidle) \ + idx =srcu_read_lock_notrace (&tracepoint_srcu); \ + \ + it_func_ptr =rcu_dereference_raw ((tp)->funcs); \ + \if (it_func_ptr) { \ do { \ it_func = (it_func_ptr)->func; \
@@ -148,9 +170,11 @@ extern void syscall_unregfunc(void); ((void (*)(proto ))(it_func))(args); \ }while ((++it_func_ptr)->func); \ } \ -rcu_read_unlock_sched_notrace (); \ -if (rcucheck) \ -rcu_irq_exit_irqson (); \ + \ +if (rcuidle) \ +srcu_read_unlock_notrace (&tracepoint_srcu, idx);\ + \ +preempt_enable_notrace (); \ }while (0 ) #ifndef MODULE
kernel/tracepoint.c +15 -1
@@ -31,6 +31,9 @@extern struct tracepoint *const __start___tracepoints_ptrs[];extern struct tracepoint *const __stop___tracepoints_ptrs[]; +DEFINE_SRCU (tracepoint_srcu); +EXPORT_SYMBOL_GPL (tracepoint_srcu); +/* Set to 1 to enable tracepoint debug output */ static const int tracepoint_debug;
@@ -67,16 +70,27 @@ static inline void *allocate_probes(int count)return p ==NULL ?NULL : p->probes; } -static void rcu_free_old_probes (struct rcu_head *head) +static void srcu_free_old_probes (struct rcu_head *head) {kfree (container_of(head ,struct tp_probes ,rcu )); } +static void rcu_free_old_probes (struct rcu_head *head) +{ +call_srcu (&tracepoint_srcu, head, srcu_free_old_probes); +} +static inline void release_probes (struct tracepoint_func *old) {if (old) {struct tp_probes *tp_probes =container_of (old, struct tp_probes, probes[0]); +/* +* Tracepoint probes are protected by both sched RCU and SRCU, +* by calling the SRCU callback in the sched RCU callback we +* cover both cases. So let us chain the SRCU and sched RCU +* callbacks to wait for both grace periods. +*/ call_rcu_sched (&tp_probes->rcu, rcu_free_old_probes); } }
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 16/34 tracing: Centralize preemptirq tracepoints and unify their usage
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
This patch detaches the preemptirq tracepoints from the tracers and keeps it separate.
Advantages:
* Lockdep and irqsoff event can now run in parallel since they no longer have their own calls.
* This unifies the usecase of adding hooks to an irqsoff and irqson event, and a preemptoff and preempton event.
3 users of the events exist:
- Lockdep
- irqsoff and preemptoff tracers
- irqs and preempt trace events
The unification cleans up several ifdefs and makes the code in preempt tracer and irqsoff tracers simpler. It gets rid of all the horrific ifdeferry around PROVE_LOCKING and makes configuration of the different users of the tracepoints more easy and understandable. It also gets rid of the time_* function calls from the lockdep hooks used to call into the preemptirq tracer which is not needed anymore. The negative delta in lines of code in this patch is quite large too.
In the patch we introduce a new CONFIG option PREEMPTIRQ_TRACEPOINTS as a single point for registering probes onto the tracepoints. With this,
the web of config options for preempt/irq toggle tracepoints and its users becomes:
PREEMPT_TRACER PREEMPTIRQ_EVENTS IRQSOFF_TRACER PROVE_LOCKING
| | \ | |
\ (selects) / \ \ (selects) /
TRACE_PREEMPT_TOGGLE ----> TRACE_IRQFLAGS
\ /
\ (depends on) / PREEMPTIRQ_TRACEPOINTS
Other than the performance tests mentioned in the previous patch, I also ran the locking API test suite. I verified that all tests cases are passing.
I also injected issues by not registering lockdep probes onto the tracepoints and I see failures to confirm that the probes are indeed working.
This series + lockdep probes not registered (just to inject errors):
[ 0.000000] hard-irqs-on + irq-safe-A/21: ok | ok | ok | [ 0.000000] soft-irqs-on + irq-safe-A/21: ok | ok | ok | [ 0.000000] sirq-safe-A => hirqs-on/12:FAILED|FAILED| ok | [ 0.000000] sirq-safe-A => hirqs-on/21:FAILED|FAILED| ok | [ 0.000000] hard-safe-A + irqs-on/12:FAILED|FAILED| ok | [ 0.000000] soft-safe-A + irqs-on/12:FAILED|FAILED| ok | [ 0.000000] hard-safe-A + irqs-on/21:FAILED|FAILED| ok | [ 0.000000] soft-safe-A + irqs-on/21:FAILED|FAILED| ok | [ 0.000000] hard-safe-A + unsafe-B #1/123: ok | ok | ok | [ 0.000000] soft-safe-A + unsafe-B #1/123: ok | ok | ok |
With this series + lockdep probes registered, all locking tests pass:
[ 0.000000] hard-irqs-on + irq-safe-A/21: ok | ok | ok | [ 0.000000] soft-irqs-on + irq-safe-A/21: ok | ok | ok | [ 0.000000] sirq-safe-A => hirqs-on/12: ok | ok | ok | [ 0.000000] sirq-safe-A => hirqs-on/21: ok | ok | ok | [ 0.000000] hard-safe-A + irqs-on/12: ok | ok | ok | [ 0.000000] soft-safe-A + irqs-on/12: ok | ok | ok | [ 0.000000] hard-safe-A + irqs-on/21: ok | ok | ok | [ 0.000000] soft-safe-A + irqs-on/21: ok | ok | ok | [ 0.000000] hard-safe-A + unsafe-B #1/123: ok | ok | ok | [ 0.000000] soft-safe-A + unsafe-B #1/123: ok | ok | ok |
--- include/linux/ftrace.h | 11 +- include/linux/irqflags.h | 11 +- include/linux/lockdep.h | 8 +- include/linux/preempt.h | 2 +- include/trace/events/preemptirq.h | 23 +-- init/main.c | 5 +- kernel/locking/lockdep.c | 35 ++--- kernel/sched/core.c | 2 +- kernel/trace/Kconfig | 22 ++- kernel/trace/Makefile | 2 +- kernel/trace/trace_irqsoff.c | 231 ++++++++---------------------- kernel/trace/trace_preemptirq.c | 72 ++++++++++ 12 files changed, 195 insertions(+), 229 deletions(-) create mode 100644 kernel/trace/trace_preemptirq.c
include/linux/ftrace.h +1 -10
@@ -701,16 +701,7 @@ static inline unsigned long get_lock_parent_ip(void)return CALLER_ADDR2 ; } -#ifdef CONFIG_IRQSOFF_TRACER -extern void time_hardirqs_on (unsigned long a0,unsigned long a1); -extern void time_hardirqs_off (unsigned long a0,unsigned long a1); -#else -static inline void time_hardirqs_on (unsigned long a0,unsigned long a1) { } -static inline void time_hardirqs_off (unsigned long a0,unsigned long a1) { } -#endif - -#if defined(CONFIG_PREEMPT_TRACER ) || \ - (defined(CONFIG_DEBUG_PREEMPT ) && defined(CONFIG_PREEMPTIRQ_EVENTS )) +#ifdef CONFIG_TRACE_PREEMPT_TOGGLE extern void trace_preempt_on (unsigned long a0,unsigned long a1);extern void trace_preempt_off (unsigned long a0,unsigned long a1);#else
include/linux/irqflags.h +8 -3
@@ -15,9 +15,16 @@#include <linux/typecheck.h> #include <asm/irqflags.h> -#ifdef CONFIG_TRACE_IRQFLAGS +/* Currently trace_softirqs_on/off is used only by lockdep */ +#ifdef CONFIG_PROVE_LOCKING extern void trace_softirqs_on (unsigned long ip);extern void trace_softirqs_off (unsigned long ip); +#else +# define trace_softirqs_on (ip) do { } while (0) +# define trace_softirqs_off (ip) do { } while (0) +#endif + +#ifdef CONFIG_TRACE_IRQFLAGS extern void trace_hardirqs_on (void );extern void trace_hardirqs_off (void );# define trace_hardirq_context (p) ((p)->hardirq_context)
@@ -43,8 +50,6 @@ do { \#else # define trace_hardirqs_on () do { } while (0)# define trace_hardirqs_off () do { } while (0) -# define trace_softirqs_on (ip) do { } while (0) -# define trace_softirqs_off (ip) do { } while (0)# define trace_hardirq_context (p) 0# define trace_softirq_context (p) 0# define trace_hardirqs_enabled (p) 0
include/linux/lockdep.h +5 -3
@@ -266,7 +266,8 @@ struct held_lock {/* * Initialization, self-test and debugging-output methods: */ -extern void lockdep_info (void ); +extern void lockdep_init (void ); +extern void lockdep_init_early (void );extern void lockdep_reset (void );extern void lockdep_reset_lock (struct lockdep_map *lock);extern void lockdep_free_key_range (void *start,unsigned long size);
@@ -406,7 +407,8 @@ static inline void lockdep_on(void)# define lock_downgrade (l, i) do { } while (0)# define lock_set_class (l, n, k, s, i) do { } while (0)# define lock_set_subclass (l, s, i) do { } while (0) -# define lockdep_info () do { } while (0) +# define lockdep_init () do { } while (0) +# define lockdep_init_early () do { } while (0)# define lockdep_init_map (lock, name, key, sub) \ do { (void)(name); (void)(key); } while (0)# define lockdep_set_class (lock, key) do { (void)(key); } while (0)
@@ -532,7 +534,7 @@ do { \#endif /* CONFIG_LOCKDEP */ -#ifdef CONFIG_TRACE_IRQFLAGS +#ifdef CONFIG_PROVE_LOCKING extern void print_irqtrace_events (struct task_struct *curr);#else static inline void print_irqtrace_events (struct task_struct *curr)
include/linux/preempt.h +1 -1
@@ -150,7 +150,7 @@*/ #define in_atomic_preempt_off () (preempt_count() != PREEMPT_DISABLE_OFFSET) -#if defined(CONFIG_DEBUG_PREEMPT ) || defined(CONFIG_PREEMPT_TRACER ) +#if defined(CONFIG_DEBUG_PREEMPT ) || defined(CONFIG_TRACE_PREEMPT_TOGGLE )extern void preempt_count_add (int val);extern void preempt_count_sub (int val);#define preempt_count_dec_and_test () \
include/trace/events/preemptirq.h +14 -9
@@ -1,4 +1,4 @@ -#ifdef CONFIG_PREEMPTIRQ_EVENTS +#ifdef CONFIG_PREEMPTIRQ_TRACEPOINTS #undef TRACE_SYSTEM#define TRACE_SYSTEM preemptirq
@@ -32,7 +32,7 @@ DECLARE_EVENT_CLASS(preemptirq_template, (void *)((unsigned long)(_stext) + __entry->parent_offs)) ); -#ifndef CONFIG_PROVE_LOCKING +#ifdef CONFIG_TRACE_IRQFLAGS DEFINE_EVENT (preemptirq_template, irq_disable, TP_PROTO(unsigned long ip, unsigned long parent_ip),TP_ARGS (ip, parent_ip));
@@ -40,9 +40,14 @@ DEFINE_EVENT(preemptirq_template, irq_disable,DEFINE_EVENT (preemptirq_template, irq_enable, TP_PROTO(unsigned long ip, unsigned long parent_ip),TP_ARGS (ip, parent_ip)); +#else +#define trace_irq_enable (...) +#define trace_irq_disable (...) +#define trace_irq_enable_rcuidle (...) +#define trace_irq_disable_rcuidle (...)#endif -#ifdef CONFIG_DEBUG_PREEMPT +#ifdef CONFIG_TRACE_PREEMPT_TOGGLE DEFINE_EVENT (preemptirq_template, preempt_disable, TP_PROTO(unsigned long ip, unsigned long parent_ip),TP_ARGS (ip, parent_ip));
@@ -50,22 +55,22 @@ DEFINE_EVENT(preemptirq_template, preempt_disable,DEFINE_EVENT (preemptirq_template, preempt_enable, TP_PROTO(unsigned long ip, unsigned long parent_ip),TP_ARGS (ip, parent_ip)); +#else +#define trace_preempt_enable (...) +#define trace_preempt_disable (...) +#define trace_preempt_enable_rcuidle (...) +#define trace_preempt_disable_rcuidle (...)#endif #endif /* _TRACE_PREEMPTIRQ_H */ #include <trace/define_trace.h> -#endif /* !CONFIG_PREEMPTIRQ_EVENTS */ - -#if !defined(CONFIG_PREEMPTIRQ_EVENTS ) || defined(CONFIG_PROVE_LOCKING ) +#else /* !CONFIG_PREEMPTIRQ_TRACEPOINTS */ #define trace_irq_enable (...)#define trace_irq_disable (...)#define trace_irq_enable_rcuidle (...)#define trace_irq_disable_rcuidle (...) -#endif - -#if !defined(CONFIG_PREEMPTIRQ_EVENTS ) || !defined(CONFIG_DEBUG_PREEMPT )#define trace_preempt_enable (...)#define trace_preempt_disable (...)#define trace_preempt_enable_rcuidle (...)
init/main.c +4 -1
@@ -648,6 +648,9 @@ asmlinkage __visible void __init start_kernel(void)profile_init ();call_function_init ();WARN (!irqs_disabled (),"Interrupts were enabled early\n" ); + +lockdep_init_early (); + early_boot_irqs_disabled = false;local_irq_enable ();
@@ -663,7 +666,7 @@ asmlinkage __visible void __init start_kernel(void)panic ("Too many boot %s vars at `%s'" , panic_later, panic_param); -lockdep_info (); +lockdep_init ();/* * Need to run this when irqs are enabled, because it wants
kernel/locking/lockdep.c +14 -21
@@ -55,6 +55,7 @@#include "lockdep_internals.h" +#include <trace/events/preemptirq.h> #define CREATE_TRACE_POINTS #include <trace/events/lock.h>
@@ -2839,10 +2840,9 @@ static void __trace_hardirqs_on_caller(unsigned long ip)debug_atomic_inc (hardirqs_on_events); } -__visible void trace_hardirqs_on_caller(unsigned long ip) +static void lockdep_hardirqs_on (void *none,unsigned long ignore, +unsigned long ip) { -time_hardirqs_on (CALLER_ADDR0 , ip); -if (unlikely (!debug_locks || current->lockdep_recursion))return ;
@@ -2881,23 +2881,15 @@ __visible void trace_hardirqs_on_caller(unsigned long ip)__trace_hardirqs_on_caller (ip); current->lockdep_recursion =0 ; } -EXPORT_SYMBOL (trace_hardirqs_on_caller); - -void trace_hardirqs_on (void ) -{ -trace_hardirqs_on_caller (CALLER_ADDR0 ); -} -EXPORT_SYMBOL (trace_hardirqs_on);/* * Hardirqs were disabled: */ -__visible void trace_hardirqs_off_caller(unsigned long ip) +static void lockdep_hardirqs_off (void *none,unsigned long ignore, +unsigned long ip) {struct task_struct *curr = current; -time_hardirqs_off (CALLER_ADDR0 , ip); -if (unlikely (!debug_locks || current->lockdep_recursion))return ;
@@ -2919,13 +2911,6 @@ __visible void trace_hardirqs_off_caller(unsigned long ip) }else debug_atomic_inc (redundant_hardirqs_off); } -EXPORT_SYMBOL (trace_hardirqs_off_caller); - -void trace_hardirqs_off (void ) -{ -trace_hardirqs_off_caller (CALLER_ADDR0 ); -} -EXPORT_SYMBOL (trace_hardirqs_off);/* * Softirqs will be enabled:
@@ -4330,7 +4315,15 @@ void lockdep_reset_lock(struct lockdep_map *lock)raw_local_irq_restore (flags); } -void __init lockdep_info (void ) +void __init lockdep_init_early (void ) +{ +#ifdef CONFIG_PROVE_LOCKING +register_trace_prio_irq_disable (lockdep_hardirqs_off,NULL ,INT_MAX ); +register_trace_prio_irq_enable (lockdep_hardirqs_on,NULL ,INT_MIN ); +#endif +} + +void __init lockdep_init (void ) {printk ("Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar\n" );
kernel/sched/core.c +1 -1
@@ -3189,7 +3189,7 @@ static inline void sched_tick_stop(int cpu) { }#endif #if defined(CONFIG_PREEMPT ) && (defined(CONFIG_DEBUG_PREEMPT ) || \ - defined(CONFIG_PREEMPT_TRACER )) + defined(CONFIG_TRACE_PREEMPT_TOGGLE ))/* * If the value passed in is equal to the current preempt count * then we just disabled preemption. Start timing the latency.
kernel/trace/Kconfig +17 -5
@@ -82,6 +82,15 @@ config RING_BUFFER_ALLOW_SWAP Allow the use of ring_buffer_swap_cpu. Adds a very slight overhead to tracing when enabled. +config PREEMPTIRQ_TRACEPOINTS + bool + depends on TRACE_PREEMPT_TOGGLE || TRACE_IRQFLAGS + select TRACING + default y + help + Create preempt/irq toggle tracepoints if needed, so that other parts + of the kernel can use them to generate or add hooks to them. + # All tracer options should select GENERIC_TRACER. For those options that are # enabled by all tracers (context switch and event tracer) they select TRACING. # This allows those options to appear when no other tracer is selected. But the
@@ -155,18 +164,20 @@ config FUNCTION_GRAPH_TRACER the return value. This is done by setting the current return address on the current task structure into a stack of calls. +config TRACE_PREEMPT_TOGGLE + bool + help + Enables hooks which will be called when preemption is first disabled, + and last enabled. config PREEMPTIRQ_EVENTS bool "Enable trace events for preempt and irq disable/enable" select TRACE_IRQFLAGS - depends on DEBUG_PREEMPT || !PROVE_LOCKING - depends on TRACING + select TRACE_PREEMPT_TOGGLE if PREEMPT + select GENERIC_TRACER default n help Enable tracing of disable and enable events for preemption and irqs. - For tracing preempt disable/enable events, DEBUG_PREEMPT must be - enabled. For tracing irq disable/enable events, PROVE_LOCKING must - be disabled. config IRQSOFF_TRACER bool "Interrupts-off Latency Tracer"
@@ -203,6 +214,7 @@ config PREEMPT_TRACER select RING_BUFFER_ALLOW_SWAP select TRACER_SNAPSHOT select TRACER_SNAPSHOT_PER_CPU_SWAP + select TRACE_PREEMPT_TOGGLE help This option measures the time spent in preemption-off critical sections, with microsecond accuracy.
kernel/trace/Makefile +1 -1
@@ -41,7 +41,7 @@ obj-$(CONFIG_TRACING_MAP) += tracing_map.o obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o -obj-$(CONFIG_PREEMPTIRQ_EVENTS) += trace_irqsoff.o +obj-$(CONFIG_PREEMPTIRQ_TRACEPOINTS) += trace_preemptirq.o obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
kernel/trace/trace_irqsoff.c +57 -174
304 lines not on this page · raw message
kernel/trace/trace_preemptirq.c new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 17/34 tracefs: Annotate tracefs_ops with __ro_after_init
In reply to Steven RostedtFrom: Zubin Mithra <[email protected]>
tracefs_ops is initialized inside tracefs_create_instance_dir and not modified after. tracefs_create_instance_dir allows for initialization only once, and is called from create_trace_instances(marked __init), which is called from tracer_init_tracefs(marked __init). Also, mark tracefs_create_instance_dir as __init.
--- fs/tracefs/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/tracefs/inode.c +3 -2
@@ -53,7 +53,7 @@ static const struct file_operations tracefs_file_operations = {static struct tracefs_dir_ops {int (*mkdir)(const char *name);int (*rmdir)(const char *name); -} tracefs_ops; +} tracefs_ops__ro_after_init ;static char *get_dname (struct dentry *dentry) {
@@ -478,7 +478,8 @@ struct dentry *tracefs_create_dir(const char *name, struct dentry *parent)* * Returns the dentry of the instances directory. */ -struct dentry *tracefs_create_instance_dir (const char *name,struct dentry *parent, +__init struct dentry *tracefs_create_instance_dir (const char *name, +struct dentry *parent,int (*mkdir)(const char *name),int (*rmdir)(const char *name)) {
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 18/34 tracing: Do not call start/stop() functions when tracing_on does not change
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Currently, when one echo's in 1 into tracing_on, the current tracer's "start()" function is executed, even if tracing_on was already one. This can lead to strange side effects. One being that if the hwlat tracer is enabled, and someone does "echo 1 > tracing_on" into tracing_on, the hwlat tracer's start() function is called again which will recreate another kernel thread, and make it unable to remove the old one.
--- kernel/trace/trace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace.c +3 -1
@@ -7628,7 +7628,9 @@ rb_simple_write(struct file *filp, const char __user *ubuf,if (buffer) {mutex_lock (&trace_types_lock); -if (val) { +if (!!val ==tracer_tracing_is_on (tr)) { + val =0 ;/* do nothing */ + }else if (val) {tracer_tracing_on (tr);if (tr->current_trace->start) tr->current_trace->start (tr);
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 19/34 ftrace: Add missing check for existing hwlat thread
In reply to Steven RostedtFrom: Erica Bugden <[email protected]>
The hwlat tracer uses a kernel thread to measure latencies. The function that creates this kernel thread, start_kthread(), can be called when the tracer is initialized and when the tracer is explicitly enabled. start_kthread() does not check if there is an existing hwlat kernel thread and will create a new one each time it is called.
This causes the reference to the previous thread to be lost. Without the thread reference, the old kernel thread becomes unstoppable and continues to use CPU time even after the hwlat tracer has been disabled. This problem can be observed when a system is booted with tracing enabled and the hwlat tracer is configured like this:
echo hwlat > current_tracer; echo 1 > tracing_on
Add the missing check for an existing kernel thread in start_kthread() to prevent this problem. This function and the rest of the hwlat kernel thread setup and teardown are already serialized because they are called through the tracer core code with trace_type_lock held.
[
Note, this only fixes the symptom. The real fix was not to call this function when tracing_on was already one. But this still makes the code more robust, so we'll add it.
]
--- kernel/trace/trace_hwlat.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_hwlat.c +3 -0
@@ -354,6 +354,9 @@ static int start_kthread(struct trace_array *tr)struct task_struct *kthread;int next_cpu; +if (hwlat_kthread) +return 0 ; +/* Just pick the first CPU on first iteration */ current_mask = &save_cpumask;get_online_cpus ();
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 20/34 tracing: Do a WARN_ON() if start_thread() in hwlat is called when thread exists
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The start function of the hwlat tracer should never be called when the hwlat thread already exists. If it is called, do a WARN_ON().
--- kernel/trace/trace_hwlat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_hwlat.c +1 -1
@@ -354,7 +354,7 @@ static int start_kthread(struct trace_array *tr)struct task_struct *kthread;int next_cpu; -if (hwlat_kthread) +if (WARN_ON (hwlat_kthread))return 0 ;/* Just pick the first CPU on first iteration */
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 21/34 tracing: Make tracer_tracing_is_on() return bool
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
There's code that expects tracer_tracing_is_on() to be either true or false, not some random number. Currently, it should only return one or zero, but just in case, change its return value to bool, to enforce it.
--- kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +1 -1
@@ -1087,7 +1087,7 @@ void disable_trace_on_warning(void)* * Shows real state of the ring buffer if it is enabled or not. */ -int tracer_tracing_is_on (struct trace_array *tr) +bool tracer_tracing_is_on (struct trace_array *tr) {if (tr->trace_buffer.buffer)return ring_buffer_record_is_on (tr->trace_buffer.buffer);
kernel/trace/trace.h +1 -1
@@ -594,7 +594,7 @@ void tracing_reset_current(int cpu);void tracing_reset_all_online_cpus (void );int tracing_open_generic (struct inode *inode,struct file *filp);bool tracing_is_disabled (void ); -int tracer_tracing_is_on (struct trace_array *tr); +bool tracer_tracing_is_on (struct trace_array *tr);void tracer_tracing_on (struct trace_array *tr);void tracer_tracing_off (struct trace_array *tr); struct dentry *trace_create_file(const char *name,
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 22/34 ring-buffer: Make ring_buffer_record_is_on() return bool
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The value of ring_buffer_record_is_on() is either true or false, so have its return value be bool.
--- include/linux/ring_buffer.h | 2 +- kernel/trace/ring_buffer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/ring_buffer.h +1 -1
@@ -164,7 +164,7 @@ void ring_buffer_record_disable(struct ring_buffer *buffer);void ring_buffer_record_enable (struct ring_buffer *buffer);void ring_buffer_record_off (struct ring_buffer *buffer);void ring_buffer_record_on (struct ring_buffer *buffer); -int ring_buffer_record_is_on (struct ring_buffer *buffer); +bool ring_buffer_record_is_on (struct ring_buffer *buffer);int ring_buffer_record_is_set_on (struct ring_buffer *buffer);void ring_buffer_record_disable_cpu (struct ring_buffer *buffer,int cpu);void ring_buffer_record_enable_cpu (struct ring_buffer *buffer,int cpu);
kernel/trace/ring_buffer.c +1 -1
@@ -3221,7 +3221,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_on);* * Returns true if the ring buffer is in a state that it accepts writes. */ -int ring_buffer_record_is_on (struct ring_buffer *buffer) +bool ring_buffer_record_is_on (struct ring_buffer *buffer) {return !atomic_read (&buffer->record_disabled); }
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 23/34 ring-buffer: Make ring_buffer_record_is_set_on() return bool
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The value of ring_buffer_record_is_set_on() is either true or false, so have its return value be bool.
--- include/linux/ring_buffer.h | 2 +- kernel/trace/ring_buffer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/ring_buffer.h +1 -1
@@ -165,7 +165,7 @@ void ring_buffer_record_enable(struct ring_buffer *buffer);void ring_buffer_record_off (struct ring_buffer *buffer);void ring_buffer_record_on (struct ring_buffer *buffer);bool ring_buffer_record_is_on (struct ring_buffer *buffer); -int ring_buffer_record_is_set_on (struct ring_buffer *buffer); +bool ring_buffer_record_is_set_on (struct ring_buffer *buffer);void ring_buffer_record_disable_cpu (struct ring_buffer *buffer,int cpu);void ring_buffer_record_enable_cpu (struct ring_buffer *buffer,int cpu);
kernel/trace/ring_buffer.c +1 -1
@@ -3237,7 +3237,7 @@ bool ring_buffer_record_is_on(struct ring_buffer *buffer)* ring_buffer_record_disable(), as that is a temporary disabling of * the ring buffer. */ -int ring_buffer_record_is_set_on (struct ring_buffer *buffer) +bool ring_buffer_record_is_set_on (struct ring_buffer *buffer) {return !(atomic_read (&buffer->record_disabled) &RB_BUFFER_OFF ); }
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 24/34 ftrace: Use true and false for boolean values in ops_references_rec()
In reply to Steven RostedtFrom: "Gustavo A. R. Silva" <[email protected]>
Return statements in functions returning bool should use true or false instead of an integer value.
This code was detected with the help of Coccinelle.
--- kernel/trace/ftrace.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/trace/ftrace.c +5 -5
@@ -2898,22 +2898,22 @@ ops_references_rec(struct ftrace_ops *ops, struct dyn_ftrace *rec) {/* If ops isn't enabled, ignore it */ if (!(ops->flags &FTRACE_OPS_FL_ENABLED )) -return 0 ; +return false;/* If ops traces all then it includes this function */ if (ops_traces_mod (ops)) -return 1 ; +return true;/* The function must be in the filter */ if (!ftrace_hash_empty (ops->func_hash->filter_hash) && !__ftrace_lookup_ip (ops->func_hash->filter_hash, rec->ip)) -return 0 ; +return false;/* If in notrace hash, we ignore it too */ if (ftrace_lookup_ip (ops->func_hash->notrace_hash, rec->ip)) -return 0 ; +return false; -return 1 ; +return true; }static int ftrace_update_code (struct module *mod,struct ftrace_page *new_pgs)
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 25/34 tracing/kprobes: Fix within_notrace_func() to check only notrace functions
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Fix within_notrace_func() to check only notrace functions and to ignore the kprobe-event which can not solve symbol addresses.
within_notrace_func() returns true if the given kprobe events probe point seems to be out-of-range. But that is not the correct place to check for it, it should be done in kprobes afterwards.
kprobe-events allow users to define a probe point on "currently unloaded module" so that it can trace the event during module load. In this case, the user will put a probe on a symbol which is not in kallsyms yet and it hits the within_notrace_func(). As a result, kprobe-events always refuses if user defines a probe on a "currenly unloaded module".
--- kernel/trace/trace_kprobe.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/trace/trace_kprobe.c +5 -3
@@ -88,6 +88,7 @@ static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk)return nhit; } +/* Return 0 if it fails to find the symbol address */ static nokprobe_inline unsigned long trace_kprobe_address (struct trace_kprobe *tk) {
@@ -96,7 +97,8 @@ unsigned long trace_kprobe_address(struct trace_kprobe *tk)if (tk->symbol) { addr = (unsigned long )kallsyms_lookup_name (trace_kprobe_symbol (tk)); - addr += tk->rp.kp.offset; +if (addr) + addr += tk->rp.kp.offset; }else { addr = (unsigned long )tk->rp.kp.addr; }
@@ -519,8 +521,8 @@ static bool within_notrace_func(struct trace_kprobe *tk)unsigned long offset, size, addr; addr =trace_kprobe_address (tk); -if (!kallsyms_lookup_size_offset (addr, &size, &offset)) -return true;/* Out of range. */ +if (!addr || !kallsyms_lookup_size_offset (addr, &size, &offset)) +return false;return !ftrace_location_range (addr - offset, addr - offset + size); }
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 26/34 trace: Use rcu_dereference_raw for hooks from trace-event subsystem
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
Since we switched to using SRCU for tracepoints used in the idle path, we can no longer use rcu_dereference_sched for dereferencing points in trace-event hooks.
Since tracepoints can now use either SRCU or sched-RCU, just use rcu_dereference_raw for traceevents just like we're doing when dereferencing the tracepoint table.
This prevents an RCU warning reported by Masami:
[ 282.060593] WARNING: can't dereference registers at 00000000f3c7f62b [ 282.063200] ============================= [ 282.064082] WARNING: suspicious RCU usage [ 282.064963] 4.18.0-rc6+ #15 Tainted: G W [ 282.066048] ----------------------------- [ 282.066923] /home/mhiramat/ksrc/linux/kernel/trace/trace_events.c:242 suspicious rcu_dereference_check() usage! [ 282.068974] [ 282.068974] other info that might help us debug this: [ 282.068974] [ 282.070770] [ 282.070770] RCU used illegally from idle CPU! [ 282.070770] rcu_scheduler_active = 2, debug_locks = 1 [ 282.072938] RCU used illegally from extended quiescent state! [ 282.074183] no locks held by swapper/0/0. [ 282.075071] [ 282.075071] stack backtrace: [ 282.076121] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W [ 282.077782] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) [ 282.079604] Call Trace: [ 282.080212] <IRQ> [ 282.080755] dump_stack+0x85/0xcb [ 282.081523] trace_event_ignore_this_pid+0x66/0x70 [ 282.082541] trace_event_raw_event_preemptirq_template+0xa2/0xb0 [ 282.083774] ? interrupt_entry+0xc4/0xe0 [ 282.084665] ? trace_hardirqs_off_thunk+0x1a/0x1c [ 282.085669] trace_hardirqs_off_caller+0x90/0xd0 [ 282.086597] trace_hardirqs_off_thunk+0x1a/0x1c [ 282.087433] ? call_function_interrupt+0xa/0x20 [ 282.088201] interrupt_entry+0xc4/0xe0 [ 282.088848] ? call_function_interrupt+0xa/0x20 [ 282.089579] </IRQ> [ 282.090029] ? native_safe_halt+0x2/0x10 [ 282.090695] ? default_idle+0x1f/0x160 [ 282.091330] ? default_idle_call+0x24/0x40 [ 282.091997] ? do_idle+0x210/0x250 [ 282.092658] ? cpu_startup_entry+0x6f/0x80 [ 282.093338] ? start_kernel+0x49d/0x4bd [ 282.093987] ? secondary_startup_64+0xa5/0xb0
--- kernel/trace/trace_events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_events.c +2 -2
@@ -239,7 +239,7 @@ bool trace_event_ignore_this_pid(struct trace_event_file *trace_file)struct trace_array_cpu *data;struct trace_pid_list *pid_list; - pid_list =rcu_dereference_sched (tr->filtered_pids); + pid_list =rcu_dereference_raw (tr->filtered_pids);if (!pid_list)return false;
@@ -512,7 +512,7 @@ event_filter_pid_sched_process_exit(void *data, struct task_struct *task)struct trace_pid_list *pid_list;struct trace_array *tr = data; - pid_list =rcu_dereference_sched (tr->filtered_pids); + pid_list =rcu_dereference_raw (tr->filtered_pids);trace_filter_add_remove_task (pid_list,NULL , task); }
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 27/34 tracing: irqsoff: Account for additional preempt_disable
In reply to Steven RostedtFrom: "Joel Fernandes (Google)" <[email protected]>
Recently we tried to make the preemptirqsoff tracer to use irqsoff tracepoint probes. However this causes issues as reported by Masami:
[2.271078] Testing tracer preemptirqsoff: .. no entries found ..FAILED! [2.381015] WARNING: CPU: 0 PID: 1 at /home/mhiramat/ksrc/linux/kernel/
trace/trace.c:1512 run_tracer_selftest+0xf3/0x154
This is due to the tracepoint code increasing the preempt nesting count by calling an additional preempt_disable before calling into the preemptoff tracer which messes up the preempt_count() check in tracer_hardirqs_off.
To fix this, make the irqsoff tracer probes balance the additional outer preempt_disable with a preempt_enable_notrace.
The other way to fix this is to just use SRCU for all tracepoints. However we can't do that because we can't use NMIs from RCU context.
--- kernel/trace/trace_irqsoff.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
kernel/trace/trace_irqsoff.c +26 -0
@@ -603,14 +603,40 @@ static void irqsoff_tracer_stop(struct trace_array *tr)*/ static void tracer_hardirqs_on (void *none,unsigned long a0,unsigned long a1) { +/* +* Tracepoint probes are expected to be called with preempt disabled, +* We don't care about being called with preempt disabled but we need +* to know in the future if that changes so we can remove the next +* preempt_enable. +*/ +WARN_ON_ONCE (!preempt_count ()); + +/* Tracepoint probes disable preemption atleast once, account for that */ +preempt_enable_notrace (); +if (!preempt_trace () &&irq_trace ())stop_critical_timing (a0, a1); + +preempt_disable_notrace (); }static void tracer_hardirqs_off (void *none,unsigned long a0,unsigned long a1) { +/* +* Tracepoint probes are expected to be called with preempt disabled, +* We don't care about being called with preempt disabled but we need +* to know in the future if that changes so we can remove the next +* preempt_enable. +*/ +WARN_ON_ONCE (!preempt_count ()); + +/* Tracepoint probes disable preemption atleast once, account for that */ +preempt_enable_notrace (); +if (!preempt_trace () &&irq_trace ())start_critical_timing (a0, a1); + +preempt_disable_notrace (); }static int irqsoff_tracer_init (struct trace_array *tr)
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 28/34 tracing: Partial revert of "tracing: Centralize preemptirq tracepoints and unify their usage"
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Joel Fernandes created a nice patch that cleaned up the duplicate hooks used by lockdep and irqsoff latency tracer. It made both use tracepoints. But it caused lockdep to trigger several false positives. We have not figured out why yet, but removing lockdep from using the trace event hooks and just call its helper functions directly (like it use to), makes the problem go away.
This is a partial revert of the clean up patch c3bc8fd637a9 ("tracing:
Centralize preemptirq tracepoints and unify their usage") that adds direct calls for lockdep, but also keeps most of the clean up done to get rid of the horrible preprocessor if statements.
--- include/linux/irqflags.h | 8 ++++++-- include/linux/lockdep.h | 2 -- init/main.c | 2 -- kernel/locking/lockdep.c | 14 ++----------- kernel/trace/trace_preemptirq.c | 36 ++++++++++++++++++--------------- 5 files changed, 28 insertions(+), 34 deletions(-)
include/linux/irqflags.h +6 -2
@@ -19,9 +19,13 @@#ifdef CONFIG_PROVE_LOCKING extern void trace_softirqs_on (unsigned long ip);extern void trace_softirqs_off (unsigned long ip); +extern void lockdep_hardirqs_on (unsigned long ip); +extern void lockdep_hardirqs_off (unsigned long ip);#else -# define trace_softirqs_on (ip) do { } while (0) -# define trace_softirqs_off (ip) do { } while (0) +static inline void trace_softirqs_on (unsigned long ip) { } +static inline void trace_softirqs_off (unsigned long ip) { } +static inline void lockdep_hardirqs_on (unsigned long ip) { } +static inline void lockdep_hardirqs_off (unsigned long ip) { }#endif #ifdef CONFIG_TRACE_IRQFLAGS
include/linux/lockdep.h +0 -2
@@ -267,7 +267,6 @@ struct held_lock {* Initialization, self-test and debugging-output methods: */ extern void lockdep_init (void ); -extern void lockdep_init_early (void );extern void lockdep_reset (void );extern void lockdep_reset_lock (struct lockdep_map *lock);extern void lockdep_free_key_range (void *start,unsigned long size);
@@ -408,7 +407,6 @@ static inline void lockdep_on(void)# define lock_set_class (l, n, k, s, i) do { } while (0)# define lock_set_subclass (l, s, i) do { } while (0)# define lockdep_init () do { } while (0) -# define lockdep_init_early () do { } while (0)# define lockdep_init_map (lock, name, key, sub) \ do { (void)(name); (void)(key); } while (0)# define lockdep_set_class (lock, key) do { (void)(key); } while (0)
init/main.c +0 -2
@@ -649,8 +649,6 @@ asmlinkage __visible void __init start_kernel(void)call_function_init ();WARN (!irqs_disabled (),"Interrupts were enabled early\n" ); -lockdep_init_early (); - early_boot_irqs_disabled = false;local_irq_enable ();
kernel/locking/lockdep.c +2 -12
@@ -2840,8 +2840,7 @@ static void __trace_hardirqs_on_caller(unsigned long ip)debug_atomic_inc (hardirqs_on_events); } -static void lockdep_hardirqs_on (void *none,unsigned long ignore, -unsigned long ip) +void lockdep_hardirqs_on (unsigned long ip) {if (unlikely (!debug_locks || current->lockdep_recursion))return ;
@@ -2885,8 +2884,7 @@ static void lockdep_hardirqs_on(void *none, unsigned long ignore,/* * Hardirqs were disabled: */ -static void lockdep_hardirqs_off (void *none,unsigned long ignore, -unsigned long ip) +void lockdep_hardirqs_off (unsigned long ip) {struct task_struct *curr = current;
@@ -4315,14 +4313,6 @@ void lockdep_reset_lock(struct lockdep_map *lock)raw_local_irq_restore (flags); } -void __init lockdep_init_early (void ) -{ -#ifdef CONFIG_PROVE_LOCKING -register_trace_prio_irq_disable (lockdep_hardirqs_off,NULL ,INT_MAX ); -register_trace_prio_irq_enable (lockdep_hardirqs_on,NULL ,INT_MIN ); -#endif -} -void __init lockdep_init (void ) {printk ("Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar\n" );
kernel/trace/trace_preemptirq.c +20 -16
@@ -19,41 +19,45 @@ static DEFINE_PER_CPU(int, tracing_irq_cpu);void trace_hardirqs_on (void ) { -if (!this_cpu_read (tracing_irq_cpu)) -return ; +if (this_cpu_read (tracing_irq_cpu)) { +trace_irq_enable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); +this_cpu_write (tracing_irq_cpu,0 ); + } -trace_irq_enable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); -this_cpu_write (tracing_irq_cpu,0 ); +lockdep_hardirqs_on (CALLER_ADDR0 ); }EXPORT_SYMBOL (trace_hardirqs_on);void trace_hardirqs_off (void ) { -if (this_cpu_read (tracing_irq_cpu)) -return ; +if (!this_cpu_read (tracing_irq_cpu)) { +this_cpu_write (tracing_irq_cpu,1 ); +trace_irq_disable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); + } -this_cpu_write (tracing_irq_cpu,1 ); -trace_irq_disable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); +lockdep_hardirqs_off (CALLER_ADDR0 ); }EXPORT_SYMBOL (trace_hardirqs_off); __visible void trace_hardirqs_on_caller(unsigned long caller_addr) { -if (!this_cpu_read (tracing_irq_cpu)) -return ; +if (this_cpu_read (tracing_irq_cpu)) { +trace_irq_enable_rcuidle (CALLER_ADDR0 , caller_addr); +this_cpu_write (tracing_irq_cpu,0 ); + } -trace_irq_enable_rcuidle (CALLER_ADDR0 , caller_addr); -this_cpu_write (tracing_irq_cpu,0 ); +lockdep_hardirqs_on (CALLER_ADDR0 ); }EXPORT_SYMBOL (trace_hardirqs_on_caller); __visible void trace_hardirqs_off_caller(unsigned long caller_addr) { -if (this_cpu_read (tracing_irq_cpu)) -return ; +if (!this_cpu_read (tracing_irq_cpu)) { +this_cpu_write (tracing_irq_cpu,1 ); +trace_irq_disable_rcuidle (CALLER_ADDR0 , caller_addr); + } -this_cpu_write (tracing_irq_cpu,1 ); -trace_irq_disable_rcuidle (CALLER_ADDR0 , caller_addr); +lockdep_hardirqs_off (CALLER_ADDR0 ); }EXPORT_SYMBOL (trace_hardirqs_off_caller);#endif /* CONFIG_TRACE_IRQFLAGS */
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 29/34 tracing/irqsoff: Handle preempt_count for different configs
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
I was hitting the following warning:
WARNING: CPU: 0 PID: 1 at kernel/trace/trace_irqsoff.c:631 tracer_hardirqs_off+0x15/0x2a Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.18.0-rc6-test+ #13 Hardware name: MSI MS-7823/CSM-H87M-G43 (MS-7823), BIOS V1.6 02/22/2014 EIP: tracer_hardirqs_off+0x15/0x2a Code: ff 85 c0 74 0e 8b 45 00 8b 50 04 8b 45 04 e8 35 ff ff ff 5d c3 55 64 a1 cc 37 51 c1 a9 ff ff ff 7f 89 e5 53 89 d3 89 ca 75 02 <0f> 0b e8 90 fc ff ff 85 c0 74 07 89 d8 e8 0c ff ff ff 5b 5d c3 55 EAX: 80000000 EBX: c04337f0 ECX: c04338e3 EDX: c04338e3 ESI: c04337f0 EDI: c04338e3 EBP: f2aa1d68 ESP: f2aa1d64 DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068 EFLAGS: 00210046 CR0: 80050033 CR2: 00000000 CR3: 01668000 CR4: 001406f0 Call Trace: trace_irq_disable_rcuidle+0x63/0x6c trace_hardirqs_off+0x26/0x30 default_send_IPI_mask_allbutself_logical+0x31/0x93 default_send_IPI_allbutself+0x37/0x48 native_send_call_func_ipi+0x4d/0x6a smp_call_function_many+0x165/0x19d ? add_nops+0x34/0x34 ? trace_hardirqs_on_caller+0x2d/0x2d ? add_nops+0x34/0x34 smp_call_function+0x1f/0x23 on_each_cpu+0x15/0x43 ? trace_hardirqs_on_caller+0x2d/0x2d ? trace_hardirqs_on_caller+0x2d/0x2d ? trace_irq_disable_rcuidle+0x1/0x6c text_poke_bp+0xa0/0xc2 ? trace_hardirqs_on_caller+0x2d/0x2d arch_jump_label_transform+0xa7/0xcb ? trace_irq_disable_rcuidle+0x5/0x6c __jump_label_update+0x3e/0x6d jump_label_update+0x7d/0x81 static_key_slow_inc_cpuslocked+0x58/0x6d static_key_slow_inc+0x19/0x20 tracepoint_probe_register_prio+0x19e/0x1d1 ? start_critical_timings+0x1c/0x1c tracepoint_probe_register+0xf/0x11 irqsoff_tracer_init+0x21/0xf2 tracer_init+0x16/0x1a trace_selftest_startup_irqsoff+0x25/0xc4 run_tracer_selftest+0xca/0x131 register_tracer+0xd5/0x172 ? trace_event_define_fields_preemptirq_template+0x45/0x45 init_irqsoff_tracer+0xd/0x11 do_one_initcall+0xab/0x1e8 ? rcu_read_lock_sched_held+0x3d/0x44 ? trace_initcall_level+0x52/0x86 kernel_init_freeable+0x195/0x21a ? rest_init+0xb4/0xb4 kernel_init+0xd/0xe4 ret_from_fork+0x2e/0x38
It is due to running a CONFIG_PREEMPT_VOLUNTARY kernel, which would trigger this warning every time:
WARN_ON_ONCE(preempt_count());
Because on CONFIG_PREEMPT_VOLUNTARY, preempt_count() is always zero.
This warning is to make sure preempt_count is set because tracer_hardirqs_on() does a preempt_enable_notrace() to make the preempt_trace() work properly, as being called by a trace event, the trace event code disables preemption, and the tracer wants to know what the preemption was before it was called.
Instead of enabling preemption like this, just record the preempt_count, subtract PREEMPT_DISABLE_OFFSET from it (which is zero with !CONFIG_PREEMPT set), and pass that value to the necessary functions, which should use the passed in parameter instead of calling preempt_count() directly.
--- kernel/trace/trace_irqsoff.c | 66 ++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 29 deletions(-)
kernel/trace/trace_irqsoff.c +37 -29
@@ -40,12 +40,12 @@ static int start_irqsoff_tracer(struct trace_array *tr, int graph);#ifdef CONFIG_PREEMPT_TRACER static inline int -preempt_trace (void ) +preempt_trace (int pc) { -return ((trace_type &TRACER_PREEMPT_OFF ) &&preempt_count ()); +return ((trace_type &TRACER_PREEMPT_OFF ) && pc); }#else -# define preempt_trace () (0) +# define preempt_trace (pc) (0)#endif #ifdef CONFIG_IRQSOFF_TRACER
@@ -366,7 +366,7 @@ check_critical_timing(struct trace_array *tr, }static inline void -start_critical_timing (unsigned long ip,unsigned long parent_ip) +start_critical_timing (unsigned long ip,unsigned long parent_ip,int pc) {int cpu;struct trace_array *tr = irqsoff_trace;
@@ -394,7 +394,7 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip)local_save_flags (flags); -__trace_function (tr, ip, parent_ip, flags,preempt_count ()); +__trace_function (tr, ip, parent_ip, flags, pc);per_cpu (tracing_cpu, cpu) =1 ;
@@ -402,7 +402,7 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip) }static inline void -stop_critical_timing (unsigned long ip,unsigned long parent_ip) +stop_critical_timing (unsigned long ip,unsigned long parent_ip,int pc) {int cpu;struct trace_array *tr = irqsoff_trace;
@@ -428,7 +428,7 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip)atomic_inc (&data->disabled);local_save_flags (flags); -__trace_function (tr, ip, parent_ip, flags,preempt_count ()); +__trace_function (tr, ip, parent_ip, flags, pc);check_critical_timing (tr, data, parent_ip ? : ip, cpu); data->critical_start =0 ;atomic_dec (&data->disabled);
@@ -437,15 +437,19 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip)/* start and stop critical timings used to for stoppage (in idle) */ void start_critical_timings (void ) { -if (preempt_trace () ||irq_trace ()) -start_critical_timing (CALLER_ADDR0 ,CALLER_ADDR1 ); +int pc =preempt_count (); + +if (preempt_trace (pc) ||irq_trace ()) +start_critical_timing (CALLER_ADDR0 ,CALLER_ADDR1 , pc); }EXPORT_SYMBOL_GPL (start_critical_timings);void stop_critical_timings (void ) { -if (preempt_trace () ||irq_trace ()) -stop_critical_timing (CALLER_ADDR0 ,CALLER_ADDR1 ); +int pc =preempt_count (); + +if (preempt_trace (pc) ||irq_trace ()) +stop_critical_timing (CALLER_ADDR0 ,CALLER_ADDR1 , pc); }EXPORT_SYMBOL_GPL (stop_critical_timings);
@@ -603,40 +607,40 @@ static void irqsoff_tracer_stop(struct trace_array *tr)*/ static void tracer_hardirqs_on (void *none,unsigned long a0,unsigned long a1) { +unsigned int pc =preempt_count (); +/* * Tracepoint probes are expected to be called with preempt disabled, * We don't care about being called with preempt disabled but we need * to know in the future if that changes so we can remove the next * preempt_enable. */ -WARN_ON_ONCE (!preempt_count ()); - -/* Tracepoint probes disable preemption atleast once, account for that */ -preempt_enable_notrace (); +WARN_ON_ONCE (pc <PREEMPT_DISABLE_OFFSET ); -if (!preempt_trace () &&irq_trace ()) -stop_critical_timing (a0, a1); +/* Use PREEMPT_DISABLE_OFFSET to handle !CONFIG_PREEMPT cases */ + pc -=PREEMPT_DISABLE_OFFSET ; -preempt_disable_notrace (); +if (!preempt_trace (pc) &&irq_trace ()) +stop_critical_timing (a0, a1, pc); }static void tracer_hardirqs_off (void *none,unsigned long a0,unsigned long a1) { +unsigned int pc =preempt_count (); +/* * Tracepoint probes are expected to be called with preempt disabled, * We don't care about being called with preempt disabled but we need * to know in the future if that changes so we can remove the next * preempt_enable. */ -WARN_ON_ONCE (!preempt_count ()); - -/* Tracepoint probes disable preemption atleast once, account for that */ -preempt_enable_notrace (); +WARN_ON_ONCE (pc <PREEMPT_DISABLE_OFFSET ); -if (!preempt_trace () &&irq_trace ()) -start_critical_timing (a0, a1); +/* Use PREEMPT_DISABLE_OFFSET to handle !CONFIG_PREEMPT cases */ + pc -=PREEMPT_DISABLE_OFFSET ; -preempt_disable_notrace (); +if (!preempt_trace (pc) &&irq_trace ()) +start_critical_timing (a0, a1, pc); }static int irqsoff_tracer_init (struct trace_array *tr)
@@ -679,14 +683,18 @@ static struct tracer irqsoff_tracer __read_mostly =#ifdef CONFIG_PREEMPT_TRACER static void tracer_preempt_on (void *none,unsigned long a0,unsigned long a1) { -if (preempt_trace () && !irq_trace ()) -stop_critical_timing (a0, a1); +int pc =preempt_count (); + +if (preempt_trace (pc) && !irq_trace ()) +stop_critical_timing (a0, a1, pc); }static void tracer_preempt_off (void *none,unsigned long a0,unsigned long a1) { -if (preempt_trace () && !irq_trace ()) -start_critical_timing (a0, a1); +int pc =preempt_count (); + +if (preempt_trace (pc) && !irq_trace ()) +start_critical_timing (a0, a1, pc); }static int preemptoff_tracer_init (struct trace_array *tr)
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 30/34 tracing: More reverting of "tracing: Centralize preemptirq tracepoints and unify their usage"
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Joel Fernandes created a nice patch that cleaned up the duplicate hooks used by lockdep and irqsoff latency tracer. It made both use tracepoints. But the latency tracer is triggering warnings when using tracepoints to call into the latency tracer's routines. Mainly, they can be called from NMI context. If that happens, then the SRCU may not work properly because on some architectures, SRCU is not safe to be called in both NMI and non-NMI context.
This is a partial revert of the clean up patch c3bc8fd637a9 ("tracing:
Centralize preemptirq tracepoints and unify their usage") that adds back the direct calls into the latency tracer. It also only calls the trace events when not in NMI.
--- kernel/trace/trace.h | 15 +++++++++++ kernel/trace/trace_irqsoff.c | 48 +++------------------------------ kernel/trace/trace_preemptirq.c | 25 ++++++++++++----- 3 files changed, 38 insertions(+), 50 deletions(-)
kernel/trace/trace.h +15 -0
@@ -1827,6 +1827,21 @@ static inline int tracing_alloc_snapshot_instance(struct trace_array *tr) }#endif +#ifdef CONFIG_PREEMPT_TRACER +void tracer_preempt_on (unsigned long a0,unsigned long a1); +void tracer_preempt_off (unsigned long a0,unsigned long a1); +#else +static inline void tracer_preempt_on (unsigned long a0,unsigned long a1) { } +static inline void tracer_preempt_off (unsigned long a0,unsigned long a1) { } +#endif +#ifdef CONFIG_IRQSOFF_TRACER +void tracer_hardirqs_on (unsigned long a0,unsigned long a1); +void tracer_hardirqs_off (unsigned long a0,unsigned long a1); +#else +static inline void tracer_hardirqs_on (unsigned long a0,unsigned long a1) { } +static inline void tracer_hardirqs_off (unsigned long a0,unsigned long a1) { } +#endif +extern struct trace_iterator *tracepoint_print_iter;#endif /* _LINUX_KERNEL_TRACE_H */
kernel/trace/trace_irqsoff.c +4 -44
109 lines not on this page · raw message
kernel/trace/trace_preemptirq.c +19 -6
@@ -9,6 +9,7 @@#include <linux/uaccess.h> #include <linux/module.h> #include <linux/ftrace.h> +#include "trace.h" #define CREATE_TRACE_POINTS #include <trace/events/preemptirq.h>
@@ -20,7 +21,9 @@ static DEFINE_PER_CPU(int, tracing_irq_cpu);void trace_hardirqs_on (void ) {if (this_cpu_read (tracing_irq_cpu)) { -trace_irq_enable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); +if (!in_nmi ()) +trace_irq_enable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); +tracer_hardirqs_on (CALLER_ADDR0 ,CALLER_ADDR1 );this_cpu_write (tracing_irq_cpu,0 ); }
@@ -32,7 +35,9 @@ void trace_hardirqs_off(void) {if (!this_cpu_read (tracing_irq_cpu)) {this_cpu_write (tracing_irq_cpu,1 ); -trace_irq_disable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); +tracer_hardirqs_off (CALLER_ADDR0 ,CALLER_ADDR1 ); +if (!in_nmi ()) +trace_irq_disable_rcuidle (CALLER_ADDR0 ,CALLER_ADDR1 ); }lockdep_hardirqs_off (CALLER_ADDR0 );
@@ -42,7 +47,9 @@ EXPORT_SYMBOL(trace_hardirqs_off); __visible void trace_hardirqs_on_caller(unsigned long caller_addr) {if (this_cpu_read (tracing_irq_cpu)) { -trace_irq_enable_rcuidle (CALLER_ADDR0 , caller_addr); +if (!in_nmi ()) +trace_irq_enable_rcuidle (CALLER_ADDR0 , caller_addr); +tracer_hardirqs_on (CALLER_ADDR0 , caller_addr);this_cpu_write (tracing_irq_cpu,0 ); }
@@ -54,7 +61,9 @@ __visible void trace_hardirqs_off_caller(unsigned long caller_addr) {if (!this_cpu_read (tracing_irq_cpu)) {this_cpu_write (tracing_irq_cpu,1 ); -trace_irq_disable_rcuidle (CALLER_ADDR0 , caller_addr); +tracer_hardirqs_off (CALLER_ADDR0 , caller_addr); +if (!in_nmi ()) +trace_irq_disable_rcuidle (CALLER_ADDR0 , caller_addr); }lockdep_hardirqs_off (CALLER_ADDR0 );
@@ -66,11 +75,15 @@ EXPORT_SYMBOL(trace_hardirqs_off_caller);void trace_preempt_on (unsigned long a0,unsigned long a1) { -trace_preempt_enable_rcuidle (a0, a1); +if (!in_nmi ()) +trace_preempt_enable_rcuidle (a0, a1); +tracer_preempt_on (a0, a1); }void trace_preempt_off (unsigned long a0,unsigned long a1) { -trace_preempt_disable_rcuidle (a0, a1); +if (!in_nmi ()) +trace_preempt_disable_rcuidle (a0, a1); +tracer_preempt_off (a0, a1); }#endif
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 31/34 ftrace: Remove unused pointer ftrace_swapper_pid
In reply to Steven RostedtFrom: Colin Ian King <[email protected]>
Pointer ftrace_swapper_pid is defined but is never used hence it is redundant and can be removed. The use of this variable was removed in commit 345ddcc882d8 ("ftrace: Have set_ftrace_pid use the bitmap like events do").
Cleans up clang warning:
warning: 'ftrace_swapper_pid' defined but not used [-Wunused-const-variable=]
--- kernel/trace/ftrace.c | 2 -- 1 file changed, 2 deletions(-)
kernel/trace/ftrace.c +0 -2
@@ -1020,8 +1020,6 @@ static __init void ftrace_profile_tracefs(struct dentry *d_tracer) }#endif /* CONFIG_FUNCTION_PROFILER */ -static struct pid *const ftrace_swapper_pid = &init_struct_pid; -#ifdef CONFIG_FUNCTION_GRAPH_TRACER static int ftrace_graph_active;#else
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 32/34 tracing: Fix synchronizing to event changes with tracepoint_synchronize_unregister()
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Now that some trace events can be protected by srcu_read_lock(tracepoint_srcu), we need to make sure all locations that depend on this are also protected. There were many places that did a synchronize_sched() thinking that it was enough to protect againts access to trace events. This use to be the case, but now that we use SRCU for _rcuidle() trace events, they may not be protected by synchronize_sched(), as they may be called in paths that RCU is not watching for preempt disable.
--- kernel/trace/trace_events.c | 8 ++++---- kernel/trace/trace_events_filter.c | 15 ++++++++------- kernel/trace/trace_events_hist.c | 2 +- kernel/trace/trace_events_trigger.c | 6 ++++-- 4 files changed, 17 insertions(+), 14 deletions(-)
kernel/trace/trace_events.c +4 -4
@@ -636,7 +636,7 @@ static void __ftrace_clear_event_pids(struct trace_array *tr)rcu_assign_pointer (tr->filtered_pids,NULL );/* Wait till all users are no longer using pid filtering */ -synchronize_sched (); +tracepoint_synchronize_unregister ();trace_free_pid_list (pid_list); }
@@ -1622,7 +1622,7 @@ ftrace_event_pid_write(struct file *filp, const char __user *ubuf, }if (filtered_pids) { -synchronize_sched (); +tracepoint_synchronize_unregister ();trace_free_pid_list (filtered_pids); }else if (pid_list) {/*
@@ -3036,8 +3036,8 @@ int event_trace_del_tracer(struct trace_array *tr)/* Disable any running events */ __ftrace_set_clr_event_nolock (tr,NULL ,NULL ,NULL ,0 ); -/* Access to events are within rcu_read_lock_sched() */ -synchronize_sched (); +/* Make sure no more events are being executed */ +tracepoint_synchronize_unregister ();down_write (&trace_event_sem);__trace_remove_event_dirs (tr);
kernel/trace/trace_events_filter.c +8 -7
@@ -899,7 +899,8 @@ int filter_match_preds(struct event_filter *filter, void *rec)if (!filter)return 1 ; - prog =rcu_dereference_sched (filter->prog); +/* Protected by either SRCU(tracepoint_srcu) or preempt_disable */ + prog =rcu_dereference_raw (filter->prog);if (!prog)return 1 ;
@@ -1626,10 +1627,10 @@ static int process_system_preds(struct trace_subsystem_dir *dir,/* * The calls can still be using the old filters. -* Do a synchronize_sched() to ensure all calls are +* Do a synchronize_sched() and to ensure all calls are * done with them before we free them. */ -synchronize_sched (); +tracepoint_synchronize_unregister ();list_for_each_entry_safe (filter_item, tmp, &filter_list, list) {__free_filter (filter_item->filter);list_del (&filter_item->list);
@@ -1648,7 +1649,7 @@ static int process_system_preds(struct trace_subsystem_dir *dir,kfree (filter);/* If any call succeeded, we still need to sync */ if (!fail) -synchronize_sched (); +tracepoint_synchronize_unregister ();list_for_each_entry_safe (filter_item, tmp, &filter_list, list) {__free_filter (filter_item->filter);list_del (&filter_item->list);
@@ -1790,7 +1791,7 @@ int apply_event_filter(struct trace_event_file *file, char *filter_string)event_clear_filter (file);/* Make sure the filter is not being used */ -synchronize_sched (); +tracepoint_synchronize_unregister ();__free_filter (filter);return 0 ;
@@ -1817,7 +1818,7 @@ int apply_event_filter(struct trace_event_file *file, char *filter_string)if (tmp) {/* Make sure the call is done with the filter */ -synchronize_sched (); +tracepoint_synchronize_unregister ();__free_filter (tmp); } }
@@ -1847,7 +1848,7 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, filter = system->filter; system->filter =NULL ;/* Ensure all filters are no longer used */ -synchronize_sched (); +tracepoint_synchronize_unregister ();filter_free_subsystem_filters (dir, tr);__free_filter (filter); goto out_unlock;
kernel/trace/trace_events_hist.c +1 -1
@@ -5141,7 +5141,7 @@ static void hist_clear(struct event_trigger_data *data)if (data->name)pause_named_trigger (data); -synchronize_sched (); +tracepoint_synchronize_unregister ();tracing_map_clear (hist_data->map);
kernel/trace/trace_events_trigger.c +4 -2
@@ -34,7 +34,9 @@ void trigger_data_free(struct event_trigger_data *data)if (data->cmd_ops->set_filter) data->cmd_ops->set_filter (NULL , data,NULL ); -synchronize_sched ();/* make sure current triggers exit before free */ +/* make sure current triggers exit before free */ +tracepoint_synchronize_unregister (); +kfree (data); }
@@ -752,7 +754,7 @@ int set_trigger_filter(char *filter_str,if (tmp) {/* Make sure the call is done with the filter */ -synchronize_sched (); +tracepoint_synchronize_unregister ();free_event_filter (tmp); }
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 33/34 uprobes: Use synchronize_rcu() not synchronize_sched()
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
While debugging another bug, I was looking at all the synchronize*() functions being used in kernel/trace, and noticed that trace_uprobes was using synchronize_sched(), with a comment to synchronize with {u,ret}_probe_trace_func(). When looking at those functions, the data is protected with "rcu_read_lock()" and not with "rcu_read_lock_sched()". This is using the wrong synchronize_*() function.
--- kernel/trace/trace_uprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_uprobe.c +1 -1
@@ -952,7 +952,7 @@ probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)list_del_rcu (&link->list);/* synchronize with u{,ret}probe_trace_func */ -synchronize_sched (); +synchronize_rcu ();kfree (link);if (!list_empty (&tu->tp.files))
Signature · 1 line
2.18.0
Steven Rostedt
maintainerPATCH 34/34 tracepoints: Free early tracepoints after RCU is initialized
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
When enabling trace events via the kernel command line, I hit this warning:
WARNING: CPU: 0 PID: 13 at kernel/rcu/srcutree.c:236 check_init_srcu_struct+0xe/0x61 Modules linked in: CPU: 0 PID: 13 Comm: watchdog/0 Not tainted 4.18.0-rc6-test+ #6 Hardware name: MSI MS-7823/CSM-H87M-G43 (MS-7823), BIOS V1.6 02/22/2014 RIP: 0010:check_init_srcu_struct+0xe/0x61 Code: 48 c7 c6 ec 8a 65 b4 e8 ff 79 fe ff 48 89 df 31 f6 e8 f2 fa ff ff 5a 5b 41 5c 5d c3 0f 1f 44 00 00 83 3d 68 94 b8 01 01 75 02 <0f> 0b 48 8b 87 f0 0a 00 00 a8 03 74 45 55 48 89 e5 41 55 41 54 4c RSP: 0000:ffff96eb9ea03e68 EFLAGS: 00010246 RAX: ffff96eb962b5b01 RBX: ffffffffb4a87420 RCX: 0000000000000001 RDX: ffffffffb3107969 RSI: ffff96eb962b5b40 RDI: ffffffffb4a87420 RBP: ffff96eb9ea03eb0 R08: ffffabbd00cd7f48 R09: 0000000000000000 R10: ffff96eb9ea03e68 R11: ffffffffb4a6eec0 R12: ffff96eb962b5b40 R13: ffff96eb9ea03ef8 R14: ffffffffb3107969 R15: ffffffffb3107948 FS: 0000000000000000(0000) GS:ffff96eb9ea00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff96eb13ab2000 CR3: 0000000192a1e001 CR4: 00000000001606f0 Call Trace: <IRQ> ? __call_srcu+0x2d/0x290 ? rcu_process_callbacks+0x26e/0x448 ? allocate_probes+0x2b/0x2b call_srcu+0x13/0x15 rcu_free_old_probes+0x1f/0x21 rcu_process_callbacks+0x2ed/0x448 __do_softirq+0x172/0x336 irq_exit+0x62/0xb2 smp_apic_timer_interrupt+0x161/0x19e apic_timer_interrupt+0xf/0x20 </IRQ>
The problem is that the enabling of trace events before RCU is set up will cause SRCU to give this warning. To avoid this, add a list to store probes that need to be freed till after RCU is initialized, and then free them then.
--- kernel/tracepoint.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
kernel/tracepoint.c +32 -0
@@ -53,6 +53,9 @@ static LIST_HEAD(tracepoint_module_list);*/ static DEFINE_MUTEX (tracepoints_mutex); +static struct rcu_head *early_probes; +static bool ok_to_free_tracepoints; +/* * Note about RCU : * It is used to delay the free of multiple probes array until a quiescent
@@ -80,11 +83,40 @@ static void rcu_free_old_probes(struct rcu_head *head)call_srcu (&tracepoint_srcu, head, srcu_free_old_probes); } +static __init int release_early_probes (void ) +{ +struct rcu_head *tmp; + + ok_to_free_tracepoints = true; + +while (early_probes) { + tmp = early_probes; + early_probes = tmp->next; +call_rcu_sched (tmp, rcu_free_old_probes); + } + +return 0 ; +} + +/* SRCU is initialized at core_initcall */ +postcore_initcall (release_early_probes); +static inline void release_probes (struct tracepoint_func *old) {if (old) {struct tp_probes *tp_probes =container_of (old, struct tp_probes, probes[0]); + +/* +* We can't free probes if SRCU is not initialized yet. +* Postpone the freeing till after SRCU is initialized. +*/ +if (unlikely (!ok_to_free_tracepoints)) { + tp_probes->rcu.next = early_probes; + early_probes = &tp_probes->rcu; +return ; + } +/* * Tracepoint probes are protected by both sched RCU and SRCU, * by calling the SRCU callback in the sched RCU callback we
Signature · 1 line
2.18.0