From: Petr Mladek <pmladek@suse.com>
To: Song Liu <song@kernel.org>
Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, jpoimboe@kernel.org,
jikos@kernel.org, mbenes@suse.cz, joe.lawrence@redhat.com,
nathan@kernel.org, morbo@google.com, justinstitt@google.com,
mcgrof@kernel.org, thunder.leizhen@huawei.com, kees@kernel.org,
kernel-team@meta.com, mmaurer@google.com,
samitolvanen@google.com, mhiramat@kernel.org,
rostedt@goodmis.org
Subject: Re: [PATCH v2 2/3] kallsyms: Add APIs to match symbol without .XXXX suffix.
Date: Thu, 8 Aug 2024 12:20:55 +0200 [thread overview]
Message-ID: <ZrScBzRRTB--q7Y-@pathway.suse.cz> (raw)
In-Reply-To: <20240802210836.2210140-3-song@kernel.org>
On Fri 2024-08-02 14:08:34, Song Liu wrote:
> With CONFIG_LTO_CLANG=y, the compiler may add suffix to function names
> to avoid duplication. This causes confusion with users of kallsyms.
> On one hand, users like livepatch are required to match the symbols
> exactly. On the other hand, users like kprobe would like to match to
> original function names.
>
> Solve this by splitting kallsyms APIs. Specifically, existing APIs now
> should match the symbols exactly. Add two APIs that match only the part
> without .XXXX suffix. Specifically, the following two APIs are added.
>
> 1. kallsyms_lookup_name_without_suffix()
> 2. kallsyms_on_each_match_symbol_without_suffix()
>
> These APIs will be used by kprobe.
>
> Also cleanup some code and update kallsyms_selftests accordingly.
>
> --- a/kernel/kallsyms.c
> +++ b/kernel/kallsyms.c
> @@ -164,30 +164,27 @@ static void cleanup_symbol_name(char *s)
> {
> char *res;
>
> - if (!IS_ENABLED(CONFIG_LTO_CLANG))
> - return;
> -
> /*
> * LLVM appends various suffixes for local functions and variables that
> * must be promoted to global scope as part of LTO. This can break
> * hooking of static functions with kprobes. '.' is not a valid
> - * character in an identifier in C. Suffixes only in LLVM LTO observed:
> - * - foo.llvm.[0-9a-f]+
> + * character in an identifier in C, so we can just remove the
> + * suffix.
> */
> - res = strstr(s, ".llvm.");
> + res = strstr(s, ".");
IMHO, we should not remove the suffixes like .constprop*, .part*,
.isra*. They implement a special optimized variant of the function.
It is not longer the original full-featured one.
> if (res)
> *res = '\0';
>
> return;
> }
>
> -static int compare_symbol_name(const char *name, char *namebuf)
> +static int compare_symbol_name(const char *name, char *namebuf, bool exact_match)
> {
> - /* The kallsyms_seqs_of_names is sorted based on names after
> - * cleanup_symbol_name() (see scripts/kallsyms.c) if clang lto is enabled.
> - * To ensure correct bisection in kallsyms_lookup_names(), do
> - * cleanup_symbol_name(namebuf) before comparing name and namebuf.
> - */
> + int ret = strcmp(name, namebuf);
> +
> + if (exact_match || !ret)
> + return ret;
> +
> cleanup_symbol_name(namebuf);
> return strcmp(name, namebuf);
> }
> @@ -204,13 +201,17 @@ static unsigned int get_symbol_seq(int index)
>
> static int kallsyms_lookup_names(const char *name,
> unsigned int *start,
> - unsigned int *end)
> + unsigned int *end,
> + bool exact_match)
> {
> int ret;
> int low, mid, high;
> unsigned int seq, off;
> char namebuf[KSYM_NAME_LEN];
>
> + if (!IS_ENABLED(CONFIG_LTO_CLANG))
> + exact_match = true;
IMHO, this is very a bad design. It causes that
kallsyms_on_each_match_symbol_without_suffix(,,, false);
does not longer work as expected. It creates a hard to maintain
code. The code does not do what it looks like.
The caller should decide whether it wants to ignore the suffix or no.
And this function should always respect the @exact_match parameter value.
> +
> low = 0;
> high = kallsyms_num_syms - 1;
>
Best Regards,
Petr
next prev parent reply other threads:[~2024-08-08 10:20 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 21:08 [PATCH v2 0/3] Fix kallsyms with CONFIG_LTO_CLANG Song Liu
2024-08-02 21:08 ` [PATCH v2 1/3] kallsyms: Do not cleanup .llvm.<hash> suffix before sorting symbols Song Liu
2024-08-02 21:08 ` [PATCH v2 2/3] kallsyms: Add APIs to match symbol without .XXXX suffix Song Liu
2024-08-05 13:45 ` Masami Hiramatsu
2024-08-05 17:46 ` Song Liu
2024-08-08 10:20 ` Petr Mladek [this message]
2024-08-08 15:13 ` Song Liu
2024-08-02 21:08 ` [PATCH v2 3/3] tracing/kprobes: Use APIs that matches symbols without .XXX suffix Song Liu
2024-08-06 18:44 ` Steven Rostedt
2024-08-06 19:35 ` Song Liu
2024-08-06 20:00 ` Steven Rostedt
2024-08-06 20:01 ` Steven Rostedt
2024-08-06 20:12 ` Song Liu
2024-08-07 0:01 ` Masami Hiramatsu
2024-08-07 0:19 ` Song Liu
2024-08-07 10:08 ` Masami Hiramatsu
2024-08-07 15:33 ` Sami Tolvanen
2024-08-07 20:48 ` Song Liu
2024-08-08 9:59 ` Petr Mladek
2024-08-08 15:20 ` Song Liu
2024-08-09 15:40 ` Petr Mladek
2024-08-09 16:33 ` Song Liu
2024-08-08 15:52 ` Masami Hiramatsu
2024-08-09 6:20 ` Alessandro Carminati
2024-08-09 16:40 ` Song Liu
2024-08-07 21:26 ` Masami Hiramatsu
2024-08-07 19:41 ` Song Liu
2024-08-07 20:08 ` Steven Rostedt
2024-08-07 20:40 ` Song Liu
2024-08-07 20:43 ` Song Liu
2024-08-07 20:55 ` Masami Hiramatsu
2024-08-07 21:07 ` Song Liu
2024-08-07 14:58 ` zhang warden
2024-08-07 19:46 ` Song Liu
2024-08-08 2:10 ` zhang warden
2024-08-08 9:48 ` Petr Mladek
2024-08-08 15:17 ` 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=ZrScBzRRTB--q7Y-@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mmaurer@google.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.com \
--cc=song@kernel.org \
--cc=thunder.leizhen@huawei.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;
as well as URLs for NNTP newsgroup(s).