Skip to content

Commit f2d7cff

Browse files
mhiramatgregkh
authored andcommitted
tracing: Disable ftrace selftests when any tracer is running
commit 60efe21 upstream. Disable ftrace selftests when any tracer (kernel command line options like ftrace=, trace_events=, kprobe_events=, and boot-time tracing) starts running because selftest can disturb it. Currently ftrace= and trace_events= are checked, but kprobe_events has a different flag, and boot-time tracing didn't checked. This unifies the disabled flag and all of those boot-time tracing features sets the flag. This also fixes warnings on kprobe-event selftest (CONFIG_FTRACE_STARTUP_TEST=y and CONFIG_KPROBE_EVENTS=y) with boot-time tracing (ftrace.event.kprobes.EVENT.probes) like below; [ 59.803496] trace_kprobe: Testing kprobe tracing: [ 59.804258] ------------[ cut here ]------------ [ 59.805682] WARNING: CPU: 3 PID: 1 at kernel/trace/trace_kprobe.c:1987 kprobe_trace_self_tests_ib [ 59.806944] Modules linked in: [ 59.807335] CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.10.0-rc7+ torvalds#172 [ 59.808029] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1 04/01/204 [ 59.808999] RIP: 0010:kprobe_trace_self_tests_init+0x5f/0x42b [ 59.809696] Code: e8 03 00 00 48 c7 c7 30 8e 07 82 e8 6d 3c 46 ff 48 c7 c6 00 b2 1a 81 48 c7 c7 7 [ 59.812439] RSP: 0018:ffffc90000013e78 EFLAGS: 00010282 [ 59.813038] RAX: 00000000ffffffef RBX: 0000000000000000 RCX: 0000000000049443 [ 59.813780] RDX: 0000000000049403 RSI: 0000000000049403 RDI: 000000000002deb0 [ 59.814589] RBP: ffffc90000013e90 R08: 0000000000000001 R09: 0000000000000001 [ 59.815349] R10: 0000000000000001 R11: 0000000000000000 R12: 00000000ffffffef [ 59.816138] R13: ffff888004613d80 R14: ffffffff82696940 R15: ffff888004429138 [ 59.816877] FS: 0000000000000000(0000) GS:ffff88807dcc0000(0000) knlGS:0000000000000000 [ 59.817772] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 59.818395] CR2: 0000000001a8dd38 CR3: 0000000002222000 CR4: 00000000000006a0 [ 59.819144] Call Trace: [ 59.819469] ? init_kprobe_trace+0x6b/0x6b [ 59.819948] do_one_initcall+0x5f/0x300 [ 59.820392] ? rcu_read_lock_sched_held+0x4f/0x80 [ 59.820916] kernel_init_freeable+0x22a/0x271 [ 59.821416] ? rest_init+0x241/0x241 [ 59.821841] kernel_init+0xe/0x10f [ 59.822251] ret_from_fork+0x22/0x30 [ 59.822683] irq event stamp: 16403349 [ 59.823121] hardirqs last enabled at (16403359): [<ffffffff810db81e>] console_unlock+0x48e/0x580 [ 59.824074] hardirqs last disabled at (16403368): [<ffffffff810db786>] console_unlock+0x3f6/0x580 [ 59.825036] softirqs last enabled at (16403200): [<ffffffff81c0033a>] __do_softirq+0x33a/0x484 [ 59.825982] softirqs last disabled at (16403087): [<ffffffff81a00f02>] asm_call_irq_on_stack+0x10 [ 59.827034] ---[ end trace 200c544775cdfeb3 ]--- [ 59.827635] trace_kprobe: error on probing function entry. Link: https://lkml.kernel.org/r/160741764955.3448999.3347769358299456915.stgit@devnote2 Fixes: 4d65528 ("tracing/boot Add kprobe event support") Cc: Ingo Molnar <[email protected]> Cc: [email protected] Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 054c923 commit f2d7cff

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

kernel/trace/trace.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,21 @@ bool ring_buffer_expanded;
6868
static bool __read_mostly tracing_selftest_running;
6969

7070
/*
71-
* If a tracer is running, we do not want to run SELFTEST.
71+
* If boot-time tracing including tracers/events via kernel cmdline
72+
* is running, we do not want to run SELFTEST.
7273
*/
7374
bool __read_mostly tracing_selftest_disabled;
7475

