mirror of https://lore.kernel.org/lkml/
 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, stable@vger.kernel.org
Subject: Re: [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error
Date: Sat, 21 Nov 2026 23:18:38 +0000	[thread overview]
Message-ID: <179530311840.3135.8141689247648916052@kernel.org> (raw)
In-Reply-To: <20261117225521.19689-3-federico@rimpianto.com>

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

Critical: 0 · High: 0 (2) · 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] In atl1c_clean_rx()
  (drivers/net/ethernet/atheros/atl1c/atl1c_main.c), the RRD valid bit…

Pre-existing issues:
- [High] This patch adds a new schedule_work(&adapter->common_task) call
  (atl1c_clean_rx(), line 1939) in NAPI context.
- [High] The reset branch of atl1c_common_task() (lines 363-367) calls
  atl1c_down()/atl1c_up() without rtnl_lock and without taking…

--

net: atl1c: free the RX buffer when the descriptor reports an error

With this patch, atl1c_clean_rx() unmaps and frees the skb for RRDs that
report RRS_RX_ERR_SUM or RRS_802_3_LEN_ERR. Before, those buffers leaked.
Each RRD's RFD count and index are now checked against
rfd_ring->next_to_clean, and a mismatch schedules an adapter reset. The
RRD ring is also zeroed in atl1c_clean_rx_ring().

> diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
> index e9baee8fa7e5e..5d00f2489d154 100644
> --- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
> +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
> @@ -933,8 +933,9 @@ static void atl1c_clean_rx_ring(struct atl1c_adapter *adapter, u32 queue)
>  		buffer_info = &rfd_ring->buffer_info[j];
>  		atl1c_clean_buffer(pdev, buffer_info, 0);
>  	}
> -	/* zero out the descriptor ring */
> +	/* zero out the descriptor rings */
>  	memset(rfd_ring->desc, 0, rfd_ring->size);
> +	memset(rrd_ring->desc, 0, rrd_ring->size);
>  	rfd_ring->next_to_clean = 0;
>  	rfd_ring->next_to_use = 0;
>  	rrd_ring->next_to_use = 0;

[ ... ]

