From: Miroslav Benes <mbenes@suse.cz>
To: Song Chen <chensong_2000@189.cn>
Cc: Steven Rostedt <rostedt@goodmis.org>,
mcgrof@kernel.org, petr.pavlu@suse.com, da.gomez@kernel.org,
samitolvanen@google.com, atomlin@atomlin.com,
mhiramat@kernel.org, mark.rutland@arm.com,
mathieu.desnoyers@efficios.com, linux-modules@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
live-patching@vger.kernel.org
Subject: Re: [PATCH] kernel/trace/ftrace: introduce ftrace module notifier
Date: Thu, 26 Feb 2026 11:51:53 +0100 (CET) [thread overview]
Message-ID: <alpine.LSU.2.21.2602261147150.5739@pobox.suse.cz> (raw)
In-Reply-To: <e18ed5f4-3917-46e7-bca9-78063e6e4457@189.cn>
[-- Attachment #1: Type: text/plain, Size: 3620 bytes --]
Hi,
+ Cc: live-patching@vger.kernel.org
On Thu, 26 Feb 2026, Song Chen wrote:
> Hi,
>
> 在 2026/2/26 08:27, Steven Rostedt 写道:
> > On Wed, 25 Feb 2026 13:46:39 +0800
> > chensong_2000@189.cn wrote:
> >
> >> From: Song Chen <chensong_2000@189.cn>
> >>
> >> Like kprobe, fprobe and btf, this patch attempts to introduce
> >> a notifier_block for ftrace to decouple its initialization from
> >> load_module.
> >>
> >> Below is the table of ftrace fucntions calls in different
> >> module state:
> >>
> >> MODULE_STATE_UNFORMED ftrace_module_init
> >> MODULE_STATE_COMING ftrace_module_enable
> >> MODULE_STATE_LIVE ftrace_free_mem
> >> MODULE_STATE_GOING ftrace_release_mod
> >>
> >> Unlike others, ftrace module notifier must take care of state
> >> MODULE_STATE_UNFORMED to ensure calling ftrace_module_init
> >> before complete_formation which changes module's text property.
> >>
> >> That pretty much remains same logic with its original design,
> >> the only thing that changes is blocking_notifier_call_chain
> >> (MODULE_STATE_GOING) has to be moved from coming_cleanup to
> >> ddebug_cleanup in function load_module to ensure
> >> ftrace_release_mod is invoked in case complete_formation fails.
> >>
> >> Signed-off-by: Song Chen <chensong_2000@189.cn>
> >> ---
> >> kernel/module/main.c | 14 ++++----------
> >> kernel/trace/ftrace.c | 37 +++++++++++++++++++++++++++++++++++++
> >> 2 files changed, 41 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/kernel/module/main.c b/kernel/module/main.c
> >> index 710ee30b3bea..5dc0a980e9bd 100644
> >> --- a/kernel/module/main.c
> >> +++ b/kernel/module/main.c
> >> @@ -45,7 +45,6 @@
> >> #include <linux/license.h>
> >> #include <asm/sections.h>
> >> #include <linux/tracepoint.h>
> >> -#include <linux/ftrace.h>
> >> #include <linux/livepatch.h>
> >> #include <linux/async.h>
> >> #include <linux/percpu.h>
> >> @@ -836,7 +835,6 @@ SYSCALL_DEFINE2(delete_module, const char __user *,
> >> name_user,
> >> blocking_notifier_call_chain(&module_notify_list,
> >> MODULE_STATE_GOING, mod);
> >> klp_module_going(mod);
> >> - ftrace_release_mod(mod);
> >
> > Is the above safe? klp uses ftrace. That means klp_module_going() may
> > need to be called before ftrace_release_mod(). That said, I wonder if
> > klp_module_going() could be moved into ftrace_release_mod()?
> >
> >>
>
> I didn't test with klp, so i'm not sure if it's safe. But i consider klp is
> the other part which should be decoupled after ftrace and klp should introduce
> its own notifier.
>
> If klp_module_going must be running before ftrace_release_mod, i can try to
> use priority in notifier_block to ensure their order.
>
> Let me see if there is any way to use notifier and remain below calling
> sequence:
>
> ftrace_module_enable
> klp_module_coming
> blocking_notifier_call_chain_robust(MODULE_STATE_COMING)
>
> blocking_notifier_call_chain(MODULE_STATE_GOING)
> klp_module_going
> ftrace_release_mod
Both klp and ftrace used module notifiers in the past. We abandoned that
and opted for direct calls due to issues with ordering at the time. I do
not have the list of problems at hand but I remember it was very fragile.
See commits 7dcd182bec27 ("ftrace/module: remove ftrace module
notifier"), 7e545d6eca20 ("livepatch/module: remove livepatch module
notifier") and their surroundings.
So unless there is a reason for the change (which should be then carefully
reviewed and properly tested), I would prefer to keep it as is. What is
the motivation? I am failing to find it in the commit log.
Regards,
Miroslav
next prev parent reply other threads:[~2026-02-26 10:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 5:46 chensong_2000
2026-02-26 0:27 ` Steven Rostedt
2026-02-26 10:12 ` Song Chen
2026-02-26 10:51 ` Miroslav Benes [this message]
2026-02-26 17:30 ` Steven Rostedt
2026-02-27 1:34 ` Song Chen
2026-03-06 9:57 ` Petr Mladek
2026-04-12 14:10 ` Song Chen
2026-04-21 22:40 ` Song Liu
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=alpine.LSU.2.21.2602261147150.5739@pobox.suse.cz \
--to=mbenes@suse.cz \
--cc=atomlin@atomlin.com \
--cc=chensong_2000@189.cn \
--cc=da.gomez@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.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
all inboxes | Powered by JetHome®