From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796420160; b=DR7EhgqsEJ6Fixs7Ao2u1VFHiLBQPfwANVdE59TXbkOsmBJRIke+7V/mk3xqHQFxlFMq t90/PYgcnkpsF5d8tLCfqTOMBeE9ffMIrCTRL0m2tgFXX7pN37qgcLRsNvgQjV3UysKqU JYZmprjGuUPvluCPFBpszEAp3z/Z29/0PoOz0GQE3IT1MDp8TeKXKWCVSAwgsopGA+Qmv FTqZuStug+PK5dlQPkxNEqcplQqT3xjDz1vgIL/XwJ9F3wYXRmDweb+bnWG6ocivXplYn cEgkLiBWdPrCLZHTVCB8MJoLEAwgtWonT/i3Fp819NcB8cjp0238GlDWxxa8Pa+r/RQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796420160; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=B+zHSdlBqfeIOy0EcD3mnopZnc3BZknGdUFX4kjkTyg=; b=4LtaTX0bij3pML2hegAS+ALBXGjspxLsug+iBh4GHWcBMiyNNZnp2bohFIVPbQvTybai DHItjXwpiTooJ+Ffl7lWnTh41+emgOm2lL6yY+F+jzr+qC7khvbNxQukFUWuuqeLR8/7p ClNSEjTwT/CIWv5qkR3jhpqz8D96IQPa+H1OFmkGVqAzfGZvfRHC+5NTC+ov3EnnxBL/H zyv2qBvOY1mhG6tAml4UFeuIHkWOHbqETkAWZpi/JMoFiWMGg6g9LC90/l6IZOlggm50N 6Q2WpRLSErlYd9H0BuzG8RHHEdIJo8n+TeVexrroNQRsOL8d3ihiwznZmlK7GdLl5aQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BgL7OCTf; arc=none smtp.remote-ip=74.125.82.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AA89606A322 for ; Fri, 4 Dec 2026 21:36:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1AA89606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BgL7OCTf Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-386c71feeeaso1838879eec.0 for ; Fri, 04 Dec 2026 13:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796420159; x=1797024959; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=B+zHSdlBqfeIOy0EcD3mnopZnc3BZknGdUFX4kjkTyg=; b=BgL7OCTfnBPRcjDg1ZcweDuNEff29uPLnNdzCEO2umxl7cJ3YrKXNpb28R1tUfw7x+ 18bcal8ovMrZPuHlcUje2tgN60E7YTnOChj5JNDDFzydqISXMgrIkTSY41tPM4YPyLXF tlcZ4/uvdu9qfUCZcny9/eceQfSY/bIzvMjUYZ0u9LhuTgR9dHjK6f9rIXpX2qDFUPR2 CBPJqQPgQeG6cyveWLqAnkdXTqEVINvUTOj+395tWrcEqNMKlBRYPNTYuPZLxcllTSHQ Qp4PeM0QtEZypLiU36IbAocWbgp/d1vaOYiUAxrPKzwGQeqv6G/P0wCr0ug9YfnmBFZL lfdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796420159; x=1797024959; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=B+zHSdlBqfeIOy0EcD3mnopZnc3BZknGdUFX4kjkTyg=; b=veOvmT19pMOls+bQwMvjt7xiN5zg/JwQBU3HQ8udzivAKgWJ+u7ryh/ClSdq9vLbAQ xwau2BnvRVyof9kxqU/GEuj5NPOjeBsWj4+J7Ci89G1zoviHfC46RRz0WesOWWoalKdg m3m2Y7mCuamAqbzHNhvudQrJV43Q/cHLysSW/PJGWkxzYaiM5KR6rxLaHv+bB4dmWnvd vL0hQQRlA4S9UB2AyMN9wedLUKO+r2pHUt4tL1m0pyWAWABuO6Mw1eStRY75VOH4uYfQ PyWI1GiSjx2bPIXVWGiNiKyppFaxROM4A+uVX7WlIlT7k7JSIaRxqUPTtKR/ahhXLAPk eSEg== X-Forwarded-Encrypted: i=1; AL+hErGp9tZo6977LrBj8KvIFLih3KfitcSA3CmjqKjkOBFITqcgSBBsKvmG7skoHawK/P/6+jw=@vger.kernel.org X-Gm-Message-State: APuU4Z9UMd5YOM6tnYVJeCbxouJJBtOMVh3hzpF8RqvtBjNN06JbN7Ie zQALYD8qpUflKOQy9dmpWkBeIc0YgAJafYaQfbMXBXZdyk4T7GB8EPy5EB6rTN200uU= X-Gm-Gg: AZFdTZfwQ93AoO61pSkpBXSaqMrKGj47tcTYcNMHdmkx8A+aUKNHtPkFQVPYZAbiyFR x51oKqahHaQ1jW55zS2OkHlKSfs5QXshqw6lUvr/oHY0fEkqHqQkJ1mGI3M5tyJPXR01rydwti5 eZgsIk84OXkAthltABr1NxM/RmEwvYuZuphTwA25ceHaXCOuuBExFvzWEQsp3lRm08INJGy0mfK S7kOoZXDiJ9GzzlIUauIKFQcjw8p0ZSFgLR4bF7TrfKRXDJRXJrgfb5q+qnpl9ddF3edDn8HCvz bGWt9wwBgBtaji7X6eRW0HO+V2ziWsYtlZg3uzXQnYPChpAEdvd2tAQo9zCeOAOXrMi67TNM3b4 KV5T/BicKOaxdYt+UBfPOAZLFd7gA9c7GIKlEIJBDj5NJg9IeneofDmFxZV7pnzt/KGJrc+IIKw UZa3T5fI/BBUyrOzvXTlA52ITGTTGDoig+x9WUo+5QyA9HxWFmMaW/8BzbRkyXJRdURmp1c5txg hel/inY5o7oF6z10CpiCLQJuYgOwsi/B03rHvetksYmvo0/Oewa+KpfSSsvK9xxUeWn53c5Cpi2 QL6lRMAw9nmmO9ajEfIrFUUjhwT3vZQJv9B9fs5qhcMWDSPJA2EIK8OWPBiwqAyX X-Received: by 2002:a05:693c:60d4:b0:387:43db:4d9 with SMTP id 5a478bee46e88-38752174126mr3447490eec.16.1796420159166; Fri, 04 Dec 2026 13:35:59 -0800 (PST) Received: from ?IPV6:2a03:83e0:115c:1:15e7:543c:f32a:fb90? ([2620:10d:c090:500::6:cdc]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875224312fsm11042922eec.26.2026.12.04.13.35.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 13:35:58 -0800 (PST) Message-ID: <2f700c05-707f-4abc-9fc9-68c44a6ef013@gmail.com> Date: Fri, 4 Dec 2026 21:35:57 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next 4/5] bpf: tcp: Prefetch values of hot sk storage maps before transmit To: sashiko-reviews@lists.linux.dev, bpf@vger.kernel.org References: <20261204-sk_storage_prefetch-v1-0-ea52fb48b52b@meta.com> <20261204-sk_storage_prefetch-v1-4-ea52fb48b52b@meta.com> Content-Language: en-US From: Mykyta Yatsenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/4/26 8:18 PM, sashiko-bot@kernel.org wrote: > 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); >> } >> >> +/* Prefetch the values of sk in the slots seen in this round of 256 transmits */ >> +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 = 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(). Agree. > > [ ... ] > >> 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 hot) >> +{ >> + struct bpf_local_storage_data *sdata; >> + struct bpf_local_storage *storage; >> + int i; >> + >> + guard(rcu)(); >> + storage = rcu_dereference(sk->sk_bpf_storage); >> + if (!storage) >> + return; >> + for_each_set_bit(i, &hot, BPF_LOCAL_STORAGE_CACHE_SIZE) { >> + sdata = 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. > Same as previous patch. >> + >> +static void bpf_sk_storage_xmit_mark(struct bpf_map *map) >> +{ >> + u16 idx = ((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. >