Skip to contentSkip to conversation

drm/amdgpu: add UAPI for user queue query status

PATCH Superseded Prike Liang 2 participants 9 messages Sep 15 – Sep 21

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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
index cd1b8034a2fb..183ac26f2bd3 100644
@@ -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
#1 lore raw

PATCH v2 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
index 3938f7b8ec4b..1be5e70dd4e8 100644
@@ -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
index 6412a7f7b6ef..40228c60a1ea 100644
@@ -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
#2 lore raw

PATCH v2 3/5 drm/amdgpu: extend UAPI for reporting userq invalid VA

In reply to Prike Liang

Add 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
index 183ac26f2bd3..2f81ec3265cd 100644
@@ -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
#3 lore raw

PATCH v2 4/5 drm/amdgpu: extend UAPI for reporting userq invalid VA

In reply to Prike Liang

Add 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
index 1be5e70dd4e8..6c92575213c1 100644
@@ -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
#4 lore raw

PATCH v2 5/5 drm/amdgpu: mark queue and process as guilty for hung user queue

In reply to Prike Liang

When a hung user queue triggers a reset, its context becomes corrupted and must not be replayed. Mark both the queue and its owning process as guilty so that user space is notified that the offending queue is no longer usable and must recreate the context before resubmitting work.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c   |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 48 +++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  5 ++-
 3 files changed, 51 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3 -1
index b15ed4a534f1..1094057d2e1d 100644
@@ -589,7 +589,9 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
 	if (ctx->generation != amdgpu_vm_generation(adev, &fpriv->vm))
 		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_VRAMLOST;
 
-	if (amdgpu_ctx_guilty(ctx))
+	if (amdgpu_ctx_guilty(ctx) ||
+	    ((out->state.flags & AMDGPU_CTX_QUERY2_FLAGS_RESET) &&
+	     READ_ONCE(fpriv->userq_mgr.guilty)))
 		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_GUILTY;
 
 	if (amdgpu_in_reset(adev))
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +44 -4

