Article View: linux.kernel.netdev
Article #26240Re: [PATCH net] net: stmmac: remove STMMAC_DOWN
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 09:15
Date: Thu, 03 Dec 2026 09:15
168 lines
14709 bytes
14709 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 0 (1) ยท Medium: 1 ยท 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] A fatal error raised during the reset window can now be
consumed and its reset request silently dropped.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it can cause a
hang or use-after-free on driver removal.
--
net: stmmac: remove STMMAC_DOWN
This patch removes the STMMAC_DOWN state bit. That bit was only ever set
inside stmmac_reset_subtask(), around dev_close()/dev_open(). The interrupt
handlers no longer return early during the reset window, and
stmmac_xdp_xmit() and stmmac_xsk_wakeup() test STMMAC_RESETING instead.
Link: https://lore.kernel.org/netdev/20240327110142.159851-1-cathy.cai@unisoc.com/
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index a685ce4638f61..7f7be965604e0 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -337,8 +337,7 @@ static void stmmac_enable_all_queues(struct stmmac_priv *priv)
>
> static void stmmac_service_event_schedule(struct stmmac_priv *priv)
> {
> - if (!test_bit(STMMAC_DOWN, &priv->state) &&
> - !test_and_set_bit(STMMAC_SERVICE_SCHED, &priv->state))
> + if (!test_and_set_bit(STMMAC_SERVICE_SCHED, &priv->state))
> queue_work(priv->wq, &priv->service_task);
> }
[Severity: Medium]
Can a reset request raised during the reset window get lost here?
The commit message says stmmac_service_event_schedule() is "already
guarded by STMMAC_SERVICE_SCHED". However, that bit stays set for the whole
reset, because stmmac_service_task() clears it only after
stmmac_reset_subtask() returns:
stmmac_service_task() {
stmmac_reset_subtask(priv);
clear_bit(STMMAC_SERVICE_SCHED, &priv->state);
}
With the STMMAC_DOWN early returns gone, stmmac_interrupt(),
stmmac_safety_interrupt() and (on GMAC4) stmmac_mac_interrupt() ->
stmmac_dma_err_interrupt() now run normally during that window.
In the dev_open() half, __stmmac_open() re-arms the safety features in
stmmac_hw_setup(). It then calls phylink_start() and stmmac_request_irq()
before dev_open() returns.
If an uncorrectable safety error or fatal DMA error fires after the IRQs
are requested, the handler consumes it. On XGMAC, dwxgmac3_handle_mac_err()
writes the status back to clear it, and then:
stmmac_safety_feat_interrupt()
stmmac_global_err()
netif_carrier_off(priv->dev);
set_bit(STMMAC_RESET_REQUESTED, &priv->state);
stmmac_service_event_schedule()
test_and_set_bit(STMMAC_SERVICE_SCHED) returns 1, no queue_work()
stmmac_reset_subtask() already consumed STMMAC_RESET_REQUESTED with
test_and_clear_bit() before dev_close(), and nothing checks it again
afterwards. The hardware status has been cleared, so the IRQ doesn't fire
again.
Wouldn't this leave the MAC running after an uncorrectable fault with no
reset pending? If phylink had already resolved link-up, carrier also stays
off. dev_watchdog() doesn't call ndo_tx_timeout while carrier is off.
That means nothing seems to re-queue the service task until a link event
or an admin down/up.
A narrower form of this race existed before, between
clear_bit(STMMAC_DOWN) and clear_bit(STMMAC_SERVICE_SCHED). Before this
patch, though, the handlers did not touch latched errors during the rest
of the reset window.
Would it help to clear STMMAC_SERVICE_SCHED before calling
stmmac_reset_subtask()? Alternatively, the service task could check
STMMAC_RESET_REQUESTED again after clearing STMMAC_SERVICE_SCHED, and
requeue the work if it is set.
[ ... ]
> @@ -7527,9 +7506,6 @@ static void stmmac_reset_subtask(struct stmmac_priv *priv)
> {
> if (!test_and_clear_bit(STMMAC_RESET_REQUESTED, &priv->state))
> return;
> - if (test_bit(STMMAC_DOWN, &priv->state))
> - return;
> -
> netdev_err(priv->dev, "Reset adapter.\n");
>
> rtnl_lock();
> @@ -7537,10 +7513,8 @@ static void stmmac_reset_subtask(struct stmmac_priv *priv)
> while (test_and_set_bit(STMMAC_RESETING, &priv->state))
> usleep_range(1000, 2000);
>
> - set_bit(STMMAC_DOWN, &priv->state);
> dev_close(priv->dev);
> dev_open(priv->dev, NULL);
> - clear_bit(STMMAC_DOWN, &priv->state);
> clear_bit(STMMAC_RESETING, &priv->state);
> rtnl_unlock();
> }
[Severity: High]
This isn't a bug introduced by this patch, but can this dev_open() run
on a netdev that is being unregistered?
stmmac_dvr_remove() doesn't cancel priv->service_task before teardown:
stmmac_dvr_remove() {
...
unregister_netdev(ndev);
...
phylink_destroy(priv->phylink);
...
stmmac_mdio_unregister(ndev);
destroy_workqueue(priv->wq);
...
}
stmmac_global_err() can queue the work in two ways:
- from an IRQ handler, before free_irq() runs in the unregister close
path
- from ndo_tx_timeout, just before unregister_netdev()
The worker then blocks in rtnl_lock() here.
Once unregister_netdev() drops RTNL in netdev_run_todo(), the worker
continues. Its dev_close() does nothing because IFF_UP is clear, and
dev_open() reaches __dev_open().
__dev_open() only checks netif_device_present(), and unregister doesn't
clear __LINK_STATE_PRESENT. So stmmac_open() runs: it connects the PHY,
requests IRQs and allocates DMA rings, and dev_activate() attaches qdiscs
that hold netdev references.
Depending on timing, couldn't this make netdev_wait_allrefs_any() wait
forever? Or could stmmac_dvr_remove() go on to phylink_destroy() and
stmmac_mdio_unregister() while the worker is still using priv->phylink?
destroy_workqueue() only drains the work after those calls.
The STMMAC_DOWN check removed above never covered this, since the bit was
only set inside this same function. Is a cancel_work_sync() on
priv->service_task needed before unregister_netdev()? Some other check
that stops the reset once the device is going away would also work.
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201091256.3000677-1-zxyan0222%40gmail.com
Technical Details
Message-ID:
<179628935561.3146.10251855086500360375@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376437-linux-kernel-netdev=dewy.ruReferences:
<20261201091256.3000677-1-zxyan0222@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376437-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] net: stmmac: remove STMMAC_DOWN Date: Thu, 03 Dec 2026 09:15:55 +0000 Organization: Usenet Network Message-ID: <179628935561.3146.10251855086500360375@kernel.org> References: <20261201091256.3000677-1-zxyan0222@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2445992"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:RBGjBXC8Xh+6YqHQuMZ13D4DsPw= sha256:vg+CfnfMq9sgTx4AmEmwbPOIUmYsfVUAgJc4ep6Gq0c= sha1:Cr+7dzW+zJ4rJgHF6b8x3IBJcoI= sha256:cXH0rczgDf6+uhOQUgJsriN+vYE5TQj5OwBLPibH4Pc= 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 4851511789E; Thu, 3 Dec 2026 12:16:31 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, 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 BijdskiG2Hef; Thu, 3 Dec 2026 12:16:27 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-376437-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 87AA6117894; Thu, 3 Dec 2026 12:16:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id B44B56041C2; Thu, 3 Dec 2026 09:16:18 +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=1796289358; b=2BGj1LTSJggNqORejwdhtgyxqY7O2VCFsYDwbaEMfP9FObFfbNPbF9dj/92v7hTyaYyx uvMq42v2PpLABSJuhl7O5kGvvSK8TzW1Am+NsTh9CuVXixWLs9XK8A0H2yqTxu5JeHGwz Mo8vhqpebUrqfrubmxfzh7kxZRHQfZoOxsIHvUMhRK0wdFQpCAcwnTvdCepg1J42EhFB0 8Fy1njZv19KZgLciKHp9E8VqG36bI3jqlKPWuJ0rNU9N68G8dy9OjlGcOue9K0La4c4rz Cmpgs0wPEOnv10hN90WxfZwO2bMy1uJa3hgMi7fUcWC66Yq11EmrImGgj5bSLAfvRIQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289358; 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=P5Ep9htVu4cJXTRDVnqRDWWE0NfdQwPiihvyOHvQ55A=; b=uOgXELFibnnAq3scjExDFvOINIW3pqS+wH7t+aAZeR2hY74Je1GxZlq3x9f5+owhy4mo p2RiHL668sU2guGLQe5Gls0Nkv0tZf1fSCQhtMiAE/icmg+7SNIW85Ss9SEVVcjC5E1Pw pV95NbbgyGAUgTJmzmsXQuFfe891SyMeDbRNQqB1qpl5lrdtUWQsEkR1addUwaMSc+9W9 2HUX6XlXffb+iFygvMPueGcHM1N+c03paKH2K/7USdl16FvdIMsXNuVrb6ErFIxNWJ4vN A4PcDGWb7uCf1tkxwVxfNR1j9OVcWKYP5poLlCsy5amaFyLW3l983DAlLL4ucwe4Izg== 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=IWroeZut; 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 950A2606A69E; Thu, 3 Dec 2026 09:15: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=IWroeZut 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=1796289357; b=ILx7pgPqqN/nT/ysE/FSJvKKMLCW11SEhFpGzjQHbwW8IpFnECOSc/8A7g4UVbDhgw3U h14zmXowZF1sDrFqws6iAyAemj+tVZB4UX0I/yjtbEJOUXQJB5nYKSLAFnoDzigKiYot1 ks7CMX8E9HRfNJFSdp1PfEyRsFFy4xFyUDc0VlEHnKzFP4tLNU5VUL9B3tgWQRW4H1JBX D6ndCVnCDTzVupsyiGXwJofhXXyKIXs8vF+o9NDip3zqYAWb4u57bV23mgEsCTnULgRUc K7zexHCTD8XTfwn3JriecVEBJsfqQJp6hNVvgMwiDtiV9dmjB+kLQUHYYJGCKV84oyA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289357; 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=P5Ep9htVu4cJXTRDVnqRDWWE0NfdQwPiihvyOHvQ55A=; b=HNFq3CzRIAa+s153uUV1BZxBaEKB4usOpv0t0O/T1L/+WdM1pc8OerjGOmTz15x5cQpX WrE38XIEau7YJ8MPMEEY2ZY/kZfacXxAmyw/9eTC9SDhfpndlx7m1jL0fiyLJr1Hj5jqe h0sO9ZBDxNtaDSNopb/BzUvFIPtPZ7F+TNEGNaQwb4fhPXqbAlIK3hLgcu3jCRidVbIqm smtKn+XyE5bpgWQM01+3PddGaKrJIKaAEYt2Z4/+G7cLExzOGmHK731qdEOA7V3v/aI4m gSpHEDnXrEMiRavfs2YmfEVR1YygStpXrOhDjv3T0KTP03Iy2IRuYR1mEpdA+h83a4Q== 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=IWroeZut; 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 B609D606A698; Thu, 3 Dec 2026 09:15:57 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DE891F0089C; Thu, 3 Dec 2026 09:15:56 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796289357; bh=P5Ep9htVu4cJXTRDVnqRDWWE0NfdQwPiihvyOHvQ55A=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=IWroeZutzS/fV3knKbvsdgKzOcvbxKskvMEYWH4KoP/DDYm8mKIMCB6pn63F84j1G cHRtIbtDiyBNDXT6rZZBLcdTVznI/MryZ+E953YeZbblIzV1ruaVYhY0dMYFHOGcbn jm5uzYtmsn2nMzvelr0gfB+QsGnSGsp+Xu3cdvxn8GFLTJVjr3NuDqfye8Qv/KU/oU TdnVffjEfUzZR8jw50d8C60ZBh3F2Yk7uSUtl0fH9j+1FoTIXr/cP8mzFUWFy/Go4B u7R/226tQgJGPNr3bO4kjFb9xAMXbWqNaYrNOvuT5tIYr8hU/87l/rMhPb/Zt++2I6 al6N9s7Kdqpmg== X-Cc: maxime.chevallier@bootlin.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, andrew+netdev@lunn.ch, Jose.Abreu@synopsys.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, bigeasy@linutronix.de, clrkwllms@kernel.org, rostedt@goodmis.org, 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, linux-rt-devel@lists.linux.dev, bpf@vger.kernel.org X-In-Reply-To: <20261201091256.3000677-1-zxyan0222@gmail.com> 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