diff options
| author | Breno Leitao <leitao@debian.org> | 2026-05-07 14:04:46 +0300 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2026-05-08 20:59:27 +0300 |
| commit | a7488f089bdfa87c4fef1744d4dca9f4f8b46f8b (patch) | |
| tree | 34bc80d99fdef6e8716a948604a7ca278cdece26 /tools/lib/python/feat | |
| parent | 20e81c64c905bd765e69ef07920d2b1130dc79b6 (diff) | |
| download | linux-a7488f089bdfa87c4fef1744d4dca9f4f8b46f8b.tar.xz | |
workqueue: Release PENDING in __queue_work() drain/destroy reject path
The caller of __queue_work() owns WORK_STRUCT_PENDING, won via
test_and_set_bit() in queue_work_on()/__queue_delayed_work(). The
state machine documented above __queue_work() requires that owner
to either hand the token to a pwq (insert_work() -> set_work_pwq()),
hand it to a timer, or release it via set_work_pool_and_clear_pending().
try_to_grab_pending() relies on this: when it observes
"PENDING && off-queue" it busy-loops, trusting the current owner to
make progress.
The (__WQ_DESTROYING | __WQ_DRAINING) early-return path violates that
contract. It WARN_ONCE()s and bare-returns, leaving work->data with
PENDING set, WORK_STRUCT_PWQ clear, and work->entry empty.
The path is reachable without explicit API abuse: queue_delayed_work()
arms a timer with PENDING set; if drain_workqueue() runs while the
timer is still pending, delayed_work_timer_fn() -> __queue_work() in
softirq context hits the WARN, current is not a wq worker so
is_chained_work() is false, and the work is silently dropped with
PENDING leaked.
Mirror what clear_pending_if_disabled() already does on its analogous
reject path: unpack the off-queue data and call
set_work_pool_and_clear_pending() to release the token before
returning.
I was able to reproduce this by queueing several slow works on
a max_active=1 wq, arm a delayed_work whose timer fires while
drain_workqueue() is blocked, then call cancel_delayed_work_sync().
Without this patch the cancel livelocks at 100% CPU; with it the cancel
returns immediately.
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'tools/lib/python/feat')
0 files changed, 0 insertions, 0 deletions
