Re: [PATCH] drm/sched: Sanitise wqueue_start/wqueue_stop/is_stopped interleavings
From: Nicolas Frattaroli
Date: Tue Dec 01 2026 - 08:19:37 EST
On Tuesday, 1 December 2026 08:56:35 Central European Standard Time Philipp Stanner wrote:
> 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/20261124122951.878199-11-phasta@xxxxxxxxxx/
>
>
> 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?
Will do. My current solution also has a deadlock according to both
sashiko and casual reading of the code, but funnily enough I could
not yet trigger a lockdep splat by running both code paths. Basically
work_tdr can and will start/stop the drm_sched as well, so synchronously
disabling it while holding the pause_lock in drm_sched_fini is a bad idea.
In practice, lockdep has somehow not complained, despite me confirming with
ftrace that both the timedout function ran and the drm_sched_fini function
ran. I guess because in none of those executions, the timedout thread
synchronised with drm_sched_fini? Who knows.
Kind regards,
Nicolas Frattaroli
>
>
> Thx
> P.
>