Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] r8169: clear RxOverflow before unmasking interrupts
@ 2026-11-21  7:36 Jure Rebernik
  2026-11-23 19:20 ` Jacob Keller
  2026-11-25  7:53 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Jure Rebernik @ 2026-11-21  7:36 UTC (permalink / raw)
  To: Heiner Kallweit, nic_swsd, netdev
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sunil Goutham, Jacob Keller, linux-kernel,
	Jure Rebernik, stable

When the RTL8125B runs out of RX descriptors it sets RxOverflow
(RxDescUnavail in the vendor driver) and stops receiving. It does not
start again when the driver returns descriptors to it, only when
RxOverflow is cleared in IntrStatus. Since commit 6994520a3328 ("r8169:
disable interrupt source RxOverflow") nothing may clear it:

 1. The ring fills. The chip completes the last frames (RxOK), then
    sets RxOverflow and stops receiving.
 2. rtl8169_interrupt() read IntrStatus before RxOverflow was set, so it
    clears only RxOK.
 3. NAPI empties the ring and unmasks the interrupts.
 4. The stopped receiver raises no new RxOK, and RxOverflow is not an
    interrupt source. Reception stays stopped, and every frame is
    counted in rx_missed, until another event such as TxOK makes the
    handler clear all status bits.

This was observed on a machine in real use: an RTL8125B (XID 641) on the
PCIe bus of an arm64 Qualcomm QCS8550, running v7.2.6 and receiving UDP
at 800 Mbit/s while sending nothing. Reception stopped for seconds and
a single transmitted packet restarted it. During each stop, a debugfs
dump added to a test build of the driver showed IntrMask 0x2f,
IntrStatus 0x50, NAPI idle and all 256 RX descriptors owned by the NIC,
and writing only RxOverflow to IntrStatus from user space, through the
sysfs PCI resource mapping and with nothing transmitted, restarted
reception in 17 of 17 stops. The order of steps 1 and 2 is inferred
from that state, not traced. Reproducing the stall itself needs no
kernel modification.

Clear RxOverflow in rtl8169_poll() once NAPI has emptied the ring, right
before unmasking. This restarts reception without making the "ring
empty" condition an interrupt source again.

Testing, on v7.2.6 with an RTL8125B and inbound UDP at 800 Mbit/s in
30 s runs:

 - A test build with a module parameter that switches between the old
   and the new behaviour on the same boot, 75 runs each:

     old: 9 runs lost more than 1000 datagrams, 1041366 lost in total
     new: no run lost more than 1000 datagrams, 846 lost in total and
          at most 184 in one run

   The 846 equal the NIC's rx_missed count over those runs. The NIC
   dropped them while the default 256-entry RX ring was briefly full;
   reception did not stop.

 - This patch as written, without the module parameter: no run of 20
   lost more than 1000 datagrams (166 lost in total due to the default
   256-entry RX ring). With the unchanged driver on the same day, 3 of
   10 runs did (237264 lost in total).

On this tree the patch was only built, not run; rtl8169_poll() is the
same here as in v7.2.

The investigation was done with an AI coding assistant (Claude Code):
it wrote the HIL test scripts, the debugfs instrumentation and the
register tools used above, proposed this change and drafted this
changelog. I reviewed the change and the evidence, and the test
results above come from runs on our hardware.

Fixes: 6994520a3328 ("r8169: disable interrupt source RxOverflow")
Cc: stable@vger.kernel.org
Signed-off-by: Jure Rebernik <jure.rebernik@luxonis.com>
---

Notes:
    v2:
    - Clear RxOverflow in rtl8169_poll() instead of making it an interrupt
      source again, as there should be no "ring empty" interrupt (Jakub)
    - Describe the race step by step
    - Same-boot A/B test results
    
    Keeping the v1 approach also fixes the stall: with RxOverflow in the
    unconditional init of tp->irq_mask, as Jakub suggested for v1, 0 of 76
    runs lost more than 1000 datagrams against 5 of 76 with the old mask.
    I can send that version instead if it is preferred.
    
    With the RX ring raised to 1024 entries, which this patch does not do,
    and v1 or v2 of this fix, 20 runs on two boards lost no datagrams at
    all.
    
    The patch changes only rtl8169_poll(), the single-vector path that
    RTL8125B uses. The multi-vector path added for RTL8127 after v7.3 has
    its own poll handlers and is not changed.
    
    v1: https://lore.kernel.org/netdev/20261101102720.702600-1-jure.rebernik@luxonis.com/

 drivers/net/ethernet/realtek/r8169_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index f151ab681393..99b0a410f58e 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -5670,8 +5670,14 @@ static int rtl8169_poll(struct napi_struct *napi, int budget)
 	/* rtl8169_poll() is used only when there is a single RX ring. */
 	work_done = rtl_rx(dev, tp, &tp->rx_ring[0], budget, napi);
 
-	if (work_done < budget && napi_complete_done(napi, work_done))
+	if (work_done < budget && napi_complete_done(napi, work_done)) {
+		/* After running out of RX descriptors the chip does not
+		 * receive again until RxOverflow is cleared. The ring is
+		 * empty now, so clear it before unmasking.
+		 */
+		rtl_ack_events(tp, RxOverflow);
 		rtl_irq_enable(tp);
+	}
 
 	return work_done;
 }
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] r8169: clear RxOverflow before unmasking interrupts
  2026-11-21  7:36 [PATCH net v2] r8169: clear RxOverflow before unmasking interrupts Jure Rebernik
@ 2026-11-23 19:20 ` Jacob Keller
  2026-11-25  7:53 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2026-11-23 19:20 UTC (permalink / raw)
  To: Jure Rebernik, Heiner Kallweit, nic_swsd, netdev
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sunil Goutham, linux-kernel, stable

