From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: thomas.lendacky@amd.com, davem@davemloft.net
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown()
Date: Wed, 18 Dec 2019 22:01:02 +0800 [thread overview]
Message-ID: <20191218140102.11579-1-baijiaju1990@gmail.com> (raw)
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
next reply other threads:[~2019-12-18 14:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-18 14:01 Jia-Ju Bai [this message]
2019-12-18 14:30 ` Markus Elfring
2019-12-18 21:26 ` David Miller
2019-12-19 2:40 ` Jia-Ju Bai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191218140102.11579-1-baijiaju1990@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®