From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796098944; b=rDhV2mUSLdBSUQ5a1F2g/DB6lBGR47uwzfilvorXnFnQqzD/kgh2MfrGkf4Uqjs7sCgl l3JwAnuE81q9uzrfvZaB515O/IFnE54UiW48KkCG/Fgv7SvAlnmL+O5qzHUjtD9wN97Fd KuQ5tEc/SgvmSuKZ6kq9uTMHTA23iNtZU7dkkDvcranNy5qfnAZTrpcILFKo3Ydkrbszy ldrywXTHku7HxXDPVUr6+81Km9ZO8B2qdExW8Pj9dnYSyaGKK00h8pSXqvXwWs9fpEqmK xvlHuHDN3+UNorzAuhzFD2Roq8SEHPUJpKQ37+0GUyxhl9+CSL69xV/AqawMMhtUhzQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796098944; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=hZMpM49PX8nWdUQzRIJX6vuqVhN286CowzmTPJgtyPM=; b=SCNa4Dc3tQ8N2mx3YsOlytnxu8DYrqP5DenLiPq1IRedP6zhtF22t3JRMwl9RGCBd7// c+wR4RJinCkf1/IPkQj0lI5ZeI4g2tmEPxnga6tM/H2Ei6ZXxn9HAqB6GnbrcOSaQ0daW lKBgjIzJhDuxPoiJmDoWVnWOG8nGKGyR957ZtP5w5PNdFsBHnmBHm2+nk27kxW2k3H42y ysrtWA2/8WinmEUV0XWB4muBmfgXzJeysGfCduer0unEsfc7oRuDaTKVhctQ1ZoflVpA6 HXSS5qbomXfJthKik14jvHN/HpA3WXJqsbYLXENU/FX+Cuy09R5ok8I44tXgeZp8J9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CltBXl3r; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E502606A31A; Tue, 1 Dec 2026 04:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CltBXl3r Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17E1A1F000C1; Tue, 1 Dec 2026 04:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796098944; bh=hZMpM49PX8nWdUQzRIJX6vuqVhN286CowzmTPJgtyPM=; h=From:To:Cc:Subject:Date; b=CltBXl3r4FGARZkG3TlLm5Mab/VPWAKUBxY7rfeeKI+5F9++46xiKhLNZWWDm/Plg w9OR4oZK1oVE2egz9X5bOh6FAREgHMwTSHoMo5LA6Dhq24bfxhXcH95x9Kwjj2jlt6 CRWg7P7SvPyAQBurSPrrUuNGrSnmXJzrPx+B8n5JGKjbAgH/GUR3UtLQMwfugnU2Nj IlSvC3uT68GQyd+Yx7g4G0ehUMa4KOte672fF8LpDt755zdWhp/aRj4QH0Gf7+zIYQ LgZaUNwukiiYg2v7TrHgPPucp4Xl9pVNX+BCCj271RQ6+OMMOtuxxFts/FaVMUhGEb w+eXiDa33QQXQ== From: Song Liu 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 Subject: [PATCH v3 00/22] Move notrace from inline to __always_inline Date: Mon, 30 Nov 2026 20:21:39 -0800 Message-ID: <20261201042201.3199928-1-song@kernel.org> X-Mailer: git-send-email 2.53.1 X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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