All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Turner <mattst88@gmail.com>
To: "Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Sunil Khatri" <sunil.khatri@amd.com>,
	"Trigger Huang" <Trigger.Huang@amd.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org, Matt Turner <mattst88@gmail.com>
Subject: [PATCH 03/14] drm/amdgpu: don't overwrite the IP state while a coredump is formatted
Date: Wed, 02 Dec 2026 17:36:09 -0500	[thread overview]
Message-ID: <20261202-amdgpu-devcoredump-v1-3-3dfa0e033b97@gmail.com> (raw)
In-Reply-To: <20261202-amdgpu-devcoredump-v1-0-3dfa0e033b97@gmail.com>

The IP blocks' dump_ip_state() saves their registers into per device
arrays, and the coredump worker prints them from there with
print_ip_state() while it formats the dump, concurrently with recovery.
A hang detected while the worker is still busy runs dump_ip_state()
again and overwrites the arrays under the worker, so the first dump can
mix the registers of two hangs. The second hang's coredump is then
dropped because the worker is busy, so the overwrite gains nothing.

Move the dump into amdgpu_coredump_dump_ip_state(), which skips it while
the worker is busy and records whether it ran. amdgpu_coredump() takes
that into the coredump and clears it, so if the worker finishes between
the two, the new dump says the IP state is unavailable instead of
showing the previous hang's registers. The callers all run on the reset
domain's workqueue, so no other dump can come in between.

