On Fri, Sep 19, 2025 at 4:29 AM Prike Liang <[email protected]> wrote:
>
> From: Alex Deucher <[email protected]>
>
> Query the status of the user queue, currently whether
> the queue is hung and whether or not VRAM is lost.
>
> v2: Misc cleanups
>
> Reviewed-by: Sunil Khatri <[email protected]>
> Signed-off-by: Alex Deucher <[email protected]>
> Reviewed-by: Prike Liang <[email protected]>
Might as well squash patches 9 and 10 into patch 8.
Alex
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 35 ++++++++++++++++++++++-
> drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 1 +
> 2 files changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index 224d09019997..8ac7236091fa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -610,6 +610,7 @@ amdgpu_userq_create(struct drm_file *filp, union
> drm_amdgpu_userq *args)
> queue->queue_type = args->in.ip_type;
> queue->vm = &fpriv->vm;
> queue->priority = priority;
> + queue->generation = amdgpu_vm_generation(adev, &fpriv->vm);
>
> db_info.queue_type = queue->queue_type;
> db_info.doorbell_handle = queue->doorbell_handle;
> @@ -699,6 +700,34 @@ amdgpu_userq_create(struct drm_file *filp, union
> drm_amdgpu_userq *args)
> return r;
> }
>
> +static int
> +amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq
> *args)
> +{
> + struct amdgpu_fpriv *fpriv = filp->driver_priv;
> + struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
> + struct amdgpu_device *adev = uq_mgr->adev;
> + struct amdgpu_usermode_queue *queue;
> + int queue_id = args->in.queue_id;
> +
> + mutex_lock(&uq_mgr->userq_mutex);
> +
> + queue = amdgpu_userq_find(uq_mgr, queue_id);
> + if (!queue) {
> + dev_dbg(adev->dev, "Invalid queue id to query\n");
> + mutex_unlock(&uq_mgr->userq_mutex);
> + return -EINVAL;
> + }
> + args->out_qs.flags = 0;
> + if (queue->state == AMDGPU_USERQ_STATE_HUNG)
> + args->out_qs.flags |= AMDGPU_USERQ_QUERY_STATUS_FLAGS_HUNG;
> + if (queue->generation != amdgpu_vm_generation(adev, &fpriv->vm))
> + args->out_qs.flags |=
> AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST;
> +
> + mutex_unlock(&uq_mgr->userq_mutex);
> +
> + return 0;
> +}
> +
> static int amdgpu_userq_input_args_validate(struct drm_device *dev,
> union drm_amdgpu_userq *args,
> struct drm_file *filp)
> @@ -779,7 +808,11 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void
> *data,
> if (r)
> drm_file_err(filp, "Failed to destroy usermode
> queue\n");
> break;
> -
> + case AMDGPU_USERQ_OP_QUERY_STATUS:
> + r = amdgpu_userq_query_status(filp, args);
> + if (r)
> + drm_file_err(filp, "Failed to query usermode queue
> status\n");
> + break;
> default:
> drm_dbg_driver(dev, "Invalid user queue op specified: %d\n",
> args->in.op);
> return -EINVAL;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
> index 7bbbb5988fc7..e0ca466681f3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
> @@ -74,6 +74,7 @@ struct amdgpu_usermode_queue {
> struct dentry *debugfs_queue;
>
> struct list_head userq_va_list;
> + uint64_t generation;
> };
>
> struct amdgpu_userq_funcs {
> --
> 2.34.1
>