Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jakobunt@gmail.com
Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, mcoquelin.stm32@gmail.com,
	alexandre.torgue@foss.st.com, jakob.unterwurzacher@cherry.de,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: stmmac: reset the DMA on a fatal bus error
Date: Tue, 24 Nov 2026 14:33:10 +0000	[thread overview]
Message-ID: <179553079064.3135.2914132404967559636@kernel.org> (raw)
In-Reply-To: <20261120-stmmac_dma_fatal_error-v1-1-acd57921af57@cherry.de>

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

Critical: 0 · High: 0 (1) · Medium: 4 · Low: 1

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] On dwxgmac2 the Fatal Bus Error interrupt is never enabled, so
  the patch's dwxgmac2 change cannot run.
- [Medium] Recovery from an FBE depends entirely on the service task, and
  the service-task logic can lose a reset request.
- [Medium] The patch targets FBEs around suspend/resume, but the reset it
  now triggers is not coordinated with PM transitions.
- [Medium] In multi-MSI mode the FBE handling added by the patch may
  never run.
- [Low] The patch fixes a hang that users can see.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch adds
  a new trigger for it.

--

net: stmmac: reset the DMA on a fatal bus error

The dwmac100/1000, dwmac4, dwxgmac2 and loongson DMA interrupt handlers
now report a DMA fatal bus error as a new dma_fatal_error status instead
of tx_hard_error. The shared and per-channel MSI interrupt paths then
call stmmac_global_err() to reset the adapter from the service task. The
goal is to recover the RX DMA stalls seen on RK3588 after resume.

> The only trace is the fatal_bus_error_irq counter in
> ethtool -S. The interface needs a manual down/up to recover.

[Severity: Low]
This looks like a fix for a hang that users can hit. Before this patch:

- dwmac_dma_interrupt(), dwmac4_dma_interrupt() and
  loongson_dwmac_dma_interrupt() mapped FBE to "ret = tx_hard_error".
- dwxgmac2_dma_interrupt() used "ret |= tx_hard_error".
- stmmac_msi_intr_rx() threw away the return value of
  stmmac_napi_check().

Should this have a Fixes: tag and target net, and possibly Cc: stable?
The subject doesn't say whether it is meant for net or net-next. Without
a Fixes: tag, stable backporters can't easily tell which trees need it.

[ ... ]

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
> index 0a6e82a155c0e..bc06076410dc7 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c
> @@ -335,7 +335,7 @@ static int dwxgmac2_dma_interrupt(struct stmmac_priv *priv,
>  		}
>  		if (unlikely(intr_status & XGMAC_FBE)) {
>  			x->fatal_bus_error_irq++;
> -			ret |= tx_hard_error;
> +			ret |= dma_fatal_error;
>  		}
>  	}

[Severity: Medium]
Can this branch be reached on dwxgmac2? dwxgmac2_dma_init_chan() sets
the per-channel interrupt enable like this:

	writel(XGMAC_DMA_INT_DEFAULT_EN, ioaddr + XGMAC_DMA_CH_INT_EN(chan));

and dwxgmac2.h has:

#define XGMAC_DMA_INT_DEFAULT_EN	(XGMAC_NIE | XGMAC_AIE | \
					XGMAC_RIE | XGMAC_TIE)

Nothing defines or sets an FBEE (bit 12) enable for XGMAC. dwmac4 does
include DMA_CHAN_INTR_ENA_FBE in DMA_CHAN_INTR_ABNORMAL.

My reading of the databook is that AIS only reflects abnormal sources
whose own enable bit is set. If that is right, a fatal bus error would
not set XGMAC_AIS or raise an interrupt. The XGMAC_FBE test above sits
inside the XGMAC_AIS block, so it would never run.

The acknowledge at the end of dwxgmac2_dma_interrupt() is also masked
with intr_en, so bit 12 would never be cleared:

	writel(intr_en & intr_status, ioaddr + XGMAC_DMA_CH_STATUS(chan));

