* [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown()
@ 2019-12-18 14:01 Jia-Ju Bai
2019-12-18 14:30 ` Markus Elfring
2019-12-18 21:26 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Jia-Ju Bai @ 2019-12-18 14:01 UTC (permalink / raw)
To: thomas.lendacky, davem; +Cc: netdev, linux-kernel, Jia-Ju Bai
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown()
2019-12-18 14:01 [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown() Jia-Ju Bai
@ 2019-12-18 14:30 ` Markus Elfring
2019-12-18 21:26 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-12-18 14:30 UTC (permalink / raw)
To: Jia-Ju Bai, netdev; +Cc: linux-kernel, David S. Miller, Thomas Lendacky
> The function call path (from bottom to top) in Linux 4.19 is:
Does this Linux version need more adjustments than the current
development version?
> These bugs are found by a static analysis tool STCheck written
> by myself.
Would you like to point any more background information out
for this software?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown()
2019-12-18 14:01 [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown() Jia-Ju Bai
2019-12-18 14:30 ` Markus Elfring
@ 2019-12-18 21:26 ` David Miller
2019-12-19 2:40 ` Jia-Ju Bai
1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2019-12-18 21:26 UTC (permalink / raw)
To: baijiaju1990; +Cc: thomas.lendacky, netdev, linux-kernel
From: Jia-Ju Bai <baijiaju1990@gmail.com>
Date: Wed, 18 Dec 2019 22:01:02 +0800
> @@ -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);
> +
Nope, this doesn't work at all.
You can't leave NAPI enabled, and thus packet processing, after the TX
and RX units of the chip have been powered down.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown()
2019-12-18 21:26 ` David Miller
@ 2019-12-19 2:40 ` Jia-Ju Bai
0 siblings, 0 replies; 4+ messages in thread
From: Jia-Ju Bai @ 2019-12-19 2:40 UTC (permalink / raw)
To: David Miller; +Cc: thomas.lendacky, netdev, linux-kernel
On 2019/12/19 5:26, David Miller wrote:
> From: Jia-Ju Bai <baijiaju1990@gmail.com>
> Date: Wed, 18 Dec 2019 22:01:02 +0800
>
>> @@ -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);
>> +
> Nope, this doesn't work at all.
>
> You can't leave NAPI enabled, and thus packet processing, after the TX
> and RX units of the chip have been powered down.
Looking at the code, only xgbe_powerup() and xgbe_powerdown() use the
spinlock "pdata->lock".
How about change the spinlock to a mutex?
Best wishes,
Jia-Ju Bai
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-19 2:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18 14:01 [PATCH] net: amd: xgbe: fix possible sleep-in-atomic-context bugs in xgbe_powerdown() Jia-Ju Bai
2019-12-18 14:30 ` Markus Elfring
2019-12-18 21:26 ` David Miller
2019-12-19 2:40 ` Jia-Ju Bai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).