mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] compiler_types: Do not mark inline functions notrace
@ 2026-10-21 22:22 Song Liu
  0 siblings, 0 replies; only message in thread
From: Song Liu @ 2026-10-21 22:22 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel, live-patching
  Cc: rostedt, mhiramat, mark.rutland, kernel-team, Song Liu

Commit 45959ee7aa64 ("ftrace: Do not function trace inlined functions")
added notrace to the inline macro. At the time, inline was only a hint
with CONFIG_OPTIMIZE_INLINING, and whether a given inline function got
an mcount call depended on the gcc version. Some functions that must
not be traced, such as the paravirt native_*() helpers, were marked
inline and relied on being inlined, so a different gcc could silently
break the function tracer. Making all inline functions notrace removed
that dependency on the compiler.

The reasons for that change no longer hold:

 - Code that must not be instrumented is now marked noinstr, and objtool
   validates that noinstr code only calls other noinstr code, see commit
   c4a33939a7eb ("objtool: Implement noinstr validation"). This check
   is based on sections, not on notrace, so an out-of-line inline
   function called from noinstr code is reported whether it is notrace
   or not. The paravirt helpers that the tracer itself depends on, such
   as pv_native_save_fl(), are now in .noinstr.text or __always_inline.

 - All ftrace callbacks are recursion safe since commit a25d036d939a
   ("ftrace: Reverse what the RECURSION flag means in the ftrace_ops"),
   so tracing a function that the tracer itself calls no longer causes
   recursion problems.

 - CONFIG_OPTIMIZE_INLINING was made always on by commit ac7c3e4ff401
   ("compiler: enable CONFIG_OPTIMIZE_INLINING forcibly") and removed
   by commit 889b3c1245de ("compiler: remove CONFIG_OPTIMIZE_INLINING
   entirely"). The compiler also inlines static functions that are not
   marked inline, and creates .constprop, .isra and .part clones, so
   the set of traceable functions already depends on the compiler.
   notrace on inline does not make it consistent. It only hides the
   inline functions that the compiler chose not to inline.

Hiding these functions has a cost. They cannot be traced with ftrace or
used as BPF fentry/fexit targets. They also cannot be livepatched,
because livepatch redirects functions through ftrace, so a fix to one
of them has to be shipped by livepatching its callers instead.

A function that really must not be traced should be marked notrace or
noinstr explicitly, instead of relying on the inline keyword.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@kernel.org>
---
 include/linux/compiler_types.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index c5921f139007..ea7f2a928b4d 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -230,9 +230,8 @@ struct ftrace_likely_data {
  * externally visible function. This makes extern inline behave as per gnu89
  * semantics rather than c99. This prevents multiple symbol definition errors
  * of extern inline functions at link time.
- * A lot of inline functions can cause havoc with function tracing.
  */
-#define inline inline __gnu_inline __inline_maybe_unused notrace
+#define inline inline __gnu_inline __inline_maybe_unused
 
 /*
  * gcc provides both __inline__ and __inline as alternate spellings of
-- 
2.53.0-Meta


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-21 22:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 22:22 [PATCH] compiler_types: Do not mark inline functions notrace Song Liu

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®