Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: federico@rimpianto.com
Cc: chris.snook@gmail.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v5 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset
Date: Sun, 29 Nov 2026 11:48:37 +0000	[thread overview]
Message-ID: <179595291724.3146.10471005923458447939@kernel.org> (raw)
In-Reply-To: <20261125113120.99743-2-federico@rimpianto.com>

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

Critical: 0 · High: 0 (2) · Medium: 1 · 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] When atl1c_rx_poll_sync() returns false (timeout, or
  __AT_DOWN), atl1c_check_link_status() returns at line 325, right after…
- [Low] The new comment above atl1c_rx_poll_sync() (lines 253-258), and
  the matching sentence in the commit message, say that…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch
  leaves it reachable: the link-down reset still frees TX buffers while…
- [High] This problem wasn't introduced by this patch, but the new
  __AT_DOWN gate does not close it.

--

net: atl1c: wait for in-flight RX polls before the link-down ring reset

This patch makes the link-change work item wait until NAPI_STATE_SCHED is
clear on every RX queue before atl1c_check_link_status() resets the MAC
and the DMA rings. The wait starts after netif_carrier_off() and an
smp_mb(). It is bounded, and it gives up if __AT_DOWN appears, in which
case the link-down reset is skipped. atl1c_up() passes false and does not
wait.

> diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
> index eddd8406867f7..afab3e16903ba 100644
> --- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
> +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
> @@ -248,7 +248,52 @@ void atl1c_reinit_locked(struct atl1c_adapter *adapter)
>  	clear_bit(__AT_RESETTING, &adapter->flags);
>  }
>  
> -static void atl1c_check_link_status(struct atl1c_adapter *adapter)
> +#define ATL1C_POLL_SYNC_TRIES 500
> +
> +/* atl1c_clean_rx() looks at the carrier only when it is entered.  A poll
> + * that passed that test before the carrier went off keeps walking the RRD
> + * ring.  NAPI_STATE_SCHED is held for the whole poll, and a poll that
> + * starts later sees the carrier off and returns without touching the
> + * rings, so once the bit is observed clear on every RX queue no poll is
> + * running and none can start.

[Severity: Low]
Is this description accurate? The commit message makes the same claim:

  "NAPI_STATE_SCHED is held for the whole poll, so observing it clear on
  every RX queue means no poll is running"

On every completion path, atl1c_clean_rx() calls napi_complete_done()
first, which clears NAPI_STATE_SCHED. Only after that does it write
REG_IMR:

quit_polling:
		napi_complete_done(napi, work_done);
		spin_lock_irqsave(&adapter->hw.intr_mask_lock, flags);
		adapter->hw.intr_mask |= atl1c_qregs[rrd_ring->num].rx_isr;
		AT_WRITE_REG(&adapter->hw, REG_IMR, adapter->hw.intr_mask);

Every poll takes this carrier-off quit path during the new wait.
atl1c_clean_tx() has the same tail. So the poll is still running, and still
writing a device register, after the bit being sampled has gone clear.

That write re-arms the mask that atl1c_common_task() cleared with
atl1c_irq_disable(). It does not check irq_sem. Two cases leave device
interrupts live during atl1c_reset_dma_ring() and atl1c_configure():

  - the write lands after the soft reset in atl1c_reset_mac();
  - atl1c_intr() runs (shared INTx or netpoll) and writes REG_ISR = 0.

New polls can also still start through IRQs, busy-poll or netpoll, which
contradicts "none can start". RX polls that start later return early once
they see the carrier off, so the RX ring argument still holds. The IMR
rewrite in the poll tail also predates this patch.

Could the comment and the commit message describe the guarantee more
narrowly?

[ ... ]

> +static bool atl1c_rx_poll_sync(struct atl1c_adapter *adapter)
> +{
> +	int i;
> +
> +	for (i = 0; i < adapter->rx_queue_count; ++i) {
> +		int tries = ATL1C_POLL_SYNC_TRIES;
> +
> +		while (test_bit(NAPI_STATE_SCHED,
> +				&adapter->rrd_ring[i].napi.state)) {

[Severity: High]
This is a pre-existing issue, but the patch leaves it reachable. Only
rrd_ring[i].napi is sampled here. Once this returns true, the link-down
path calls atl1c_reset_dma_ring(), which frees every TX buffer first:

	/* release tx-pending skbs and reset tx/rx ring index */
	for (i = 0; i < adapter->tx_queue_count; ++i)
		atl1c_clean_tx_ring(adapter, i);

atl1c_irq_disable() only calls synchronize_irq(). It does not wait for a TX
NAPI that is already scheduled or running on another CPU.

atl1c_clean_tx() has no carrier gate. It walks the same buffer_info[]
entries without a lock:

		atl1c_clean_buffer(pdev, buffer_info, budget);
		if (++next_to_clean == tpd_ring->count)
			next_to_clean = 0;
		atomic_set(&tpd_ring->next_to_clean, next_to_clean);

atl1c_clean_buffer() checks ATL1C_BUFFER_FREE, unmaps and calls
napi_consume_skb(). Only after that does it clear skb and dma.

Can atl1c_clean_tx() and atl1c_clean_tx_ring() both see the same entry as
live? That would mean a double DMA unmap and a double napi_consume_skb() of
the same skb. The poll could also write a stale next_to_clean back after
the reset has zeroed it.

The argument that "a poll that starts later sees the carrier off and
returns" holds for atl1c_clean_rx(), but not for atl1c_clean_tx().

The Fixes: commit 5e5c0964d9b9 added this reset specifically to release
pending TX skbs. The notes below the --- list the TX side as not addressed,
but those notes are dropped when the patch is applied. The second patch in
the series does not touch the TX side either.

Since this is tagged for stable, should the commit message say that the
TX half of the reset is still racy?

> +			if (test_bit(__AT_DOWN, &adapter->flags))
> +				return false;

[Severity: High]
This is a pre-existing issue, but does this check close the race with a
concurrent atl1c_down()?

__AT_DOWN is only tested while SCHED is observed set. If every RX SCHED
bit is clear when sampled, the function returns true without looking at
__AT_DOWN. Nothing rechecks it before atl1c_reset_mac() (which includes a
msleep(10)), atl1c_reset_dma_ring() and atl1c_configure().

atl1c_down() does:

	set_bit(__AT_DOWN, &adapter->flags);
	netif_carrier_off(netdev);
	for (i = 0; i < adapter->tx_queue_count; ++i)
		napi_disable(&adapter->tpd_ring[i].napi);
	for (i = 0; i < adapter->rx_queue_count; ++i)
		napi_disable(&adapter->rrd_ring[i].napi);
	...
	atl1c_reset_dma_ring(adapter);

Only atl1c_close() calls cancel_work_sync(&adapter->common_task) first.
These callers reach atl1c_down() while the work item may be running:

  - atl1c_change_mtu()
  - atl1c_reinit_locked() (ethtool)
  - atl1c_suspend()
  - PCI error recovery

The work item takes neither __AT_RESETTING nor RTNL.

Case one: atl1c_down() has set __AT_DOWN but has not yet disabled the RX
NAPIs, or it starts after the wait has returned true. Both contexts then
run atl1c_reset_dma_ring()->atl1c_clean_buffer() on the same buffer_info
entries. Could that double-free and double-unmap the skbs? The work item's
atl1c_configure() could also refill rings that the teardown is freeing.

Case two: a full down/up finishes inside that window.
atl1c_up()->atl1c_check_link_status(adapter, false) can turn the carrier
back on, then clear __AT_DOWN and call napi_enable(). A new RX poll would
then pass the carrier gate and walk the RRD/RFD rings while the work item
frees them.

The notes below the --- acknowledge the missing serialisation. The commit
body, though, presents the __AT_DOWN check as the answer to a concurrent
teardown.

