public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	stable@vger.kernel.org,
	"Joel Fernandes (Google)" <joel@joelfernandes.org>
Subject: [for-linus][PATCH 02/11] tracing: Make sure trace_printk() can output as soon as it can be used
Date: Wed, 25 Jan 2023 11:18:26 -0500	[thread overview]
Message-ID: <20230125162010.016206071@goodmis.org> (raw)
In-Reply-To: 20230125161824.332648375@goodmis.org

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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: e725c731e3bb1 ("tracing: Split tracing initialization into two for early initialization")
Reported-by: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Tested-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace.c        | 2 ++
 kernel/trace/trace.h        | 1 +
 kernel/trace/trace_output.c | 3 +--
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a555a861b978..78ed5f1baa8c 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -10295,6 +10295,8 @@ void __init early_trace_init(void)
 			static_key_enable(&tracepoint_printk_key.key);
 	}
 	tracer_alloc_buffers();
+
+	init_events();
 }
 
 void __init trace_init(void)
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index e46a49269be2..4eb6d6b97a9f 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1490,6 +1490,7 @@ extern void trace_event_enable_cmd_record(bool enable);
 extern void trace_event_enable_tgid_record(bool enable);
 
 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_del_tracer(struct trace_array *tr);
 extern void __trace_early_add_events(struct trace_array *tr);
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 57a13b61f186..bd475a00f96d 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -1535,7 +1535,7 @@ static struct trace_event *events[] __initdata = {
 	NULL
 };
 
-__init static int init_events(void)
+__init int init_events(void)
 {
 	struct trace_event *event;
 	int i, ret;
@@ -1548,4 +1548,3 @@ __init static int init_events(void)
 
 	return 0;
 }
-early_initcall(init_events);
-- 
2.39.0

  parent reply	other threads:[~2023-01-25 16:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 16:18 [for-linus][PATCH 00/11] tracing: Updates for 6.2 Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 01/11] ftrace: Export ftrace_free_filter() to modules Steven Rostedt
2023-01-25 16:18 ` Steven Rostedt [this message]
2023-01-25 16:18 ` [for-linus][PATCH 03/11] ftrace/scripts: Update the instructions for ftrace-bisect.sh Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 04/11] tracing: Kconfig: Fix spelling/grammar/punctuation Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 05/11] tracing/osnoise: Use built-in RCU list checking Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 06/11] trace_events_hist: add check for return value of create_hist_field Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 07/11] lib: Kconfig: fix spellos Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 08/11] tracing/filter: fix kernel-doc warnings Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 09/11] ftrace: Maintain samples/ftrace Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 10/11] rv: remove redundant initialization of pointer ptr Steven Rostedt
2023-01-25 16:18 ` [for-linus][PATCH 11/11] bootconfig: Update MAINTAINERS file to add tree and mailing list Steven Rostedt
2023-01-25 16:22 ` [for-linus][PATCH 00/11] tracing: Updates for 6.2 Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230125162010.016206071@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox