Re: [PATCH v2 5/5] kthread: remove worker->task self assignment
From: sashiko-bot@kernel.org
Date: 2026-09-05 09:40:39
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Removing the self-assignment `worker->task = current;` breaks out-of-tree (OOT) users of the old `kthread_run(kthread_worker_fn, ...)` API, causing them to permanently deadlock due to missed wakeups. -- commit 4e8323d40e4fe5053d4171cbca8193f9bd6080b8 Author: Bradley Morgan [off-list ref] kthread: remove worker->task self assignment All kthread worker users now create their workers with kthread_create_worker*(), which sets worker->task before the worker starts. The self assignment in kthread_worker_fn() is removed, leaving a warning check for out-of-tree users.
quoted hunk ↗ jump to hunk
diff --git a/kernel/kthread.c b/kernel/kthread.c index 63beb59b7a3d1..643407647e79d 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c@@ -987,12 +987,10 @@ int kthread_worker_fn(void *worker_ptr) struct kthread_worker *worker = worker_ptr; struct kthread_work *work; - /* - * FIXME: Update the check and remove the assignment when all kthread - * worker users are created using kthread_create_worker*() functions. + /* All workers are created with worker->task set. If this fires, + * the caller is broken. */ - WARN_ON(worker->task && worker->task != current); - worker->task = current; + WARN_ON(worker->task != current);
[Severity: Medium]
Does removing this assignment cause out-of-tree users of the old
kthread_run() API to hang permanently?
Because the self-assignment is removed, worker->task will remain NULL for any
callers still using the old API. When new work is inserted, the wakeup will be
silently skipped in kthread_insert_work():
kernel/kthread.c:kthread_insert_work() {
...
if (!worker->current_work && likely(worker->task))
wake_up_process(worker->task);
...
}
This means the warning intended as a sanity check turns into a silent, fatal
breakage where the worker hangs in TASK_INTERRUPTIBLE and queued work is never
processed.
if (worker->flags & KTW_FREEZABLE) set_freezable();
-- Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788513591.git.brads@mainlining.org?part=5