104 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +4 -1
index 40228c60a1ea..f2eca744a3c5 100644
@@ -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;
@@ -132,7 +134,8 @@ struct amdgpu_userq_mgr {
 	struct drm_file			*file;
 	struct mutex			proc_ctx_lock;
 	struct amdgpu_userq_obj		proc_ctx_obj;
-
+	/* Set when any queue owned by this process is reset guilty */
+	bool                            guilty;
 	bool				proc_ctx_allocated;
 	uint32_t			proc_ctx_array_index;
 	/**
Signature · 1 line
2.34.1
maintainer
#5 lore raw

Re: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

On 9/15/26 09:19, Prike Liang wrote:
...

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h struct amdgpu_userq_mgr { · line 141

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -1
@@ -132,7 +134,8 @@ struct amdgpu_userq_mgr {
 	struct drm_file			*file;
 	struct mutex			proc_ctx_lock;
 	struct amdgpu_userq_obj		proc_ctx_obj;
-
+	/* Set when any queue owned by this process is reset guilty */
+	bool                            guilty;
 	bool				proc_ctx_allocated;
 	uint32_t			proc_ctx_array_index;
 	/**

Again, clear NAK to having a flag in the queue manager as well.

We should not track that here, especially since there is no way to reset it as far as I can see.

Regards,
Christian.

#6 lore raw

RE: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

AMD General

Regards,
Prike

Quoted 24 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, September 15, 2026 10:03 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Pelloux-Prayer, Pierre- Eric <[email protected]>
Subject: Re: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

On 9/15/26 09:19, Prike Liang wrote:
...

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h struct amdgpu_userq_mgr { · line 141

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -1
@@ -132,7 +134,8 @@ struct amdgpu_userq_mgr {
    struct drm_file                 *file;
    struct mutex                    proc_ctx_lock;
    struct amdgpu_userq_obj         proc_ctx_obj;
-
+   /* Set when any queue owned by this process is reset guilty */
+   bool                            guilty;
    bool                            proc_ctx_allocated;
    uint32_t                        proc_ctx_array_index;
    /**

Again, clear NAK to having a flag in the queue manager as well.

Quoted 2 lines

We should not track that here, especially since there is no way to reset it as far as I can see.

The userq_mgr->guilty was originally added to track VRAM-lost resets through amdgpu_ctx_query2() so userspace could reuse its EGL_EXT_create_context_robustness handling. If userspace switches to querying user queue status via amdgpu_userq_query_status(), we can drop userq_mgr->guilty and rely directly on AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST for identifying the case of userq vram lost.

Thanks,
Prike

Quoted 2 lines

Regards,
Christian.

maintainer
#7 lore raw

Re: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

Quoted 29 lines · Prike

AMD General

Regards,
Prike

Quoted 24 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, September 15, 2026 10:03 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Pelloux-Prayer, Pierre- Eric <[email protected]>
Subject: Re: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

On 9/15/26 09:19, Prike Liang wrote:
...

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h struct amdgpu_userq_mgr { · line 141

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -1
@@ -132,7 +134,8 @@ struct amdgpu_userq_mgr {
    struct drm_file                 *file;
    struct mutex                    proc_ctx_lock;
    struct amdgpu_userq_obj         proc_ctx_obj;
-
+   /* Set when any queue owned by this process is reset guilty */
+   bool                            guilty;
    bool                            proc_ctx_allocated;
    uint32_t                        proc_ctx_array_index;
    /**

Again, clear NAK to having a flag in the queue manager as well.

Quoted 4 lines
Quoted 2 lines

We should not track that here, especially since there is no way to reset it as far as I can see.

The userq_mgr->guilty was originally added to track VRAM-lost resets through amdgpu_ctx_query2() so userspace could reuse its EGL_EXT_create_context_robustness handling.

Hui? I don't understand what you mean.

amdgpu_ctx_query2() does the VRAM lost tracking through a VM generation check. See this line here:

if (ctx->generation != amdgpu_vm_generation(adev, &fpriv->vm))

	out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_VRAMLOST;

Why would we need an userq guilty flag for that?

Regards,
Christian.

Quoted 7 lines

If userspace switches to querying user queue status via amdgpu_userq_query_status(), we can drop userq_mgr->guilty and rely directly on AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST for identifying the case of userq vram lost.

Thanks,
Prike

Quoted 2 lines

Regards,
Christian.

#8 lore raw

RE: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

AMD General

Regards,
Prike

Quoted 48 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, September 16, 2026 9:56 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Pelloux-Prayer, Pierre- Eric <[email protected]>
Subject: Re: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

Quoted 29 lines · Prike

AMD General

Regards,
Prike

Quoted 24 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, September 15, 2026 10:03 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Pelloux-Prayer, Pierre- Eric <[email protected]>
Subject: Re: [PATCH v2 5/5] drm/amdgpu: mark queue and process as guilty for hung user queue

On 9/15/26 09:19, Prike Liang wrote:
...

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h struct amdgpu_userq_mgr { · line 141

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -1
@@ -132,7 +134,8 @@ struct amdgpu_userq_mgr {
    struct drm_file                 *file;
    struct mutex                    proc_ctx_lock;
    struct amdgpu_userq_obj         proc_ctx_obj;
-
+   /* Set when any queue owned by this process is reset guilty */
+   bool                            guilty;
    bool                            proc_ctx_allocated;
    uint32_t                        proc_ctx_array_index;
    /**

Again, clear NAK to having a flag in the queue manager as well.

Quoted 4 lines
Quoted 2 lines

We should not track that here, especially since there is no way to reset it as far as I can see.

The userq_mgr->guilty was originally added to track VRAM-lost resets through

amdgpu_ctx_query2() so userspace could reuse its
EGL_EXT_create_context_robustness handling.

Hui? I don't understand what you mean.

Quoted 7 lines

amdgpu_ctx_query2() does the VRAM lost tracking through a VM generation check. See this line here:

if (ctx->generation != amdgpu_vm_generation(adev, &fpriv->vm))

      out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_VRAMLOST;

Why would we need an userq guilty flag for that?

When a user queue (userq) reset fails and falls back to a full device reset, userspace needs to detect the invalid/dead queue state in order to recreate it.

Currently, userspace drivers (e.g., Mesa) can query reset status through either amdgpu_ctx_query2() or amdgpu_userq_query_status(). However, amdgpu_ctx is not directly involved in userq lifecycle management, and Mesa plans to decouple legacy context dependencies from user queue handling.

To support standalone userq workflows, I plan to extend amdgpu_userq_query_status() to report detailed reset status flags (analogous to amdgpu_ctx_query2()), enabling userspace to identify reset fallout (e.g., guilty/innocent/unknown reset) and initiate queue recovery without relying on amdgpu_ctx.

Thanks,
Prike

Quoted 14 lines

Regards,
Christian.

Quoted 1 line

If userspace switches to querying user queue status via

amdgpu_userq_query_status(), we can drop userq_mgr->guilty and rely directly on AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST for identifying the case of userq vram lost.

Quoted 6 lines

Thanks,
Prike

Quoted 2 lines

Regards,
Christian.