Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: contact@c127.dev
Cc: kuba@kernel.org, pabeni@redhat.com, edumazet@kernel.org,
	davem@davemloft.net, andrew+netdev@lunn.ch,
	maxime.chevallier@bootlin.com, me@ziyao.cc,
	mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org, zhangfeionline@gmail.com
Subject: Re: [PATCH net-next 2/3] net: stmmac: add an opt-in MSI vector mask for NAPI
Date: Sat, 05 Dec 2026 20:37:56 +0000	[thread overview]
Message-ID: <179650307649.3148.17022466268731706828@kernel.org> (raw)
In-Reply-To: <20261204203130.287919-3-contact@c127.dev>

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

Critical: 0 · High: 0 (1) · Medium: 2 · 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).

- [Medium] stmmac_napi_unmask_irq() (stmmac_main.c:2647-2653) calls
  stmmac_napi_unmask_vec() first.
- [Medium] The vector mask depends on the irq core replaying the event
  that arrives while the vector is lazily disabled.

Pre-existing issues:
- [High] In stmmac_setup_tc_block_cb()
  (drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:6743-6767), NAPI is…

--

net: stmmac: add an opt-in MSI vector mask for NAPI

This patch adds STMMAC_FLAG_NAPI_MASK_MSI_VEC. When it is set together
with STMMAC_FLAG_MULTI_MSI_EN, the per-channel RX/TX MSI handlers mask
their vector with disable_irq_nosync() instead of masking the channel
interrupt in DMA_CHAN_INTR_ENA. The NAPI poll re-enables the vector, and
the irq core is expected to resend any event raised while it was masked.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index b3524d46863da..b34942ad08ba0 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -2592,6 +2592,78 @@ static void stmmac_stop_tx_dma(struct stmmac_priv *priv, u32 chan)
>  	stmmac_stop_tx(priv, priv->ioaddr, chan);
>  }
>  
> +/* Mask a channel interrupt for NAPI. With STMMAC_FLAG_NAPI_MASK_MSI_VEC
> + * and per-channel MSIs, the MSI vector is disabled instead of the DMA
> + * channel interrupt, so an event raised meanwhile is resent by the irq
> + * core (lazy disable) when the vector is enabled again. Called with
> + * ch->lock held.
> + */
> +static void stmmac_napi_mask_irq(struct stmmac_priv *priv, u32 chan,
> +				 u32 dir)
> +{
> +	struct stmmac_channel *ch = &priv->channel[chan];
> +
> +	if ((priv->plat->flags & STMMAC_FLAG_NAPI_MASK_MSI_VEC) &&
> +	    (priv->plat->flags & STMMAC_FLAG_MULTI_MSI_EN)) {
> +		if (dir == DMA_DIR_RX && !ch->rx_vec_masked) {
> +			ch->rx_vec_masked = true;
> +			disable_irq_nosync(priv->msi->rx_irq[chan]);
> +			return;
> +		}

[Severity: Medium]
What happens here on architectures that provide neither irq_retrigger nor
CONFIG_HARDIRQS_SW_RESEND?

The PCI MSI/MSI-X chips have no irq_disable callback, so
disable_irq_nosync() is a lazy disable. An MSI that arrives while the
vector is disabled sets IRQS_PENDING. On enable_irq(), check_irq_resend()
clears IRQS_PENDING and then does:

	if (!try_retrigger(desc))
		err = irq_sw_resend(desc);

Without CONFIG_HARDIRQS_SW_RESEND, irq_sw_resend() is a stub that returns
-EINVAL.

LoongArch, for example, does not select HARDIRQS_SW_RESEND, and none of
the Loongson irqchips (pch-msi, eiointc, avec) implement irq_retrigger.
DWMAC_MOTORCOMM depends only on PCI. The later motorcomm patch in this
series sets the flag unconditionally on MSI-X in motorcomm_setup_irq():

	plat->flags |= STMMAC_FLAG_MULTI_MSI_EN |
		       STMMAC_FLAG_NAPI_MASK_MSI_VEC;

On such a host, could an RI/TI raised between the poll's last descriptor
check and enable_irq() be dropped? The stmmac handler would never run for
it, so the latched DMA_CHAN_STATUS bit would wait for an unrelated event.
That is the same symptom this patch is meant to fix.

The commit message says:

  The resend uses irq_retrigger() or CONFIG_HARDIRQS_SW_RESEND, which
  arm64 and x86 select.

The code does not enforce this dependency, though. Should the flag be
gated (for example with IS_ENABLED(CONFIG_HARDIRQS_SW_RESEND))? Other
options would be to fall back to IRQ_DISABLE_UNLAZY, or to re-check the
channel status after enable_irq().

> +		if (dir == DMA_DIR_TX && !ch->tx_vec_masked) {
> +			ch->tx_vec_masked = true;
> +			disable_irq_nosync(priv->msi->tx_irq[chan]);
> +			return;
> +		}
> +	}

[ ... ]

> +static void stmmac_napi_unmask_vec(struct stmmac_priv *priv, u32 chan,
> +				   bool *rx, bool *tx)
> +{
> +	struct stmmac_channel *ch = &priv->channel[chan];
> +
> +	if (*rx && ch->rx_vec_masked) {
> +		ch->rx_vec_masked = false;
> +		enable_irq(priv->msi->rx_irq[chan]);
> +		*rx = false;
> +	}
> +	if (*tx && ch->tx_vec_masked) {
> +		ch->tx_vec_masked = false;
> +		enable_irq(priv->msi->tx_irq[chan]);
> +		*tx = false;
> +	}
> +}
> +
> +/* Undo stmmac_napi_mask_irq() or a DMA mask from the other NAPI
> + * schedulers when a poll completes. Called with ch->lock held.
> + */
> +static void stmmac_napi_unmask_irq(struct stmmac_priv *priv, u32 chan,
> +				   bool rx, bool tx)
> +{
> +	stmmac_napi_unmask_vec(priv, chan, &rx, &tx);
> +	if (rx || tx)
> +		stmmac_enable_dma_irq(priv, priv->ioaddr, chan, rx, tx);
> +}

[Severity: Medium]
Can a completing TX poll leave DMA_CHAN_INTR_ENA.TIE cleared here?

stmmac_napi_unmask_vec() clears *tx whenever ch->tx_vec_masked is set, so
stmmac_enable_dma_irq() is skipped for TX. That assumes only one TX mask
is outstanding. However, stmmac_tx_timer() still applies the DMA mask
without checking tx_vec_masked:

	if (likely(napi_schedule_prep(napi))) {
		...
		stmmac_disable_dma_irq(priv, priv->ioaddr, ch->index, 0, 1);

One possible sequence:

1. A TX MSI goes through stmmac_napi_check(dir=DMA_DIR_TX), and
   stmmac_napi_mask_irq() sets tx_vec_masked and calls
   disable_irq_nosync(tx_irq).

2. The poll finishes, but napi_complete_done() returns false while still
   clearing NAPIF_STATE_SCHED. This happens with napi_defer_hard_irqs
   plus gro_flush_timeout, or with prefer-busy-poll. stmmac_napi_poll_tx()
   skips the unmask, so tx_vec_masked stays true.

3. stmmac_tx_timer_arm() arms txtimer, because napi_is_scheduled() is now
   false.

4. stmmac_tx_timer() wins napi_schedule_prep() and clears TIE.

5. When that poll completes, stmmac_napi_unmask_irq(priv, chan, false,
   true) calls only enable_irq(), and TIE stays cleared.

After this, would TX completions stop raising an MSI until a later
timer-driven poll completes with tx_vec_masked == false?

That is the timer-only TX completion behaviour this patch is trying to
remove. Before the patch, both masks were the same DMA bit, so this state
could not occur.

> +
> +/* Enable the channel interrupts when a queue (re)starts. A NAPI stopped
> + * by napi_disable() may have left its vector disabled.
> + */
> +static void stmmac_start_chan_irq(struct stmmac_priv *priv, u32 chan,
> +				  bool rx, bool tx)
> +{
> +	bool vrx = rx, vtx = tx;
> +
> +	stmmac_napi_unmask_vec(priv, chan, &vrx, &vtx);
> +	stmmac_enable_dma_irq(priv, priv->ioaddr, chan, rx, tx);
> +}

[Severity: High]
This is a pre-existing issue, but is there a napi_disable()/napi_enable()
path that never reaches stmmac_start_chan_irq()?

stmmac_setup_tc_block_cb() does:

	__stmmac_disable_all_queues(priv);
	...
	stmmac_enable_all_queues(priv);

Those helpers only call napi_disable() and napi_enable().

Consider this sequence on an RX channel:

RX MSI hardirq
stmmac_napi_check(dir=DMA_DIR_RX)
  napi_schedule_prep(rx_napi)
  stmmac_napi_mask_irq()
    ch->rx_vec_masked = true;
    disable_irq_nosync(priv->msi->rx_irq[chan]);

tc filter add/delete with hw offload
stmmac_setup_tc_block_cb()
  __stmmac_disable_all_queues()
    napi_disable()

Under load, stmmac_napi_poll_rx() returns the full budget. The
napi_complete_done() branch that calls stmmac_napi_unmask_irq() is
skipped, and __napi_poll() completes NAPI itself:

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

stmmac_enable_all_queues() then calls napi_enable(), but nothing calls
enable_irq().

Would the RX vector stay at disable depth 1 with rx_vec_masked still
true? RX has no timer fallback. Would rx_napi on that channel then never
be scheduled again until close/open or resume?

The commit message says:

  stmmac_enable_all_dma_irq() and stmmac_enable_rx/tx_queue() re-enable
  a vector left disabled by napi_disable().

This path goes through neither of them.

The old DMA mask scheme leaves DMA_CHAN_INTR_ENA.RIE cleared on this path
in the same way, so the stall predates this patch. However, the later
YT6801 glue patch in this series ("net: stmmac: motorcomm: mask the MSI
vector during NAPI") wires only rx_irq[0]. There, this would stop RX for
the whole interface.

On TX, a later timer-driven poll undoes the stale tx_vec_masked left
here. Because of the mask stacking described above in
stmmac_napi_unmask_irq(), that leaves TIE masked for one more timer
cycle.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204203130.287919-1-contact%40c127.dev

  reply	other threads:[~2026-12-05 20:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 20:31 [PATCH net-next 0/3] net: stmmac: reduce DMA interrupt latency on YT6801 Johan Alvarado
2026-12-04 20:31 ` [PATCH net-next 1/3] net: stmmac: dwmac4: do not treat TBU as a TX event Johan Alvarado
2026-12-05 20:37   ` netdev-bot+sashiko
2026-12-04 20:31 ` [PATCH net-next 2/3] net: stmmac: add an opt-in MSI vector mask for NAPI Johan Alvarado
2026-12-05 20:37   ` netdev-bot+sashiko [this message]
2026-12-04 20:31 ` [PATCH net-next 3/3] net: stmmac: motorcomm: mask the MSI vector during NAPI Johan Alvarado
2026-12-05 20:37   ` netdev-bot+sashiko

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=179650307649.3148.17022466268731706828@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=contact@c127.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --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=me@ziyao.cc \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=zhangfeionline@gmail.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