From: Simon Horman <horms@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH net v3] netpoll: Fix deadlock in memory allocation under spinlock
Date: Thu, 16 Oct 2025 13:40:56 +0100 [thread overview]
Message-ID: <aPDn2OIpD31U-TEU@horms.kernel.org> (raw)
In-Reply-To: <20251014-fix_netpoll_aa-v3-1-bff72762294e@debian.org>
On Tue, Oct 14, 2025 at 09:37:50AM -0700, Breno Leitao wrote:
> Fix a AA deadlock in refill_skbs() where memory allocation while holding
> skb_pool->lock can trigger a recursive lock acquisition attempt.
>
> The deadlock scenario occurs when the system is under severe memory
> pressure:
>
> 1. refill_skbs() acquires skb_pool->lock (spinlock)
> 2. alloc_skb() is called while holding the lock
> 3. Memory allocator fails and calls slab_out_of_memory()
> 4. This triggers printk() for the OOM warning
> 5. The console output path calls netpoll_send_udp()
> 6. netpoll_send_udp() attempts to acquire the same skb_pool->lock
> 7. Deadlock: the lock is already held by the same CPU
>
> Call stack:
> refill_skbs()
> spin_lock_irqsave(&skb_pool->lock) <- lock acquired
> __alloc_skb()
> kmem_cache_alloc_node_noprof()
> slab_out_of_memory()
> printk()
> console_flush_all()
> netpoll_send_udp()
> skb_dequeue()
> spin_lock_irqsave(&skb_pool->lock) <- deadlock attempt
>
> This bug was exposed by commit 248f6571fd4c51 ("netpoll: Optimize skb
> refilling on critical path") which removed refill_skbs() from the
> critical path (where nested printk was being deferred), letting nested
> printk being calld form inside refill_skbs()
>
> Refactor refill_skbs() to never allocate memory while holding
> the spinlock.
>
> Another possible solution to fix this problem is protecting the
> refill_skbs() from nested printks, basically calling
> printk_deferred_{enter,exit}() in refill_skbs(), then, any nested
> pr_warn() would be deferred.
>
> I prefer tthis approach, given I _think_ it might be a good idea to move
> the alloc_skb() from GFP_ATOMIC to GFP_KERNEL in the future, so, having
> the alloc_skb() outside of the lock will be necessary step.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> Fixes: 248f6571fd4c51 ("netpoll: Optimize skb refilling on critical path")
> ---
> Changes in v3:
> - Removed the "return" before the exit labels. (Simon)
> - Link to v2: https://lore.kernel.org/r/20251014-fix_netpoll_aa-v2-1-dafa6a378649@debian.org
>
> Changes in v2:
> - Added a return after the successful path (Rik van Riel)
> - Changed the Fixes tag to point to the commit that exposed the problem.
> - Link to v1: https://lore.kernel.org/r/20251013-fix_netpoll_aa-v1-1-94a1091f92f0@debian.org
Thanks for the updates.
Reviewed-by: Simon Horman <horms@kernel.org>
next prev parent reply other threads:[~2025-10-16 12:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 16:37 [PATCH net v3] netpoll: Fix deadlock in memory allocation under spinlock Breno Leitao
2025-10-16 12:40 ` Simon Horman [this message]
2025-10-16 23:23 ` Jakub Kicinski
2025-11-03 14:12 ` Breno Leitao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aPDn2OIpD31U-TEU@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).