Commit d89a2adb authored by Michael Chan's avatar Michael Chan Committed by David S. Miller

tg3: Fix vunmap() BUG_ON() triggered from tg3_free_consistent().

tg3_free_consistent() calls dma_free_coherent() to free tp->hw_stats
under spinlock and can trigger BUG_ON() in vunmap() because vunmap()
may sleep.  Fix it by removing the spinlock and relying on the
TG3_FLAG_INIT_COMPLETE flag to prevent race conditions between
tg3_get_stats64() and tg3_free_consistent().  TG3_FLAG_INIT_COMPLETE
is always cleared under tp->lock before tg3_free_consistent()
and therefore tg3_get_stats64() can safely access tp->hw_stats
under tp->lock if TG3_FLAG_INIT_COMPLETE is set.

Fixes: f5992b72 ("tg3: Fix race condition in tg3_get_stats64().")
Reported-by: default avatarZumeng Chen <zumeng.chen@gmail.com>
Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent af50e4ba
...@@ -8733,14 +8733,15 @@ static void tg3_free_consistent(struct tg3 *tp) ...@@ -8733,14 +8733,15 @@ static void tg3_free_consistent(struct tg3 *tp)
tg3_mem_rx_release(tp); tg3_mem_rx_release(tp);
tg3_mem_tx_release(tp); tg3_mem_tx_release(tp);
/* Protect tg3_get_stats64() from reading freed tp->hw_stats. */ /* tp->hw_stats can be referenced safely:
tg3_full_lock(tp, 0); * 1. under rtnl_lock
* 2. or under tp->lock if TG3_FLAG_INIT_COMPLETE is set.
*/
if (tp->hw_stats) { if (tp->hw_stats) {
dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats),
tp->hw_stats, tp->stats_mapping); tp->hw_stats, tp->stats_mapping);
tp->hw_stats = NULL; tp->hw_stats = NULL;
} }
tg3_full_unlock(tp);
} }
/* /*
...@@ -14178,7 +14179,7 @@ static void tg3_get_stats64(struct net_device *dev, ...@@ -14178,7 +14179,7 @@ static void tg3_get_stats64(struct net_device *dev,
struct tg3 *tp = netdev_priv(dev); struct tg3 *tp = netdev_priv(dev);
spin_lock_bh(&tp->lock); spin_lock_bh(&tp->lock);
if (!tp->hw_stats) { if (!tp->hw_stats || !tg3_flag(tp, INIT_COMPLETE)) {
*stats = tp->net_stats_prev; *stats = tp->net_stats_prev;
spin_unlock_bh(&tp->lock); spin_unlock_bh(&tp->lock);
return; return;
......
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