The mt76 worker thread uses a manual set_current_state(TASK_INTERRUPTIBLE) / schedule() loop. On PREEMPT_RT kernels, this pattern triggers: BUG: scheduling while atomic: mt76-usb-rx phy/2852/0x00000002 The manual task state manipulation interacts poorly with RT's preemption model, where different locking and state transition semantics apply. Replace the open-coded sleep loop with wait_event_interruptible() on a new wait_queue_head embedded in struct mt76_worker. The schedule point becomes an RT-safe wait_event that properly handles the task state transitions. Update mt76_worker_schedule() to use wake_up() to signal the wait queue. This follows the standard kernel pattern for kthread wait loops and eliminates the need for manual set_current_state() calls entirely. Link: https://github.com/openwrt/mt76/issues/1053 Signed-off-by: Joshua Klinesmith --- drivers/net/wireless/mediatek/mt76/util.c | 8 ++++---- drivers/net/wireless/mediatek/mt76/util.h | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/util.c b/drivers/net/wireless/mediatek/mt76/util.c index 83d3dc42e534..452c303d8a68 100644 --- a/drivers/net/wireless/mediatek/mt76/util.c +++ b/drivers/net/wireless/mediatek/mt76/util.c @@ -111,20 +111,20 @@ int __mt76_worker_fn(void *ptr) struct mt76_worker *w = ptr; while (!kthread_should_stop()) { - set_current_state(TASK_INTERRUPTIBLE); - if (kthread_should_park()) { kthread_parkme(); continue; } if (!test_and_clear_bit(MT76_WORKER_SCHEDULED, &w->state)) { - schedule(); + wait_event_interruptible(w->wq, + test_bit(MT76_WORKER_SCHEDULED, &w->state) || + kthread_should_stop() || + kthread_should_park()); continue; } set_bit(MT76_WORKER_RUNNING, &w->state); - set_current_state(TASK_RUNNING); w->fn(w); cond_resched(); clear_bit(MT76_WORKER_RUNNING, &w->state); diff --git a/drivers/net/wireless/mediatek/mt76/util.h b/drivers/net/wireless/mediatek/mt76/util.h index 617966e8de76..a1ac52753a3f 100644 --- a/drivers/net/wireless/mediatek/mt76/util.h +++ b/drivers/net/wireless/mediatek/mt76/util.h @@ -9,12 +9,14 @@ #include #include #include +#include #include struct mt76_worker { struct task_struct *task; void (*fn)(struct mt76_worker *); + wait_queue_head_t wq; unsigned long state; }; @@ -63,6 +65,7 @@ mt76_worker_setup(struct ieee80211_hw *hw, struct mt76_worker *w, if (fn) w->fn = fn; + init_waitqueue_head(&w->wq); w->task = kthread_run(__mt76_worker_fn, w, "mt76-%s %s", name, dev_name); @@ -82,7 +85,7 @@ static inline void mt76_worker_schedule(struct mt76_worker *w) if (!test_and_set_bit(MT76_WORKER_SCHEDULED, &w->state) && !test_bit(MT76_WORKER_RUNNING, &w->state)) - wake_up_process(w->task); + wake_up(&w->wq); } static inline void mt76_worker_disable(struct mt76_worker *w) -- 2.43.0