Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/sched: Increment job count before swapping tail spsc queue
@ 2025-06-13 21:20 Matthew Brost
  2025-06-13 22:03 ` Cavitt, Jonathan
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Matthew Brost @ 2025-06-13 21:20 UTC (permalink / raw)
  To: intel-xe, dri-devel; +Cc: dakr, christian.koenig, pstanner

A small race exists between spsc_queue_push and the run-job worker, in
which spsc_queue_push may return not-first while the run-job worker has
already idled due to the job count being zero. If this race occurs, job
scheduling stops, leading to hangs while waiting on the job’s DMA
fences.

Seal this race by incrementing the job count before appending to the
SPSC queue.

This race was observed on a drm-tip 6.16-rc1 build with the Xe driver in
an SVM test case.

Fixes: 1b1f42d8fde4 ("drm: move amd_gpu_scheduler into common location")
Fixes: 27105db6c63a ("drm/amdgpu: Add SPSC queue to scheduler.")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 include/drm/spsc_queue.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/drm/spsc_queue.h b/include/drm/spsc_queue.h
index 125f096c88cb..ee9df8cc67b7 100644
--- a/include/drm/spsc_queue.h
+++ b/include/drm/spsc_queue.h
@@ -70,9 +70,11 @@ static inline bool spsc_queue_push(struct spsc_queue *queue, struct spsc_node *n
 
 	preempt_disable();
 
+	atomic_inc(&queue->job_count);
+	smp_mb__after_atomic();
+
 	tail = (struct spsc_node **)atomic_long_xchg(&queue->tail, (long)&node->next);
 	WRITE_ONCE(*tail, node);
-	atomic_inc(&queue->job_count);
 
 	/*
 	 * In case of first element verify new node will be visible to the consumer
-- 
2.34.1


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

end of thread, other threads:[~2025-07-01 23:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13 21:20 [PATCH] drm/sched: Increment job count before swapping tail spsc queue Matthew Brost
2025-06-13 22:03 ` Cavitt, Jonathan
2025-06-14  0:18 ` ✗ CI.checkpatch: warning for " Patchwork
2025-06-14  0:19 ` ✓ CI.KUnit: success " Patchwork
2025-06-14  0:56 ` ✓ Xe.CI.BAT: " Patchwork
2025-06-16  1:36 ` ✓ Xe.CI.Full: " Patchwork
2025-07-01  7:40 ` [PATCH] " Christian König
2025-07-01 23:19   ` Matthew Brost

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