Does this need real exclusion? One option is to take __AT_RESETTING or the
instance lock in the work item and recheck state under it. Another is to
have every atl1c_down() caller call cancel_work_sync() first.

> +			if (!tries--) {
> +				dev_warn_ratelimited(&adapter->pdev->dev,
> +						     "RX poll won't finish, skipping link-down reset\n");
> +				return false;
> +			}
> +			usleep_range(1000, 2000);
> +		}
> +	}
> +
> +	return true;
> +}

[ ... ]

> @@ -265,6 +310,20 @@ static void atl1c_check_link_status(struct atl1c_adapter *adapter)
>  	if (!link) {
>  		/* link down */
>  		netif_carrier_off(netdev);
> +		if (sync_polls) {

[ ... ]

> +			smp_mb();
> +			if (!atl1c_rx_poll_sync(adapter))
> +				return;

[Severity: Medium]
When atl1c_rx_poll_sync() returns false, this return skips the whole
link-down hardware sequence, not only the ring reset:

  - hw->hibernate = true
  - atl1c_reset_mac()
  - atl1c_set_aspm(hw, SPEED_0)
  - atl1c_post_phy_linkchg(hw, SPEED_0)
  - atl1c_reset_dma_ring()
  - atl1c_configure()

Nothing records that this work is still owed.

The next link-change event is normally a link-up. atl1c_link_chg_event()
has already set adapter->link_speed = SPEED_0, so the link-up branch runs
atl1c_set_aspm(), atl1c_post_phy_linkchg() and atl1c_start_mac() on a MAC
that was never stopped or reset. Would that leave TX descriptors pending in
the DMA engine, the condition 5e5c0964d9b9 was added to fix?

On msi_lnkpatch parts, the SPEED_0 branch of atl1c_post_phy_linkchg()
restores MIIDBG_SYSMODCTRL and MIIDBG_MSE16DB. That branch is skipped. The
link-up branch only rewrites those registers for SPEED_100, so a link that
comes back at 1000M would keep the 100M thresholds.

hw->hibernate also stays false while the link is down. On l2c_b2 and
l1d_2, atl1c_read_phy_core() and atl1c_write_phy_core() then use the fast
MDIO clock instead of MDIO_CTRL_CLK_25_128.

Under NAPI threaded busy-poll the timeout is not rare, it happens every
time. napi_complete_done() returns without clearing NAPI_STATE_SCHED while
NAPIF_STATE_IN_BUSY_POLL is set:

	if (unlikely(n->state & (NAPIF_STATE_NPSVC |
				 NAPIF_STATE_IN_BUSY_POLL)))
		return false;

In that mode every link-down sleeps about 0.5-1 s in the work item with
device interrupts masked, logs the warning and skips the reset. The commit
message only says "the rings are left untouched and the handler runs again
on the next link-change event".

Could the steps that don't touch the rings (hibernate, set_aspm(SPEED_0),
post_phy_linkchg(SPEED_0)) run before the wait? Alternatively, could the
skipped MAC/DMA reset be deferred, for example by setting
ATL1C_WORK_EVENT_RESET?

> +		}
>  		hw->hibernate = true;
>  		if (atl1c_reset_mac(hw) != 0)
>  			if (netif_msg_hw(adapter))

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125113120.99743-1-federico%40rimpianto.com

  reply	other threads:[~2026-11-29 11:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 11:31 [PATCH net v5 0/2] net: atl1c: fix the RX buffer leak on errored frames Federico Musto
2026-11-25 11:31 ` [PATCH net v5 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset Federico Musto
2026-11-29 11:48   ` netdev-bot+sashiko [this message]
2026-11-25 11:31 ` [PATCH net v5 2/2] net: atl1c: free the RX buffer when the descriptor reports an error Federico Musto
2026-11-29 11:48   ` 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=179595291724.3146.10471005923458447939@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=chris.snook@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=federico@rimpianto.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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