Skip to content

Commit 80b6ef8

Browse files
Tvrtko UrsulinPhilipp Stanner
authored andcommitted
drm/amdgpu: Pop jobs from the queue more robustly
Replace a copy of DRM scheduler's to_drm_sched_job with a copy of a newly added drm_sched_entity_queue_pop. This allows breaking the hidden dependency that queue_node has to be the first element in struct drm_sched_job. A comment is also added with a reference to the mailing list discussion explaining the copied helper will be removed when the whole broken amdgpu_job_stop_all_jobs_on_sched is removed. Signed-off-by: Tvrtko Ursulin <[email protected]> Cc: Christian König <[email protected]> Cc: Danilo Krummrich <[email protected]> Cc: Matthew Brost <[email protected]> Cc: Philipp Stanner <[email protected]> Cc: Zhang, Hawking <[email protected]> Reviewed-by: Christian König <[email protected]> Signed-off-by: Philipp Stanner <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent b6eb664 commit 80b6ef8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,24 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)
411411
return fence;
412412
}
413413

414-
#define to_drm_sched_job(sched_job) \
415-
container_of((sched_job), struct drm_sched_job, queue_node)
414+
/*
415+
* This is a duplicate function from DRM scheduler sched_internal.h.
416+
* Plan is to remove it when amdgpu_job_stop_all_jobs_on_sched is removed, due
417+
* latter being incorrect and racy.
418+
*
419+
* See https://lore.kernel.org/amd-gfx/[email protected]/
420+
*/
421+
static struct drm_sched_job *
422+
drm_sched_entity_queue_pop(struct drm_sched_entity *entity)
423+
{
424+
struct spsc_node *node;
425+
426+
node = spsc_queue_pop(&entity->job_queue);
427+
if (!node)
428+
return NULL;
429+
430+
return container_of(node, struct drm_sched_job, queue_node);
431+
}
416432

417433
void amdgpu_job_stop_all_jobs_on_sched(struct drm_gpu_scheduler *sched)
418434
{
@@ -425,7 +441,7 @@ void amdgpu_job_stop_all_jobs_on_sched(struct drm_gpu_scheduler *sched)
425441
struct drm_sched_rq *rq = sched->sched_rq[i];
426442
spin_lock(&rq->lock);
427443
list_for_each_entry(s_entity, &rq->entities, list) {
428-
while ((s_job = to_drm_sched_job(spsc_queue_pop(&s_entity->job_queue)))) {
444+
while ((s_job = drm_sched_entity_queue_pop(s_entity))) {
429445
struct drm_sched_fence *s_fence = s_job->s_fence;
430446

431447
dma_fence_signal(&s_fence->scheduled);

0 commit comments

Comments
 (0)