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=1796385277; b=laj6BtRr7Ie+tZv19n1ilIezMqis1dZBZTqZ3ZRTgdCSG+EmmVqlavsRJgu5oc7iBNyI BimffpkvgrDTth9BKrO3/+ashqx4BGtTvUwBw/+VKtm0tPnlY8+c95a6w+wRjUFRiOS6a emg3IMQNu73jhCieXQTvNYxSpg4ib9t93OB6wB/HoHAP3/VsejtsD3nLhPRUx9YhAXufW hVx+2kLKvCgP7cgODEZN9GdG+YIPMhpDnLHg1tgL+kEDoWDQONjcdLQvh8DNwLoErcQN+ vfvEeGjID0QTMZifpGI6F2QeAqHUSA9sAQ4fo37nE+kyDJtarGFbl3EDZW4uHFWsvfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385277; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=nvxWEYPgo1pZ3qhhzxTOrISOWTDamUtyFgIQ/pmRtIY=; b=eF/jwJ5UrU/jHWRe4qPa5YMTMrl6kpSdyfBP3+AQZ+F05Lz9ygKS9nuC36DLlgKsOe6G ucItJ8rfQ5zAB6IT/UIEVwQRgGjTF4vQN+zAbvQVn8MfYdoJPUa9W7iBZY2J9oPIU7KA+ proJoGKc/n6fD5erRBYmT5Cfxeg8yQQgltx1znlHtrWnfxwQVw9FBzXHZ4dDTXLYpZyCC LfuYRZ9LCyv0Xje3v86xN8FMnbZTPdZyu5nN9OBBZFXUYNn3iwvzon+6s6BaykmM3p67k HlM+OHj9EOpSA5N5VIP3nWdEojLBYWGwLiT7Ki2bl6Av90GE14n4CTHmTOd4aPyo3iA== 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="fx3VvDc/"; 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 3FC49606A322; Fri, 4 Dec 2026 11:54:37 +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=fx3VvDc/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8F5D1F000C2; Fri, 4 Dec 2026 11:54:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385277; bh=nvxWEYPgo1pZ3qhhzxTOrISOWTDamUtyFgIQ/pmRtIY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fx3VvDc/8zeDqVepmWs0WsPUx/J5Qnmqxz2+Wb4h8klHLnGFpSZ0v++G7N5EzCNoB dL1bpBN23QhDUtmsdUqkB9hRKU1Ku1OAWeeJXC8AhASSkRTl9RRxxLq0dU2pck70my 0zOaiK7MXWEAHeVooMCFl11zmo4M7SomWfsZizwPAyGyCp/Mq1XhJyAF8/yeodRNp7 N3LCmSs3IEDXXHyzVYMBJXwBoQlJ4DiFOd7oZhaOOw4EsPAlpEaGEYZCBC8EiCTWgZ JiLBpvkSQs5AHJO7P7yMfZVOf8k2Y7fEQAPNWWvfRiNPC/m7bq93lUXL8UP6UxdwvN +jFs5sbWNffYA== Subject: Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock From: netdev-bot+sashiko@kernel.org To: herbert@gondor.apana.org.au Cc: urezki@gmail.com, netdev@vger.kernel.org, willemdebruijn.kernel@gmail.com, torvalds@linux-foundation.org, liam@infradead.org, dave@stgolabs.net, mhocko@suse.com, bhe@redhat.com, glider@google.com, ryabinin.a.a@gmail.com, elver@google.com, mhocko@kernel.org, linux-crypto@vger.kernel.org, akpm@linux-foundation.org, tgraf@suug.ch, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, ljs@kernel.org, mason@kernel.org, aliceryhl@google.com, andrewjballance@gmail.com, stable@vger.kernel.org, david@kernel.org, jordan@jrife.io, martin.lau@kernel.org, kuba@kernel.org Date: Fri, 04 Dec 2026 11:54:35 +0000 Message-ID: <179638527524.3146.15958336218339553970@kernel.org> In-Reply-To: References: X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] Incomplete fix: the TCP BPF iterator keeps the same kvmalloc(GFP_NOWAIT)-under-BH-spinlock deadlock that this patch… -- bpf: udp: Do not call kvmalloc while holding BH spin lock With this patch, bpf_iter_udp_realloc_batch() uses kmalloc instead of kvmalloc when it is called with GFP_NOWAIT. That call happens while the UDP bucket lock is held with BH disabled. The vmalloc fallback in kvmalloc takes plain spinlocks, so it can deadlock against softirq users of the same bucket lock. > diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c > index d784faf939c3b..613ea92e95b18 100644 > --- a/net/ipv4/udp.c > +++ b/net/ipv4/udp.c > @@ -3886,8 +3886,12 @@ static int bpf_iter_udp_realloc_batch(struct bpf_udp_iter_state *iter, > { > union bpf_udp_iter_batch_item *new_batch; > > - new_batch = kvmalloc_objs(*new_batch, new_batch_sz, > - flags | __GFP_NOWARN); > + if (flags != GFP_NOWAIT) > + new_batch = kvmalloc_objs(*new_batch, new_batch_sz, > + flags | __GFP_NOWARN); > + else > + new_batch = kmalloc_objs(*new_batch, new_batch_sz, > + flags | __GFP_NOWARN); [Severity: High] Does the TCP BPF iterator need the same change? The TCP twin of this helper in net/ipv4/tcp_ipv4.c still calls kvmalloc unconditionally: net/ipv4/tcp_ipv4.c:bpf_iter_tcp_realloc_batch() { ... new_batch = kvmalloc_objs(*new_batch, new_batch_sz, flags | __GFP_NOWARN); ... } bpf_iter_tcp_batch() calls it with GFP_NOWAIT while it still holds the bucket lock: net/ipv4/tcp_ipv4.c:bpf_iter_tcp_batch() { ... /* Batch size was still too small. Hold onto the lock while we try * again with a larger batch to make sure the current bucket's size * does not change in the meantime. */ err = bpf_iter_tcp_realloc_batch(iter, expected, GFP_NOWAIT); ... } For established and request sockets, that lock is the ehash bucket lock. It is taken with BH disabled, as bpf_iter_tcp_unlock_bucket() shows: spin_unlock_bh(inet_ehash_lockp(hinfo, st->bucket)); The softirq path takes the same ehash lock with a plain spin_lock(). One example is inet_ehash_insert(), which runs from tcp_v4_syn_recv_sock() and from request socket hashing. Suppose the batch is larger than PAGE_SIZE (more than 512 items) and the GFP_NOWAIT kmalloc fails. Then __kvmalloc_node_noprof() falls back to __vmalloc_node_range_noprof() with the same flags. vmalloc takes plain spinlocks such as free_vmap_area_lock without disabling BH. Could this deadlock the same way as the UDP case described in the commit message? CPU0 bpf_iter_tcp_batch() spin_lock_bh(ehash bucket lock) bpf_iter_tcp_realloc_batch(iter, expected, GFP_NOWAIT) kvmalloc -> __vmalloc_node_range_noprof() spin_lock(&free_vmap_area_lock) <- spins CPU1 holds free_vmap_area_lock with BH enabled tcp_v4_syn_recv_sock() inet_ehash_insert() spin_lock(same ehash bucket lock) <- spins As far as I can tell, TCP is the only other caller under net/ that passes GFP_NOWAIT to a realloc_batch helper. The Fixes tag points at c6307674ed82, which made both iterators reach this path. Would it make sense to fix bpf_iter_tcp_realloc_batch() in the same patch? If not, could the commit message mention TCP, so that backports don't treat the regression as fully closed? > if (!new_batch) > return -ENOMEM; [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/aw6KwbtmeFFSf_MS%40gondor.apana.org.au