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=1796415532; b=UTnTIsDq+t+lBr5I87E/4K2CJFy9dLwwF4nHkYscGQcraFvSOb5j25uD3f8wNHZ8lCzI YUpy/9Ud5QwObDKE+05a4gTceIcUqN0SPbpK8yOj4drY7rmLwxTP//lWfmCOEGQMXZ95h s42gPyeECrWZbmobh+6pjtP7jhaqlU+SAcb1ZGikBoXt/Schl7i0AuQnvmQZMefdSLE/6 R/EkFNNwhmvOjue4NcE3BvOCw2vcT0kRlMEw/Z3+Knb4Fcl/pIFOgq2fbwraT79U4L3xB uii5upTfbDandbfZyPAabp6TWyFKbCv3q9IVGRXvfbwORRZNmjCqK1d0wCtEI23hbAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796415532; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=q6oeAvcEqk4XdlDa2dWLfGjRfY4RhJg8Rp5QS+5/TyI=; b=BaXXxktXqE3Wn1AhV3EsJEx9jlPjMNtO0KwZF9hNU6bbPjjI1IXuD7MG36qTcwovXjoU oT6KoYhDWZjRVauOipKgqHb+yWoRCpQm2pIviDh7F7VnxWnOw3Q7wnZcur+ocUuwCec9K JiNwA+oFJy7/yMCa6s6a19lKRcwqtFbfWsCjRsOwywC/cRSYxxuEAbG8peVjoyGLJdTpa tK5wwmndOfojYTjIhr9IvHadrVNj7xopDD1ua2yg3lWB8/rmynhZeiIHExEry8DkTYW56 soyrUkC+RKWZDjrrc317/qA+cpmKlUlbilvcEv84edX1cyH5YhnstJJrQlnFq/F8psA== 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=FgdN8YMq; 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 05062606A322 for ; Fri, 4 Dec 2026 20:18:52 +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=FgdN8YMq Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1BCB1F0093B; Fri, 4 Dec 2026 20:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796415531; bh=q6oeAvcEqk4XdlDa2dWLfGjRfY4RhJg8Rp5QS+5/TyI=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=FgdN8YMqRiQ3vLtfSgm6ncwX7my8AOBApl36GrjMAS9eyty1YBY4HwoO0ziE/LlZG 2/yEUwMpPxpm/I/7GCjiy9H8CraLp2hOzFXMjUYUF2PB/a5cc0UHXgoy+f+T1aLaeY E9V/8zUB7JZDZA4+pS7QX9uz0v8vDRm2jbKlI7wjYbj0N/YV9td63ZLrLqU1haEO/l JnB67DvLcIb/IOrxH8+3ms6C3ArBGFhpLARMCtOr6y6wQptRt9rKa8wpzSBMdX+eVm yP+k7mjnUT9VwOfgongUBn5/hwb9PuwxafrVVKHc6l+kjyGqQn85e4zDh+lIhWxiT0 +ulQQEk/Xd8HA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next 4/5] bpf: tcp: Prefetch values of hot sk storage maps before transmit Reply-To: sashiko-reviews@lists.linux.dev To: "Mykyta Yatsenko" , bpf@vger.kernel.org In-Reply-To: <20261204-sk_storage_prefetch-v1-4-ea52fb48b52b@meta.com> References: <20261204-sk_storage_prefetch-v1-0-ea52fb48b52b@meta.com> <20261204-sk_storage_prefetch-v1-4-ea52fb48b52b@meta.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:18:51 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] bpf: unconditional per-CPU RMW in bpf_sk_storage_prefetch_values() - [Medium] bpf: unconditional this_cpu_or() in bpf_sk_storage_xmit_mark() - [Medium] bpf: RFO prefetchw() in bpf_sk_storage_prefetch_hot() bounces shared lines -- commit f0130b9d642d8428468cd298e6da4b722527388b Author: Mykyta Yatsenko bpf: tcp: Prefetch values of hot sk storage maps before transmit This commit records which bpf_local_storage cache[] slots are looked up per CPU in bpf_sk_storage_get() and prefetches the elements in those slots from __tcp_transmit_skb() before calling ->queue_xmit(), clearing the per-CPU mask every 256 transmits. Link: https://lore.kernel.org/bpf/DN8A36W906WG.1BTUYRC2FIIR@gmail.com/ > diff --git a/include/net/bpf_sk_storage.h b/include/net/bpf_sk_storage.h > index c97cbc299bbb2..ec12c3aaa9775 100644 > --- a/include/net/bpf_sk_storage.h > +++ b/include/net/bpf_sk_storage.h [ ... ] > @@ -54,6 +66,20 @@ static inline void bpf_sk_storage_prefetch_cache(const= struct sock *sk) > prefetchw(storage + SMP_CACHE_BYTES); > } > =20 > +/* Prefetch the values of sk in the slots seen in this round of 256 tran= smits */ > +static inline void bpf_sk_storage_prefetch_values(const struct sock *sk) > +{ > + u16 seen; > + > + if (!static_branch_unlikely(&bpf_sk_storage_xmit_key)) > + return; > + if (unlikely(!this_cpu_inc_return(bpf_sk_storage_xmit.round))) > + this_cpu_write(bpf_sk_storage_xmit.seen, 0); > + seen =3D this_cpu_read(bpf_sk_storage_xmit.seen); > + if (seen && rcu_access_pointer(sk->sk_bpf_storage)) > + bpf_sk_storage_prefetch_hot(sk, seen); > +} [Severity: Medium] Should bpf_sk_storage_prefetch_values() check bpf_sk_storage_xmit.seen before incrementing bpf_sk_storage_xmit.round? Whenever any BPF_MAP_TYPE_SK_STORAGE map exists, __tcp_transmit_skb() runs this_cpu_inc_return(bpf_sk_storage_xmit.round) on every TCP segment, even on CPUs where seen is zero. Outside x86, arm64, and s390, this_cpu_add_return_1 falls back to raw_local_irq_save()/raw_local_irq_restore() per packet. On arm64 and x86-64 it still executes an atomic RMW (ldaddb or xaddb) with a memory clobber, dirtying the per-CPU cacheline on every transmit. Reading seen first and returning when it is zero would skip the RMW when no slots are marked, matching bpf_sk_storage_prefetch_cache(). [ ... ] > diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c > index 875fff681869e..5feea65d25ea3 100644 > --- a/net/core/bpf_sk_storage.c > +++ b/net/core/bpf_sk_storage.c > @@ -39,6 +39,43 @@ static void bpf_sk_storage_key_fn(struct work_struct *= work) [ ... ] > +/* As in a lookup, the RCU read lock keeps the storage and the elements = */ > +void bpf_sk_storage_prefetch_hot(const struct sock *sk, unsigned long ho= t) > +{ > + struct bpf_local_storage_data *sdata; > + struct bpf_local_storage *storage; > + int i; > + > + guard(rcu)(); > + storage =3D rcu_dereference(sk->sk_bpf_storage); > + if (!storage) > + return; > + for_each_set_bit(i, &hot, BPF_LOCAL_STORAGE_CACHE_SIZE) { > + sdata =3D rcu_dereference(storage->cache[i]); > + if (sdata) > + prefetchw(sdata); > + } > +} [Severity: Medium] Can prefetchw(sdata) here cause cross-CPU cacheline bouncing in full-duplex TCP workloads? On x86-64 (with X86_FEATURE_3DNOWPREFETCH) and arm64 (prfm pstl1keep), prefetchw() issues a store-intent read-for-ownership prefetch that invalidates shared copies on other CPUs. The same applies to the prefetchw() calls on storage->cache[] in bpf_sk_storage_prefetch_cache(). Because bpf_sk_storage_xmit_mark() runs for all bpf_sk_storage_get() callers, a map read only on the RX CPU is still pulled into exclusive state by the TX CPU on every transmit. On arm64, prefetch() already emits prfm pldl1keep and does not need the x86-64 clang workaround. > + > +static void bpf_sk_storage_xmit_mark(struct bpf_map *map) > +{ > + u16 idx =3D ((struct bpf_local_storage_map *)map)->cache_idx; > + > + this_cpu_or(bpf_sk_storage_xmit.seen, BIT(idx)); > +} [Severity: Medium] Can bpf_sk_storage_xmit_mark() skip this_cpu_or() when BIT(idx) is already set in bpf_sk_storage_xmit.seen? Because seen is only cleared every 256 TCP transmits (and never on CPUs not transmitting TCP), BIT(idx) is already set on almost every bpf_sk_storage_get() and bpf_sk_storage_get_tracing() lookup. Outside x86, arm64, and s390, this_cpu_or_2 falls back to this_cpu_generic_to_op(), adding raw_local_irq_save() and raw_local_irq_restore() to every lookup; on arm64 it executes an LSE ldseth (or LL/SC loop) instead of a plain load. Guarding the update with an unlikely check on this_cpu_read(bpf_sk_storage_xmit.seen) & BIT(idx) avoids the atomic RMW and IRQ disable on the steady-state lookup path. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-sk_storage= _prefetch-v1-0-ea52fb48b52b@meta.com?part=3D4