Hi Adrian,

On Fri, 15 Nov 2024 19:14:18 +0000
Adrián Larumbe <adrian.laru...@collabora.com> wrote:

> @@ -71,9 +112,9 @@ void panthor_kernel_bo_destroy(struct panthor_kernel_bo 
> *bo)
>   * Return: A valid pointer in case of success, an ERR_PTR() otherwise.
>   */
>  struct panthor_kernel_bo *
> -panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
> -                      size_t size, u32 bo_flags, u32 vm_map_flags,
> -                      u64 gpu_va)
> +panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_file 
> *pfile,
> +                      struct panthor_vm *vm, size_t size, u32 bo_flags,
> +                      u32 vm_map_flags, u64 gpu_va)
>  {
>       struct drm_gem_shmem_object *obj;
>       struct panthor_kernel_bo *kbo;
> @@ -116,6 +157,16 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, 
> struct panthor_vm *vm,
>       bo->exclusive_vm_root_gem = panthor_vm_root_gem(vm);
>       drm_gem_object_get(bo->exclusive_vm_root_gem);
>       bo->base.base.resv = bo->exclusive_vm_root_gem->resv;
> +
> +     INIT_LIST_HEAD(&kbo->private_obj);
> +
> +     /* Only FW regions are not bound to an open file */
> +     if (pfile) {
> +             mutex_lock(&ptdev->private_obj_list_lock);
> +             list_add(&kbo->private_obj, &pfile->private_file_list);
> +             mutex_unlock(&ptdev->private_obj_list_lock);

I hate the fact we have to take a device lock to insert/remove elements
in the private_file list. I'd rather opt for an idr map (like we have
for public GEM handles), with the pfile owning a ref to the internal
GEMs.

When the kbo needs to be added to the pfile kbo list, you pass a
non-NULL pfile and let panthor_kernel_bo_create() add the entry to the
IDR. In the destroy path, you remove the entry, and reset the
kbo->handle value, to make sure panthor_kernel_bo_destroy() is not
called a second time with a non-NULL pfile. This way your lock can be
moved to panthor_file, and you don't have to worry about UAFs on the
pfile object.

> +     }
> +
>       return kbo;
>  
>  err_free_va:

Regards,

Boris

Reply via email to