[PATCH v2 06/11] drm/amdgpu: track the userq bo va for its obj management

Liang, Prike Prike.Liang at amd.com
Thu Jun 19 12:56:41 UTC 2025


[Public]

Regards,
      Prike

> -----Original Message-----
> From: Alex Deucher <alexdeucher at gmail.com>
> Sent: Tuesday, June 17, 2025 11:38 PM
> To: Liang, Prike <Prike.Liang at amd.com>
> Cc: amd-gfx at lists.freedesktop.org; Deucher, Alexander
> <Alexander.Deucher at amd.com>; Koenig, Christian <Christian.Koenig at amd.com>
> Subject: Re: [PATCH v2 06/11] drm/amdgpu: track the userq bo va for its obj
> management
>
> On Tue, Jun 17, 2025 at 4:12 AM Prike Liang <Prike.Liang at amd.com> wrote:
> >
> > The user queue object destroy requires ensuring its VA has been
> > unmapped prior to the queue being destroyed.
> > Otherwise, the kernel driver should report an invalidated error to the
> > user IOCLT request.
> >
> > Signed-off-by: Prike Liang <Prike.Liang at amd.com>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> > index 2882ef8fe719..2a7ec7daf3da 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> > @@ -459,12 +459,24 @@ amdgpu_userq_destroy(struct drm_file *filp, int
> queue_id)
> >                 amdgpu_bo_unpin(queue->db_obj.obj);
> >                 amdgpu_bo_unreserve(queue->db_obj.obj);
> >         }
> > +
> > +       /*
> > +        * At this point the userq obj va should be unmapped,
> > +        * otherwise will return error to user.
> > +        */
>
> I think ideally the queue would remain mapped until after it's destroyed.  I.e., on the
> userspace side:
>
> destroy queue
> unmap VAs
> free BOs
I checked and traced the amdgpu_vm_bo_unmap() and amdgpu_userq_destroy() call sequence, and that shows the userq VA seems always unmapped before destroying the userq.
So now the free sequence like as following:
unmap VAs
destroy queue
free BOs

> Alex
>
> > +       if (amdgpu_userq_buffer_vas_mapped(&fpriv->vm, queue)) {
> > +               drm_warn(adev_to_drm(uq_mgr->adev), "the userq obj va shouldn't be
> mapped during destroying userq\n");
> > +               r=  -EINVAL;
> > +       }
> > +
> >         r = amdgpu_userq_unmap_helper(uq_mgr, queue);
> >         /*TODO: It requires a reset for unmap error*/
> >         if (r != AMDGPU_USERQ_STATE_UNMAPPED) {
> >                 drm_warn(adev_to_drm(uq_mgr->adev), "trying to destroy a HW
> mapping userq\n");
> >                 r = -ETIMEDOUT;
> >         }
> > +
> > +       amdgpu_userq_buffer_vas_put(&fpriv->vm, queue);
> >         amdgpu_userq_cleanup(uq_mgr, queue, queue_id);
> >         mutex_unlock(&uq_mgr->userq_mutex);
> >
> > @@ -585,6 +597,11 @@ amdgpu_userq_create(struct drm_file *filp, union
> drm_amdgpu_userq *args)
> >                 goto unlock;
> >         }
> >
> > +       /* refer to the userq objects vm bo*/
> > +       amdgpu_userq_buffer_va_get(queue->vm, args->in.queue_va);
> > +       amdgpu_userq_buffer_va_get(queue->vm, args->in.rptr_va);
> > +       amdgpu_userq_buffer_va_get(queue->vm, args->in.wptr_va);
> > +
> >         qid = idr_alloc(&uq_mgr->userq_idr, queue, 1,
> AMDGPU_MAX_USERQ_COUNT, GFP_KERNEL);
> >         if (qid < 0) {
> >                 drm_file_err(uq_mgr->file, "Failed to allocate a queue
> > id\n");
> > --
> > 2.34.1
> >


More information about the amd-gfx mailing list