mt76: add missing locking around ampdu action
Subsystems (2)
Felix Fietkau
maintainerPATCH 1/4 mt76: add missing locking around ampdu action
This is needed primarily to avoid races in dealing with rx aggregation related data structures
--- drivers/net/wireless/mediatek/mt76/mt7603/main.c | 2 ++ drivers/net/wireless/mediatek/mt76/mt7615/main.c | 2 ++ drivers/net/wireless/mediatek/mt76/mt76x02_util.c | 2 ++ 3 files changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7603/main.c +2 -0
@@ -569,6 +569,7 @@ mt7603_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mtxq = (struct mt76_txq *)txq->drv_priv; +mutex_lock (&dev->mt76.mutex);switch (action) {case IEEE80211_AMPDU_RX_START : mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
@@ -598,6 +599,7 @@ mt7603_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,ieee80211_stop_tx_ba_cb_irqsafe (vif, sta->addr, tid);break ; } +mutex_unlock (&dev->mt76.mutex);return 0 ; }
drivers/net/wireless/mediatek/mt76/mt7615/main.c +2 -0
@@ -483,6 +483,7 @@ mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mtxq = (struct mt76_txq *)txq->drv_priv; +mutex_lock (&dev->mt76.mutex);switch (action) {case IEEE80211_AMPDU_RX_START : mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
@@ -513,6 +514,7 @@ mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,ieee80211_stop_tx_ba_cb_irqsafe (vif, sta->addr, tid);break ; } +mutex_unlock (&dev->mt76.mutex);return 0 ; }
drivers/net/wireless/mediatek/mt76/mt76x02_util.c +2 -0
@@ -372,6 +372,7 @@ int mt76x02_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, mtxq = (struct mt76_txq *)txq->drv_priv; +mutex_lock (&dev->mt76.mutex);switch (action) {case IEEE80211_AMPDU_RX_START : mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid,
@@ -401,6 +402,7 @@ int mt76x02_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,ieee80211_stop_tx_ba_cb_irqsafe (vif, sta->addr, tid);break ; } +mutex_unlock (&dev->mt76.mutex);return 0 ; }
Signature · 1 line
2.17.0
Felix Fietkau
maintainerPATCH 2/4 mt76: drop rcu read lock in mt76_rx_aggr_stop
A rcu read locked section is not allowed to sleep, and the rcu lock here isn't actually necessary, because we're holding dev->mutex. Fixes an issue when the tid work item is still running while freeing a station or stopping the aggregation session
--- drivers/net/wireless/mediatek/mt76/agg-rx.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/agg-rx.c +3 -7
@@ -277,17 +277,13 @@ static void mt76_rx_aggr_shutdown(struct mt76_dev *dev, struct mt76_rx_tid *tid)void mt76_rx_aggr_stop (struct mt76_dev *dev,struct mt76_wcid *wcid,u8 tidno) { -struct mt76_rx_tid *tid; - -rcu_read_lock (); +struct mt76_rx_tid *tid =NULL ; - tid =rcu_dereference (wcid->aggr[tidno]); +rcu_swap_protected (wcid->aggr[tidno], tid, +lockdep_is_held (&dev->mutex));if (tid) { -rcu_assign_pointer (wcid->aggr[tidno],NULL );mt76_rx_aggr_shutdown (dev, tid);kfree_rcu (tid, rcu_head); } - -rcu_read_unlock (); }EXPORT_SYMBOL_GPL (mt76_rx_aggr_stop);
Signature · 1 line
2.17.0
Felix Fietkau
maintainerPATCH 3/4 mt76: fix aggregation stop issue
In reply to Felix FietkauCancel the workqueue after the tid has been cleaned up, in order to avoid a possible rescheduling from within the work function.
--- drivers/net/wireless/mediatek/mt76/agg-rx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/agg-rx.c +6 -4
@@ -130,8 +130,10 @@ mt76_rx_aggr_check_ctl(struct sk_buff *skb, struct sk_buff_head *frames)return ;spin_lock_bh (&tid->lock); -mt76_rx_aggr_release_frames (tid, frames, seqno); -mt76_rx_aggr_release_head (tid, frames); +if (!tid->stopped) { +mt76_rx_aggr_release_frames (tid, frames, seqno); +mt76_rx_aggr_release_head (tid, frames); + }spin_unlock_bh (&tid->lock); }
@@ -257,8 +259,6 @@ static void mt76_rx_aggr_shutdown(struct mt76_dev *dev, struct mt76_rx_tid *tid)u8 size = tid->size;int i; -cancel_delayed_work_sync (&tid->reorder_work); -spin_lock_bh (&tid->lock); tid->stopped = true;
@@ -273,6 +273,8 @@ static void mt76_rx_aggr_shutdown(struct mt76_dev *dev, struct mt76_rx_tid *tid) }spin_unlock_bh (&tid->lock); + +cancel_delayed_work_sync (&tid->reorder_work); }void mt76_rx_aggr_stop (struct mt76_dev *dev,struct mt76_wcid *wcid,u8 tidno)
Signature · 1 line
2.17.0
Felix Fietkau
maintainerPATCH 4/4 mt76: avoid enabling interrupt if NAPI poll is still pending
In reply to Felix Fietkauif napi_complete() returns false, it means that polling is still pending. Interrupts should not fire until the polling is no longer scheduled
--- drivers/net/wireless/mediatek/mt76/dma.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/dma.c +1 -3
@@ -537,10 +537,8 @@ mt76_dma_rx_poll(struct napi_struct *napi, int budget)rcu_read_unlock (); -if (done < budget) { -napi_complete (napi); +if (done < budget &&napi_complete (napi)) dev->drv->rx_poll_complete (dev, qid); - }return done; }
Signature · 1 line
2.17.0