Re: [PATCH v3 00/22] Move notrace from inline to __always_inline

From: Song Liu

Date: Thu Dec 03 2026 - 01:42:05 EST


Hi David,

On Wed, Dec 2, 2026 at 3:56 PM David Laight
<david.laight.linux@xxxxxxxxx> wrote:
>
> On Wed, 2 Dec 2026 11:12:09 -0800
> Song Liu <song@xxxxxxxxxx> wrote:
[...]
> > To clarify, the motivation is not to trace functions marked with
> > "inline". We observed the issue when we want to livepatch a
> > function marked with "inline". If the function is actually inlined
> > by the compiler, we will livepatch the callers of it, which works
> > as-is. However, if the compiler decides not to inline this function,
> > we need extra work for the livepatch (basically apply a bunch of
> > s/inline/__always_inline/). This is not too difficult or too much
> > work. However, I still don't think "inline" means "if not inlined,
> > still not traceable/livepatchable".
>
> Well, the compiler can inline some (but not all) calls to a static
> function and also inline calls to a non-static function.
> So unless you force everything either noinline or always_inline
> you'll always get multiple copies.
> Not to mention the 'constprop' alternatives it can generate when one
> argument is constant.

Yes, it is possible that a function can be inlined at some call sites,
but not at other callsites. This is very confusing for tracing. But
this is not an issue for livepatch at all. The binary diff algorithm,
used by kpatch-build and klp-build, can easily figure out which
functions need patching. For example, we have func_a called by
func_b and func_c, and it is inlined in func_b, but not in func_c.
When we livepatch func_a, the algorithm knows we need to
patch both func_a and func_b.

With current code, if func_a is NOT marked as "inline", this
livepatch works fine. However, if func_a is marked as "inline",
the not inlined version func_a is not ftraceable, and thus not
livepatch-able. This is the issue we want to address in this set.

IOW, with current code, the following livepatch works:

static int func_a() { ... } /* we livepatch func_a */
int func_b() { func_a(); } /* inlined by compiler */
int func_c() { func_a(); } /* NOT inlined by compiler */

But the following livepatch does NOT work:

static int inline func_a() { ... } /* we livepatch func_a */
int func_b() { func_a(); } /* inlined by compiler */
int func_c() { func_a(); } /* NOT inlined by compiler */

The compiler makes the same inlining decisions for both
cases, but the "inline" annotation makes out of line func_a
not livepatch-able, because "inline" includes "notrace" at
the moment.

Does this make sense?

Thanks,
Song