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=1796099012; b=oTV5GX92wDRkWUECBgfbCF2QB5//CLYtLKm6M+YNjmP3lbGNkGstNRvbDK45jJykWVcu BYsSjA43erRgW4KDP4iIzIO+RbF/O/6VHsDFSqlaiBn91AUdV+FJSw2cU/zd64gbeX862 clUXGBDEZ2lmf4/HqFk37MvoEyNA3wnxpEpzw4oHsqwK0AVNqK+VRGdZ8SYBQQfhBSYaX N48wiOw/WW15KGnVzUFbsi64QRz0Mz5IXKzDDLv242ubaGBk1oNzS1YkdBMEXINnB15qY RisL5nCl3WezK9jSTTRMJtHLX1w/LuRuUNYHtE9XHEoORDsMrUyluJcDwScmTNzcegw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796099012; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=gMmpCTplOoC0BBrL1mJyDsaJ//CpSacdQiDFiPAwQpc=; b=LYLgyohNUwDam2hwono/+aH3Ov1Pllv9fGP3BsUwbcsvJ5jkqfrfJx86FAs7C8f6RWkK S+RfY0vwFc1nJSNNzy5KnLhsDzVhPA/XvM3p62lK9znoqZ9fr6Wa/8bzO4W/CKybeFxkJ /7TTEUJp1NJrGVLJpxKzN/n6UwJNZykbHO7OSe/t3T0BjcZKA/GcqFuOqjRdSR5aUtD+k hWu0LdT44UslYIMlFoYadgeifbkw77qFobls50b7bqok451eA/Z/D9xdQurUq2UCXrQzN nm359ThAWZDxnQOfJRhUvsO5YyB+sKR8tqC9HJgQmKqSOORXPDZ1XYvfD8VojnX7iCA== 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=aaGpBszl; 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 157EB606A325; Tue, 1 Dec 2026 04:23:31 +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=aaGpBszl Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA2641F00A16; Tue, 1 Dec 2026 04:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796099011; bh=gMmpCTplOoC0BBrL1mJyDsaJ//CpSacdQiDFiPAwQpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aaGpBszlBl05AX7jADnO6ZG9u7dvCz8O97UtMUdN2tGsEbuewXpl14KEi4oqNjIpt wGgMgcdpsRwhnWb4CSwA/f9CAPiSQKLMiJq9XA+chtP0nSwkPyAH9G/nvdiZs309ly 2Df6VYGeeZ6ba+NhIYRpEnFF3p/yRS1ddJ3q8OLisNhlUYpLrUT5MTwMwW5feNVbMr sRS3osoSrmzmSwUtQRjeX3ay6fMTAHoIBTs/jVUd9IcJG5zai+kKf3g6yG1T6+Aa0V IFDTZnDqI3cZTQ1tEWUE5HPT3JZojzi/NDaN0e5qhDW/kxRzksDejgHxbpUNxHfy1V NHAUkLGOz8ZiQ== 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 04/22] bpf: Mark the BPF trampoline helpers notrace Date: Mon, 30 Nov 2026 20:21:43 -0800 Message-ID: <20261201042201.3199928-5-song@kernel.org> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261201042201.3199928-1-song@kernel.org> References: <20261201042201.3199928-1-song@kernel.org> X-Mailing-List: linux-kernel@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 The BPF trampoline calls __bpf_prog_enter*() before each program and __bpf_prog_exit*() after it, and calls __bpf_tramp_enter() and __bpf_tramp_exit() around the traced function. These functions are notrace: if anything they call could run a BPF program, attaching a program there would recurse without bound. The recursion check in __bpf_prog_enter_recur() does not prevent this, because the trampoline calls the enter and exit functions even for a program it then skips. For the same reason, btf_id_deny already rejects attaching to the out-of-line migrate_disable() and migrate_enable(), and, with CONFIG_PREEMPT_RCU, to __rcu_read_lock() and __rcu_read_unlock(). Many of the helpers they call are plain inline functions: - bpf_set_run_ctx(), bpf_reset_run_ctx(), bpf_prog_get_recursion_context() and bpf_prog_put_recursion_context(); - __migrate_disable() and __migrate_enable(); - the !CONFIG_PREEMPT_RCU __rcu_read_lock() and __rcu_read_unlock(), rcu_read_unlock() and rcu_read_unlock_migrate(), and the lockdep annotations rcu_lock_acquire(), rcu_try_lock_acquire() and rcu_lock_release(); - rcu_read_lock_trace(), rcu_read_unlock_trace() and srcu_lock_release(); - percpu_ref_get(), percpu_ref_put(), percpu_ref_get_many(), percpu_ref_put_many() and __ref_is_percpu(); - local_inc() and local_add() on x86, called through u64_stats_inc() and u64_stats_add() from bpf_prog_inc_misses_counter() and __update_prog_stats(). An out-of-line copy of any of them is untraced only because inline implies notrace. Mark them notrace explicitly. No functional change. Assisted-by: Claude:claude-opus-5 Signed-off-by: Song Liu --- arch/x86/include/asm/local.h | 4 ++-- include/linux/bpf.h | 8 ++++---- include/linux/percpu-refcount.h | 12 ++++++------ include/linux/rcupdate.h | 14 +++++++------- include/linux/rcupdate_trace.h | 4 ++-- include/linux/sched.h | 8 ++++---- include/linux/srcu.h | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h index 68af7b74450a..07b1d52e9ab4 100644 --- a/arch/x86/include/asm/local.h +++ b/arch/x86/include/asm/local.h @@ -16,7 +16,7 @@ typedef struct { #define local_read(l) atomic_long_read(&(l)->a) #define local_set(l, i) atomic_long_set(&(l)->a, (i)) -static inline void local_inc(local_t *l) +static inline void notrace local_inc(local_t *l) { asm volatile(_ASM_INC "%0" : "+m" (l->a.counter)); @@ -28,7 +28,7 @@ static inline void local_dec(local_t *l) : "+m" (l->a.counter)); } -static inline void local_add(long i, local_t *l) +static inline void notrace local_add(long i, local_t *l) { asm volatile(_ASM_ADD "%1,%0" : "+m" (l->a.counter) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index a6976776e90b..62714645aa2b 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2330,7 +2330,7 @@ struct bpf_struct_ops_common_value { enum bpf_struct_ops_state state; }; -static inline bool bpf_prog_get_recursion_context(struct bpf_prog *prog) +static inline bool notrace bpf_prog_get_recursion_context(struct bpf_prog *prog) { #ifdef CONFIG_ARM64 u8 rctx = interrupt_context_level(); @@ -2350,7 +2350,7 @@ static inline bool bpf_prog_get_recursion_context(struct bpf_prog *prog) #endif } -static inline void bpf_prog_put_recursion_context(struct bpf_prog *prog) +static inline void notrace bpf_prog_put_recursion_context(struct bpf_prog *prog) { #ifdef CONFIG_ARM64 u8 rctx = interrupt_context_level(); @@ -2769,7 +2769,7 @@ struct bpf_tramp_run_ctx { struct bpf_run_ctx *saved_run_ctx; }; -static inline struct bpf_run_ctx *bpf_set_run_ctx(struct bpf_run_ctx *new_ctx) +static inline notrace struct bpf_run_ctx *bpf_set_run_ctx(struct bpf_run_ctx *new_ctx) { struct bpf_run_ctx *old_ctx = NULL; @@ -2780,7 +2780,7 @@ static inline struct bpf_run_ctx *bpf_set_run_ctx(struct bpf_run_ctx *new_ctx) return old_ctx; } -static inline void bpf_reset_run_ctx(struct bpf_run_ctx *old_ctx) +static inline void notrace bpf_reset_run_ctx(struct bpf_run_ctx *old_ctx) { #ifdef CONFIG_BPF_SYSCALL current->bpf_ctx = old_ctx; diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h index 1e3212e2c827..ebfcbf668a7e 100644 --- a/include/linux/percpu-refcount.h +++ b/include/linux/percpu-refcount.h @@ -155,8 +155,8 @@ static inline void percpu_ref_kill(struct percpu_ref *ref) * because doing so forces the compiler to generate two conditional * branches as it can't assume that @ref->percpu_count is not NULL. */ -static inline bool __ref_is_percpu(struct percpu_ref *ref, - unsigned long __percpu **percpu_countp) +static inline bool notrace __ref_is_percpu(struct percpu_ref *ref, + unsigned long __percpu **percpu_countp) { unsigned long percpu_ptr; @@ -195,7 +195,7 @@ static inline bool __ref_is_percpu(struct percpu_ref *ref, * * This function is safe to call as long as @ref is between init and exit. */ -static inline void percpu_ref_get_many(struct percpu_ref *ref, unsigned long nr) +static inline void notrace percpu_ref_get_many(struct percpu_ref *ref, unsigned long nr) { unsigned long __percpu *percpu_count; @@ -217,7 +217,7 @@ static inline void percpu_ref_get_many(struct percpu_ref *ref, unsigned long nr) * * This function is safe to call as long as @ref is between init and exit. */ -static inline void percpu_ref_get(struct percpu_ref *ref) +static inline void notrace percpu_ref_get(struct percpu_ref *ref) { percpu_ref_get_many(ref, 1); } @@ -324,7 +324,7 @@ static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) * * This function is safe to call as long as @ref is between init and exit. */ -static inline void percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr) +static inline void notrace percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr) { unsigned long __percpu *percpu_count; @@ -347,7 +347,7 @@ static inline void percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr) * * This function is safe to call as long as @ref is between init and exit. */ -static inline void percpu_ref_put(struct percpu_ref *ref) +static inline void notrace percpu_ref_put(struct percpu_ref *ref) { percpu_ref_put_many(ref, 1); } diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 3f74ae6d6e1f..5ac08bebc17b 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -107,12 +107,12 @@ void __rcu_read_unlock(void); void rcu_read_unlock_strict(void); #endif -static inline void __rcu_read_lock(void) +static inline void notrace __rcu_read_lock(void) { preempt_disable(); } -static inline void __rcu_read_unlock(void) +static inline void notrace __rcu_read_unlock(void) { if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD)) rcu_read_unlock_strict(); @@ -304,17 +304,17 @@ extern struct lockdep_map rcu_callback_map; #ifdef CONFIG_DEBUG_LOCK_ALLOC -static inline void rcu_lock_acquire(struct lockdep_map *map) +static inline void notrace rcu_lock_acquire(struct lockdep_map *map) { lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_); } -static inline void rcu_try_lock_acquire(struct lockdep_map *map) +static inline void notrace rcu_try_lock_acquire(struct lockdep_map *map) { lock_acquire(map, 0, 1, 2, 0, NULL, _THIS_IP_); } -static inline void rcu_lock_release(struct lockdep_map *map) +static inline void notrace rcu_lock_release(struct lockdep_map *map) { lock_release(map, _THIS_IP_); } @@ -872,7 +872,7 @@ static __always_inline void rcu_read_lock(void) * * See rcu_read_lock() for more information. */ -static inline void rcu_read_unlock(void) +static inline void notrace rcu_read_unlock(void) __releases_shared(RCU) { RCU_LOCKDEP_WARN(!rcu_is_watching(), @@ -991,7 +991,7 @@ static __always_inline void rcu_read_lock_dont_migrate(void) rcu_read_lock(); } -static inline void rcu_read_unlock_migrate(void) +static inline void notrace rcu_read_unlock_migrate(void) __releases_shared(RCU) { rcu_read_unlock(); diff --git a/include/linux/rcupdate_trace.h b/include/linux/rcupdate_trace.h index 273c59a03251..aa1ad9433d36 100644 --- a/include/linux/rcupdate_trace.h +++ b/include/linux/rcupdate_trace.h @@ -93,7 +93,7 @@ static inline void rcu_read_unlock_tasks_trace(struct srcu_ctr __percpu *scp) * * For more details, please see the documentation for rcu_read_lock(). */ -static inline void rcu_read_lock_trace(void) +static inline void notrace rcu_read_lock_trace(void) { int n; struct task_struct *t = current; @@ -120,7 +120,7 @@ static inline void rcu_read_lock_trace(void) * * For more details, please see the documentation for rcu_read_unlock(). */ -static inline void rcu_read_unlock_trace(void) +static inline void notrace rcu_read_unlock_trace(void) { int n; struct srcu_ctr __percpu *scp; diff --git a/include/linux/sched.h b/include/linux/sched.h index e4f6323d7855..f3f0def6da0d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2441,7 +2441,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); #endif #define this_rq_pinned() (*(unsigned int *)((void *)this_rq_raw() + RQ_nr_pinned)) -static inline void __migrate_enable(void) +static inline void notrace __migrate_enable(void) { struct task_struct *p = current; @@ -2476,7 +2476,7 @@ static inline void __migrate_enable(void) this_rq_pinned()--; } -static inline void __migrate_disable(void) +static inline void notrace __migrate_disable(void) { struct task_struct *p = current; @@ -2496,8 +2496,8 @@ static inline void __migrate_disable(void) p->migration_disabled = 1; } #else /* !COMPILE_OFFSETS */ -static inline void __migrate_disable(void) { } -static inline void __migrate_enable(void) { } +static inline void notrace __migrate_disable(void) { } +static inline void notrace __migrate_enable(void) { } #endif /* !COMPILE_OFFSETS */ /* diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 380b5964fcb4..36f4c6445642 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -250,7 +250,7 @@ static inline void srcu_lock_acquire(struct lockdep_map *map) } /* Annotates a srcu_read_lock() */ -static inline void srcu_lock_release(struct lockdep_map *map) +static inline void notrace srcu_lock_release(struct lockdep_map *map) { lock_map_release(map); } -- 2.53.1-Meta