Netdev List
 help / color / mirror / Atom feed
From: "swing.chen" <swing.chen@ugreen.com>
To: netdev@vger.kernel.org
Cc: hanson.wang@ugreen.com, Heiner Kallweit <hkallweit1@gmail.com>,
	nic_swsd@realtek.com, Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [RFC PATCH net] r8169: order TX completion reads after observing cur_tx
Date: Fri,  4 Dec 2026 10:36:42 +0800	[thread overview]
Message-ID: <20261204023642.2933576-1-swing.chen@ugreen.com> (raw)

A UGREEN DH4300 Plus (RK3588C, arm64) repeatedly panicked while its
RTL8125B (XID 641) was transmitting. The link was up at 2.5 Gbit/s.
Pstore captured six distinct panics on this machine, all on vendor
kernel 6.1.84 (build d64bed19bdfd), with the same failure:

  kernel BUG at lib/dynamic_queue_limits.c:27!
  pc : dql_completed+0x13c/0x14c
  lr : rtl8169_poll+0x3a0/0x54c [r8169]

In each crash, the completion count exceeded the number of bytes BQL
had outstanding by exactly 60. In one case the driver reported 254
bytes complete with only 194 outstanding.

rtl8169_start_xmit() orders its stores before publishing cur_tx, but
rtl_tx() uses READ_ONCE() to read that index. This does not order the
subsequent reads of the descriptor and BQL state against the index
load on the completion CPU.

Publish cur_tx with smp_store_release() and pair it with an acquire
load in rtl_tx(). Also move BQL enqueue accounting before dma_wmb(),
ahead of the handoff of the first descriptor to the device. The device
still signals completion by clearing DescOwn.

With both changes applied to the vendor kernel, the same machine
continued transmitting without another DQL panic during the field
test. This result does not distinguish the two changes or establish
which one prevented the panic. On the net tree, r8169.o was cross-built
for arm64 with W=1 and BQL enabled. There is no mainline reproduction
or kernel selftest result to report.

Link: https://lore.kernel.org/netdev/20261118141130.2694997-1-hanson.wang@ugreen.com/
Signed-off-by: swing.chen <swing.chen@ugreen.com>
---
RFC question: would you keep the release/acquire pairing and leave BQL
accounting where it is? In the original code the accounting is already
before cur_tx is published. The field run tested the two changes together.
The vendor baseline also lacks c71e3a5cffd5 ("r8169: Fix possible ring
buffer corruption on fragmented Tx packets."); its contribution to the
field failures has not been ruled out.

Only the vendor build was run on hardware. The net tree was not booted
on the board; allyesconfig and allmodconfig builds were not run either.
CodeBuddy assisted with the port, the log analysis and the write-up.

 drivers/net/ethernet/realtek/r8169_main.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index 1da64c6e39e2..c09d0d8734fa 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -5118,17 +5118,15 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
 
 	skb_tx_timestamp(skb);
 
+	door_bell = __netdev_sent_queue(dev, skb->len, netdev_xmit_more());
+
 	/* Force memory writes to complete before releasing descriptor */
 	dma_wmb();
 
-	door_bell = __netdev_sent_queue(dev, skb->len, netdev_xmit_more());
-
 	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);
+	/* Publish descriptor, skb and BQL state to rtl_tx's acquire load. */
+	smp_store_release(&tp->cur_tx, tp->cur_tx + frags + 1);
 
 	stop_queue = !netif_subqueue_maybe_stop(dev, 0, rtl_tx_slots_avail(tp),
 						R8169_TX_STOP_THRS,
@@ -5232,7 +5230,8 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,
 
 	dirty_tx = tp->dirty_tx;
 
-	while (READ_ONCE(tp->cur_tx) != dirty_tx) {
+	/* Pairs with the release in rtl8169_start_xmit() before reclaim. */
+	while (smp_load_acquire(&tp->cur_tx) != dirty_tx) {
 		unsigned int entry = dirty_tx % NUM_TX_DESC;
 		u32 status;
 
-- 
2.34.1


                 reply	other threads:[~2026-12-04  2:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261204023642.2933576-1-swing.chen@ugreen.com \
    --to=swing.chen@ugreen.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hanson.wang@ugreen.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --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