ftrace/rcu: Handle unsafe RCU functions and ftrace callbacks
Subsystems (6)
Steven Rostedt
maintainercover ftrace/rcu: Handle unsafe RCU functions and ftrace callbacks
This is the latest patches to be queued for 3.12.
A little late, but as Dave Jones has been stumbling over this for a while, I thought it would be good to get it in now. It's not that complex to resolve any issues that may pop up.
I'll keep it in linux-next for a while to make sure it really is clean.
Note, the checker will stumble over a few functions in irq and scheduler code if enabled. This is because those patches have not received Acks from Thomas Gleixner and Peter Zijlstra. When I get those acks, I'll add the changes to silent those too.
Thanks to Paul McKenney for reviewing the patches.
Enjoy,
-- Steve
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: 7fb3a66134ed5a40448131cf4195823d22f70aa3
Alexander Z Lam (1)
tracing: Make tracing_cpumask available for all instances
Steven Rostedt (Red Hat) (17)
ftrace: Fix a slight race in modifying what function callback gets traced ftrace/rcu: Do not trace debug_lockdep_rcu_enabled()
ftrace: Add hash list to save RCU unsafe functions
ftrace: Do not set ftrace records for unsafe RCU when not allowed
ftrace: Set ftrace internal function tracing RCU safe
ftrace: Add test for ops against unsafe RCU functions in callback
ftrace: Do not display non safe RCU functions in available_filter_functions
ftrace: Add rcu_unsafe_filter_functions file
ftrace: Add selftest to check if RCU unsafe functions are filtered properly
ftrace: Create a RCU unsafe checker
ftrace: Add infrastructure to stop RCU unsafe checker from checking
ftrace: Disable RCU unsafe checker when function graph is enabled
ftrace: Disable the RCU unsafe checker when irqsoff is enabled ftrace/lockdep: Have the RCU lockdep splat show what function triggered ftrace/rcu: Mark functions that are RCU unsafe ftrace/cpuidle/x86: Mark functions that are RCU unsafe
ftrace: Print a message when the rcu checker is disabled
----
b/arch/x86/kernel/process.c | 2 b/drivers/cpuidle/cpuidle.c | 2 b/include/asm-generic/vmlinux.lds.h | 10 + b/include/linux/ftrace.h | 38 +++++ b/kernel/cpu/idle.c | 2 b/kernel/lockdep.c | 2 b/kernel/rcupdate.c | 2 b/kernel/rcutiny.c | 1 b/kernel/rcutree.c | 7 + b/kernel/trace/Kconfig | 22 +++ b/kernel/trace/ftrace.c | 17 ++ b/kernel/trace/trace.c | 37 ++--- b/kernel/trace/trace.h | 1 b/kernel/trace/trace_functions.c | 48 ++++++- b/kernel/trace/trace_irqsoff.c | 16 ++ b/kernel/trace/trace_selftest.c | 94 +++++++++++++ b/kernel/trace/trace_selftest_dynamic.c | 7 + include/linux/ftrace.h | 8 + kernel/trace/ftrace.c | 218 +++++++++++++++++++++++++++++--- kernel/trace/trace.h | 17 ++ kernel/trace/trace_functions.c | 40 +++++ 21 files changed, 551 insertions(+), 40 deletions(-)
Steven Rostedt
maintainerPATCH 1/18 tracing: Make tracing_cpumask available for all instances
From: Alexander Z Lam <[email protected]>
Allow tracer instances to disable tracing by cpu by moving the static global tracing_cpumask into trace_array.
--- kernel/trace/trace.c | 37 ++++++++++++++++++++----------------- kernel/trace/trace.h | 1 + 2 files changed, 21 insertions(+), 17 deletions(-)
kernel/trace/trace.c +20 -17
@@ -3166,11 +3166,6 @@ static const struct file_operations show_traces_fops = { };/* -* Only trace on a CPU if the bitmask is set: -*/ -static cpumask_var_t tracing_cpumask; - -/* * The tracer itself will not take this lock, but still we want * to provide a consistent cpumask to user-space: */
@@ -3186,11 +3181,12 @@ static ssize_t tracing_cpumask_read(struct file *filp, char __user *ubuf, size_t count, loff_t *ppos) { + struct trace_array *tr = file_inode(filp)->i_private;int len;mutex_lock (&tracing_cpumask_update_lock); - len =cpumask_scnprintf (mask_str, count, tracing_cpumask); + len =cpumask_scnprintf (mask_str, count, tr->tracing_cpumask);if (count - len <2 ) { count = -EINVAL ; goto out_err;
@@ -3208,7 +3204,7 @@ static ssize_t tracing_cpumask_write(struct file *filp, const char __user *ubuf, size_t count, loff_t *ppos) { - struct trace_array *tr = filp->private_data; + struct trace_array *tr = file_inode(filp)->i_private;cpumask_var_t tracing_cpumask_new;int err, cpu;
@@ -3228,12 +3224,12 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,* Increase/decrease the disabled counter if we are * about to flip a bit in the cpumask: */ -if (cpumask_test_cpu (cpu, tracing_cpumask) && +if (cpumask_test_cpu (cpu, tr->tracing_cpumask) && !cpumask_test_cpu (cpu, tracing_cpumask_new)) {atomic_inc (&per_cpu_ptr (tr->trace_buffer.data, cpu)->disabled);ring_buffer_record_disable_cpu (tr->trace_buffer.buffer, cpu); } -if (!cpumask_test_cpu (cpu, tracing_cpumask) && +if (!cpumask_test_cpu (cpu, tr->tracing_cpumask) &&cpumask_test_cpu (cpu, tracing_cpumask_new)) {atomic_dec (&per_cpu_ptr (tr->trace_buffer.data, cpu)->disabled);ring_buffer_record_enable_cpu (tr->trace_buffer.buffer, cpu);
@@ -3242,7 +3238,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,arch_spin_unlock (&ftrace_max_lock);local_irq_enable (); -cpumask_copy (tracing_cpumask, tracing_cpumask_new); +cpumask_copy (tr->tracing_cpumask, tracing_cpumask_new);mutex_unlock (&tracing_cpumask_update_lock);free_cpumask_var (tracing_cpumask_new);
@@ -3256,9 +3252,10 @@ err_unlock: }static const struct file_operations tracing_cpumask_fops = { - .open = tracing_open_generic, + .open = tracing_open_generic_tr, .read = tracing_cpumask_read, .write = tracing_cpumask_write, + .release = tracing_release_generic_tr, .llseek = generic_file_llseek, };
@@ -5938,6 +5935,11 @@ static int new_instance_create(const char *name)if (!tr->name) goto out_free_tr; +if (!alloc_cpumask_var (&tr->tracing_cpumask,GFP_KERNEL )) + goto out_free_tr; + +cpumask_copy (tr->tracing_cpumask, cpu_all_mask); +raw_spin_lock_init (&tr->start_lock); tr->current_trace = &nop_trace;
@@ -5969,6 +5971,7 @@ static int new_instance_create(const char *name) out_free_tr:if (tr->trace_buffer.buffer)ring_buffer_free (tr->trace_buffer.buffer); +free_cpumask_var (tr->tracing_cpumask);kfree (tr->name);kfree (tr);
@@ -6098,6 +6101,9 @@ init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) {int cpu; +trace_create_file ("tracing_cpumask" ,0644 , d_tracer, + tr, &tracing_cpumask_fops); +trace_create_file ("trace_options" ,0644 , d_tracer, tr, &tracing_iter_fops);
@@ -6147,9 +6153,6 @@ static __init int tracer_init_debugfs(void)init_tracer_debugfs (&global_trace, d_tracer); -trace_create_file ("tracing_cpumask" ,0644 , d_tracer, - &global_trace, &tracing_cpumask_fops); -trace_create_file ("available_tracers" ,0444 , d_tracer, &global_trace, &show_traces_fops);
@@ -6371,7 +6374,7 @@ __init static int tracer_alloc_buffers(void)if (!alloc_cpumask_var (&tracing_buffer_mask,GFP_KERNEL )) goto out; -if (!alloc_cpumask_var (&tracing_cpumask,GFP_KERNEL )) +if (!alloc_cpumask_var (&global_trace.tracing_cpumask,GFP_KERNEL )) goto out_free_buffer_mask;/* Only allocate trace_printk buffers if a trace_printk exists */
@@ -6386,7 +6389,7 @@ __init static int tracer_alloc_buffers(void) ring_buf_size =1 ;cpumask_copy (tracing_buffer_mask, cpu_possible_mask); -cpumask_copy (tracing_cpumask, cpu_all_mask); +cpumask_copy (global_trace.tracing_cpumask, cpu_all_mask);raw_spin_lock_init (&global_trace.start_lock);
@@ -6441,7 +6444,7 @@ out_free_cpumask:#ifdef CONFIG_TRACER_MAX_TRACE free_percpu (global_trace.max_buffer.data);#endif -free_cpumask_var (tracing_cpumask); +free_cpumask_var (global_trace.tracing_cpumask); out_free_buffer_mask:free_cpumask_var (tracing_buffer_mask); out:
kernel/trace/trace.h +1 -0
@@ -206,6 +206,7 @@ struct trace_array {struct dentry *event_dir;struct list_head systems;struct list_head events; +cpumask_var_t tracing_cpumask;/* only trace on set CPUs */ int ref; };
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 2/18 ftrace: Fix a slight race in modifying what function callback gets traced
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
There's a slight race when going from a list function to a non list function. That is, when only one callback is registered to the function tracer, it gets called directly by the mcount trampoline. But if this function has filters, it may be called by the wrong functions.
As the list ops callback that handles multiple callbacks that are registered to ftrace, it also handles what functions they call. While the transaction is taking place, use the list function always, and after all the updates are finished (only the functions that should be traced are being traced), then we can update the trampoline to call the function directly.
--- kernel/trace/ftrace.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
kernel/trace/ftrace.c +16 -1
@@ -1978,12 +1978,27 @@ int __weak ftrace_arch_code_modify_post_process(void)void ftrace_modify_all_code (int command) { +int update = command &FTRACE_UPDATE_TRACE_FUNC ; + +/* +* If the ftrace_caller calls a ftrace_ops func directly, +* we need to make sure that it only traces functions it +* expects to trace. When doing the switch of functions, +* we need to update to the ftrace_ops_list_func first +* before the transition between old and new calls are set, +* as the ftrace_ops_list_func will check the ops hashes +* to make sure the ops are having the right functions +* traced. +*/ +if (update) +ftrace_update_ftrace_func (ftrace_ops_list_func); +if (command &FTRACE_UPDATE_CALLS )ftrace_replace_code (1 );else if (command &FTRACE_DISABLE_CALLS )ftrace_replace_code (0 ); -if (command &FTRACE_UPDATE_TRACE_FUNC ) +if (update && ftrace_trace_function != ftrace_ops_list_func)ftrace_update_ftrace_func (ftrace_trace_function);if (command &FTRACE_START_FUNC_RET )
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 3/18 ftrace/rcu: Do not trace debug_lockdep_rcu_enabled()
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
The function debug_lockdep_rcu_enabled() is part of the RCU lockdep debugging, and is called very frequently. I found that if I enable a lot of debugging and run the function graph tracer, this function can cause a live lock of the system.
We don't usually trace lockdep infrastructure, no need to trace this either.
--- kernel/rcupdate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcupdate.c +1 -1
@@ -122,7 +122,7 @@ struct lockdep_map rcu_sched_lock_map =STATIC_LOCKDEP_MAP_INIT ("rcu_read_lock_sched" , &rcu_sched_lock_key);EXPORT_SYMBOL_GPL (rcu_sched_lock_map); -int debug_lockdep_rcu_enabled (void ) +int notrace debug_lockdep_rcu_enabled(void) {return rcu_scheduler_active && debug_locks && current->lockdep_recursion ==0 ;
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 4/18 ftrace: Add hash list to save RCU unsafe functions
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Some ftrace function tracing callbacks use RCU (perf), thus if it gets called from tracing a function outside of the RCU tracking, like in entering or leaving NO_HZ idle/userspace, the RCU read locks in the callback are useless.
As normal function tracing does not use RCU, and function tracing happens to help debug RCU, we do not want to limit all callbacks from tracing these "unsafe" RCU functions. Instead, we create an infrastructure that will let us mark these unsafe RCU functions and we will only allow callbacks that explicitly say they do not use RCU to be called by these functions.
This patch adds the infrastructure to create the hash of functions that are RCU unsafe. This is done with the FTRACE_UNSAFE_RCU() macro. It works like EXPORT_SYMBOL() does. Simply place the macro under the RCU unsafe function:
void func(void)
{
[...]
}FTRACE_UNSAFE_RCU(func);
--- include/asm-generic/vmlinux.lds.h | 10 +++ include/linux/ftrace.h | 38 +++++++++++ kernel/trace/ftrace.c | 135 ++++++++++++++++++++++++++++++++++--- 3 files changed, 174 insertions(+), 9 deletions(-)
include/asm-generic/vmlinux.lds.h +10 -0
@@ -93,6 +93,15 @@#define MCOUNT_REC ()#endif +#ifdef CONFIG_FUNCTION_TRACER +#define FTRACE_UNSAFE_RCU () . = ALIGN(8); \ + VMLINUX_SYMBOL(__start_ftrace_unsafe_rcu) = .; \ + *(_ftrace_unsafe_rcu) \ + VMLINUX_SYMBOL(__stop_ftrace_unsafe_rcu) = .; +#else +#define FTRACE_UNSAFE_RCU () +#endif +#ifdef CONFIG_TRACE_BRANCH_PROFILING #define LIKELY_PROFILE () VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \ *(_ftrace_annotated_branch) \
@@ -479,6 +488,7 @@ MEM_DISCARD(init.data) \ KERNEL_CTORS() \ MCOUNT_REC() \ +FTRACE_UNSAFE_RCU () \ *(.init.rodata) \ FTRACE_EVENTS() \TRACE_SYSCALLS () \
include/linux/ftrace.h +38 -0
@@ -92,6 +92,9 @@ typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,* STUB - The ftrace_ops is just a place holder. * INITIALIZED - The ftrace_ops has already been initialized (first use time * register_ftrace_function() is called, it will initialized the ops) +* RCU_SAFE - The callback uses no rcu type locking. This allows the +* callback to be called in locations that RCU is not active. +* (like going into or coming out of idle NO_HZ) */ enum {FTRACE_OPS_FL_ENABLED =1 <<0 ,
@@ -103,6 +106,7 @@ enum {FTRACE_OPS_FL_RECURSION_SAFE =1 <<6 ,FTRACE_OPS_FL_STUB =1 <<7 ,FTRACE_OPS_FL_INITIALIZED =1 <<8 , + FTRACE_OPS_FL_RCU_SAFE = 1 << 9, }; struct ftrace_ops {
@@ -219,6 +223,40 @@ static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)extern void ftrace_stub (unsigned long a0,unsigned long a1,struct ftrace_ops *op,struct pt_regs *regs); +/* +* In order to speed up boot, save both the name and the +* address of the function to find to add to hashes. The +* list of function mcount addresses are sorted by the address, +* but we still need to use the name to find the actual location +* as the mcount call is usually not at the address of the +* start of the function. +*/ +struct ftrace_func_finder { +const char *name; +unsigned long ip; +}; + +/* +* For functions that are called when RCU is not tracking the CPU +* (like for entering or leaving NO_HZ mode, and RCU then ignores +* the CPU), they need to be marked with FTRACE_UNSAFE_RCU(). +* This will prevent all function tracing callbacks from calling +* this function unless the callback explicitly states that it +* doesn't use RCU with the FTRACE_OPS_FL_RCU_SAFE flag. +* +* The usage of FTRACE_UNSAFE_RCU() is the same as EXPORT_SYMBOL(). +* Just place the macro underneath the function that is unsafe. +*/ +#define FTRACE_UNSAFE_RCU (func) \ + static struct ftrace_func_finder __ftrace_unsafe_rcu_##func \ + __initdata = { \ + .name = #func, \ + .ip = (unsigned long)func, \ + }; \ + struct ftrace_func_finder *__ftrace_unsafe_rcu_ptr_##func \ + __attribute__((__section__("_ftrace_unsafe_rcu"))) = \ + &__ftrace_unsafe_rcu_##func +#else /* !CONFIG_FUNCTION_TRACER */ /* * (un)register_ftrace_function must be a macro since the ops parameter
kernel/trace/ftrace.c +126 -9
165 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 5/18 ftrace: Do not set ftrace records for unsafe RCU when not allowed
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
For the ftrace_ops that use RCU read locks, and can not be called by unsafe RCU functions (those outside of RCU tracking), have them not update the RCU unsafe function records when they are being registered or unregistered.
The ftrace function records store a counter of all the ftrace_ops callbacks that are hooked to the function the record represents. As unsafe RCU functions should not call callbacks that do not specify that they do not use RCU, do not update those records for ops that do not specify they are RCU safe.
--- kernel/trace/ftrace.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
kernel/trace/ftrace.c +17 -2
@@ -1168,6 +1168,12 @@ static struct ftrace_page *ftrace_new_pgs;static struct ftrace_page *ftrace_pages_start;static struct ftrace_page *ftrace_pages; +/* +* Hash of functions that are not safe to be called by +* callbacks that use RCU read locks. +*/ +static struct ftrace_hash *ftrace_unsafe_rcu; +static bool ftrace_hash_empty (struct ftrace_hash *hash) {return !hash || !hash->count;
@@ -1638,6 +1644,7 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops, {struct ftrace_hash *hash;struct ftrace_hash *other_hash; +struct ftrace_hash *rcu_hash;struct ftrace_page *pg;struct dyn_ftrace *rec;int count =0 ;
@@ -1647,6 +1654,12 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops,if (!(ops->flags &FTRACE_OPS_FL_ENABLED ))return ; +/* Ignore rcu unsafe functions unless ops handles them */ +if (ops->flags &FTRACE_OPS_FL_RCU_SAFE ) + rcu_hash =NULL ; +else + rcu_hash = ftrace_unsafe_rcu; +/* * In the filter_hash case: * If the count is zero, we update all records.
@@ -1680,6 +1693,10 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops,int in_hash =0 ;int match =0 ; +/* Ignore all in the rcu unsafe hash */ +if (ftrace_lookup_ip (rcu_hash, rec->ip)) +continue ; +if (all) {/* * Only the filter_hash affects all records.
@@ -4306,8 +4323,6 @@ struct notifier_block ftrace_module_exit_nb = {extern struct ftrace_func_finder *__start_ftrace_unsafe_rcu[];extern struct ftrace_func_finder *__stop_ftrace_unsafe_rcu[]; -static struct ftrace_hash *ftrace_unsafe_rcu; -static void __init create_unsafe_rcu_hash (void ) {struct ftrace_func_finder *finder;
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 6/18 ftrace: Set ftrace internal function tracing RCU safe
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Since none of the internal ftrace function tracing uses RCU in their callbacks, it is OK to set the global_ops (the one that they all use) to RCU safe.
--- kernel/trace/ftrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/ftrace.c +3 -1
@@ -1146,7 +1146,9 @@ static struct ftrace_ops global_ops = { .func = ftrace_stub, .notrace_hash = EMPTY_HASH, .filter_hash = EMPTY_HASH, - .flags = FTRACE_OPS_FL_RECURSION_SAFE | FTRACE_OPS_FL_INITIALIZED, + .flags =FTRACE_OPS_FL_RECURSION_SAFE | +FTRACE_OPS_FL_INITIALIZED | +FTRACE_OPS_FL_RCU_SAFE , INIT_REGEX_LOCK(global_ops) };
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 7/18 ftrace: Add test for ops against unsafe RCU functions in callback
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
When more than one ftrace_ops is registered, the list function is used to call all registered functions. It uses the filter and notrace hashes from the ftrace_ops to determine if the corresponding callback should be called or not.
Currently, it does not take into account for RCU unsafe functions. If multiple functions are registered, and an RCU safe callback is used on a RCU unsafe function, and the RCU unsafe callback says to trace all functions, it will end up tracing this RCU unsafe function and still suffer the problems when using RCU when RCU tracing is off.
Add a test to the multiple ops list function to test if the ops in question can use an RCU unsafe function or not, and if the function being traced happens to be an RCU unsafe function.
--- kernel/trace/ftrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/ftrace.c +3 -1
@@ -1480,7 +1480,9 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs)if ((ftrace_hash_empty (filter_hash) ||ftrace_lookup_ip (filter_hash, ip)) && (ftrace_hash_empty (notrace_hash) || - !ftrace_lookup_ip (notrace_hash, ip))) + !ftrace_lookup_ip (notrace_hash, ip)) && + (ops->flags &FTRACE_OPS_FL_RCU_SAFE || + !ftrace_lookup_ip (ftrace_unsafe_rcu, ip))) ret =1 ;else ret =0 ;
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 8/18 ftrace: Do not display non safe RCU functions in available_filter_functions
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
As available_filter_functions file displays functions that are generally available for tracing, do not show the ones that are RCU unsafe. Otherwise it may be confusing for perf users to see these functions in this file but not be able to trace them.
--- include/linux/ftrace.h | 1 + kernel/trace/ftrace.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
include/linux/ftrace.h +1 -0
@@ -411,6 +411,7 @@ enum {FTRACE_ITER_DO_HASH = (1 <<3 ),FTRACE_ITER_HASH = (1 <<4 ),FTRACE_ITER_ENABLED = (1 <<5 ), + FTRACE_ITER_NO_UNSAFE = (1 << 6), };void arch_ftrace_update_code (int command);
kernel/trace/ftrace.c +5 -1
@@ -2660,7 +2660,10 @@ t_next(struct seq_file *m, void *v, loff_t *pos) !ftrace_lookup_ip(ops->notrace_hash, rec->ip)) || ((iter->flags & FTRACE_ITER_ENABLED) && - !(rec->flags & FTRACE_FL_ENABLED))) { + !(rec->flags & FTRACE_FL_ENABLED)) || + + ((iter->flags & FTRACE_ITER_NO_UNSAFE) && + ftrace_lookup_ip(ftrace_unsafe_rcu, rec->ip))) { rec =NULL ; goto retry;
@@ -2788,6 +2791,7 @@ ftrace_avail_open(struct inode *inode, struct file *file) iter =__seq_open_private (file, &show_ftrace_seq_ops,sizeof (*iter));if (iter) { iter->pg = ftrace_pages_start; + iter->flags =FTRACE_ITER_NO_UNSAFE ; iter->ops = &global_ops; }
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 9/18 ftrace: Add rcu_unsafe_filter_functions file
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Since the RCU unsafe functions are no longer displayed by the available_filter_functions, we still need a way to see these functions in order to trace them. Create a new file that lists the functions that were declared RCU unsafe.
--- include/linux/ftrace.h | 1 + kernel/trace/ftrace.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
include/linux/ftrace.h +1 -0
@@ -412,6 +412,7 @@ enum {FTRACE_ITER_HASH = (1 <<4 ),FTRACE_ITER_ENABLED = (1 <<5 ),FTRACE_ITER_NO_UNSAFE = (1 <<6 ), + FTRACE_ITER_UNSAFE_ONLY = (1 << 7), };void arch_ftrace_update_code (int command);
kernel/trace/ftrace.c +31 -0
@@ -2662,6 +2662,9 @@ t_next(struct seq_file *m, void *v, loff_t *pos) ((iter->flags &FTRACE_ITER_ENABLED ) && !(rec->flags &FTRACE_FL_ENABLED )) || + ((iter->flags &FTRACE_ITER_UNSAFE_ONLY ) && + !ftrace_lookup_ip (ftrace_unsafe_rcu, rec->ip)) || + ((iter->flags &FTRACE_ITER_NO_UNSAFE ) && ftrace_lookup_ip(ftrace_unsafe_rcu, rec->ip))) {
@@ -2799,6 +2802,24 @@ ftrace_avail_open(struct inode *inode, struct file *file) }static int +ftrace_rcu_unsafe_open (struct inode *inode,struct file *file) +{ +struct ftrace_iterator *iter; + +if (unlikely (ftrace_disabled)) +return -ENODEV ; + + iter =__seq_open_private (file, &show_ftrace_seq_ops,sizeof (*iter)); +if (iter) { + iter->pg = ftrace_pages_start; + iter->flags =FTRACE_ITER_UNSAFE_ONLY ; + iter->ops = &global_ops; + } + +return iter ?0 : -ENOMEM ; +} + +static int ftrace_enabled_open (struct inode *inode,struct file *file) {struct ftrace_iterator *iter;
@@ -3850,6 +3871,13 @@ static const struct file_operations ftrace_avail_fops = { .release = seq_release_private, }; +static const struct file_operations ftrace_rcu_unsafe_fops = { + .open = ftrace_rcu_unsafe_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release_private, +}; +static const struct file_operations ftrace_enabled_fops = { .open = ftrace_enabled_open, .read = seq_read,
@@ -4086,6 +4114,9 @@ static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)trace_create_file ("available_filter_functions" ,0444 , d_tracer,NULL , &ftrace_avail_fops); +trace_create_file ("rcu_unsafe_filter_functions" ,0444 , + d_tracer,NULL , &ftrace_rcu_unsafe_fops); +trace_create_file ("enabled_functions" ,0444 , d_tracer,NULL , &ftrace_enabled_fops);
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 10/18 ftrace: Add selftest to check if RCU unsafe functions are filtered properly
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Add a boot time start up test that has a RCU safe ftrace_ops as well as an unsafe one. Make sure the RCU safe ops can trace RCU unsafe functions while the unsafe ftrace_ops can not.
--- kernel/trace/trace.h | 2 + kernel/trace/trace_selftest.c | 94 +++++++++++++++++++++++++++++++++ kernel/trace/trace_selftest_dynamic.c | 7 +++ 3 files changed, 103 insertions(+)
kernel/trace/trace.h +2 -0
@@ -648,6 +648,8 @@ extern unsigned long ftrace_update_tot_cnt;extern int DYN_FTRACE_TEST_NAME (void );#define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2extern int DYN_FTRACE_TEST_NAME2 (void ); +#define DYN_FTRACE_TEST_RCU_UNSAFE trace_selftest_dynamic_test_rcu_unsafe +extern int DYN_FTRACE_TEST_RCU_UNSAFE (void );extern bool ring_buffer_expanded;extern bool tracing_selftest_disabled;
kernel/trace/trace_selftest.c +94 -0
106 lines not on this page · raw message
kernel/trace/trace_selftest_dynamic.c +7 -0
@@ -11,3 +11,10 @@ int DYN_FTRACE_TEST_NAME2(void)/* used to call mcount */ return 0 ; } + +int trace_selftest_dynamic_test_rcu_unsafe (void ) +{ +/* used to call mcount */ +return 0 ; +} +FTRACE_UNSAFE_RCU (trace_selftest_dynamic_test_rcu_unsafe);
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 11/18 ftrace: Create a RCU unsafe checker
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Knowing what functions are not safe to be traced by callbacks that use RCU read locks, is not easy to figure out. By adding a function tracer callback that is set as a non RCU safe callback that also uses rcu_read_lock() and enables PROVE_RCU, it can be used to find locations in the kernel that need to be tagged with FTRACE_UNSAFE_RCU().
On boot up, this callback gets registered so that all functions are being traced, and there's no way to turn this off. In the future we can make this enabled or disabled at run time, but for now it's only used for debugging and should not be enabled by normal users.
--- kernel/trace/Kconfig | 22 ++++++++++++++++++ kernel/trace/ftrace.c | 12 ++++++++++ kernel/trace/trace.h | 3 +++ kernel/trace/trace_functions.c | 48 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 84 insertions(+), 1 deletion(-)
kernel/trace/Kconfig +22 -0
@@ -489,6 +489,28 @@ config FTRACE_MCOUNT_RECORD config FTRACE_SELFTEST bool +config FTRACE_UNSAFE_RCU_CHECKER + bool "Trace for unsafe RCU callers" + depends on DYNAMIC_FTRACE + depends on PROVE_LOCKING + select PROVE_RCU + help + Some function tracing callbacks use RCU read lock (namely perf). + There are some RCU critical functions that are called out + of scope for RCU. For example, when NO_HZ_FULL is enabled, + and coming out of user space. The CPU is not being tracked by + RCU and all rcu_read_lock()s will be ignored. These functions + need to be tagged as unsafe for RCU so that only function callbacks + that specify that they do not use RCU will be called by them. + + This option will enable PROVE_RCU and will enable on boot up + a function callback that traces all functions and uses an + rcu_read_lock(). If any function that is not tagged as unsafe + for RCU is called, a debug splat will be shown. This is used + for finding unsafe RCU callers that need to be tagged. + + If you don't understand any of this, then say N. + config FTRACE_STARTUP_TEST bool "Perform a startup test on ftrace" depends on GENERIC_TRACER
kernel/trace/ftrace.c +12 -0
@@ -1359,6 +1359,13 @@ alloc_and_copy_ftrace_hash(int size_bits, struct ftrace_hash *hash)return NULL ; } +#ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER +bool ftrace_rcu_unsafe (unsigned long addr) +{ +return ftrace_lookup_ip (ftrace_unsafe_rcu, addr) !=NULL ; +} +#endif +static void ftrace_hash_rec_disable (struct ftrace_ops *ops,int filter_hash); static void
@@ -4391,6 +4398,11 @@ static void __init create_unsafe_rcu_hash(void)if (WARN_ON_ONCE (strcmp (str, finder->name) !=0 ))continue ; +#ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER +/* When checker is enabled, show what was marked unsafe */ +pr_info ("add ftrace rcu unsafe %p (%s)\n" , + (void *)ip, finder->name); +#endif add_hash_entry (ftrace_unsafe_rcu, ip); } }
kernel/trace/trace.h +3 -0
@@ -760,6 +760,9 @@ static inline int ftrace_graph_addr(unsigned long addr) return 0; } +#ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER +extern bool ftrace_rcu_unsafe (unsigned long addr); +#endif #else static inline int ftrace_graph_addr (unsigned long addr) {
kernel/trace/trace_functions.c +47 -1
56 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 12/18 ftrace: Add infrastructure to stop RCU unsafe checker from checking
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
This is a light weight way to keep the rcu checker from checking RCU safety. It adds a ftrace_unsafe_rcu_checker_disable/enable() that increments or decrements a counter respectively. When the counter is set, the RCU unsafe checker callback does not run the tests to see if RCU is safe or not. But the callback still gets called. It just does not call rcu_read_(un)lock().
This is required by the graph tracer because the checks can cause the graph tracer to live lock the system by its own calls. That is, the graph tracer will still trace rcu and the rcu debugging, and this will slow down the checker, which is still calling all other functions (in interrupts and faults), which can cause the timer interrupt to take oven a millisecond to complete, and it will then trigger once it finishes, live locking the system.
It's also needed by the irqsoff tracer, because it may be called in RCU unsafe regions and if its internal functions get traced then the RCU unsafe checker may have some false positives.
--- kernel/trace/trace.h | 12 +++++++++--- kernel/trace/trace_functions.c | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-)
kernel/trace/trace.h +9 -3
@@ -760,9 +760,6 @@ static inline int ftrace_graph_addr(unsigned long addr) return 0; } -#ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER -extern bool ftrace_rcu_unsafe (unsigned long addr); -#endif #else static inline int ftrace_graph_addr (unsigned long addr) {
@@ -1061,4 +1058,13 @@ int perf_ftrace_event_register(struct ftrace_event_call *call,#define perf_ftrace_event_register NULL#endif +#ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER +extern bool ftrace_rcu_unsafe (unsigned long addr); +extern void ftrace_unsafe_rcu_checker_disable (void ); +extern void ftrace_unsafe_rcu_checker_enable (void ); +#else +static inline void ftrace_unsafe_rcu_checker_disable (void ) { } +static inline void ftrace_unsafe_rcu_checker_enable (void ) { } +#endif +#endif /* _LINUX_KERNEL_TRACE_H */
kernel/trace/trace_functions.c +22 -0
@@ -560,12 +560,34 @@ static inline int init_func_cmd_traceon(void)#endif /* CONFIG_DYNAMIC_FTRACE */ #ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER + static DEFINE_PER_CPU(int, ftrace_rcu_running); +static atomic_t ftrace_unsafe_rcu_disabled; + +void ftrace_unsafe_rcu_checker_disable (void ) +{ +atomic_inc (&ftrace_unsafe_rcu_disabled); +/* Make sure the update is seen immediately */ +smp_mb__after_atomic_inc (); +} + +void ftrace_unsafe_rcu_checker_enable (void ) +{ +atomic_dec (&ftrace_unsafe_rcu_disabled); +/* Make sure the update is seen immediately */ +smp_mb__after_atomic_dec (); +} +static void ftrace_unsafe_callback (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct pt_regs *pt_regs) { +/* Make sure we see disabled or not first */ +smp_rmb (); +if (atomic_read (&ftrace_unsafe_rcu_disabled)) +return ; +preempt_disable_notrace ();if (this_cpu_read (ftrace_rcu_running))
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 13/18 ftrace: Disable RCU unsafe checker when function graph is enabled
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Having the RCU unsafe checker running when function graph is enabled can cause a live lock. That's because the RCU unsafe checker enables full lockdep debugging on RCU which does a lot of internal calls that may be traced by the function graph tracer. This adds quite a bit of overhead and can possibly live lock the system by causing the timer interrupt to take longer than 1 HZ.
Just do not do the RCU unsafe checks when function graph tracer is enabled.
--- kernel/trace/ftrace.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/trace/ftrace.c +7 -0
@@ -5118,6 +5118,12 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc, goto out; } +/* +* The Unsafe RCU checker can live lock function graph tracing. +* It's best to just disable it while doing the fgraph tracing. +*/ +ftrace_unsafe_rcu_checker_disable (); + ftrace_graph_return = retfunc; ftrace_graph_entry = entryfunc;
@@ -5141,6 +5147,7 @@ void unregister_ftrace_graph(void)ftrace_shutdown (&global_ops,FTRACE_STOP_FUNC_RET );unregister_pm_notifier (&ftrace_suspend_notifier);unregister_trace_sched_switch (ftrace_graph_probe_sched_switch,NULL ); +ftrace_unsafe_rcu_checker_enable (); out:mutex_unlock (&ftrace_lock);
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 14/18 ftrace: Disable the RCU unsafe checker when irqsoff is enabled
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
The irqsoff tracer can be called during some of the RCU unsafe regions. The problem is that some of the internal calls that it makes may also be traced. For example, it uses spin locks. But if the spin lock gets traced and the RCU unsafe checker runs, it will trigger that RCU is not safe to use. But the only reason a spin lock is being used in an RCU unsafe region is because the irqsoff trace uses it, and causes a false positive.
Disable the unsafe RCU checker when irqsoff is enabled.
--- kernel/trace/trace_irqsoff.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
kernel/trace/trace_irqsoff.c +14 -2
@@ -584,9 +584,14 @@ static int start_irqsoff_tracer(struct trace_array *tr, int graph) ret =register_irqsoff_function (graph,0 ); -if (!ret &&tracing_is_enabled ()) +if (!ret &&tracing_is_enabled ()) { +/* +* irqsoff tracer can cause unsafe rcu checker +* to have false positives. +*/ +ftrace_unsafe_rcu_checker_disable (); tracer_enabled =1 ; -else + }else tracer_enabled =0 ;return ret;
@@ -594,6 +599,9 @@ static int start_irqsoff_tracer(struct trace_array *tr, int graph)static void stop_irqsoff_tracer (struct trace_array *tr,int graph) { +if (tracer_enabled) +ftrace_unsafe_rcu_checker_enable (); + tracer_enabled =0 ;unregister_irqsoff_function (graph);
@@ -630,11 +638,15 @@ static void irqsoff_tracer_reset(struct trace_array *tr)static void irqsoff_tracer_start (struct trace_array *tr) { +if (!tracer_enabled) +ftrace_unsafe_rcu_checker_disable (); tracer_enabled =1 ; }static void irqsoff_tracer_stop (struct trace_array *tr) { +if (tracer_enabled) +ftrace_unsafe_rcu_checker_enable (); tracer_enabled =0 ; }
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 15/18 ftrace/lockdep: Have the RCU lockdep splat show what function triggered
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
When the RCU lockdep splat hits because of the unsafe RCU checker, the backtrace does not always show the culprit. But the culprit was passed to the unsafe RCU checker.
Save the ip of the function being traced in a per_cpu variable, and when the RCU lockdep detects a problem, it can also print out what function was being traced if it was caused by the unsafe RCU checker.
--- include/linux/ftrace.h | 6 ++++++ kernel/lockdep.c | 2 ++ kernel/trace/trace_functions.c | 14 +++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-)
include/linux/ftrace.h +6 -0
@@ -885,4 +885,10 @@ unsigned long arch_syscall_addr(int nr);#endif /* CONFIG_FTRACE_SYSCALLS */ +#ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER +extern void print_ftrace_rcu_func (int cpu); +#else +static inline void print_ftrace_rcu_func (int cpu) { } +#endif +#endif /* _LINUX_FTRACE_H */
kernel/lockdep.c +2 -0
@@ -4229,6 +4229,8 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s) : "", rcu_scheduler_active, debug_locks); +print_ftrace_rcu_func (raw_smp_processor_id ()); +/* * If a CPU is in the RCU-free window in idle (ie: in the section * between rcu_idle_enter() and rcu_idle_exit(), then RCU
kernel/trace/trace_functions.c +13 -1
@@ -562,7 +562,6 @@ static inline int init_func_cmd_traceon(void)#ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER static DEFINE_PER_CPU(int, ftrace_rcu_running); -static atomic_t ftrace_unsafe_rcu_disabled;void ftrace_unsafe_rcu_checker_disable (void )
@@ -579,6 +578,17 @@ void ftrace_unsafe_rcu_checker_enable(void)smp_mb__after_atomic_dec (); } +static DEFINE_PER_CPU(unsigned long, ftrace_rcu_func); + +void print_ftrace_rcu_func (int cpu) +{ +unsigned long ip =per_cpu (ftrace_rcu_func, cpu); + +if (ip) +printk ("ftrace_rcu_func: %pS\n" , + (void *)per_cpu (ftrace_rcu_func, cpu)); +} +static void ftrace_unsafe_callback (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct pt_regs *pt_regs)
@@ -599,10 +609,12 @@ ftrace_unsafe_callback(unsigned long ip, unsigned long parent_ip, goto out;this_cpu_write (ftrace_rcu_running,1 ); +this_cpu_write (ftrace_rcu_func, ip);/* Should trigger a RCU splat if called from unsafe RCU function */ rcu_read_lock ();rcu_read_unlock (); +this_cpu_write (ftrace_rcu_func,0 );this_cpu_write (ftrace_rcu_running,0 ); out:
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 16/18 ftrace/rcu: Mark functions that are RCU unsafe
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Some callbacks of the function tracer use rcu_read_lock(). This means that there's places that can not be traced because RCU is not tracking the CPU for various reasons (like NO_HZ_FULL and coming back from userspace).
These functions need to be marked so that callbacks that use RCU do not trace them.
--- kernel/rcutiny.c | 1 + kernel/rcutree.c | 7 +++++++ 2 files changed, 8 insertions(+)
kernel/rcutiny.c +1 -0
@@ -173,6 +173,7 @@ void rcu_irq_enter(void)local_irq_restore (flags); }EXPORT_SYMBOL_GPL (rcu_irq_enter); +FTRACE_UNSAFE_RCU (rcu_irq_enter);#ifdef CONFIG_DEBUG_LOCK_ALLOC
kernel/rcutree.c +7 -0
@@ -53,6 +53,7 @@#include <linux/delay.h> #include <linux/stop_machine.h> #include <linux/random.h> +#include <linux/ftrace.h> #include "rcutree.h" #include <trace/events/rcu.h>
@@ -373,6 +374,7 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,rcu_lockdep_assert (!lock_is_held (&rcu_sched_lock_map),"Illegal idle entry in RCU-sched read-side critical section." ); } +FTRACE_UNSAFE_RCU (rcu_eqs_enter_common);/* * Enter an RCU extended quiescent state, which can be either the
@@ -392,6 +394,7 @@ static void rcu_eqs_enter(bool user) rdtp->dynticks_nesting -=DYNTICK_TASK_NEST_VALUE ;rcu_eqs_enter_common (rdtp, oldval, user); } +FTRACE_UNSAFE_RCU (rcu_eqs_enter);/** * rcu_idle_enter - inform RCU that current CPU is entering idle
@@ -513,6 +516,7 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval, idle->pid, idle->comm); /* must be idle task! */ } } +FTRACE_UNSAFE_RCU (rcu_eqs_exit_common);/* * Exit an RCU extended quiescent state, which can be either the
@@ -553,6 +557,7 @@ void rcu_idle_exit(void)local_irq_restore (flags); }EXPORT_SYMBOL_GPL (rcu_idle_exit); +FTRACE_UNSAFE_RCU (rcu_idle_exit);#ifdef CONFIG_RCU_USER_QS /**
@@ -565,6 +570,7 @@ void rcu_user_exit(void) {rcu_eqs_exit (1 ); } +FTRACE_UNSAFE_RCU (rcu_user_exit);/** * rcu_user_exit_after_irq - inform RCU that we won't resume to userspace
@@ -625,6 +631,7 @@ void rcu_irq_enter(void)rcu_eqs_exit_common (rdtp, oldval, true);local_irq_restore (flags); } +FTRACE_UNSAFE_RCU (rcu_irq_enter);/** * rcu_nmi_enter - inform RCU of entry to NMI context
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerRe: [for-next][PATCH 16/18] ftrace/rcu: Mark functions that are RCU unsafe
kernel/rcutiny.c
Quoted 7 lines · On Wed, 04 Sep 2013 10:36:08 -0400 Steven Rostedt <[email protected]> wrote:
From: "Steven Rostedt (Red Hat)" <[email protected]>
kernel/rcutiny.c +0
-0
Wu's bot discovered that rcutiny.c is missing an include to ftrace.h.
Here's the change I made to this, and will rebase linux-next again to have this. (Hopefully, Stephen hasn't pulled this branch in yet).
kernel/rcutiny.c +1 -0
@@ -28,6 +28,7 @@#include <linux/rcupdate.h> #include <linux/kernel.h> #include <linux/export.h> +#include <linux/ftrace.h> #include <linux/mutex.h> #include <linux/sched.h> #include <linux/types.h>
-- Steve
Quoted 20 lines
kernel/rcutiny.c +1
-0@@ -173,6 +173,7 @@ void rcu_irq_enter(void)local_irq_restore (flags); }EXPORT_SYMBOL_GPL (rcu_irq_enter); +FTRACE_UNSAFE_RCU (rcu_irq_enter);#ifdef CONFIG_DEBUG_LOCK_ALLOC kernel/rcutree.c +1
-0@@ -53,6 +53,7 @@#include <linux/delay.h> #include <linux/stop_machine.h> #include <linux/random.h> +#include <linux/ftrace.h> #include "rcutree.h" #include <trace/events/rcu.h>
Steven Rostedt
maintainerPATCH 17/18 ftrace/cpuidle/x86: Mark functions that are RCU unsafe
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Some callbacks of the function tracer use rcu_read_lock(). This means that there's places that can not be traced because RCU is not tracking the CPU for various reasons (like NO_HZ_FULL and coming back from userspace).
These functions need to be marked so that callbacks that use RCU do not trace them.
--- arch/x86/kernel/process.c | 2 ++ drivers/cpuidle/cpuidle.c | 2 ++ kernel/cpu/idle.c | 2 ++ 3 files changed, 6 insertions(+)
arch/x86/kernel/process.c +2 -0
@@ -17,6 +17,7 @@#include <linux/stackprotector.h> #include <linux/tick.h> #include <linux/cpuidle.h> +#include <linux/ftrace.h> #include <trace/events/power.h> #include <linux/hw_breakpoint.h> #include <asm/cpu.h>
@@ -316,6 +317,7 @@ void default_idle(void)#ifdef CONFIG_APM_MODULE EXPORT_SYMBOL (default_idle);#endif +FTRACE_UNSAFE_RCU (default_idle);#ifdef CONFIG_XEN bool xen_set_default_idle (void )
drivers/cpuidle/cpuidle.c +2 -0
@@ -19,6 +19,7 @@#include <linux/ktime.h> #include <linux/hrtimer.h> #include <linux/module.h> +#include <linux/ftrace.h> #include <trace/events/power.h> #include "cpuidle.h"
@@ -168,6 +169,7 @@ int cpuidle_idle_call(void)return 0 ; } +FTRACE_UNSAFE_RCU (cpuidle_idle_call);/** * cpuidle_install_idle_handler - installs the cpuidle idle loop handler
kernel/cpu/idle.c +2 -0
@@ -5,6 +5,7 @@#include <linux/cpu.h> #include <linux/tick.h> #include <linux/mm.h> +#include <linux/ftrace.h> #include <linux/stackprotector.h> #include <asm/tlb.h>
@@ -61,6 +62,7 @@ void __weak arch_cpu_idle(void) cpu_idle_force_poll =1 ;local_irq_enable (); } +FTRACE_UNSAFE_RCU (arch_cpu_idle);/* * Generic idle loop implementation
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 18/18 ftrace: Print a message when the rcu checker is disabled
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Let the user know that the RCU safety checker for function tracing has been disabled. The checker only runs when the user specifically configures it in the kernel, and this is done to search for locations in the kernel that may be unsafe for a function trace callback to use rcu_read_lock()s. But if things like function graph tracing is started, which can live lock the machine when the checker is running, it is disabled. It would be nice if the kernel let the user know that the checker is disabled, and when it is re-enabled again.
As the checker only gets disabled and re-enabled by user actions (starting and stoping the function graph tracer or the irqsoff tracer) it is fine to have a printk display that it is disabled or not.
--- kernel/trace/trace_functions.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/trace/trace_functions.c +4 -0
@@ -569,6 +569,8 @@ void ftrace_unsafe_rcu_checker_disable(void)atomic_inc (&ftrace_unsafe_rcu_disabled);/* Make sure the update is seen immediately */ smp_mb__after_atomic_inc (); +pr_info ("Disabled FTRACE RCU checker (%pS)\n" , +__builtin_return_address (0 )); }void ftrace_unsafe_rcu_checker_enable (void )
@@ -576,6 +578,8 @@ void ftrace_unsafe_rcu_checker_enable(void)atomic_dec (&ftrace_unsafe_rcu_disabled);/* Make sure the update is seen immediately */ smp_mb__after_atomic_dec (); +pr_info ("Enabled FTRACE RCU checker (%pS)\n" , +__builtin_return_address (0 )); } static DEFINE_PER_CPU(unsigned long, ftrace_rcu_func);
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerQuoted 15 lines · On Wed, 04 Sep 2013 10:35:52 -0400 Steven Rostedt <[email protected]> wrote:
This is the latest patches to be queued for 3.12.
A little late, but as Dave Jones has been stumbling over this for a while, I thought it would be good to get it in now. It's not that complex to resolve any issues that may pop up.
I'll keep it in linux-next for a while to make sure it really is clean.
Note, the checker will stumble over a few functions in irq and scheduler code if enabled. This is because those patches have not received Acks from Thomas Gleixner and Peter Zijlstra. When I get those acks, I'll add the changes to silent those too.
Thanks to Paul McKenney for reviewing the patches.
Quoted 9 lines
Enjoy,
-- Steve
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-nextHead SHA1:
7fb3a66134ed5a40448131cf4195823d22f70aa3
Wu's autobot has found a few stupid mistakes (nothing big, but should be cleaned up before pushing to Linus). I reverted this change from my for-next tree, and I'm pushing to another branch. If I don't get more updates from Wu's checks by tomorrow, I'll push the updated branch to for-next again.
-- Steve