From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Francis Laniel <flaniel@linux.microsoft.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linux trace kernel <linux-trace-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH for-next] tracing/kprobes: Add symbol counting check when module loads
Date: Fri, 3 Nov 2023 12:27:19 +0900 [thread overview]
Message-ID: <20231103122719.829de1daad83a08fe09ab2bd@kernel.org> (raw)
In-Reply-To: <5987802.lOV4Wx5bFT@pwmachine>
On Thu, 02 Nov 2023 14:57:12 +0200
Francis Laniel <flaniel@linux.microsoft.com> wrote:
> Hi!
>
> Le mercredi 1 novembre 2023, 01:15:09 EET Masami Hiramatsu a écrit :
> > Hi,
> >
> > On Tue, 31 Oct 2023 23:24:43 +0200
> >
> > Francis Laniel <flaniel@linux.microsoft.com> wrote:
> > > > @@ -729,17 +744,55 @@ static int count_mod_symbols(void *data, const
> > > > char
> > > > *name, unsigned long unused) return 0;
> > > >
> > > > }
> > > >
> > > > -static unsigned int number_of_same_symbols(char *func_name)
> > > > +static unsigned int number_of_same_symbols(const char *mod, const char
> > > > *func_name) {
> > > >
> > > > struct sym_count_ctx ctx = { .count = 0, .name = func_name };
> > > >
> > > > - kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count);
> > > > + if (!mod)
> > > > + kallsyms_on_each_match_symbol(count_symbols, func_name,
> > >
> > > &ctx.count);
> > >
> > > > - module_kallsyms_on_each_symbol(NULL, count_mod_symbols, &ctx);
> > > > + module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx);
> > >
> > > I may be missing something here or reviewing too quickly.
> > > Wouldn't this function return count to be 0 if func_name is only part of
> > > the module named mod?
> >
> > No, please read below.
> >
> > > Indeed, if the function is not in kernel symbol,
> > > kallsyms_on_each_match_symbol() will not loop.
> > > And, by giving mod to module_kallsyms_on_each_symbol(), the corresponding
> > > module will be skipped, so count_mob_symbols() would not be called.
> > > Hence, we would have 0 as count, which would lead to ENOENT later.
> >
> > Would you mean the case func_name is on the specific module?
> > If 'mod' is specified, module_kallsyms_on_each_symbol() only loops on
> > symbols in the module names 'mod'.
> >
> > int module_kallsyms_on_each_symbol(const char *modname,
> > int (*fn)(void *, const char *, unsigned
> > long), void *data)
> > {
> > struct module *mod;
> > unsigned int i;
> > int ret = 0;
> >
> > mutex_lock(&module_mutex);
> > list_for_each_entry(mod, &modules, list) {
> > struct mod_kallsyms *kallsyms;
> >
> > if (mod->state == MODULE_STATE_UNFORMED)
> > continue;
> >
> > if (modname && strcmp(modname, mod->name))
> > continue;
> > ...
> >
> > So with above change, 'if mod is not specified, search the symbols in kernel
> > and all modules. If mod is sepecified, search the symbol on the specific
> > module'.
> >
> > Thus, "if func_name is only part of the module named mod", the
> > module_kallsyms_on_each_symbol() will count the 'func_name' in 'mod' module
> > correctly.
>
> Sorry, I looked to quickly and forgot about the return value of strcmp()...
No problem, strcmp() always traps us :)
>
> From the code, everything seems OK!
> If I have some time, I will test it and potentially come back with a "Tested-
> by" tag but without any warranty.
Thank you!
>
> > Thank you,
> >
> >
> > Thank you,
>
> Best regards.
>
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2023-11-03 3:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-29 3:10 [PATCH for-next] tracing/kprobes: Add symbol counting check when module loads Masami Hiramatsu (Google)
2023-10-30 13:59 ` Steven Rostedt
2023-10-31 16:56 ` Andrii Nakryiko
2023-10-31 21:24 ` Francis Laniel
2023-10-31 23:15 ` Masami Hiramatsu
2023-11-02 12:57 ` Francis Laniel
2023-11-03 3:27 ` Masami Hiramatsu [this message]
2023-11-10 12:31 ` Francis Laniel
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=20231103122719.829de1daad83a08fe09ab2bd@kernel.org \
--to=mhiramat@kernel.org \
--cc=andrii@kernel.org \
--cc=flaniel@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).