Article View: linux.kernel.netdev
Article #12996Re: [PATCH net v2] net: stmmac: Disable queues before netif_tx_disable in xdp_release
From: netdev-bot+sashiko
Date: Mon, 09 Nov 2026 05:53
Date: Mon, 09 Nov 2026 05:53
182 lines
15034 bytes
15034 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 1 (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).
- [High] The patch moves the hrtimer_cancel() loop on tx_q->txtimer ahead
of netif_tx_disable().
- [Medium] The reorder only blocks one of the two places that can wake a
TX queue after netif_tx_disable() in stmmac_xdp_release().
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a use-
after-free in the same teardown.
--
net: stmmac: Disable queues before netif_tx_disable in xdp_release
This commit reorders stmmac_xdp_release(). NAPI is now disabled and the TX
coalescing hrtimers are cancelled before netif_tx_disable() is called. The
goal is to stop stmmac_tx_clean() from waking a TX queue while the DMA
rings are being torn down, using the same order as __stmmac_release().
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 7ffed295eb14a..7d1497392b8b5 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -7264,15 +7264,15 @@ void stmmac_xdp_release(struct net_device *dev)
> struct stmmac_priv *priv = netdev_priv(dev);
> u8 chan;
>
> - /* Ensure tx function is not running */
> - netif_tx_disable(dev);
> -
> /* Disable NAPI process */
> stmmac_disable_all_queues(priv);
>
> for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
> hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
>
> + /* Ensure tx function is not running */
> + netif_tx_disable(dev);
[Severity: High]
hrtimer_cancel() now runs before netif_tx_disable(). Can a stmmac_xmit()
or stmmac_tso_xmit() that is already in flight re-arm tx_q->txtimer after
the cancel has returned?
stmmac_tx_timer_arm() checks the NAPI state and then acts on it:
stmmac_main.c:stmmac_tx_timer_arm() {
...
if (unlikely(!napi_is_scheduled(napi))) {
if (unlikely(!(hrtimer_active(&tx_q->txtimer))))
hrtimer_start(&tx_q->txtimer,
STMMAC_COAL_TIMER(tx_coal_timer),
HRTIMER_MODE_REL);
} else {
...
}
One possible interleaving:
CPU1 (stmmac_xmit, txq lock held)
stmmac_tx_timer_arm()
napi_is_scheduled(napi) returns false
<hardirq, or preempted on PREEMPT_RT>
CPU0 (stmmac_xdp_release)
stmmac_disable_all_queues() /* napi_disable() sets SCHED */
hrtimer_cancel(&tx_q->txtimer) /* nothing queued, returns */
CPU1
hrtimer_start(&tx_q->txtimer, ...)
CPU0
netif_tx_disable() /* waits for the txq lock, timer stays queued */
stmmac_xdp_set_prog() then calls stmmac_xdp_open() straight away, and
stmmac_xdp_open() does:
hrtimer_setup(&tx_q->txtimer, stmmac_tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
The coalesce timer defaults to 5ms and ethtool can raise it to 100ms, so
the stray timer is likely still queued at that point. Would re-initializing
a queued hrtimer corrupt the per-CPU hrtimer base?
Before this patch, netif_tx_disable() ran first, so in-flight xmits were
drained before the timers were cancelled.
The commit message says:
"Once NAPI is disabled, NAPI_STATE_SCHED stays set, so
stmmac_tx_timer_arm() takes the hrtimer_try_to_cancel() path and new
transmissions cannot re-arm the TX timers after hrtimer_cancel()."
This seems to hold only for transmissions that check the NAPI state after
napi_disable(). Would the order stmmac_disable_all_queues() ->
netif_tx_disable() -> hrtimer_cancel() close both this window and the
stmmac_tx_clean() one?
> +
> /* Free the IRQ lines */
> stmmac_free_irq(dev, REQ_IRQ_ERR_ALL, 0);
>
[Severity: Medium]
Disabling NAPI first stops the wake in stmmac_tx_clean(). Is there still a
second waker in the window between netif_tx_disable() and
stmmac_free_irq()?
stmmac_tx_err() also calls netif_tx_wake_queue(). It runs from the hard
IRQ handlers stmmac_dma_interrupt() and stmmac_msi_intr_tx() when the
status is tx_hard_error:
stmmac_main.c:stmmac_tx_err() {
...
stmmac_start_tx_dma(priv, chan);
priv->xstats.tx_errors++;
netif_tx_wake_queue(netdev_get_tx_queue(priv->dev, chan));
}
The IRQ lines stay requested until stmmac_free_irq(), which now runs after
netif_tx_disable(). stmmac_xdp_release() never sets STMMAC_DOWN, so the
STMMAC_DOWN check in stmmac_msi_intr_tx() does not filter this either.
Suppose the DMA reports TPS or FBE in that window. The queue is woken
again and TX DMA is restarted. Could the NET_TX softirq then call
stmmac_xmit() while stmmac_stop_all_dma() and free_dma_desc_resources()
are freeing the descriptor ring and tx_skbuff/tx_skbuff_dma?
The trigger needs a fatal bus error or a transmit-process-stopped status in
this window, so it is narrow. __stmmac_release() has the same
netif_tx_disable() -> stmmac_free_irq() window. It is still the same
failure the commit message describes: the queue restarts after
netif_tx_disable() and ndo_start_xmit() runs during ring teardown.
[Severity: High]
This isn't a bug introduced by this patch, but it is the ndo_xdp_xmit()
race the v2 changelog mentions. Can stmmac_xdp_xmit() write into the TX
rings that free_dma_desc_resources() is freeing here?
On program removal, stmmac_xdp_set_prog() does:
if (!prog)
xdp_features_clear_redirect_target(dev);
need_update = !!priv->xdp_prog != !!prog;
if (if_running && need_update)
stmmac_xdp_release(dev);
Nothing waits for a grace period between these two calls.
stmmac_disable_all_queues() only calls synchronize_rcu() when an RX queue
has an xsk_pool.
Another device's NAPI may already have passed the feature check in
__xdp_enqueue() and queued frames in a devmap bulk queue. When it flushes
through bq_xmit_all() -> stmmac_xdp_xmit(), the only gate is:
if (unlikely(test_bit(STMMAC_DOWN, &priv->state)))
return -ENETDOWN;
stmmac_xdp_release() never sets STMMAC_DOWN. stmmac_xdp_xmit() also takes
__netif_tx_lock() without checking whether the queue is stopped, so
netif_tx_disable() does not fence it.
stmmac_xdp_xmit_xdpf() then writes into tx_q->dma_tx and
tx_q->tx_skbuff_dma. __free_dma_tx_desc_resources() releases that memory
with dma_free_coherent() and kfree().
The v2 changelog already says this will be handled separately.
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261105053916.22353-1-muhammad.nazim.amirul.nazle.asmade%40altera.com
Technical Details
Message-ID:
<179420362880.994134.12466150409496809199@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359037-linux-kernel-netdev=dewy.ruReferences:
<20261105053916.22353-1-muhammad.nazim.amirul.nazle.asmade@altera.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359037-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2] net: stmmac: Disable queues before netif_tx_disable in xdp_release Date: Mon, 09 Nov 2026 05:53:48 +0000 Organization: Usenet Network Message-ID: <179420362880.994134.12466150409496809199@kernel.org> References: <20261105053916.22353-1-muhammad.nazim.amirul.nazle.asmade@altera.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="283716"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:v85hbHvOB6cSRGbcOJKABhdnmgg= sha256:ab7XdqDGsdmLG/qRmt0lzggQUF4ze79jvpZHcb9MKmg= sha1:an4kZjaRwgauiMUYWeuUZlbJvzU= sha256:9icbEzyt5KfSIWiBTgDTYBE6ay7mtkP1fIdT3vBN9+A= 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 7E5881136E4; Mon, 9 Nov 2026 08:54:47 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, 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 A772vygKTUgM; Mon, 9 Nov 2026 08:54:39 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359037-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id D422D113691; Mon, 9 Nov 2026 08:54:28 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 301D0658C0; Mon, 9 Nov 2026 05:54:02 +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=1794203642; b=j2Tmosbl8TqthZZnt5X/xi5x0nwD29tnMzYO0zcYsJL5phitywCtm8HE7AaEE2WBR/gZ vGM3M2Bl8SW2+mGqVBvfKBJsVrSSi0zmWtDoVkgwmLqbuYHz0iJXuw3B1Ywvw0gjqIHPj TKK7BIn3NWjoULOo1uTPHLqaJ6TtZErBfKpgnI7nvgoscWZNbQhfmpLdtFBCWY3PMXQPi SRN5M8+RRhD/LYycyyTxU41yIejylfEawcLQ0KByuIAYnUhUyaW4EJsfT2uFhHE1yT9mP 2rnOwfTTuKS4AaUdLbQAnvWQBKaGIczTup5ziCVk2pfdXZboVPwTx+a3FqW8tk5w/rA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794203642; 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=W1mfR/+JXbp1hpCZu9HuoqLOwrMsPqWR8ZMYk9Ds6Ng=; b=CV3mMbfykM5TkNOzxa8q87z2P00/5URBoRB/AiCINdj2jzsNGsz/t+nCnpAdmvv0G7PB gb4/HSFhqe34T+TxGBezuDd7SRBjp4OILdu8t7ahvkNXdZN4mLvfL3HX9HhKWnEa6uE5W 81YmbM+9SkGxS5nBoOBTj4BVaUrjPOF8UgSeIaA0u5tHrMqMR1R6TPhHqqHWGLXUoQLvu toWyNKQ+R92oorZugbTF9AOwLWhVAIiP+Y6RKuHMphSOHdn+ho1TZMyK6+M5lfdKJua5o iMcLZVVuRpYeSLvaLMRrlhit3qT9gtn+8eJwm/15CX38idQFMEHzg29wb+Tl6rNLkGQ== 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=ijlKxu8n; 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 076AA606A32A; Mon, 9 Nov 2026 05:54:02 +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=ijlKxu8n 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=1794203631; b=ZCFRYO/6Ylv4B/DgXL6rgzSF51Z1aFPJhPrsq+dcqmVOnQbC+Npzj+I5GeuyA+v2iDkL ZveoGZ1x2M92GVF33MNdDHZf/fDA32MERt7iFpgNc0bDHeVJOHAfSBArVRPC7mU+qXmtK o02xHStcA8lf2sj2AZSpk4lDyiUDEUz/kngvt0j5AprJtcwVBlS1COpQVgvKKmGRZprSy j9j6bfk+WAqrKC+4WQIkjACjKJcacDC3JYQZTrn7SnssCi2+QrhVFh5pkdZsjdnYkHxbT SCAYk7FtV3gb2W4d1HqGBmq2P9MkUrZegFsiDuVsiWPmRPL1XARrsYXiaaILjGsFVuA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794203631; 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=W1mfR/+JXbp1hpCZu9HuoqLOwrMsPqWR8ZMYk9Ds6Ng=; b=4BMgLEiYnPyCwvqxwntCdA219LM38X27Gd2Eqf4zbwWBo9FQv+R/Tcqf6lLuejNk5Eik HyWwjIYSOiP9mKHKGv+lVxMi/TaDeHxfd8uXRUQ407F/VUvQdL5UXh6k4RNyOMxKJFclA ljti8dE34BC+eDYZA/7mwvz3u8jZoFnb84azkl/Pb1g1DT4dkbqOxzaXEkK93bTpiO4e+ QxRzhh9KvbxL3RSw2g6QiTA/F+87YHCLeJGy+ctr6PTkdyMFr/n78+r3yjCodC6qqP4Wk JkOaSdHM9o52B5eZ5KwQH43p4NU+Xq+W3s0vAtQYgctrko0qlYVwc/4rD/Cg5xJraLg== 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=ijlKxu8n; 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 CAFAF606A31C; Mon, 9 Nov 2026 05:53:50 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 459FF1F0089F; Mon, 9 Nov 2026 05:53:49 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794203630; bh=W1mfR/+JXbp1hpCZu9HuoqLOwrMsPqWR8ZMYk9Ds6Ng=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=ijlKxu8n/cdoHYoaEVAKvBG2RpOt+W23Lb9OFOL3uAySOP2c4vvmvXKKsfHW4RbVB 9yk5/JkSPA1SQm21DI37LVMJGSnoL1NyCehVi4f8LG5XsYpXEUFvhyrVuez2mbzdel hpy3vnYy4Gf6eS9HTrZEV2hOZxLuNWRj2q0fhkrhZAjBTSTWocr6prPkZBGi1gVyG3 XvMgEPU5KoeCey2RYtUrg2vSwDrWmTqkM/Fo0jhMx/ayNBz0gw8ihXy15ARQJiMzkM osdowQDUTqaumgEdN4QGi3toLKjsoVBDOidmdJHmfIKoMau6rKuGsyfp1wa1mgo1OU wb/gdwnXuc9Jg== X-Cc: netdev@vger.kernel.org, kuba@kernel.org, maxime.chevallier@bootlin.com, ansuelsmth@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com, 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, faizal.abdul.rahim@intel.com, noor.azura.ahmad.tarmizi@intel.com, yoong.siang.song@intel.com, rohan.g.thomas@altera.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org X-In-Reply-To: <20261105053916.22353-1-muhammad.nazim.amirul.nazle.asmade@altera.com> X-sashiko-severity: High 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