amdgpu_coredump() silently returns when the worker is still formatting
the previous dump or when allocating the dump fails, and the worker
silently frees the dump when allocating the formatted output fails.
Someone looking at a dump, or waiting for one, has no way to tell that
hangs were missed.

Warn when amdgpu drops a dump, count the dropped dumps, and print the
count in the header of each dump. It is a running total rather than the
count since the previous dump: dev_coredumpm() discards a new dump
while an earlier one for the device has not been read yet, without
telling the driver, and a count carried in the discarded dump would be
lost. Those discarded dumps are not counted, for the same reason.

Suggested-by: Gregoire Pean <[email protected]>
Signed-off-by: Matt Turner <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 28 ++++++++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h |  1 +
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index c8ca96ce5bdc..f40b5f062fd9 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;
+       /* coredumps dropped since the device was initialized */
+       atomic_t                        coredump_dropped;
        /* the IP state was dumped for the next coredump */
        bool                            coredump_ip_state_valid;
        /* the last VM fault when the IP state was dumped */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c
index 3cb1927b0f47..19e3a47ded79 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c
@@ -672,6 +672,8 @@ amdgpu_devcoredump_format(char *buffer, size_t count, 
struct amdgpu_coredump_inf
        drm_printf(&p, "kernel: %s\n", init_utsname()->release);
        drm_printf(&p, "module: " KBUILD_MODNAME "\n");
        drm_printf(&p, "time: %ptSp\n", &coredump->reset_time);
+       if (coredump->dropped)
+               drm_printf(&p, "dropped coredumps: %u\n", coredump->dropped);
        drm_printf(&p, "pasid: %u\n", coredump->pasid);
        drm_printf(&p, "vmid: %u\n", coredump->vmid);
 
@@ -869,8 +871,13 @@ static void amdgpu_devcoredump_deferred_work(struct 
work_struct *work)
         */
        coredump->formatted_size = amdgpu_devcoredump_format(
                NULL, AMDGPU_CORE_DUMP_SIZE_MAX, coredump);
-       coredump->formatted = kvzalloc(coredump->formatted_size, GFP_KERNEL);
+       coredump->formatted = kvzalloc(coredump->formatted_size,
+                                      GFP_KERNEL | __GFP_NOWARN);
        if (!coredump->formatted) {
+               atomic_inc(&adev->coredump_dropped);
+               drm_warn(adev_to_drm(adev),
+                        "failed to allocate %zd bytes for coredump\n",
+                        coredump->formatted_size);
                amdgpu_devcoredump_free(coredump);
                goto end;
        }
@@ -943,15 +950,28 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool 
skip_vram_check,
        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))
+       if (work_busy(&adev->coredump_work)) {
+               atomic_inc(&adev->coredump_dropped);
+               drm_warn_ratelimited(dev,
+                                    "previous coredump still being processed, 
dropping this one\n");
                return;
+       }
 
        if (job && job->pasid)
                size += sizeof(struct amdgpu_coredump_ib_info) * job->num_ibs;
 
-       coredump = kvzalloc(size, GFP_NOWAIT);
-       if (!coredump)
+       coredump = kvzalloc(size, GFP_NOWAIT | __GFP_NOWARN);
+       if (!coredump) {
+               atomic_inc(&adev->coredump_dropped);
+               drm_warn_ratelimited(dev, "failed to allocate coredump\n");
                return;
+       }
+
+       /*
+        * A running total rather than the count since the previous dump, which
+        * would be lost if dev_coredumpm() discards this dump.
+        */
+       coredump->dropped = atomic_read(&adev->coredump_dropped);
 
        coredump->skip_vram_check = skip_vram_check;
        coredump->reset_vram_lost = vram_lost;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h
index 6a51fbe357dc..97d5fbe8320e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h
@@ -94,6 +94,7 @@ struct amdgpu_coredump_info {
        ssize_t                         formatted_size;
        char                            *formatted;
 
+       unsigned int                    dropped;
        unsigned int                    pasid;
        unsigned int                    vmid;
        pid_t                           submit_tgid;

-- 
2.56.1

Reply via email to