mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/sched: Extend locking in drm_sched_entity_select_rq()
@ 2026-11-17  9:37 Philipp Stanner
  2026-11-26 16:14 ` Philipp Stanner
  0 siblings, 1 reply; 3+ messages in thread
From: Philipp Stanner @ 2026-11-17  9:37 UTC (permalink / raw)
  To: Matthew Brost, Danilo Krummrich, Philipp Stanner,
	Christian König, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Tvrtko Ursulin
  Cc: dri-devel, linux-kernel

drm_sched_entity_select_rq() evaluates entity->sched_list locklessly,
which is elsewhere always lock-protected. Another lockless check regards
spsc_queue_count(). spsc_queue is evaluated under lock protection at
many places already and the plan is to replace it with fully locked
infrastructure anyways.

Move the spin_lock() in drm_sched_entity_select_rq() upwards.

Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 drivers/gpu/drm/scheduler/sched_entity.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 03e68b4102d5..3856d5e507d7 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -577,22 +577,21 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)
 	struct drm_gpu_scheduler *sched;
 	struct drm_sched_rq *rq;
 
+	spin_lock(&entity->lock);
+
 	/* single possible engine and already selected */
 	if (!entity->sched_list)
-		return;
+		goto unlock;
 
 	/* queue non-empty, stay on the same engine */
 	if (spsc_queue_count(&entity->job_queue))
-		return;
+		goto unlock;
 
-	spin_lock(&entity->lock);
 	fence = entity->last_scheduled;
 
 	/* stay on the same engine if the previous job hasn't finished */
-	if (fence && !dma_fence_is_signaled(fence)) {
-		spin_unlock(&entity->lock);
-		return;
-	}
+	if (fence && !dma_fence_is_signaled(fence))
+		goto unlock;
 
 	sched = drm_sched_pick_best(entity->sched_list, entity->num_sched_list);
 	rq = sched ? sched->sched_rq[entity->rq_priority] : NULL;
@@ -604,6 +603,7 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)
 	if (entity->num_sched_list == 1)
 		entity->sched_list = NULL;
 
+unlock:
 	spin_unlock(&entity->lock);
 }
 
-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/sched: Extend locking in drm_sched_entity_select_rq()
  2026-11-17  9:37 [PATCH] drm/sched: Extend locking in drm_sched_entity_select_rq() Philipp Stanner
@ 2026-11-26 16:14 ` Philipp Stanner
  2026-11-26 16:39   ` Tvrtko Ursulin
  0 siblings, 1 reply; 3+ messages in thread
From: Philipp Stanner @ 2026-11-26 16:14 UTC (permalink / raw)
  To: Philipp Stanner, Matthew Brost, Danilo Krummrich,
	Christian König, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Tvrtko Ursulin
  Cc: dri-devel, linux-kernel

On Tue, 2026-11-17 at 10:37 +0100, Philipp Stanner wrote:
> drm_sched_entity_select_rq() evaluates entity->sched_list locklessly,
> which is elsewhere always lock-protected. Another lockless check regards
> spsc_queue_count(). spsc_queue is evaluated under lock protection at
> many places already and the plan is to replace it with fully locked
> infrastructure anyways.
> 
> Move the spin_lock() in drm_sched_entity_select_rq() upwards.

Tvrtko, Christian, objections with merging that for now?

P.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/sched: Extend locking in drm_sched_entity_select_rq()
  2026-11-26 16:14 ` Philipp Stanner
@ 2026-11-26 16:39   ` Tvrtko Ursulin
  0 siblings, 0 replies; 3+ messages in thread
From: Tvrtko Ursulin @ 2026-11-26 16:39 UTC (permalink / raw)
  To: phasta, Matthew Brost, Danilo Krummrich, Christian König,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: dri-devel, linux-kernel


On 26/11/2026 16:14, Philipp Stanner wrote:
> On Tue, 2026-11-17 at 10:37 +0100, Philipp Stanner wrote:
>> drm_sched_entity_select_rq() evaluates entity->sched_list locklessly,
>> which is elsewhere always lock-protected. Another lockless check regards
>> spsc_queue_count(). spsc_queue is evaluated under lock protection at
>> many places already and the plan is to replace it with fully locked
>> infrastructure anyways.
>>
>> Move the spin_lock() in drm_sched_entity_select_rq() upwards.
> 
> Tvrtko, Christian, objections with merging that for now?

I don't have any huge objections but it is a bit underwhelming aka we 
don't get anything much with it really.

I was hoping my series which ends with "drm/sched: Address the fence_seq 
fixme" would get some more attention because it basically ends with a 
similar but perhaps a better result, where the lock actually goes one 
level up to drm_sched_job_arm and atomic_t fence_seq gets removed. So we 
can say there are some tangible benefits in that case.

But it is not just that series and the sched_list confusion it fixes, 
but also since in this commit message you elude to spsc queue removal, 
that's another one which we have sitting in limbo.

I mean it's all well and good moving spsc_queue_count under a lock but, 
again, it doesn't gain us much. In the spsc removal sketch I have for 
example demonstrated how that we can easily remove that 
spsc_queue_count, plus some spsc_queue_peeks. In theory that could be 
done even without the full spsc queue removal.

Perhaps we could close on all those opens somehow?

Regards,

Tvrtko


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-26 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  9:37 [PATCH] drm/sched: Extend locking in drm_sched_entity_select_rq() Philipp Stanner
2026-11-26 16:14 ` Philipp Stanner
2026-11-26 16:39   ` Tvrtko Ursulin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®