OSDN Git Service

drm/amdgpu: install ctx entities with cmpxchg
authorChristian König <christian.koenig@amd.com>
Wed, 23 Feb 2022 13:35:31 +0000 (14:35 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 4 Mar 2022 18:03:30 +0000 (13:03 -0500)
Since we removed the context lock we need to make sure that not two threads
are trying to install an entity at the same time.

Signed-off-by: Christian König <christian.koenig@amd.com>
Fixes: 461fa7b0ac565e ("drm/amdgpu: remove ctx->lock")
Reviewed-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c

index 2d2dcea..5981c7d 100644 (file)
@@ -205,9 +205,15 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
        if (r)
                goto error_free_entity;
 
-       ctx->entities[hw_ip][ring] = entity;
+       /* It's not an error if we fail to install the new entity */
+       if (cmpxchg(&ctx->entities[hw_ip][ring], NULL, entity))
+               goto cleanup_entity;
+
        return 0;
 
+cleanup_entity:
+       drm_sched_entity_fini(&entity->entity);
+
 error_free_entity:
        kfree(entity);