> @@ -1914,47 +1909,59 @@ static int atl1c_clean_rx(struct napi_struct *napi, int budget)
>  		if (work_done >= budget)
>  			break;
>  		rrs = ATL1C_RRD_DESC(rrd_ring, rrd_ring->next_to_clean);
> -		if (likely(RRS_RXD_IS_VALID(rrs->word3))) {
> -			rfd_num = (rrs->word0 >> RRS_RX_RFD_CNT_SHIFT) &
> -				RRS_RX_RFD_CNT_MASK;
> -			if (unlikely(rfd_num != 1))
> -				/* TODO support mul rfd*/
> -				if (netif_msg_rx_err(adapter))
> -					dev_warn(&pdev->dev,
> -						"Multi rfd not support yet!\n");
> -			goto rrs_checked;
> -		} else {
> +		if (!RRS_RXD_IS_VALID(rrs->word3))
> +			break;
> +
> +		rrs_word0 = le32_to_cpu(rrs->word0);

[Severity: Medium]
Should there be a dma_rmb() between the RRS_RXD_IS_VALID() test on word3
and the read of word0 here?

The notes after the commit message say the missing barrier is
pre-existing and will be fixed in a separate patch. Before this patch, a
stale word0 only made one poll stop early. Now the RFD count and index
taken from word0 decide whether ATL1C_WORK_EVENT_RESET is scheduled, and
that runs atl1c_down()/atl1c_up() from atl1c_common_task().

On weakly ordered CPUs such as arm64 and powerpc, the control dependency
on the word3 test does not order the later word0 load. So word0 can be
read before the device's RRD write is visible.

The RRD ring is zero after open, because dma_alloc_coherent() zeroes it.
With the memset added to atl1c_clean_rx_ring() above, it is also zero
after every reset. On the first lap after open or reset, a stale word0
would then be 0 and give rfd_num == 0, which hits:

	if (unlikely(rfd_num != 1 ||
		     rfd_index != rfd_ring->next_to_clean ||
		     !buffer_info->skb)) {
		...
		set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event);
		schedule_work(&adapter->common_task);

Could this produce a spurious "RRD out of sync" message and a full MAC
reset that drops the link? The reset zeroes the ring again, so the next
lap is exposed in the same way.

Without the memset, a stale word0 at slot k would still hold the
previous lap's value (count 1, index k) and pass the check.

Would a dma_rmb() right after the RRS_RXD_IS_VALID() test close this
window?

> +		rfd_num = (rrs_word0 >> RRS_RX_RFD_CNT_SHIFT) &
> +			RRS_RX_RFD_CNT_MASK;
> +		rfd_index = (rrs_word0 >> RRS_RX_RFD_INDEX_SHIFT) &
> +			RRS_RX_RFD_INDEX_MASK;
> +		buffer_info = &rfd_ring->buffer_info[rfd_ring->next_to_clean];

[ ... ]

> +		if (unlikely(rfd_num != 1 ||
> +			     rfd_index != rfd_ring->next_to_clean ||
> +			     !buffer_info->skb)) {
> +			dev_err_ratelimited(&pdev->dev,
> +					    "RRD out of sync: RFD count %u index %u, expected index %u%s; resetting\n",
> +					    rfd_num, rfd_index,
> +					    rfd_ring->next_to_clean,
> +					    buffer_info->skb ? "" : " (no buffer)");
> +			set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event);
> +			schedule_work(&adapter->common_task);

[Severity: High]
This isn't a bug introduced by this patch, but this schedule_work() is a
new producer for common_task that only napi_disable() can quiesce. Can
common_task be queued again after it has been cancelled, and then outlive
the adapter?

atl1c_close() cancels the work before atl1c_down() quiesces NAPI and the
IRQ:

atl1c_close() {
	set_bit(__AT_DOWN, &adapter->flags);
	cancel_work_sync(&adapter->common_task);
	atl1c_down(adapter);
	...
}

atl1c_down() {
	atl1c_del_timer(adapter);
	adapter->work_event = 0; /* clear all event */
	...
		napi_disable(&adapter->rrd_ring[i].napi);
	atl1c_irq_disable(adapter);
	atl1c_free_irq(adapter);
	...
}

An RX poll still running in this window that hits an out-of-sync RRD
sets ATL1C_WORK_EVENT_RESET and calls schedule_work() again. The existing
ISR_ERROR path in the interrupt handler and atl1c_link_chg_event() can do
the same.

atl1c_remove() then does:

	unregister_netdev(netdev);
	...
	free_netdev(netdev);

There is no cancel_work_sync() or flush_work() between the two. If the
worker has not run by then, the queued work_struct sits in freed
netdev_priv() memory. atl1c_common_task() would then run container_of()
and test_bit(__AT_DOWN, &adapter->flags) on freed memory.

Would a cancel_work_sync() once NAPI and the IRQ are quiesced avoid this?
That could go at the end of atl1c_close(), or in atl1c_remove() after
unregister_netdev().

[Severity: High]
This is a pre-existing issue, but this patch adds a new trigger (an
out-of-sync RRD) for the reset in atl1c_common_task(). The existing
triggers are tx_timeout and ISR_ERROR. Is that reset path serialized
against other callers of atl1c_down()/atl1c_up()?

atl1c_common_task() {
	if (test_bit(__AT_DOWN, &adapter->flags))
		return;

	if (test_and_clear_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event)) {
		netif_device_detach(netdev);
		atl1c_down(adapter);
		atl1c_up(adapter);
		netif_device_attach(netdev);
	}
	...
}

It takes neither rtnl_lock nor __AT_RESETTING. atl1c_change_mtu() runs
under rtnl and takes __AT_RESETTING before its own atl1c_down() and
atl1c_up(). Nothing keeps the two apart.

Suppose atl1c_change_mtu()'s atl1c_down() runs while common_task is
between napi_disable() and napi_enable(). The second napi_disable() takes
netdev_lock() and waits on NAPI_STATE_SCHED, which is already set.
common_task's napi_enable() then blocks on netdev_lock().

Can this deadlock while atl1c_change_mtu() holds rtnl?

Other interleavings look like they could unmap and free the same RX
buffers twice through atl1c_reset_dma_ring(). They could also call
free_irq()/request_irq() twice.

The previous patch in this series, "net: atl1c: wait for in-flight RX
polls before the link-down ring reset", describes the same
napi_disable()/netdev_lock() deadlock for the link-change work.

>  			break;
>  		}

[ ... ]

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

      reply	other threads:[~2026-11-21 23:18 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 ` [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset Federico Musto
2026-11-21 23:18   ` 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 [this message]

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=179530311840.3135.8141689247648916052@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 \
    --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

all inboxes | Powered by JetHome®