๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24052

Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt

#24052
From: 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
Technical Details
Message-ID: <179592208502.3146.8715233436463560934@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373351-linux-kernel-netdev=dewy.ru
References: <20261125022643.1169045-1-montrealtango@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373351-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] r8169: recheck the TX descriptor after a vector-map interrupt
Date: Sun, 29 Nov 2026 03:14:45 +0000
Organization: Usenet Network
Message-ID: <179592208502.3146.8715233436463560934@kernel.org>
References: <20261125022643.1169045-1-montrealtango@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1090410"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9orMdEquCSzIB5i8Lgyer3oRyJ0= sha256:7iGw6DBjbRBRXkO/WOlmsBEqtrgtiIk3fdNEZzx0+IQ=
	sha1:2oP19NtvZoCkiCz3scruTXd1uEs= sha256:MLtnO0Yh2kZntQXhOuUxl+dnnIveBcDSCcinWIAzknw=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CF1F2125F8A; Sun, 29 Nov 2026 06:15:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ZApxUcpDFt99;
	Sun, 29 Nov 2026 06:15:05 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373351-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id CC706125F8C; Sun, 29 Nov 2026 06:14:56 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 150F526445; Sun, 29 Nov 2026 03:14:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795922092;
	b=eD8MBKNDmPIb6uJZXNMW2zYA+BIQmbViDbwhDKv4IqkKEjOhkpV6dcJhROiBuvaGHqyz
	 Bg3o65yAU7hkrSL03Kx6kW3NKto3kVS/A9xp/7h8feSldaP7yEiPaGvDybfhzT1N4KmHj
	 K6TyF2TtzY7u23I5QPGexycEl3wMAQ9lIxXgIJuwhRh5Ykp4PQITEXaWfnTAMkxRxMqie
	 Xon2QXRsHHnInMd2d5+BQVFhU5PESdqBfJlNhIn1yEZReAX+rETh4aY6WrlfKhnl2nany
	 QP29v7HBCKg5/8nGrnw9SZ2vdjVaLzRAIbhvlqR4NXPJhZnGGKdek2rNV+7uh+8SQ6g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795922092;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=pWlPTYBuhSoHgfN2IMpJc3dV7mlLsRTV6K0PAnKjPPA=;
	b=OEheXm+ZWpyXk+GUZeODCjPeAfDjv+9C2T4NjNH9do+b8Ek/1QDZhFUWH+vpWL07u0gX
	 /0Y6SAGgDHO24XO1EdGDRurR44/tdXuygn2dqGnGa9ZOx3ha39bAwAxrsQ3y3qKRhkQHb
	 Ne6Wuk/KK0uMetZyh4k89NASCDYiaDoPd8/Q+hFO+sqft7ftTHUc92tIAeXqBkWx/9BNd
	 47kESLt9pYW7kNFJRZR6gfLANFs1gguyv0DoicEI9vxHw9YuVMWoOhqi1/ogFInDahnvg
	 9H5525xEUfjlUTXhj0aeMrSk8GyWuzKr0P0VY6FLWx/rnyhkQpuzRQ6naQTECjQNQdw==
X-ARC-Authentication-Results: i=2; 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=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AF9D606A32D;
	Sun, 29 Nov 2026 03:14:52 +0000 (UTC)
X-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
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-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==
X-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==
X-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
X-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)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 785131F000C1;
	Sun, 29 Nov 2026 03:14:45 +0000 (UTC)
X-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==
X-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
X-In-Reply-To: <20261125022643.1169045-1-montrealtango@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list