From: Steven Rostedt <rostedt@xxxxxxxxxxx> commit cc252bb592638e0f7aea40d580186c36d89526b8 upstream. 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. Cc: stable@xxxxxxxxxxxxxxx Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx> Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx> Link: https://lore.kernel.org/20241211135335.094ba282@xxxxxxxxxxxxxxxxx Fixes: 2c02f7375e65 ("fgraph: Use CPU hotplug mechanism to initialize idle shadow stacks") Reported-by: Linus Walleij <linus.walleij@xxxxxxxxxx> Tested-by: Linus Walleij <linus.walleij@xxxxxxxxxx> Closes: https://lore.kernel.org/all/CACRpkdaTBrHwRbbrphVy-=SeDz6MSsXhTKypOtLrTQ+DgGAOcQ@xxxxxxxxxxxxxx/ Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/trace/fgraph.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -1160,7 +1160,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); @@ -1168,6 +1168,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); Patches currently in stable-queue which might be from rostedt@xxxxxxxxxxx are queue-6.12/ring-buffer-fix-overflow-in-__rb_map_vma.patch queue-6.12/tracing-add-s-check-in-test_event_printk.patch queue-6.12/tracing-check-s-dereference-via-the-field-and-not-the-tp_printk-format.patch queue-6.12/tracing-add-missing-helper-functions-in-event-pointer-dereference-check.patch queue-6.12/tracing-fix-test_event_printk-to-process-entire-print-argument.patch queue-6.12/fgraph-still-initialize-idle-shadow-stacks-when-starting.patch queue-6.12/trace-ring-buffer-do-not-use-tp_printk-formatting-for-boot-mapped-buffers.patch