Fixes: af8644121e3e ("drm/amdgpu: add ip dump for each ip in devcoredump")
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 56 +++++++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h |  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c       | 12 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c          | 10 +----
 5 files changed, 59 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 5dfb57e7c0b3..7eff62f4cdda 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -930,6 +930,8 @@ struct amdgpu_device {
 #ifdef CONFIG_DEV_COREDUMP
 	struct amdgpu_coredump_info	*coredump;
 	struct work_struct		coredump_work;
+	/* the IP state was dumped for the next coredump */
+	bool				coredump_ip_state_valid;
 #endif
 
 	struct mutex			benchmark_mutex;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c
index 0c6533b950f6..0e235096977b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c
@@ -29,6 +29,9 @@
 #include "atom.h"
 
 #ifndef CONFIG_DEV_COREDUMP
+void amdgpu_coredump_dump_ip_state(struct amdgpu_device *adev)
+{
+}
 void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,
 		     bool vram_lost, struct amdgpu_job *job)
 {
@@ -451,12 +454,17 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_inf
 
 	/* dump the ip state for each ip */
 	drm_printf(&p, "IP Dump\n");
-	for (int i = 0; i < coredump->adev->num_ip_blocks; i++) {
-		ip_block = &coredump->adev->ip_blocks[i];
-		if (ip_block->version->funcs->print_ip_state) {
-			drm_printf(&p, "IP: %s\n", ip_block->version->funcs->name);
-			ip_block->version->funcs->print_ip_state(ip_block, &p);
-			drm_printf(&p, "\n");
+	if (!coredump->ip_state_valid) {
+		drm_printf(&p, "unavailable\n\n");
+	} else {
+		for (int i = 0; i < coredump->adev->num_ip_blocks; i++) {
+			ip_block = &coredump->adev->ip_blocks[i];
+			if (ip_block->version->funcs->print_ip_state) {
+				drm_printf(&p, "IP: %s\n",
+					   ip_block->version->funcs->name);
+				ip_block->version->funcs->print_ip_state(ip_block, &p);
+				drm_printf(&p, "\n");
+			}
 		}
 	}
 
@@ -566,6 +574,36 @@ static void amdgpu_devcoredump_deferred_work(struct work_struct *work)
 	adev->coredump = NULL;
 }
 
+/**
+ * amdgpu_coredump_dump_ip_state - save the IP state for the next coredump
+ * @adev: amdgpu device pointer
+ *
+ * Run each IP block's dump_ip_state() so that the following amdgpu_coredump()
+ * can include the register state at the time of the hang.
+ *
+ * The coredump worker reads the saved registers while it formats a dump, so
+ * skip this while the worker is busy. Callers run on the reset domain's
+ * single threaded workqueue, so no other hang can be dumped in between.
+ */
+void amdgpu_coredump_dump_ip_state(struct amdgpu_device *adev)
+{
+	int i;
+
+	adev->coredump_ip_state_valid = false;
+
+	if (work_busy(&adev->coredump_work))
+		return;
+
+	dev_info(adev->dev, "Dumping IP State\n");
+	for (i = 0; i < adev->num_ip_blocks; i++)
+		if (adev->ip_blocks[i].version->funcs->dump_ip_state)
+			adev->ip_blocks[i].version->funcs
+				->dump_ip_state((void *)&adev->ip_blocks[i]);
+	dev_info(adev->dev, "Dumping IP State Completed\n");
+
+	adev->coredump_ip_state_valid = true;
+}
+
 void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,
 		     bool vram_lost, struct amdgpu_job *job)
 {
@@ -575,8 +613,13 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,
 	struct drm_sched_job *s_job;
 	u64 ring_count;
 	struct amdgpu_ring *ring;
+	bool ip_state_valid;
 	int i, idx;
 
+	/* Don't let a later coredump print this hang's IP state. */
+	ip_state_valid = adev->coredump_ip_state_valid;
+	adev->coredump_ip_state_valid = false;
+
 	/* No need to generate a new coredump if there's one in progress already. */
 	if (work_busy(&adev->coredump_work))
 		return;
@@ -590,6 +633,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,
 
 	coredump->skip_vram_check = skip_vram_check;
 	coredump->reset_vram_lost = vram_lost;
+	coredump->ip_state_valid = ip_state_valid;
 
 	if (job && job->pasid) {
 		struct amdgpu_task_info *ti;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h
index cb874d8c3394..54b323b007db 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h
@@ -51,6 +51,8 @@ struct amdgpu_coredump_info {
 	bool                            skip_vram_check;
 	bool                            reset_vram_lost;
 	struct amdgpu_ring              *ring;
+	/* the IP blocks' dump_ip_state() was run for this hang */
+	bool				ip_state_valid;
 
 	struct amdgpu_coredump_ring	*rings;
 	u32				num_rings;
@@ -68,6 +70,7 @@ struct amdgpu_coredump_info {
 };
 #endif
 
+void amdgpu_coredump_dump_ip_state(struct amdgpu_device *adev);
 void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,
 		     bool vram_lost, struct amdgpu_job *job);
 void amdgpu_coredump_init(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 4a98a667526d..9b61589b891e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -5197,15 +5197,9 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
 	if (!amdgpu_sriov_vf(adev)) {
 		need_full_reset = true;
 
-		if (!test_bit(AMDGPU_SKIP_COREDUMP, &reset_context->flags)) {
-			dev_info(adev->dev, "Dumping IP State\n");
-			/* Trigger ip dump before we reset the asic */
-			for (i = 0; i < adev->num_ip_blocks; i++)
-				if (adev->ip_blocks[i].version->funcs->dump_ip_state)
-					adev->ip_blocks[i].version->funcs
-						->dump_ip_state((void *)&adev->ip_blocks[i]);
-			dev_info(adev->dev, "Dumping IP State Completed\n");
-		}
+		/* Trigger ip dump before we reset the asic */
+		if (!test_bit(AMDGPU_SKIP_COREDUMP, &reset_context->flags))
+			amdgpu_coredump_dump_ip_state(adev);
 
 		if (need_full_reset)
 			r = amdgpu_device_ip_suspend(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index fa13d7beba80..e6d7514b0a02 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -36,15 +36,7 @@
 static void amdgpu_job_do_core_dump(struct amdgpu_device *adev,
 				    struct amdgpu_job *job)
 {
-	int i;
-
-	dev_info(adev->dev, "Dumping IP State\n");
-	for (i = 0; i < adev->num_ip_blocks; i++)
-		if (adev->ip_blocks[i].version->funcs->dump_ip_state)
-			adev->ip_blocks[i].version->funcs
-				->dump_ip_state((void *)&adev->ip_blocks[i]);
-	dev_info(adev->dev, "Dumping IP State Completed\n");
-
+	amdgpu_coredump_dump_ip_state(adev);
 	amdgpu_coredump(adev, true, false, job);
 }
 

-- 
2.56.1


  parent reply	other threads:[~2026-12-02 22:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 22:36 [PATCH 00/14] drm/amdgpu: capture more of the hang state in the devcoredump Matt Turner
2026-12-02 22:36 ` [PATCH 01/14] drm/amdgpu: dump the IP state of each device in an XGMI hive Matt Turner
2026-12-02 22:36 ` [PATCH 02/14] drm/amdgpu: only give the hung job to its own device's coredump Matt Turner
2026-12-02 22:36 ` Matt Turner [this message]
2026-12-02 22:36 ` [PATCH 04/14] drm/amdgpu: take a coredump before resets done by a reset handler Matt Turner
2026-12-02 22:36 ` [PATCH 05/14] drm/amdgpu: copy the VM fault info when the hang is detected Matt Turner
2026-12-02 22:36 ` [PATCH 06/14] drm/amdgpu/gfx10-12: dump CP_STAT and the IB2 state of each gfx queue Matt Turner
2026-12-02 22:36 ` [PATCH 07/14] drm/amdgpu: copy the IB contents before formatting the devcoredump Matt Turner
2026-12-02 22:36 ` [PATCH 08/14] drm/amdgpu: copy the IB contents when the hang is detected Matt Turner
2026-12-02 22:36 ` [PATCH 09/14] drm/amdgpu: record the submitting thread of the hung job in the coredump Matt Turner
2026-12-02 22:36 ` [PATCH 10/14] drm/amdgpu: dump the unsignaled fences of each ring " Matt Turner
2026-12-02 22:36 ` [PATCH 11/14] drm/amdgpu: report dropped devcoredumps Matt Turner
2026-12-02 22:36 ` [PATCH 12/14] drm/amdgpu: list the VM mappings of the hung job in the coredump Matt Turner
2026-12-02 22:36 ` [PATCH 13/14] drm/amdgpu: add AMDGPU_VM_PAGE_DUMP to include BOs " Matt Turner
2026-12-02 22:36 ` [PATCH 14/14] drm/amdgpu: bump the devcoredump version Matt Turner

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=20261202-amdgpu-devcoredump-v1-3-3dfa0e033b97@gmail.com \
    --to=mattst88@gmail.com \
    --cc=Trigger.Huang@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=sunil.khatri@amd.com \
    --cc=tzimmermann@suse.de \
    /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.