Skip to contentSkip to conversation

tracing/events: don't discard an event after commit

PATCH Superseded Frederic Weisbecker 2 participants 4 messages Mar 22, 2009 – Mar 23, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing/events: don't discard an event after commit

Note: depends on "tracing/events: don't use wake up for events"

When we want to filter an event, the filter test is done after the event is commited to the ring-buffer to be discarded later if needed.

But a reader could be reading this event while we are trying to discard it. Other kind of racy events can even happen because the event is commited and can be read and/or consumed.

What we want is to discard the event before committing it.

---
 kernel/trace/trace_events_stage_3.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_stage_3.h +3 -2
index 9a3bd49..9d2fa78 100644
@@ -222,10 +222,11 @@ static void ftrace_raw_event_##call(proto)				\
 									\
 	assign;								\
 									\
-	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
-									\
 	if (call->preds && !filter_match_preds(call, entry))		\
 		ring_buffer_event_discard(event);			\
+									\
+	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
+									\
 }									\
 									\
 static int ftrace_raw_reg_event_##call(void)				\
Signature · 1 line
1.6.1
#1 lore raw

PATCH v2 1/1 tracing/events: don't discard an event after commit

Note: depends on "tracing/events: don't use wake up for events"

When we want to filter an event, the filter test is done after the event is commited to the ring-buffer to be discarded later if needed.

But a reader could be reading this event while we are trying to discard it. Other kind of racy events can even happen because the event is commited and can be read and/or consumed.

What we want is to discard the event before committing it.

v2: add a reported-by Steven Rostedt

---
 kernel/trace/trace_events_stage_3.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_stage_3.h +3 -2
index 9a3bd49..9d2fa78 100644
@@ -222,10 +222,11 @@ static void ftrace_raw_event_##call(proto)				\
 									\
 	assign;								\
 									\
-	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
-									\
 	if (call->preds && !filter_match_preds(call, entry))		\
 		ring_buffer_event_discard(event);			\
+									\
+	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
+									\
 }									\
 									\
 static int ftrace_raw_reg_event_##call(void)				\
Signature · 1 line
1.6.1
#2 lore raw
Commit-ID:  b118415bfad6d75792a85ac999e25149db8e6919
Gitweb:     http://git.kernel.org/tip/b118415bfad6d75792a85ac999e25149db8e6919
Author:     Frederic Weisbecker <[email protected]>
AuthorDate: Mon, 23 Mar 2009 00:18:39 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 23 Mar 2009 09:22:15 +0100

tracing/events: don't discard an event after commit

When we want to filter an event, the filter test is done after the event is commited to the ring-buffer to be discarded later if needed.

But a reader could be reading this event while we are trying to discard it. Other kind of racy events can even happen because the event is commited and can be read and/or consumed.

What we want is to discard the event before committing it.

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_events_stage_3.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_stage_3.h +3 -2
index 9a3bd49..9d2fa78 100644
@@ -222,10 +222,11 @@ static void ftrace_raw_event_##call(proto)				\
 									\
 	assign;								\
 									\
-	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
-									\
 	if (call->preds && !filter_match_preds(call, entry))		\
 		ring_buffer_event_discard(event);			\
+									\
+	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
+									\
 }									\
 									\
 static int ftrace_raw_reg_event_##call(void)				\
#3 lore raw
In reply to Frederic Weisbecker

Hi Frederic,

Quoted 6 lines · Frederic Weisbecker

Note: depends on "tracing/events: don't use wake up for events"

When we want to filter an event, the filter test is done after the event is commited to the ring-buffer to be discarded later if needed.

Quoted 6 lines

But a reader could be reading this event while we are trying to discard it. Other kind of racy events can even happen because the event is commited and can be read and/or consumed.

What we want is to discard the event before committing it.

Thanks for fixing this - I had intend on doing this, but it completely slipped my mind.

Thanks for all your other comments and fixes too...

Tom

Quoted 26 lines

v2: add a reported-by Steven Rostedt

---
 kernel/trace/trace_events_stage_3.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_stage_3.h +3 -2
index 9a3bd49..9d2fa78 100644
@@ -222,10 +222,11 @@ static void ftrace_raw_event_##call(proto)				\
 									\
 	assign;								\
 									\
-	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
-									\
 	if (call->preds && !filter_match_preds(call, entry))		\
 		ring_buffer_event_discard(event);			\
+									\
+	trace_nowake_buffer_unlock_commit(event, irq_flags, pc);	\
+									\
 }									\
 									\
 static int ftrace_raw_reg_event_##call(void)				\