Skip to contentSkip to conversation

stmmac: call local_irq_save other than disable_irq in poll_controller

PATCH In review Sonic Zhang 2 participants 4 messages May 5, 2015 – May 6, 2015

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

PATCH 1/1 stmmac: call local_irq_save other than disable_irq in poll_controller

From: Sonic Zhang <[email protected]>

It is possible that poll_controller is called from netpoll.c with irq already disabled. Unexpected interrupt may be triggered if always enable irq before returning from poll_controller.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -2
index 05c146f..830c008 100644
@@ -2465,9 +2465,11 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
  */
 static void stmmac_poll_controller(struct net_device *dev)
 {
-	disable_irq(dev->irq);
+	unsigned long flags;
+
+	local_irq_save(flags);
 	stmmac_interrupt(dev->irq, dev);
-	enable_irq(dev->irq);
+	local_irq_restore(flags);
 }
 #endif
 
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw

From: Sonic Zhang <[email protected]>
Date: Tue, 5 May 2015 15:55:53 +0800

Quoted 7 lines

From: Sonic Zhang <[email protected]>

It is possible that poll_controller is called from netpoll.c with irq already disabled. Unexpected interrupt may be triggered if always enable irq before returning from poll_controller.

Nope, this is wrong.

If you don't use disable_irq(), the interrupt handler can run in parallel on another cpu and you definitely do not want that.

There is nothing wrong with the interrupt triggering on the enable_irq() here. If that causes some problem, there is a bug in this driver.

#2 lore raw

Hi David,

Quoted 9 lines · David Miller

From: Sonic Zhang <[email protected]>
Date: Tue, 5 May 2015 15:55:53 +0800

Quoted 6 lines

From: Sonic Zhang <[email protected]>

It is possible that poll_controller is called from netpoll.c with irq already disabled. Unexpected interrupt may be triggered if always enable irq before returning from poll_controller.

Quoted 6 lines
Quoted 1 line

Nope, this is wrong.

If you don't use disable_irq(), the interrupt handler can run in parallel on another cpu and you definitely do not want that.

How about change local_irq_save(flags) to
spin_lock_irqsave(&priv->lock, flags) ?

Quoted 4 lines

There is nothing wrong with the interrupt triggering on the enable_irq() here. If that causes some problem, there is a bug in this driver.

When I debug Linux kernel via KGDB over Ethernet, KGDB calls netpoll API and stmmac_poll_controller to send UDP packets with all interrupts disabled. KGDB assumes all interrupts keeps disabled when it is active and doing UDP data transmission. Enabling interrupts in stmmac_poll_controller causes KGDB re-enter exception and system halt.

Although KGDB over Ethernet is not part of the mainline tree, I feel this patch is useful in case other kernel functions want to call netpoll API with interrupts disabled.

Regards,

Sonic

maintainer
#3 lore raw

From: Sonic Zhang <[email protected]>
Date: Wed, 6 May 2015 11:53:53 +0800

Quoted 5 lines

When I debug Linux kernel via KGDB over Ethernet, KGDB calls netpoll API and stmmac_poll_controller to send UDP packets with all interrupts disabled. KGDB assumes all interrupts keeps disabled when it is active and doing UDP data transmission. Enabling interrupts in stmmac_poll_controller causes KGDB re-enter exception and system halt.

If KGDB has disabled local cpu interrupts, that cannot happen.

What stmmac_poll_controller() is doing is enabling a specific interupt source, not "interrupts" generally. The latter is what KGDB can specifically control and should care about.