diff options
author | Duoming Zhou <duoming@zju.edu.cn> | 2022-04-17 20:55:19 +0800 |
---|---|---|
committer | Paolo Abeni <pabeni@redhat.com> | 2022-04-21 10:30:45 +0200 |
commit | bc6de2878429e85c1f1afaa566f7b5abb2243eef (patch) | |
tree | 5f6c2e9d9c4f2a660332a774412fbe89bc21272f | |
parent | 5e6242151d7f17b056a82ca7b860c4ec8eaa7589 (diff) | |
download | linux-stable-bc6de2878429e85c1f1afaa566f7b5abb2243eef.tar.gz linux-stable-bc6de2878429e85c1f1afaa566f7b5abb2243eef.tar.bz2 linux-stable-bc6de2878429e85c1f1afaa566f7b5abb2243eef.zip |
drivers: net: hippi: Fix deadlock in rr_close()
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>
Link: https://lore.kernel.org/r/20220417125519.82618-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-rw-r--r-- | drivers/net/hippi/rrunner.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c index 16105292b140..74e845fa2e07 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, ®s->TxPi); writel(0, ®s->IpRxPi); |