All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ks8851: Cancel any pending IRQ work
@ 2012-04-12 16:44 mjr
  2012-04-12 20:19 ` Stephen Boyd
  0 siblings, 1 reply; 4+ messages in thread
From: mjr @ 2012-04-12 16:44 UTC (permalink / raw)
  To: davem; +Cc: sboyd, ben, netdev, Matt Renzelmann

From: Matt Renzelmann <mjr@cs.wisc.edu>

An unexpected/spurious interrupt may cause the irq_work queue to
execute during or after module unload, which can cause a crash.  It
should be canceled.

Signed-off-by: Matt Renzelmann <mjr@cs.wisc.edu>
---
 drivers/net/ethernet/micrel/ks8851.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
index c722aa6..ab46953 100644
--- a/drivers/net/ethernet/micrel/ks8851.c
+++ b/drivers/net/ethernet/micrel/ks8851.c
@@ -1540,6 +1540,7 @@ static int __devexit ks8851_remove(struct spi_device *spi)
 		dev_info(&spi->dev, "remove\n");
 
 	unregister_netdev(priv->netdev);
+	cancel_work_sync(&priv->irq_work);
 	free_irq(spi->irq, priv);
 	free_netdev(priv->netdev);
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ks8851: Cancel any pending IRQ work
  2012-04-12 16:44 [PATCH] ks8851: Cancel any pending IRQ work mjr
@ 2012-04-12 20:19 ` Stephen Boyd
  2012-04-12 20:34   ` Matt Renzelmann
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2012-04-12 20:19 UTC (permalink / raw)
  To: mjr; +Cc: davem, ben, netdev

On 04/12/12 09:44, mjr@cs.wisc.edu wrote:
> From: Matt Renzelmann <mjr@cs.wisc.edu>
>
> An unexpected/spurious interrupt may cause the irq_work queue to
> execute during or after module unload, which can cause a crash.  It
> should be canceled.
>
> Signed-off-by: Matt Renzelmann <mjr@cs.wisc.edu>
> ---
>  drivers/net/ethernet/micrel/ks8851.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
> index c722aa6..ab46953 100644
> --- a/drivers/net/ethernet/micrel/ks8851.c
> +++ b/drivers/net/ethernet/micrel/ks8851.c
> @@ -1540,6 +1540,7 @@ static int __devexit ks8851_remove(struct spi_device *spi)
>  		dev_info(&spi->dev, "remove\n");
>  
>  	unregister_netdev(priv->netdev);
> +	cancel_work_sync(&priv->irq_work);
>  	free_irq(spi->irq, priv);
>  	free_netdev(priv->netdev);
>  

Is this actually solving anything? Presumably cancel_work_sync() could
run and then another spurious interrupt could come in after that
function returns and we would have the same problem again. We should
probably free the irq before unregistering the netdev so that
ks8851_net_stop() would run after the interrupt is no longer registered,
and the flush_work() in there would finish the last work. But then we
have a problem where we're enabling the irq in the irq_work callback
after the irq has been freed. Ugh.

I also see a potential deadlock in ks8851_net_stop(). ks8851_net_stop()
holds the ks->lock while calling flush_work() which could deadlock if an
interrupt comes and schedules an irq_work between the time
ks8851_net_stop() grabs the mutex and calls flush_work().

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] ks8851: Cancel any pending IRQ work
  2012-04-12 20:19 ` Stephen Boyd
@ 2012-04-12 20:34   ` Matt Renzelmann
  2012-04-13 18:32     ` Stephen Boyd
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Renzelmann @ 2012-04-12 20:34 UTC (permalink / raw)
  To: 'Stephen Boyd'; +Cc: davem, ben, netdev, Matt Renzelmann

> 
> Is this actually solving anything? Presumably cancel_work_sync() could
> run and then another spurious interrupt could come in after that
> function returns and we would have the same problem again. We should
> probably free the irq before unregistering the netdev so that
> ks8851_net_stop() would run after the interrupt is no longer registered,
> and the flush_work() in there would finish the last work. But then we
> have a problem where we're enabling the irq in the irq_work callback
> after the irq has been freed. Ugh.
> 
> I also see a potential deadlock in ks8851_net_stop(). ks8851_net_stop()
> holds the ks->lock while calling flush_work() which could deadlock if an
> interrupt comes and schedules an irq_work between the time
> ks8851_net_stop() grabs the mutex and calls flush_work().
> 

I agree on all counts -- the patch is buggy, though it does at least "shrink"
the window of vulnerability.  Frankly, I don't believe I'm qualified to write an
appropriate patch for this driver, at least without spending considerably more
time on it.

FWIW, I found this problem with a new driver-testing tool we've developed called
SymDrive, and my goal is primarily to determine if the bug is real or not.  The
tool is imperfect and we are trying to validate its operation.

That said, if there is an issue here, and we can come up with an appropriate
fix, then I'd be happy to write a patch for it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ks8851: Cancel any pending IRQ work
  2012-04-12 20:34   ` Matt Renzelmann
@ 2012-04-13 18:32     ` Stephen Boyd
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2012-04-13 18:32 UTC (permalink / raw)
  To: Matt Renzelmann; +Cc: davem, netdev, Ben Dooks

On 04/12/12 13:34, Matt Renzelmann wrote:
> I agree on all counts -- the patch is buggy, though it does at least "shrink"
> the window of vulnerability.  Frankly, I don't believe I'm qualified to write an
> appropriate patch for this driver, at least without spending considerably more
> time on it.
>
> FWIW, I found this problem with a new driver-testing tool we've developed called
> SymDrive, and my goal is primarily to determine if the bug is real or not.  The
> tool is imperfect and we are trying to validate its operation.

The bug is real if your interrupt controller is broken :-) One could
argue that it's outside the scope of this driver to handle broken
interrupt controllers or buggy genirq code, but being defensive sounds
like a good idea.

>
> That said, if there is an issue here, and we can come up with an appropriate
> fix, then I'd be happy to write a patch for it.
>

I'll see what I can do in the next few days about the deadlock I mentioned.

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-13 18:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-12 16:44 [PATCH] ks8851: Cancel any pending IRQ work mjr
2012-04-12 20:19 ` Stephen Boyd
2012-04-12 20:34   ` Matt Renzelmann
2012-04-13 18:32     ` Stephen Boyd

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.