From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796251001; b=VgNnEwpfb/mMCPvexenC85AM0SbwCmWnV6e5TYvMXl9EXktZPF7+E7NIbfO7KEpdIHC8 eiruca/a5E+59G3dpmYXY6s7CCUuJAZwLds2mOuoMH8QBbbYXL+tAKc7arLuuN5Ih1US9 lYSLfkJyp1n1SKQIg5znDST4Oz59Qm6ddDPWg2FaHMJoqkdkk9amy7Q3T5NRwOwVvXdzm Q+23Uo0B9qBbvvREm35QdQOJhY9pxhBvzRrSdOnNIxHRRFL5be+KSNgRZD6l6ifE/Ybxc 0T6o0GnK2iakHaRxHgfFFLO7J4rJ2hcTsN2uNyaHUL4ri9AMrSmKTe5pAtbkrAEjNHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796251001; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=k2l1Rza44qDOJR9Qb3Z+Tzj4icdwDXqKdwSG1CaZ3vU=; b=fQlKghcW3bX8lNYvKB1JYNNvmdCW5PlKWYS9YOeeDg/Cg+y5jtupnYoHiF++DLK/V2Kx NC5ZwJoi5mpWuY4KKR46z+wcbddxuYDF0nJ18xdbqgxBCrczkkAuuXMC3XaLfeiYEZjRs DLRagfSBfWR8vdRaINAs8EA5LjeedHAFhcoJuJu4qk91EiXdnG94wgpeIzszQF3vSZDB8 EQNDAgEw7fKPo2mU2qTvPUkZYaucfHai+A1nruYcVPmk+4cT4SsWTsCMf8b5xWB6noTTD +iTAPY9mq9u3P/++HCC8S/huy0Lk3UaSISGTxRleC6Qq1hEqyXjZk4/VA9FhfgyxeBA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xnX11y5C; arc=none smtp.remote-ip=209.85.128.176 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88ACD606A696 for ; Wed, 2 Dec 2026 22:36:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 88ACD606A696 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=xnX11y5C Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-8b2d14968c9so132930757b3.0 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=vger.kernel.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=xnX11y5CcTGka1LmTxamtDsw75ClO2KC0Jfa1fwmzkhl+8iaAqVUSZHxeLwbsza61q odBtOh4BUniUwiuaPopbNxBh2/xJvGlNV29OCaHWTxpPrGU0szNQagazp370NQUWQYOc P9UG4RTEOt1OZhmE7+6lfgJsl+fZwlEpet1tSMcQEYC40Hf8mCNNuE4tg1FWicuppUD+ BmttIUcjVyICa5apJ/H4DyXCRMOHu4eOXD1f4Y0Oie+79uYrLAIsufNTyGwsv5j4XdlW UaaGG92YFYiZj5apxHL83s9FXKU4fBgV9gVEGnfCowORXSRCbLt6ATukNzegZ8ZAjjkr JGEA== 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=ETd018ADXqxmTMYbPCFe1jpCdbTLqQ7e90q72bS5HN9QN/euQQwQTuyBRuohyvjE8O rEsRsMfdyp861wqZ6PBv1uFaTNFJA+yTLxSrWHzvqd5Ie/Rw+NAh40pFJIH/DQSvsDLD N4VtLP2Yc4glCgOFqInd6yKVUJ2ZCfkQ2uly34sOc7UexNEgIgg2OWwWl7srQyIIi6qB 4/QiR6guZOf2hcxzisHIc6RiiLpup5OJ2qkGxfSjCL/LETVtsriFxCMdyzRfYJEfBAho MTDk4RlvZufWWUwjjvTL52rpUjXlP13Gleir2ViDp3hluctgEhGgeBPp+qP9vXjMu2F4 f3Zg== X-Forwarded-Encrypted: i=1; AL+hErEOP4EgBqFnxxyM96a2m0BgCwMv6cOGuJKl5vkL0nesF7zhRs1PJlh+940bO6zJLIPQyRI017cr3XZ4g2E=@vger.kernel.org X-Gm-Message-State: APuU4Z8MjBdh1ao/qSqxxg/lvimS699FDoL3gYTmIsUl56tPCHe8xRME CQ/0vredtlOKT06CsPja+DfxSvNQ8q0/L5tk4nkvBEhxE9K98oEwS/rz X-Gm-Gg: AZFdTZfr43BAc6HyOQJrdlBXtjkT6WY9Mnz5FM+tJn9hwA2/nV2k9UlsutZfoW5MGaM VaoTZr0xFY9u4SG1wCqwxtQNvLzsk8rpwB/FfhOaLlEgHRzrXznsEftZuF3VBLKbl6ksgY9UXn7 Lo3HT5nknP/krwaO6Bf2UA1PBJh0mNAr65tVs/jf+NXUdYM9nUY6sAZcuZMKTZbbdDCxrwbxZKR tp2wqDjKeBjIdq7rb8bFi6c+VSImlldagX6Y7pa5xZu3OxiPD5hLJrZxhdWjSFP/Fd+MYruAr/I KpRv0mN1jOqMFhWlm1DqcmBmeLbhdlIfgEJlq0mAaB4xpfE40llUZBfeOHD9n8tp6i9P/4U2Z+F RSGVyH87lNy2oAPigFRh0OB47Suq15UHptvrOUKPqC/vO1MmQCbHjHYW/tQj9hT32kEUGURMPtM cHKmqxxlBySfNt7j7aIkLq2kGfdURWjmuuGEKzd+BiNWWG+WBtZDXW9PsS/f7PDYOJBr/kwQKnx 0ZblToqh9zcjHfDvquRfvjOxD6JmHPuFHc32dC05U3GlZdKPlkscsX0Byh3RDtpB97bXoxFaPYT yyMDgcz6hCENaRnTBIHneq2vqqPQ+0JNhe/Z713vJGCdKB1qKBUqIykU+IwUssbqNbTKvtcnF/b K4pkeW46fjwKp1HXlIkEsJCBKNaS1k0sGXHJU0C7tHi4P1z+AyYrctW2pn4G1tl/5kYpqDHGKQX BdMmnPt2AdpLA1wV+UFn4= 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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