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

From: Masami Hiramatsu (Google)

Date: Thu Dec 03 2026 - 21:28:28 EST


Hi Song,

On Wed, 2 Dec 2026 22:49:34 -0800, Song Liu <song@xxxxxxxxxx> wrote:
> On Wed, Dec 2, 2026 at 6:33 PM Masami Hiramatsu (Google)
> <mhiramat@xxxxxxxxxx> wrote:
[...]
> > As David mentioned, depends on the optimization level, normal
> > "static" functions can be inlined silently. Maybe what Song need is
> > a config option to set "-fno-inline". :(
>
> Static functions being inlined silently is not an issue for livepatch.
> The binary diff algorithm will figure out which function(s) really need
> livepatching.
>
> The issue is "inline annotation" plus "not inlined" (compiler decision)
> means not livepatch-able. The proposed fix is to make inline
> annotation does NOT automatically include "notrace".
>
> Does this make sense?

Yes, I understand the livepatch issue you are describing: when a function
is marked `inline` without `__always_inline` and the compiler generates
an instance, the implicit `notrace` on `inline` prevents ftrace (and
thus ftrace-based livepatching) from patching that copy, so you have to
convert it to `__always_inline` or drop `inline` for such cases.

My concern is that modifying inline macros globally could lead to the
exclusion of inline function calls, including those within the internal
execution paths of ftrace and call-graph tracing, from tracing (via
`notrace`), thus there is a risk of the loss of protection against
recursive calls.

-----
For example, `tracing_gen_ctx()` / `tracing_gen_ctx_flags()` (called in
`function_test_events_call()` before `preempt_disable_notrace()` and the
recursion counter check) call `arch_local_save_flags()` and
`arch_irqs_disabled_flags()`, `trace_test_and_set_recursion()` reads
`current` via `current_thread_info()` before setting
`current->trace_recursion`, and `is_kernel_text()` (called by
`core_kernel_text()` in MIPS `prepare_ftrace_return()` before
`function_graph_enter()`) calls `in_gate_area_no_mm()`. Across
architectures without an objtool-like static check for `notrace`, any
remaining or future plain `static inline` helper on those paths can
break silently.
-----

Also, regarding your earlier question about `__switch_to()`:

> Hmm.. Do we really have the protection today? For example, on x86,
> __switch_to is marked with __notrace_funcgraph. But __switch_to
> calls switch_to_extra, which calls __switch_to_xtra, and __switch_to_xtra
> is actually traceable. Is this a problem?

That is actually fine, because __notrace_funcgraph on __switch_to()
is specifically for function_graph's current->ret_stack tracking across
the current task switch, not general ftrace recursion.

In __switch_to(), raw_cpu_write(current_task, next_p) updates `current`:
if __switch_to() itself were graph-traced, entry would push the return
address onto prev_p->ret_stack while return would pop from
next_p->ret_stack. On the other hand, switch_to_extra() is called after
current_task has already switched to next_p, so `current` remains
next_p across both entry and exit of __switch_to_xtra().
This consistency is important for function graph tracer.

On the other hand, if notrace is removed from inline macro without static
verification, an un-inlined "inline" helper called from notrace or
ftrace pre-recursion paths has no such safeguard. That is why I believe
we need compile-time validation (similar to noinstr checks) before
changing inline globally.

Thanks,

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>