Message ID | 20170918195919.15860-1-ville.syrjala@linux.intel.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Johannes Berg |
Headers | show |
> I got the following lockdep warning about the rcu_dereference()s in > ieee80211_tx_h_select_key(). After tracing all callers of > ieee80211_tx_h_select_key() I discovered that > ieee80211_get_buffered_bc() > and ieee80211_build_data_template() had the rcu_read_lock/unlock() > but > three other places did not. So I just blindly added them and made the > read side critical section extend as far as the lifetime of 'tx' > which > is where we seem to be stuffing the rcu protected pointers. No real > clue whether this is correct or not. Heh. I think we should do it in ieee80211_tx_dequeue(), if not even in the driver (and document that it's required) johannes > @@ -3411,6 +3430,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct > ieee80211_hw *hw, > ieee80211_tx_result r; > struct ieee80211_vif *vif; > > + rcu_read_lock(); > + > spin_lock_bh(&fq->lock); > > if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags)) > @@ -3513,6 +3534,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct > ieee80211_hw *hw, > out: > spin_unlock_bh(&fq->lock); > > + rcu_read_unlock(); > i.e. this in itself should be sufficient, though you should probably reorder and acquire the spinlock first since that might spin, and you want to keep the RCU section minimal (it's trivial here, after all) johannes
On Mon, Sep 18, 2017 at 10:11:17PM +0200, Johannes Berg wrote: > > I got the following lockdep warning about the rcu_dereference()s in > > ieee80211_tx_h_select_key(). After tracing all callers of > > ieee80211_tx_h_select_key() I discovered that > > ieee80211_get_buffered_bc() > > and ieee80211_build_data_template() had the rcu_read_lock/unlock() > > but > > three other places did not. So I just blindly added them and made the > > read side critical section extend as far as the lifetime of 'tx' > > which > > is where we seem to be stuffing the rcu protected pointers. No real > > clue whether this is correct or not. > > Heh. > > I think we should do it in ieee80211_tx_dequeue(), Oh, I guess I didn't trace the call chains far enough. ieee80211_tx() does indeed look OK. But unless I made another mistake in my analysis ieee80211_tx_prepare_skb() is still busted. > if not even in the > driver (and document that it's required) > > johannes > > > @@ -3411,6 +3430,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct > > ieee80211_hw *hw, > > ieee80211_tx_result r; > > struct ieee80211_vif *vif; > > > > + rcu_read_lock(); > > + > > spin_lock_bh(&fq->lock); > > > > if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags)) > > @@ -3513,6 +3534,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct > > ieee80211_hw *hw, > > out: > > spin_unlock_bh(&fq->lock); > > > > + rcu_read_unlock(); > > > > i.e. this in itself should be sufficient, though you should probably > reorder and acquire the spinlock first since that might spin, and you > want to keep the RCU section minimal (it's trivial here, after all) Good point. I'll respin with that change.
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 94826680cf2b..073022ee2462 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -1770,15 +1770,21 @@ bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw, struct ieee80211_tx_data tx; struct sk_buff *skb2; - if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP) + rcu_read_lock(); + + if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP) { + rcu_read_unlock(); return false; + } info->band = band; info->control.vif = vif; info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)]; - if (invoke_tx_handlers(&tx)) + if (invoke_tx_handlers(&tx)) { + rcu_read_unlock(); return false; + } if (sta) { if (tx.sta) @@ -1792,9 +1798,12 @@ bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw, if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) { ieee80211_free_txskb(hw, skb2); ieee80211_purge_tx_queue(hw, &tx.skbs); + rcu_read_unlock(); return false; } + rcu_read_unlock(); + return true; } EXPORT_SYMBOL(ieee80211_tx_prepare_skb); @@ -1818,14 +1827,18 @@ static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, return true; } + rcu_read_lock(); + /* initialises tx */ led_len = skb->len; res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb); if (unlikely(res_prepare == TX_DROP)) { ieee80211_free_txskb(&local->hw, skb); + rcu_read_unlock(); return true; } else if (unlikely(res_prepare == TX_QUEUED)) { + rcu_read_unlock(); return true; } @@ -1835,16 +1848,22 @@ static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)]; - if (invoke_tx_handlers_early(&tx)) + if (invoke_tx_handlers_early(&tx)) { + rcu_read_unlock(); return false; + } - if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb)) + if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb)) { + rcu_read_unlock(); return true; + } if (!invoke_tx_handlers_late(&tx)) result = __ieee80211_tx(local, &tx.skbs, led_len, tx.sta, txpending); + rcu_read_unlock(); + return result; } @@ -3411,6 +3430,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, ieee80211_tx_result r; struct ieee80211_vif *vif; + rcu_read_lock(); + spin_lock_bh(&fq->lock); if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags)) @@ -3513,6 +3534,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, out: spin_unlock_bh(&fq->lock); + rcu_read_unlock(); + return skb; } EXPORT_SYMBOL(ieee80211_tx_dequeue);