On Thu, Sep 18, 2025 at 4:18 AM Prike Liang <prike.li...@amd.com> wrote:
>
> Track the userq obj for its life time, and reference and
> dereference the buffer flag at its creating and destroying
> period.
>
> Suggested-by: Alex Deucher <alexander.deuc...@amd.com>
> Signed-off-by: Prike Liang <prike.li...@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index 71cac54791c9..3c8f05a9e82d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -138,6 +138,22 @@ int amdgpu_userq_buffer_va_list_del(struct amdgpu_vm *vm,
>         return -EINVAL;
>  }
>
> +static int amdgpu_userq_buffer_vas_list_cleanup(struct amdgpu_device *adev,
> +                               struct amdgpu_usermode_queue *queue)
> +{
> +       struct amdgpu_userq_va_cursor *va_cursor, *tmp;
> +       int r;
> +
> +       list_for_each_entry_safe(va_cursor, tmp, &queue->userq_va_list, list) 
> {
> +               r += amdgpu_userq_buffer_va_list_del(queue->vm, 
> va_cursor->gpu_addr);
> +               dev_dbg(adev->dev, "delete the userq:%p va:%llx r:%d\n",
> +                       queue, va_cursor->gpu_addr, r);
> +               list_del(&va_cursor->list);

Move list_del() into the amdgpu_userq_buffer_va_list_del() and move
the bo_reserve/unreserve() into this function.

Alex

> +               kfree(va_cursor);
> +       }
> +       return r;
> +}
> +
>  static int
>  amdgpu_userq_unmap_helper(struct amdgpu_userq_mgr *uq_mgr,
>                           struct amdgpu_usermode_queue *queue)
> @@ -200,6 +216,8 @@ amdgpu_userq_cleanup(struct amdgpu_userq_mgr *uq_mgr,
>         struct amdgpu_device *adev = uq_mgr->adev;
>         const struct amdgpu_userq_funcs *uq_funcs = 
> adev->userq_funcs[queue->queue_type];
>
> +       /* Drop the userq reference. */
> +       amdgpu_userq_buffer_vas_list_cleanup(adev, queue);
>         uq_funcs->mqd_destroy(uq_mgr, queue);
>         amdgpu_userq_fence_driver_free(queue);
>         idr_remove(&uq_mgr->userq_idr, queue_id);
> --
> 2.34.1
>

Reply via email to