LKML Archive on
help / color / mirror / Atom feed
From: Steven Rostedt <>
To: Linus Torvalds <>
Cc: LKML <>,
	Ingo Molnar <>,
	Andrew Morton <>,
	Pingfan Liu <>
Subject: [GIT PULL] tracing: Limit the shooting in the foot of tp_printk
Date: Tue, 17 Aug 2021 15:24:19 -0400	[thread overview]
Message-ID: <20210817152419.01539bf0@oasis.local.home> (raw)


tracing: Limit the shooting in the foot of tp_printk

The "tp_printk" option redirects the trace event output to printk at boot
up. This is useful when a machine crashes before boot where the trace events
can not be retrieved by the in kernel ring buffer. But it can be "dangerous"
because trace events can be located in high frequency locations such as
interrupts and the scheduler, where a printk can slow it down that it live
locks the machine (because by the time the printk finishes, the next event
is triggered). Thus tp_printk must be used with care.

It was discovered that the filter logic to trace events does not apply to
the tp_printk events. This can cause a surprise and live lock when the user
expects it to be filtered to limit the amount of events printed to the
console when in fact it still prints everything.

Please pull the latest trace-v5.14-rc6 tree, which can be found at:


Tag SHA1: bdb8b13b3e0d3878b6981d1a40df89f3813eadc9
Head SHA1: 6c34df6f350df9579ce99d887a2b5fa14cc13b32

Pingfan Liu (1):
      tracing: Apply trace filters on all output channels

 kernel/trace/trace.c | 18 +++++++++++++++---
 kernel/trace/trace.h | 32 --------------------------------
 2 files changed, 15 insertions(+), 35 deletions(-)
commit 6c34df6f350df9579ce99d887a2b5fa14cc13b32
Author: Pingfan Liu <>
Date:   Sat Aug 14 11:45:38 2021 +0800

    tracing: Apply trace filters on all output channels
    The event filters are not applied on all of the output, which results in
    the flood of printk when using tp_printk. Unfolding
    event_trigger_unlock_commit_regs() into trace_event_buffer_commit(), so
    the filters can be applied on every output.
    Fixes: 0daa2302968c1 ("tracing: Add tp_printk cmdline to have tracepoints go to printk()")
    Signed-off-by: Pingfan Liu <>
    Signed-off-by: Steven Rostedt (VMware) <>

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 33899a71fdc1..a1adb29ef5c1 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2897,14 +2897,26 @@ int tracepoint_printk_sysctl(struct ctl_table *table, int write,
 void trace_event_buffer_commit(struct trace_event_buffer *fbuffer)
+	enum event_trigger_type tt = ETT_NONE;
+	struct trace_event_file *file = fbuffer->trace_file;
+	if (__event_trigger_test_discard(file, fbuffer->buffer, fbuffer->event,
+			fbuffer->entry, &tt))
+		goto discard;
 	if (static_key_false(&tracepoint_printk_key.key))
 	if (static_branch_unlikely(&trace_event_exports_enabled))
 		ftrace_exports(fbuffer->event, TRACE_EXPORT_EVENT);
-	event_trigger_unlock_commit_regs(fbuffer->trace_file, fbuffer->buffer,
-				    fbuffer->event, fbuffer->entry,
-				    fbuffer->trace_ctx, fbuffer->regs);
+	trace_buffer_unlock_commit_regs(file->tr, fbuffer->buffer,
+			fbuffer->event, fbuffer->trace_ctx, fbuffer->regs);
+	if (tt)
+		event_triggers_post_call(file, tt);
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index a180abf76d4e..4a0e693000c6 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1389,38 +1389,6 @@ event_trigger_unlock_commit(struct trace_event_file *file,
 		event_triggers_post_call(file, tt);
- * event_trigger_unlock_commit_regs - handle triggers and finish event commit
- * @file: The file pointer associated with the event
- * @buffer: The ring buffer that the event is being written to
- * @event: The event meta data in the ring buffer
- * @entry: The event itself
- * @trace_ctx: The tracing context flags.
- *
- * This is a helper function to handle triggers that require data
- * from the event itself. It also tests the event against filters and
- * if the event is soft disabled and should be discarded.
- *
- * Same as event_trigger_unlock_commit() but calls
- * trace_buffer_unlock_commit_regs() instead of trace_buffer_unlock_commit().
- */
-static inline void
-event_trigger_unlock_commit_regs(struct trace_event_file *file,
-				 struct trace_buffer *buffer,
-				 struct ring_buffer_event *event,
-				 void *entry, unsigned int trace_ctx,
-				 struct pt_regs *regs)
-	enum event_trigger_type tt = ETT_NONE;
-	if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
-		trace_buffer_unlock_commit_regs(file->tr, buffer, event,
-						trace_ctx, regs);
-	if (tt)
-		event_triggers_post_call(file, tt);
 #define FILTER_PRED_INVALID	((unsigned short)-1)
 #define FILTER_PRED_IS_RIGHT	(1 << 15)
 #define FILTER_PRED_FOLD	(1 << 15)

             reply	other threads:[~2021-08-17 19:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 19:24 Steven Rostedt [this message]
2021-08-17 19:49 ` pr-tracker-bot

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:

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

  git send-email \
    --in-reply-to=20210817152419.01539bf0@oasis.local.home \ \ \ \ \ \ \
    --subject='Re: [GIT PULL] tracing: Limit the shooting in the foot of tp_printk' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).