mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: montrealtango@gmail.com
Cc: netdev@vger.kernel.org, hkallweit1@gmail.com,
	javen_xu@realsil.com.cn, nic_swsd@realtek.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt
Date: Sun, 29 Nov 2026 03:14:45 +0000	[thread overview]
Message-ID: <179592208502.3146.8715233436463560934@kernel.org> (raw)
In-Reply-To: <20261125022643.1169045-1-montrealtango@gmail.com>

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

Critical: 0 · High: 0 (1) · 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] The patch may leave the same race open on the RX side.
- [Low] The flush read added to rtl_tx() is `RTL_R8(tp,
  IMR_CLEAR_VEC_MAP_REG)`, an 8-bit read of register 0x0d00.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it sits in the
  loop the patch modifies.

--

r8169: recheck the TX descriptor after a vector-map interrupt

In vector-map interrupt mode (irq_nvecs > 1), this patch makes rtl_tx()
check the first pending TX descriptor a second time if it still looks
owned by the chip. Before the second check it reads IMR_CLEAR_VEC_MAP_REG
to make the descriptor write-back visible. The goal is to stop completed
packets from staying unreaped until the TX watchdog resets the chip.

> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index f151ab6813932..76b96f31017dd 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -5228,6 +5228,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,
>  		   int budget)
>  {
>  	unsigned int dirty_tx, bytes_compl = 0, pkts_compl = 0;
> +	bool recheck = tp->irq_nvecs > 1;
>  	struct sk_buff *skb;
>  
>  	dirty_tx = tp->dirty_tx;
> @@ -5237,8 +5238,17 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,
>  		u32 status;
>  
>  		status = le32_to_cpu(READ_ONCE(tp->TxDescArray[entry].opts1));

[Severity: High]
This isn't a bug introduced by this patch, but is a read barrier missing
between the cur_tx load and the opts1 load in rtl_tx()?

The producer side in rtl8169_start_xmit() does:

	txd_first->opts1 |= cpu_to_le32(DescOwn | FirstFrag);

	/* rtl_tx needs to see descriptor changes before updated tp->cur_tx */
	smp_wmb();

	WRITE_ONCE(tp->cur_tx, tp->cur_tx + frags + 1);

The consumer side in rtl_tx() does:

	while (READ_ONCE(tp->cur_tx) != dirty_tx) {
		unsigned int entry = dirty_tx % NUM_TX_DESC;
		...
		status = le32_to_cpu(READ_ONCE(tp->TxDescArray[entry].opts1));

Nothing on the reader side, such as smp_rmb() or smp_load_acquire(),
pairs with that smp_wmb(). The opts1 address depends only on the local
dirty_tx. The control dependency through the while condition does not
order a later load on arm64 or POWER.

On a weakly ordered CPU, can TX NAPI see the new cur_tx but still read
the zeroed opts1 that rtl8169_unmap_tx_skb() left on the previous pass?
DescOwn would then look clear, and rtl_tx() would treat a descriptor that
was just queued as completed. It would unmap the buffer and memset the
descriptor and the tx_skb slot. It would then call napi_consume_skb() on
an skb the NIC may still fetch, or leak the skb if the tx_skb load was
also stale. Finally it would advance dirty_tx past an entry that is still
in flight.

The new continue path reads both values again after the register read,
but they are still unordered relative to each other. Would an smp_rmb()
before the opts1 load, or smp_load_acquire(&tp->cur_tx), close this?

> -		if (status & DescOwn)
> -			break;
> +		if (status & DescOwn) {
> +			/* The vector-map TX interrupt can arrive before the
> +			 * descriptor write-back is visible. A register read
> +			 * makes it visible; look once more.
> +			 */
> +			if (!recheck)
> +				break;
> +			recheck = false;
> +			RTL_R8(tp, IMR_CLEAR_VEC_MAP_REG);

[Severity: Low]
Why read IMR_CLEAR_VEC_MAP_REG for the flush? Everywhere else in the
driver this register is only written, as a 32-bit write-1-to-clear mask
register:

rtl_irq_disable():
	RTL_W32(tp, IMR_CLEAR_VEC_MAP_REG, 0xffffffff);

rtl8169_disable_hw_interrupt_msix():
	RTL_W32(tp, IMR_CLEAR_VEC_MAP_REG, BIT(message_id));

This is the only read of it, at any width.

The driver already has a helper for this purpose:

static void rtl_pci_commit(struct rtl8169_private *tp)
{
	/* Read an arbitrary register to commit a preceding PCI write */
	RTL_R8(tp, ChipCmd);
}

The commit message compares this with the legacy IntrStatus read. In
vector-map mode the counterpart of that read would be ISR_VEC_MAP_REG,
not IMR_CLEAR_VEC_MAP_REG.

Is a byte read of this mask-clear register known to have no side effects
on every chip that uses vector-map mode? If Realtek did not specify this
register, could the patch use rtl_pci_commit() instead, or document why
this register was chosen?

> +			continue;
> +		}

[Severity: Medium]
Is the RX side open to the same race? The commit message blames the
vector-map interrupt model and says the legacy handler is safe because it
reads IntrStatus before polling.

The RX vectors use the same hard IRQ handler as TX. That handler only
does MMIO writes before it schedules NAPI:

rtl8169_interrupt_msix() {
	...
	rtl8169_disable_hw_interrupt_msix(tp, message_id);
	rtl8169_clear_hw_isr(tp, message_id);

	napi_schedule(napi);
	...
}

In rtl8169_poll_msix_rx()->rtl_rx(), the loop still stops at the first
owned descriptor and never checks it again:

	status = le32_to_cpu(rtl8169_rx_desc_opts1(tp, desc));
	if (status & DescOwn)
		break;

rtl8169_poll_msix_rx() then completes NAPI and re-enables the vector:

	if (work_done < budget && napi_complete_done(napi, work_done))
		rtl8169_enable_hw_interrupt_msix(tp, message_id);

If RX write-back can lag the MSI-X message the same way, the received
frame would stay in the ring until another frame raises a new RX
interrupt. Was RX checked for this? If RX is safe, could the commit
message say why?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125022643.1169045-1-montrealtango%40gmail.com

      parent reply	other threads:[~2026-11-29  3:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  2:26 Vlad Banea
2026-11-25  2:32 ` netdev-bot+sinfo
2026-11-25  2:45   ` Vlad Banea
2026-11-29  3:14 ` 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=179592208502.3146.8715233436463560934@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=javen_xu@realsil.com.cn \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=montrealtango@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --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

all inboxes | Powered by JetHome®