Skip to content

Commit 338c15e

Browse files
jbrandebdavem330
authored andcommitted
e1000: fix occasional panic on unload
Net drivers in general have an issue where timers fired by mod_timer or work threads with schedule_work are running outside of the rtnl_lock. With no other lock protection these routines are vulnerable to races with driver unload or reset paths. The longer term solution to this might be a redesign with safer locks being taken in the driver to guarantee no reentrance, but for now a safe and effective fix is to take the rtnl_lock in these routines. Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com> Tested-by: Jeff Pieper <jeffrey.e.pieper@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5cf42fc commit 338c15e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

drivers/net/e1000/e1000_main.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,21 @@ void e1000_down(struct e1000_adapter *adapter)
521521
e1000_clean_all_rx_rings(adapter);
522522
}
523523

524+
void e1000_reinit_safe(struct e1000_adapter *adapter)
525+
{
526+
while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
527+
msleep(1);
528+
rtnl_lock();
529+
e1000_down(adapter);
530+
e1000_up(adapter);
531+
rtnl_unlock();
532+
clear_bit(__E1000_RESETTING, &adapter->flags);
533+
}
534+
524535
void e1000_reinit_locked(struct e1000_adapter *adapter)
525536
{
537+
/* if rtnl_lock is not held the call path is bogus */
538+
ASSERT_RTNL();
526539
WARN_ON(in_interrupt());
527540
while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
528541
msleep(1);
@@ -2247,7 +2260,10 @@ static void e1000_update_phy_info_task(struct work_struct *work)
22472260
struct e1000_adapter,
22482261
phy_info_task);
22492262
struct e1000_hw *hw = &adapter->hw;
2263+
2264+
rtnl_lock();
22502265
e1000_phy_get_info(hw, &adapter->phy_info);
2266+
rtnl_unlock();
22512267
}
22522268

22532269
/**
@@ -2273,6 +2289,7 @@ static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
22732289
struct net_device *netdev = adapter->netdev;
22742290
u32 tctl;
22752291

2292+
rtnl_lock();
22762293
if (atomic_read(&adapter->tx_fifo_stall)) {
22772294
if ((er32(TDT) == er32(TDH)) &&
22782295
(er32(TDFT) == er32(TDFH)) &&
@@ -2293,6 +2310,7 @@ static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
22932310
mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
22942311
}
22952312
}
2313+
rtnl_unlock();
22962314
}
22972315

22982316
bool e1000_has_link(struct e1000_adapter *adapter)
@@ -3160,7 +3178,7 @@ static void e1000_reset_task(struct work_struct *work)
31603178
struct e1000_adapter *adapter =
31613179
container_of(work, struct e1000_adapter, reset_task);
31623180

3163-
e1000_reinit_locked(adapter);
3181+
e1000_reinit_safe(adapter);
31643182
}
31653183

31663184
/**

0 commit comments

Comments
 (0)