drm/amdgpu: add UAPI for user queue query status
Subsystems (3)
PATCH v4 1/4 drm/amdgpu: add UAPI for user queue query status
From: Alex Deucher <[email protected]>
Add an API to query whether a queue is broken because it is hung or VRAM has been lost. Report either condition through a single BROKEN flag.
--- include/uapi/drm/amdgpu_drm.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/uapi/drm/amdgpu_drm.h +11 -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,9 @@ union drm_amdgpu_ctx {/* for queues that need access to protected content */ #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE (1 << 2) +/* the queue is broken because it is hung or VRAM was lost */ +#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN (1 << 0) +/* * This structure is a container to pass input configuration * info for all supported userqueue related operations.
@@ -433,9 +437,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 v4 2/4 drm/amdgpu/userq: implement support for query status
From: Alex Deucher <[email protected]>
Query the status of the user queue. Report BROKEN when the queue is hung or its VM generation indicates that VRAM has been lost.
v2: Misc cleanups
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 34 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 1 + 2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +34 -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,33 @@ 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 || + queue->generation !=amdgpu_vm_generation (adev, &fpriv->vm)) + args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN ; +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 +961,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 v4 3/4 drm/amdgpu/userq: report invalid VA through the broken status flag
In reply to Prike LiangReport a queue with an invalid virtual address as BROKEN, alongside hung queues and queues whose VRAM has been lost. Use the existing BROKEN flag instead of exposing a separate INVALID_VA status flag.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 1 + include/uapi/drm/amdgpu_drm.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -0
@@ -832,6 +832,7 @@ 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 || + queue->state ==AMDGPU_USERQ_STATE_INVALID_VA || queue->generation !=amdgpu_vm_generation (adev, &fpriv->vm)) args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN ;amdgpu_userq_put (queue);
include/uapi/drm/amdgpu_drm.h +1 -1
@@ -353,7 +353,7 @@ union drm_amdgpu_ctx {/* for queues that need access to protected content */ #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE (1 << 2) -/* the queue is broken because it is hung or VRAM was lost */ +/* the queue is broken because it is hung, has an invalid VA, or VRAM was lost */ #define AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN (1 << 0)/*
Signature · 1 line
2.34.1
PATCH v4 4/4 drm/amdgpu/userq: report GPU reset in progress
In reply to Prike LiangReport an ongoing GPU reset through RESET_IN_PROGRESS at bit 1, alongside BROKEN at bit 0, so userspace can query whether GPU recovery is ongoing.
Validate query inputs using the same rules as queue deletion and document the required fields. Drop the queue reference after releasing userq_mutex because the final put may destroy the queue and acquire that mutex.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 +++++- include/uapi/drm/amdgpu_drm.h | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +5 -1
@@ -835,8 +835,11 @@ amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args) queue->state ==AMDGPU_USERQ_STATE_INVALID_VA || queue->generation != amdgpu_vm_generation(adev, &fpriv->vm)) args->out_qs.flags |= AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN; -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 ; }
@@ -898,6 +901,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 ||
include/uapi/drm/amdgpu_drm.h +5 -3
@@ -355,19 +355,21 @@ union drm_amdgpu_ctx {/* the queue is broken because it is hung, has an invalid VA, or VRAM was lost */ #define AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN (1 << 0) +/* indicate that a GPU reset has not completed yet */ +#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS (1 << 1)/* * 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 v4 4/4] drm/amdgpu/userq: report GPU reset in progress
AMD General
Ping on the series
Regards,
Prike
Quoted 85 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Saturday, October 10, 2026 10:50 AM
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 v4 4/4] drm/amdgpu/userq: report GPU reset in progressReport an ongoing GPU reset through
RESET_IN_PROGRESSat bit 1, alongside BROKEN at bit 0, so userspace can query whether GPU recovery is ongoing.Validate query inputs using the same rules as queue deletion and document the required fields. Drop the queue reference after releasing
userq_mutexbecause the final put may destroy the queue and acquire that mutex.Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 +++++- include/uapi/drm/amdgpu_drm.h | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6
-1@@ -835,8 +835,11 @@ amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args) queue->state == AMDGPU_USERQ_STATE_INVALID_VA || queue->generation != amdgpu_vm_generation(adev, &fpriv->vm)) args->out_qs.flags |= AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN; - 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; }@@ -898,6 +901,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 ||include/uapi/drm/amdgpu_drm.h index renamed from include/uapi/drm/amdgpu_drm.h +0
-0
98c3fa8a4a72..32ed4c4349a4100644include/uapi/drm/amdgpu_drm.h +3
-2@@ -355,19 +355,21 @@ union drm_amdgpu_ctx {/* the queue is broken because it is hung, has an invalid VA, or VRAM was lost */ #define AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN (1 << 0) +/* indicate that a GPU reset has not completed yet */ #define +AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS (1 << 1)/* * 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
RE: [PATCH v4 4/4] drm/amdgpu/userq: report GPU reset in progress
AMD General
Hi @Deucher, Alexander, @Pelloux-Prayer, Pierre-Eric
Could you please review the following patches, which include the libdrm implementation?
https://gitlab.freedesktop.org/mesa/libdrm/-/merge_requests/487
Regards,
Prike
Quoted 106 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Wednesday, October 21, 2026 5:15 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pelloux-Prayer, Pierre-Eric <Pierre-eric.Pelloux- [email protected]>
Subject: RE: [PATCH v4 4/4] drm/amdgpu/userq: report GPU reset in progressAMD General
Ping on the series
Regards,
PrikeQuoted 10 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Saturday, October 10, 2026 10:50 AM
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 v4 4/4] drm/amdgpu/userq: report GPU reset in progressQuoted 2 lines
Report an ongoing GPU reset through
RESET_IN_PROGRESSat bit 1, alongside BROKEN at bit 0, so userspace can query whether GPU recovery isongoing.
Quoted 48 lines
Validate query inputs using the same rules as queue deletion and document the required fields. Drop the queue reference after releasing
userq_mutexbecause the final put may destroy the queue and acquire that mutex.Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 +++++- include/uapi/drm/amdgpu_drm.h | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6
-1@@ -835,8 +835,11 @@ amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args) queue->state == AMDGPU_USERQ_STATE_INVALID_VA || queue->generation != amdgpu_vm_generation(adev, &fpriv->vm)) args->out_qs.flags |= AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN; - 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; }@@ -898,6 +901,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 || diff --git
a/include/uapi/drm/amdgpu_drm.hb/include/uapi/drm/amdgpu_drm.hindex98c3fa8a4a72..32ed4c4349a4100644include/uapi/drm/amdgpu_drm.h +0
-0@@ -355,19 +355,21 @@ union drm_amdgpu_ctx {/* the queue is broken because it is hung, has an invalid VA, or VRAM Quoted 1 line
was lost */ #define
AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN(1<< 0)
include/uapi/drm/amdgpu_drm.h
Quoted 2 lines
include/uapi/drm/amdgpu_drm.h +2
-0+/* indicate that a GPU reset has not completed yet */ #define +AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS (1 <<1)
Quoted 24 lines
/*
* This structure is a container to pass input configuration
* info for all supported userqueue related operations.
* For operationAMDGPU_USERQ_OP_CREATE: user is expected
* to set all fields, excep the parameter 'queue_id'.
- * For operationAMDGPU_USERQ_OP_FREE: the only input parameter expected
- * to be set is 'queue_id', eveything else is ignored.
+ * For operationsAMDGPU_USERQ_OP_FREEandAMDGPU_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
RE: [PATCH v4 4/4] drm/amdgpu/userq: report GPU reset in progress
AMD General
Hi @Deucher, Alexander
Since @Pelloux-Prayer, Pierre-Eric has already reviewed the userq query libdrm implementation, could you please help review the corresponding kernel patch?
Regards,
Prike
Quoted 134 lines
-----Original Message-----
From: Liang, Prike
Sent: Monday, November 2, 2026 9:02 PM
To: 'Liang, Prike' <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>
Cc: Koenig, Christian <[email protected]>
Subject: RE: [PATCH v4 4/4] drm/amdgpu/userq: report GPU reset in progressHi @Deucher, Alexander, @Pelloux-Prayer, Pierre-Eric
Could you please review the following patches, which include the libdrm implementation?
https://gitlab.freedesktop.org/mesa/libdrm/-/merge_requests/487
Regards,
PrikeQuoted 29 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Wednesday, October 21, 2026 5:15 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pelloux-Prayer, Pierre-Eric <Pierre-eric.Pelloux- [email protected]>
Subject: RE: [PATCH v4 4/4] drm/amdgpu/userq: report GPU reset in progressAMD General
Ping on the series
Regards,
PrikeQuoted 11 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Saturday, October 10, 2026 10:50 AM
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 v4 4/4] drm/amdgpu/userq: report GPU reset in progressQuoted 8 lines
Quoted 3 lines
Report an ongoing GPU reset through
RESET_IN_PROGRESSat bit 1, alongside BROKEN at bit 0, so userspace can query whether GPU recovery isongoing.
Quoted 4 lines
Validate query inputs using the same rules as queue deletion and document the required fields. Drop the queue reference after releasing
userq_mutexbecause the final put may destroy the queue and acquirethat mutex.
Quoted 45 lines
Quoted 45 lines
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 +++++- include/uapi/drm/amdgpu_drm.h | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +5
-1@@ -835,8 +835,11 @@ amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args) queue->state == AMDGPU_USERQ_STATE_INVALID_VA || queue->generation != amdgpu_vm_generation(adev, &fpriv->vm)) args->out_qs.flags |=AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN ; -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 ; }@@ -898,6 +901,7 @@ static intamdgpu_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 || diff --git
a/include/uapi/drm/amdgpu_drm.hb/include/uapi/drm/amdgpu_drm.hindex98c3fa8a4a72..32ed4c4349a4100644include/uapi/drm/amdgpu_drm.h +0
-0@@ -355,19 +355,21 @@ union drm_amdgpu_ctx {Quoted 2 lines
Quoted 2 lines
include/uapi/drm/amdgpu_drm.h +0
-0/* the queue is broken because it is hung, has an invalid VA, or VRAM was lost */ #define
AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN(1Quoted 3 lines
<< 0)
include/uapi/drm/amdgpu_drm.h
Quoted 2 lines
include/uapi/drm/amdgpu_drm.h +2
-0+/* indicate that a GPU reset has not completed yet */ #define +AMDGPU_USERQ_QUERY_STATUS_FLAGS_RESET_IN_PROGRESS (1<<
Quoted 25 lines
1)
Quoted 24 lines
/*
* This structure is a container to pass input configuration
* info for all supported userqueue related operations.
* For operationAMDGPU_USERQ_OP_CREATE: user is expected
* to set all fields, excep the parameter 'queue_id'.
- * For operationAMDGPU_USERQ_OP_FREE: the only input parameter expected
- * to be set is 'queue_id', eveything else is ignored.
+ * For operationsAMDGPU_USERQ_OP_FREEandAMDGPU_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