Skip to contentSkip to conversation

fgraph: Still initialize idle shadow stacks when starting

PATCH In review Steven Rostedt 2 participants 3 messages Dec 11, 2024 – Dec 12, 2024

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 fgraph: Still initialize idle shadow stacks when starting

From: Steven Rostedt <[email protected]>

A bug was discovered where the idle shadow stacks were not initialized for offline CPUs when starting function graph tracer, and when they came online they were not traced due to the missing shadow stack. To fix this, the idle task shadow stack initialization was moved to using the CPU hotplug callbacks. But it removed the initialization when the function graph was enabled. The problem here is that the hotplug callbacks are called when the CPUs come online, but the idle shadow stack initialization only happens if function graph is currently active. This caused the online CPUs to not get their shadow stack initialized.

The idle shadow stack initialization still needs to be done when the function graph is registered, as they will not be allocated if function graph is not registered.

---
 kernel/trace/fgraph.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/trace/fgraph.c +7 -1
index 0bf78517b5d4..ddedcb50917f 100644
@@ -1215,7 +1215,7 @@ void fgraph_update_pid_func(void)
 static int start_graph_tracing(void)
 {
 	unsigned long **ret_stack_list;
-	int ret;
+	int ret, cpu;
 
 	ret_stack_list = kcalloc(FTRACE_RETSTACK_ALLOC_SIZE,
 				 sizeof(*ret_stack_list), GFP_KERNEL);
@@ -1223,6 +1223,12 @@ static int start_graph_tracing(void)
 	if (!ret_stack_list)
 		return -ENOMEM;
 
+	/* The cpu_boot init_task->ret_stack will never be freed */
+	for_each_online_cpu(cpu) {
+		if (!idle_task(cpu)->ret_stack)
+			ftrace_graph_init_idle_task(idle_task(cpu), cpu);
+	}
+
 	do {
 		ret = alloc_retstack_tasklist(ret_stack_list);
 	} while (ret == -EAGAIN);
Signature · 1 line
2.45.2
Tested-by on v1 1/1
#1 lore raw
Quoted 17 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

A bug was discovered where the idle shadow stacks were not initialized for offline CPUs when starting function graph tracer, and when they came online they were not traced due to the missing shadow stack. To fix this, the idle task shadow stack initialization was moved to using the CPU hotplug callbacks. But it removed the initialization when the function graph was enabled. The problem here is that the hotplug callbacks are called when the CPUs come online, but the idle shadow stack initialization only happens if function graph is currently active. This caused the online CPUs to not get their shadow stack initialized.

The idle shadow stack initialization still needs to be done when the function graph is registered, as they will not be allocated if function graph is not registered.

Quoted 5 lines

Yep that solves my issue and I can go on debugging my boot!

Thanks for patching this up so quickly Stephen, you're the best.

Yours,
Linus Walleij

author maintainer
#2 lore raw
Quoted 25 lines · Linus Walleij
Quoted 17 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

A bug was discovered where the idle shadow stacks were not initialized for offline CPUs when starting function graph tracer, and when they came online they were not traced due to the missing shadow stack. To fix this, the idle task shadow stack initialization was moved to using the CPU hotplug callbacks. But it removed the initialization when the function graph was enabled. The problem here is that the hotplug callbacks are called when the CPUs come online, but the idle shadow stack initialization only happens if function graph is currently active. This caused the online CPUs to not get their shadow stack initialized.

The idle shadow stack initialization still needs to be done when the function graph is registered, as they will not be allocated if function graph is not registered.

Quoted 5 lines
Quoted 5 lines

Yep that solves my issue and I can go on debugging my boot!

Thanks for patching this up so quickly Stephen, you're the best.

No problem, but I don't know who this "Stephen" is? ;-)

-- Steve

Quoted 2 lines

Yours,
Linus Walleij