net: sgi: ioc3-eth: IRQ and link timer fixes
Subsystems (5)
v2 cover net: sgi: ioc3-eth: IRQ and link timer fixes
Two fixes for ioc3-eth: the shared IRQ is requested in probe before the state its handler uses exists and outlives free_netdev(), and ioc3_init() waits for the link timer in hardirq context.
v1 was posted for net. Its patch 1 was applied to net-next as 944841b8af49 ("net: sgi: ioc3-eth: set platform drvdata in probe"), so this version goes to net-next as well.
Tested on an SGI Fuel.
---
Changes in v2:
- Patch 1 replaces v1 patch 2 ("fix IRQ lifetime against netdev teardown"): the IRQ is requested in ndo_open and freed in ndo_stop instead of being reordered in probe.
- Patch 2 is new, for the link timer wait reported in the review of v1 patch 2.
- Both messages say how the bug was reproduced and how the fix was tested.
v1: https://lore.kernel.org/r/[email protected]
Imre Kaloz (2):
net: sgi: ioc3-eth: request the IRQ in open, not probe
net: sgi: ioc3-eth: do not wait for the link timer in ioc3_init
drivers/net/ethernet/sgi/ioc3-eth.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
base-commit: f89726ffabef1b08c52e6163b7ab94b0d5f15503
Signature · 1 line
2.47.3
PATCH v2 1/2 net: sgi: ioc3-eth: request the IRQ in open, not probe
The shared IRQ is requested in probe before the rings, lock and timer its handler uses exist, and under devm it outlives free_netdev() on the error paths and in remove.
Request it in ndo_open once the RX buffers exist and free it in ndo_stop before stopping the chip, because free_irq() waits for a running handler and ioc3_error() restarts the chip.
Found by review; with DEBUG_SHIRQ, unbinding the driver without this change faults on freed memory. Tested on an SGI Fuel with DEBUG_SHIRQ and SLUB_DEBUG_ON: link down/up and driver unbind/rebind.
--- drivers/net/ethernet/sgi/ioc3-eth.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/net/ethernet/sgi/ioc3-eth.c +11 -7
@@ -781,6 +781,7 @@ static inline void ioc3_stop(struct ioc3_private *ip)static int ioc3_open (struct net_device *dev) {struct ioc3_private *ip =netdev_priv (dev); +int err; ip->ehar_h =0 ; ip->ehar_l =0 ;
@@ -790,6 +791,13 @@ static int ioc3_open(struct net_device *dev)netdev_err (dev,"%s: rx buffer allocation failed\n" , __func__);return -ENOMEM ; } + err =request_irq (dev->irq, ioc3_interrupt,IRQF_SHARED ,"ioc3-eth" , + dev); +if (err) { +netdev_err (dev,"Can't get irq %d\n" , dev->irq); +ioc3_free_rx_bufs (ip); +return err; + }ioc3_start (ip);ioc3_mii_start (ip);
@@ -803,6 +811,9 @@ static int ioc3_close(struct net_device *dev)timer_delete_sync (&ip->ioc3_timer); +/* ioc3_error() restarts the chip, so free the IRQ before stopping it */ +free_irq (dev->irq, dev); +netif_stop_queue (dev);ioc3_stop (ip);
@@ -870,13 +881,6 @@ static int ioc3eth_probe(struct platform_device *pdev) goto out_free; } -if (devm_request_irq (&pdev->dev, dev->irq, ioc3_interrupt, -IRQF_SHARED ,"ioc3-eth" , dev)) { -dev_err (&pdev->dev,"Can't get irq %d\n" , dev->irq); - err = -ENODEV ; - goto out_free; - } -spin_lock_init (&ip->ioc3_lock);timer_setup (&ip->ioc3_timer, ioc3_timer,0 );
Signature · 1 line
2.47.3
PATCH v2 2/2 net: sgi: ioc3-eth: do not wait for the link timer in ioc3_init
In reply to Imre Kalozioc3_init() waits for the link timer with timer_delete_sync(), but it runs from ioc3_error() in hardirq context with ioc3_lock held, and from ioc3_timeout() under spin_lock_irq(). A callback interrupted on this CPU never finishes, and one on another CPU spins on ioc3_lock, which the waiter holds.
Stop the timer in ioc3_open() instead and leave it running across resets, so the link poll no longer stops after the first error interrupt.
Reproduced by injecting an IOC3 error interrupt from a kernel
modification: without this change, timer_delete_sync() warns from hardirq context. Tested on an SGI Fuel with DEBUG_SHIRQ andSLUB_DEBUG_ON: link down/up, driver unbind/rebind and an injected error interrupt.
--- drivers/net/ethernet/sgi/ioc3-eth.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/sgi/ioc3-eth.c +1 -3
@@ -718,8 +718,6 @@ static void ioc3_init(struct net_device *dev)struct ioc3_private *ip =netdev_priv (dev);struct ioc3_ethregs *regs = ip->regs; -timer_delete_sync (&ip->ioc3_timer);/* Kill if running */ -writel (EMCR_RST , ®s->emcr);/* Reset */ readl (®s->emcr);/* Flush WB */ udelay (4 );/* Give it time ... */
@@ -786,6 +784,7 @@ static int ioc3_open(struct net_device *dev) ip->ehar_h =0 ; ip->ehar_l =0 ; +timer_delete_sync (&ip->ioc3_timer);ioc3_init (dev);if (ioc3_alloc_rx_bufs (dev)) {netdev_err (dev,"%s: rx buffer allocation failed\n" , __func__);
@@ -1131,7 +1130,6 @@ static void ioc3_timeout(struct net_device *dev, unsigned int txqueue) }ioc3_start (ip);ioc3_mii_init (ip); -ioc3_mii_start (ip);spin_unlock_irq (&ip->ioc3_lock);
Signature · 1 line
2.47.3