From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796250987; b=14L8KNiryczlXrgWBKk3ZO810c1xIa7fg/MdcWitIETMxnYjiOtb9lR3MHIY+m4YxFGT NwETYcBNz4yaSOiLnsXBNFClkSa+1VtjrgQRTo7gWR4ydYPTK4sz0iiUpiK03ikGJ3UIt QNo6I5Tvzsk1Fb+kGO07nJGbWneKlahxfzROiRMwEzzipBzgNZ8kfHfGoJ0asbdNpNjHq Uz61Z/z2ODYbW4Po/5FAocjglZrYTJL5ZG0QCYniw19UXa5Cf3rwtGCcYpzuJ60QmMDoD R1GvRl5kgUaJJixnU8hKUUoFLF0uu9DGRWGjW4BepvZOA2BZURA+v04TcUye8w+PqZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796250987; 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=QSQ2VKfs13gzlZgBHBkytBABZrnXmv87WW7GbjONTFg=; b=Uzl80Ak7DXc7/zmDrAEcVrCd9nVKYLioEgNJSyuimAUTPipsg2SMc22a33bAnV/Oc2TJ RCPK6gSeR2Y6j3cEjVnfLwb91jNjMPKnJ1KDSX0gbFvmA3EL8xmtjz060CzF8MZPA6OGL 3Tz0dSLk7wTiFuH3If8E2hi9JXZ48cRzdky3TmncFvdan9BYged8FpuPdGTxrQruAZ2tQ 8wbjSs3fImnN8jixDY39UnufvBrFdmN0hkvnU2m81QKQXnyarQw5sVL3W9pJuhzPrw1Cb sauEDO/FSE5s6NK/WO4wjXOlyYCwkmL2HVLBhhAhiVmZYWsNGAO7/x83H0fiMlzK+Bg== 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=mQj5F2Ac; arc=none smtp.remote-ip=74.125.224.43 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (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 41910606A334 for ; Wed, 2 Dec 2026 22:36:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 41910606A334 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=mQj5F2Ac Received: by mail-yx1-f43.google.com with SMTP id 956f58d0204a3-67be9601f31so11889916d50.3 for ; Wed, 02 Dec 2026 14:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796250986; x=1796855786; 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=QSQ2VKfs13gzlZgBHBkytBABZrnXmv87WW7GbjONTFg=; b=mQj5F2AcvWX7uHIahhq+pBx982m0+S/wwXiSrCz4kIMHY//aL/XWduQCwc9V+7U6es qwhkmHkn/Auc0nUbX66jR3Viat+jvu3WLeQnU4n/vN+vF0k83zjbd3sINzzy71v2fEKf qiMZp7XklZAapp46O/mc8BAGONvR9Roqkmka3oTqfmx2FuVAIL2So0QSvmj+TgQcHi02 b0iFHww5XyMQTUyOQDqhryRb5H0kAQJWOMPqK6eSS2yRkC+84SnHzZbSOcKlDL2Gr8La 8vyGjI4yDqB7DWy+6ReOzboDa8zSjPM8S0CHZBohS32mB8THznoxXXjf+fCdL6TzgQPu dTZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796250986; x=1796855786; 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=QSQ2VKfs13gzlZgBHBkytBABZrnXmv87WW7GbjONTFg=; b=aHnmUw/6VvI1zSWGM175lVAf8bGX2RH34ktbbMi0ns8qewp2j7laWHfFQ57awPJjdH UTaWjdiGrMC7zKS2mHJNSoNwbJoB1wDOnKzkgLTeVwSR8OhcTmj2THroRLirUmNO7Olt alM52+N1Ghqa9vBeId+O5gaweGFyxnM0BUKIeRjHph3ON6OSv/8y3m3w6ftMwJaoD4Mq cMjSH74IBnmvKGb3DDTsk4l8uHPsKZmfgmhekbSri9089xqQkq/7RiILTqituzUjsFoE 2mHcTpP192Vaq+0aRACIHoJQU1SEVpokMf9DFeOSWlGKuXLoQ/V204958GBN5svrADcm C0CA== X-Forwarded-Encrypted: i=1; AL+hErF0lqQwvVHVPFmoLPV/5biALW415q6ll+n9NP+0hQ4tkEcAG0skFwv+ZtDczEtVbw3V8IZ+ucBgtn0vyds=@vger.kernel.org X-Gm-Message-State: APuU4Z+YrgW0Xa69LLZuKujCmQbzNi67cPcP5o8iNAV1CFXN/fQCVuk6 xQK5vB18FCejkeonCUDaEg4334fpvn2jSQpKWRh8q+4x2RFtOCUkzmax X-Gm-Gg: AZFdTZf6j2i9xQb+QD8q6sztF+xho0DcjF5pS7uzYiYcucH7P76+pKMHmsvEkktVY9b xAvSw/Y4nEeQlWw7IClt3EQw96p8mh1xzcH7hZ40ZpNw1gmsA+vntEWNfk1DxLnDOZPcJIo/MLe xbSkn/OCo4baXDh3lBPnjb9WBUHj5U2ZsZmjWUmd+d4435xLvK43NQMok7DaMxEzdh023UAYm3C YipqvsG/5CHqPTMjke1jvUYllQpGy09ds/QYpBKvK1wfokIdC5+/t3SN+WlvG4bXbVtvPOFBfem hW6CGZ4G25utTB8B7kr0D1SxDdwkBIJ0+2QDCF2DNJByGsIMccuuMM2HrnyyhYtF7DOr2MVyQk9 c945po/6oB1T6FLfCpVvaVtiV2eFF5ljmv++Tftc+2X6Q3ZCeYspMqmtR5zXTBQuFmAumvcI9N2 ZujmoCfz4nWo20/7HW9xioYP5WCnMOfn35t8xEWEaRKh0s/Jm1m6UqGZ/HmR5ILXd8y2XfMDadP pgdpxD2orby5gshyvaAS4dc/9KZNfwtZRbRjkoTabVrwePLv6lG/YAcvOzNWEhqq3e+Doglj2Ea PMp4exL+lTG3JWWn4DEPc5jrUyHrMHji6ydFOzwFDtA8Lj9mXpHtCFAQ+4X+gn5O9keHRBZKj2f VvYQ1cahPMPWCird9/QoxzzkJs8nMQ/kdgZO8/HZmx/xHbLRBGwALZaGbOcG01A9a8gYpE0RFAR uhzW1U7cusX3UVQMm+k2A= X-Received: by 2002:a05:690e:128c:b0:67d:c122:e5e6 with SMTP id 956f58d0204a3-67df440b767mr17896186d50.31.1796250986197; Wed, 02 Dec 2026 14:36:26 -0800 (PST) Received: from localhost (107-220-129-194.lightspeed.chrlnc.sbcglobal.net. [107.220.129.194]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67eb40514besm2092150d50.22.2026.12.02.14.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 14:36:24 -0800 (PST) From: Matt Turner Date: Wed, 02 Dec 2026 17:36:13 -0500 Subject: [PATCH 07/14] drm/amdgpu: copy the IB contents before formatting the devcoredump 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-7-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=15235; i=mattst88@gmail.com; h=from:subject:message-id; bh=IlelfdI2VfkDyVKsK/WSjJu6d6BH+3rt44X9IDUvghg=; b=owGbwMvMwCW25rVmCc8sv+mMp9WSGLIF5kbwTDc1/nl1Q9HkEyd/ptXdmhGSsu16SsXn/bbrJ MqXv591ouMjC4MYF8NMMUWWuPWKLLPadiz1OS39C2YOKxPIEGmRBgYgYGHgy03MKzXSMdIz1TbU MwQydIziIXJ6DBqZxcWlqUW6aQVFDnn5JYklmfl5xXr5Bal5BekFemmZaSUZGflFxalAI/TyUkt MXR3djAwNTCwdLcycLBxNTZydnQyd3BwdnV2djCzNTQycLR1NXC3NGbg4BWCuEXBj+Gck6ZZwdt 9XlTtTjgeLt9kcv6XotIL1Y/tR903z1c9/tmthZHhsU+NXH17KUbPl47nInurqhmN+v35dTtII6 Qqvk2fawQwA X-Developer-Key: i=mattst88@gmail.com; a=openpgp; fpr=3BB639E56F861FA2E86505690FDD682D974CA72A The IB contents are read from inside the formatting function, which runs twice: once to size the output and once to fill it. The sizing pass does not lock the VM, so it prints a placeholder for every dword, and only the second pass reads the BOs and finds out whether an IB is readable. Nothing records why one could not be read. Copy the IB contents once from the coredump worker before formatting, into a buffer per IB along with an error code explaining why the contents are missing. Both formatting passes then print the same data, and the dump says why an IB is absent. This replaces the ttm_bo_kmap() based read from "drm/amdgpu: fix IB content read in the devcoredump". The copy only needs a GPU address and a size within one mapping, so describe it with a struct amdgpu_coredump_blob, which later changes use to copy other ranges of the VM. Factor the BO read into a helper that does not allocate and does not map the whole BO. VRAM is read through amdgpu_device_vram_access() 4 KiB at a time, so that the MM_INDEX/MM_DATA fallback for CPU invisible VRAM never keeps interrupts disabled for long. System memory is read one page at a time with kmap_local_page() when the kernel's linear mapping of the pages can be used: TTM only gives it the caching of the BO on x86, and maps decrypted BOs with pgprot_decrypted(), so other BOs are read through ttm_bo_kmap() of just the range being copied. BOs whose pages are not resident are refused. The copies are freed once the dump is formatted, since reading the dump only uses the formatted text. Suggested-by: Gregoire Pean Signed-off-by: Matt Turner --- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 319 +++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 11 + 2 files changed, 224 insertions(+), 106 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c index 4d1b89527545..c3f01acc0e8c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "amdgpu_dev_coredump.h" #include "atom.h" @@ -222,38 +223,157 @@ amdgpu_devcoredump_mapping_bo(struct amdgpu_bo_va_mapping *mapping) return mapping->bo_va->base.bo; } -static void -amdgpu_devcoredump_print_ibs(struct drm_printer *p, - struct amdgpu_coredump_info *coredump, - bool sizing_pass) +/* + * Whether the pages of @ttm can be read through the kernel's linear mapping. + * TTM only gives that mapping the caching of the BO on x86, and maps the pages + * of a decrypted BO with pgprot_decrypted(), so read anything else through + * ttm_bo_kmap() as TTM does. + */ +static bool amdgpu_devcoredump_tt_linear_ok(struct ttm_tt *ttm) +{ + if (ttm->page_flags & TTM_TT_FLAG_DECRYPTED) + return false; + + return ttm->caching == ttm_cached || IS_ENABLED(CONFIG_X86); +} + +/* + * Copy @size bytes at @offset in @abo to @dst. The caller holds the BO's + * reservation. VRAM is read 4 KiB at a time, which bounds how long the + * MM_INDEX/MM_DATA fallback for CPU invisible VRAM keeps interrupts disabled + * whatever the page size. + */ +static int amdgpu_devcoredump_read_bo(struct amdgpu_bo *abo, u64 offset, + void *dst, u64 size) +{ + struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev); + struct ttm_resource *res = abo->tbo.resource; + struct ttm_tt *ttm = abo->tbo.ttm; + struct ttm_bo_kmap_obj map; + bool is_iomem; + int r; + + if (!res) + return -ENODATA; + + if (!IS_ALIGNED(offset, 4) || !IS_ALIGNED(size, 4)) + return -EINVAL; + + switch (res->mem_type) { + case TTM_PL_VRAM: { + struct amdgpu_res_cursor cursor; + + amdgpu_res_first(res, offset, size, &cursor); + while (cursor.remaining) { + u64 len = min_t(u64, cursor.size, SZ_4K); + + amdgpu_device_vram_access(adev, cursor.start, dst, len, + false); + dst += len; + amdgpu_res_next(&cursor, len); + cond_resched(); + } + return 0; + } + case TTM_PL_SYSTEM: + case TTM_PL_TT: + case AMDGPU_PL_PREEMPT: + if (!ttm || !ttm->pages) + return -EOPNOTSUPP; + + if (!ttm_tt_is_populated(ttm) || + ttm->page_flags & (TTM_TT_FLAG_SWAPPED | TTM_TT_FLAG_BACKED_UP)) + return -ENODATA; + + if (!amdgpu_devcoredump_tt_linear_ok(ttm)) { + pgoff_t first = offset >> PAGE_SHIFT; + + r = ttm_bo_kmap(&abo->tbo, first, + PFN_UP(offset + size) - first, &map); + if (r) + return r; + memcpy(dst, ttm_kmap_obj_virtual(&map, &is_iomem) + + offset_in_page(offset), size); + ttm_bo_kunmap(&map); + return 0; + } + + while (size) { + pgoff_t idx = offset >> PAGE_SHIFT; + size_t pg_off = offset_in_page(offset); + size_t len = min_t(u64, size, PAGE_SIZE - pg_off); + void *src; + + if (idx >= ttm->num_pages || !ttm->pages[idx]) + return -ENODATA; + + src = kmap_local_page(ttm->pages[idx]); + memcpy(dst, src + pg_off, len); + kunmap_local(src); + + dst += len; + offset += len; + size -= len; + cond_resched(); + } + return 0; + default: + return -EOPNOTSUPP; + } +} + +/* + * Copy a range of GPU memory, which must lie within a single mapping, into a + * newly allocated buffer. The VM root PD and the BO behind the mapping must be + * reserved by the caller. + */ +static int amdgpu_devcoredump_copy_blob(struct amdgpu_vm *vm, + struct amdgpu_coredump_blob *blob) +{ + struct amdgpu_bo_va_mapping *mapping; + struct amdgpu_bo *abo; + u64 offset; + void *data; + int r; + + mapping = amdgpu_vm_bo_lookup_mapping(vm, blob->va); + abo = amdgpu_devcoredump_mapping_bo(mapping); + if (!abo) + return -ENOENT; + + if (blob->va + blob->size > (mapping->last + 1) * AMDGPU_GPU_PAGE_SIZE) + return -ERANGE; + + offset = blob->va - mapping->start * AMDGPU_GPU_PAGE_SIZE + + mapping->offset; + + /* amdgpu_device_vram_access() can fail without telling us. */ + data = kvzalloc(blob->size, GFP_KERNEL | __GFP_NOWARN); + if (!data) + return -ENOMEM; + + r = amdgpu_devcoredump_read_bo(abo, offset, data, blob->size); + if (r) { + kvfree(data); + return r; + } + + blob->data = data; + return 0; +} + +/* + * Copy the contents of the IBs of the hung job, blocking on the reservation + * locks as needed. This runs from the coredump worker, before formatting, so + * that both formatting passes see the same data. + */ +static void amdgpu_devcoredump_capture_vm(struct amdgpu_coredump_info *coredump) { - struct amdgpu_device *adev = coredump->adev; struct amdgpu_bo_va_mapping *mapping; struct amdgpu_bo *abo; struct drm_exec exec; struct amdgpu_vm *vm; - u32 *ib_content; - u64 va_start, offset; - u8 *kptr; - u32 off; - int r; - - /* - * On the sizing pass there is no VM to look up and no BO to lock; the - * size estimate doesn't depend on whether the IB BOs are reachable. - * Just emit the per-IB headers (the content is not written anywhere). - */ - if (sizing_pass) { - for (int i = 0; i < coredump->num_ibs; i++) { - drm_printf(p, "\nIB #%d 0x%llx %d dw\n", i, - coredump->ibs[i].gpu_addr, - coredump->ibs[i].ib_size_dw); - - for (int j = 0; j < coredump->ibs[i].ib_size_dw; j++) - drm_printf(p, "0xffffffff\n"); - } - return; - } + int r = 0; /* * Lock the VM root PD and every IB BO together in a single drm_exec @@ -264,14 +384,18 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, */ drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 1 + coredump->num_ibs); drm_exec_until_all_locked(&exec) { - vm = amdgpu_vm_lock_by_pasid(adev, coredump->pasid, &exec); - if (!vm) + /* Don't keep an -EDEADLK from a previous pass. */ + r = 0; + vm = amdgpu_vm_lock_by_pasid(coredump->adev, coredump->pasid, + &exec); + if (!vm) { + r = -ESRCH; goto unlock; + } for (int i = 0; i < coredump->num_ibs; i++) { - u64 addr = coredump->ibs[i].gpu_addr & AMDGPU_GMC_HOLE_MASK; - - mapping = amdgpu_vm_bo_lookup_mapping(vm, addr); + mapping = amdgpu_vm_bo_lookup_mapping(vm, + coredump->ibs[i].blob.va); abo = amdgpu_devcoredump_mapping_bo(mapping); if (!abo) continue; @@ -284,80 +408,47 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, } for (int i = 0; i < coredump->num_ibs; i++) { - u64 size = (u64)coredump->ibs[i].ib_size_dw * 4; - bool emit_content = false; + struct amdgpu_coredump_blob *blob = &coredump->ibs[i].blob; - ib_content = kvmalloc_array(coredump->ibs[i].ib_size_dw, 4, - GFP_KERNEL); - if (!ib_content) - continue; - - va_start = coredump->ibs[i].gpu_addr & AMDGPU_GMC_HOLE_MASK; - mapping = amdgpu_vm_bo_lookup_mapping(vm, va_start); - abo = amdgpu_devcoredump_mapping_bo(mapping); - if (!abo || !abo->tbo.resource) - goto output_ib_content; - - if (va_start + size > - (mapping->last + 1) * AMDGPU_GPU_PAGE_SIZE) - goto output_ib_content; - - offset = va_start - mapping->start * AMDGPU_GPU_PAGE_SIZE + - mapping->offset; - - if (abo->tbo.resource->mem_type == TTM_PL_VRAM) { - struct amdgpu_res_cursor cursor; - - off = 0; - amdgpu_res_first(abo->tbo.resource, offset, size, - &cursor); - while (cursor.remaining) { - amdgpu_device_vram_access(adev, cursor.start, - &ib_content[off], - cursor.size, false); - off += cursor.size / 4; - amdgpu_res_next(&cursor, cursor.size); - } - emit_content = true; - } else { - struct ttm_bo_kmap_obj map; - unsigned long first = offset >> PAGE_SHIFT; - bool is_iomem; - - /* - * Map only the pages backing the IB, into a local map - * object so a kernel mapping held in abo->kmap is left - * untouched. - */ - r = ttm_bo_kmap(&abo->tbo, first, - PFN_UP(offset + size) - first, &map); - if (r) - goto output_ib_content; - - kptr = ttm_kmap_obj_virtual(&map, &is_iomem); - kptr += offset_in_page(offset); - if (is_iomem) - memcpy_fromio(ib_content, - (void __iomem *)kptr, size); - else - memcpy(ib_content, kptr, size); - - ttm_bo_kunmap(&map); - emit_content = true; - } - -output_ib_content: - drm_printf(p, "\nIB #%d 0x%llx %d dw\n", i, - coredump->ibs[i].gpu_addr, coredump->ibs[i].ib_size_dw); - if (emit_content) { - for (int j = 0; j < coredump->ibs[i].ib_size_dw; j++) - drm_printf(p, "0x%08x\n", ib_content[j]); - } - kvfree(ib_content); + blob->status = amdgpu_devcoredump_copy_blob(vm, blob); } unlock: drm_exec_fini(&exec); + + if (r) { + for (int i = 0; i < coredump->num_ibs; i++) + coredump->ibs[i].blob.status = r; + } +} + +/* Print the contents of a blob, or why they are missing. */ +static void amdgpu_devcoredump_print_blob(struct drm_printer *p, + struct amdgpu_coredump_blob *blob) +{ + const u32 *dw = blob->data; + + if (!blob->data) { + drm_printf(p, "contents unavailable: %pe\n", + ERR_PTR(blob->status)); + return; + } + + for (u64 i = 0; i < blob->size / 4; i++) + drm_printf(p, "0x%08x\n", dw[i]); +} + +static void +amdgpu_devcoredump_print_ibs(struct drm_printer *p, + struct amdgpu_coredump_info *coredump) +{ + for (int i = 0; i < coredump->num_ibs; i++) { + struct amdgpu_coredump_ib_info *ib = &coredump->ibs[i]; + + 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); + } } static ssize_t @@ -370,9 +461,7 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_inf struct amdgpu_ring *ring; int ver, i, j; u32 ring_idx; - bool sizing_pass; - sizing_pass = buffer == NULL; iter.data = buffer; iter.start = 0; iter.offset = 0; @@ -503,7 +592,7 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_inf drm_printf(&p, "VRAM is lost due to GPU reset!\n"); if (coredump->num_ibs) - amdgpu_devcoredump_print_ibs(&p, coredump, sizing_pass); + amdgpu_devcoredump_print_ibs(&p, coredump); return count - iter.remain; } @@ -531,12 +620,22 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count, return byte_copied; } +/* 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; + } +} + static void amdgpu_devcoredump_free(void *data) { struct amdgpu_coredump_info *coredump = data; u32 i; kvfree(coredump->formatted); + amdgpu_devcoredump_free_blobs(coredump); for (i = 0; i < coredump->num_rings; i++) kvfree(coredump->rings[i].ring_dw); kvfree(coredump->rings); @@ -551,6 +650,9 @@ static void amdgpu_devcoredump_deferred_work(struct work_struct *work) if (!coredump) goto end; + if (coredump->num_ibs) + amdgpu_devcoredump_capture_vm(coredump); + /* Do a one-time preparation of the coredump output because * repeatingly calling drm_coredump_printer is very slow. */ @@ -563,6 +665,7 @@ static void amdgpu_devcoredump_deferred_work(struct work_struct *work) } amdgpu_devcoredump_format(coredump->formatted, coredump->formatted_size, coredump); + amdgpu_devcoredump_free_blobs(coredump); /* If there's an existing coredump for this device, the free function will be * called immediately so coredump might be invalid after the call to dev_coredumpm. @@ -656,8 +759,12 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->vmid = job->vmid; coredump->num_ibs = job->num_ibs; for (i = 0; i < job->num_ibs; ++i) { - coredump->ibs[i].gpu_addr = job->ibs[i].gpu_addr; - coredump->ibs[i].ib_size_dw = job->ibs[i].length_dw; + struct amdgpu_coredump_ib_info *ib = &coredump->ibs[i]; + + ib->gpu_addr = job->ibs[i].gpu_addr; + ib->ib_size_dw = job->ibs[i].length_dw; + ib->blob.va = ib->gpu_addr & AMDGPU_GMC_HOLE_MASK; + ib->blob.size = (u64)ib->ib_size_dw * 4; } } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h index 6836f312b3f8..ffcb08428631 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h @@ -38,9 +38,20 @@ struct amdgpu_coredump_ring { u32 ring_index; }; +/* A range of GPU memory copied into the coredump */ +struct amdgpu_coredump_blob { + /* GPU VA with the hole bits masked off, and size in bytes */ + u64 va; + u64 size; + /* contents, or NULL with the reason in status */ + void *data; + int status; +}; + struct amdgpu_coredump_ib_info { uint64_t gpu_addr; u32 ib_size_dw; + struct amdgpu_coredump_blob blob; }; struct amdgpu_coredump_info { -- 2.56.1