On 11/20/2026 11:36 PM, Jure Rebernik wrote:
> When the RTL8125B runs out of RX descriptors it sets RxOverflow
> (RxDescUnavail in the vendor driver) and stops receiving. It does not
> start again when the driver returns descriptors to it, only when
> RxOverflow is cleared in IntrStatus. Since commit 6994520a3328 ("r8169:
> disable interrupt source RxOverflow") nothing may clear it:
> 
>  1. The ring fills. The chip completes the last frames (RxOK), then
>     sets RxOverflow and stops receiving.
>  2. rtl8169_interrupt() read IntrStatus before RxOverflow was set, so it
>     clears only RxOK.
>  3. NAPI empties the ring and unmasks the interrupts.
>  4. The stopped receiver raises no new RxOK, and RxOverflow is not an
>     interrupt source. Reception stays stopped, and every frame is
>     counted in rx_missed, until another event such as TxOK makes the
>     handler clear all status bits.
> 
> This was observed on a machine in real use: an RTL8125B (XID 641) on the
> PCIe bus of an arm64 Qualcomm QCS8550, running v7.2.6 and receiving UDP
> at 800 Mbit/s while sending nothing. Reception stopped for seconds and
> a single transmitted packet restarted it. During each stop, a debugfs
> dump added to a test build of the driver showed IntrMask 0x2f,
> IntrStatus 0x50, NAPI idle and all 256 RX descriptors owned by the NIC,
> and writing only RxOverflow to IntrStatus from user space, through the
> sysfs PCI resource mapping and with nothing transmitted, restarted
> reception in 17 of 17 stops. The order of steps 1 and 2 is inferred
> from that state, not traced. Reproducing the stall itself needs no
> kernel modification.
> 
> Clear RxOverflow in rtl8169_poll() once NAPI has emptied the ring, right
> before unmasking. This restarts reception without making the "ring
> empty" condition an interrupt source again.
> 
> Testing, on v7.2.6 with an RTL8125B and inbound UDP at 800 Mbit/s in
> 30 s runs:
> 
>  - A test build with a module parameter that switches between the old
>    and the new behaviour on the same boot, 75 runs each:
> 
>      old: 9 runs lost more than 1000 datagrams, 1041366 lost in total
>      new: no run lost more than 1000 datagrams, 846 lost in total and
>           at most 184 in one run
> 
>    The 846 equal the NIC's rx_missed count over those runs. The NIC
>    dropped them while the default 256-entry RX ring was briefly full;
>    reception did not stop.
> 
>  - This patch as written, without the module parameter: no run of 20
>    lost more than 1000 datagrams (166 lost in total due to the default
>    256-entry RX ring). With the unchanged driver on the same day, 3 of
>    10 runs did (237264 lost in total).
> 
> On this tree the patch was only built, not run; rtl8169_poll() is the
> same here as in v7.2.
> 
> The investigation was done with an AI coding assistant (Claude Code):
> it wrote the HIL test scripts, the debugfs instrumentation and the
> register tools used above, proposed this change and drafted this
> changelog. I reviewed the change and the evidence, and the test
> results above come from runs on our hardware.
> 
> Fixes: 6994520a3328 ("r8169: disable interrupt source RxOverflow")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jure Rebernik <jure.rebernik@luxonis.com>
> ---

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

> 
> Notes:
>     v2:
>     - Clear RxOverflow in rtl8169_poll() instead of making it an interrupt
>       source again, as there should be no "ring empty" interrupt (Jakub)
>     - Describe the race step by step
>     - Same-boot A/B test results
>     
>     Keeping the v1 approach also fixes the stall: with RxOverflow in the
>     unconditional init of tp->irq_mask, as Jakub suggested for v1, 0 of 76
>     runs lost more than 1000 datagrams against 5 of 76 with the old mask.
>     I can send that version instead if it is preferred.
>     
>     With the RX ring raised to 1024 entries, which this patch does not do,
>     and v1 or v2 of this fix, 20 runs on two boards lost no datagrams at
>     all.
>     
>     The patch changes only rtl8169_poll(), the single-vector path that
>     RTL8125B uses. The multi-vector path added for RTL8127 after v7.3 has
>     its own poll handlers and is not changed.
>     
>     v1: https://lore.kernel.org/netdev/20261101102720.702600-1-jure.rebernik@luxonis.com/
> 
>  drivers/net/ethernet/realtek/r8169_main.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index f151ab681393..99b0a410f58e 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -5670,8 +5670,14 @@ static int rtl8169_poll(struct napi_struct *napi, int budget)
>  	/* rtl8169_poll() is used only when there is a single RX ring. */
>  	work_done = rtl_rx(dev, tp, &tp->rx_ring[0], budget, napi);
>  
> -	if (work_done < budget && napi_complete_done(napi, work_done))
> +	if (work_done < budget && napi_complete_done(napi, work_done)) {
> +		/* After running out of RX descriptors the chip does not
> +		 * receive again until RxOverflow is cleared. The ring is
> +		 * empty now, so clear it before unmasking.
> +		 */
> +		rtl_ack_events(tp, RxOverflow);
>  		rtl_irq_enable(tp);
> +	}
>  
>  	return work_done;
>  }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2] r8169: clear RxOverflow before unmasking interrupts
  2026-11-21  7:36 [PATCH net v2] r8169: clear RxOverflow before unmasking interrupts Jure Rebernik
  2026-11-23 19:20 ` Jacob Keller
@ 2026-11-25  7:53 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25  7:53 UTC (permalink / raw)
  To: jure.rebernik
  Cc: hkallweit1, nic_swsd, netdev, andrew+netdev, davem, edumazet,
	kuba, pabeni, sgoutham, jacob.e.keller, linux-kernel, stable

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 2

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).

- [High] In rtl8169_poll()
  (drivers/net/ethernet/realtek/r8169_main.c:5673-5680), RxOverflow is…
- [Low] The changelog says "On this tree the patch was only built, not
  run; rtl8169_poll() is the same here as in v7.2." That is wrong.
- [Low] r8169_init_napi() registers rtl8169_poll() for every device with
  irq_nvecs <= 1.

--

r8169: clear RxOverflow before unmasking interrupts

The patch clears RxOverflow in rtl8169_poll() once NAPI completes, just
before interrupts are re-enabled. Without this, the RTL8125B stays stopped
after it runs out of RX descriptors. That stall comes from 6994520a3328,
which removed RxOverflow from the interrupt sources.

> On this tree the patch was only built, not run; rtl8169_poll() is the
> same here as in v7.2.

[Severity: Low]

Is this statement accurate? In this tree, parts of rtl8169_poll() come
from the multi-queue rework:

36af5aac9545 ("r8169: prepare for multi irqs and napi")
5df447aee076 ("r8169: refactor RX path to prepare for multi-queue")

For example, rtl_rx() now takes a pointer to a single RX ring:

	/* rtl8169_poll() is used only when there is a single RX ring. */
	work_done = rtl_rx(dev, tp, &tp->rx_ring[0], budget, napi);

Also, rtl_ack_events() now has an irq_nvecs > 1 branch that writes
ISR_VEC_MAP_REG.

The single-vector path still writes IntrStatus_8125/IntrStatus as before,
so the logic looks functionally equivalent. However, the A/B results were
measured on different code than what is submitted.

With Cc: stable and Fixes: 6994520a3328, the context line above does not
exist in any stable tree, so each backport will need to be adapted by
hand.

Could the changelog say that the code that was tested differs from the
code submitted here?

> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index f151ab6813932..99b0a410f58e4 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -5670,8 +5670,14 @@ static int rtl8169_poll(struct napi_struct *napi, int budget)
>  	/* rtl8169_poll() is used only when there is a single RX ring. */
>  	work_done = rtl_rx(dev, tp, &tp->rx_ring[0], budget, napi);
>  
> -	if (work_done < budget && napi_complete_done(napi, work_done))
> +	if (work_done < budget && napi_complete_done(napi, work_done)) {

[Severity: High]

Should the RxOverflow ack depend on napi_complete_done() returning true?

napi_complete_done() returns false early while busy polling:

net/core/dev.c:napi_complete_done() {
	if (unlikely(n->state & (NAPIF_STATE_NPSVC |
				 NAPIF_STATE_IN_BUSY_POLL)))
		return false;
    ...
}

It also returns false while defer_hard_irqs_count > 0 and a
gro_flush_timeout is set.

With threaded busy-poll enabled on the NAPI instance, napi_threaded_poll()
keeps NAPI_STATE_IN_BUSY_POLL set while the kthread polls:

net/core/dev.c:napi_threaded_poll() {
    ...
		want_busy_poll = val & NAPIF_STATE_THREADED_BUSY_POLL;
		in_busy_poll = val & NAPIF_STATE_IN_BUSY_POLL;
    ...
		if (want_busy_poll != in_busy_poll)
			assign_bit(NAPI_STATE_IN_BUSY_POLL, &napi->state,
				   want_busy_poll);
    ...
}

In that mode, rtl8169_poll() is called in a loop and never reaches
rtl_ack_events(tp, RxOverflow) or rtl_irq_enable().

The first interrupt has already masked interrupts:

rtl8169_interrupt() {
    ...
	rtl_irq_disable(tp);
	napi_schedule(napi);
out:
	rtl_ack_events(tp, status);
    ...
}

So the interrupt handler, the only other code that acks status bits, does
not run again.

If the 256-entry ring overruns in this mode, does the RTL8125B latch
RxOverflow and stay stopped until busy-poll is turned off or the interface
is reset? Every incoming frame would be counted in rx_missed.

Socket busy polling (napi_busy_loop()), defer_hard_irqs/gro_flush_timeout
and irq-suspend look like they cause the same stall. In those cases it
only lasts until the busy-poll or deferral window ends.

The descriptors are already back with the NIC whenever rtl_rx() stops at
a NIC-owned descriptor (work_done < budget), whether or not NAPI completes.

Could the ack be tied to work_done < budget and moved out of the
napi_complete_done() condition?

> +		/* After running out of RX descriptors the chip does not
> +		 * receive again until RxOverflow is cleared. The ring is
> +		 * empty now, so clear it before unmasking.
> +		 */
> +		rtl_ack_events(tp, RxOverflow);

[Severity: Low]

This isn't a bug, but the comment presents this as general chip behavior.
The changelog only describes and tests RTL8125B.

r8169_init_napi() registers rtl8169_poll() for every single-vector device:

	} else {
		netif_napi_add(tp->dev, &tp->rtl8169_napi[0], rtl8169_poll);

get_max_irq_nvecs() only allows more than one vector for
RTL_GIGA_MAC_VER_80. So this extra IntrStatus write now happens on every
NAPI completion for RTL8169/8168/8101/8125/8126 as well.

6994520a3328 was tested on RTL8168h, on the premise that running out of
descriptors needs no special handling.

Could the changelog and the comment say whether this RxOverflow behavior
is specific to RTL8125B or also applies to older chips? Could they also
say that the change affects all chip generations but was tested only on
RTL8125B?

>  		rtl_irq_enable(tp);
> +	}
>  
>  	return work_done;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121073652.410916-1-jure.rebernik%40luxonis.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25  7:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21  7:36 [PATCH net v2] r8169: clear RxOverflow before unmasking interrupts Jure Rebernik
2026-11-23 19:20 ` Jacob Keller
2026-11-25  7:53 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox