Skip to contentSkip to conversation

r8169: Fix irq masking in rtl8169_interrupt()

PATCH In review Karsten Wiese 3 participants 16 messages Mar 17, 2009 – Mar 24, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 r8169: Fix irq masking in rtl8169_interrupt()

Only adjust the NAPI bits of the interruptmask, if netif_rx_schedule_prep() returns true.
Without this, I see interrupt storms here using 2.6.29-rcx and 2.6.27.19 and device needed rmmod r8169 + modprobe r8169 to start working.

---
 drivers/net/r8169.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
drivers/net/r8169.c +4 -5
index b347340..0c943ba 100644
@@ -3708,12 +3708,11 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
 		rtl8169_check_link_status(dev, tp, ioaddr);
 
 	if (status & tp->napi_event) {
-		RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
-		tp->intr_mask = ~tp->napi_event;
-
-		if (likely(netif_rx_schedule_prep(&tp->napi)))
+		if (likely(netif_rx_schedule_prep(&tp->napi))) {
+			RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
+			tp->intr_mask = ~tp->napi_event;
 			__netif_rx_schedule(&tp->napi);
-		else if (netif_msg_intr(tp)) {
+		} else if (netif_msg_intr(tp)) {
 			printk(KERN_INFO "%s: interrupt %04x in poll\n",
 			       dev->name, status);
 		}
Signature · 1 line
1.6.0.6
#1 lore raw

Karsten Wiese <[email protected]> :

Quoted 5 lines

Only adjust the NAPI bits of the interruptmask, if netif_rx_schedule_prep() returns true.
Without this, I see interrupt storms here using 2.6.29-rcx and 2.6.27.19 and device needed rmmod r8169 + modprobe r8169 to start working.

How the patch is supposed to work is not completely clear to me.

Can you elaborate a bit ?

Signature · 1 line
Ueimor
#2 lore raw

Am Dienstag 17 März 2009 schrieb Francois Romieu:

Quoted 8 lines

Karsten Wiese <[email protected]> :

Quoted 5 lines

Only adjust the NAPI bits of the interruptmask, if netif_rx_schedule_prep() returns true.
Without this, I see interrupt storms here using 2.6.29-rcx and 2.6.27.19 and device needed rmmod r8169 + modprobe r8169 to start working.

How the patch is supposed to work is not completely clear to me.

Without it, if netif_rx_schedule_prep() returns 0, __netif_rx_schedule() is not called so nothing is there to care for the transfer. Nonetheless intr_mask is changed so that its not possible that __netif_rx_schedule() is ever called later.

Patch works by letting rtl8169_interrupt() again call netif_rx_schedule_prep() until it succeeds and __netif_rx_schedule() is called.

Thanks,
Karsten

#3 lore raw

Karsten Wiese <[email protected]> :

Quoted 1 line

Am Dienstag 17 März 2009 schrieb Francois Romieu:

[...]

Quoted 9 lines
Quoted 1 line

How the patch is supposed to work is not completely clear to me.

Without it, if netif_rx_schedule_prep() returns 0, __netif_rx_schedule() is not called so nothing is there to care for the transfer. Nonetheless intr_mask is changed so that its not possible that __netif_rx_schedule() is ever called later.

Patch works by letting rtl8169_interrupt() again call netif_rx_schedule_prep() until it succeeds and __netif_rx_schedule() is called.

Thanks for the explanation.

If netif_rx_schedule fails after napi is enabled, there is a racing poll thread to care for the transfer.

Stated differently the bug is noticeable because napi_enable() should be called before request_irq() in rtl8169_open, right ?

Signature · 1 line
Ueimor
#4 lore raw

Am Mittwoch 18 März 2009 schrieb Francois Romieu:

Quoted 13 lines

Karsten Wiese <[email protected]> :

Quoted 1 line

Am Dienstag 17 März 2009 schrieb Francois Romieu:

[...]

Quoted 9 lines
Quoted 1 line

How the patch is supposed to work is not completely clear to me.

Without it, if netif_rx_schedule_prep() returns 0, __netif_rx_schedule() is not called so nothing is there to care for the transfer. Nonetheless intr_mask is changed so that its not possible that __netif_rx_schedule() is ever called later.

Patch works by letting rtl8169_interrupt() again call netif_rx_schedule_prep() until it succeeds and __netif_rx_schedule() is called.

Quoted 7 lines

Thanks for the explanation.

If netif_rx_schedule fails after napi is enabled, there is a racing poll thread to care for the transfer.

Stated differently the bug is noticeable because napi_enable() should be called before request_irq() in rtl8169_open, right ?

Propably yes. That would mean the first interrupt is received before rtl_hw_start() is called in rtl8169_open. The source of that interrupt would be something else then?

Thanks,
Karsten

#5 lore raw

Karsten Wiese <[email protected]> :

Quoted 1 line

Am Mittwoch 18 März 2009 schrieb Francois Romieu:

[...]

Quoted 9 lines
Quoted 5 lines

If netif_rx_schedule fails after napi is enabled, there is a racing poll thread to care for the transfer.

Stated differently the bug is noticeable because napi_enable() should be called before request_irq() in rtl8169_open, right ?

Propably yes. That would mean the first interrupt is received before rtl_hw_start() is called in rtl8169_open. The source of that interrupt would be something else then?

All we need is thus a shared interrupt racing on a different CPU with rtl8169_open and some IO versus memory reordering so that the hardware is started and a change in the status register can be seen in the IRQ handler before napi_enable/NAPI_STATE_SCHED escapes from the CPU where rtl8169_open is running...

It does not look like a credible explanation. :o/

Signature · 1 line
Ueimor
maintainer
#6 lore raw

From: Francois Romieu <[email protected]>
Date: Wed, 18 Mar 2009 23:36:29 +0100

Quoted 13 lines

Karsten Wiese <[email protected]> :

Quoted 1 line

Am Mittwoch 18 März 2009 schrieb Francois Romieu:

[...]

Quoted 9 lines
Quoted 5 lines

If netif_rx_schedule fails after napi is enabled, there is a racing poll thread to care for the transfer.

Stated differently the bug is noticeable because napi_enable() should be called before request_irq() in rtl8169_open, right ?

Propably yes. That would mean the first interrupt is received before rtl_hw_start() is called in rtl8169_open. The source of that interrupt would be something else then?

Quoted 7 lines

All we need is thus a shared interrupt racing on a different CPU with rtl8169_open and some IO versus memory reordering so that the hardware is started and a change in the status register can be seen in the IRQ handler before napi_enable/NAPI_STATE_SCHED escapes from the CPU where rtl8169_open is running...

It does not look like a credible explanation. :o/

Agreed, looking at how this part of the driver works I can't see how this condition can arise either.

#7 lore raw
In reply to Francois Romieu

Am Mittwoch 18 März 2009 schrieb Francois Romieu:

Quoted 13 lines

Karsten Wiese <[email protected]> :

Quoted 1 line

Am Mittwoch 18 März 2009 schrieb Francois Romieu:

[...]

Quoted 9 lines
Quoted 5 lines

If netif_rx_schedule fails after napi is enabled, there is a racing poll thread to care for the transfer.

Stated differently the bug is noticeable because napi_enable() should be called before request_irq() in rtl8169_open, right ?

Propably yes. That would mean the first interrupt is received before rtl_hw_start() is called in rtl8169_open. The source of that interrupt would be something else then?

Quoted 7 lines

All we need is thus a shared interrupt racing on a different CPU with rtl8169_open and some IO versus memory reordering so that the hardware is started and a change in the status register can be seen in the IRQ handler before napi_enable/NAPI_STATE_SCHED escapes from the CPU where rtl8169_open is running...

It does not look like a credible explanation. :o/

Found it: CONFIG_DEBUG_SHIRQ is set here causing a "test-call" to rtl8169_interrupt() from irq_request().

$SUBJECT patch is ok, me still thinks. You?

Thanks,
Karsten

#8 lore raw

Karsten Wiese <[email protected]> :
[...]

Quoted 4 lines

Found it: CONFIG_DEBUG_SHIRQ is set here causing a "test-call" to rtl8169_interrupt() from irq_request().

$SUBJECT patch is ok, me still thinks. You ?

I will have to convince myself that nothing bad can happen in the window between netif_rx_schedule_prep and RTL_W16. No big deal.

I do not understand why / how the patch works at all : AFAIU, the status register must contain some napi-related event in order for the patch to make a difference. That's exactly what rtl8169_irq_mask_and_ack() is supposed to prevent. -> Does it fail ?

So I'd really like to understand what is going on here.

PS: while I agree on the motivation for CONFIG_DEBUG_SHIRQ, I wonder if it is 100% safe to run an IRQ handler from a context which does not adhere to the original semantic. If its {disable/enable}_irq pair races with a similar pair due to a different driver on the same (shared) irq, things could imho be unsafe.

Signature · 1 line
Ueimor
#9 lore raw

Am Donnerstag 19 März 2009 schrieb Francois Romieu:

Quoted 9 lines

Karsten Wiese <[email protected]> :
[...]

Quoted 4 lines

Found it: CONFIG_DEBUG_SHIRQ is set here causing a "test-call" to rtl8169_interrupt() from irq_request().

$SUBJECT patch is ok, me still thinks. You ?

I will have to convince myself that nothing bad can happen in the window between netif_rx_schedule_prep and RTL_W16. No big deal.

RTL_W16 is a posted write, if it happens, theres no difference if its posted before or after netif_rx_schedule_prep.

Quoted 3 lines

I do not understand why / how the patch works at all : AFAIU, the status register must contain some napi-related event in order for the patch to make a difference.

It contains 0x25 when the "test-call" runs, Link, Rx and Tx Flags.

Quoted 2 lines

That's exactly what rtl8169_irq_mask_and_ack() is
supposed to prevent. -> Does it fail ?

rtl8169_irq_mask_and_ack() resets status once and prevents interrupts being sent by device. Maybe status reset doesn't work because device is stopped or device isn't _completely_ stopped and updates status flags later. Maybe Tx status only becomes 0 if some Tx data is queued.

Quoted 1 line

So I'd really like to understand what is going on here.

Well, without patch any further interrupt causing napi-status isn't reset _and_ netif_rx_schedule() isn't active. screaming interrupts. slooooowish pc. Wonder why it proceeded at all though.

After rmmod/modprobe the status register contained 0x20 when in rtl8169_irq_mask_and_ack() during "test-call", letting device work normally.

Quoted 5 lines

PS: while I agree on the motivation for CONFIG_DEBUG_SHIRQ, I wonder if it is 100% safe to run an IRQ handler from a context which does not adhere to the original semantic. If its {disable/enable}_irq pair races with a similar pair due to a different driver on the same (shared) irq, things could imho be unsafe.

From the comment of disable_irq():
"This function waits for any pending IRQ handlers for this interrupt to complete before returning."
No race possible, in theory ;-)

The pc I debugged this on is a UP with no other device active on the used int16.

Thanks,
Karsten

#10 lore raw

Karsten Wiese <[email protected]> :
[...]

Quoted 2 lines

The pc I debugged this on is a UP with no other device active on the used int16.

/me wonders...

Does your network adapter support pxe or some boot time operation ?

Btw the XID of the device would be welcome.

Signature · 1 line
Ueimor
#11 lore raw

Am Sonntag 22 März 2009 schrieb Francois Romieu:

Quoted 8 lines

Karsten Wiese <[email protected]> :
[...]

Quoted 2 lines

The pc I debugged this on is a UP with no other device active on the used int16.

/me wonders...

Does your network adapter support pxe or some boot time operation ?

Yes, deavtivated in BIOS.

Quoted 1 line

Btw the XID of the device would be welcome.

XID is 04000000

Thanks,
Karsten

#12 lore raw

Karsten Wiese <[email protected]> :
[...]

Quoted 1 line

Yes, deavtivated in BIOS.

Ok, it starts to make some sense.

Does the patch below make a difference ?

drivers/net/r8169.c +2 -2
index 4b7cb38..b5a7358 100644
@@ -2011,8 +2011,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		}
 	}
 
-	pci_set_master(pdev);
-
 	/* ioremap MMIO region */
 	ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE);
 	if (!ioaddr) {
@@ -2039,6 +2037,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		msleep_interruptible(1);
 	}
 
+	pci_set_master(pdev);
+
 	/* Identify chip attached to board */
 	rtl8169_get_mac_version(tp, ioaddr);
 
Signature · 1 line
Ueimor
#13 lore raw

Am Montag 23 März 2009 schrieb Francois Romieu:

Quoted 7 lines

Karsten Wiese <[email protected]> :
[...]

Quoted 1 line

Yes, deavtivated in BIOS.

Ok, it starts to make some sense.

Does the patch below make a difference ?

No.

Quoted 22 lines
drivers/net/r8169.c +2 -2
index 4b7cb38..b5a7358 100644
@@ -2011,8 +2011,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		}
 	}
 
-	pci_set_master(pdev);
-
 	/* ioremap MMIO region */
 	ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE);
 	if (!ioaddr) {
@@ -2039,6 +2037,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		msleep_interruptible(1);
 	}
 
+	pci_set_master(pdev);
+
 	/* Identify chip attached to board */
 	rtl8169_get_mac_version(tp, ioaddr);
 
#14 lore raw

Am Dienstag 24 März 2009 schrieb Karsten Wiese:

