]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/imagination: Populate FW common context ID before passing to the FW
authorBrajesh Gupta <brajesh.gupta@imgtec.com>
Tue, 19 May 2026 08:25:26 +0000 (13:55 +0530)
committerMatt Coster <matt.coster@imgtec.com>
Tue, 19 May 2026 11:40:11 +0000 (12:40 +0100)
Initialise the context ID for the FW common context correctly by moving
the context allocation earlier.

Signed-off-by: Brajesh Gupta <brajesh.gupta@imgtec.com>
Reviewed-by: Matt Coster <matt.coster@imgtec.com>
Link: https://patch.msgid.link/20260519-b4-context_reset-v2-1-931018a7131d@imgtec.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
drivers/gpu/drm/imagination/pvr_context.c

index 8de70c30b9de0e4aca1160ddb83eca1c0d597e29..eba4694400b5a987804f658e5d0fd9f5ca3482ed 100644 (file)
@@ -318,10 +318,14 @@ int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_co
                goto err_put_vm;
        }
 
-       err = pvr_context_create_queues(ctx, args, ctx->data);
+       err = xa_alloc(&pvr_dev->ctx_ids, &ctx->ctx_id, ctx, xa_limit_32b, GFP_KERNEL);
        if (err)
                goto err_free_ctx_data;
 
+       err = pvr_context_create_queues(ctx, args, ctx->data);
+       if (err)
+               goto err_free_ctx_id;
+
        err = init_fw_objs(ctx, args, ctx->data);
        if (err)
                goto err_destroy_queues;
@@ -329,23 +333,12 @@ int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_co
        err = pvr_fw_object_create(pvr_dev, ctx_size, PVR_BO_FW_FLAGS_DEVICE_UNCACHED,
                                   ctx_fw_data_init, ctx, &ctx->fw_obj);
        if (err)
-               goto err_free_ctx_data;
+               goto err_destroy_queues;
 
-       err = xa_alloc(&pvr_dev->ctx_ids, &ctx->ctx_id, ctx, xa_limit_32b, GFP_KERNEL);
+       err = xa_alloc(&pvr_file->ctx_handles, &args->handle, ctx, xa_limit_32b, GFP_KERNEL);
        if (err)
                goto err_destroy_fw_obj;
 
-       err = xa_alloc(&pvr_file->ctx_handles, &args->handle, ctx, xa_limit_32b, GFP_KERNEL);
-       if (err) {
-               /*
-                * It's possible that another thread could have taken a reference on the context at
-                * this point as it is in the ctx_ids xarray. Therefore instead of directly
-                * destroying the context, drop a reference instead.
-                */
-               pvr_context_put(ctx);
-               return err;
-       }
-
        spin_lock(&pvr_dev->ctx_list_lock);
        list_add_tail(&ctx->file_link, &pvr_file->contexts);
        spin_unlock(&pvr_dev->ctx_list_lock);
@@ -358,6 +351,15 @@ err_destroy_fw_obj:
 err_destroy_queues:
        pvr_context_destroy_queues(ctx);
 
+err_free_ctx_id:
+       /*
+        * Ctx_id is not exposed to userspace and not visible yet within
+        * the kernel/FW, plus a matching context handle (exposed to userspace)
+        * hasn't been allocated yet, so it is safe to remove ctx_id
+        * from the ctx_ids xarray.
+        */
+       xa_erase(&pvr_dev->ctx_ids, ctx->ctx_id);
+
 err_free_ctx_data:
        kfree(ctx->data);