From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Menglong Dong <menglong.dong@linux.dev>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Menglong Dong <menglong8.dong@gmail.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
jiang.biao@linux.dev, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] tracing/fprobe: Avoid kcalloc() in rcu_read_lock section
Date: Fri, 10 Apr 2026 09:19:00 +0900 [thread overview]
Message-ID: <20260410091900.d9dff4cef540e7d61d4a83c8@kernel.org> (raw)
In-Reply-To: <2258680.irdbgypaU6@7940hx>
On Thu, 09 Apr 2026 20:05:13 +0800
Menglong Dong <menglong.dong@linux.dev> wrote:
> On 2026/4/9 18:35 Masami Hiramatsu (Google) <mhiramat@kernel.org> write:
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> >
> > fprobe_remove_node_in_module() is called under RCU read locked, but
> > this invokes kcalloc() if there are more than 8 fprobes installed
> > on the module. Sashiko warns it because kcalloc() can sleep [1].
> >
> > [1] https://sashiko.dev/#/patchset/177552432201.853249.5125045538812833325.stgit%40mhiramat.tok.corp.google.com
> >
> > To fix this issue, expand the batch size to 128 and do not expand
> > the fprobe_addr_list, but just cancel walking on fprobe_ip_table,
> > update fgraph/ftrace_ops and retry the loop again.
> >
> > Fixes: 0de4c70d04a4 ("tracing: fprobe: use rhltable for fprobe_ip_table")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > ---
> > kernel/trace/fprobe.c | 53 ++++++++++++++++++-------------------------------
> > 1 file changed, 19 insertions(+), 34 deletions(-)
> >
> > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > index 56d145017902..058cf6ef7ebb 100644
> > --- a/kernel/trace/fprobe.c
> > +++ b/kernel/trace/fprobe.c
> > @@ -536,7 +536,7 @@ static void fprobe_graph_remove_ips(unsigned long *addrs, int num)
>
> Hi, Masami. Thanks for the fixes. Overall, the whole series
> LGTM.
>
> Some nits below.
>
> >
> > #ifdef CONFIG_MODULES
> >
> [...]
> > unsigned long val, void *data)
> > @@ -591,6 +567,7 @@ static int fprobe_module_callback(struct notifier_block *nb,
> > struct fprobe_hlist_node *node;
> > struct rhashtable_iter iter;
> > struct module *mod = data;
> > + bool retry;
> >
> > if (val != MODULE_STATE_GOING)
> > return NOTIFY_DONE;
> > @@ -600,13 +577,19 @@ static int fprobe_module_callback(struct notifier_block *nb,
> > if (!alist.addrs)
> > return NOTIFY_DONE;
>
> The "retry" confuse me a little. How about we use "again" and "more"
> here:
>
> +again:
> + more = false;
OK. And Sashiko pointed out that we can retry right after calling
rhltable_walk_enter(), and it seems true according to
https://lwn.net/Articles/751374/
We can seep inside rhltable_walk_enter()/exit() but not inside
rhashtable_walk_start()/end().
So let me update it.
>
> >
> > +retry:
> > + retry = false;
> > + alist.index = 0;
> > mutex_lock(&fprobe_mutex);
> > rhltable_walk_enter(&fprobe_ip_table, &iter);
> > do {
> > rhashtable_walk_start(&iter);
> >
> > while ((node = rhashtable_walk_next(&iter)) && !IS_ERR(node))
> > - fprobe_remove_node_in_module(mod, node, &alist);
> > + if (fprobe_remove_node_in_module(mod, node, &alist) < 0) {
> > + retry = true;
> > + break;
> > + }
>
> Wrap the code within the "while" with {}?
OK.
Thank you!
>
> Thanks!
> Menglong Dong
>
> >
> > rhashtable_walk_stop(&iter);
> > } while (node == ERR_PTR(-EAGAIN));
> > @@ -615,6 +598,8 @@ static int fprobe_module_callback(struct notifier_block *nb,
> > if (alist.index > 0)
> > fprobe_set_ips(alist.addrs, alist.index, 1, 0);
> > mutex_unlock(&fprobe_mutex);
> > + if (retry)
> > + goto retry;
> >
> > kfree(alist.addrs);
> >
> >
> >
> >
>
>
>
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-04-10 0:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 10:35 [PATCH v2 0/2] tracing/fprobe: Fix fprobe_ip_table related bugs Masami Hiramatsu (Google)
2026-04-09 10:35 ` [PATCH v2 1/2] tracing/fprobe: Avoid kcalloc() in rcu_read_lock section Masami Hiramatsu (Google)
2026-04-09 12:05 ` Menglong Dong
2026-04-10 0:19 ` Masami Hiramatsu [this message]
2026-04-09 10:36 ` [PATCH v2 2/2] tracing/fprobe: Check the same type fprobe on table as the unregistered one Masami Hiramatsu (Google)
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=20260410091900.d9dff4cef540e7d61d4a83c8@kernel.org \
--to=mhiramat@kernel.org \
--cc=jiang.biao@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=menglong.dong@linux.dev \
--cc=menglong8.dong@gmail.com \
--cc=rostedt@goodmis.org \
/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