* [PATCH wireless-next] wifi: mt76: use wait_event_interruptible in worker thread for PREEMPT_RT
@ 2026-04-07 3:27 Joshua Klinesmith
0 siblings, 0 replies; only message in thread
From: Joshua Klinesmith @ 2026-04-07 3:27 UTC (permalink / raw)
To: linux-wireless; +Cc: nbd, lorenzo, Joshua Klinesmith
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 <joshuaklinesmith@gmail.com>
---
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 <linux/skbuff.h>
#include <linux/bitops.h>
#include <linux/bitfield.h>
+#include <linux/wait.h>
#include <net/mac80211.h>
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-07 3:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 3:27 [PATCH wireless-next] wifi: mt76: use wait_event_interruptible in worker thread for PREEMPT_RT Joshua Klinesmith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox