Skip to content

Commit 13f61df

Browse files
LorenzoBianconiKalle Valo
authored andcommitted
mt76: fix schedule while atomic in mt76x02_reset_state
Fix following schedule while atomic in mt76x02_reset_state since synchronize_rcu is run inside a RCU section [44036.944222] mt76x2e 0000:06:00.0: MCU message 31 (seq 3) timed out [44036.944281] BUG: sleeping function called from invalid context at kernel/rcu/tree_exp.h:818 [44036.944284] in_atomic(): 1, irqs_disabled(): 0, pid: 28066, name: kworker/u4:1 [44036.944287] INFO: lockdep is turned off. [44036.944292] CPU: 1 PID: 28066 Comm: kworker/u4:1 Tainted: G W 5.0.0-rc7-wdn-t1+ #7 [44036.944294] Hardware name: Dell Inc. Studio XPS 1340/0K183D, BIOS A11 09/08/2009 [44036.944305] Workqueue: phy1 mt76x02_wdt_work [mt76x02_lib] [44036.944308] Call Trace: [44036.944317] dump_stack+0x67/0x90 [44036.944322] ___might_sleep.cold.88+0x9f/0xaf [44036.944327] rcu_blocking_is_gp+0x13/0x50 [44036.944330] synchronize_rcu+0x17/0x80 [44036.944337] mt76_sta_state+0x138/0x1d0 [mt76] [44036.944349] mt76x02_wdt_work+0x1c9/0x610 [mt76x02_lib] [44036.944355] process_one_work+0x2a5/0x620 [44036.944361] worker_thread+0x35/0x3e0 [44036.944368] kthread+0x11c/0x140 [44036.944376] ret_from_fork+0x3a/0x50 [44036.944384] BUG: scheduling while atomic: kworker/u4:1/28066/0x00000002 [44036.944387] INFO: lockdep is turned off. [44036.944389] Modules linked in: cmac ctr ccm af_packet snd_hda_codec_hdmi Introduce __mt76_sta_remove in order to run sta_remove without holding dev->mutex. Move __mt76_sta_remove outside of RCU section in mt76x02_reset_state Fixes: e4ebb8b403d1 ("mt76: mt76x2: implement full device restart on watchdog reset") Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
1 parent f2a00a8 commit 13f61df

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

drivers/net/wireless/mediatek/mt76/mac80211.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,27 +679,31 @@ mt76_sta_add(struct mt76_dev *dev, struct ieee80211_vif *vif,
679679
return ret;
680680
}
681681

682-
static void
683-
mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
684-
struct ieee80211_sta *sta)
682+
void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
683+
struct ieee80211_sta *sta)
685684
{
686685
struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
687-
int idx = wcid->idx;
688-
int i;
686+
int i, idx = wcid->idx;
689687

690688
rcu_assign_pointer(dev->wcid[idx], NULL);
691689
synchronize_rcu();
692690

693-
mutex_lock(&dev->mutex);
694-
695691
if (dev->drv->sta_remove)
696692
dev->drv->sta_remove(dev, vif, sta);
697693

698694
mt76_tx_status_check(dev, wcid, true);
699695
for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
700696
mt76_txq_remove(dev, sta->txq[i]);
701697
mt76_wcid_free(dev->wcid_mask, idx);
698+
}
699+
EXPORT_SYMBOL_GPL(__mt76_sta_remove);
702700

701+
static void
702+
mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
703+
struct ieee80211_sta *sta)
704+
{
705+
mutex_lock(&dev->mutex);
706+
__mt76_sta_remove(dev, vif, sta);
703707
mutex_unlock(&dev->mutex);
704708
}
705709

drivers/net/wireless/mediatek/mt76/mt76.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
695695
struct ieee80211_sta *sta,
696696
enum ieee80211_sta_state old_state,
697697
enum ieee80211_sta_state new_state);
698+
void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
699+
struct ieee80211_sta *sta);
698700

699701
struct ieee80211_sta *mt76_rx_convert(struct sk_buff *skb);
700702

drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,23 @@ static void mt76x02_reset_state(struct mt76x02_dev *dev)
441441
{
442442
int i;
443443

444+
lockdep_assert_held(&dev->mt76.mutex);
445+
444446
clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
445447

446448
rcu_read_lock();
447-
448449
ieee80211_iter_keys_rcu(dev->mt76.hw, NULL, mt76x02_key_sync, NULL);
450+
rcu_read_unlock();
449451

450452
for (i = 0; i < ARRAY_SIZE(dev->mt76.wcid); i++) {
451-
struct mt76_wcid *wcid = rcu_dereference(dev->mt76.wcid[i]);
452-
struct mt76x02_sta *msta;
453453
struct ieee80211_sta *sta;
454454
struct ieee80211_vif *vif;
455+
struct mt76x02_sta *msta;
456+
struct mt76_wcid *wcid;
455457
void *priv;
456458

459+
wcid = rcu_dereference_protected(dev->mt76.wcid[i],
460+
lockdep_is_held(&dev->mt76.mutex));
457461
if (!wcid)
458462
continue;
459463

@@ -463,13 +467,10 @@ static void mt76x02_reset_state(struct mt76x02_dev *dev)
463467
priv = msta->vif;
464468
vif = container_of(priv, struct ieee80211_vif, drv_priv);
465469

466-
mt76_sta_state(dev->mt76.hw, vif, sta,
467-
IEEE80211_STA_NONE, IEEE80211_STA_NOTEXIST);
470+
__mt76_sta_remove(&dev->mt76, vif, sta);
468471
memset(msta, 0, sizeof(*msta));
469472
}
470473

471-
rcu_read_unlock();
472-
473474
dev->vif_mask = 0;
474475
dev->beacon_mask = 0;
475476
}
@@ -489,11 +490,11 @@ static void mt76x02_watchdog_reset(struct mt76x02_dev *dev)
489490
for (i = 0; i < ARRAY_SIZE(dev->mt76.napi); i++)
490491
napi_disable(&dev->mt76.napi[i]);
491492

493+
mutex_lock(&dev->mt76.mutex);
494+
492495
if (restart)
493496
mt76x02_reset_state(dev);
494497

495-
mutex_lock(&dev->mt76.mutex);
496-
497498
if (dev->beacon_mask)
498499
mt76_clear(dev, MT_BEACON_TIME_CFG,
499500
MT_BEACON_TIME_CFG_BEACON_TX |

0 commit comments

Comments
 (0)