Skip to content

Commit 3bb06eb

Browse files
committed
tracing: Make sure trace_printk() can output as soon as it can be used
Currently trace_printk() can be used as soon as early_trace_init() is called from start_kernel(). But if a crash happens, and "ftrace_dump_on_oops" is set on the kernel command line, all you get will be: [ 0.456075] <idle>-0 0dN.2. 347519us : Unknown type 6 [ 0.456075] <idle>-0 0dN.2. 353141us : Unknown type 6 [ 0.456075] <idle>-0 0dN.2. 358684us : Unknown type 6 This is because the trace_printk() event (type 6) hasn't been registered yet. That gets done via an early_initcall(), which may be early, but not early enough. Instead of registering the trace_printk() event (and other ftrace events, which are not trace events) via an early_initcall(), have them registered at the same time that trace_printk() can be used. This way, if there is a crash before early_initcall(), then the trace_printk()s will actually be useful. Link: https://lkml.kernel.org/r/[email protected] Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Fixes: e725c73 ("tracing: Split tracing initialization into two for early initialization") Reported-by: "Joel Fernandes (Google)" <[email protected]> Tested-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 8be9fbd commit 3bb06eb

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

kernel/trace/trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10295,6 +10295,8 @@ void __init early_trace_init(void)
1029510295
static_key_enable(&tracepoint_printk_key.key);
1029610296
}
1029710297
tracer_alloc_buffers();
10298+
10299+
init_events();
1029810300
}
1029910301

1030010302
void __init trace_init(void)

kernel/trace/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ extern void trace_event_enable_cmd_record(bool enable);
14901490
extern void trace_event_enable_tgid_record(bool enable);
14911491

14921492
extern int event_trace_init(void);
1493+
extern int init_events(void);
14931494
extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
14941495
extern int event_trace_del_tracer(struct trace_array *tr);
14951496
extern void __trace_early_add_events(struct trace_array *tr);

kernel/trace/trace_output.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ static struct trace_event *events[] __initdata = {
15351535
NULL
15361536
};
15371537

1538-
__init static int init_events(void)
1538+
__init int init_events(void)
15391539
{
15401540
struct trace_event *event;
15411541
int i, ret;
@@ -1548,4 +1548,3 @@ __init static int init_events(void)
15481548

15491549
return 0;
15501550
}
1551-
early_initcall(init_events);

0 commit comments

Comments
 (0)