From: Philipp Stanner <phasta@kernel.org>
To: "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>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] drm/sched: Guard sched->ready with ACCESS_ONCE()
Date: Mon, 29 Jun 2026 12:40:40 +0200 [thread overview]
Message-ID: <20260629104040.2695163-2-phasta@kernel.org> (raw)
commit faf6e1a87e07 ("drm/sched: Add boolean to mark if sched is ready to work v5")
moved tracking of the hardware ring's state from the driver (amdgpu in
that case) into drm_sched. To do so, it added a 'ready' flag to the
scheduler.
This flag is currently being accessed through drm_sched_wqueue_ready()
and, even worse, directly through the scheduler struct. Since drm_sched
does not have a consistent locking design, all these accesses are
potentially undefined behavior as they are subject to compiler
optimizations.
Make the code base more robust by guarding access to the 'ready' flag
with ACCESS_ONCE().
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
drivers/gpu/drm/scheduler/sched_main.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
index d2ca01b31ee4..c4e4ac436a86 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -929,7 +929,7 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list,
for (i = 0; i < num_sched_list; ++i) {
sched = sched_list[i];
- if (!sched->ready) {
+ if (!READ_ONCE(sched->ready)) {
DRM_WARN("scheduler %s is not ready, skipping",
sched->name);
continue;
@@ -1143,7 +1143,18 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)
if (sched->own_submit_wq)
destroy_workqueue(sched->submit_wq);
- sched->ready = false;
+
+ /* The 'ready' flag only exists in drm_sched because amdgpu uses it to
+ * represent the state of its hardware rings. This problem is related to
+ * the fundamental issue of drm_sched not having a solid, consistent
+ * locking design.
+ *
+ * Obviously, it does not make sense at all to set this flag to false
+ * here, but since it's unclear whether it can ever be removed from
+ * amdgpu's point of view, we guard it here with WRITE_ONCE() to make it
+ * slightly less broken.
+ */
+ WRITE_ONCE(sched->ready, false);
if (!list_empty(&sched->pending_list))
dev_warn(sched->dev, "Tearing down scheduler while jobs are pending!\n");
@@ -1195,7 +1206,7 @@ EXPORT_SYMBOL(drm_sched_increase_karma);
*/
bool drm_sched_wqueue_ready(struct drm_gpu_scheduler *sched)
{
- return sched->ready;
+ return READ_ONCE(sched->ready);
}
EXPORT_SYMBOL(drm_sched_wqueue_ready);
base-commit: 6648301c5bb2ef23f0fb15bcb01d21ff66f36799
--
2.54.0
next reply other threads:[~2026-06-29 10:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 10:40 Philipp Stanner [this message]
2026-06-29 10:40 ` [PATCH 2/2] drm/sched: Deprecate drm_sched_wqueue_ready() Philipp Stanner
2026-06-29 11:57 ` Danilo Krummrich
2026-06-29 12:09 ` [PATCH 1/2] drm/sched: Guard sched->ready with ACCESS_ONCE() Danilo Krummrich
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=20260629104040.2695163-2-phasta@kernel.org \
--to=phasta@kernel.org \
--cc=airlied@gmail.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox