Skip to content

Commit 83c34fd

Browse files
John Greenedavem330
authored andcommitted
8139cp: Prevent dev_close/cp_interrupt race on MTU change
commit: cb64edb 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. Reported-by: "Francois Romieu" <romieu@fr.zoreil.com> 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. Signed-off-by: "John Greene" <jogreene@redhat.com> CC: "David S. Miller" <davem@davemloft.net> CC: "David Woodhouse" <David.Woodhouse@intel.com> Tested-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f8b8403 commit 83c34fd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/net/ethernet/realtek/8139cp.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,28 +577,30 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
577577
{
578578
struct net_device *dev = dev_instance;
579579
struct cp_private *cp;
580+
int handled = 0;
580581
u16 status;
581582

582583
if (unlikely(dev == NULL))
583584
return IRQ_NONE;
584585
cp = netdev_priv(dev);
585586

587+
spin_lock(&cp->lock);
588+
586589
status = cpr16(IntrStatus);
587590
if (!status || (status == 0xFFFF))
588-
return IRQ_NONE;
591+
goto out_unlock;
592+
593+
handled = 1;
589594

590595
netif_dbg(cp, intr, dev, "intr, status %04x cmd %02x cpcmd %04x\n",
591596
status, cpr8(Cmd), cpr16(CpCmd));
592597

593598
cpw16(IntrStatus, status & ~cp_rx_intr_mask);
594599

595-
spin_lock(&cp->lock);
596-
597600
/* close possible race's with dev_close */
598601
if (unlikely(!netif_running(dev))) {
599602
cpw16(IntrMask, 0);
600-
spin_unlock(&cp->lock);
601-
return IRQ_HANDLED;
603+
goto out_unlock;
602604
}
603605

604606
if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))
@@ -612,7 +614,6 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
612614
if (status & LinkChg)
613615
mii_check_media(&cp->mii_if, netif_msg_link(cp), false);
614616

615-
spin_unlock(&cp->lock);
616617

617618
if (status & PciErr) {
618619
u16 pci_status;
@@ -625,7 +626,10 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
625626
/* TODO: reset hardware */
626627
}
627628

628-
return IRQ_HANDLED;
629+
out_unlock:
630+
spin_unlock(&cp->lock);
631+
632+
return IRQ_RETVAL(handled);
629633
}
630634

631635
#ifdef CONFIG_NET_POLL_CONTROLLER

0 commit comments

Comments
 (0)