drm/amdgpu: add UAPI for user queue query status
Subsystems (3)
PATCH v3 1/5 drm/amdgpu: add UAPI for user queue query status
From: Alex Deucher <[email protected]>
Add an API to query queue status such as whether the queue is hung or whether vram is lost.
--- include/uapi/drm/amdgpu_drm.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/uapi/drm/amdgpu_drm.h +14 -0
@@ -340,6 +340,7 @@ union drm_amdgpu_ctx {/* user queue IOCTL operations */ #define AMDGPU_USERQ_OP_CREATE 1#define AMDGPU_USERQ_OP_FREE 2 +#define AMDGPU_USERQ_OP_QUERY_STATUS 3/* queue priority levels */ /* low < normal low < normal high < high */
@@ -352,6 +353,12 @@ union drm_amdgpu_ctx {/* for queues that need access to protected content */ #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE (1 << 2) + +/* the queue is hung */ +#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_HUNG (1 << 0) +/* indicate vram lost since queue was created */ +#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST (1 << 1) +/* * This structure is a container to pass input configuration * info for all supported userqueue related operations.
@@ -433,9 +440,16 @@ struct drm_amdgpu_userq_out {__u32 _pad; }; +/* The structure to carry output of userqueue ops */ +struct drm_amdgpu_userq_out_query_state { +__u32 flags; +__u32 _pad; +}; +union drm_amdgpu_userq {struct drm_amdgpu_userq_in in;struct drm_amdgpu_userq_out out; +struct drm_amdgpu_userq_out_query_state out_qs; };/* GFX V11 IP specific MQD parameters */
Signature · 1 line
2.34.1
PATCH v3 2/5 drm/amdgpu/userq: implement support for query status
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
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 35 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 1 + 2 files changed, 36 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +35 -0
@@ -692,6 +692,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); queue->xcp_id = (fpriv->xcp_id !=AMDGPU_XCP_NO_PARTITION ) ? fpriv->xcp_id :0 ; queue->userq_mgr = uq_mgr;
@@ -812,6 +813,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_get (uq_mgr, queue_id); +if (!queue) { +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 ; +amdgpu_userq_put (queue); +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)
@@ -933,6 +962,12 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,break ; } +case AMDGPU_USERQ_OP_QUERY_STATUS : + r =amdgpu_userq_query_status (filp, args); +if (r) +drm_dbg_driver (dev,"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 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
@@ -79,6 +79,7 @@ struct amdgpu_usermode_queue {struct dma_fence *last_fence;u32 xcp_id;int priority; +uint64_t generation;struct dentry *debugfs_queue;/**
Signature · 1 line
2.34.1
PATCH v3 3/5 drm/amdgpu: extend UAPI for reporting userq invalid VA
In reply to Prike LiangAdd UAPI new definition for reporting userq invalid virtual address status to user space.
--- include/uapi/drm/amdgpu_drm.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/drm/amdgpu_drm.h +2 -1
@@ -358,7 +358,8 @@ union drm_amdgpu_ctx {#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_HUNG (1 << 0)/* indicate vram lost since queue was created */ #define AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST (1 << 1) - +/* the invalid userq VA unmapped */ +#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_INVALID_VA (1 << 2)/* * This structure is a container to pass input configuration * info for all supported userqueue related operations.
Signature · 1 line
2.34.1
PATCH v3 4/5 drm/amdgpu: extend UAPI for reporting userq invalid VA
In reply to Prike LiangAdd UAPI new definition for reporting userq invalid virtual address status to user space.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2 -0
@@ -835,6 +835,8 @@ amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args) 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 ; +if (queue->state ==AMDGPU_USERQ_STATE_INVALID_VA ) + args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_INVALID_VA ;amdgpu_userq_put (queue);mutex_unlock (&uq_mgr->userq_mutex);
Signature · 1 line
2.34.1
PATCH v3 5/5 drm/amdgpu: track user queue guilt and report reset status
In reply to Prike LiangA hung user queue must not be replayed after reset because its context may be corrupted. Keep the guilty state on the queue and report it through the sticky HUNG status. Skip guilty queues and queues whose VM generation has changed when mapping or restoring them.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 30 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 +++ include/uapi/drm/amdgpu_drm.h | 11 ++++++--- 3 files changed, 37 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +26 -4
@@ -148,6 +148,8 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work) } } +WRITE_ONCE (queue->guilty, true); +if (amdgpu_userq_is_reset_type_supported (adev, queue->queue_type,AMDGPU_RESET_TYPE_PER_QUEUE )) {int r;
@@ -174,7 +176,7 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work)* handler to another is illegal if you don't take extra precautions! */ if (gpu_reset) -amdgpu_userq_mgr_reset_work (&queue->userq_mgr->reset_work); +amdgpu_userq_mgr_reset_work (&uq_mgr->reset_work); }/*
@@ -338,6 +340,10 @@ static int amdgpu_userq_restore_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r =0 ; +if (READ_ONCE (queue->guilty) || + queue->generation !=amdgpu_vm_generation (adev, queue->vm)) +return 0 ; +if (queue->state ==AMDGPU_USERQ_STATE_PREEMPTED ) {trace_amdgpu_userq_state_start (queue);
@@ -388,6 +394,10 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r; +if (READ_ONCE (queue->guilty) || + queue->generation !=amdgpu_vm_generation (adev, queue->vm)) +return 0 ; +if (queue->state ==AMDGPU_USERQ_STATE_UNMAPPED ) {trace_amdgpu_userq_state_start (queue);
@@ -692,6 +702,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->reset_counter =atomic_read (&adev->gpu_reset_counter); queue->generation =amdgpu_vm_generation (adev, &fpriv->vm); queue->xcp_id = (fpriv->xcp_id !=AMDGPU_XCP_NO_PARTITION ) ? fpriv->xcp_id :0 ;
@@ -831,14 +842,20 @@ amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args) } args->out_qs.flags =0 ; -if (queue->state ==AMDGPU_USERQ_STATE_HUNG ) +if (queue->reset_counter !=atomic_read (&adev->gpu_reset_counter)) + args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET ; +if (queue->state ==AMDGPU_USERQ_STATE_HUNG || +READ_ONCE (queue->guilty)) 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 ;if (queue->state ==AMDGPU_USERQ_STATE_INVALID_VA ) args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_INVALID_VA ; -amdgpu_userq_put (queue); +if (amdgpu_in_reset (adev)) + args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS ;mutex_unlock (&uq_mgr->userq_mutex); +/* The final put may destroy the queue and take userq_mutex. */ +amdgpu_userq_put (queue);return 0 ; }
@@ -900,6 +917,7 @@ static int amdgpu_userq_input_args_validate(struct drm_device *dev, }break ;case AMDGPU_USERQ_OP_FREE : +case AMDGPU_USERQ_OP_QUERY_STATUS : if (args->in.ip_type || args->in.doorbell_handle || args->in.doorbell_offset ||
@@ -1596,7 +1614,11 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)int ret =0 , r;xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { -if (queue->state ==AMDGPU_USERQ_STATE_HUNG && !vram_lost) { +if (vram_lost ||READ_ONCE (queue->guilty) || + queue->generation !=amdgpu_vm_generation (adev, queue->vm)) +continue ; + +if (queue->state ==AMDGPU_USERQ_STATE_HUNG ) {trace_amdgpu_userq_state_start (queue); userq_funcs = adev->userq_funcs[queue->queue_type];
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -0
@@ -51,6 +51,8 @@ struct amdgpu_userq_obj {struct amdgpu_usermode_queue {int queue_type;enum amdgpu_userq_state state; +/* Reset due to a hang; must not be re-mapped, userspace recreates. */ +bool guilty;uint64_t doorbell_handle;uint64_t doorbell_index;u32 doorbell_offset;
@@ -79,6 +81,7 @@ struct amdgpu_usermode_queue {struct dma_fence *last_fence;u32 xcp_id;int priority; +unsigned int reset_counter;uint64_t generation;struct dentry *debugfs_queue;
include/uapi/drm/amdgpu_drm.h +8 -3
@@ -360,18 +360,23 @@ union drm_amdgpu_ctx {#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST (1 << 1)/* the invalid userq VA unmapped */ #define AMDGPU_USERQ_QUERY_STATUS_FLAGS_INVALID_VA (1 << 2) +/* indicate a GPU reset occurred since the queue was created */ +#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET (1 << 3) +/* indicate that a GPU reset has not completed yet */ +#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS (1 << 4) +/* * This structure is a container to pass input configuration * info for all supported userqueue related operations. * For operation AMDGPU_USERQ_OP_CREATE: user is expected * to set all fields, excep the parameter 'queue_id'. -* For operation AMDGPU_USERQ_OP_FREE: the only input parameter expected -* to be set is 'queue_id', eveything else is ignored. +* For operations AMDGPU_USERQ_OP_FREE and AMDGPU_USERQ_OP_QUERY_STATUS: +* only 'op' and 'queue_id' should be set; all other fields must be zero. */ struct drm_amdgpu_userq_in {/** AMDGPU_USERQ_OP_* */ __u32 op; -/** Queue id passed for operation USERQ_OP_FREE */ +/** Queue id passed for operations USERQ_OP_FREE and USERQ_OP_QUERY_STATUS */ __u32 queue_id;/** the target GPU engine to execute workload (AMDGPU_HW_IP_*) */ __u32 ip_type;
Signature · 1 line
2.34.1
RE: [PATCH v3 5/5] drm/amdgpu: track user queue guilt and report reset status
AMD General
The corresponding Libdrm patch updated as: https://gitlab.freedesktop.org/mesa/libdrm/-/merge_requests/487, please help review the series patch together, thanks!
Regards,
Prike
Quoted 190 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, September 22, 2026 3:59 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pelloux-Prayer, Pierre-Eric <Pierre-eric.Pelloux- [email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH v3 5/5] drm/amdgpu: track user queue guilt and report reset statusA hung user queue must not be replayed after reset because its context may be corrupted. Keep the guilty state on the queue and report it through the sticky HUNG status. Skip guilty queues and queues whose VM generation has changed when mapping or restoring them.
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 30 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 +++ include/uapi/drm/amdgpu_drm.h | 11 ++++++--- 3 files changed, 37 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0@@ -148,6 +148,8 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work) } } +WRITE_ONCE (queue->guilty, true); + if (amdgpu_userq_is_reset_type_supported(adev, queue->queue_type,AMDGPU_RESET_TYPE_PER_QUEUE)) { int r;drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -174,7 +176,7 @@ static void amdgpu_userq_hang_detect_work(structwork_struct *work) * handler to another is illegal if you don't take extra precautions! */ if (gpu_reset) -amdgpu_userq_mgr_reset_work (&queue->userq_mgr->reset_work); +amdgpu_userq_mgr_reset_work (&uq_mgr->reset_work); }/*
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +9
-0@@ -338,6 +340,10 @@ static int amdgpu_userq_restore_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r =0 ; +if (READ_ONCE (queue->guilty) || + queue->generation !=amdgpu_vm_generation (adev, queue->vm)) +return 0 ; +if (queue->state ==AMDGPU_USERQ_STATE_PREEMPTED ) {trace_amdgpu_userq_state_start (queue);@@ -388,6 +394,10 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r; +if (READ_ONCE (queue->guilty) || + queue->generation !=amdgpu_vm_generation (adev, queue->vm)) +return 0 ; +if (queue->state ==AMDGPU_USERQ_STATE_UNMAPPED ) {trace_amdgpu_userq_state_start (queue);@@ -692,6 +702,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->reset_counter =atomic_read (&adev->gpu_reset_counter); queue->generation =amdgpu_vm_generation (adev, &fpriv->vm); queue->xcp_id = (fpriv->xcp_id != AMDGPU_XCP_NO_PARTITION) ?fpriv->xcp_id : 0;drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10
-2@@ -831,14 +842,20 @@ amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args) } args->out_qs.flags =0 ; -if (queue->state ==AMDGPU_USERQ_STATE_HUNG ) +if (queue->reset_counter !=atomic_read (&adev->gpu_reset_counter)) + args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET ; +if (queue->state ==AMDGPU_USERQ_STATE_HUNG || +READ_ONCE (queue->guilty)) 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 ;if (queue->state ==AMDGPU_USERQ_STATE_INVALID_VA ) args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_INVALID_VA ; -amdgpu_userq_put (queue); +if (amdgpu_in_reset (adev)) + args->out_qs.flags |= +AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS ;mutex_unlock (&uq_mgr->userq_mutex); +/* The final put may destroy the queue and take userq_mutex. */ +amdgpu_userq_put (queue);return 0 ; }@@ -900,6 +917,7 @@ static int amdgpu_userq_input_args_validate(struct drm_device *dev, }break ;case AMDGPU_USERQ_OP_FREE : +case AMDGPU_USERQ_OP_QUERY_STATUS : if (args->in.ip_type || args->in.doorbell_handle ||args->in.doorbell_offset ||drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +5
-1@@ -1596,7 +1614,11 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)int ret =0 , r;xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { -if (queue->state ==AMDGPU_USERQ_STATE_HUNG && !vram_lost) { +if (vram_lost ||READ_ONCE (queue->guilty) || + queue->generation !=amdgpu_vm_generation (adev, queue->vm)) +continue ; + +if (queue->state ==AMDGPU_USERQ_STATE_HUNG ) {trace_amdgpu_userq_state_start (queue);userq_funcs = adev->userq_funcs[queue->queue_type];drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3
-0@@ -51,6 +51,8 @@ struct amdgpu_userq_obj { struct amdgpu_usermode_queue {int queue_type;enum amdgpu_userq_state state; +/* Reset due to a hang; must not be re-mapped, userspace recreates. */ +bool guilty;uint64_t doorbell_handle;uint64_t doorbell_index;u32 doorbell_offset;@@ -79,6 +81,7 @@ struct amdgpu_usermode_queue {struct dma_fence *last_fence;u32 xcp_id;int priority; +unsigned int reset_counter;uint64_t generation;struct dentry *debugfs_queue;include/uapi/drm/amdgpu_drm.h index renamed from include/uapi/drm/amdgpu_drm.h +0
-0
2f81ec3265cd..7e928c4e8868100644include/uapi/drm/amdgpu_drm.h +6
-2@@ -360,18 +360,23 @@ union drm_amdgpu_ctx { #defineAMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST (1 <<1 ) /* the invalid userq VA unmapped */#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_INVALID_VA (1 << 2) +/* indicate a GPU reset occurred since the queue was created */ #define +AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET (1 << 3) +/* indicate that a GPU reset has not completed yet */ #define +AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS (1 << 4) +/* * This structure is a container to pass input configuration * info for all supported userqueue related operations. * For operation AMDGPU_USERQ_OP_CREATE: user is expected * to set all fields, excep the parameter 'queue_id'. -* For operation AMDGPU_USERQ_OP_FREE: the only input parameter expected -* to be set is 'queue_id', eveything else is ignored. +* For operations AMDGPU_USERQ_OP_FREE and
AMDGPU_USERQ_OP_QUERY_STATUS:
+ * only 'op' and 'queue_id' should be set; all other fields must be zero. */struct drm_amdgpu_userq_in { /** AMDGPU_USERQ_OP_* */ __u32 op;include/uapi/drm/amdgpu_drm.h +2
-2-/** Queue id passed for operation USERQ_OP_FREE */ +/** Queue id passed for operations USERQ_OP_FREE and +USERQ_OP_QUERY_STATUS */ __u32 queue_id;/** the target GPU engine to execute workload (AMDGPU_HW_IP_*) */ __u32 ip_type; --2.34.1