From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
To: "Boris Brezillon" <boris.brezillon@collabora.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Philipp Stanner" <phasta@kernel.org>,
"Christian König" <ckoenig.leichtzumerken@gmail.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Luben Tuikov" <luben.tuikov@amd.com>,
phasta@kernel.org
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
kernel@collabora.com, stable@vger.kernel.org
Subject: Re: [PATCH] drm/sched: Sanitise wqueue_start/wqueue_stop/is_stopped interleavings
Date: Tue, 01 Dec 2026 14:18:59 +0100 [thread overview]
Message-ID: <gXbC6u14SCyzjtkwypJHIg@collabora.com> (raw)
In-Reply-To: <132b66f04e0ed601e45f721f777834b15bf05ed3.camel@mailbox.org>
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@kernel.org/
>
>
> 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.
>
prev parent reply other threads:[~2026-12-01 13:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 8:27 [PATCH] drm/sched: Sanitise wqueue_start/wqueue_stop/is_stopped interleavings Nicolas Frattaroli
2026-11-28 8:42 ` sashiko-bot
2026-11-30 9:24 ` Boris Brezillon
2026-11-30 16:31 ` Philipp Stanner
2026-12-01 7:56 ` Philipp Stanner
2026-12-01 13:18 ` Nicolas Frattaroli [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=gXbC6u14SCyzjtkwypJHIg@collabora.com \
--to=nicolas.frattaroli@collabora.com \
--cc=airlied@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luben.tuikov@amd.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=phasta@kernel.org \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.