[PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset
From: Federico Musto
Date: Tue Nov 17 2026 - 17:56:40 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Federico Musto <federico@xxxxxxxxxxxxx>
---
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