提交 be88cf30 编写于 作者: S Steven Rostedt (Google) 提交者: sanglipeng

tracing: Make sure trace_printk() can output as soon as it can be used

stable inclusion
from stable-v5.10.166
commit de3930a4883ddad2244efd6d349013294c62c75c
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7TH9O

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=de3930a4883ddad2244efd6d349013294c62c75c

--------------------------------

commit 3bb06eb6 upstream.

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/20230104161412.019f6c55@gandalf.local.home

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Fixes: e725c731 ("tracing: Split tracing initialization into two for early initialization")
Reported-by: N"Joel Fernandes (Google)" <joel@joelfernandes.org>
Tested-by: NJoel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: NSteven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Nsanglipeng <sanglipeng1@jd.com>
上级 6b40106a
...@@ -9779,6 +9779,8 @@ void __init early_trace_init(void) ...@@ -9779,6 +9779,8 @@ void __init early_trace_init(void)
static_key_enable(&tracepoint_printk_key.key); static_key_enable(&tracepoint_printk_key.key);
} }
tracer_alloc_buffers(); tracer_alloc_buffers();
init_events();
} }
void __init trace_init(void) void __init trace_init(void)
......
...@@ -1675,6 +1675,7 @@ extern void trace_event_enable_cmd_record(bool enable); ...@@ -1675,6 +1675,7 @@ extern void trace_event_enable_cmd_record(bool enable);
extern void trace_event_enable_tgid_record(bool enable); extern void trace_event_enable_tgid_record(bool enable);
extern int event_trace_init(void); extern int event_trace_init(void);
extern int init_events(void);
extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr); extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
extern int event_trace_del_tracer(struct trace_array *tr); extern int event_trace_del_tracer(struct trace_array *tr);
extern void __trace_early_add_events(struct trace_array *tr); extern void __trace_early_add_events(struct trace_array *tr);
......
...@@ -1495,7 +1495,7 @@ static struct trace_event *events[] __initdata = { ...@@ -1495,7 +1495,7 @@ static struct trace_event *events[] __initdata = {
NULL NULL
}; };
__init static int init_events(void) __init int init_events(void)
{ {
struct trace_event *event; struct trace_event *event;
int i, ret; int i, ret;
...@@ -1513,4 +1513,3 @@ __init static int init_events(void) ...@@ -1513,4 +1513,3 @@ __init static int init_events(void)
return 0; return 0;
} }
early_initcall(init_events);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册