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 <[email protected]>
---
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