Skip to contentSkip to conversation

8139cp: Prevent dev_close/cp_interrupt race on MTU change

PATCH In review John Greene 3 participants 6 messages Dec 19, 2012 – Jan 9, 2013

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

PATCH 1/1 8139cp: Prevent dev_close/cp_interrupt race on MTU change

commit: cb64edb6b89491edfdbae52ba7db9a8b8391d339 upstream

Above commit may introduce a race between cp_interrupt and dev_close / change MTU / dev_open up state. Changes cp_interrupt to tolerate this. Change spin_locking in cp_interrupt to avoid possible but unobserved race.

Tested on virtual hardware, Tx MTU size up to 4096, max tx payload
was ping -s 4068 for MTU of 4096. No real hardware, need test assist.

CC "David S. Miller" <[email protected]>
CC "David Woodhouse" <[email protected]>
---
 drivers/net/ethernet/realtek/8139cp.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/net/ethernet/realtek/8139cp.c +11 -7
index 0da3f5e..585c35c 100644
@@ -577,28 +577,30 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
 {
 	struct net_device *dev = dev_instance;
 	struct cp_private *cp;
+	int handled = 0;
 	u16 status;
 
 	if (unlikely(dev == NULL))
 		return IRQ_NONE;
 	cp = netdev_priv(dev);
 
+	spin_lock(&cp->lock);
+
 	status = cpr16(IntrStatus);
 	if (!status || (status == 0xFFFF))
-		return IRQ_NONE;
+		goto out_unlock;
+
+	handled = 1;
 
 	netif_dbg(cp, intr, dev, "intr, status %04x cmd %02x cpcmd %04x\n",
 		  status, cpr8(Cmd), cpr16(CpCmd));
 
 	cpw16(IntrStatus, status & ~cp_rx_intr_mask);
 
-	spin_lock(&cp->lock);
-
 	/* close possible race's with dev_close */
 	if (unlikely(!netif_running(dev))) {
 		cpw16(IntrMask, 0);
-		spin_unlock(&cp->lock);
-		return IRQ_HANDLED;
+		goto out_unlock;
 	}
 
 	if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))
@@ -612,7 +614,6 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
 	if (status & LinkChg)
 		mii_check_media(&cp->mii_if, netif_msg_link(cp), false);
 
-	spin_unlock(&cp->lock);
 
 	if (status & PciErr) {
 		u16 pci_status;
@@ -625,7 +626,10 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
 		/* TODO: reset hardware */
 	}
 
-	return IRQ_HANDLED;
+out_unlock:
+	spin_unlock(&cp->lock);
+
+	return IRQ_RETVAL(handled);
 }
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
Signature · 1 line
1.7.11.7
maintainer
#1 lore raw

From: John Greene <[email protected]>
Date: Wed, 19 Dec 2012 14:47:48 -0500

Quoted 7 lines

commit: cb64edb6b89491edfdbae52ba7db9a8b8391d339 upstream

Above commit may introduce a race between cp_interrupt and dev_close / change MTU / dev_open up state. Changes cp_interrupt to tolerate this. Change spin_locking in cp_interrupt to avoid possible but unobserved race.

Quoted 7 lines

Tested on virtual hardware, Tx MTU size up to 4096, max tx payload
was ping -s 4068 for MTU of 4096. No real hardware, need test assist.

You sent this as a "request for testing" last week, but I saw no testing on real hardware whatsoever.

Tested-by
#2 lore raw
Quoted 2 lines · David Miller

You sent this as a "request for testing" last week, but I saw no testing on real hardware whatsoever.

Thanks for the reminder :)

Seems to work fine here. I haven't confirmed whether I actually see the race or not but changing MTU on a live device works fine, even when it's being ping-flooded.

Signature · 1 line
dwmw2
maintainer
#3 lore raw

From: David Woodhouse <[email protected]>
Date: Wed, 19 Dec 2012 20:55:47 +0000

Quoted 11 lines · David Miller
Quoted 2 lines

You sent this as a "request for testing" last week, but I saw no testing on real hardware whatsoever.

Thanks for the reminder :)

Seems to work fine here. I haven't confirmed whether I actually see the race or not but changing MTU on a live device works fine, even when it's being ping-flooded.

That's more like it, applied, thanks everyone. :-)

#4 lore raw
In reply to David Woodhouse
Quoted 4 lines · David Woodhouse
Quoted 2 lines · David Miller

You sent this as a "request for testing" last week, but I saw no testing on real hardware whatsoever.

Quoted 8 lines

Thanks for the reminder :)

Seems to work fine here. I haven't confirmed whether I actually see the race or not but changing MTU on a live device works fine, even when it's being ping-flooded.

Thanks all. Happy holidays!

Signature · 1 line
John Greene
#5 lore raw
In reply to John Greene
Quoted 71 lines · John Greene

commit: cb64edb6b89491edfdbae52ba7db9a8b8391d339 upstream

Above commit may introduce a race between cp_interrupt and dev_close / change MTU / dev_open up state. Changes cp_interrupt to tolerate this. Change spin_locking in cp_interrupt to avoid possible but unobserved race.

Tested on virtual hardware, Tx MTU size up to 4096, max tx payload
was ping -s 4068 for MTU of 4096. No real hardware, need test assist.

CC "David S. Miller" <[email protected]>
CC "David Woodhouse" <[email protected]>
---
  drivers/net/ethernet/realtek/8139cp.c | 18 +++++++++++-------
  1 file changed, 11 insertions(+), 7 deletions(-)
drivers/net/ethernet/realtek/8139cp.c +7 -6
index 0da3f5e..585c35c 100644
@@ -577,28 +577,30 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
  {
  	struct net_device *dev = dev_instance;
  	struct cp_private *cp;
+	int handled = 0;
  	u16 status;
 
  	if (unlikely(dev == NULL))
  		return IRQ_NONE;
  	cp = netdev_priv(dev);
 
+	spin_lock(&cp->lock);
+
  	status = cpr16(IntrStatus);
  	if (!status || (status == 0xFFFF))
-		return IRQ_NONE;
+		goto out_unlock;
+
+	handled = 1;
 
  	netif_dbg(cp, intr, dev, "intr, status %04x cmd %02x cpcmd %04x\n",
  		  status, cpr8(Cmd), cpr16(CpCmd));
 
  	cpw16(IntrStatus, status & ~cp_rx_intr_mask);
 
-	spin_lock(&cp->lock);
-
  	/* close possible race's with dev_close */
  	if (unlikely(!netif_running(dev))) {
  		cpw16(IntrMask, 0);
-		spin_unlock(&cp->lock);
-		return IRQ_HANDLED;
+		goto out_unlock;
  	}
 
  	if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))
@@ -612,7 +614,6 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
  	if (status & LinkChg)
  		mii_check_media(&cp->mii_if, netif_msg_link(cp), false);
 
-	spin_unlock(&cp->lock);
 
  	if (status & PciErr) {
  		u16 pci_status;
@@ -625,7 +626,10 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
  		/* TODO: reset hardware */

drivers/net/ethernet/realtek/8139cp.c static irqreturn_t cp_interrupt (int irq, void *dev_instance) · line 635

Quoted 10 lines
drivers/net/ethernet/realtek/8139cp.c +4 -1
  	}
 
-	return IRQ_HANDLED;
+out_unlock:
+	spin_unlock(&cp->lock);
+
+	return IRQ_RETVAL(handled);
  }
 
  #ifdef CONFIG_NET_POLL_CONTROLLER

Can I get a quick update on this? Seems to have fallen thru the cracks.
Thanks.

Signature · 1 line
John Greene