Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

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>

authored by

John Greene and committed by
David S. Miller
83c34fd0 f8b84034

+11 -7
+11 -7
drivers/net/ethernet/realtek/8139cp.c
··· 577 577 { 578 578 struct net_device *dev = dev_instance; 579 579 struct cp_private *cp; 580 + int handled = 0; 580 581 u16 status; 581 582 582 583 if (unlikely(dev == NULL)) 583 584 return IRQ_NONE; 584 585 cp = netdev_priv(dev); 585 586 587 + spin_lock(&cp->lock); 588 + 586 589 status = cpr16(IntrStatus); 587 590 if (!status || (status == 0xFFFF)) 588 - return IRQ_NONE; 591 + goto out_unlock; 592 + 593 + handled = 1; 589 594 590 595 netif_dbg(cp, intr, dev, "intr, status %04x cmd %02x cpcmd %04x\n", 591 596 status, cpr8(Cmd), cpr16(CpCmd)); 592 597 593 598 cpw16(IntrStatus, status & ~cp_rx_intr_mask); 594 599 595 - spin_lock(&cp->lock); 596 - 597 600 /* close possible race's with dev_close */ 598 601 if (unlikely(!netif_running(dev))) { 599 602 cpw16(IntrMask, 0); 600 - spin_unlock(&cp->lock); 601 - return IRQ_HANDLED; 603 + goto out_unlock; 602 604 } 603 605 604 606 if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr)) ··· 614 612 if (status & LinkChg) 615 613 mii_check_media(&cp->mii_if, netif_msg_link(cp), false); 616 614 617 - spin_unlock(&cp->lock); 618 615 619 616 if (status & PciErr) { 620 617 u16 pci_status; ··· 626 625 /* TODO: reset hardware */ 627 626 } 628 627 629 - return IRQ_HANDLED; 628 + out_unlock: 629 + spin_unlock(&cp->lock); 630 + 631 + return IRQ_RETVAL(handled); 630 632 } 631 633 632 634 #ifdef CONFIG_NET_POLL_CONTROLLER