linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] tracing/wakeup: Balance prolog on fgraph failure
@ 2025-10-06 17:58 Sasha Levin
  2025-10-06 17:58 ` [PATCH 2/2] tracing/irqsoff: " Sasha Levin
  2025-10-08 15:24 ` [PATCH 1/2] tracing/wakeup: " Steven Rostedt
  0 siblings, 2 replies; 4+ messages in thread
From: Sasha Levin @ 2025-10-06 17:58 UTC (permalink / raw)
  To: rostedt, mhiramat
  Cc: mathieu.desnoyers, linux-kernel, linux-trace-kernel, Sasha Levin

Commit a485ea9e3ef3 ("tracing: Fix irqsoff and wakeup latency tracers when
using function graph") added fgraph_reserve_data()/fgraph_retrieve_data() to
the wakeup tracer's function-graph hooks.

When func_prolog_preempt_disable() succeeded but those calls failed, the code
returned without undoing the prolog (no local_dec(&data->disabled), no
preempt_enable_notrace()). That leaked a preempt disable into later code and
could trigger "BUG: scheduling while atomic".

Balance the prolog on these failure paths in both entry and return hooks.

Fixes: a485ea9e3ef3 ("tracing: Fix irqsoff and wakeup latency tracers when using function graph")
Assisted-by: gpt-5-codex
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 kernel/trace/trace_sched_wakeup.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c
index bf1cb80742aed..fa48bbdf0851c 100644
--- a/kernel/trace/trace_sched_wakeup.c
+++ b/kernel/trace/trace_sched_wakeup.c
@@ -138,8 +138,11 @@ static int wakeup_graph_entry(struct ftrace_graph_ent *trace,
 		return 0;
 
 	calltime = fgraph_reserve_data(gops->idx, sizeof(*calltime));
-	if (!calltime)
+	if (!calltime) {
+		local_dec(&data->disabled);
+		preempt_enable_notrace();
 		return 0;
+	}
 
 	*calltime = trace_clock_local();
 
@@ -169,8 +172,11 @@ static void wakeup_graph_return(struct ftrace_graph_ret *trace,
 	rettime = trace_clock_local();
 
 	calltime = fgraph_retrieve_data(gops->idx, &size);
-	if (!calltime)
+	if (!calltime) {
+		local_dec(&data->disabled);
+		preempt_enable_notrace();
 		return;
+	}
 
 	__trace_graph_return(tr, trace, trace_ctx, *calltime, rettime);
 	local_dec(&data->disabled);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-08 15:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-06 17:58 [PATCH 1/2] tracing/wakeup: Balance prolog on fgraph failure Sasha Levin
2025-10-06 17:58 ` [PATCH 2/2] tracing/irqsoff: " Sasha Levin
2025-10-08 15:27   ` Steven Rostedt
2025-10-08 15:24 ` [PATCH 1/2] tracing/wakeup: " Steven Rostedt

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).