Commit 0486a063 authored by Ivan Vecera's avatar Ivan Vecera Committed by David S. Miller

tg3: prevent ifup/ifdown during PCI error recovery

The patch fixes race conditions between PCI error recovery callbacks and
potential ifup/ifdown.

First, if ifup (tg3_open) is called between tg3_io_error_detected() and
tg3_io_resume() then tp->timer is armed twice before expiry. Once during
tg3_open() and again during tg3_io_resume(). This results in BUG
at kernel/time/timer.c:945.

Second, if ifdown (tg3_close) is called between tg3_io_error_detected()
and tg3_io_resume() then tg3_napi_disable() is called twice without
a tg3_napi_enable between. Once during tg3_io_error_detected() and again
during tg3_close(). The tg3_io_resume() then hangs on rtnl_lock().

v2: Added logging messages per Prashant's request

Cc: Prashant Sreedharan <prashant@broadcom.com>
Cc: Michael Chan <mchan@broadcom.com>
Signed-off-by: default avatarIvan Vecera <ivecera@redhat.com>
Acked-by: default avatarPrashant Sreedharan <prashant@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 88e41947
...@@ -11617,6 +11617,12 @@ static int tg3_open(struct net_device *dev) ...@@ -11617,6 +11617,12 @@ static int tg3_open(struct net_device *dev)
struct tg3 *tp = netdev_priv(dev); struct tg3 *tp = netdev_priv(dev);
int err; int err;
if (tp->pcierr_recovery) {
netdev_err(dev, "Failed to open device. PCI error recovery "
"in progress\n");
return -EAGAIN;
}
if (tp->fw_needed) { if (tp->fw_needed) {
err = tg3_request_firmware(tp); err = tg3_request_firmware(tp);
if (tg3_asic_rev(tp) == ASIC_REV_57766) { if (tg3_asic_rev(tp) == ASIC_REV_57766) {
...@@ -11674,6 +11680,12 @@ static int tg3_close(struct net_device *dev) ...@@ -11674,6 +11680,12 @@ static int tg3_close(struct net_device *dev)
{ {
struct tg3 *tp = netdev_priv(dev); struct tg3 *tp = netdev_priv(dev);
if (tp->pcierr_recovery) {
netdev_err(dev, "Failed to close device. PCI error recovery "
"in progress\n");
return -EAGAIN;
}
tg3_ptp_fini(tp); tg3_ptp_fini(tp);
tg3_stop(tp); tg3_stop(tp);
...@@ -17561,6 +17573,7 @@ static int tg3_init_one(struct pci_dev *pdev, ...@@ -17561,6 +17573,7 @@ static int tg3_init_one(struct pci_dev *pdev,
tp->rx_mode = TG3_DEF_RX_MODE; tp->rx_mode = TG3_DEF_RX_MODE;
tp->tx_mode = TG3_DEF_TX_MODE; tp->tx_mode = TG3_DEF_TX_MODE;
tp->irq_sync = 1; tp->irq_sync = 1;
tp->pcierr_recovery = false;
if (tg3_debug > 0) if (tg3_debug > 0)
tp->msg_enable = tg3_debug; tp->msg_enable = tg3_debug;
...@@ -18071,6 +18084,8 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, ...@@ -18071,6 +18084,8 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
rtnl_lock(); rtnl_lock();
tp->pcierr_recovery = true;
/* We probably don't have netdev yet */ /* We probably don't have netdev yet */
if (!netdev || !netif_running(netdev)) if (!netdev || !netif_running(netdev))
goto done; goto done;
...@@ -18195,6 +18210,7 @@ static void tg3_io_resume(struct pci_dev *pdev) ...@@ -18195,6 +18210,7 @@ static void tg3_io_resume(struct pci_dev *pdev)
tg3_phy_start(tp); tg3_phy_start(tp);
done: done:
tp->pcierr_recovery = false;
rtnl_unlock(); rtnl_unlock();
} }
......
...@@ -3407,6 +3407,7 @@ struct tg3 { ...@@ -3407,6 +3407,7 @@ struct tg3 {
struct device *hwmon_dev; struct device *hwmon_dev;
bool link_up; bool link_up;
bool pcierr_recovery;
}; };
/* Accessor macros for chip and asic attributes /* Accessor macros for chip and asic attributes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment