diff options
author | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2017-04-14 17:45:45 -0400 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2017-04-15 17:04:37 -0400 |
commit | acceb72e90624ec6c3f2fc62e72dab892cd075da (patch) | |
tree | 3529cecc00d61587f0bdf849823b85edaa9917b0 /kernel/trace/ftrace.c | |
parent | d54b6eeb553c89ed8d4c5a2ed73df374a45b9562 (diff) |
ftrace: Fix removing of second function probe
When two function probes are added to set_ftrace_filter, and then one of
them is removed, the update to the function locations is not performed, and
the record keeping of the function states are corrupted, and causes an
ftrace_bug() to occur.
This is easily reproducable by adding two probes, removing one, and then
adding it back again.
# cd /sys/kernel/debug/tracing
# echo schedule:traceoff > set_ftrace_filter
# echo do_IRQ:traceoff > set_ftrace_filter
# echo \!do_IRQ:traceoff > /debug/tracing/set_ftrace_filter
# echo do_IRQ:traceoff > set_ftrace_filter
Causes:
------------[ cut here ]------------
WARNING: CPU: 2 PID: 1098 at kernel/trace/ftrace.c:2369 ftrace_get_addr_curr+0x143/0x220
Modules linked in: [...]
CPU: 2 PID: 1098 Comm: bash Not tainted 4.10.0-test+ #405
Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01 v02.05 05/07/2012
Call Trace:
dump_stack+0x68/0x9f
__warn+0x111/0x130
? trace_irq_work_interrupt+0xa0/0xa0
warn_slowpath_null+0x1d/0x20
ftrace_get_addr_curr+0x143/0x220
? __fentry__+0x10/0x10
ftrace_replace_code+0xe3/0x4f0
? ftrace_int3_handler+0x90/0x90
? printk+0x99/0xb5
? 0xffffffff81000000
ftrace_modify_all_code+0x97/0x110
arch_ftrace_update_code+0x10/0x20
ftrace_run_update_code+0x1c/0x60
ftrace_run_modify_code.isra.48.constprop.62+0x8e/0xd0
register_ftrace_function_probe+0x4b6/0x590
? ftrace_startup+0x310/0x310
? debug_lockdep_rcu_enabled.part.4+0x1a/0x30
? update_stack_state+0x88/0x110
? ftrace_regex_write.isra.43.part.44+0x1d3/0x320
? preempt_count_sub+0x18/0xd0
? mutex_lock_nested+0x104/0x800
? ftrace_regex_write.isra.43.part.44+0x1d3/0x320
? __unwind_start+0x1c0/0x1c0
? _mutex_lock_nest_lock+0x800/0x800
ftrace_trace_probe_callback.isra.3+0xc0/0x130
? func_set_flag+0xe0/0xe0
? __lock_acquire+0x642/0x1790
? __might_fault+0x1e/0x20
? trace_get_user+0x398/0x470
? strcmp+0x35/0x60
ftrace_trace_onoff_callback+0x48/0x70
ftrace_regex_write.isra.43.part.44+0x251/0x320
? match_records+0x420/0x420
ftrace_filter_write+0x2b/0x30
__vfs_write+0xd7/0x330
? do_loop_readv_writev+0x120/0x120
? locks_remove_posix+0x90/0x2f0
? do_lock_file_wait+0x160/0x160
? __lock_is_held+0x93/0x100
? rcu_read_lock_sched_held+0x5c/0xb0
? preempt_count_sub+0x18/0xd0
? __sb_start_write+0x10a/0x230
? vfs_write+0x222/0x240
vfs_write+0xef/0x240
SyS_write+0xab/0x130
? SyS_read+0x130/0x130
? trace_hardirqs_on_caller+0x182/0x280
? trace_hardirqs_on_thunk+0x1a/0x1c
entry_SYSCALL_64_fastpath+0x18/0xad
RIP: 0033:0x7fe61c157c30
RSP: 002b:00007ffe87890258 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: ffffffff8114a410 RCX: 00007fe61c157c30
RDX: 0000000000000010 RSI: 000055814798f5e0 RDI: 0000000000000001
RBP: ffff8800c9027f98 R08: 00007fe61c422740 R09: 00007fe61ca53700
R10: 0000000000000073 R11: 0000000000000246 R12: 0000558147a36400
R13: 00007ffe8788f160 R14: 0000000000000024 R15: 00007ffe8788f15c
? trace_hardirqs_off_caller+0xc0/0x110
---[ end trace 99fa09b3d9869c2c ]---
Bad trampoline accounting at: ffffffff81cc3b00 (do_IRQ+0x0/0x150)
Cc: stable@vger.kernel.org
Fixes: 59df055f1991 ("ftrace: trace different functions with a different tracer")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/ftrace.c')
-rw-r--r-- | kernel/trace/ftrace.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 34f63e78d661..4b6459a57fbc 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -3780,23 +3780,24 @@ static void __enable_ftrace_function_probe(struct ftrace_ops_hash *old_hash) | |||
3780 | ftrace_probe_registered = 1; | 3780 | ftrace_probe_registered = 1; |
3781 | } | 3781 | } |
3782 | 3782 | ||
3783 | static void __disable_ftrace_function_probe(void) | 3783 | static bool __disable_ftrace_function_probe(void) |
3784 | { | 3784 | { |
3785 | int i; | 3785 | int i; |
3786 | 3786 | ||
3787 | if (!ftrace_probe_registered) | 3787 | if (!ftrace_probe_registered) |
3788 | return; | 3788 | return false; |
3789 | 3789 | ||
3790 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { | 3790 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { |
3791 | struct hlist_head *hhd = &ftrace_func_hash[i]; | 3791 | struct hlist_head *hhd = &ftrace_func_hash[i]; |
3792 | if (hhd->first) | 3792 | if (hhd->first) |
3793 | return; | 3793 | return false; |
3794 | } | 3794 | } |
3795 | 3795 | ||
3796 | /* no more funcs left */ | 3796 | /* no more funcs left */ |
3797 | ftrace_shutdown(&trace_probe_ops, 0); | 3797 | ftrace_shutdown(&trace_probe_ops, 0); |
3798 | 3798 | ||
3799 | ftrace_probe_registered = 0; | 3799 | ftrace_probe_registered = 0; |
3800 | return true; | ||
3800 | } | 3801 | } |
3801 | 3802 | ||
3802 | 3803 | ||
@@ -3926,6 +3927,7 @@ static void | |||
3926 | __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | 3927 | __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, |
3927 | void *data, int flags) | 3928 | void *data, int flags) |
3928 | { | 3929 | { |
3930 | struct ftrace_ops_hash old_hash_ops; | ||
3929 | struct ftrace_func_entry *rec_entry; | 3931 | struct ftrace_func_entry *rec_entry; |
3930 | struct ftrace_func_probe *entry; | 3932 | struct ftrace_func_probe *entry; |
3931 | struct ftrace_func_probe *p; | 3933 | struct ftrace_func_probe *p; |
@@ -3937,6 +3939,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | |||
3937 | struct hlist_node *tmp; | 3939 | struct hlist_node *tmp; |
3938 | char str[KSYM_SYMBOL_LEN]; | 3940 | char str[KSYM_SYMBOL_LEN]; |
3939 | int i, ret; | 3941 | int i, ret; |
3942 | bool disabled; | ||
3940 | 3943 | ||
3941 | if (glob && (strcmp(glob, "*") == 0 || !strlen(glob))) | 3944 | if (glob && (strcmp(glob, "*") == 0 || !strlen(glob))) |
3942 | func_g.search = NULL; | 3945 | func_g.search = NULL; |
@@ -3955,6 +3958,10 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | |||
3955 | 3958 | ||
3956 | mutex_lock(&trace_probe_ops.func_hash->regex_lock); | 3959 | mutex_lock(&trace_probe_ops.func_hash->regex_lock); |
3957 | 3960 | ||
3961 | old_hash_ops.filter_hash = old_hash; | ||
3962 | /* Probes only have filters */ | ||
3963 | old_hash_ops.notrace_hash = NULL; | ||
3964 | |||
3958 | hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, *orig_hash); | 3965 | hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, *orig_hash); |
3959 | if (!hash) | 3966 | if (!hash) |
3960 | /* Hmm, should report this somehow */ | 3967 | /* Hmm, should report this somehow */ |
@@ -3992,12 +3999,17 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | |||
3992 | } | 3999 | } |
3993 | } | 4000 | } |
3994 | mutex_lock(&ftrace_lock); | 4001 | mutex_lock(&ftrace_lock); |
3995 | __disable_ftrace_function_probe(); | 4002 | disabled = __disable_ftrace_function_probe(); |
3996 | /* | 4003 | /* |
3997 | * Remove after the disable is called. Otherwise, if the last | 4004 | * Remove after the disable is called. Otherwise, if the last |
3998 | * probe is removed, a null hash means *all enabled*. | 4005 | * probe is removed, a null hash means *all enabled*. |
3999 | */ | 4006 | */ |
4000 | ret = ftrace_hash_move(&trace_probe_ops, 1, orig_hash, hash); | 4007 | ret = ftrace_hash_move(&trace_probe_ops, 1, orig_hash, hash); |
4008 | |||
4009 | /* still need to update the function call sites */ | ||
4010 | if (ftrace_enabled && !disabled) | ||
4011 | ftrace_run_modify_code(&trace_probe_ops, FTRACE_UPDATE_CALLS, | ||
4012 | &old_hash_ops); | ||
4001 | synchronize_sched(); | 4013 | synchronize_sched(); |
4002 | if (!ret) | 4014 | if (!ret) |
4003 | free_ftrace_hash_rcu(old_hash); | 4015 | free_ftrace_hash_rcu(old_hash); |