Re: [PATCH net v3] netpoll: Fix deadlock in memory allocation under spinlock

From: Breno Leitao

Date: Mon Nov 03 2025 - 09:21:59 EST


On Thu, Oct 16, 2025 at 04:23:23PM -0700, Jakub Kicinski wrote:
> On Tue, 14 Oct 2025 09:37:50 -0700 Breno Leitao wrote:
> > + while (1) {
> > + spin_lock_irqsave(&skb_pool->lock, flags);
> > + if (skb_pool->qlen >= MAX_SKBS)
> > + goto unlock;
> > + spin_unlock_irqrestore(&skb_pool->lock, flags);
>
> No need for the lock here:
>
> if (READ_ONCE(..) >= MAX_SKBS)
>
> > skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC);
> > if (!skb)
> > - break;
> > + return;
> >
> > + spin_lock_irqsave(&skb_pool->lock, flags);
> > + if (skb_pool->qlen >= MAX_SKBS)
> > + /* Discard if len got increased (TOCTOU) */
> > + goto discard;
>
> Not sure this is strictly needed, the number 32 (MAX_SKBS) was not
> chosen super scientifically anyway, doesn't matter if we go over a
> little.

Agree. I will take this approach them, since it is not going to hurt at
all.

Thanks for the review,
--breno