From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19876606A32C for ; Wed, 2 Dec 2026 22:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ycedg0sA Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E49501125A8; Wed, 2 Dec 2026 22:36:46 +0000 (UTC) Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8FD1E1125A8 for ; Wed, 2 Dec 2026 22:36:40 +0000 (UTC) Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-8b595601695so64146307b3.3 for ; Wed, 02 Dec 2026 14:36:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796250999; x=1796855799; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=k2l1Rza44qDOJR9Qb3Z+Tzj4icdwDXqKdwSG1CaZ3vU=; b=ycedg0sAMEQOQvkn5mOcfRof+C3s1eB7Uzhocl1kmCLIEpxsAtkv6h7oa5cKBFPKxc mOaiUWT/GjdHA+++2I1ldb8pK4wpFWgOOMcqZOW4PtqD3ZHv808eL/f2GkmbXRnxCtRo a8wAMzAZEXk6dR2lszb6uwEJ8t6XKrCHQu2AekgSH0mTU31F2fMj6BBprkDiB2Yx7GLn 3tK+V/Up3WIOvEFxZ18RBtQM2S83gaD4bxxgaWCyDKSJjY/GobIDn3VYFKcgNfDq1x6l AHIxtQVgVf+SYXNcWn/8EHH41Sf4VupwVZSowLsHMYw/gY1XMq0sxiy7oQrlikxbwF58 8BMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796250999; x=1796855799; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=k2l1Rza44qDOJR9Qb3Z+Tzj4icdwDXqKdwSG1CaZ3vU=; b=qgruynifuXzbr1ifnLzzeFC54hTwT5dlgoc8uZYjFRTgE112L/xpfdKuWLB0w4qrh+ nz3WI4tVzPBPrVO/wPN+S1EPdqrhagsM8Xp9Mo8FeQWfJhNSyQWC9SYGs4yIEaF7H3G4 JFMNWBdTRTzdfCwlon0ApREFytg/dwisXFEbdZnbwjJE3Log46ksG4K36L847xYs58zJ PwJKHvXekQFZEG2JsMi/rSiN010Ozaquw7Jn8Yt9xA1S8R+GnoqmLyuJ1hTLxO3DWJF4 RkfWaxBexriY6eH7dbpO9XG/moLBaWxOFWyeQ/HFXGUfGLGs6M5kTYp1oX9lQ2CG5Q1Z Mdsg== X-Forwarded-Encrypted: i=1; AL+hErGe2oWqg0wwuCAN4AM0Z7/sBkwSo/UQ7CMjYh8S48AV9EyMzH6yx35i1gMXo5K+n7m4DJvbKm8QjmQ=@lists.freedesktop.org X-Gm-Message-State: APuU4Z8oRSkrbelU+kPxan2CQbnUkJZFC8HY5HCsZlDhe8xh+nI0MEoF EPp8CN5sOnLu/EUOGH7Dojdm8aoZk3WNPGi/6+SSjt8AoUu5o6WbSlAC X-Gm-Gg: AZFdTZenqxuA4SR62FIUu3zia5OFXX08a7pqDW9Qg4E3M/lYYlLz++xJPwCxxtDagzt KuWHDPki0S5T9JGt5jXJz2odpJjy0zMGEVAQSR4lycfUuuZqO79ZRb5R8Q2tOIfLNEVw+XoDTGL Ane2UZV9XipVzik3EiiW7OVqkNMY062nPan8gOosxflkBOKoknPDrtK4dUH61SDAM6OgVDiX3ei juPMWLX98mgNADzvg1i4CNYou4L4si+YzwIxT++yXZaayFaSkAoL8q2ibkxr3rikzpOmWBrBqbr Wnnqp6KSYY2Lk2xXI+GDb6olAgFhUXOz9IPKRZK1VmnSmk3rPUakbsbmI0ar3Xf7RDr1Q7PWVrz VHs7p6ENPtZdFjB4PqOGNw6TGiHBUhP9gSuqDgaAtWoSHvGy1twnKgekTtFKiVypdSg3QLD7qdR u+s7vUa5aRJnKC7IHrYsLbsBZQ7qPBz0xWeuGj0AHNI14fwKqv1n+868lx+6dHNTZQyLPQKehbw jHETl7e2mYWCXWHPd2V3adMKwMzYGZHomBtE5BWGhXk7AtP+5OJavjX4KhPP0floEJWSl33hWBL 13mVOVZ8HPeoc16xRwG8cBeU/GaK7nEaWOzsnxecQXCbol8/K/ok23LUtjSLx8QnYbaOK0o5LXb JUEf9FCbLySm5Q+sz+zSAvRzf2o47js0EZTZA4yV1Im6SECOXTXfVuMAi1b6pG3hCN4BJ0jMXnd ELLSDyL3EyL+bpQbMKsaE= X-Received: by 2002:a05:690c:e218:20b0:8b5:5da1:618e with SMTP id 00721157ae682-8b55da162d5mr82244317b3.30.1796250999466; Wed, 02 Dec 2026 14:36:39 -0800 (PST) Received: from localhost (107-220-129-194.lightspeed.chrlnc.sbcglobal.net. [107.220.129.194]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b52028d89csm166567937b3.15.2026.12.02.14.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 14:36:37 -0800 (PST) From: Matt Turner Date: Wed, 02 Dec 2026 17:36:19 -0500 Subject: [PATCH 13/14] drm/amdgpu: add AMDGPU_VM_PAGE_DUMP to include BOs in the coredump X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-amdgpu-devcoredump-v1-13-3dfa0e033b97@gmail.com> References: <20261202-amdgpu-devcoredump-v1-0-3dfa0e033b97@gmail.com> In-Reply-To: <20261202-amdgpu-devcoredump-v1-0-3dfa0e033b97@gmail.com> To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sunil Khatri , Trigger Huang Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Matt Turner , Gregoire Pean X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=18518; i=mattst88@gmail.com; h=from:subject:message-id; bh=ivZtLslKdCUQ/BoWLdiJt09PgrH2X9MEM9Kpozx6Ub4=; b=owGbwMvMwCW25rVmCc8sv+mMp9WSGLIF5kYcrHLifPVp4V7uA2Waj9mf/7jyyuVPepzETs/oy d0/H6ms6PjIwiDGxTBTTJElbr0iy6y2HUt9Tkv/gpnDygQyRFqkgQEIWBj4chPzSo10jPRMtQ31 DIEMHaN4iJweg0ZmcXFpapFuWkGRQ15+SWJJZn5esV5+QWpeQXqBXlpmWklGRn5RcSrQCL281BJ TV0c3I0MDE0tHCzMnC0dTE2dnJ0MnN0dHZ1cnI0tzEwNnS0cTV0tzBi5OAZhrmvgZ/sfXZdjwqk w8ERU52+VLX8rOuOZZp9Zv2XVi5wHh01X725gYGZ4evNVlbDMpVMjWPHKxGuPiR5utE/2bJig5d srWMlztZwEA X-Developer-Key: i=mattst88@gmail.com; a=openpgp; fpr=3BB639E56F861FA2E86505690FDD682D974CA72A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The coredump has the IBs of the hung job, but a hang often depends on memory the IBs only point at: descriptors, shader binaries, indirect draw arguments, or the user's own state. The kernel can't tell which of the VM's mappings matter, but the userspace driver can. Add AMDGPU_VM_PAGE_DUMP, a mapping flag that only asks for the contents of the mapping to be included in the coredump when a job of that VM hangs, like DRM_XE_VM_BIND_FLAG_DUMPABLE does for xe. It is stored with the mapping like the other flags and ignored by the PTE code, which only tests the bits it knows about. At hang time, under the root PD trylock already used for the IBs, copy the start of each flagged mapping: at most 64 mappings, 4 MiB of each and 32 MiB in total, so a careless flag can't make every coredump huge. The dump gives how many of the flagged mappings it has and how much of each, so it is clear when these limits left something out. They are copied after the IBs and the mapping list, which matter more if GFP_NOWAIT allocations start to fail. As with the IBs, a BO that can't be copied without blocking, including one in CPU invisible VRAM, or that doesn't fit in the 8 MiB copied at hang time, is retried from the coredump worker and marked as captured late. The worker only copies a mapping that is still flagged and starts at the same address, so it can't dump a mapping that replaced the flagged one. The worker also selects the BOs if the root PD was contended, or if the VM has more mappings than the list holds, since finding the flagged ones means walking all of them. 32 MiB as one hex dword per line, as the IBs are printed, would be almost 90 MiB of text, so print each BO as a single line of ascii85 instead, as i915, msm and xe do for buffer contents in their coredumps. That takes at most five characters per dword, and one for each zero dword. Formatting can still take a while, so stop early once the printer is full and reschedule now and then. Bump the KMS minor version so userspace can tell whether the flag is accepted. Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/47015 Suggested-by: Gregoire Pean Signed-off-by: Matt Turner --- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 213 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 14 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- include/uapi/drm/amdgpu_drm.h | 6 + 5 files changed, 213 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c index 8395e9d35f7e..c531bc894a63 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c @@ -22,6 +22,7 @@ * */ +#include #include #include #include @@ -59,6 +60,14 @@ void amdgpu_coredump_fini(struct amdgpu_device *adev) /* Only this many VM mappings are listed in the coredump. */ #define AMDGPU_COREDUMP_MAX_MAPPINGS 1024 +/* + * Limits on copying the mappings flagged with AMDGPU_VM_PAGE_DUMP: how many, + * how much of each, and how much in total. + */ +#define AMDGPU_COREDUMP_MAX_BOS 64 +#define AMDGPU_COREDUMP_BO_MAX_BYTES ((u64)SZ_4M) +#define AMDGPU_COREDUMP_BOS_MAX_BYTES ((u64)SZ_32M) + /* Placement of a mapping without a BO or whose BO has no backing store */ #define AMDGPU_COREDUMP_MEM_TYPE_NONE -1 /* Placement of a mapping whose BO could not be locked to read it */ @@ -376,6 +385,12 @@ static int amdgpu_devcoredump_copy_blob(struct amdgpu_vm *vm, if (!abo) return -ENOENT; + /* The worker must not copy a mapping that replaced a flagged one. */ + if (blob->flagged && + (!(mapping->flags & AMDGPU_VM_PAGE_DUMP) || + mapping->start * AMDGPU_GPU_PAGE_SIZE != blob->va)) + return -ENOENT; + if (blob->va + blob->size > (mapping->last + 1) * AMDGPU_GPU_PAGE_SIZE) return -ERANGE; @@ -497,6 +512,82 @@ static int amdgpu_devcoredump_capture_mappings(struct amdgpu_vm *vm, return 0; } +/* + * Choose which parts of the mappings flagged with AMDGPU_VM_PAGE_DUMP to copy: + * the start of each mapping, up to the per-mapping and total limits. The VM + * root PD must be reserved by the caller. + */ +static int amdgpu_devcoredump_select_bos(struct amdgpu_vm *vm, + struct amdgpu_coredump_info *coredump, + bool nowait) +{ + struct amdgpu_bo_va_mapping *mapping = NULL; + u64 budget = AMDGPU_COREDUMP_BOS_MAX_BYTES; + u32 count = 0, n = 0; + + /* + * Finding the flagged mappings means walking all of them, so leave + * that to the worker if there are more than are listed. + */ + if (nowait && coredump->more_mappings) + return -EAGAIN; + + while ((mapping = amdgpu_vm_bo_next_mapping(vm, mapping))) + count += !!(mapping->flags & AMDGPU_VM_PAGE_DUMP); + + coredump->total_bos = count; + if (!count) + return 0; + + count = min(count, AMDGPU_COREDUMP_MAX_BOS); + coredump->bos = kvzalloc_objs(struct amdgpu_coredump_bo_info, count, + (nowait ? GFP_NOWAIT : GFP_KERNEL) | + __GFP_NOWARN); + if (!coredump->bos) + return -ENOMEM; + + while (n < count && budget && + (mapping = amdgpu_vm_bo_next_mapping(vm, mapping))) { + struct amdgpu_coredump_bo_info *bo; + struct amdgpu_coredump_blob *blob; + u64 mapping_size, size; + + if (!(mapping->flags & AMDGPU_VM_PAGE_DUMP)) + continue; + + mapping_size = (mapping->last - mapping->start + 1) * + AMDGPU_GPU_PAGE_SIZE; + size = min3(mapping_size, AMDGPU_COREDUMP_BO_MAX_BYTES, budget); + budget -= size; + + bo = &coredump->bos[n++]; + bo->mapping_size = mapping_size; + blob = &bo->blob; + blob->va = mapping->start * AMDGPU_GPU_PAGE_SIZE; + blob->size = size; + blob->status = -EAGAIN; + blob->flagged = true; + } + coredump->num_bos = n; + + return 0; +} + +static u32 amdgpu_devcoredump_num_blobs(struct amdgpu_coredump_info *coredump) +{ + return coredump->num_ibs + coredump->num_bos; +} + +/* The IBs of the hung job, followed by the flagged mappings. */ +static struct amdgpu_coredump_blob * +amdgpu_devcoredump_get_blob(struct amdgpu_coredump_info *coredump, u32 i) +{ + if (i < coredump->num_ibs) + return &coredump->ibs[i].blob; + + return &coredump->bos[i - coredump->num_ibs].blob; +} + /* Copy @blob at hang time if it fits in what is left of @budget. */ static void amdgpu_devcoredump_copy_blob_nowait(struct amdgpu_vm *vm, struct amdgpu_coredump_blob *blob, @@ -533,9 +624,11 @@ amdgpu_devcoredump_capture_vm_nowait(struct amdgpu_device *adev, blob->status = PTR_ERR(vm); } coredump->mappings_status = PTR_ERR(vm); + coredump->bos_status = PTR_ERR(vm); return; } + /* In order of importance, in case GFP_NOWAIT allocations fail. */ for (int i = 0; i < coredump->num_ibs; i++) amdgpu_devcoredump_copy_blob_nowait(vm, &coredump->ibs[i].blob, &budget); @@ -543,6 +636,11 @@ amdgpu_devcoredump_capture_vm_nowait(struct amdgpu_device *adev, coredump->mappings_status = amdgpu_devcoredump_capture_mappings(vm, coredump, true); + coredump->bos_status = amdgpu_devcoredump_select_bos(vm, coredump, true); + for (u32 i = 0; i < coredump->num_bos; i++) + amdgpu_devcoredump_copy_blob_nowait(vm, &coredump->bos[i].blob, + &budget); + dma_resv_unlock(vm->root.bo->tbo.base.resv); } @@ -608,8 +706,9 @@ amdgpu_devcoredump_print_mappings(struct drm_printer *p, } /* - * List the VM mappings if that failed at hang time. The VM root PD must be - * reserved by the caller. + * List the VM mappings and select the flagged BOs if that failed at hang time. + * The VM root PD must be reserved by the caller. The selected BOs are then + * copied like any other blob that has to be retried. */ static void amdgpu_devcoredump_list_vm_late(struct amdgpu_vm *vm, struct amdgpu_coredump_info *coredump) @@ -619,6 +718,10 @@ static void amdgpu_devcoredump_list_vm_late(struct amdgpu_vm *vm, amdgpu_devcoredump_capture_mappings(vm, coredump, false); coredump->mappings_late = !coredump->mappings_status; } + + if (amdgpu_devcoredump_status_retry(coredump->bos_status)) + coredump->bos_status = + amdgpu_devcoredump_select_bos(vm, coredump, false); } /* @@ -630,6 +733,7 @@ static void amdgpu_devcoredump_list_vm_late(struct amdgpu_vm *vm, static void amdgpu_devcoredump_capture_vm_late(struct amdgpu_coredump_info *coredump) { + u32 num_blobs = amdgpu_devcoredump_num_blobs(coredump); struct amdgpu_bo_va_mapping *mapping; struct amdgpu_coredump_blob *blob; struct amdgpu_bo *abo; @@ -638,20 +742,23 @@ amdgpu_devcoredump_capture_vm_late(struct amdgpu_coredump_info *coredump) bool retry; int r = 0; - retry = amdgpu_devcoredump_status_retry(coredump->mappings_status); - for (int i = 0; i < coredump->num_ibs; i++) - retry |= amdgpu_devcoredump_blob_retry(&coredump->ibs[i].blob); + retry = amdgpu_devcoredump_status_retry(coredump->mappings_status) || + amdgpu_devcoredump_status_retry(coredump->bos_status); + for (u32 i = 0; i < num_blobs; i++) { + blob = amdgpu_devcoredump_get_blob(coredump, i); + retry |= amdgpu_devcoredump_blob_retry(blob); + } if (!retry) return; /* - * Lock the VM root PD and every IB BO together in a single drm_exec - * ticket. Reserving the IB BOs one by one while the root PD is held + * Lock the VM root PD and every BO together in a single drm_exec + * ticket. Reserving the BOs one by one while the root PD is held * would be a recursive reservation_ww_class_mutex acquire without a - * ww_acquire_ctx, which trips lockdep and self-deadlocks for IB BOs + * ww_acquire_ctx, which trips lockdep and self-deadlocks for BOs * that share their dma_resv with the root PD (always-valid BOs). */ - drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 1 + coredump->num_ibs); + drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 1 + num_blobs); drm_exec_until_all_locked(&exec) { /* Don't keep an -EDEADLK from a previous pass. */ r = 0; @@ -663,9 +770,10 @@ amdgpu_devcoredump_capture_vm_late(struct amdgpu_coredump_info *coredump) } amdgpu_devcoredump_list_vm_late(vm, coredump); + num_blobs = amdgpu_devcoredump_num_blobs(coredump); - for (int i = 0; i < coredump->num_ibs; i++) { - blob = &coredump->ibs[i].blob; + for (u32 i = 0; i < num_blobs; i++) { + blob = amdgpu_devcoredump_get_blob(coredump, i); if (!amdgpu_devcoredump_blob_retry(blob)) continue; @@ -681,8 +789,8 @@ amdgpu_devcoredump_capture_vm_late(struct amdgpu_coredump_info *coredump) } } - for (int i = 0; i < coredump->num_ibs; i++) { - blob = &coredump->ibs[i].blob; + for (u32 i = 0; i < num_blobs; i++) { + blob = amdgpu_devcoredump_get_blob(coredump, i); if (!amdgpu_devcoredump_blob_retry(blob)) continue; @@ -696,18 +804,26 @@ amdgpu_devcoredump_capture_vm_late(struct amdgpu_coredump_info *coredump) if (r) { if (amdgpu_devcoredump_status_retry(coredump->mappings_status)) coredump->mappings_status = r; - for (int i = 0; i < coredump->num_ibs; i++) { - blob = &coredump->ibs[i].blob; + if (amdgpu_devcoredump_status_retry(coredump->bos_status)) + coredump->bos_status = r; + for (u32 i = 0; i < num_blobs; i++) { + blob = amdgpu_devcoredump_get_blob(coredump, i); if (amdgpu_devcoredump_blob_retry(blob)) blob->status = r; } } } -/* Print the contents of a blob, or why they are missing. */ +/* + * Print the contents of a blob, or why they are missing: as one hex dword + * per line, or if @ascii85 is set as a single line of ascii85, which takes + * at most five characters per dword instead of eleven. + */ static void amdgpu_devcoredump_print_blob(struct drm_printer *p, - struct amdgpu_coredump_blob *blob) + struct amdgpu_coredump_blob *blob, + bool ascii85) { + char buf[ASCII85_BUFSZ]; const u32 *dw = blob->data; if (!blob->data) { @@ -719,8 +835,23 @@ static void amdgpu_devcoredump_print_blob(struct drm_printer *p, if (blob->late) drm_printf(p, "contents captured after recovery started\n"); - for (u64 i = 0; i < blob->size / 4; i++) - drm_printf(p, "0x%08x\n", dw[i]); + if (!ascii85) { + for (u64 i = 0; i < blob->size / 4; i++) + drm_printf(p, "0x%08x\n", dw[i]); + return; + } + + drm_puts(p, "data: "); + for (u64 i = 0; i < blob->size / 4; i++) { + drm_puts(p, ascii85_encode(dw[i], buf)); + + if (!(i % SZ_64K)) { + if (drm_coredump_printer_is_full(p)) + return; + cond_resched(); + } + } + drm_puts(p, "\n"); } static void @@ -732,7 +863,36 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, drm_printf(p, "\nIB #%d 0x%llx %d dw\n", i, ib->gpu_addr, ib->ib_size_dw); - amdgpu_devcoredump_print_blob(p, &ib->blob); + amdgpu_devcoredump_print_blob(p, &ib->blob, false); + } +} + +static void +amdgpu_devcoredump_print_bos(struct drm_printer *p, + struct amdgpu_coredump_info *coredump) +{ + struct amdgpu_device *adev = coredump->adev; + + if (coredump->bos_status) { + drm_printf(p, "\nDumped BOs unavailable: %pe\n", + ERR_PTR(coredump->bos_status)); + return; + } + + if (!coredump->total_bos) + return; + + /* Both counts and sizes: the caps can leave out BOs or their ends. */ + drm_printf(p, "\nDumped BOs: %u of %u\n", coredump->num_bos, + coredump->total_bos); + + for (u32 i = 0; i < coredump->num_bos; i++) { + struct amdgpu_coredump_bo_info *bo = &coredump->bos[i]; + + drm_printf(p, "\nBO #%u 0x%016llx 0x%llx of 0x%llx bytes\n", i, + amdgpu_gmc_sign_extend(bo->blob.va), bo->blob.size, + bo->mapping_size); + amdgpu_devcoredump_print_blob(p, &bo->blob, true); } } @@ -973,6 +1133,9 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_inf if (coredump->num_ibs) amdgpu_devcoredump_print_ibs(&p, coredump); + if (coredump->pasid) + amdgpu_devcoredump_print_bos(&p, coredump); + return count - iter.remain; } @@ -1002,9 +1165,12 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count, /* Free the copied memory, which is only needed to format the dump. */ static void amdgpu_devcoredump_free_blobs(struct amdgpu_coredump_info *coredump) { - for (int i = 0; i < coredump->num_ibs; i++) { - kvfree(coredump->ibs[i].blob.data); - coredump->ibs[i].blob.data = NULL; + for (u32 i = 0; i < amdgpu_devcoredump_num_blobs(coredump); i++) { + struct amdgpu_coredump_blob *blob = + amdgpu_devcoredump_get_blob(coredump, i); + + kvfree(blob->data); + blob->data = NULL; } } @@ -1016,6 +1182,7 @@ static void amdgpu_devcoredump_free(void *data) kvfree(coredump->formatted); kvfree(coredump->mappings); amdgpu_devcoredump_free_blobs(coredump); + kvfree(coredump->bos); for (i = 0; i < coredump->num_rings; i++) { kvfree(coredump->rings[i].ring_dw); kvfree(coredump->rings[i].fences); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h index 844fc87f386e..00982cf80809 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h @@ -63,6 +63,8 @@ struct amdgpu_coredump_blob { int status; /* copied by the worker rather than when the hang was detected */ bool late; + /* the start of a mapping flagged with AMDGPU_VM_PAGE_DUMP */ + bool flagged; }; struct amdgpu_coredump_ib_info { @@ -71,6 +73,12 @@ struct amdgpu_coredump_ib_info { struct amdgpu_coredump_blob blob; }; +struct amdgpu_coredump_bo_info { + /* size of the whole mapping, of which blob has the start */ + u64 mapping_size; + struct amdgpu_coredump_blob blob; +}; + struct amdgpu_coredump_mapping { u64 va; u64 size; @@ -116,6 +124,12 @@ struct amdgpu_coredump_info { /* listed by the worker rather than when the hang was detected */ bool mappings_late; + /* contents of the mappings with AMDGPU_VM_PAGE_DUMP set */ + struct amdgpu_coredump_bo_info *bos; + u32 num_bos; + u32 total_bos; + int bos_status; + pid_t submit_tgid; pid_t submit_pid; char submit_process_name[TASK_COMM_LEN]; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index d2db20c172c6..8c2f958116aa 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -129,9 +129,10 @@ * - 3.64.0 - Userq IP support query * - 3.65.0 - Add userq syncobj timeline signaling support * - 3.66.0 - Allow jpeg type 4 packets and VCE SEI command + * - 3.67.0 - Add AMDGPU_VM_PAGE_DUMP */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 66 +#define KMS_DRIVER_MINOR 67 #define KMS_DRIVER_PATCHLEVEL 0 /* diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 65b88e6008e4..6e7591d6ef2a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -889,7 +889,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, const uint32_t valid_flags = AMDGPU_VM_DELAY_UPDATE | AMDGPU_VM_PAGE_READABLE | AMDGPU_VM_PAGE_WRITEABLE | AMDGPU_VM_PAGE_EXECUTABLE | AMDGPU_VM_MTYPE_MASK | - AMDGPU_VM_PAGE_NOALLOC; + AMDGPU_VM_PAGE_NOALLOC | AMDGPU_VM_PAGE_DUMP; const uint32_t prt_flags = AMDGPU_VM_DELAY_UPDATE | AMDGPU_VM_PAGE_PRT; diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index 894fca0a79cc..cec897772728 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -915,6 +915,12 @@ struct drm_amdgpu_gem_list_handles_entry { #define AMDGPU_VM_MTYPE_RW (5 << 5) /* don't allocate MALL */ #define AMDGPU_VM_PAGE_NOALLOC (1 << 9) +/* + * Include the contents of the mapping in the device coredump taken when a job + * using this VM hangs, subject to size limits. Has no effect on the GPU + * mapping itself. + */ +#define AMDGPU_VM_PAGE_DUMP (1 << 10) struct drm_amdgpu_gem_va { /** GEM object handle */ -- 2.56.1