The commit message says the change covers "all DMA cores that report
the error (dwmac100/1000, dwmac4, dwxgmac2, loongson)". Does dwxgmac2
also need FBEE defined and enabled for this to work?

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 25894771e9e9f..16ba83db34546 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -349,6 +349,24 @@ static void stmmac_global_err(struct stmmac_priv *priv)
>  	stmmac_service_event_schedule(priv);
>  }
>  
> +/* A fatal bus error stops both the TX and the RX DMA of the channel. Only a
> + * reset of the DMA brings them back, so restarting the TX side alone is not
> + * enough: RX would stay stopped without any further error.
> + */
> +static bool stmmac_dma_fatal_error(struct stmmac_priv *priv, int status,
> +				   u32 chan)
> +{
> +	if (likely(!(status & dma_fatal_error)))
> +		return false;
> +
> +	if (net_ratelimit())
> +		netdev_err(priv->dev, "DMA fatal bus error on channel %u\n",
> +			   chan);
> +	stmmac_global_err(priv);

[Severity: High]
This is a pre-existing issue that this patch did not introduce, but the
patch adds a new way to trigger it. stmmac_global_err() queues
priv->service_task, and nothing cancels or flushes that work before
close or remove. The only place STMMAC_DOWN is set is inside
stmmac_reset_subtask() itself.

Can the reset worker re-open a device that is being removed?

reset worker                        stmmac_dvr_remove()
stmmac_reset_subtask()
  test_bit(STMMAC_DOWN) is false
                                    unregister_netdev()
                                      dev_close() -> stmmac_release()
  rtnl_lock() waits
                                    unregister_netdev() returns
  dev_close() is a no-op
  dev_open() -> stmmac_open()       phylink_destroy(priv->phylink)
                                    reset_control_assert(...)
                                    ...
                                    destroy_workqueue(priv->wq)

__dev_open() checks netif_device_present() but not reg_state. That
means stmmac_open() would run again on the unregistered netdev. It
would:

- re-request the IRQs, which are not devm-managed
- reallocate the DMA rings
- use priv->phylink while phylink_destroy() is running

The netdev itself comes from devm_alloc_etherdev_mqs(), so it is freed
after remove.

Could this cause a use-after-free of phylink, priv or the netdev? Or a
hang in unregister_netdev() waiting on references taken by the re-open?

A plain ifdown looks similar: a pending reset would re-open an interface
that was just closed.

Should service_task be cancelled with cancel_work_sync(), and
STMMAC_DOWN set, in the close and remove paths before teardown? The
same path can already be reached from stmmac_tx_timeout() and from the
safety-feature errors.

[Severity: Medium]
Is this reset coordinated with suspend and resume? stmmac_suspend()
neither sets STMMAC_DOWN nor cancels service_task, and priv->wq is not
freezable.

On the suspend side, an FBE handled before stmmac_stop_all_dma() in
stmmac_suspend() lets the worker run during or after suspend.
dev_close() -> stmmac_release() tears down the IRQs and DMA. dev_open()
then fails, because netif_device_detach() has already run:

net/core/dev.c:__dev_open() {
	...
	if (!netif_device_present(dev)) {
		...
		if (!netif_device_present(dev))
			return -ENODEV;
	}
	...
}

stmmac_reset_subtask() ignores the dev_open() result. stmmac_resume()
returns early when !netif_running(ndev), so the interface would stay
down after resume. If plat->suspend has already gated the clocks,
stmmac_release() would also access MMIO in an unclocked block.

On the resume side, stmmac_resume() does:

	stmmac_enable_all_dma_irq(priv);
	...
	phylink_resume(priv->phylink);
	rtnl_unlock();

	netif_device_attach(ndev);

An FBE after the DMA restarts would queue the reset. A worker waiting
on rtnl could then reach dev_open() before netif_device_attach() and
get the same -ENODEV.

Resume is the scenario this patch targets. Could this leave the
interface closed and needing a manual up, which is the symptom being
fixed?

> +
> +	return true;
> +}

[ ... ]

> @@ -6533,6 +6555,9 @@ static irqreturn_t stmmac_msi_intr_tx(int irq, void *data)
>  
>  	status = stmmac_napi_check(priv, chan, DMA_DIR_TX);
>  
> +	if (stmmac_dma_fatal_error(priv, status, chan))
> +		return IRQ_HANDLED;
> +

[Severity: Medium]
Will these per-channel vectors ever see FBE in multi-MSI mode? With
multi_msi_en, dwmac4_dma_init() programs DMA_BUS_MODE_INTM_MODE1, and
dwxgmac2_dma_init() does the same for XGMAC.

As I read the databook for INTM=1, sbd_perch_tx and sbd_perch_rx only
signal TI and RI. Abnormal channel events such as FBE go to
sbd_intr_o, which is the MAC vector here.

stmmac_mac_interrupt() only does this, and never reads the DMA channel
status:

	/* To handle Common interrupts */
	stmmac_common_interrupt(priv);

After a fatal bus error the channel stops, so no further TI or RI
interrupt arrives to bring the status through this path.

The commit message says the per-channel MSI interrupt paths are
covered. If the above is right, would multi-MSI platforms still stay
stalled after an FBE?

[ ... ]

> @@ -6557,7 +6583,8 @@ static irqreturn_t stmmac_msi_intr_rx(int irq, void *data)
>  	if (test_bit(STMMAC_DOWN, &priv->state))
>  		return IRQ_HANDLED;
>  
> -	stmmac_napi_check(priv, chan, DMA_DIR_RX);
> +	status = stmmac_napi_check(priv, chan, DMA_DIR_RX);
> +	stmmac_dma_fatal_error(priv, status, chan);

[Severity: Medium]
An FBE is a one-shot event, so can a reset request be lost here?

First case: during the reset, stmmac_reset_subtask() calls dev_open()
with STMMAC_DOWN still set. An FBE raised after the DMA restarts hits
the early return above without being decoded. stmmac_interrupt() and
stmmac_msi_intr_tx() return early the same way.

Second case: after the reset, there is a gap between clearing
STMMAC_DOWN and clearing STMMAC_SERVICE_SCHED:

stmmac_reset_subtask()
	clear_bit(STMMAC_DOWN, &priv->state);
	clear_bit(STMMAC_RESETING, &priv->state);
	rtnl_unlock();

stmmac_service_task()
	stmmac_reset_subtask(priv);
	clear_bit(STMMAC_SERVICE_SCHED, &priv->state);

An FBE handled in that gap calls stmmac_global_err(). That turns the
carrier off and sets STMMAC_RESET_REQUESTED. However,
test_and_set_bit(STMMAC_SERVICE_SCHED) in
stmmac_service_event_schedule() fails, so no work is queued. The
running task then clears SERVICE_SCHED and exits.

Would that leave RX and TX DMA stopped, the carrier forced off, and no
reset pending? dev_watchdog() skips devices without carrier, so
tx_timeout would not recover it either.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-stmmac_dma_fatal_error-v1-1-acd57921af57%40cherry.de


      parent reply	other threads:[~2026-11-24 15:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 14:16 [PATCH] net: stmmac: reset the DMA on a fatal bus error Jakob Unterwurzacher
2026-11-22 17:53 ` Nicolai Buchwitz
2026-11-23 10:04   ` Jakob Unterwurzacher
2026-11-24 14:33 ` 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=179553079064.3135.2914132404967559636@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jakob.unterwurzacher@cherry.de \
    --cc=jakobunt@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --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