[PATCH v2 09/11] drm/amdgpu: validate userq activity status for GEM_VA unmap

Liang, Prike Prike.Liang at amd.com
Thu Jun 19 13:25:47 UTC 2025


[Public]

The patch#7 ~patch9 are drafting for validating the unmapped metadata whether it is idled. If the user force unmaps a busy userq,
then a warning message will be reported here.
Hi, @Deucher, Alexander Could you please help review the patches 7-9 to see whether they can fulfill the userq VA unmap validation design?

Regards,
      Prike

> -----Original Message-----
> From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> On Behalf Of Prike Liang
> Sent: Tuesday, June 17, 2025 4:02 PM
> To: amd-gfx at lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher at amd.com>; Koenig, Christian
> <Christian.Koenig at amd.com>; Liang, Prike <Prike.Liang at amd.com>
> Subject: [PATCH v2 09/11] drm/amdgpu: validate userq activity status for GEM_VA
> unmap
>
> The userq VA unmap requires validating queue status before unamapping it, if user
> tries to unmap a busy userq by GEM VA IOCTL then the driver should report an error
> for this illegal usage.
>
> Signed-off-by: Prike Liang <Prike.Liang at amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 +++++++++++++---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    |  8 ++++++++
>  2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index f04b51ded06f..be3220a973ae 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -225,7 +225,7 @@ amdgpu_userq_map_helper(struct amdgpu_userq_mgr
> *uq_mgr,
>       return r;
>  }
>
> -static void
> +static int
>  amdgpu_userq_wait_for_last_fence(struct amdgpu_userq_mgr *uq_mgr,
>                                struct amdgpu_usermode_queue *queue)  { @@ -
> 234,10 +234,14 @@ amdgpu_userq_wait_for_last_fence(struct amdgpu_userq_mgr
> *uq_mgr,
>
>       if (f && !dma_fence_is_signaled(f)) {
>               ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
> -             if (ret <= 0)
> +             if (ret <= 0) {
>                       drm_file_err(uq_mgr->file, "Timed out waiting for
> fence=%llu:%llu\n",
>                                    f->context, f->seqno);
> +                     return -ETIMEDOUT;
> +             }
>       }
> +
> +     return 0;
>  }
>
>  static void
> @@ -453,7 +457,13 @@ amdgpu_userq_destroy(struct drm_file *filp, int queue_id)
>               mutex_unlock(&uq_mgr->userq_mutex);
>               return -EINVAL;
>       }
> -     amdgpu_userq_wait_for_last_fence(uq_mgr, queue);
> +
> +     if (amdgpu_userq_wait_for_last_fence(uq_mgr, queue)) {
> +             drm_warn(adev_to_drm(uq_mgr->adev), "Don't destroy a busy
> userq\n");
> +             mutex_unlock(&uq_mgr->userq_mutex);
> +             return -EINVAL;
> +     }
> +
>       r = amdgpu_bo_reserve(queue->db_obj.obj, true);
>       if (!r) {
>               amdgpu_bo_unpin(queue->db_obj.obj);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 5e075e8f0ca3..afc493f43256 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1929,6 +1929,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
>       struct amdgpu_bo_va_mapping *mapping;
>       struct amdgpu_vm *vm = bo_va->base.vm;
>       bool valid = true;
> +     int r;
>
>       saddr /= AMDGPU_GPU_PAGE_SIZE;
>
> @@ -1949,6 +1950,13 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device
> *adev,
>                       return -ENOENT;
>       }
>
> +     /* It's unlike to happen that the mapping userq hasn't been idled
> +      * during user unmap vm except the vm unmaped forcely from user space.
> +      */
> +     r = amdgpu_userq_gem_va_unmap_validate(vm, saddr);
> +     if (unlikely(r && r != -EBUSY))
> +             dev_warn(adev->dev, "Here should be an improper unmap request
> from
> +user space\n");
> +
>       list_del(&mapping->list);
>       amdgpu_vm_it_remove(mapping, &vm->va);
>       mapping->bo_va = NULL;
> --
> 2.34.1



More information about the amd-gfx mailing list