From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=54.243.244.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796352013; b=F/+gtoIFHWVIdRw5bANk+WSqFtSW84rCOTI1wkzmJiKcrODR9XzBT1ARdVNUu5AEBe8u T8FMRnWIgkewqhWRPMJfIbLe/SKQ6CjQfJ55k4IJ/yw+w4/7T+fFJPAs5nmqCpi/SqZ3U PY9yj56qXfR5mRNJ82uMIaMt2GldNT3koTQorftYtKU+8Flqnfrw14ytRHDktqSRRPIUv oC3IDxGQfcrfWHBEC+vKsULHGzaGiWFaHrhAScLwUvzC9QBeHY+N5i8s6zEQ9Tpf4K5b7 lT6AUQfBm1tPJBlhVQNZLdw7NgmxJB+HNHGcFiBy9bdE6lHnnoEudEAO/41tb3Uecog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796352013; h=DMARC-Filter:DKIM-Signature:X-QQ-mid:X-QQ-Originating-IP:Received: X-QQ-SSF:X-QQ-GoodBg:X-BIZMAIL-ID:EX-QQ-RecipientCnt:From:To:Cc: Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding:X-QQ-SENDSIZE:Feedback-ID:X-QQ-XMAILINFO: X-QQ-XMRINFO:X-QQ-RECHKSPAM; bh=VFxsW1ios6D4kotlRkFu9wj/UnWpHu2nNTFkusTj0IA=; b=fuViAyUdqwwtLTtWMExmFYQQ+JCmG9irM/IFRLeGQo8twFFsf9yoPy1uaOWh+piqJZMH perJrZo3nd5CbXxVgVHxEbAJCRX4We6dM5fzoxemhdz8f8VWwtbgoUHN97QKAYh7B5kJB AS0my9lkUDic6qudG5wjCuafbh6vwZ1kBwTFfDBbaIHDMO0lJEvUG6XXutALD3VHWGIue 0FuZKTpXkpinxwy2vx9tSymvNeI3tyKyxp2MUKyLN46kOb4wGhLz/ZiEr7tkXWYMC3IuD HeIEchj4zdJdWY4rvKtlgiJTMkURK7BrXaVW6X/jjnL1toN06BuIWMfED9tywLBZ93w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=ugreen.com; spf=pass smtp.mailfrom=ugreen.com; dkim=pass header.d=ugreen.com header.i=@ugreen.com header.a=rsa-sha256 header.s=pkvm2402 header.b=qfQgqUVV; arc=none smtp.remote-ip=54.243.244.52 Received: from smtpbguseast3.qq.com (smtpbguseast3.qq.com [54.243.244.52]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AB09606A339 for ; Fri, 4 Dec 2026 02:40:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8AB09606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ugreen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ugreen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=ugreen.com header.i=@ugreen.com header.a=rsa-sha256 header.s=pkvm2402 header.b=qfQgqUVV DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ugreen.com; s=pkvm2402; t=1796351825; bh=VFxsW1ios6D4kotlRkFu9wj/UnWpHu2nNTFkusTj0IA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=qfQgqUVVOuD8MiMNCXJQkX5bpl/lXq2NvbQs7INs3xg2UtEnMgQkRftVEM2s4davu a7VHfwqoLlYEs6lz/lhhWoPEnh6ESnzexp3euILgTTo+TaSCDbNnQ2pCsJESOpS836 OjtPIxImAf+ctgtn57zhtzWE4zkeauduEwcC5i0U= X-QQ-mid: zesmtpgz9t1796351811t6c91a9ea X-QQ-Originating-IP: vvFPkFg66DJhxFeIJYNLJBJvq4cmHfDpHoVob3tPdvo= Received: from localhost.localdomain ( [121.34.63.119]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 04 Dec 2026 10:36:45 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 2069383893636607505 EX-QQ-RecipientCnt: 9 From: "swing.chen" To: netdev@vger.kernel.org Cc: hanson.wang@ugreen.com, Heiner Kallweit , nic_swsd@realtek.com, Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [RFC PATCH net] r8169: order TX completion reads after observing cur_tx Date: Fri, 4 Dec 2026 10:36:42 +0800 Message-Id: <20261204023642.2933576-1-swing.chen@ugreen.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: zesmtpgz:ugreen.com:qybglogicsvrgz:qybglogicsvrgz5b-1 X-QQ-XMAILINFO: NYaClDVrQHFLaJidhD4rF3moUUUUk4qtDewfZ1nal+ZXk7k2MqDWZQnC sd0FCskXXY6tQ4hItJR3ztmgfg7LV/YUTh2Ywes55MOwTmPKXtOIgQwdrk0lIVBFZh6ON4B 4naYg3UAuDscCCY2+q54lu7HArEsDGgVLivoWhtG9bSZqZG3PoS4Vkuz60YGtkT1wXJUWxf xKQw0oe3m8CqgaImrDsiCHM2jKRm1W58TRi5cbJl++Umr1AlmtXam7EMoFUZv+MjL7u7R8z d4tM01Av9FzBEvFLsAc0MIZkWHqPpG0r0pG3u9osozyOaANemjJG86ho8nQhKyW9zu5f51A T3atG6MTr3zO4cc/IhmHfXz0iGdx0tWYkAkOhjrIRCd5qseqyk8uGA7AEQq7BJD8/22tFRu 1xkBEaFy7jPRn4dB/fMdJJRkbDBGOYyMhE4H8AlDLU7NIOInlcgb0/4kJMXSkZNYE+T24Y0 kFXMpBeCOW0F2EEq/6EeXDw7kBGPWebRvrJBznwbZnUNe7kw//SD6ztL5/vYUyGT+mUDLDg O9mc/dST8FBCpcsrd52ZGjl8AoNA4CY3koqCLc7TRd2cpIfKXkaj923N1gFlVKgDX40ip+X OPhwZUcOKCzR+Qn/YOA13zB3y67l5gWLubhdvq7WNbckUnqwKYyGF4Ra6zCQjc1P9p5hPRU if9DbUHvGDl0usHCuckOXZvS4fV56lXWisaG9BpOPvnf3XH1hUwVPCKmR3B4/iW6U3d1/PY iefAAmTFslNY6hRbL9v7OXc5ZZJh6lTB508adA37rvrY52y0i1QVxPwbmS4GWzNazRMzjFu 8ywEMS8AXTt8+fD4dYzfxZ1AtQDcY+1e4tJi2fn/FlSUb7x7plwXvsodj+SrBOs9WEPrIkm uGT4Lu2weZzDSCkxdLdehmcy4AUj38w6VBizMtTZFuOnmrRxb1dGq5ICokNcPnXQROMtjVm nrdQoON4xoj8sQonRw8sFYqVpYpdSAUHDF20xb1EgPw1P+4NledYZhjkYNUgWRwStrlh0PK 9aj7B/jMEvbu3/wUlwq6MJ9dIx2qg= X-QQ-XMRINFO: Nq+8W0+stu50tPAe92KXseR0ZZmBTk3gLg== X-QQ-RECHKSPAM: 0 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 --- 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