Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: Anandu.Padinhare@electrifex.com
Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
	ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org,
	john.fastabend@gmail.com, sdf@fomichev.me,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org,
	rmk+kernel@armlinux.org.uk, cfsworks@gmail.com, nb@tipi-net.de,
	david.wu@rock-chips.com, stable@vger.kernel.org
Subject: Re: [PATCH net v2] net: stmmac: retry a failed RX refill from a timer
Date: Sun, 29 Nov 2026 06:34:35 +0000	[thread overview]
Message-ID: <179593407568.3146.3078773695061553580@kernel.org> (raw)
In-Reply-To: <MA0PR01MB92174ED1110DC61766D591C4FD432@MA0PR01MB9217.INDPRD01.PROD.OUTLOOK.COM>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 (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] The new full-budget return in stmmac_rx() can leave RX dead in
  the tc block offload path, which is the failure this patch is meant to…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but resume hands
  RX descriptors without valid buffer addresses back to the DMA, and the…

--

net: stmmac: retry a failed RX refill from a timer

The patch adds a per-channel timer to stmmac. The timer schedules RX NAPI
when a page_pool refill failure leaves too few RX descriptors with the DMA.
stmmac_rx() now also returns the full budget when it stopped at the
descriptor before dirty_rx and the refill then succeeded. That way NAPI
polls again instead of waiting for an RX interrupt.

Link: https://lore.kernel.org/netdev/20260331195927.3353cc6d@kernel.org/
Link: https://lore.kernel.org/netdev/20260402174049.0ac088cc@kernel.org/

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index a685ce4638f61..bd0badb90bc8a 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

[ ... ]

> @@ -328,8 +361,17 @@ static void stmmac_enable_all_queues(struct stmmac_priv *priv)
>  			continue;
>  		}
>  
> -		if (queue < rx_queues_cnt)
> +		if (queue < rx_queues_cnt) {
> +			/* Disabling the queues cancelled any pending refill
> +			 * retry, but the ring may have been kept as it was.
> +			 * Check it while no poll can run.
> +			 */
> +			bool refill = stmmac_rx_refill_needed(priv, queue);
> +
>  			napi_enable(&ch->rx_napi);
> +			if (refill)
> +				stmmac_rx_refill_timer_arm(ch);
> +		}
>  		if (queue < tx_queues_cnt)
>  			napi_enable(&ch->tx_napi);
>  	}

[Severity: High]
This isn't a bug introduced by this patch, but the new check here can't
catch it. On resume, can the RX DMA get descriptors that have no valid
buffer address?

stmmac_resume() calls stmmac_reset_queues_param(), and
stmmac_reset_rx_queue() does:

	rx_q->cur_rx = 0;
	rx_q->dirty_rx = 0;

It then calls stmmac_clear_descriptors(). stmmac_clear_rx_descriptors()
runs stmmac_init_rx_desc() on every slot without checking
buf_pool[i].page.

On dwmac4, dwmac4_rd_init_rx_desc() only calls dwmac4_set_rx_owner(). That
ORs OWN and BUFFER1_VALID into des3 and leaves des0/des1 unchanged.

Suppose an earlier stmmac_rx_refill() stopped on a page_pool allocation
failure. The slots after it were already consumed: buf->page is NULL, and
des0/des1 still hold write-back data (for example the VLAN tag that
dwmac4_wrback_get_rx_vlan_tci() reads from des0).

After resume the DMA owns those descriptors. Could it write received
frames to an address built from those stale write-back words?

Resume reset the indices, so stmmac_rx_refill_needed() sees
CIRC_SPACE(0, 0, size) = size - 1 here and never arms the refill timer.

The notes below the --- line list "resume after a failed refill" as not
changed. Is a separate fix planned for it?

[ ... ]

> @@ -6146,6 +6195,13 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
>  	priv->xstats.rx_dropped += rx_dropped;
>  	priv->xstats.rx_errors += rx_errors;
>  
> +	/* A frame may be waiting in the descriptor we stopped at. If the
> +	 * refill freed it, poll again rather than wait for an interrupt
> +	 * that already fired. If not, the refill timer polls again.
> +	 */
> +	if (unlikely(at_dirty) && !stmmac_rx_refill_needed(priv, queue))
> +		return limit;
> +
>  	return count;
>  }

[Severity: High]
Can this full-budget return leave the RX DMA interrupt masked for good
on the tc block offload path?

stmmac_napi_check() masks the channel's RX DMA interrupt before it
schedules rx_napi:

	if (napi_schedule_prep(rx_napi)) {
		spin_lock_irqsave(&ch->lock, flags);
		stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 0);
		spin_unlock_irqrestore(&ch->lock, flags);
		__napi_schedule(rx_napi);
	}

Only stmmac_napi_poll_rx() unmasks it, and only when work_done < budget
and napi_complete_done() succeeds.

With this change, stmmac_rx() returns limit even when count < limit. If a
napi_disable() is pending at that point, __napi_poll() completes NAPI
itself:

	if (unlikely(napi_disable_pending(n))) {
		napi_complete(n);
		return work;
	}

so the driver's unmask never runs.

stmmac_setup_tc_block_cb() (cls_u32 / flower offload) calls
__stmmac_disable_all_queues() and then stmmac_enable_all_queues(). Neither
unmasks the DMA interrupt or reinitialises the ring.

The new check in stmmac_enable_all_queues() arms the timer only when
stmmac_rx_refill_needed() is true. This full-budget return only happens
when it is false, and the ring indices don't change in between. After
napi_enable() there is no pending timer and no scheduled poll, and the RX
interrupt is still masked.

Before this patch, a 64-entry ring (DMA_MIN_RX_SIZE) with the default NAPI
weight of 64 could return at most 63, so every poll completed and
unmasked the interrupt. The notes below the --- line report 400 of 851
polls returning the full budget with a 64-entry ring. With larger rings
the same thing now also happens after an allocation failure followed by a
successful refill, which is the case this patch is meant to fix.

The notes say a separate fix will follow, but that text won't reach git,
and the patch is tagged for stable. Could the fix be part of this patch?
For example, always call napi_schedule(&ch->rx_napi), or arm the refill
timer, after napi_enable() in stmmac_enable_all_queues() or
stmmac_setup_tc_block_cb().

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/MA0PR01MB92174ED1110DC61766D591C4FD432%40MA0PR01MB9217.INDPRD01.PROD.OUTLOOK.COM

      reply	other threads:[~2026-11-29  6:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:17 [PATCH net v2] net: stmmac: retry a failed RX refill from a timer Anandu Padinhare
2026-11-29  6:34 ` netdev-bot+sashiko [this message]

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=179593407568.3146.3078773695061553580@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Anandu.Padinhare@electrifex.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cfsworks@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=david.wu@rock-chips.com \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=sdf@fomichev.me \
    --cc=stable@vger.kernel.org \
    /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