Skip to contentSkip to conversation

tracing: Add notrace to event functions that hook to ftrace

PATCH New Steven Rostedt 2 participants 2 messages Nov 19 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing: Add notrace to event functions that hook to ftrace

From: Steven Rostedt <[email protected]>

A few functions in trace_events.c are used to hook to the ftrace function hooks. Before CONFIG_FUNCTION_SELF_TRACING was added, these functions were not marked for tracing because the entire directory was set to "notrace". But now that certain files can be traced by ftrace when the CONFIG_FUNCTION_SELF_TRACING config is set, individual functions that use ftrace must be annotated with "notrace" otherwise they can trigger a triple fault when called.

Annotate the trace_events.c functions that are attached to ftrace with "notrace.

Fixes f93a7d0caccd6 ("ftrace: Allow tracing of some of the tracing code")
---
 kernel/trace/trace_events.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace_events.c +3 -3
index c9d31c9f3fca..7f89160aeff3 100644
@@ -4317,7 +4317,7 @@ static void update_event_probe(struct event_probe_data *data)
 		set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
 }
 
-static void
+static void notrace
 event_enable_probe(unsigned long ip, unsigned long parent_ip,
 		   struct trace_array *tr, struct ftrace_probe_ops *ops,
 		   void *data)
@@ -4334,7 +4334,7 @@ event_enable_probe(unsigned long ip, unsigned long parent_ip,
 	update_event_probe(edata);
 }
 
-static void
+static void notrace
 event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
 			 struct trace_array *tr, struct ftrace_probe_ops *ops,
 			 void *data)
@@ -5205,7 +5205,7 @@ static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
 
 static struct trace_event_file event_trace_file __initdata;
 
-static void __init
+static void notrace __init
 function_test_events_call(unsigned long ip, unsigned long parent_ip,
 			  struct ftrace_ops *op, struct ftrace_regs *regs)
 {
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] tracing: missing notrace on update_event_probe() causes ftrace recursion --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] tracing: missing notrace on update_event_probe() causes ftrace recursion
--

commit fa7d6fcf36a58e2cb33d20aff7d184dfe9c6060d
Author: Steven Rostedt <[email protected]>

tracing: Add notrace to event functions that hook to ftrace

This commit adds the notrace annotation to event_enable_probe(), event_enable_count_probe(), and function_test_events_call() so they are not traced when CONFIG_FUNCTION_SELF_TRACING is enabled.

Quoted 14 lines
kernel/trace/trace_events.c +1 -1
index 6afed2091e19c..fa8927068609a 100644
@@ -4317,7 +4317,7 @@ static void update_event_probe(struct event_probe_data *data)
 		set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
 }
 
-static void
+static void notrace
 event_enable_probe(unsigned long ip, unsigned long parent_ip,
 		   struct trace_array *tr, struct ftrace_probe_ops *ops,
 		   void *data)

kernel/trace/trace_events.c event_enable_probe(unsigned long ip, unsigned long parent_ip, · line 4340

Quoted 8 lines
kernel/trace/trace_events.c +1 -1
@@ -4334,7 +4334,7 @@ event_enable_probe(unsigned long ip, unsigned long parent_ip,
 	update_event_probe(edata);
 }
 
-static void
+static void notrace
 event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
 			 struct trace_array *tr, struct ftrace_probe_ops *ops,
 			 void *data)

[Severity: High]
Should update_event_probe() also be marked notrace (or inline)?

Both event_enable_probe() and event_enable_count_probe() run via function_trace_probe_call() without FTRACE_OPS_FL_RECURSION and call update_event_probe(). Because update_event_probe() is neither notrace nor inline, GCC cannot inline it into its notrace callers and emits it with an ftrace entry hook under CONFIG_FUNCTION_SELF_TRACING. If an enable_event or disable_event function probe matches update_event_probe() (for example via a wildcard filter in set_ftrace_filter), calling update_event_probe() re-enters function_trace_probe_call() and recurses until the stack overflows.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1