From: sashiko-bot@kernel.org
To: "Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/sched: Do not restore unsaved virtual runtime
Date: Fri, 14 Aug 2026 08:10:21 +0000 [thread overview]
Message-ID: <20260814081021.D0FAB1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260814075739.32481-2-tvrtko.ursulin@igalia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] A killed and stopped scheduler entity can be unconditionally added back to the runqueue's rbtree, leading to a use-after-free when the entity is subsequently freed by the driver.
--
--- Patch [1]: [PATCH 1/2] drm/sched: Do not restore unsaved virtual runtime ---
commit 8feac77c9420bd8a6d250c6a988250fe755b6870
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Subject: drm/sched: Do not restore unsaved virtual runtime
This patch modifies the queue push/pop and runqueue management paths in the
drm scheduler. It extends the scope of entity->lock to encompass both queue
management and rbtree updates. This prevents a race condition where a new job
could be pushed to an entity before its virtual runtime was correctly saved.
> diff --git a/drivers/gpu/drm/scheduler/sched_rq.c b/drivers/gpu/drm/scheduler/sched_rq.c
> index 0464d324d98d5..23f46ec610e78 100644
> --- a/drivers/gpu/drm/scheduler/sched_rq.c
> +++ b/drivers/gpu/drm/scheduler/sched_rq.c
[ ... ]
> @@ -343,16 +340,17 @@ drm_sched_rq_next_rr_ts(struct drm_sched_rq *rq,
> */
> void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)
> {
> + struct drm_sched_rq *rq = entity->rq;
> struct drm_sched_job *next_job;
> - struct drm_sched_rq *rq;
> +
> + lockdep_assert_held(&entity->lock);
> +
> + spin_lock(&rq->lock);
>
> /*
> * Update the entity's location in the min heap according to
> * the timestamp of the next job, if any.
> */
> - spin_lock(&entity->lock);
> - rq = entity->rq;
> - spin_lock(&rq->lock);
> next_job = drm_sched_entity_queue_peek(entity);
> if (next_job) {
[Severity: High]
This is a pre-existing issue, but can this lead to a use-after-free if the
entity is killed concurrently?
If drm_sched_entity_kill() in drivers/gpu/drm/scheduler/sched_entity.c is
called on an entity with multiple pending jobs concurrently with the scheduler
thread popping a job:
drm_sched_entity_kill() {
...
spin_lock(&entity->lock);
entity->stopped = true;
drm_sched_rq_remove_entity(entity->rq, entity);
spin_unlock(&entity->lock);
...
}
Meanwhile, the scheduler thread popping a job calls drm_sched_rq_pop_entity()
in drivers/gpu/drm/scheduler/sched_rq.c. Since next_job is not NULL, the code
takes this path and calls drm_sched_rq_update_fifo_locked(), which
unconditionally adds the entity back to the runqueue's rbtree, ignoring
entity->stopped.
When the killer thread wakes up and finishes, the entity is freed but still
linked in the rbtree, which corrupts the rbtree.
Should drm_sched_rq_pop_entity() check entity->stopped before re-adding the
entity to the runqueue, similar to the check in drm_sched_rq_add_entity()?
> ktime_t ts;
> @@ -375,8 +373,8 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)
> drm_sched_entity_save_vruntime(entity, min_vruntime);
> }
> }
> +
> spin_unlock(&rq->lock);
> - spin_unlock(&entity->lock);
> }
>
> /**
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260814075739.32481-1-tvrtko.ursulin@igalia.com?part=1
next prev parent reply other threads:[~2026-08-14 8:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 7:57 [PATCH 0/2] drm/sched: Fair policy fixups Tvrtko Ursulin
2026-08-14 7:57 ` [PATCH 1/2] drm/sched: Do not restore unsaved virtual runtime Tvrtko Ursulin
2026-08-14 8:10 ` sashiko-bot [this message]
2026-08-14 8:53 ` Matthew Brost
2026-08-14 9:58 ` Tvrtko Ursulin
2026-08-14 7:57 ` [PATCH 2/2] drm/sched: Ensure monotonic min_vruntime Tvrtko Ursulin
2026-08-14 8:09 ` sashiko-bot
2026-08-14 10:34 ` Tvrtko Ursulin
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=20260814081021.D0FAB1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tvrtko.ursulin@igalia.com \
/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.