Quoted 5 lines

Am Montag 23 März 2009 schrieb Francois Romieu:

Quoted 2 lines

Does the patch below make a difference ?

No.

patch below helps.

Thanks,
Karsten
--------------------->
[PATCH] r8169: Reset IntrStatus after chip rest

On a MSI MS-6702E mainboard, when in rtl8169_init_one() for the first time after BIOS has run, IntrStatus reads 5 after chip has been reset. IntrStatus should equal 0 there, so patch changes IntrStatus reset to happen after chip reset instead of before.
R8169_MSG_DEFAULT is changed to include NETIF_MSG_INTR, because without an important error message from rtl8169_interrupt() isn't shown by default.

---
 drivers/net/r8169.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
drivers/net/r8169.c +9 -3
index 56a1eb8..b06e153 100644
@@ -45,8 +45,9 @@
 #define dprintk(fmt, args...)	do {} while (0)
 #endif /* RTL8169_DEBUG */
 
-#define R8169_MSG_DEFAULT \
-	(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
+#define R8169_MSG_DEFAULT					\
+	(NETIF_MSG_DRV | NETIF_MSG_PROBE |			\
+	 NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_INTR)
 
 #define TX_BUFFS_AVAIL(tp) \
 	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
@@ -2076,7 +2077,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		dev_info(&pdev->dev, "no PCI Express capability\n");
 
 	/* Unneeded ? Don't mess with Mrs. Murphy. */
-	rtl8169_irq_mask_and_ack(ioaddr);
+	RTL_W16(IntrMask, 0x0000);
 
 	/* Soft reset the chip. */
 	RTL_W8(ChipCmd, CmdReset);
@@ -2088,6 +2089,11 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		msleep_interruptible(1);
 	}
 
+	/* On an MSI MS-6702E, when here for the first time after
+	   BIOS has run, IntrStatus contains 5. Play safe.
+	*/
+	RTL_W16(IntrStatus, 0xffff);
+
 	/* Identify chip attached to board */
 	rtl8169_get_mac_version(tp, ioaddr);
 
Signature · 1 line
1.6.0.6
#15 lore raw

Karsten Wiese <[email protected]> :
[...]

Quoted 1 line

patch below helps.

Thanks.

I'll wrap it up without the change to R8169_MSG_DEFAULT:
- it can be set through ethtool and a module option
- the current default is not a clear nuisance

Signature · 1 line
Ueimor