From: Jesse Zhang <Jesse.Zhang@amd.com>
To: <igt-dev@lists.freedesktop.org>
Cc: Vitaly Prosyak <vitaly.prosyak@amd.com>,
Alex Deucher <alexander.deucher@amd.com>,
Christian Koenig <christian.koenig@amd.com>,
Jesse Zhang <Jesse.Zhang@amd.com>,
Jesse Zhang <jesse.zhang@amd.com>
Subject: [PATCH i-g-t 1/2] tests/amdgpu/amd_deadlock: add gfx user-queue clean-hang reset test
Date: Mon, 20 Jul 2026 17:55:41 +0800 [thread overview]
Message-ID: <20260720095555.1537413-1-Jesse.Zhang@amd.com> (raw)
Submit a gfx user-queue job whose only packet is a WAIT_REG_MEM that never
completes (polls a resident BO for a value that never arrives). The queue
hangs with no fault, so the driver recovers it with a per-queue reset. Add
it as the amdgpu-deadlock-gfx-umq subtest, gated on AMDGPU_ENABLE_USERQTEST
and per-queue reset capability.
Signed-off-by: Jesse Zhang <jesse.zhang@amd.com>
---
lib/amdgpu/amd_deadlock_helpers.c | 91 +++++++++++++++++++++++++++++++
lib/amdgpu/amd_deadlock_helpers.h | 4 ++
tests/amdgpu/amd_deadlock.c | 9 +++
3 files changed, 104 insertions(+)
diff --git a/lib/amdgpu/amd_deadlock_helpers.c b/lib/amdgpu/amd_deadlock_helpers.c
index 06c577085..c679e60c7 100644
--- a/lib/amdgpu/amd_deadlock_helpers.c
+++ b/lib/amdgpu/amd_deadlock_helpers.c
@@ -412,6 +412,97 @@ bad_access_helper(amdgpu_device_handle device_handle, unsigned int cmd_error,
}
}
+/*
+ * Emit a WAIT_REG_MEM that waits forever: poll bo_mc (initialised to 0) for a
+ * value != 0. This is a valid packet that never completes, i.e. a clean hang
+ * with no page fault, so it can be recovered by a per-queue reset.
+ */
+static void gfx_ring_emit_wait_reg_mem_hang(struct amdgpu_ring_context *ring_context)
+{
+ uint32_t i = 0;
+
+ ring_context->pm4[i++] = PACKET3(PACKET3_WAIT_REG_MEM, 5);
+ ring_context->pm4[i++] = WAIT_REG_MEM_MEM_SPACE(1) | /* memory */
+ WAIT_REG_MEM_FUNCTION(4) | /* != */
+ WAIT_REG_MEM_ENGINE(0); /* me */
+ ring_context->pm4[i++] = ring_context->bo_mc & 0xfffffffc;
+ ring_context->pm4[i++] = (ring_context->bo_mc >> 32) & 0xffffffff;
+ ring_context->pm4[i++] = 0; /* reference value */
+ ring_context->pm4[i++] = 0xffffffff; /* and mask */
+ ring_context->pm4[i++] = 0x00000004; /* poll interval */
+ ring_context->pm4_dw = i;
+}
+
+/*
+ * Submit a single job that hangs the queue on a WAIT_REG_MEM (no fault) and
+ * let per-queue reset recover it. Uses the normal (synchronised) submit path
+ * so the CP actually runs the packet.
+ */
+void amdgpu_hang_ring_helper(amdgpu_device_handle device_handle, unsigned int ip_type,
+ struct pci_addr *pci, bool user_queue)
+{
+ const struct amdgpu_ip_block_version *ip_block;
+ const int write_length = 128;
+ const int pm4_dw = 256;
+ struct amdgpu_ring_context *ring_context;
+ int r = 0;
+
+ ip_block = get_ip_block(device_handle, ip_type);
+ ring_context = calloc(1, sizeof(*ring_context));
+ igt_assert(ring_context);
+
+ if (user_queue) {
+ ip_block->funcs->userq_create(device_handle, ring_context, ip_type);
+ } else {
+ r = amdgpu_cs_ctx_create(device_handle, &ring_context->context_handle);
+ igt_assert_eq(r, 0);
+ }
+
+ ring_context->write_length = write_length;
+ ring_context->pm4 = calloc(pm4_dw, sizeof(*ring_context->pm4));
+ ring_context->pm4_size = pm4_dw;
+ ring_context->res_cnt = 1;
+ ring_context->ring_id = 0;
+ ring_context->user_queue = user_queue;
+ igt_assert(ring_context->pm4);
+
+ r = amdgpu_bo_alloc_and_map_sync(device_handle,
+ ring_context->write_length * sizeof(uint32_t),
+ 4096, AMDGPU_GEM_DOMAIN_GTT,
+ AMDGPU_GEM_CREATE_CPU_GTT_USWC,
+ AMDGPU_VM_MTYPE_UC,
+ &ring_context->bo,
+ (void **)&ring_context->bo_cpu,
+ &ring_context->bo_mc,
+ &ring_context->va_handle,
+ ring_context->timeline_syncobj_handle,
+ ++ring_context->point, user_queue);
+ igt_assert_eq(r, 0);
+ if (user_queue) {
+ r = amdgpu_timeline_syncobj_wait(device_handle,
+ ring_context->timeline_syncobj_handle,
+ ring_context->point);
+ igt_assert_eq(r, 0);
+ }
+
+ /* the memory the queue polls stays 0, so the queue hangs */
+ memset((void *)ring_context->bo_cpu, 0, ring_context->write_length * sizeof(uint32_t));
+ ring_context->resources[0] = ring_context->bo;
+
+ gfx_ring_emit_wait_reg_mem_hang(ring_context);
+
+ amdgpu_test_exec_cs_helper(device_handle, ip_block->type, ring_context, 0);
+
+ amdgpu_bo_unmap_and_free(ring_context->bo, ring_context->va_handle, ring_context->bo_mc,
+ ring_context->write_length * sizeof(uint32_t));
+ if (user_queue) {
+ ip_block->funcs->userq_destroy(device_handle, ring_context, ip_type);
+ } else {
+ free(ring_context->pm4);
+ free(ring_context);
+ }
+}
+
#define MAX_DMABUF_COUNT 0x20000
#define MAX_DWORD_COUNT 256
diff --git a/lib/amdgpu/amd_deadlock_helpers.h b/lib/amdgpu/amd_deadlock_helpers.h
index c46ebb67b..accbf2e41 100644
--- a/lib/amdgpu/amd_deadlock_helpers.h
+++ b/lib/amdgpu/amd_deadlock_helpers.h
@@ -33,5 +33,9 @@ bad_access_ring_helper(amdgpu_device_handle device_handle, unsigned int cmd_erro
void
amdgpu_hang_sdma_ring_helper(amdgpu_device_handle device_handle, uint8_t hang_type, struct pci_addr *pci);
+
+void
+amdgpu_hang_ring_helper(amdgpu_device_handle device_handle, unsigned int ip_type,
+ struct pci_addr *pci, bool user_queue);
#endif
diff --git a/tests/amdgpu/amd_deadlock.c b/tests/amdgpu/amd_deadlock.c
index 5325c0ade..118948992 100644
--- a/tests/amdgpu/amd_deadlock.c
+++ b/tests/amdgpu/amd_deadlock.c
@@ -246,6 +246,15 @@ int igt_main()
amdgpu_wait_memory_helper(device, AMDGPU_HW_IP_DMA, &pci, true);
}
}
+
+ igt_describe("Test-per-queue-reset-of-a-cleanly-hung-gfx-user-queue");
+ igt_subtest_with_dynamic("amdgpu-deadlock-gfx-umq") {
+ if (enable_test && userq_arr_cap[AMD_IP_GFX] &&
+ is_reset_enable(AMD_IP_GFX, AMDGPU_RESET_TYPE_PER_QUEUE, &pci)) {
+ igt_dynamic_f("amdgpu-deadlock-gfx-umq")
+ amdgpu_hang_ring_helper(device, AMDGPU_HW_IP_GFX, &pci, true);
+ }
+ }
#endif
igt_fixture() {
--
2.49.0
next reply other threads:[~2026-07-20 9:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 9:55 Jesse Zhang [this message]
2026-07-20 9:55 ` [PATCH i-g-t 2/2] tests/amdgpu/amd_deadlock: add gfx user-queue priv-fault reset test Jesse Zhang
2026-07-21 1:46 ` ✓ Xe.CI.BAT: success for series starting with [i-g-t,1/2] tests/amdgpu/amd_deadlock: add gfx user-queue clean-hang " Patchwork
2026-07-21 2:03 ` ✓ i915.CI.BAT: " Patchwork
2026-07-21 9:47 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-07-21 14:29 ` ✗ i915.CI.Full: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260720095555.1537413-1-Jesse.Zhang@amd.com \
--to=jesse.zhang@amd.com \
--cc=alexander.deucher@amd.com \
--cc=christian.koenig@amd.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=vitaly.prosyak@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox