Skip to contentSkip to conversation

tracing: Fix race where histograms can be called before the event

PATCH In review Steven Rostedt 2 participants 2 messages Nov 23, 2022 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing: Fix race where histograms can be called before the event

From: "Steven Rostedt (Google)" <[email protected]>

commit 94eedf3dded5 ("tracing: Fix race where eprobes can be called before the event") fixed an issue where if an event is soft disabled, and the trigger is being added, there's a small window where the event sees that there's a trigger but does not see that it requires reading the event yet, and then calls the trigger with the record == NULL.

This could be solved with adding memory barriers in the hot path, or to make sure that all the triggers requiring a record check for NULL. The latter was chosen.

Commit 94eedf3dded5 set the eprobe trigger handle to check for NULL, but the same needs to be done with histograms.

Fixes 7491e2c442781 ("tracing: Add a probe that attaches to trace events")
---
 kernel/trace/trace_events_hist.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/trace_events_hist.c +3 -0
index 087c19548049..1c82478e8dff 100644
@@ -5143,6 +5143,9 @@ static void event_hist_trigger(struct event_trigger_data *data,
 	void *key = NULL;
 	unsigned int i;
 
+	if (unlikely(!rbe))
+		return;
+
 	memset(compound_key, 0, hist_data->key_size);
 
 	for_each_hist_key_field(i, hist_data) {
Signature · 1 line
2.35.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · On Wed, 23 Nov 2022 16:43:23 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (Google)" <[email protected]>

commit 94eedf3dded5 ("tracing: Fix race where eprobes can be called before the event") fixed an issue where if an event is soft disabled, and the trigger is being added, there's a small window where the event sees that there's a trigger but does not see that it requires reading the event yet, and then calls the trigger with the record == NULL.

This could be solved with adding memory barriers in the hot path, or to make sure that all the triggers requiring a record check for NULL. The latter was chosen.

Commit 94eedf3dded5 set the eprobe trigger handle to check for NULL, but the same needs to be done with histograms.

Quoted 6 lines
Fixes 7491e2c442781 ("tracing: Add a probe that attaches to trace events")

I confirmed that other trigger callbacks only use the event_trigger_data, So this looks good to me.

Thank you!

Quoted 21 lines
---
 kernel/trace/trace_events_hist.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/trace_events_hist.c +3 -0
index 087c19548049..1c82478e8dff 100644
@@ -5143,6 +5143,9 @@ static void event_hist_trigger(struct event_trigger_data *data,
 	void *key = NULL;
 	unsigned int i;
 
+	if (unlikely(!rbe))
+		return;
+
 	memset(compound_key, 0, hist_data->key_size);
 
 	for_each_hist_key_field(i, hist_data) {
Signature · 1 line
2.35.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>