Skip to content

Commit

Permalink
e1000: convert to private mutex from rtnl
Browse files Browse the repository at this point in the history
The e1000 driver when running with lockdep could run into
some possible deadlocks between the work items acquiring
rtnl and the rtnl lock being acquired before work items
were cancelled.

Use a private mutex to make sure lock ordering isn't violated.
The private mutex is only used to protect areas not generally
covered by the rtnl lock already.

Signed-off-by: Jesse Brandeburg <[email protected]>
CC: Thomas Gleixner <[email protected]>
CC: Tushar Dave <[email protected]>
Tested-by: Aaron Brown <[email protected]>
Signed-off-by: Jeff Kirsher <[email protected]>
  • Loading branch information
jbrandeb authored and Jeff Kirsher committed Oct 7, 2011
1 parent 4e0d8f7 commit 0ef4eed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
2 changes: 2 additions & 0 deletions drivers/net/ethernet/intel/e1000/e1000.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ struct e1000_adapter {
struct delayed_work watchdog_task;
struct delayed_work fifo_stall_task;
struct delayed_work phy_info_task;

struct mutex mutex;
};

enum e1000_state_t {
Expand Down
38 changes: 29 additions & 9 deletions drivers/net/ethernet/intel/e1000/e1000_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,10 @@ static void e1000_reinit_safe(struct e1000_adapter *adapter)
{
while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
msleep(1);
rtnl_lock();
mutex_lock(&adapter->mutex);
e1000_down(adapter);
e1000_up(adapter);
rtnl_unlock();
mutex_unlock(&adapter->mutex);
clear_bit(__E1000_RESETTING, &adapter->flags);
}

Expand Down Expand Up @@ -1317,6 +1317,7 @@ static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
e1000_irq_disable(adapter);

spin_lock_init(&adapter->stats_lock);
mutex_init(&adapter->mutex);

set_bit(__E1000_DOWN, &adapter->flags);

Expand Down Expand Up @@ -2331,9 +2332,11 @@ static void e1000_update_phy_info_task(struct work_struct *work)
struct e1000_adapter *adapter = container_of(work,
struct e1000_adapter,
phy_info_task.work);
rtnl_lock();
if (test_bit(__E1000_DOWN, &adapter->flags))
return;
mutex_lock(&adapter->mutex);
e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
rtnl_unlock();
mutex_unlock(&adapter->mutex);
}

/**
Expand All @@ -2349,7 +2352,9 @@ static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
struct net_device *netdev = adapter->netdev;
u32 tctl;

rtnl_lock();
if (test_bit(__E1000_DOWN, &adapter->flags))
return;
mutex_lock(&adapter->mutex);
if (atomic_read(&adapter->tx_fifo_stall)) {
if ((er32(TDT) == er32(TDH)) &&
(er32(TDFT) == er32(TDFH)) &&
Expand All @@ -2370,7 +2375,7 @@ static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
schedule_delayed_work(&adapter->fifo_stall_task, 1);
}
}
rtnl_unlock();
mutex_unlock(&adapter->mutex);
}

bool e1000_has_link(struct e1000_adapter *adapter)
Expand Down Expand Up @@ -2424,6 +2429,10 @@ static void e1000_watchdog(struct work_struct *work)
struct e1000_tx_ring *txdr = adapter->tx_ring;
u32 link, tctl;

if (test_bit(__E1000_DOWN, &adapter->flags))
return;

mutex_lock(&adapter->mutex);
link = e1000_has_link(adapter);
if ((netif_carrier_ok(netdev)) && link)
goto link_up;
Expand Down Expand Up @@ -2512,8 +2521,8 @@ static void e1000_watchdog(struct work_struct *work)
* (Do the reset outside of interrupt context). */
adapter->tx_timeout_count++;
schedule_work(&adapter->reset_task);
/* return immediately since reset is imminent */
return;
/* exit immediately since reset is imminent */
goto unlock;
}
}

Expand Down Expand Up @@ -2542,6 +2551,9 @@ static void e1000_watchdog(struct work_struct *work)
/* Reschedule the task */
if (!test_bit(__E1000_DOWN, &adapter->flags))
schedule_delayed_work(&adapter->watchdog_task, 2 * HZ);

unlock:
mutex_unlock(&adapter->mutex);
}

enum latency_range {
Expand Down Expand Up @@ -3248,6 +3260,8 @@ static void e1000_reset_task(struct work_struct *work)
struct e1000_adapter *adapter =
container_of(work, struct e1000_adapter, reset_task);

if (test_bit(__E1000_DOWN, &adapter->flags))
return;
e1000_reinit_safe(adapter);
}

Expand Down Expand Up @@ -4702,15 +4716,19 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)

netif_device_detach(netdev);

mutex_lock(&adapter->mutex);

if (netif_running(netdev)) {
WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
e1000_down(adapter);
}

#ifdef CONFIG_PM
retval = pci_save_state(pdev);
if (retval)
if (retval) {
mutex_unlock(&adapter->mutex);
return retval;
}
#endif

status = er32(STATUS);
Expand Down Expand Up @@ -4765,6 +4783,8 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
if (netif_running(netdev))
e1000_free_irq(adapter);

mutex_unlock(&adapter->mutex);

pci_disable_device(pdev);

return 0;
Expand Down

0 comments on commit 0ef4eed

Please sign in to comment.