On Sat, 2026-11-28 at 09:27 +0100, Nicolas Frattaroli wrote: > drm_sched_wqueue_stop() will WRITE_ONCE 1 to the sched's pause_submit > member. This member is checked (with READ_ONCE) in every > drm_sched_run_job_queue() and drm_sched_run_free_queue() invocation, > which is how the two work items drm_sched_wqueue_stop() cancels would > usually get re-armed. > > However, this is of little consequence on SMP systems, where the effect > of WRITE_ONCE is not guaranteed to be ordered with READ_ONCE calls on > other CPUs. As a consequence, during drm_sched_fini(), a work item may > become re-armed after its call to drm_sched_wqueue_stop(), and run into > a sched->sched_rq that is now NULL, dereferencing a NULL pointer.
I just realize that we have recently solved basically the same issue for drm::JobQueue. https://lore.kernel.org/rust-for-linux/[email protected]/ We need to park and unpark the queue. We do that for scheduling- reasons, but the addressed issue is basically the same since we also use it to halt the run_worker in our JobQueue deconstructor. The mechanism is based on an atomic bool + srcu to wait for everyone to have seen the flag. Only then do we tear down. The flag is checked in the worker, so no matter who might kick the worker when for what reason, it will never access freed resources. Maybe you can draw inspiration from that and see whether a mechanism like that could address the observed problem in drm_sched? Thx P.
