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=1796415820; b=e80S98GD0xu6tGKPv0wGIFJ0T5rLf/SCL83kf/V6DveaBTK1KQyscyZ9XRXD/UlzP93X ao5W6T6V0AH322ZEc6KeZo4WpVw5lgcNXJoCnXSrX1Kk4wMggzPMADThaSVcw3Z70UAB1 /u8QnnShLa/4b6jt1qjYz6qZZPbiFt743EN44qus6geDqspjnKyQFhfQ5E7rjuzxHACGw e87FcS4CfvT+r6+S8r1FsplyXboinDVkVr5hl7Lm4tviU6EL5MZTl5kUt+Zkz0VgdGVfp wXdYtCdV4yFYfehFJyQ4d30r7X0AzC3L4YvVqaKBL3Wk7EipbswhzJRedguNkCOz6yA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796415820; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=t/2VbJTUXYeJD+qPLBpCITpMCrRiidzjDetx2DfKdPQ=; b=j1jmM28iCpQhliddfzJ2Rn66jde4BL/nI6WQS7hT7Jo4MVi8wRSABg/L4Y9bFwa6WFQa Mj0kX6eb7DW/1UlrfhOxwX+ivhU4SEzS5V8uwk7xuiLYbiJUwGLLgnAGmIcP9IgzheqMm 5SeSRgvZ530S2TocY7XOUQu8ACngoB2CG9oAIj/6bKjEaijVPvKz14sH9Cb7iPTF7AjPn j4H+0NGNzt+FBI1amm2YInRuaC6sk2cBBNsNzl6GN99qUo1kndUPwt/sA6hIIu8FnO+be nXKufpsGDk+04cHfe5RZ22E9pKxLp6HIFkbU1Yhjn9/YLMgVB1oyheRyVRb+NkthqXw== 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=gyJrJwRz; 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 89A8C606A322 for ; Fri, 4 Dec 2026 20:23:40 +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=gyJrJwRz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E4721F00936; Fri, 4 Dec 2026 20:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796415820; bh=t/2VbJTUXYeJD+qPLBpCITpMCrRiidzjDetx2DfKdPQ=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=gyJrJwRzBRZ0+HDcF+A4Qy5DGRvL21+duwvOs207KA0CwasGZgmY6rWPayeHD90JN 5zfZ5lqat9qjnNgeeDk3xJbnfxjDmJuRUDVpF3APWZC7B96zxUJycl4YPSyvNKM2e8 1QoAs7u9vU0qnG9HzhWXRFfBzEX2FjNuTZQBb24CdZLIM+c4mFfPupLuEkX4lWcB14 BpkL+Og/Pa3kdQiC96Nh2HPI6QSiPXiQ03qoocpJJA3/kKEsGoFLUDjO4Al3CGBXGU 3bdpBaZsvXz3NsNJXCSfdAUV31M194mfuNkIVJGUwj4ZKhP3QdMrWA2s4UnJNkxoIp ZW7HxyAEmNyAA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next 3/5] bpf: tcp: Prefetch sk storage cache[] before TCP transmit Reply-To: sashiko-reviews@lists.linux.dev To: "Mykyta Yatsenko" , bpf@vger.kernel.org In-Reply-To: <20261204-sk_storage_prefetch-v1-3-ea52fb48b52b@meta.com> References: <20261204-sk_storage_prefetch-v1-0-ea52fb48b52b@meta.com> <20261204-sk_storage_prefetch-v1-3-ea52fb48b52b@meta.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:23:39 +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 2 potential issues to consider: - [Medium] bpf: prefetchw() on read-only cache[] in bpf_sk_storage_prefetch_cache() - [Medium] bpf: tcp: bpf_sk_storage_prefetch_cache() loads cold sk_bpf_storage on TX -- commit 2c340de4783284547e3b378ba37fabbc3b62bef3 Author: Mykyta Yatsenko bpf: tcp: Prefetch sk storage cache[] before TCP transmit This commit adds a static-key-gated helper to prefetch a socket's BPF local storage cache[] array at the start of tcp_sendmsg_locked() and __tcp_transmit_skb(), enabled via a delayed work item whenever any BPF_MAP_TYPE_SK_STORAGE map exists. Link: https://lore.kernel.org/bpf/DN8A36W906WG.1BTUYRC2FIIR@gmail.com/ Link: https://github.com/llvm/llvm-project/pull/248194 > diff --git a/include/net/bpf_sk_storage.h b/include/net/bpf_sk_storage.h > index 2926f1f00d656..c97cbc299bbb2 100644 > --- a/include/net/bpf_sk_storage.h > +++ b/include/net/bpf_sk_storage.h [ ... ] > @@ -29,6 +31,29 @@ struct sk_buff; > struct nlattr; > =20 > #ifdef CONFIG_BPF_SYSCALL > +DECLARE_STATIC_KEY_FALSE(bpf_sk_storage_xmit_key); > + > +/* > + * Prefetch cache[] of the storage of sk before a TCP transmit, so that = an > + * egress program does not wait for it. There is no RCU read lock: the s= torage > + * can be freed at any time, so only prefetch it and never load from it. > + * On x86-64, clang emits no instruction for prefetch(), so use prefetch= w(). > + */ > +static inline void bpf_sk_storage_prefetch_cache(const struct sock *sk) > +{ > + const void *storage; > + > + if (!static_branch_unlikely(&bpf_sk_storage_xmit_key)) > + return; > + storage =3D rcu_access_pointer(sk->sk_bpf_storage); > + if (!storage) > + return; [Severity: Medium] Does synchronously loading sk->sk_bpf_storage on every TCP transmit add a cold cache miss for sockets that do not use egress sk_storage? sk_bpf_storage sits in the cold tail cache line of struct sock alongside sk_destruct, sk_reuseport_cb, and sk_rcu, outside sock_read_tx, so TCP TX otherwise never touches it. Because bpf_sk_storage_xmit_key is enabled whenever any sk_storage map exists, workloads using sk_storage only outside egress (such as ingress filters or tracing) take an extra cache miss in tcp_sendmsg_locked() and __tcp_transmit_skb(), even when sk_bpf_storage is NULL. Moving sk_bpf_storage into sock_read_tx or gating the prefetch on egress BPF programs would avoid this TX cache footprint regression. > + /* cache[] is at the start of the storage: one or two cache lines */ > + prefetchw(storage); > + if (sizeof_field(struct bpf_local_storage, cache) > SMP_CACHE_BYTES) > + prefetchw(storage + SMP_CACHE_BYTES); [Severity: Medium] Can prefetchw() on read-only storage->cache[] cause cross-CPU cache-line bouncing on full-duplex TCP connections? bpf_local_storage_lookup() only reads local_storage->cache[] on the fast path. On x86-64 with X86_FEATURE_3DNOWPREFETCH, prefetchw() issues RFO and invalidates shared copies on other CPUs, causing MESI ping-pong when TX and RX (tcp_v4_rcv() -> tcp_filter()) run on different CPUs. Non-x86 architectures such as arm64 already emit inline assembly read prefetches for prefetch() (prfm pldl1keep), so using prefetchw() forces unnecessary store-intent prefetches (prfm pstl1keep) there as well. In addition, bpf_local_storage_cache_idx_get() assigns slots starting from index 0, so with 8 or fewer sk_storage maps cache[8..15] is never used and unconditionally prefetching storage + SMP_CACHE_BYTES doubles the unnecessary RFO and L1 traffic. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-sk_storage= _prefetch-v1-0-ea52fb48b52b@meta.com?part=3D3