lkml.org 
[lkml]   [2019]   [Dec]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown()
Date
The driver may sleep while holding a spinlock.
The function call path (from bottom to top) in Linux 4.19 is:

drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1261:
flush_workqueue in xgbe_powerdown
drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1253:
_raw_spin_lock_irqsave in xgbe_powerdown

drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1055:
napi_disable in xgbe_napi_disable
drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1266:
xgbe_napi_disable in xgbe_powerdown
drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1253:
_raw_spin_lock_irqsave in xgbe_powerdown

drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1049:
napi_disable in xgbe_napi_disable
drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1266:
xgbe_napi_disable in xgbe_powerdown
drivers/net/ethernet/amd/xgbe/xgbe-drv.c, 1253:
_raw_spin_lock_irqsave in xgbe_powerdown

flush_workqueue() and napi_disable() can sleep at runtime.

To fix these bugs, flush_workqueue() and xgbe_napi_disable() are called
without holding the spinlock.

These bugs are found by a static analysis tool STCheck written by
myself.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
index 98f8f2033154..328361d0e190 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -1257,17 +1257,18 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
netif_tx_stop_all_queues(netdev);

xgbe_stop_timers(pdata);
- flush_workqueue(pdata->dev_workqueue);

hw_if->powerdown_tx(pdata);
hw_if->powerdown_rx(pdata);

- xgbe_napi_disable(pdata, 0);
-
pdata->power_down = 1;

spin_unlock_irqrestore(&pdata->lock, flags);

+ flush_workqueue(pdata->dev_workqueue);
+
+ xgbe_napi_disable(pdata, 0);
+
DBGPR("<--xgbe_powerdown\n");

return 0;
--
2.17.1
\
 
 \ /
  Last update: 2019-12-18 15:01    [W:0.033 / U:11.948 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site