Live Patching
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@meta.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Song Liu <songliubraving@meta.com>, Song Liu <song@kernel.org>,
	"Leizhen (ThunderTown)" <thunder.leizhen@huawei.com>,
	"live-patching@vger.kernel.org" <live-patching@vger.kernel.org>,
	"jpoimboe@kernel.org" <jpoimboe@kernel.org>,
	"jikos@kernel.org" <jikos@kernel.org>,
	"mbenes@suse.cz" <mbenes@suse.cz>,
	"joe.lawrence@redhat.com" <joe.lawrence@redhat.com>,
	Kernel Team <kernel-team@meta.com>,
	"mcgrof@kernel.org" <mcgrof@kernel.org>
Subject: Re: [PATCH] kallsyms: let kallsyms_on_each_match_symbol match symbols exactly
Date: Wed, 21 Jun 2023 19:18:03 +0000	[thread overview]
Message-ID: <E47B9D18-299C-4F95-B4F6-24DB6A54A79F@fb.com> (raw)
In-Reply-To: <ZJK5tiO3wXHiBeBh@alley>



> On Jun 21, 2023, at 1:52 AM, Petr Mladek <pmladek@suse.com> wrote:
> 
> On Tue 2023-06-20 22:36:14, Song Liu wrote:
>>> On Jun 19, 2023, at 4:32 AM, Petr Mladek <pmladek@suse.com> wrote:
>>> 
>>> On Sun 2023-06-18 22:05:19, Song Liu wrote:
>>>> On Sun, Jun 18, 2023 at 8:32 PM Leizhen (ThunderTown)
>>>> <thunder.leizhen@huawei.com> wrote:
>> 
>> [...]

[...]

>> 
>> I am not quite following the direction here. Do we need more 
>> work for this patch?
> 
> Good question. I primary tried to add more details so that
> we better understand the problem.
> 
> Honestly, I do not know the answer. I am neither familiar with
> kpatch nor with clang. Let me think loudly.
> 
> kpatch produce livepatches by comparing binaries of the original
> and fixed kernel. It adds a symbol into the livepatch when
> the same symbol has different code in the two binaries.
> 
> So one important question is how clang generates the suffix.
> Is the suffix the same in every build? Is it the same even
> after the function gets modified by a fix?
> 
> If the suffix is always the same then then the full symbol name
> would be better for kpatch. kpatch would get it for free.
> And kpatch would not longer need to use "old_sympos".

This is pretty complicated. 

1. clang with LTO does not use the suffix to eliminated duplicated
kallsyms, so old_sympos is still needed. Here is an example:

# grep init_once /proc/kallsyms
ffffffff8120ba80 t init_once.llvm.14172910296636650566
ffffffff8120ba90 t inode_init_once
ffffffff813ea5d0 t bpf_user_rnd_init_once
ffffffff813fd5b0 t init_once.llvm.17912494158778303782
ffffffff813ffbf0 t init_once
ffffffff813ffc60 t init_once
ffffffff813ffc70 t init_once
ffffffff813ffcd0 t init_once
ffffffff813ffce0 t init_once

There are two "init_once" with suffix, but there are also ones 
without them. 

2. kpatch-build does "Building original source", "Building patched 
source", and then do binary diff of the two. From our experiments, 
the suffix doesn't change between the two builds. However, we need
to match the build environment (path of kernel source, etc.) to 
make sure suffix from kpatch matches the kernel. 

3. The goal of this patch is NOT to resolve different suffix by 
llvm (.llvm.[0-9]+). Instead, we are trying fix issues like:

#  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

With existing code, compare_symbol_name() will match 
bpf_verifier_vlog to all these with CONFIG_LTO_CLANG.

We can probably teach compare_symbol_name() to not to match
these suffix, as Zhen suggested. 

If this is not ideal, I am open to suggestions that can solve
the problem. 

> But if the suffix is different then kpatch has a problem.
> kpatch would need to match symbols with different suffixes.
> It would be easy for symbols which are unique after removing
> the suffix. But it would be tricky for comparing symbols
> which do not have an unique name. kpatch would need to find
> which suffix in the original binary matches an other suffix
> in the fixed binary. In this case, it might be easier
> to use the stripped symbol names.
> 
> And the suffix might be problematic also for source based
> livepatches. They define struct klp_func in sources so
> they would need to hardcode the suffix there. It might
> be easy to keep using the stripped name and "old_sympos".
> 
> I expect that this patch actually breaks the livepatch
> selftests when the kernel is compiled with clang LTO.

Not really. This patch passes livepatch selftests. 

Thanks,
Song


  reply	other threads:[~2023-06-21 19:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 17:00 [PATCH] kallsyms: let kallsyms_on_each_match_symbol match symbols exactly Song Liu
2023-06-16  2:19 ` Leizhen (ThunderTown)
2023-06-16  5:01   ` Song Liu
2023-06-16  8:11     ` Leizhen (ThunderTown)
2023-06-16  8:43       ` Leizhen (ThunderTown)
2023-06-16  8:52         ` Leizhen (ThunderTown)
2023-06-16 17:40           ` Song Liu
2023-06-16  9:31 ` Leizhen (ThunderTown)
2023-06-16 17:37   ` Song Liu
2023-06-19  3:32     ` Leizhen (ThunderTown)
2023-06-19  5:05       ` Song Liu
2023-06-19 11:32         ` Petr Mladek
2023-06-20 22:36           ` Song Liu
2023-06-21  8:52             ` Petr Mladek
2023-06-21 19:18               ` Song Liu [this message]
2023-06-21 22:34                 ` Yonghong Song
2023-06-22 13:35                   ` Petr Mladek
2023-06-22 16:10                     ` Yonghong Song
     [not found]                       ` <4616610E-180A-4417-8592-B864F6298C7F@fb.com>
2023-06-22 20:45                         ` Yonghong Song
2023-06-23 17:43                       ` Nick Desaulniers
2023-06-25 19:06                         ` Yonghong Song

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=E47B9D18-299C-4F95-B4F6-24DB6A54A79F@fb.com \
    --to=songliubraving@meta.com \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mcgrof@kernel.org \
    --cc=pmladek@suse.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