All of lore.kernel.org
 help / color / mirror / Atom feed
* [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13
@ 2024-12-17 16:18 Steven Rostedt
  2024-12-17 16:18 ` [for-linus v2][PATCH 1/2] fgraph: Still initialize idle shadow stacks when starting Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Steven Rostedt @ 2024-12-17 16:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Al Viro, Michal Simek

Ftrace fixes for 6.13:

- Always try to initialize the idle functions when graph tracer starts

  A bug was found that when a CPU is offline when graph tracing starts
  and then comes online, that CPU is not traced. The fix to that was
  to move the initialization of the idle shadow stack over to the
  hot plug online logic, which also handle onlined CPUs. The issue was
  that it removed the initialization of the shadow stack when graph tracing
  starts, but the callbacks to the hot plug logic do nothing if graph
  tracing isn't currently running. Although that fix fixed the onlining
  of a CPU during tracing, it broke the CPUs that were already online.

- Have microblaze not try to get the "true parent" in function tracing

  If function tracing and graph tracing are both enabled at the same time
  the parent of the functions traced by the function tracer may sometimes
  be the graph tracing trampoline. The graph tracing hijacks the return
  pointer of the function to trace it, but that can interfere with the
  function tracing parent output. This was fixed by using the
  ftrace_graph_ret_addr() function passing in the kernel stack pointer
  using the ftrace_regs_get_stack_pointer() function. But Al Viro reported
  that Microblaze does not implement the kernel_stack_pointer(regs)
  helper function that ftrace_regs_get_stack_pointer() uses and fails
  to compile when function graph tracing is enabled.

  It was first thought that this was a microblaze issue, but the real
  cause is that this only works when an architecture implements
  HAVE_DYNAMIC_FTRACE_WITH_ARGS, as a requirement for that config
  is to have ftrace always pass a valid ftrace_regs to the callbacks.
  That also means that the architecture supports ftrace_regs_get_stack_pointer()
  Microblaze does not set HAVE_DYNAMIC_FTRACE_WITH_ARGS nor does it
  implement ftrace_regs_get_stack_pointer() which caused it to fail to
  build. Only implement the "true parent" logic if an architecture has
  that config set.

Changes since v1: https://lore.kernel.org/all/20241214182138.4e7984a2@batman.local.home/

- Removed the hash-ptr fix as Linus was unhappy with the code it was
  fixing and I have another series to address that. It didn't even
  belong in this pull request, as this is the ftrace topic and that
  was a tracing topic.

- Properly fix the function_get_true_parent_ip(), which wasn't a
  microblaze issue at all, but an issue for any architecture that
  does not support HAVE_DYNAMIC_FTRACE_WITH_ARGS.

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

* [for-linus v2][PATCH 1/2] fgraph: Still initialize idle shadow stacks when starting
  2024-12-17 16:18 [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13 Steven Rostedt
@ 2024-12-17 16:18 ` Steven Rostedt
  2024-12-17 16:18 ` [for-linus v2][PATCH 2/2] ftrace: Do not find "true_parent" if HAVE_DYNAMIC_FTRACE_WITH_ARGS is not set Steven Rostedt
  2024-12-17 16:33 ` [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13 Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2024-12-17 16:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Al Viro, Michal Simek, stable, Linus Walleij

From: Steven Rostedt <rostedt@goodmis.org>

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@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/20241211135335.094ba282@batman.local.home
Fixes: 2c02f7375e65 ("fgraph: Use CPU hotplug mechanism to initialize idle shadow stacks")
Reported-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Closes: https://lore.kernel.org/all/CACRpkdaTBrHwRbbrphVy-=SeDz6MSsXhTKypOtLrTQ+DgGAOcQ@mail.gmail.com/
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/fgraph.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index 0bf78517b5d4..ddedcb50917f 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -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);
-- 
2.45.2



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

* [for-linus v2][PATCH 2/2] ftrace: Do not find "true_parent" if HAVE_DYNAMIC_FTRACE_WITH_ARGS is not set
  2024-12-17 16:18 [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13 Steven Rostedt
  2024-12-17 16:18 ` [for-linus v2][PATCH 1/2] fgraph: Still initialize idle shadow stacks when starting Steven Rostedt
@ 2024-12-17 16:18 ` Steven Rostedt
  2024-12-17 16:33 ` [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13 Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2024-12-17 16:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Al Viro, Michal Simek, Jeff Xie, Al Viro

From: Steven Rostedt <rostedt@goodmis.org>

When function tracing and function graph tracing are both enabled (in
different instances) the "parent" of some of the function tracing events
is "return_to_handler" which is the trampoline used by function graph
tracing. To fix this, ftrace_get_true_parent_ip() was introduced that
returns the "true" parent ip instead of the trampoline.

To do this, the ftrace_regs_get_stack_pointer() is used, which uses
kernel_stack_pointer(). The problem is that microblaze does not implement
kerenl_stack_pointer() so when function graph tracing is enabled, the
build fails. But microblaze also does not enabled HAVE_DYNAMIC_FTRACE_WITH_ARGS.
That option has to be enabled by the architecture to reliably get the
values from the fregs parameter passed in. When that config is not set,
the architecture can also pass in NULL, which is not tested for in that
function and could cause the kernel to crash.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Jeff Xie <jeff.xie@linux.dev>
Link: https://lore.kernel.org/20241216164633.6df18e87@gandalf.local.home
Fixes: 60b1f578b578 ("ftrace: Get the true parent ip for function tracer")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace_functions.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 74c353164ca1..d358c9935164 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -176,7 +176,8 @@ static void function_trace_start(struct trace_array *tr)
 	tracing_reset_online_cpus(&tr->array_buffer);
 }
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+/* fregs are guaranteed not to be NULL if HAVE_DYNAMIC_FTRACE_WITH_ARGS is set */
+#if defined(CONFIG_FUNCTION_GRAPH_TRACER) && defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS)
 static __always_inline unsigned long
 function_get_true_parent_ip(unsigned long parent_ip, struct ftrace_regs *fregs)
 {
-- 
2.45.2



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

* Re: [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13
  2024-12-17 16:18 [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13 Steven Rostedt
  2024-12-17 16:18 ` [for-linus v2][PATCH 1/2] fgraph: Still initialize idle shadow stacks when starting Steven Rostedt
  2024-12-17 16:18 ` [for-linus v2][PATCH 2/2] ftrace: Do not find "true_parent" if HAVE_DYNAMIC_FTRACE_WITH_ARGS is not set Steven Rostedt
@ 2024-12-17 16:33 ` Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2024-12-17 16:33 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Al Viro, Michal Simek

On Tue, 17 Dec 2024 11:18:40 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> Ftrace fixes for 6.13:
> 
> - Always try to initialize the idle functions when graph tracer starts
> 
>   A bug was found that when a CPU is offline when graph tracing starts
>   and then comes online, that CPU is not traced. The fix to that was
>   to move the initialization of the idle shadow stack over to the
>   hot plug online logic, which also handle onlined CPUs. The issue was
>   that it removed the initialization of the shadow stack when graph tracing
>   starts, but the callbacks to the hot plug logic do nothing if graph
>   tracing isn't currently running. Although that fix fixed the onlining
>   of a CPU during tracing, it broke the CPUs that were already online.
> 
> - Have microblaze not try to get the "true parent" in function tracing
> 
>   If function tracing and graph tracing are both enabled at the same time
>   the parent of the functions traced by the function tracer may sometimes
>   be the graph tracing trampoline. The graph tracing hijacks the return
>   pointer of the function to trace it, but that can interfere with the
>   function tracing parent output. This was fixed by using the
>   ftrace_graph_ret_addr() function passing in the kernel stack pointer
>   using the ftrace_regs_get_stack_pointer() function. But Al Viro reported
>   that Microblaze does not implement the kernel_stack_pointer(regs)
>   helper function that ftrace_regs_get_stack_pointer() uses and fails
>   to compile when function graph tracing is enabled.
> 
>   It was first thought that this was a microblaze issue, but the real
>   cause is that this only works when an architecture implements
>   HAVE_DYNAMIC_FTRACE_WITH_ARGS, as a requirement for that config
>   is to have ftrace always pass a valid ftrace_regs to the callbacks.
>   That also means that the architecture supports ftrace_regs_get_stack_pointer()
>   Microblaze does not set HAVE_DYNAMIC_FTRACE_WITH_ARGS nor does it
>   implement ftrace_regs_get_stack_pointer() which caused it to fail to
>   build. Only implement the "true parent" logic if an architecture has
>   that config set.
> 
> Changes since v1: https://lore.kernel.org/all/20241214182138.4e7984a2@batman.local.home/
> 
> - Removed the hash-ptr fix as Linus was unhappy with the code it was
>   fixing and I have another series to address that. It didn't even
>   belong in this pull request, as this is the ftrace topic and that
>   was a tracing topic.
> 
> - Properly fix the function_get_true_parent_ip(), which wasn't a
>   microblaze issue at all, but an issue for any architecture that
>   does not support HAVE_DYNAMIC_FTRACE_WITH_ARGS.


I forgot to append the diffstat and branch where this lives:

  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
ftrace/fixes

Head SHA1: 166438a432d76c68d3f0da60667248f3c2303d6c


Steven Rostedt (2):
      fgraph: Still initialize idle shadow stacks when starting
      ftrace: Do not find "true_parent" if HAVE_DYNAMIC_FTRACE_WITH_ARGS is not set

----
 kernel/trace/fgraph.c          | 8 +++++++-
 kernel/trace/trace_functions.c | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)

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

end of thread, other threads:[~2024-12-17 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-17 16:18 [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13 Steven Rostedt
2024-12-17 16:18 ` [for-linus v2][PATCH 1/2] fgraph: Still initialize idle shadow stacks when starting Steven Rostedt
2024-12-17 16:18 ` [for-linus v2][PATCH 2/2] ftrace: Do not find "true_parent" if HAVE_DYNAMIC_FTRACE_WITH_ARGS is not set Steven Rostedt
2024-12-17 16:33 ` [for-linus v2][PATCH 0/2] ftrace: Fixes for v6.13 Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.