๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by Vlad Banea Wed, 25 Nov 2026 02:26
[PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt
#22251
Author: Vlad Banea
Date: Wed, 25 Nov 2026 02:26
63 lines
12813 bytes
With the vector-map interrupt model, the TX interrupt can arrive before
the descriptor write-back is visible to the CPU. rtl_tx() then stops at
a descriptor that still looks owned by the chip, and completed packets
stay unreaped until BQL stops the queue and the watchdog resets the
chip. The legacy handler is not affected because it reads IntrStatus
before polling.

If the first pending descriptor still looks owned, read a register,
which makes the write-back visible, and check it once more.

Fixes: 677f8f8c4c5f ("r8169: add support for new interrupt mapping")
Signed-off-by: Vlad Banea <montrealtango@gmail.com>
---

Notes:
    Javen Xu confirmed that the RTL8127A, the chip upstream uses this
    interrupt model for, is affected:
    https://lore.kernel.org/netdev/d672fb6d16b04fb4a1c9b3202d276662@realsil.com.cn/
    
    This was patch 1 of the RTL8125B RSS RFC; the rest follows for net-next.
    Since the RFC, the second read is a continue instead of a repeated read.
    RFC: https://lore.kernel.org/netdev/20261111220114.3863505-1-montrealtango@gmail.com/

 drivers/net/ethernet/realtek/r8169_main.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index f151ab681393..76b96f31017d 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));
-		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);
+			continue;
+		}
 
 		skb = tp->tx_skb[entry].skb;
 		rtl8169_unmap_tx_skb(tp, entry);

base-commit: 846a6d0982be30aaba5268aac14a0c557d70cc23
-- 
2.53.0
Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt
#22257
Author: netdev-bot+sinfo
Date: Wed, 25 Nov 2026 02:32
19 lines
8442 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt
#22268
Author: Vlad Banea
Date: Wed, 25 Nov 2026 02:45
13 lines
12266 bytes
Tested on two RTL8125B (XID 641, firmware rtl8125b-2_0.0.2 07/13/20)
connected back to back, in an x86_64 KVM guest with VFIO passthrough.
Upstream uses the vector-map interrupt model only on the RTL8127A, which
I don't have, so the test kernel also had the RTL8125B RSS series from
the RFC to enable it on these chips. Without the fix, bursty TCP traffic
hit TX timeouts (17 and 6 in two runs of 30 bursts); with it, none, and
sustained traffic ran at 2.36 Gbit/s with no retransmits. The same fix
was also tested on a RISC-V board (SpacemiT K1) with two RTL8125B.

Javen Xu confirmed that the RTL8127A is affected as well.

Vlad
Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt
#24052
Author: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 03:14
168 lines
13880 bytes
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
Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt
#24155
Author: Vlad Banea
Date: Sun, 29 Nov 2026 13:40
26 lines
12881 bytes
> - [Medium] The patch may leave the same race open on the RX side.

RX was checked separately with a TCP request/response test that leaves
gaps between requests, so a frame stranded at the end of a burst would
only be picked up by the sender's loss probe: no stranded descriptors in
20000 receive bursts. v2 says so in the commit message.

> - [Low] The flush read added to rtl_tx() is `RTL_R8(tp,
>   IMR_CLEAR_VEC_MAP_REG)`, an 8-bit read of register 0x0d00.

v1 read IMR_CLEAR_VEC_MAP_REG because that is the read Realtek's own
driver does in the same place, and I kept it as is. Any register read
works here, though: with the burst test that showed 19 TX timeouts in
31 bursts without the fix, reading ISR_VEC_MAP_REG and rtl_pci_commit()
(ChipCmd) both gave none. rtl_pci_commit() is documented for committing
a preceding write, not read. So v2 reads ISR_VEC_MAP_REG, the vector-map
counterpart of the IntrStatus read in the legacy handler.

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

Agreed that it is independent of this fix. I can send a separate patch
adding the read barrier if that is wanted.

pw-bot: cr
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads