From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795922086; b=ywNt4sN6S4ehq0cooIPjcqs0ir4A+qckVLCKNBzpP+p22wk9H+SAu7c6RILX5ZZyGyER red6/tb8IC9rvSHqWONhnBuZVTddem9REtclSajekfH8EEer3goCPJ87ohUGbHe4pVxaR PiRofkSB1CJtbGJetxI+8oqZLOnzDF1tzFxXfZyfnp2jUp51eu14gwyUoGywc1gptBo+f HvlGtCZ+TCFAwt/wM4DOr/v1Jaf6F42hJ07gEKJtoqe9E6CNLfYI9f9RXgEbwOYSL33GZ uLy6yAQxKbSH5NJSeBvy62AQ05/nsvchKLftYRBvJSsDHyYxmvZsXp+6Q3EMRjRdIXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795922086; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=pWlPTYBuhSoHgfN2IMpJc3dV7mlLsRTV6K0PAnKjPPA=; b=1nvVEJK7jg78Nl68PSOYyoxdpMtEhkhBF1+lxUcSJNG128m2Rx5yG+5XisRMqlLexF8e v1dd9kg2xs5p4QPjRaENPsWEUT4khGNH2Xl0yZVFaHO/TKMjKiwcN3Xs1wKdX5NWtP6Zz As+DKfMDcQSU3FBbWhCpNhtSW577zXRb3nvDpF1y5XvI6RlYNLvHGlU2wbfQIAWRLm2xr AxYFf9WcQnYhc4iF86JHxz01AjvstSVHWKNct4tH72FR0napp+F8m6W0L69gGG1Spq2fA 3RC3EsJjKPKzthsPhwh2xmkNyn2JxN2qRhk7OWxMQZmmBzKhGi152d0P6dMWT8BZECA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="fTWOk/rU"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65EA7606A31C; Sun, 29 Nov 2026 03:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fTWOk/rU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 785131F000C1; Sun, 29 Nov 2026 03:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795922086; bh=pWlPTYBuhSoHgfN2IMpJc3dV7mlLsRTV6K0PAnKjPPA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fTWOk/rU9rJ+GH04WtiuXrqmNpcarA29dsVvDUyhAzlKRSN1sAbPNCoB/wZJeIVvL nKDL2QnQ6aA2ZShfJpi6WDuHua7bGH7ZY3njqQ9CBNhR1p3pMPnvgvEd9uNY30esW4 szeqAy3YzkEjOwwQQ9rCYogfcz9PWwRdcd59QfvgkykKpdXXGy1G3cAbP/2nOqrjyn EvitxhFRQwNwmeqJXxH5dDfrS357BiKynkyaOFwVemWsAQuQRcyRFWuAhZ7hayGozm HC+bY8tGLRNcCaRlEE5x9HuHvrOr+HrCvXvzrUC6CwZerKQbBhp51vnPTNY0/L3B7M SSFVqDAC5j8gQ== Subject: Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt 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 Date: Sun, 29 Nov 2026 03:14:45 +0000 Message-ID: <179592208502.3146.8715233436463560934@kernel.org> In-Reply-To: <20261125022643.1169045-1-montrealtango@gmail.com> References: <20261125022643.1169045-1-montrealtango@gmail.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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