Live Patching
 help / color / mirror / Atom feed
From: Song Liu <song@kernel.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	live-patching@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
	bpf@vger.kernel.org
Cc: rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com,
	peterz@infradead.org, tglx@kernel.org, frederic@kernel.org,
	paulmck@kernel.org, catalin.marinas@arm.com, will@kernel.org,
	maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, pjw@kernel.org, palmer@dabbelt.com,
	aou@eecs.berkeley.edu, alex@ghiti.fr, ast@kernel.org,
	daniel@iogearbox.net, andrii@kernel.org, ojeda@kernel.org,
	kernel-team@meta.com, Song Liu <song@kernel.org>
Subject: [PATCH v3 00/22] Move notrace from inline to __always_inline
Date: Mon, 30 Nov 2026 20:21:39 -0800	[thread overview]
Message-ID: <20261201042201.3199928-1-song@kernel.org> (raw)

Since commit 45959ee7aa64 ("ftrace: Do not function trace inlined
functions"), every function marked inline is also notrace. When the
compiler does not inline such a function, the out-of-line copy cannot
be traced with ftrace, cannot be a BPF fentry/fexit target, and cannot
be livepatched. This series moves notrace from inline to
__always_inline, so these copies become traceable. __always_inline
functions, which are mostly low-level helpers, stay untraced.

Patches 1-21 add notrace explicitly to the inline helpers that need it.
While inline still implies notrace, they do not change the generated
code: vmlinux .text is byte-identical with and without them on x86_64
(gcc 11.5), and on arm64, powerpc and riscv (clang 22).

 - 1-2: x86 paravirt native helpers, and the helpers used by resume and
   kexec.
 - 3-6: helpers used by bpf_spin_lock, the BPF trampoline and
   bpf_mem_alloc, where an fentry program on one of them could
   deadlock, recurse without bound or corrupt the free lists.
 - 7-8: tracepoint and SRCU helpers used by tracing.
 - 9-12: helpers used by ftrace recursion protection: the accessors
   behind preempt_count() and current on arm64, powerpc, csky, mips and
   sh, the Tiny RCU rcu_is_watching(), and the tracing_gen_ctx helpers.
 - 13-15: helpers called by notrace code in the trace clocks,
   core_kernel_text() and the nofault accessors.
 - 16-21 (new in v3): helpers that noinstr code calls while RCU is not
   watching or before NMI entry: exception_enter(), the thread flag
   helpers, and helpers on arm64, powerpc and riscv, including the
   arm64 stack unwinder helpers.

To find these, I compared builds with and without patch 22, and listed
the functions that become traceable and are called from code without
an fentry call (notrace, noinstr, or built without -pg). On x86_64 this
includes calls through pv_ops, and objtool's noinstr validation checks
that the noinstr callers call them inside instrumentation windows. For
v2, I repeated the x86_64 analysis with -fno-inline, to also cover
helpers that gcc happens to inline today.

For v3, I also ran the analysis on arm64, powerpc and riscv, built with
clang. These architectures do not have objtool's noinstr validation,
and their noinstr code calls out-of-line copies of plain inline
helpers, some of them before entry code has made RCU watch, in the
cpuidle RCU-idle windows, or in NMI-like handlers. Patches 16-21 mark
these helpers. The remaining untraced callers on these architectures
are the same kinds as on x86_64: noinstr code that calls them while RCU
is watching, __schedule(), the TRACE_EVENT() output functions, and
directories built without -pg. I could not build loongarch or 32-bit
arm, so they are only covered for ftrace recursion protection.

The series makes 712 more functions traceable on x86_64 with
CONFIG_PARAVIRT_XXL and gcc 11.5, and 1464, 1429 and 1128 on arm64,
powerpc and riscv defconfigs with clang 22. None become untraceable.
In QEMU, with ftrace filtered to native_load_idt(), a kernel with v1
dies on resume from S3, as Sashiko predicted. With this series, S3
suspend/resume, CPU hotplug and hibernation test mode pass with ftrace
on all native_* functions, repeated kexec passes with ftrace on all
functions, and the function and function_graph tracers on all
functions show no warnings. The series also builds for i386.

Changes v2 => v3:
 - Rebase on v7.4-rc5 (Steven Rostedt). Patch 9 now applies on top of
   these changes to arch/arm64/include/asm/preempt.h:
   commit 1bee18253c2e ("arm64: preempt: Simplify and optimize __preempt_count_dec_and_test()")
   commit 6254b223153d ("arm64: preempt: Treat should_resched() as unlikely")
 - Add patches 16-21, found by running the analysis on arm64, powerpc
   and riscv.
 - Add Acked-by from Steven to patch 7.

v2: https://lore.kernel.org/all/20261023011049.1164625-1-song@kernel.org/
v1: https://lore.kernel.org/all/20261021222255.3124940-1-song@kernel.org/

Song Liu (22):
  x86/paravirt: Mark native pv_ops helpers notrace
  x86: Mark CPU state helpers used by resume and kexec notrace
  bpf: Mark bpf_spin_lock helpers notrace
  bpf: Mark the BPF trampoline helpers notrace
  bpf: Mark the bpf_mem_alloc fast path helpers notrace
  u64_stats: Mark the update helpers used by BPF notrace
  tracepoint: Mark __do_trace_##name() notrace
  srcu: Mark the fast notrace read-side helpers notrace
  arm64: Mark the preempt count helpers notrace
  powerpc, csky, mips, sh: Mark the accessors behind current notrace
  rcu: Mark the Tiny RCU rcu_is_watching() notrace
  tracing: Mark the tracing_gen_ctx helpers notrace
  ktime: Mark ktime_to_ns() notrace
  kallsyms: Mark the kernel text address checks notrace
  uaccess: Mark pagefault_disable() and pagefault_enable() notrace
  context_tracking: Mark exception_enter() and exception_exit() notrace
  thread_info: Mark the thread flag helpers notrace
  arm64: Mark helpers called from noinstr code notrace
  arm64: Mark the stack unwinder helpers notrace
  powerpc: Mark helpers called from noinstr code notrace
  riscv: Mark helpers called from noinstr code notrace
  compiler_types: Move notrace from inline to __always_inline

 arch/arm64/include/asm/cpufeature.h        |  4 +-
 arch/arm64/include/asm/memory.h            |  2 +-
 arch/arm64/include/asm/mmu.h               |  2 +-
 arch/arm64/include/asm/percpu.h            |  2 +-
 arch/arm64/include/asm/preempt.h           | 12 ++--
 arch/arm64/include/asm/ptrace.h            |  2 +-
 arch/arm64/include/asm/stacktrace.h        | 16 ++---
 arch/arm64/include/asm/stacktrace/common.h | 10 ++--
 arch/arm64/include/asm/vdso/processor.h    |  2 +-
 arch/arm64/include/asm/virt.h              |  2 +-
 arch/csky/include/asm/thread_info.h        |  2 +-
 arch/mips/include/asm/thread_info.h        |  2 +-
 arch/powerpc/include/asm/atomic.h          | 38 ++++++------
 arch/powerpc/include/asm/bitops.h          | 29 ++++-----
 arch/powerpc/include/asm/cmpxchg.h         |  2 +-
 arch/powerpc/include/asm/current.h         |  2 +-
 arch/powerpc/include/asm/entry-common.h    | 32 +++++-----
 arch/powerpc/include/asm/hw_irq.h          | 68 +++++++++++-----------
 arch/powerpc/include/asm/interrupt.h       |  2 +-
 arch/powerpc/include/asm/io.h              | 16 ++---
 arch/powerpc/include/asm/plpar_wrappers.h  |  4 +-
 arch/powerpc/include/asm/ptrace.h          | 14 ++---
 arch/powerpc/include/asm/rtas.h            | 10 ++--
 arch/powerpc/include/asm/synch.h           |  6 +-
 arch/powerpc/include/asm/thread_info.h     |  4 +-
 arch/powerpc/kernel/watchdog.c             |  4 +-
 arch/riscv/include/asm/cpuidle.h           |  2 +-
 arch/riscv/include/asm/irqflags.h          | 14 ++---
 arch/riscv/include/asm/vdso/processor.h    |  2 +-
 arch/riscv/include/asm/vector.h            |  8 +--
 arch/sh/include/asm/thread_info.h          |  2 +-
 arch/x86/include/asm/cpuid/api.h           |  4 +-
 arch/x86/include/asm/desc.h                | 17 +++---
 arch/x86/include/asm/gsseg.h               |  4 +-
 arch/x86/include/asm/io.h                  |  2 +-
 arch/x86/include/asm/io_bitmap.h           |  2 +-
 arch/x86/include/asm/local.h               |  8 +--
 arch/x86/include/asm/msr.h                 |  8 +--
 arch/x86/include/asm/paravirt-spinlock.h   |  2 +-
 arch/x86/include/asm/paravirt.h            | 20 +++----
 arch/x86/include/asm/pgalloc.h             |  2 +-
 arch/x86/include/asm/pgtable_64.h          | 10 ++--
 arch/x86/include/asm/processor.h           |  2 +-
 arch/x86/include/asm/segment.h             |  4 +-
 arch/x86/include/asm/special_insns.h       |  8 +--
 include/asm-generic/sections.h             |  4 +-
 include/linux/bpf.h                        |  8 +--
 include/linux/compiler_attributes.h        |  6 +-
 include/linux/compiler_types.h             |  3 +-
 include/linux/context_tracking.h           |  4 +-
 include/linux/kallsyms.h                   |  2 +-
 include/linux/ktime.h                      |  2 +-
 include/linux/llist.h                      | 16 ++---
 include/linux/percpu-refcount.h            | 12 ++--
 include/linux/pgtable.h                    | 12 ++--
 include/linux/rcupdate.h                   | 14 ++---
 include/linux/rcupdate_trace.h             |  4 +-
 include/linux/rcutiny.h                    |  2 +-
 include/linux/sched.h                      |  8 +--
 include/linux/srcu.h                       | 10 ++--
 include/linux/srcutiny.h                   |  5 +-
 include/linux/srcutree.h                   |  2 +-
 include/linux/thread_info.h                | 12 ++--
 include/linux/trace_events.h               |  6 +-
 include/linux/tracepoint.h                 |  4 +-
 include/linux/u64_stats_sync.h             | 30 +++++-----
 include/linux/uaccess.h                    |  4 +-
 kernel/bpf/helpers.c                       | 12 ++--
 68 files changed, 300 insertions(+), 292 deletions(-)


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.53.1-Meta


             reply	other threads:[~2026-12-01  4:22 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  4:21 Song Liu [this message]
2026-12-01  4:21 ` [PATCH v3 01/22] x86/paravirt: Mark native pv_ops helpers notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 02/22] x86: Mark CPU state helpers used by resume and kexec notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 03/22] bpf: Mark bpf_spin_lock helpers notrace Song Liu
2026-12-01  4:55   ` bot+bpf-ci
2026-12-01  4:21 ` [PATCH v3 04/22] bpf: Mark the BPF trampoline " Song Liu
2026-12-01  5:08   ` bot+bpf-ci
2026-12-01  4:21 ` [PATCH v3 05/22] bpf: Mark the bpf_mem_alloc fast path " Song Liu
2026-12-01  4:21 ` [PATCH v3 06/22] u64_stats: Mark the update helpers used by BPF notrace Song Liu
2026-12-01  4:55   ` bot+bpf-ci
2026-12-01  4:21 ` [PATCH v3 07/22] tracepoint: Mark __do_trace_##name() notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 08/22] srcu: Mark the fast notrace read-side helpers notrace Song Liu
2026-12-01  4:39   ` sashiko-bot
2026-12-01  4:21 ` [PATCH v3 09/22] arm64: Mark the preempt count " Song Liu
2026-12-01  4:21 ` [PATCH v3 10/22] powerpc, csky, mips, sh: Mark the accessors behind current notrace Song Liu
2026-12-01  5:08   ` bot+bpf-ci
2026-12-01  4:21 ` [PATCH v3 11/22] rcu: Mark the Tiny RCU rcu_is_watching() notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 12/22] tracing: Mark the tracing_gen_ctx helpers notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 13/22] ktime: Mark ktime_to_ns() notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 14/22] kallsyms: Mark the kernel text address checks notrace Song Liu
2026-12-01  4:36   ` sashiko-bot
2026-12-01  4:21 ` [PATCH v3 15/22] uaccess: Mark pagefault_disable() and pagefault_enable() notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 16/22] context_tracking: Mark exception_enter() and exception_exit() notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 17/22] thread_info: Mark the thread flag helpers notrace Song Liu
2026-12-01  4:21 ` [PATCH v3 18/22] arm64: Mark helpers called from noinstr code notrace Song Liu
2026-12-01  4:53   ` sashiko-bot
2026-12-01  4:21 ` [PATCH v3 19/22] arm64: Mark the stack unwinder helpers notrace Song Liu
2026-12-01  4:47   ` sashiko-bot
2026-12-01  4:21 ` [PATCH v3 20/22] powerpc: Mark helpers called from noinstr code notrace Song Liu
2026-12-01  4:50   ` sashiko-bot
2026-12-01  5:08   ` bot+bpf-ci
2026-12-01  4:22 ` [PATCH v3 21/22] riscv: " Song Liu
2026-12-01  4:22 ` [PATCH v3 22/22] compiler_types: Move notrace from inline to __always_inline Song Liu
2026-12-01  5:08   ` bot+bpf-ci
2026-12-01  5:17   ` sashiko-bot

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=20261201042201.3199928-1-song@kernel.org \
    --to=song@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=andrii@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=chleroy@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=frederic@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=live-patching@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=will@kernel.org \
    /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