From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Heiko Carstens <hca@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 4/5] fprobe: Always unregister fgraph function from ops
Date: Wed, 19 Feb 2025 09:57:15 +0900 [thread overview]
Message-ID: <20250219095715.26c7b7811b05d3952c7bfa56@kernel.org> (raw)
In-Reply-To: <20250218193126.785837383@goodmis.org>
On Tue, 18 Feb 2025 14:30:37 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> When the last fprobe is removed, it calls unregister_ftrace_graph() to
> remove the graph_ops from function graph. The issue is when it does so, it
> calls return before removing the function from its graph ops via
> ftrace_set_filter_ips(). This leaves the last function lingering in the
> fprobe's fgraph ops and if a probe is added it also enables that last
> function (even though the callback will just drop it, it does add unneeded
> overhead to make that call).
>
> # echo "f:myevent1 kernel_clone" >> /sys/kernel/tracing/dynamic_events
> # cat /sys/kernel/tracing/enabled_functions
> kernel_clone (1) tramp: 0xffffffffc02f3000 (ftrace_graph_func+0x0/0x60) ->ftrace_graph_func+0x0/0x60
>
> # echo "f:myevent2 schedule_timeout" >> /sys/kernel/tracing/dynamic_events
> # cat /sys/kernel/tracing/enabled_functions
> kernel_clone (1) tramp: 0xffffffffc02f3000 (ftrace_graph_func+0x0/0x60) ->ftrace_graph_func+0x0/0x60
> schedule_timeout (1) tramp: 0xffffffffc02f3000 (ftrace_graph_func+0x0/0x60) ->ftrace_graph_func+0x0/0x60
>
> # > /sys/kernel/tracing/dynamic_events
> # cat /sys/kernel/tracing/enabled_functions
>
> # echo "f:myevent3 kmem_cache_free" >> /sys/kernel/tracing/dynamic_events
> # cat /sys/kernel/tracing/enabled_functions
> kmem_cache_free (1) tramp: 0xffffffffc0219000 (ftrace_graph_func+0x0/0x60) ->ftrace_graph_func+0x0/0x60
> schedule_timeout (1) tramp: 0xffffffffc0219000 (ftrace_graph_func+0x0/0x60) ->ftrace_graph_func+0x0/0x60
>
> The above enabled a fprobe on kernel_clone, and then on schedule_timeout.
> The content of the enabled_functions shows the functions that have a
> callback attached to them. The fprobe attached to those functions
> properly. Then the fprobes were cleared, and enabled_functions was empty
> after that. But after adding a fprobe on kmem_cache_free, the
> enabled_functions shows that the schedule_timeout was attached again. This
> is because it was still left in the fprobe ops that is used to tell
> function graph what functions it wants callbacks from.
>
Good catch! I forgot to remove the filter in this case.
Is there anyway to be sure the filter is empty or clear it if
fprobe_graph_active == 0?
Thank you,
> Cc: stable@vger.kernel.org
> Fixes: 4346ba1604093 ("fprobe: Rewrite fprobe on function-graph tracer")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> kernel/trace/fprobe.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index 90241091ca61..886090845b1a 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -403,11 +403,9 @@ static void fprobe_graph_remove_ips(unsigned long *addrs, int num)
> lockdep_assert_held(&fprobe_mutex);
>
> fprobe_graph_active--;
> - if (!fprobe_graph_active) {
> - /* Q: should we unregister it ? */
> + /* Q: should we unregister it ? */
> + if (!fprobe_graph_active)
> unregister_ftrace_graph(&fprobe_graph_ops);
> - return;
> - }
>
> ftrace_set_filter_ips(&fprobe_graph_ops.ops, addrs, num, 1, 0);
> }
> --
> 2.47.2
>
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2025-02-19 0:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 19:30 [PATCH 0/5] ftrace: Fix fprobe with function graph accounting Steven Rostedt
2025-02-18 19:30 ` [PATCH 1/5] ftrace: Fix accounting of adding subops to a manager ops Steven Rostedt
2025-02-18 19:30 ` [PATCH 2/5] ftrace: Do not add duplicate entries in subops " Steven Rostedt
2025-02-18 19:30 ` [PATCH 3/5] fprobe: Fix accounting of when to unregister from function graph Steven Rostedt
2025-02-19 0:53 ` Masami Hiramatsu
2025-02-19 14:45 ` Steven Rostedt
2025-02-18 19:30 ` [PATCH 4/5] fprobe: Always unregister fgraph function from ops Steven Rostedt
2025-02-19 0:57 ` Masami Hiramatsu [this message]
2025-02-19 14:53 ` Steven Rostedt
2025-02-18 19:30 ` [PATCH 5/5] selftests/ftrace: Update fprobe test to check enabled_functions file Steven Rostedt
2025-02-19 1:01 ` Masami Hiramatsu
2025-02-19 15:00 ` Steven Rostedt
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=20250219095715.26c7b7811b05d3952c7bfa56@kernel.org \
--to=mhiramat@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
--cc=svens@linux.ibm.com \
/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