From: Jesse Zhang <Jesse.Zhang@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Alexander.Deucher@amd.com>,
Christian Koenig <christian.koenig@amd.com>,
<lijo.lazar@amd.com>, <Mario.Novales@amd.com>,
<Manu.Rastogi@amd.com>, <Jiongyu.Zhu@amd.com>,
Jesse Zhang <Jesse.Zhang@amd.com>
Subject: [PATCH v2 09/15] drm/amdgpu/gfx: add a gfx engine reset helper
Date: Thu, 22 Oct 2026 16:19:49 +0800 [thread overview]
Message-ID: <20261022082011.331462-9-Jesse.Zhang@amd.com> (raw)
In-Reply-To: <20261022082011.331462-1-Jesse.Zhang@amd.com>
Add amdgpu_gfx_reset_gfx_engine() around the reset_engine callback, and
AMDGPU_RESET_TYPE_PER_ENGINE for a reset of a single engine of an IP
block, eg. only the graphics engine of the GFX IP, that leaves its other
engines running. The helper only resets the engine when the IP reports
that reset type, which none does yet.
As for a pipe reset, the other kernel gfx rings are backed up, tested
and replayed, and MES is suspended across the reset, so that it doesn't
schedule the queues of the compute engine meanwhile. Their work is only
paused.
MES fetches its commands through the CP front-end though, and a hung gfx
stream can keep it from completing the suspend. Reset the engine anyway:
the reset frees the front-end.
It only takes the reset domain for read. That keeps full resets away
while the compute engine keeps working. KFD, for example, adds and
removes MES queues only after a read trylock of the reset domain, and
taking it for write would fail those calls with -EIO.
The reset also clears the HQDs of the gfx user queues. Call
amdgpu_userq_pre_engine_reset() after the MES suspend, to save the ring
state of the queues still on a HQD, and amdgpu_userq_post_engine_reset()
after the reset, before MES resumes, to restore them. @guilty_queue is
the gfx user queue that hung, if any: it is hung instead. If the engine
reset fails, amdgpu_userq_cancel_engine_reset() drops the saved ring
state for the full reset that follows.
Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 83 +++++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 4 ++
3 files changed, 88 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index c32d3b0b4153..da99fa2f1b87 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -309,6 +309,7 @@ extern uint amdgpu_hdmi_hpd_debounce_delay_ms;
#define AMDGPU_RESET_TYPE_PER_QUEUE (1 << 2) /* per queue */
#define AMDGPU_RESET_TYPE_PER_PIPE (1 << 3) /* per pipe */
#define AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET (1 << 4) /* soft-resets an IP block */
+#define AMDGPU_RESET_TYPE_PER_ENGINE (1 << 5) /* resets the engine of one ring type */
/* max cursor sizes (in pixels) */
#define CIK_CURSOR_WIDTH 128
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 0ae6e990c310..fecf2c02973a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -2181,6 +2181,89 @@ int amdgpu_gfx_reset_mes_gfx(struct amdgpu_device *adev,
return r;
}
+/**
+ * amdgpu_gfx_reset_gfx_engine() - Reset the graphics engine.
+ *
+ * @adev: amdgpu device
+ * @guilty_ring: The kernel gfx ring that hung, or NULL for a user queue.
+ * @guilty_fence: The fence which didn't signal on @guilty_ring.
+ * @guilty_queue: The gfx user queue that hung, or NULL for a kernel ring.
+ *
+ * Reset only the graphics engine, when a gfx queue or pipe reset failed.
+ */
+int amdgpu_gfx_reset_gfx_engine(struct amdgpu_device *adev,
+ struct amdgpu_ring *guilty_ring,
+ struct amdgpu_fence *guilty_fence,
+ struct amdgpu_usermode_queue *guilty_queue)
+{
+ struct amdgpu_gfx_pipe_reset_ctx ctx;
+ struct amdgpu_ring *ring;
+ int i, r;
+
+ if (!(adev->gfx.gfx_supported_reset & AMDGPU_RESET_TYPE_PER_ENGINE) ||
+ !adev->gfx.funcs->reset_engine)
+ return -EOPNOTSUPP;
+
+ dev_err(adev->dev, "Starting gfx engine reset\n");
+
+ /*
+ * Keep a full GPU reset out. Only for read: KFD can still add and
+ * remove its queues meanwhile.
+ */
+ down_read(&adev->reset_domain->sem);
+ mutex_lock(&adev->gfx.mec.reset_mutex);
+
+ amdgpu_gfx_pipe_reset_prepare(adev, guilty_ring, U32_MAX, U32_MAX, &ctx);
+
+ /* The suspend may time out while the gfx engine hangs: reset anyway. */
+ amdgpu_mes_suspend(adev, 0);
+ amdgpu_userq_pre_engine_reset(adev, AMDGPU_HW_IP_GFX);
+ r = adev->gfx.funcs->reset_engine(adev, AMDGPU_GFX_ENGINE_GFX);
+ if (r) {
+ amdgpu_userq_cancel_engine_reset(adev, AMDGPU_HW_IP_GFX);
+ amdgpu_mes_resume(adev, 0);
+ goto exit;
+ }
+
+ amdgpu_userq_post_engine_reset(adev, AMDGPU_HW_IP_GFX, guilty_queue);
+ r = amdgpu_mes_resume(adev, 0);
+ if (r)
+ goto exit;
+
+ if (guilty_ring) {
+ r = amdgpu_ring_reset_helper_end(guilty_ring, guilty_fence);
+ if (r)
+ goto exit;
+ }
+
+ for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
+ ring = &adev->gfx.gfx_ring[i];
+ if (ring == guilty_ring || !amdgpu_ring_sched_ready(ring))
+ continue;
+ r = amdgpu_ring_reset_helper_end(ring, NULL);
+ if (r)
+ goto exit;
+ }
+
+ /* Restart the schedulers stopped by amdgpu_gfx_pipe_reset_prepare(). */
+ for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
+ ring = &adev->gfx.gfx_ring[i];
+ if (ring != guilty_ring && amdgpu_ring_sched_ready(ring) &&
+ drm_sched_is_stopped(&ring->sched))
+ drm_sched_wqueue_start(&ring->sched);
+ }
+
+exit:
+ mutex_unlock(&adev->gfx.mec.reset_mutex);
+ up_read(&adev->reset_domain->sem);
+
+ if (r)
+ dev_err(adev->dev, "Failed gfx engine reset: %d\n", r);
+ else
+ dev_err(adev->dev, "Successful gfx engine reset\n");
+ return r;
+}
+
int amdgpu_gfx_mes_reset_queue(struct amdgpu_ring *ring,
unsigned int vmid,
struct amdgpu_fence *timedout_fence,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index 5e9338563de3..007da939d135 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -751,6 +751,10 @@ int amdgpu_gfx_reset_mes_gfx(struct amdgpu_device *adev,
struct amdgpu_fence *guilty_fence,
struct amdgpu_usermode_queue *queue,
unsigned int vmid, bool use_mmio);
+int amdgpu_gfx_reset_gfx_engine(struct amdgpu_device *adev,
+ struct amdgpu_ring *guilty_ring,
+ struct amdgpu_fence *guilty_fence,
+ struct amdgpu_usermode_queue *guilty_queue);
static inline const char *amdgpu_gfx_compute_mode_desc(int mode)
{
--
2.50.1
next prev parent reply other threads:[~2026-10-22 8:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 8:19 [PATCH v2 01/15] drm/amdgpu/gfx: add a reset_engine callback Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 02/15] drm/amdgpu/gfx12: add a gfx engine reset Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 03/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-10-25 17:10 ` Timur Kristóf
2026-10-26 8:35 ` Zhang, Jesse(Jie)
2026-10-26 23:51 ` Timur Kristóf
2026-10-27 9:19 ` Zhang, Jesse(Jie)
2026-10-22 8:19 ` [PATCH v2 04/15] drm/amdgpu/gfx: add callbacks to read and restore the ring state of a gfx queue Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 05/15] drm/amdgpu/gfx12: " Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 06/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 07/15] drm/amdgpu/userq: add a helper to signal the fences of a queue up to a point Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 08/15] drm/amdgpu/userq: add helpers to keep the user queues of one engine across a reset Jesse Zhang
2026-10-22 8:19 ` Jesse Zhang [this message]
2026-10-22 8:19 ` [PATCH v2 10/15] drm/amdgpu/gfx: reset the gfx engine when a kernel gfx queue reset fails Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 11/15] drm/amdgpu/userq: reset the gfx engine when a gfx user " Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 12/15] drm/amdgpu: show the engine reset in the reset masks Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 13/15] drm/amdgpu: add a debug_mask bit to disable the engine reset Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 14/15] drm/amdgpu/gfx12: enable the gfx " Jesse Zhang
2026-10-22 8:19 ` [PATCH v2 15/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-10-25 16:48 ` [PATCH v2 01/15] drm/amdgpu/gfx: add a reset_engine callback Timur Kristóf
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=20261022082011.331462-9-Jesse.Zhang@amd.com \
--to=jesse.zhang@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Jiongyu.Zhu@amd.com \
--cc=Manu.Rastogi@amd.com \
--cc=Mario.Novales@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=lijo.lazar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.