[Public] Maybe we need a PTE schedule check in the amdgpu_vm_generation() for the userq only case. This could be a sperate patch for handling that, for this patch is
Reviewed-by: Prike Liang <prike.li...@amd.com> Regards, Prike > -----Original Message----- > From: Liang, Prike <prike.li...@amd.com> > Sent: Wednesday, September 10, 2025 7:37 PM > To: amd-gfx@lists.freedesktop.org > Cc: Deucher, Alexander <alexander.deuc...@amd.com>; Koenig, Christian > <christian.koe...@amd.com>; Liang, Prike <prike.li...@amd.com>; Khatri, Sunil > <sunil.kha...@amd.com>; Deucher, Alexander <alexander.deuc...@amd.com> > Subject: [PATCH 2/9] drm/amdgpu/userq: implement support for query status > > 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 <sunil.kha...@amd.com> > Signed-off-by: Alex Deucher <alexander.deuc...@amd.com> > --- > 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 9608fe3b5a9e..83f0ecdaa0b7 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c > @@ -472,6 +472,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; @@ -553,6 +554,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) > @@ -633,7 +662,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 c027dd916672..2260b1fb8a22 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h > @@ -66,6 +66,7 @@ struct amdgpu_usermode_queue { > u32 xcp_id; > int priority; > struct dentry *debugfs_queue; > + uint64_t generation; > }; > > struct amdgpu_userq_funcs { > -- > 2.34.1