mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@meta.com>
To: "Leizhen (ThunderTown)" <thunder.leizhen@huawei.com>,
	Yonghong Song <yhs@fb.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Petr Mladek <pmladek@suse.com>, Song Liu <song@kernel.org>
Cc: Fangrui Song <maskray@google.com>,
	kernel-team@fb.com, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH] kallsyms: strip LTO-only suffixes from promoted global functions
Date: Wed, 28 Jun 2023 10:25:55 -0700	[thread overview]
Message-ID: <7404b9cd-f57e-e76b-87ff-ae3b1f68e381@meta.com> (raw)
In-Reply-To: <42da73d9-063b-24c9-6a7e-734403827dcb@huawei.com>



On 6/28/23 4:34 AM, Leizhen (ThunderTown) wrote:
> 
> 
> On 2023/6/28 14:44, Yonghong Song wrote:
>> Commit 6eb4bd92c1ce ("kallsyms: strip LTO suffixes from static functions")
>> stripped all function/variable suffixes started with '.' regardless
>> of whether those suffixes are generated at LTO mode or not. In fact,
>> as far as I know, in LTO mode, when a static function/variable is
>> promoted to the global scope, '.llvm.<...>' suffix is added.
>>
>> The existing mechanism breaks live patch for a LTO kernel even if
>> no <symbol>.llvm.<...> symbols are involved. For example, for the following
>> kernel symbols:
>>    $ grep bpf_verifier_vlog /proc/kallsyms
>>    ffffffff81549f60 t bpf_verifier_vlog
>>    ffffffff8268b430 d bpf_verifier_vlog._entry
>>    ffffffff8282a958 d bpf_verifier_vlog._entry_ptr
>>    ffffffff82e12a1f d bpf_verifier_vlog.__already_done
>> 'bpf_verifier_vlog' is a static function. '_entry', '_entry_ptr' and
>> '__already_done' are static variables used inside 'bpf_verifier_vlog',
>> so llvm promotes them to file-level static with prefix 'bpf_verifier_vlog.'.
>> Note that the func-level to file-level static function promotion also
>> happens without LTO.
>>
>> Given a symbol name 'bpf_verifier_vlog', with LTO kernel, current mechanism will
>> return 4 symbols to live patch subsystem which current live patching
>> subsystem cannot handle it. With non-LTO kernel, only one symbol
>> is returned.
>>
>> In [1], we have a lengthy discussion, the suggestion is to separate two
>> cases:
>>    (1). new symbols with suffix which are generated regardless of whether
>>         LTO is enabled or not, and
>>    (2). new symbols with suffix generated only when LTO is enabled.
>>
>> The cleanup_symbol_name() should only remove suffixes for case (2).
>> Case (1) should not be changed so it can work uniformly with or without LTO.
>>
>> This patch removed LTO-only suffix '.llvm.<...>' so live patching and
>> tracing should work the same way for non-LTO kernel.
>>
>>   [1] https://lore.kernel.org/live-patching/20230615170048.2382735-1-song@kernel.org/T/#u
> 
> Missed the addition of:
> Reported-by: Song Liu <song@kernel.org>

Will add in the next revision.

> 
>>
>> Fixes: 6eb4bd92c1ce ("kallsyms: strip LTO suffixes from static functions")
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   kernel/kallsyms.c | 5 ++---
>>   1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
>> index 77747391f49b..4874508bb950 100644
>> --- a/kernel/kallsyms.c
>> +++ b/kernel/kallsyms.c
>> @@ -174,11 +174,10 @@ static bool cleanup_symbol_name(char *s)
>>   	 * 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 observed:
>> +	 * character in an identifier in C. Suffixes only in LLVM LTO observed:
>>   	 * - foo.llvm.[0-9a-f]+
>> -	 * - foo.[0-9a-f]+
>>   	 */
>> -	res = strchr(s, '.');
>> +	res = strstr(s, ".llvm.");
> 
> We'd better modify function cleanup_symbol_name() in scripts/kallsyms.c accordingly.

Thanks, will make corresponding change in scripts/kallsyms.c as well.

> 
> 
>>   	if (res) {
>>   		*res = '\0';
>>   		return true;
>>
> 

      reply	other threads:[~2023-06-28 17:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28  6:44 Yonghong Song
2023-06-28 11:34 ` Leizhen (ThunderTown)
2023-06-28 17:25   ` Yonghong Song [this message]

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=7404b9cd-f57e-e76b-87ff-ae3b1f68e381@meta.com \
    --to=yhs@meta.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=maskray@google.com \
    --cc=ndesaulniers@google.com \
    --cc=pmladek@suse.com \
    --cc=song@kernel.org \
    --cc=thunder.leizhen@huawei.com \
    --cc=yhs@fb.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®