From: Joshua Klinesmith <joshuaklinesmith@gmail.com>
To: linux-wireless@vger.kernel.org
Cc: nbd@nbd.name, lorenzo@kernel.org,
Joshua Klinesmith <joshuaklinesmith@gmail.com>
Subject: [PATCH wireless-next] wifi: mt76: use wait_event_interruptible in worker thread for PREEMPT_RT
Date: Mon, 6 Apr 2026 23:27:12 -0400 [thread overview]
Message-ID: <20260407032712.57868-1-joshuaklinesmith@gmail.com> (raw)
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
reply other threads:[~2026-04-07 3:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260407032712.57868-1-joshuaklinesmith@gmail.com \
--to=joshuaklinesmith@gmail.com \
--cc=linux-wireless@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=nbd@nbd.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox