mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux trace kernel <linux-trace-kernel@vger.kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] fgraph: Use CPU hotplug mechanism to initialize idle shadow stacks
Date: Wed, 11 Dec 2024 11:09:52 -0500	[thread overview]
Message-ID: <20241211110952.6d89e0d8@batman.local.home> (raw)
In-Reply-To: <CACRpkdaEXUxSuVzztcVOh2VMzPHr+6jsrEC1w6ecWEd0qzgU4w@mail.gmail.com>

On Wed, 11 Dec 2024 15:23:05 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> If I boot without any tracing enabled from the cmdline and:
> 
> echo 0 > tracing_on
> echo function_graph > current_tracer
> echo do_idle > set_graph_function
> echo 1 > tracing_on
> 
> I don't get any output either.
> 
> It works for other functions, such as
> 
> echo ktime_get > set_graph_function
> 
> It seems it's the set_graph_function thing that isn't working
> with do_idle at all after this patch. Why just this function...
> The function is clearly there:
> 
> cat available_filter_functions | grep do_idle
> do_idle
> 
> I can also verify that this function is indeed getting invoked
> by adding prints to it (it's invoked all the time on any normal
> system). Does this have something to do with the context
> where do_idle is called? It's all really confusing...

Yeah, I figured it out. That commit moved the initialization before
fgraph was registered, and we had in ftrace_graph_init_idle_task():

        if (ftrace_graph_active) {
                unsigned long *ret_stack;
                        
                ret_stack = per_cpu(idle_ret_stack, cpu);
                if (!ret_stack) {
                        ret_stack = kmalloc(SHADOW_STACK_SIZE, GFP_KERNEL);
                        if (!ret_stack)
                                return;
                        per_cpu(idle_ret_stack, cpu) = ret_stack;
                }
                graph_init_task(t, ret_stack);
        }

But because ftrace_graph_active was not set yet, the initialization
didn't happen.

Can you try this patch?

-- Steve

diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index 43f4e3f57438..4706a7dce93a 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -1160,13 +1160,19 @@ 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 = kmalloc(SHADOW_STACK_SIZE, GFP_KERNEL);
 
 	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);

      reply	other threads:[~2024-12-11 16:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-19  1:43 Steven Rostedt
2024-10-21  5:58 ` Masami Hiramatsu
2024-10-22  3:35   ` Steven Rostedt
2024-10-25  1:30   ` Steven Rostedt
2024-12-10 15:11 ` Linus Walleij
2024-12-10 16:31   ` Steven Rostedt
2024-12-10 23:24   ` Masami Hiramatsu
2024-12-11 14:23     ` Linus Walleij
2024-12-11 16:09       ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241211110952.6d89e0d8@batman.local.home \
    --to=rostedt@goodmis.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®