From: Federico Musto <federico@rimpianto.com>
To: Chris Snook <chris.snook@gmail.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Federico Musto <federico@rimpianto.com>,
stable@vger.kernel.org
Subject: [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset
Date: Tue, 17 Nov 2026 23:55:20 +0100 [thread overview]
Message-ID: <20261117225521.19689-2-federico@rimpianto.com> (raw)
In-Reply-To: <20261117225521.19689-1-federico@rimpianto.com>
When the PHY reports link down, the work item calls
atl1c_check_link_status(), which resets the MAC, frees every RX buffer and
zeroes the ring indices through atl1c_reset_dma_ring(), then posts fresh
buffers through atl1c_configure(). Nothing keeps the RX poll away while it
does so: atl1c_irq_disable() masks the device interrupt and waits for the
hard interrupt handler only, and atl1c_clean_rx() tests the carrier only
when it is entered. A poll that passed that test before the carrier went
off keeps walking the RRD ring on another CPU while the work item frees
the same buffers. Both can unmap and free the same skb, or the poll can
hand the stack an skb the work item has already freed.
Once the carrier is off, wait until no RX poll is in flight before
touching the rings. A poll that starts later sees the carrier off and
returns without looking at them, so NAPI does not have to be disabled.
napi_disable() is not used because it cannot be made safe here without
serialising the work item against atl1c_down() first: the two can run
concurrently (MTU change, ethtool, suspend), a second napi_disable() on an
already disabled NAPI sleeps holding the netdev instance lock, and the
napi_enable() of the first caller then blocks on that lock.
atl1c_check_link_status() is also called by atl1c_up() before
napi_enable(). For the same reason the wait gives up when the interface is
down: a disabled NAPI keeps NAPI_STATE_SCHED set, and atl1c_down() has
quiesced NAPI on its own.
Found by code inspection; the race has not been reproduced.
Fixes: 5e5c0964d9b9 ("atl1c: do MAC-reset when PHY link down")
Cc: stable@vger.kernel.org
Signed-off-by: Federico Musto <federico@rimpianto.com>
---
New in v4. The Sashiko review flagged this race on v2 and again on v3 of
the next patch: pre-existing, but made worse by a free in the same window.
Not addressed, both pre-existing: the TX side of the same reset
(atl1c_clean_tx() and atl1c_xmit_frame() against atl1c_clean_tx_ring()),
and the missing serialisation between the work item and the callers of
atl1c_down().
---
.../net/ethernet/atheros/atl1c/atl1c_main.c | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
index eddd8406867f..e9baee8fa7e5 100644
--- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
+++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
@@ -248,6 +248,26 @@ void atl1c_reinit_locked(struct atl1c_adapter *adapter)
clear_bit(__AT_RESETTING, &adapter->flags);
}
+/* atl1c_clean_rx() looks at the carrier only when it is entered. Once the
+ * carrier is off, wait for the polls that are already past that test, so
+ * that the link-down path can reset the RX rings. A poll that starts later
+ * sees the carrier off and leaves the rings alone.
+ *
+ * A disabled NAPI keeps NAPI_STATE_SCHED set, which is why this is not
+ * napi_synchronize(): stop waiting when the interface is down. atl1c_up()
+ * gets here before napi_enable(), and atl1c_down() quiesces NAPI itself.
+ */
+static void atl1c_rx_poll_sync(struct atl1c_adapter *adapter)
+{
+ int i;
+
+ for (i = 0; i < adapter->rx_queue_count; ++i)
+ while (test_bit(NAPI_STATE_SCHED,
+ &adapter->rrd_ring[i].napi.state) &&
+ !test_bit(__AT_DOWN, &adapter->flags))
+ usleep_range(1000, 2000);
+}
+
static void atl1c_check_link_status(struct atl1c_adapter *adapter)
{
struct atl1c_hw *hw = &adapter->hw;
@@ -265,6 +285,7 @@ static void atl1c_check_link_status(struct atl1c_adapter *adapter)
if (!link) {
/* link down */
netif_carrier_off(netdev);
+ atl1c_rx_poll_sync(adapter);
hw->hibernate = true;
if (atl1c_reset_mac(hw) != 0)
if (netif_msg_hw(adapter))
--
2.47.3
next prev parent reply other threads:[~2026-11-17 22:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 22:55 [PATCH net v4 0/2] net: atl1c: fix the RX buffer leak on errored frames Federico Musto
2026-11-17 22:55 ` Federico Musto [this message]
2026-11-21 23:18 ` [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset netdev-bot+sashiko
2026-11-17 22:55 ` [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error Federico Musto
2026-11-21 23:18 ` 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=20261117225521.19689-2-federico@rimpianto.com \
--to=federico@rimpianto.com \
--cc=andrew+netdev@lunn.ch \
--cc=chris.snook@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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