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=1796101710; b=eg3Vh1MEjpkWttBKIdmgklmY3ME+9S4ngg13p6FNvAHQmEuubbODfX1jwcRpboURNZbD +O0RtFbcbboztUMXUeobMIGPbJxs7a5sqVRCMn4ipG47QRR5JOQScEPeZJAjcj4ZvGDuP 8y1Nh+4RgJD5H1xdemRSfBT9epS1wCb0lMWLCSaD4vXOiYzoluV1OEJ5Dhjp4igdxetYP 5VfAt2ls6q6yKj8HaRDxr+Qp6UYa61co0Agq3EcrRnN+FRu8TQV9DhPlAoPXFfy1+zTS2 1AwZE0KU3g9+N+7CVhvKSqhTuThsem02Pmsy2YqL4gnuksclMfU/PjQgA5krjfvAKsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796101710; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=JtSUcPdJ89aL8ygW/bTFcT/AYyFlq2sRTki1IRyFkv8=; b=o0jau7EHkCb0OpuB0Rf+tQjLstCXhsRJfV7fqUIu6muM58E/6KexacFQF4no50Tpwhst fYEBISfToA6Gsf28+2Qe1kt7wzwyE+MENqwBXunltSSL9wRAjcDQef7bsbgLxC1vGdbLW 3UMynOdwNNNDM5GcjaJ2qlHpT+e0TSO30NJzsu7ewfkMbM8Zr4fwmu0wRVvadgtSqHga0 m20aTyL5DKtNfLcy0UqRkti6c7kjChF0hpwMOcOMLx7YYseQqov5ebqn7z6AFhPmX/doA YwSY6ZOcCthULp3H0PuOchrNPNjGW1/dtktalWb8zffSiqcon8gyXSw505TE9vCZ7GA== 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=PJkNmeIh; 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 C89A6606A325; Tue, 1 Dec 2026 05:08:30 +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=PJkNmeIh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A3E31F00893; Tue, 1 Dec 2026 05:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796101710; bh=JtSUcPdJ89aL8ygW/bTFcT/AYyFlq2sRTki1IRyFkv8=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=PJkNmeIhvAjG7XscqQ0fRHnWpzb7knDIgWXCEbomhTXWlJq8GgN1F3uWgGjOe7S4S b1R3nl/HUF+h3bcCRYftGGOogb3Tg7qvGUU6TV54jTbQ4UvDbVeyGbg4fJVu67ocKO VjNGN3LBglxipdWfEcT4Gks7i/rEnKKU0Owh/coxv4mTDOv6TbFaHL5dkxOe2rkUly KOMmRI5GqnSMJSW4BKYEd2b1QhPk2FsRWnfaPy8VBK5F0MS/propSiXsQBP72Ly+W5 T/pRXA0XpNAueY1wGTVAhAuswWv/uhZ6IL2XUnqPFHp9NiNPQBHFvRy5B1HRLnRveo F9ZW7qsZr0Uvg== Content-Type: multipart/mixed; boundary="===============1979937825657277329==" 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 Message-Id: In-Reply-To: <20261201042201.3199928-5-song@kernel.org> References: <20261201042201.3199928-5-song@kernel.org> Subject: Re: [PATCH v3 04/22] bpf: Mark the BPF trampoline helpers notrace From: bot+bpf-ci@kernel.org To: song@kernel.org,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@kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev Date: Tue, 1 Dec 2026 05:08:27 +0000 (UTC) --===============1979937825657277329== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit > bpf: Mark the BPF trampoline helpers notrace TL;DR: - Possible unbounded BPF trampoline recursion if powerpc local_add helpers stay unmarked notrace - Same possible recursion on arm64 via unmarked __percpu_add_case_64() used by percpu_ref helpers > diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h > --- 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) The commit message says local_inc() and local_add() are marked "on x86", because u64_stats_inc() and u64_stats_add() reach them from bpf_prog_inc_misses_counter() and __update_prog_stats(). Should the powerpc equivalents be covered as well? powerpc64 also supports BPF trampolines and has its own plain __inline__ helpers in arch/powerpc/include/asm/local.h: #define LOCAL_OP_RETURN(op, c_op) \ static __inline__ long local_##op##_return(long a, local_t *l) \ ... #define local_inc_return(l) local_add_return(1LL, l) #define local_inc(l) local_inc_return(l) On 64-bit, local64_inc() and local64_add() map to local_inc() and local_add() (include/asm-generic/local64.h), so: __bpf_prog_enter_recur() bpf_prog_inc_misses_counter() u64_stats_inc() local64_inc() local_add_return() __bpf_prog_exit*() __update_prog_stats() u64_stats_inc()/u64_stats_add() local_add_return()/local_add() Nothing in this series touches arch/powerpc/include/asm/local.h, and a later commit in the series (compiler_types: Move notrace from inline to __always_inline) removes the implied notrace from plain inline. If an out-of-line local_add_return() gets a patchable entry, attaching to it would make __bpf_prog_enter_recur() reject the program and call bpf_prog_inc_misses_counter(), which re-enters the trampoline, without bound. loongarch looks similar one level down: local_inc()/local_add() are macros for atomic_long_inc()/atomic_long_add(), ending in arch_atomic64_add(), a plain static inline in arch/loongarch/include/asm/atomic-amo.h. Should the powerpc local_add()/local_add_return() helpers be marked notrace together with the x86 ones? [ ... ] > diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h > --- a/include/linux/percpu-refcount.h > +++ b/include/linux/percpu-refcount.h [ ... ] > @@ -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; > This marks percpu_ref_get_many() and percpu_ref_put_many() notrace because __bpf_tramp_enter() and __bpf_tramp_exit() call them. On arm64, though, the per-CPU op they use is still a plain inline helper that nothing in the series marks: this_cpu_add() this_cpu_add_8() __percpu_add_case_64() and this_cpu_sub() is this_cpu_add() with a negated value. In arch/arm64/include/asm/percpu.h the helper is generated as: #define __PERCPU_OP_CASE(w, sfx, name, sz, op_llsc, op_lse) \ static inline void \ __percpu_##name##_case_##sz(void __percpu *pcp, unsigned long val) \ The arm64 trampoline calls __bpf_tramp_enter() before the fentry programs when BPF_TRAMP_F_CALL_ORIG is set, so: arm64 trampoline __bpf_tramp_enter() percpu_ref_get() percpu_ref_get_many() this_cpu_add() __percpu_add_case_64() and likewise __bpf_tramp_exit() -> percpu_ref_put_many() -> this_cpu_sub(). The only later commit in the series touching arch/arm64/include/asm/percpu.h is "arm64: Mark helpers called from noinstr code notrace", which marks only __kern_my_cpu_offset(). Its changelog says clang emits an out-of-line copy of that helper in an arm64 defconfig build, and __percpu_add_case_64() has a longer ALTERNATIVE asm body, so an out-of-line copy seems at least as plausible. Once "compiler_types: Move notrace from inline to __always_inline" lands, such a copy gets a patchable entry. An fexit or fmod_ret program attached to it would recurse: trampoline -> __bpf_tramp_enter() -> __percpu_add_case_64() -> trampoline -> __bpf_tramp_enter() -> ... This happens before any __bpf_prog_enter*() recursion check runs. On x86 this_cpu_add() is an asm macro, so this is specific to arm64. Should the arm64 __percpu_*_case_*() helpers, or at least the add case used here, be marked notrace as part of this commit? --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46577721107 --===============1979937825657277329==--