🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27497

Re: [PATCH net-next 2/3] net: stmmac: add an opt-in MSI vector mask for NAPI

#27497
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 20:37
248 lines
16887 bytes
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
Technical Details
Message-ID: <179650307649.3148.17022466268731706828@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378121-linux-kernel-netdev=dewy.ru
References: <20261204203130.287919-3-contact@c127.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378121-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179650307649.3148.17022466268731706828@kernel.org>
References: <20261204203130.287919-3-contact@c127.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="3115053"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:IdAO712XP0wGDH18O1gOPPh+VE4= sha256:P9+Xx48wFFaOxrBkTKIWLYKY2MmGhAK85C4IkENfIkc= sha1:TPJQqbVg7hbdvJ4uI/Px1Jo/gZs= sha256:4XdzQDpYedeKuNI3at/S6MnKQgPZHxiz1HaFfgDsGAc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id ACFBD117EAC; Sat,  5 Dec 2026 23:38:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.54
X-Spam-Status: No, score=-3.54 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C5EGcMtdNNqn; Sat,  5 Dec 2026 23:38:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-378121-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id ADA26117EA9; Sat,  5 Dec 2026 23:38:05 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 9BF3F2B8BB; Sat,  5 Dec 2026 20:38:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796503078; b=QXec2C0P4BHVyBya/l0IfhtCqlrPxU9RcDiU5Up1vXngLnJzWy7WdVSebRKmZ3s/QQnT XzxVNK7yClfVvP/QBUt5fTj8+897LI+e/aP0k6irERUlzv3gmQOqV8aG3htUSElSo+EjM Taw4JJNDrI9MlasKxfvDJpx4P1/F5+ZYbs5Km7Zb6mznJmqa2q49uRQmc8ihIbVZqBvfN e8XGXOR07CvIgXeONu5y7i/OzbdFNe3tldeJB2/1ZKatvHZzp6pupDZyJAFY7rvCX3Oqa zTEpA5itnTNij2SBPQiJ+7EE+ad5WHvK1umTCBv2z7moVKmdf1wT3v33/M95jjclplQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796503078; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=flZTXOs/hA1kbbWai6MvrK2YQD5ehrLRl0tSH6D5U5w=; b=TzeXgBsW3ylbsHybmXYBx+CA1iB+j2razfogGV2u+GmuGPKa39Ge0AoeaQ58IzJBLWEt SagVDbps2aoh8VetR4aTx0Su4P4lFI1F0cJTTjGRddtA/F1ldqEb8qHEk/T6zU8r5l4Ce oNXaCM+WWDpPmGP5efVmvnO4I7hSqptVE1sL/QngmzyHH5TfgN8ZzSD/jwRIWx7AT2k58 PbZcqwfziV0/cMk0nE4o5zGDhdiZV1YLefiatl7ji/SLv4N33RJg1Ips9PG6+ysVY14JX mGOjUSfY0gT0LBTP4KBxt2KDEqWlsc+QS1YC0Z9xexTyqRY2DWtRdfVv6zQ8+yeS7uQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QQRwkkAv; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD7B1606A33F; Sat,  5 Dec 2026 20:37:58 +0000 (UTC)
X-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=QQRwkkAv
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796503077; b=YKWgptjNvDspNZcI53/EzW30Bv1d3ZZpoeqAgLVuXxWLFCSXv/2zntqfZ8HyVBxv3B39 yW53E3JME5b6koEt2fgtFJyNICIZuoInmUNLJW+ji/QY9UfHytRmGfz1HC9YkF13cEQpm +etWMoiLlR/3puXgqGw/LxmSQ2ybgyIGT4FurUnsFN3Muljt4d4lhcDdcVdKxBGsFhfRP 0EpAwYTg4HofpLRqOqoI4ukUGUznNpTxaLb31/+pVEwrWFGZzJBf1EBidMFx+14d3NQcV ZmlqvsGZ4XV7C180WAycLeS0f4IkYNFmQx4XvFX8cPw2GfTP1GtEkcGmm0biPXOobLA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796503077; 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=flZTXOs/hA1kbbWai6MvrK2YQD5ehrLRl0tSH6D5U5w=; b=oC4w1+O7G2ahfOwEuDai/mwax7bUgL8W/sUVjLYaQYe4ftL/caYCckkaFnzuP7wR8WRx lAg82s4C6NbMhN5j9S5ARgg0mCnqlJKyOzrNclWdF7S//JFktZosT+6+yLHJQhkkqyMZr SuPuVIY0fjT0Xsogp/mxjI2+NJhKsWrbTnx8v5nWJS9izFc1RdrEDKO5lKUyfqPm1mBFV Fbj1fibY4MH4L0GS7XMO9NEOpbVsdfYjAVN5zbRwlAds7WWBX5F64OKNh6pt4Llz4pUt3 6R37yyGBNYxgIwjOkP40UfKRA/zQYh7yDOxyhkyE+/ssqyWv9tqR478XaoZ3AKZmtbQ==
X-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=QQRwkkAv; arc=none smtp.remote-ip=100.103.45.18
X-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 C9F5B606A335 for <netdev@vger.kernel.org>; Sat,  5 Dec 2026 20:37:57 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEDD91F0092B; Sat,  5 Dec 2026 20:37:56 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796503077; bh=flZTXOs/hA1kbbWai6MvrK2YQD5ehrLRl0tSH6D5U5w=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=QQRwkkAvFHeNFS2YtHMMk0tUN/345fuowsj2t9rbu8T4aqhNq3cgttYK3N3tcVIVw Rgmg2Ns+d/tYQ2iprmVXheX9B60CYevtBHw2EZ8TUM6Jxq+9iaxB8BCgLaIdm6YZc9 106S0JY22vj8AxkV8aZUJWhN6MxaGEIIrDJtejQZi/fc2y/xyMOYDLGd09lc0hA37z g+EilQXqr2apOCl6q6YKT2WpLGPD5z0Jsj8krWFNjlyCZfPXXfLE55H/DlPFMcGZcG TnezSQwezxectJZsrWczLKt51wYw5YhLzPFZ7ZZcH5W8cBTTZqIKV3vI3NO8aGrKid LVfbDpyxOTgYQ==
X-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
X-In-Reply-To: <20261204203130.287919-3-contact@c127.dev>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list