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 38359606A32C for ; Wed, 2 Dec 2026 22:34:27 +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=HJSDVwA/ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F2FC010EAE6; Wed, 2 Dec 2026 22:34:20 +0000 (UTC) Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id ACC1F10EA62 for ; Wed, 2 Dec 2026 22:34:14 +0000 (UTC) Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-8b0d126f631so120823017b3.2 for ; Wed, 02 Dec 2026 14:34:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796250853; x=1796855653; 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=fUZzeScLT6hrUJswX5oZCODgZASBz451GYS191xjyQM=; b=HJSDVwA/0DDHrPgaJCidGFqnHksOE4d9ICEo+noQ9IbOibn4BJ0VQfcxYAybv/mOp3 661A5E2TeC1sCaUe5YFZCSJncUFTAVEGR9Mh9jliQnMod5dsuazDyCQ4R9AMyNpdmObN d3lHqKSfeKHOW9ay/G1Kk2/8BL3ZM4MYgR2bw0D4rmw2LVhUZOGRaq6MJDsSf6l5MmZx uqAy2fcXQtYBFw4UKDtngJvtTRTCWSKiRrqE2pfTv6EXb5ZnHDvtTRQAXo3x46qSoD9+ UHaS2KfDzIb8hDtlnPJQB2XesE3zzLvSNS5c0nkJ+XXLY8KLyYIaFogh2Bzobt1zaAmP udgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796250853; x=1796855653; 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=fUZzeScLT6hrUJswX5oZCODgZASBz451GYS191xjyQM=; b=K8YTc3KNxO4z1u0jRvuKYMBImr+jECoGuwoo0HyOgUYCJMVfI+8WeU2BI3weTeqsfA Dxi+HQ17Nj3MIEDCe416tchPbAyQQEGbQmV3e/U71nQUUv8NXtQtLyxzzW4VThLKB766 gUeyWPk+T1aLv8s/UDnz11xp4McWBknoK1UQe/X9yuMuuLV0VD4IpwQhWePsnV0qPIDH b15TzRu/KqsxOYw2uinKr5BC+bxcFkaSh1qMKi6yx/ztpfYSAezeNobpktUFfd3TqhvO L8eoNiGXmw0wIEQTAKj9aSKVvJT5ZnKE1E2GJuUUTcprLZ4QenjdUJSMk2Es+WlSXoKN rwJg== X-Forwarded-Encrypted: i=1; AL+hErHugFfQpnzO7OJ9LMh3ENTGjQ6h3i97WZR1eufK+tfTOqaik89yXTphU0VuoMuU3E2LDIvXJa4jxfw=@lists.freedesktop.org X-Gm-Message-State: APuU4Z8Io6nKFaSNfVVf2Qe6TRGzjnFSblF+9O+HhYgoH+448sPRNRsY ou8k0elxz5vYx1nzs84EbM64yi39VbyMIWlbh8mRZRQycvukxM+DUmi9 X-Gm-Gg: AZFdTZdjnUWESd6FIA2s9VXNuBvKB0ZBK6Bayc8Slawk+rovygaLDivj57Yc5X2Nmde RypZSgtpj7Vasoe0+OJNFmYhPIQUHi6M9FFGmWGA3rA3Mljzs0tasj9Sok5Wdy9A+Q3KQ+YkxLb 0ZyV2mK35uGwMelkFzbb17CRsi1ivSN0m/M+TE7b2uP+iRq+niBiCM71oY3bpe3hkW5+CC/WjhX IgJCqOi6bMdimjL/GsvPrzlrvsIrm8PeEArAJgegfjoFAeU/0A40iqj6aebAVtYlUBOMKXmU+6V yMY0YQG5gCYMjJFia4QVqSOIRzA7uBEvNvYdJTcruLMOkz4J/B3j0IxUs62lPrPXA0E+52kHcf0 sklJn0fvMpix+HMiNG5c98url+5+hSaTJvfXfqsbruR9HLaH3vPd2CpGDQtjcHOEJ2QI6pEPK4V rkWBJcgQEOQ3ixiaEWkEMKK96wFoMOjgA36enobB6xltskM1nYHAccecZhEoPru0vlbUnxyDJvN kXKc0zvMLpSXO7RLeArV/mhTz/AU08ghUqhyUTuz/udN74lKvmIMbLzZdqC0b8ljfFGYh723ENR 4qPg3uB+Ok/0cDZ/eTUpk5jWtZPnLZ5J2Bghej+kEAxESiUFD/es6CXLeGDsj1+0qBFJ8ri6Uii Gwf5vBQVRWrMNBIpE35YWVRGGkCYVikH6Ycj3VrFXYFBU3P6g2ndk+yQk+LQ7GMqVZGnQ3YSyj8 CnfqFSteMnw2WzC4AmOg== X-Received: by 2002:a05:690c:d0f:b0:8b4:d516:f820 with SMTP id 00721157ae682-8b5204d2c1bmr180375207b3.45.1796250853271; Wed, 02 Dec 2026 14:34:13 -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-8b52028d628sm161211457b3.8.2026.12.02.14.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 14:34:12 -0800 (PST) From: Matt Turner Date: Wed, 02 Dec 2026 17:34:10 -0500 Subject: [PATCH 1/3] drm/amdgpu: fix IB content read in the devcoredump X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-amdgpu-devcoredump-fixes-v1-1-59f622a29769@gmail.com> References: <20261202-amdgpu-devcoredump-fixes-v1-0-59f622a29769@gmail.com> In-Reply-To: <20261202-amdgpu-devcoredump-fixes-v1-0-59f622a29769@gmail.com> To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Simona Vetter , Pierre-Eric Pelloux-Prayer , Le Ma , Lijo Lazar 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=5579; i=mattst88@gmail.com; h=from:subject:message-id; bh=Tpd6fCVv6LaZYwmolgDnLZ8b9xKydgRfU/NUtHtF7bs=; b=owGbwMvMwCW25rVmCc8sv+mMp9WSGLIF5jycrzhl4/uHTz9v26rY13rszASTHt37S6Ryzx3Uf J22L4MnrOMjC4MYF8NMMUWWuPWKLLPadiz1OS39C2YOKxPIEGmRBgYgYGHgy03MKzXSMdIz1TbU MwQydIziIXJ6DBqZxcWlqUW6aQVFDnn5JYklmfl5xXr5Bal5BekFemmZaSUZGflFxalAI/TyUkt MXR3djAwNTCwdLcycLBxNTZydnQyd3BwdnV2djCzNTQycLR1NXC3NGbg4BWCumSrO8D9aactpxQ sX/ve+F6iU/TvxVWhOJ0eWTpn7dfE5fhpL1lszMmybOmF3/tdrYgo7jS+E/1N+N+XavAj3oh2Z8 Uytqd8qnRgB 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 amdgpu_devcoredump_print_ibs() has several problems when reading the contents of the IBs of the hung job: - PRT mappings have a bo_va with no BO behind it, so an IB address that falls into a PRT range dereferences a NULL BO in both the lock loop and the copy loop. - A BO without a resource (e.g. purged) is dereferenced via tbo.resource->mem_type. - The offset into the BO ignores mapping->offset, so for a mapping that does not start at the beginning of its BO the wrong data is dumped. - There is no check that the IB lies within the mapping, so a bogus IB address or size from a misbehaving process reads outside the mapping, possibly past the end of the BO. - ttm_bo_kmap() maps the entire BO, which needlessly vmaps large BOs, and the mapping is stored in abo->kmap, clobbering any kernel mapping the driver already holds there. - BOs with AMDGPU_GEM_CREATE_NO_CPU_ACCESS that have been moved to GTT are skipped, while BOs in CPU invisible VRAM without that flag fail in ttm_bo_kmap(). Skip mappings with no BO and BOs with no resource, honor mapping->offset, and check that the IB lies within its mapping, which amdgpu_vm_verify_parameters() already keeps within the BO. Read VRAM through amdgpu_device_vram_access(), which uses the CPU visible aperture where it can and MM_INDEX/MM_DATA for the rest, and kmap only the pages covering the IB into a local map object for everything else. Fixes: 7b15fc2d1f1a ("drm/amdgpu: dump job ibs in the devcoredump") Suggested-by: Gregoire Pean Signed-off-by: Matt Turner --- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 67 ++++++++++++++++-------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c index 30a8b4c5591d..0c6533b950f6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c @@ -209,6 +209,16 @@ static void amdgpu_devcoredump_fw_info(struct amdgpu_device *adev, } } +static struct amdgpu_bo * +amdgpu_devcoredump_mapping_bo(struct amdgpu_bo_va_mapping *mapping) +{ + /* PRT mappings have a bo_va with no BO behind it. */ + if (!mapping || !mapping->bo_va) + return NULL; + + return mapping->bo_va->base.bo; +} + static void amdgpu_devcoredump_print_ibs(struct drm_printer *p, struct amdgpu_coredump_info *coredump, @@ -259,10 +269,10 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, u64 addr = coredump->ibs[i].gpu_addr & AMDGPU_GMC_HOLE_MASK; mapping = amdgpu_vm_bo_lookup_mapping(vm, addr); - if (!mapping) + abo = amdgpu_devcoredump_mapping_bo(mapping); + if (!abo) continue; - abo = mapping->bo_va->base.bo; r = drm_exec_lock_obj(&exec, &abo->tbo.base); drm_exec_retry_on_contention(&exec); if (r) @@ -271,6 +281,7 @@ 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; ib_content = kvmalloc_array(coredump->ibs[i].ib_size_dw, 4, @@ -280,41 +291,55 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, va_start = coredump->ibs[i].gpu_addr & AMDGPU_GMC_HOLE_MASK; mapping = amdgpu_vm_bo_lookup_mapping(vm, va_start); - if (!mapping) + abo = amdgpu_devcoredump_mapping_bo(mapping); + if (!abo || !abo->tbo.resource) goto output_ib_content; - abo = mapping->bo_va->base.bo; - offset = va_start - mapping->start * AMDGPU_GPU_PAGE_SIZE; + if (va_start + size > + (mapping->last + 1) * AMDGPU_GPU_PAGE_SIZE) + goto output_ib_content; - if (abo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS) { + 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; - - if (abo->tbo.resource->mem_type != TTM_PL_VRAM) - goto output_ib_content; - - amdgpu_res_first(abo->tbo.resource, offset, - coredump->ibs[i].ib_size_dw * 4, &cursor); + amdgpu_res_first(abo->tbo.resource, offset, size, + &cursor); while (cursor.remaining) { - amdgpu_device_mm_access(adev, cursor.start, - &ib_content[off], cursor.size, - false); + 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 { - r = ttm_bo_kmap(&abo->tbo, 0, PFN_UP(abo->tbo.base.size), - &abo->kmap); + 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 = amdgpu_bo_kptr(abo); - kptr += offset; - memcpy(ib_content, kptr, coredump->ibs[i].ib_size_dw * 4); + 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); - amdgpu_bo_kunmap(abo); + ttm_bo_kunmap(&map); emit_content = true; } -- 2.56.1