Skip to contentSkip to conversation

drm/amdgpu: Add new reset option and rework coredump

PATCH Superseded André Almeida 3 participants 13 messages Jul 13, 2023 – Jul 14, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/amdgpu: Add new reset option and rework coredump

Hi,

The goal of this patchset is to improve debugging device resets on amdgpu.

The first patch creates a new module parameter to disable soft recoveries, ensuring every recovery go through the full device reset, making easier to generate resets from userspace tools like [0] and [1]. This is important to validate how the stack behaves on resets, from end-to-end.

The last patches are a rework to store more information at devcoredump files, making it more useful to be attached to bug reports.

The new coredump content look like this:

**** AMDGPU Device Coredump ****
version: 1
kernel: 6.4.0-rc7-tony+
module: amdgpu
time: 702.743534320
process_name: vulkan-triangle PID: 4561
IBs:
[0] 0xffff800100545000
[1] 0xffff800100001000
ring name: gfx_0.0.0

Due to nested IBs, this may not be the one that really caused the hang, but it gives some direction.

Thanks,
André

[0] https://gitlab.freedesktop.org/andrealmeid/gpu-timeout
[1] https://github.com/andrealmeid/vulkan-triangle-v1

Changelog:
v1: https://lore.kernel.org/dri-devel/[email protected]/
- Drop "Mark contexts guilty for causing soft recoveries" patch
- Use GFP_NOWAIT for devcoredump allocation

André Almeida (6):
drm/amdgpu: Create a module param to disable soft recovery drm/amdgpu: Allocate coredump memory in a nonblocking way drm/amdgpu: Rework coredump to use memory dynamically drm/amdgpu: Limit info in coredump for kernel threads drm/amdgpu: Log IBs and ring name at coredump drm/amdgpu: Create version number for coredumps

 drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 21 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 99 +++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  9 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   |  6 +-
 4 files changed, 106 insertions(+), 29 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/6 drm/amdgpu: Create a module param to disable soft recovery

Create a module parameter to disable soft recoveries on amdgpu, making every recovery go through the device reset path. This option makes easier to force device resets for testing and debugging purposes.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  | 9 +++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 6 +++++-
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index a84bd4a0c421..dbe062a087c5 100644
@@ -189,6 +189,7 @@ extern uint amdgpu_force_long_training;
 extern int amdgpu_lbpw;
 extern int amdgpu_compute_multipipe;
 extern int amdgpu_gpu_recovery;
+extern bool amdgpu_soft_recovery;
 extern int amdgpu_emu_mode;
 extern uint amdgpu_smu_memory_pool_size;
 extern int amdgpu_smu_pptable_id;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +9 -0
index 3b711babd4e2..7c69f3169aa6 100644
@@ -163,6 +163,7 @@ uint amdgpu_force_long_training;
 int amdgpu_lbpw = -1;
 int amdgpu_compute_multipipe = -1;
 int amdgpu_gpu_recovery = -1; /* auto */
+bool amdgpu_soft_recovery = true;
 int amdgpu_emu_mode;
 uint amdgpu_smu_memory_pool_size;
 int amdgpu_smu_pptable_id = -1;
@@ -540,6 +541,14 @@ module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);
 MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)");
 module_param_named(gpu_recovery, amdgpu_gpu_recovery, int, 0444);
 
+/**
+ * DOC: gpu_soft_recovery (bool)
+ * Set true to allow the driver to try soft recoveries if a job get stuck. Set
+ * to false to always force a GPU reset during recovery.
+ */
+MODULE_PARM_DESC(gpu_soft_recovery, "Enable GPU soft recovery mechanism (default: true)");
+module_param_named(gpu_soft_recovery, amdgpu_soft_recovery, bool, 0644);
+
 /**
  * DOC: emu_mode (int)
  * Set value 1 to enable emulation mode. This is only needed when running on an emulator. The default is 0 (disabled).
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5 -1
index 80d6e132e409..40678d9fb17e 100644
@@ -434,8 +434,12 @@ bool amdgpu_ring_soft_recovery(struct amdgpu_ring *ring, unsigned int vmid,
 			       struct dma_fence *fence)
 {
 	unsigned long flags;
+	ktime_t deadline;
 
-	ktime_t deadline = ktime_add_us(ktime_get(), 10000);
+	if (!amdgpu_soft_recovery)
+		return false;
+
+	deadline = ktime_add_us(ktime_get(), 10000);
 
 	if (amdgpu_sriov_vf(ring->adev) || !ring->funcs->soft_recovery || !fence)
 		return false;
Signature · 1 line
2.41.0
#2 lore raw

PATCH v2 2/6 drm/amdgpu: Allocate coredump memory in a nonblocking way

In reply to André Almeida

During a GPU reset, a normal memory reclaim could block to reclaim memory. Giving that coredump is a best effort mechanism, it shouldn't disturb the reset path. Change its memory allocation flag to a nonblocking one.

---
v2: New patch

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index e25f085ee886..a824f844a984 100644
@@ -5011,7 +5011,7 @@ static void amdgpu_reset_capture_coredumpm(struct amdgpu_device *adev)
 	struct drm_device *dev = adev_to_drm(adev);
 
 	ktime_get_ts64(&adev->reset_time);
-	dev_coredumpm(dev->dev, THIS_MODULE, adev, 0, GFP_KERNEL,
+	dev_coredumpm(dev->dev, THIS_MODULE, adev, 0, GFP_NOWAIT,
 		      amdgpu_devcoredump_read, amdgpu_devcoredump_free);
 }
 #endif
Signature · 1 line
2.41.0
maintainer Reviewed-by on v2 2/6
#3 lore raw

Re: [PATCH v2 2/6] drm/amdgpu: Allocate coredump memory in a nonblocking way

Am 13.07.23 um 23:32 schrieb André Almeida:

Quoted 6 lines

During a GPU reset, a normal memory reclaim could block to reclaim memory. Giving that coredump is a best effort mechanism, it shouldn't disturb the reset path. Change its memory allocation flag to a nonblocking one.

Quoted 19 lines

---
v2: New patch

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index e25f085ee886..a824f844a984 100644
@@ -5011,7 +5011,7 @@ static void amdgpu_reset_capture_coredumpm(struct amdgpu_device *adev)
  	struct drm_device *dev = adev_to_drm(adev);
 
  	ktime_get_ts64(&adev->reset_time);
-	dev_coredumpm(dev->dev, THIS_MODULE, adev, 0, GFP_KERNEL,
+	dev_coredumpm(dev->dev, THIS_MODULE, adev, 0, GFP_NOWAIT,
  		      amdgpu_devcoredump_read, amdgpu_devcoredump_free);
  }
  #endif
#4 lore raw

PATCH v2 3/6 drm/amdgpu: Rework coredump to use memory dynamically

In reply to André Almeida

Instead of storing coredump information inside amdgpu_device struct, move if to a proper separated struct and allocate it dynamically. This will make it easier to further expand the logged information.

---
v2: Replace GFP_KERNEL with GPF_NOWAIT

 drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 14 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 65 ++++++++++++++--------
 2 files changed, 51 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +9 -5
index dbe062a087c5..e1cc83a89d46 100644
@@ -1068,11 +1068,6 @@ struct amdgpu_device {
 	uint32_t                        *reset_dump_reg_list;
 	uint32_t			*reset_dump_reg_value;
 	int                             num_regs;
-#ifdef CONFIG_DEV_COREDUMP
-	struct amdgpu_task_info         reset_task_info;
-	bool                            reset_vram_lost;
-	struct timespec64               reset_time;
-#endif
 
 	bool                            scpm_enabled;
 	uint32_t                        scpm_status;
@@ -1085,6 +1080,15 @@ struct amdgpu_device {
 	uint32_t			aid_mask;
 };
 
+#ifdef CONFIG_DEV_COREDUMP
+struct amdgpu_coredump_info {
+	struct amdgpu_device		*adev;
+	struct amdgpu_task_info         reset_task_info;
+	struct timespec64               reset_time;
+	bool                            reset_vram_lost;
+};
+#endif
+
 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
 {
 	return container_of(ddev, struct amdgpu_device, ddev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +42 -23

104 lines not on this page · raw message

Signature · 1 line
2.41.0
#5 lore raw

Re: [PATCH v2 3/6] drm/amdgpu: Rework coredump to use memory dynamically

Am 13.07.23 um 23:32 schrieb André Almeida:

Quoted 7 lines

Instead of storing coredump information inside amdgpu_device struct, move if to a proper separated struct and allocate it dynamically. This will make it easier to further expand the logged information.

---
v2: Replace GFP_KERNEL with GPF_NOWAIT

Much better, thanks!

Quoted 24 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 14 +++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 65 ++++++++++++++--------
  2 files changed, 51 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -5
index dbe062a087c5..e1cc83a89d46 100644
@@ -1068,11 +1068,6 @@ struct amdgpu_device {
  	uint32_t                        *reset_dump_reg_list;
  	uint32_t			*reset_dump_reg_value;
  	int                             num_regs;
-#ifdef CONFIG_DEV_COREDUMP
-	struct amdgpu_task_info         reset_task_info;
-	bool                            reset_vram_lost;
-	struct timespec64               reset_time;
-#endif
 
  	bool                            scpm_enabled;
  	uint32_t                        scpm_status;
@@ -1085,6 +1080,15 @@ struct amdgpu_device {
  	uint32_t			aid_mask;
  };

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_device { · line 1091

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +9 -0
 
+#ifdef CONFIG_DEV_COREDUMP
+struct amdgpu_coredump_info {
+	struct amdgpu_device		*adev;
+	struct amdgpu_task_info         reset_task_info;
+	struct timespec64               reset_time;
+	bool                            reset_vram_lost;
+};
+#endif
+

We should probably put that into amdgpu_reset.h instead and move the amdgpu_coredump_* functions into amdgpu_reset.c as well.

Apart from that this looks good of hand.

Thanks,
Christian.

Quoted 115 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
  static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
  {
  	return container_of(ddev, struct amdgpu_device, ddev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +42 -23
index a824f844a984..e80670420586 100644
@@ -4963,12 +4963,17 @@ static int amdgpu_reset_reg_dumps(struct amdgpu_device *adev)
  	return 0;
  }
 
-#ifdef CONFIG_DEV_COREDUMP
+#ifndef CONFIG_DEV_COREDUMP
+static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
+			    struct amdgpu_reset_context *reset_context)
+{
+}
+#else
  static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
  		size_t count, void *data, size_t datalen)
  {
  	struct drm_printer p;
-	struct amdgpu_device *adev = data;
+	struct amdgpu_coredump_info *coredump = data;
  	struct drm_print_iterator iter;
  	int i;
 
@@ -4982,21 +4987,21 @@ static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
  	drm_printf(&p, "**** AMDGPU Device Coredump ****\n");
  	drm_printf(&p, "kernel: " UTS_RELEASE "\n");
  	drm_printf(&p, "module: " KBUILD_MODNAME "\n");
-	drm_printf(&p, "time: %lld.%09ld\n", adev->reset_time.tv_sec, adev->reset_time.tv_nsec);
-	if (adev->reset_task_info.pid)
+	drm_printf(&p, "time: %lld.%09ld\n", coredump->reset_time.tv_sec, coredump->reset_time.tv_nsec);
+	if (coredump->reset_task_info.pid)
  		drm_printf(&p, "process_name: %s PID: %d\n",
-			   adev->reset_task_info.process_name,
-			   adev->reset_task_info.pid);
+			   coredump->reset_task_info.process_name,
+			   coredump->reset_task_info.pid);
 
-	if (adev->reset_vram_lost)
+	if (coredump->reset_vram_lost)
  		drm_printf(&p, "VRAM is lost due to GPU reset!\n");
-	if (adev->num_regs) {
+	if (coredump->adev->num_regs) {
  		drm_printf(&p, "AMDGPU register dumps:\nOffset:     Value:\n");
 
-		for (i = 0; i < adev->num_regs; i++)
+		for (i = 0; i < coredump->adev->num_regs; i++)
  			drm_printf(&p, "0x%08x: 0x%08x\n",
-				   adev->reset_dump_reg_list[i],
-				   adev->reset_dump_reg_value[i]);
+				   coredump->adev->reset_dump_reg_list[i],
+				   coredump->adev->reset_dump_reg_value[i]);
  	}
 
  	return count - iter.remain;
@@ -5004,14 +5009,34 @@ static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
 
  static void amdgpu_devcoredump_free(void *data)
  {
+	kfree(data);
  }
 
-static void amdgpu_reset_capture_coredumpm(struct amdgpu_device *adev)
+static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
+			    struct amdgpu_reset_context *reset_context)
  {
+	struct amdgpu_coredump_info *coredump;
  	struct drm_device *dev = adev_to_drm(adev);
 
-	ktime_get_ts64(&adev->reset_time);
-	dev_coredumpm(dev->dev, THIS_MODULE, adev, 0, GFP_NOWAIT,
+	coredump = kmalloc(sizeof(*coredump), GFP_NOWAIT);
+
+	if (!coredump) {
+		DRM_ERROR("%s: failed to allocate memory for coredump\n", __func__);
+		return;
+	}
+
+	memset(coredump, 0, sizeof(*coredump));
+
+	coredump->reset_vram_lost = vram_lost;
+
+	if (reset_context->job && reset_context->job->vm)
+		coredump->reset_task_info = reset_context->job->vm->task_info;
+
+	coredump->adev = adev;
+
+	ktime_get_ts64(&coredump->reset_time);
+
+	dev_coredumpm(dev->dev, THIS_MODULE, coredump, 0, GFP_NOWAIT,
  		      amdgpu_devcoredump_read, amdgpu_devcoredump_free);
  }
  #endif
@@ -5119,15 +5144,9 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
  					goto out;
 
  				vram_lost = amdgpu_device_check_vram_lost(tmp_adev);
-#ifdef CONFIG_DEV_COREDUMP
-				tmp_adev->reset_vram_lost = vram_lost;
-				memset(&tmp_adev->reset_task_info, 0,
-						sizeof(tmp_adev->reset_task_info));
-				if (reset_context->job && reset_context->job->vm)
-					tmp_adev->reset_task_info =
-						reset_context->job->vm->task_info;
-				amdgpu_reset_capture_coredumpm(tmp_adev);
-#endif
+
+				amdgpu_coredump(tmp_adev, vram_lost, reset_context);
+
  				if (vram_lost) {
  					DRM_INFO("VRAM is lost due to GPU reset!\n");
  					amdgpu_inc_vram_lost(tmp_adev);
#6 lore raw

PATCH v2 4/6 drm/amdgpu: Limit info in coredump for kernel threads

In reply to André Almeida

If a kernel thread caused the reset, the information available to be logged will be limited, so return early in the dump function.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -1
index e80670420586..07546781b8b8 100644
@@ -4988,10 +4988,14 @@ static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
 	drm_printf(&p, "kernel: " UTS_RELEASE "\n");
 	drm_printf(&p, "module: " KBUILD_MODNAME "\n");
 	drm_printf(&p, "time: %lld.%09ld\n", coredump->reset_time.tv_sec, coredump->reset_time.tv_nsec);
-	if (coredump->reset_task_info.pid)
+	if (coredump->reset_task_info.pid) {
 		drm_printf(&p, "process_name: %s PID: %d\n",
 			   coredump->reset_task_info.process_name,
 			   coredump->reset_task_info.pid);
+	} else {
+		drm_printf(&p, "GPU reset caused by a kernel thread\n");
+		return count - iter.remain;
+	}
 
 	if (coredump->reset_vram_lost)
 		drm_printf(&p, "VRAM is lost due to GPU reset!\n");
Signature · 1 line
2.41.0
#7 lore raw

Re: [PATCH v2 4/6] drm/amdgpu: Limit info in coredump for kernel threads

Am 13.07.23 um 23:32 schrieb André Almeida:

Quoted 2 lines

If a kernel thread caused the reset, the information available to be logged will be limited, so return early in the dump function.

Why? The register values and vram lost state should still be valid.

Christian.

Quoted 26 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -1
index e80670420586..07546781b8b8 100644
@@ -4988,10 +4988,14 @@ static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
  	drm_printf(&p, "kernel: " UTS_RELEASE "\n");
  	drm_printf(&p, "module: " KBUILD_MODNAME "\n");
  	drm_printf(&p, "time: %lld.%09ld\n", coredump->reset_time.tv_sec, coredump->reset_time.tv_nsec);
-	if (coredump->reset_task_info.pid)
+	if (coredump->reset_task_info.pid) {
  		drm_printf(&p, "process_name: %s PID: %d\n",
  			   coredump->reset_task_info.process_name,
  			   coredump->reset_task_info.pid);
+	} else {
+		drm_printf(&p, "GPU reset caused by a kernel thread\n");
+		return count - iter.remain;
+	}
 
  	if (coredump->reset_vram_lost)
  		drm_printf(&p, "VRAM is lost due to GPU reset!\n");
#8 lore raw

Re: [PATCH v2 4/6] drm/amdgpu: Limit info in coredump for kernel threads

Em 14/07/2023 04:52, Christian König escreveu:

Quoted 8 lines

Am 13.07.23 um 23:32 schrieb André Almeida:

Quoted 2 lines

If a kernel thread caused the reset, the information available to be logged will be limited, so return early in the dump function.

Why? The register values and vram lost state should still be valid.

Fair enough, I was thinking about the new added information, such as ring and job, that won't be around for this type of thread. I'll drop this patch for the next version.

Quoted 29 lines

Christian.

Quoted 26 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -1
index e80670420586..07546781b8b8 100644
@@ -4988,10 +4988,14 @@ static ssize_t amdgpu_devcoredump_read(char 
 *buffer, loff_t offset,
       drm_printf(&p, "kernel: " UTS_RELEASE "\n");
       drm_printf(&p, "module: " KBUILD_MODNAME "\n");
       drm_printf(&p, "time: %lld.%09ld\n", coredump->reset_time.tv_sec, coredump->reset_time.tv_nsec);
-    if (coredump->reset_task_info.pid)
+    if (coredump->reset_task_info.pid) {
           drm_printf(&p, "process_name: %s PID: %d\n",
                  coredump->reset_task_info.process_name,
                  coredump->reset_task_info.pid);
+    } else {
+        drm_printf(&p, "GPU reset caused by a kernel thread\n");
+        return count - iter.remain;
+    }
       if (coredump->reset_vram_lost)
           drm_printf(&p, "VRAM is lost due to GPU reset!\n");
#9 lore raw

PATCH v2 5/6 drm/amdgpu: Log IBs and ring name at coredump

In reply to André Almeida

Log the IB addresses used by the hung job along with the stuck ring name. Note that due to nested IBs, the one that caused the reset itself may be in not listed address.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 31 +++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index e1cc83a89d46..cfeaf93934fd 100644
@@ -1086,6 +1086,9 @@ struct amdgpu_coredump_info {
 	struct amdgpu_task_info         reset_task_info;
 	struct timespec64               reset_time;
 	bool                            reset_vram_lost;
+	u64				*ibs;
+	u32				num_ibs;
+	char				ring_name[16];
 };
 #endif
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +30 -1
index 07546781b8b8..431ccc3d7857 100644
@@ -5008,12 +5008,24 @@ static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
 				   coredump->adev->reset_dump_reg_value[i]);
 	}
 
+	if (coredump->num_ibs) {
+		drm_printf(&p, "IBs:\n");
+		for (i = 0; i < coredump->num_ibs; i++)
+			drm_printf(&p, "\t[%d] 0x%llx\n", i, coredump->ibs[i]);
+	}
+
+	if (coredump->ring_name[0] != '\0')
+		drm_printf(&p, "ring name: %s\n", coredump->ring_name);
+
 	return count - iter.remain;
 }
 
 static void amdgpu_devcoredump_free(void *data)
 {
-	kfree(data);
+	struct amdgpu_coredump_info *coredump = data;
+
+	kfree(coredump->ibs);
+	kfree(coredump);
 }
 
 static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
@@ -5021,6 +5033,8 @@ static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
 {
 	struct amdgpu_coredump_info *coredump;
 	struct drm_device *dev = adev_to_drm(adev);
+	struct amdgpu_job *job = reset_context->job;
+	int i;
 
 	coredump = kmalloc(sizeof(*coredump), GFP_NOWAIT);
 
@@ -5038,6 +5052,21 @@ static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
 
 	coredump->adev = adev;
 
+	if (job && job->num_ibs) {
+		struct amdgpu_ring *ring = to_amdgpu_ring(job->base.sched);
+		u32 num_ibs = job->num_ibs;
+
+		coredump->ibs = kmalloc_array(num_ibs, sizeof(coredump->ibs), GFP_NOWAIT);
+		if (coredump->ibs)
+			coredump->num_ibs = num_ibs;
+
+		for (i = 0; i < coredump->num_ibs; i++)
+			coredump->ibs[i] = job->ibs[i].gpu_addr;
+
+		if (ring)
+			strncpy(coredump->ring_name, ring->name, 16);
+	}
+
 	ktime_get_ts64(&coredump->reset_time);
 
 	dev_coredumpm(dev->dev, THIS_MODULE, coredump, 0, GFP_NOWAIT,
Signature · 1 line
2.41.0
#10 lore raw

Re: [PATCH v2 5/6] drm/amdgpu: Log IBs and ring name at coredump

Am 13.07.23 um 23:32 schrieb André Almeida:

Quoted 64 lines

Log the IB addresses used by the hung job along with the stuck ring name. Note that due to nested IBs, the one that caused the reset itself may be in not listed address.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 31 +++++++++++++++++++++-
  2 files changed, 33 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index e1cc83a89d46..cfeaf93934fd 100644
@@ -1086,6 +1086,9 @@ struct amdgpu_coredump_info {
  	struct amdgpu_task_info         reset_task_info;
  	struct timespec64               reset_time;
  	bool                            reset_vram_lost;
+	u64				*ibs;
+	u32				num_ibs;
+	char				ring_name[16];
  };
  #endif
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -1
index 07546781b8b8..431ccc3d7857 100644
@@ -5008,12 +5008,24 @@ static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
  				   coredump->adev->reset_dump_reg_value[i]);
  	}
 
+	if (coredump->num_ibs) {
+		drm_printf(&p, "IBs:\n");
+		for (i = 0; i < coredump->num_ibs; i++)
+			drm_printf(&p, "\t[%d] 0x%llx\n", i, coredump->ibs[i]);
+	}
+
+	if (coredump->ring_name[0] != '\0')
+		drm_printf(&p, "ring name: %s\n", coredump->ring_name);
+
  	return count - iter.remain;
  }
 
  static void amdgpu_devcoredump_free(void *data)
  {
-	kfree(data);
+	struct amdgpu_coredump_info *coredump = data;
+
+	kfree(coredump->ibs);
+	kfree(coredump);
  }
 
  static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
@@ -5021,6 +5033,8 @@ static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
  {
  	struct amdgpu_coredump_info *coredump;
  	struct drm_device *dev = adev_to_drm(adev);
+	struct amdgpu_job *job = reset_context->job;
+	int i;
 
  	coredump = kmalloc(sizeof(*coredump), GFP_NOWAIT);
 

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost, · line 5055

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -5038,6 +5052,21 @@ static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
 
  	coredump->adev = adev;
 
+	if (job && job->num_ibs) {

I really really really don't want any dependency of the core dump feature towards the job.

What we could do is to record the first executed IB VAs in the hw fence, but I'm not sure how useful this is in the first place.

We have some internal feature in progress to query the VA of the draw command which cause the waves currently executing in the SQ to be retrieved.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost, · line 5059

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+		struct amdgpu_ring *ring = to_amdgpu_ring(job->base.sched);
+		u32 num_ibs = job->num_ibs;
+
+		coredump->ibs = kmalloc_array(num_ibs, sizeof(coredump->ibs), GFP_NOWAIT);

This can fail pretty easily.

Christian.

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+		if (coredump->ibs)
+			coredump->num_ibs = num_ibs;
+
+		for (i = 0; i < coredump->num_ibs; i++)
+			coredump->ibs[i] = job->ibs[i].gpu_addr;
+
+		if (ring)
+			strncpy(coredump->ring_name, ring->name, 16);
+	}
+
  	ktime_get_ts64(&coredump->reset_time);
 
  	dev_coredumpm(dev->dev, THIS_MODULE, coredump, 0, GFP_NOWAIT,
#11 lore raw

Re: [PATCH v2 5/6] drm/amdgpu: Log IBs and ring name at coredump

Em 14/07/2023 04:57, Christian König escreveu:

Quoted 58 lines

Am 13.07.23 um 23:32 schrieb André Almeida:

Quoted 57 lines

Log the IB addresses used by the hung job along with the stuck ring name. Note that due to nested IBs, the one that caused the reset itself may be in not listed address.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 31 +++++++++++++++++++++-

  2 files changed, 33 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index e1cc83a89d46..cfeaf93934fd 100644
@@ -1086,6 +1086,9 @@ struct amdgpu_coredump_info {
       struct amdgpu_task_info         reset_task_info;
       struct timespec64               reset_time;
       bool                            reset_vram_lost;
+    u64                *ibs;
+    u32                num_ibs;
+    char                ring_name[16];
   };
   #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +14 -1
index 07546781b8b8..431ccc3d7857 100644
@@ -5008,12 +5008,24 @@ static ssize_t amdgpu_devcoredump_read(char 
 *buffer, loff_t offset,
                      coredump->adev->reset_dump_reg_value[i]);
       }
+    if (coredump->num_ibs) {
+        drm_printf(&p, "IBs:\n");
+        for (i = 0; i < coredump->num_ibs; i++)
+            drm_printf(&p, "\t[%d] 0x%llx\n", i, coredump->ibs[i]);
+    }
+
+    if (coredump->ring_name[0] != '\0')
+        drm_printf(&p, "ring name: %s\n", coredump->ring_name);
+
       return count - iter.remain;
   }
   static void amdgpu_devcoredump_free(void *data)
   {
-    kfree(data);
+    struct amdgpu_coredump_info *coredump = data;
+
+    kfree(coredump->ibs);
+    kfree(coredump);
   }
   static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,
@@ -5021,6 +5033,8 @@ static void amdgpu_coredump(struct amdgpu_device 
 *adev, bool vram_lost,
   {
       struct amdgpu_coredump_info *coredump;
       struct drm_device *dev = adev_to_drm(adev);
+    struct amdgpu_job *job = reset_context->job;
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_coredump(struct · line 5054

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
+    int i;
       coredump = kmalloc(sizeof(*coredump), GFP_NOWAIT);
@@ -5038,6 +5052,21 @@ static void amdgpu_coredump(struct 
 amdgpu_device *adev, bool vram_lost,
       coredump->adev = adev;
+    if (job && job->num_ibs) {

I really really really don't want any dependency of the core dump feature towards the job.

Because of the lifetime of job?

Do you think implementing amdgpu_job_get()/put() would help here?

Quoted 2 lines

What we could do is to record the first executed IB VAs in the hw fence, but I'm not sure how useful this is in the first place.

I see, any hint here of the timedout job would be helpful AFAIK.

Quoted 9 lines

We have some internal feature in progress to query the VA of the draw command which cause the waves currently executing in the SQ to be retrieved.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_coredump(struct amdgpu_device *adev, bool vram_lost,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
+        struct amdgpu_ring *ring = to_amdgpu_ring(job->base.sched);
+        u32 num_ibs = job->num_ibs;
+
+        coredump->ibs = kmalloc_array(num_ibs, sizeof(coredump->ibs), 
 GFP_NOWAIT);

This can fail pretty easily.

Because of its size?

Quoted 16 lines

Christian.

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+        if (coredump->ibs)
+            coredump->num_ibs = num_ibs;
+
+        for (i = 0; i < coredump->num_ibs; i++)
+            coredump->ibs[i] = job->ibs[i].gpu_addr;
+
+        if (ring)
+            strncpy(coredump->ring_name, ring->name, 16);
+    }
+
       ktime_get_ts64(&coredump->reset_time);
       dev_coredumpm(dev->dev, THIS_MODULE, coredump, 0, GFP_NOWAIT,
#12 lore raw

PATCH v2 6/6 drm/amdgpu: Create version number for coredumps

In reply to André Almeida

Even if there's nothing currently parsing amdgpu's coredump files, if we eventually have such tools they will be glad to find a version field to properly read the file.

Create a version number to be displayed on top of coredump file, to be incremented when the file format or content get changed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
 2 files changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index cfeaf93934fd..905574acf3a0 100644
@@ -1081,6 +1081,9 @@ struct amdgpu_device {
 };
 
 #ifdef CONFIG_DEV_COREDUMP
+
+#define AMDGPU_COREDUMP_VERSION "1"
+
 struct amdgpu_coredump_info {
 	struct amdgpu_device		*adev;
 	struct amdgpu_task_info         reset_task_info;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
index 431ccc3d7857..c83ea7aa135a 100644
@@ -4985,6 +4985,7 @@ static ssize_t amdgpu_devcoredump_read(char *buffer, loff_t offset,
 	p = drm_coredump_printer(&iter);
 
 	drm_printf(&p, "**** AMDGPU Device Coredump ****\n");
+	drm_printf(&p, "version: " AMDGPU_COREDUMP_VERSION "\n");
 	drm_printf(&p, "kernel: " UTS_RELEASE "\n");
 	drm_printf(&p, "module: " KBUILD_MODNAME "\n");
 	drm_printf(&p, "time: %lld.%09ld\n", coredump->reset_time.tv_sec, coredump->reset_time.tv_nsec);
Signature · 1 line
2.41.0