Issue #3489 has been updated by sigttou.
I had been working on the same defect and a few neighbours in linux_workqueue.c and have just opened a PR with a fix for it: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/75 (commit 4, "drm: claim the worker for a work item atomically") the others fix a @flush_workqueue()@ lost wakeup that hangs the i915 execbuffer slow path, @flush_work()@/@cancel_work_sync()@ returning early, @drain_workqueue()@ sleeping with the worker lock held, a per-cpu flush and a busy-spin in cancel). Reading your patch, I think one thing is wrong: @process_all_work()@ clears @work->worker@ before @work->running@ (both under the finishing worker's lock). In between, @queue_work()@ on another cpu reads @worker == NULL@, claims its own worker and inserts the item. That worker's @process_all_work()@ then reaches @KKASSERT(work->running == false)@ while the first worker has not cleared @running@ yet. The window is only few instructions and I haven't run into it. Clearing @->running@ first, then a barrier, then @->worker@ when the item was not queued again, is my approach there. The canceled skip and @_cancel_work()@ leave @->worker@ set, so those items stay with their old worker (clearing it on those two paths makes the comment about claiming the cpu's worker true again). @queue_work(B, item)@ for an item still owned by a worker of workqueue A queues it on A, so @flush_workqueue(B)@ misses it (stricter than Linux, probably fine) In @wqtest.c@ @stuck@ is printed but never counted as a failure(?) ---------------------------------------- Bug #3489: drm: queue_work() drops a work item that is running on another cpu http://bugs.dragonflybsd.org/issues/3489#change-15000 * Author: tuxillo * Status: New * Priority: Normal * Target version: 6.6 * Start date: 2026-11-29 ---------------------------------------- As of master 98c93bc104, a work item queued with queue_work() or schedule_work() while it runs on another cpu's worker never runs again, although queue_work() returns true. system_wq and every workqueue without @WQ_UNBOUND@ have a worker per cpu. A driver that queues work from an interrupt to pick up new completions can lose a wakeup when the interrupt comes on another cpu while the previous run is finishing. queue_work() in sys/dev/drm/linux_workqueue.c puts the item on the calling cpu's worker, whose process_all_work() then sees @work->running@ and skips it. On Linux the item runs again after the current run. queue_work() also takes only the calling cpu's worker lock, so two cpus queueing the same idle item can both put it on their lists, and it returns true for an item that is already queued. The attached patch gives a work item to one worker from the time it is queued until it has run (@work->worker@, claimed with a compare-and-set). Queueing it again meanwhile goes to that worker, so it runs again after the current run and never on two workers at once. queue_work() returns true only when it queued the item, and INIT_WORK() clears @work->worker@. The attached wqtest.c module queues an item on system_wq from chosen cpus, 100 trials per test. In an 8-vCPU QEMU guest and on a 12-thread desktop: <pre> master patch queued from another cpu while it ran ran again 0 ran again 100 two cpus queue it at once 20-40 queues none lost lost ran on two cpus at once 2 (desktop) 0 </pre> A requeue from the same cpu, cancel_work_sync() and flush_work() behave as before, and radeon still loads and initializes on the desktop. I found this by reading the code and haven't caught a driver losing a wakeup. ---Files-------------------------------- wqtest.c (7.72 KB) Makefile (247 Bytes) 0001-drm-run-a-work-item-queued-while-it-runs-and-queue-i.patch (5.34 KB) -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account
