All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: net: hippi: Fix deadlock in rr_close()
@ 2022-04-17 12:55 Duoming Zhou
  2022-04-21  9:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Duoming Zhou @ 2022-04-17 12:55 UTC (permalink / raw)
  To: linux-kernel, jes; +Cc: netdev, linux-hippi, pabeni, kuba, davem, Duoming Zhou

There is a deadlock in rr_close(), which is shown below:

   (Thread 1)                |      (Thread 2)
                             | rr_open()
rr_close()                   |  add_timer()
 spin_lock_irqsave() //(1)   |  (wait a time)
 ...                         | rr_timer()
 del_timer_sync()            |  spin_lock_irqsave() //(2)
 (wait timer to stop)        |  ...

We hold rrpriv->lock in position (1) of thread 1 and
use del_timer_sync() to wait timer to stop, but timer handler
also need rrpriv->lock in position (2) of thread 2.
As a result, rr_close() will block forever.

This patch extracts del_timer_sync() from the protection of
spin_lock_irqsave(), which could let timer handler to obtain
the needed lock.

Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
 drivers/net/hippi/rrunner.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c
index 16105292b14..74e845fa2e0 100644
--- a/drivers/net/hippi/rrunner.c
+++ b/drivers/net/hippi/rrunner.c
@@ -1355,7 +1355,9 @@ static int rr_close(struct net_device *dev)
 
 	rrpriv->fw_running = 0;
 
+	spin_unlock_irqrestore(&rrpriv->lock, flags);
 	del_timer_sync(&rrpriv->timer);
+	spin_lock_irqsave(&rrpriv->lock, flags);
 
 	writel(0, &regs->TxPi);
 	writel(0, &regs->IpRxPi);
-- 
2.17.1


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

* Re: [PATCH] drivers: net: hippi: Fix deadlock in rr_close()
  2022-04-17 12:55 [PATCH] drivers: net: hippi: Fix deadlock in rr_close() Duoming Zhou
@ 2022-04-21  9:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-21  9:00 UTC (permalink / raw)
  To: Duoming Zhou; +Cc: linux-kernel, jes, netdev, linux-hippi, pabeni, kuba, davem

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Sun, 17 Apr 2022 20:55:19 +0800 you wrote:
> There is a deadlock in rr_close(), which is shown below:
> 
>    (Thread 1)                |      (Thread 2)
>                              | rr_open()
> rr_close()                   |  add_timer()
>  spin_lock_irqsave() //(1)   |  (wait a time)
>  ...                         | rr_timer()
>  del_timer_sync()            |  spin_lock_irqsave() //(2)
>  (wait timer to stop)        |  ...
> 
> [...]

Here is the summary with links:
  - drivers: net: hippi: Fix deadlock in rr_close()
    https://git.kernel.org/netdev/net/c/bc6de2878429

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-04-21  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-17 12:55 [PATCH] drivers: net: hippi: Fix deadlock in rr_close() Duoming Zhou
2022-04-21  9:00 ` patchwork-bot+netdevbpf

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.