net: intel: e1000e: fix possible sleep-in-atomic-context bugs in e1000e_get_hw_semaphore()
diff mbox series

Message ID 20191218141656.12416-1-baijiaju1990@gmail.com
State Accepted
Delegated to: Jeff Kirsher
Headers show
Series
  • net: intel: e1000e: fix possible sleep-in-atomic-context bugs in e1000e_get_hw_semaphore()
Related show

Commit Message

Jia-Ju Bai Dec. 18, 2019, 2:16 p.m. UTC
The driver may sleep while holding a spinlock.
The function call path (from bottom to top) in Linux 4.19 is:

drivers/net/ethernet/intel/e1000e/mac.c, 1366: 
	usleep_range in e1000e_get_hw_semaphore
drivers/net/ethernet/intel/e1000e/80003es2lan.c, 322:
	e1000e_get_hw_semaphore in e1000_release_swfw_sync_80003es2lan
drivers/net/ethernet/intel/e1000e/80003es2lan.c, 197:
	e1000_release_swfw_sync_80003es2lan in e1000_release_phy_80003es2lan
drivers/net/ethernet/intel/e1000e/netdev.c, 4883: 
	(FUNC_PTR) e1000_release_phy_80003es2lan in e1000e_update_phy_stats
drivers/net/ethernet/intel/e1000e/netdev.c, 4917:
	e1000e_update_phy_stats in e1000e_update_stats
drivers/net/ethernet/intel/e1000e/netdev.c, 5945: 
	e1000e_update_stats in e1000e_get_stats64
drivers/net/ethernet/intel/e1000e/netdev.c, 5944: 
	spin_lock in e1000e_get_stats64

drivers/net/ethernet/intel/e1000e/mac.c, 1384: 
	usleep_range in e1000e_get_hw_semaphore
drivers/net/ethernet/intel/e1000e/80003es2lan.c, 322:
	e1000e_get_hw_semaphore in e1000_release_swfw_sync_80003es2lan
drivers/net/ethernet/intel/e1000e/80003es2lan.c, 197:
	e1000_release_swfw_sync_80003es2lan in e1000_release_phy_80003es2lan
drivers/net/ethernet/intel/e1000e/netdev.c, 4883: 
	(FUNC_PTR) e1000_release_phy_80003es2lan in e1000e_update_phy_stats
drivers/net/ethernet/intel/e1000e/netdev.c, 4917:
	e1000e_update_phy_stats in e1000e_update_stats
drivers/net/ethernet/intel/e1000e/netdev.c, 5945: 
	e1000e_update_stats in e1000e_get_stats64
drivers/net/ethernet/intel/e1000e/netdev.c, 5944: 
	spin_lock in e1000e_get_stats64

(FUNC_PTR) means a function pointer is called.

To fix these bugs, usleep_range() is replaced with udelay().

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/intel/e1000e/mac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Brown, Aaron F Jan. 9, 2020, 1:01 a.m. UTC | #1
> From: netdev-owner@vger.kernel.org <netdev-owner@vger.kernel.org>
> On Behalf Of Jia-Ju Bai
> Sent: Wednesday, December 18, 2019 6:17 AM
> To: Kirsher, Jeffrey T <jeffrey.t.kirsher@intel.com>; davem@davemloft.net
> Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; Jia-Ju Bai <baijiaju1990@gmail.com>
> Subject: [PATCH] net: intel: e1000e: fix possible sleep-in-atomic-context bugs
> in e1000e_get_hw_semaphore()
> 
> The driver may sleep while holding a spinlock.
> The function call path (from bottom to top) in Linux 4.19 is:
> 
> drivers/net/ethernet/intel/e1000e/mac.c, 1366:
> 	usleep_range in e1000e_get_hw_semaphore
> drivers/net/ethernet/intel/e1000e/80003es2lan.c, 322:
> 	e1000e_get_hw_semaphore in
> e1000_release_swfw_sync_80003es2lan
> drivers/net/ethernet/intel/e1000e/80003es2lan.c, 197:
> 	e1000_release_swfw_sync_80003es2lan in
> e1000_release_phy_80003es2lan
> drivers/net/ethernet/intel/e1000e/netdev.c, 4883:
> 	(FUNC_PTR) e1000_release_phy_80003es2lan in
> e1000e_update_phy_stats
> drivers/net/ethernet/intel/e1000e/netdev.c, 4917:
> 	e1000e_update_phy_stats in e1000e_update_stats
> drivers/net/ethernet/intel/e1000e/netdev.c, 5945:
> 	e1000e_update_stats in e1000e_get_stats64
> drivers/net/ethernet/intel/e1000e/netdev.c, 5944:
> 	spin_lock in e1000e_get_stats64
> 
> drivers/net/ethernet/intel/e1000e/mac.c, 1384:
> 	usleep_range in e1000e_get_hw_semaphore
> drivers/net/ethernet/intel/e1000e/80003es2lan.c, 322:
> 	e1000e_get_hw_semaphore in
> e1000_release_swfw_sync_80003es2lan
> drivers/net/ethernet/intel/e1000e/80003es2lan.c, 197:
> 	e1000_release_swfw_sync_80003es2lan in
> e1000_release_phy_80003es2lan
> drivers/net/ethernet/intel/e1000e/netdev.c, 4883:
> 	(FUNC_PTR) e1000_release_phy_80003es2lan in
> e1000e_update_phy_stats
> drivers/net/ethernet/intel/e1000e/netdev.c, 4917:
> 	e1000e_update_phy_stats in e1000e_update_stats
> drivers/net/ethernet/intel/e1000e/netdev.c, 5945:
> 	e1000e_update_stats in e1000e_get_stats64
> drivers/net/ethernet/intel/e1000e/netdev.c, 5944:
> 	spin_lock in e1000e_get_stats64
> 
> (FUNC_PTR) means a function pointer is called.
> 
> To fix these bugs, usleep_range() is replaced with udelay().
> 
> 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/intel/e1000e/mac.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 

Tested-by: Aaron Brown <aaron.f.brown@intel.com>

Patch
diff mbox series

diff --git a/drivers/net/ethernet/intel/e1000e/mac.c b/drivers/net/ethernet/intel/e1000e/mac.c
index e531976f8a67..51512a73fdd0 100644
--- a/drivers/net/ethernet/intel/e1000e/mac.c
+++ b/drivers/net/ethernet/intel/e1000e/mac.c
@@ -1363,7 +1363,7 @@  s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
 		if (!(swsm & E1000_SWSM_SMBI))
 			break;
 
-		usleep_range(50, 100);
+		udelay(100);
 		i++;
 	}
 
@@ -1381,7 +1381,7 @@  s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
 		if (er32(SWSM) & E1000_SWSM_SWESMBI)
 			break;
 
-		usleep_range(50, 100);
+		udelay(100);
 	}
 
 	if (i == timeout) {