PATCH] net: b44.c fix sleeping-with-spinlock-helt during resume
Subsystems (3)
From: Arjan van de Ven <[email protected]>
Subject: [PATCH] net: b44.c fix sleeping-with-spinlock-helt during resume
CC: Michael Buesch <[email protected]>
The b44.c driver calls b44_chip_reset() from the resume path, with the device spinlock held.
Unfortunately, b44_chip_reset() calls ssb_pcicore_dev_irqvecs_enable() which is a sleeping function (and calls might_sleep), if and only if the device hasn't been enabled yet.
Not having this hardware, the safest solution seems to be to enable the irqvec before taking the spinlock...
http://www.kerneloops.org/search.php?search=ssb_pcicore_dev_irqvecs_enable
--- drivers/net/b44.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/net/b44.c +9 -1
@@ -1278,6 +1278,7 @@ static void b44_chip_reset(struct b44 *bp, int reset_kind)bw32 (bp,B44_DMARX_CTRL ,0 ); bp->rx_prod = bp->rx_cons =0 ; }else +/* this function sleeps! */ ssb_pcicore_dev_irqvecs_enable (&sdev->bus->pcicore, sdev);ssb_device_enable (bp->sdev,0 );
@@ -1374,7 +1375,7 @@ static int b44_set_mac_addr(struct net_device *dev, void *p) }/* Called at device open time to get the chip ready for -* packet processing. Invoked with bp->lock held. +* packet processing. Sometimes invoked with bp->lock held. */ static void __b44_set_rx_mode (struct net_device *);static void b44_init_hw (struct b44 *bp,int reset_kind)
@@ -2288,6 +2289,13 @@ static int b44_resume(struct ssb_device *sdev)return rc; } +/* +* If the device isn't enabled yet, we need to do so before taking +* the spinlock, since the enablinging function sleeps. +*/ +if (!ssb_device_is_enabled (bp->sdev)) +ssb_pcicore_dev_irqvecs_enable (&sdev->bus->pcicore, sdev); +spin_lock_irq (&bp->lock);b44_init_rings (bp);
Signature · 8 lines
1.5.5.1 -- If you want to reach me at my work email, use [email protected] For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 46 lines · On Sunday 01 June 2008 05:11:30 Arjan van de Ven wrote:
From: Arjan van de Ven <[email protected]>
Subject: [PATCH] net:b44.cfix sleeping-with-spinlock-helt during resume
CC: Michael Buesch <[email protected]>The
b44.cdriver callsb44_chip_reset()from the resume path, with the device spinlock held.
Unfortunately,b44_chip_reset()callsssb_pcicore_dev_irqvecs_enable()which is a sleeping function (and callsmight_sleep), if and only if the device hasn't been enabled yet.Not having this hardware, the safest solution seems to be to enable the irqvec before taking the spinlock...
http://www.kerneloops.org/search.php?search=ssb_pcicore_dev_irqvecs_enable
Reported-by www.kerneloops.orgSigned-off-by Arjan van de Ven--- drivers/net/b44.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)drivers/net/b44.c +2
-1@@ -1278,6 +1278,7 @@ static void b44_chip_reset(struct b44 *bp, int reset_kind)bw32 (bp,B44_DMARX_CTRL ,0 ); bp->rx_prod = bp->rx_cons =0 ; }else +/* this function sleeps! */ ssb_pcicore_dev_irqvecs_enable (&sdev->bus->pcicore, sdev);ssb_device_enable (bp->sdev,0 );@@ -1374,7 +1375,7 @@ static int b44_set_mac_addr(struct net_device *dev, void *p) }/* Called at device open time to get the chip ready for -* packet processing. Invoked with bp->lock held. +* packet processing. Sometimes invoked with bp->lock held. */ static void __b44_set_rx_mode (struct net_device *);static void b44_init_hw (struct b44 *bp,int reset_kind)@@ -2288,6 +2289,13 @@ static int b44_resume(struct ssb_device *sdev)return rc; }
drivers/net/b44.c static int b44_resume(struct ssb_device *sdev) · line 2301
Quoted 10 lines
drivers/net/b44.c +7
-0+/* +* If the device isn't enabled yet, we need to do so before taking +* the spinlock, since the enablinging function sleeps. +*/ +if (!ssb_device_is_enabled (bp->sdev)) +ssb_pcicore_dev_irqvecs_enable (&sdev->bus->pcicore, sdev); +spin_lock_irq (&bp->lock);b44_init_rings (bp);
I'm not sure how this is supposed to fix the bug.
I think you will call ssb_pcicore_dev_irqvecs_enable() twice this way. The call in b44_chip_reset() will still trigger.
Besides that, this only is a theoretical issue, as the function does only sleep on a PCI-E device. But as b44 PCI-E devices don't exist, it will never sleep. So I'd rather replace the might_sleep() with a might_sleep_if() call.
Something like the following:
drivers/ssb/driver_pcicore.c +2 -2
@@ -537,12 +537,12 @@ int ssb_pcicore_dev_irqvecs_enable(strucint err =0 ;u32 tmp; -might_sleep (); -if (!pdev) goto out; bus = pdev->bus; +might_sleep_if (pdev->id.coreid !=SSB_DEV_PCI ); +/* Enable interrupts for this device. */ if (bus->host_pci && ((pdev->id.revision >=6 ) || (pdev->id.coreid ==SSB_DEV_PCIE ))) {
Signature · 1 line
Greetings Michael.
Quoted 19 lines · On Sun, 1 Jun 2008 12:03:40 +0200 Michael Buesch <[email protected]> wrote:
Index:
wireless-testing/drivers/ssb/driver_pcicore.c
===================================================================
---wireless-testing.orig/drivers/ssb/driver_pcicore.c2008-04-23 16:06:56.000000000 +0200 +++
wireless-testing/drivers/ssb/driver_pcicore.c2008-06-01
12:02:33.000000000 +0200 @@ -537,12 +537,12 @@ int ssb_pcicore_dev_irqvecs_enable(struc int err = 0; u32 tmp;drivers/ssb/driver_pcicore.c +2
-2-might_sleep (); -if (!pdev) goto out; bus = pdev->bus; +might_sleep_if (pdev->id.coreid !=SSB_DEV_PCI ); +/* Enable interrupts for this device. */ if (bus->host_pci && ((pdev->id.revision >= 6) || (pdev->id.coreid ==
Quoted 4 lines
SSB_DEV_PCIE))) {
fair enough.... can we get something like this into 2.6.26 still? Quite a few people are hitting this (even though the warning is harmless, it still is better to silence it)
Signature · 3 lines
If you want to reach me at my work email, use [email protected] For development, discussion and tips for power savings, visit http://www.lesswatts.org
Hi Arjan, Michael,
Quoted 17 lines · Arjan van de Ven
Quoted 14 lines · On Sun, 1 Jun 2008 12:03:40 +0200 Michael Buesch <[email protected]> wrote:
Index:
wireless-testing/drivers/ssb/driver_pcicore.c
===================================================================
---wireless-testing.orig/drivers/ssb/driver_pcicore.c2008-04-23 16:06:56.000000000 +0200 +++
wireless-testing/drivers/ssb/driver_pcicore.c2008-06-01
12:02:33.000000000 +0200 @@ -537,12 +537,12 @@ int ssb_pcicore_dev_irqvecs_enable(struc int err = 0; u32 tmp;drivers/ssb/driver_pcicore.c +0
-2-might_sleep (); -if (!pdev) goto out; bus = pdev->bus;
Quoted 13 lines
Quoted 9 lines
drivers/ssb/driver_pcicore.c +2
-0+might_sleep_if (pdev->id.coreid !=SSB_DEV_PCI ); +/* Enable interrupts for this device. */ if (bus->host_pci && ((pdev->id.revision >= 6) || (pdev->id.coreid ==
SSB_DEV_PCIE))) {fair enough.... can we get something like this into 2.6.26 still? Quite a few people are hitting this (even though the warning is harmless, it still is better to silence it)
Care to CC stable when people are already hitting the problem ?
FWIW, the fix was merged in mainline as commit
a3bafeedfff2ac5fa0a316bea4570e27900b6fcc
thanks!
willy