76+
#ifdef CONFIG_FTRACE_STARTUP_TEST
77+
void __init disable_tracing_selftest(const char *reason)
78+
{
79+
if (!tracing_selftest_disabled) {
80+
tracing_selftest_disabled = true;
81+
pr_info("Ftrace startup test is disabled due to %s\n", reason);
82+
}
83+
}
84+
#endif
85+
7586
/* Pipe tracepoints to printk */
7687
struct trace_iterator *tracepoint_print_iter;
7788
int tracepoint_printk;
@@ -2113,11 +2124,7 @@ int __init register_tracer(struct tracer *type)
21132124
apply_trace_boot_options();
21142125

21152126
/* disable other selftests, since this will break it. */
2116-
tracing_selftest_disabled = true;
2117-
#ifdef CONFIG_FTRACE_STARTUP_TEST
2118-
printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n",
2119-
type->name);
2120-
#endif
2127+
disable_tracing_selftest("running a tracer");
21212128

21222129
out_unlock:
21232130
return ret;

kernel/trace/trace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,8 @@ extern bool ring_buffer_expanded;
896896
extern bool tracing_selftest_disabled;
897897

898898
#ifdef CONFIG_FTRACE_STARTUP_TEST
899+
extern void __init disable_tracing_selftest(const char *reason);
900+
899901
extern int trace_selftest_startup_function(struct tracer *trace,
900902
struct trace_array *tr);
901903
extern int trace_selftest_startup_function_graph(struct tracer *trace,
@@ -919,6 +921,9 @@ extern int trace_selftest_startup_branch(struct tracer *trace,
919921
*/
920922
#define __tracer_data __refdata
921923
#else
924+
static inline void __init disable_tracing_selftest(const char *reason)
925+
{
926+
}
922927
/* Tracers are seldom changed. Optimize when selftests are disabled. */
923928
#define __tracer_data __read_mostly
924929
#endif /* CONFIG_FTRACE_STARTUP_TEST */

kernel/trace/trace_boot.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ static int __init trace_boot_init(void)
344344
trace_boot_init_one_instance(tr, trace_node);
345345
trace_boot_init_instances(trace_node);
346346

347+
disable_tracing_selftest("running boot-time tracing");
348+
347349
return 0;
348350
}
349351
/*

kernel/trace/trace_events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3201,7 +3201,7 @@ static __init int setup_trace_event(char *str)
32013201
{
32023202
strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
32033203
ring_buffer_expanded = true;
3204-
tracing_selftest_disabled = true;
3204+
disable_tracing_selftest("running event tracing");
32053205

32063206
return 1;
32073207
}

kernel/trace/trace_kprobe.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626
/* Kprobe early definition from command line */
2727
static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata;
28-
static bool kprobe_boot_events_enabled __initdata;
2928

3029
static int __init set_kprobe_boot_events(char *str)
3130
{
3231
strlcpy(kprobe_boot_events_buf, str, COMMAND_LINE_SIZE);
32+
disable_tracing_selftest("running kprobe events");
33+
3334
return 0;
3435
}
3536
__setup("kprobe_event=", set_kprobe_boot_events);
@@ -1887,8 +1888,6 @@ static __init void setup_boot_kprobe_events(void)
18871888
ret = trace_run_command(cmd, create_or_delete_trace_kprobe);
18881889
if (ret)
18891890
pr_warn("Failed to add event(%d): %s\n", ret, cmd);
1890-
else
1891-
kprobe_boot_events_enabled = true;
18921891

18931892
cmd = p;
18941893
}
@@ -1973,10 +1972,8 @@ static __init int kprobe_trace_self_tests_init(void)
19731972
if (tracing_is_disabled())
19741973
return -ENODEV;
19751974

1976-
if (kprobe_boot_events_enabled) {
1977-
pr_info("Skipping kprobe tests due to kprobe_event on cmdline\n");
1975+
if (tracing_selftest_disabled)
19781976
return 0;
1979-
}
19801977

19811978
target = kprobe_trace_selftest_target;
19821979

kernel/trace/trace_selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ trace_selftest_startup_function_graph(struct tracer *trace,
787787

788788
/* Have we just recovered from a hang? */
789789
if (graph_hang_thresh > GRAPH_MAX_FUNC_TEST) {
790-
tracing_selftest_disabled = true;
790+
disable_tracing_selftest("recovering from a hang");
791791
ret = -1;
792792
goto out;
793793
}

0 commit comments

Comments
 (0)