From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796250854; b=DqC+c/Ak98BYdgYlKm8HwzwlVuzbeUt0mWioS5mwxV8UAeXgTrsAdn3YeG2nkfwKgAGO qY/6duCzKo4SaP8kJiLDMHT4ja+BEjMIQCl5jq29Vspigfg4UrQ7ZZM9mVboO9KNIzoUQ dwH7lvqN+nJngQTjYcGyHYYOAOXI12tHbAXXWPmv/hreahkRSkdO4WV5cYqX18fQ4q8JJ 66qh3fnSyclW6C5W6DKuzT9J+J5+UAnnnpSSoum+D5Q+2FHKRT8pCV80nXg89cy0Pot7M srJnbYalMU14SbNDdbXSjFw8dqPfioGPvTpVqebGqcdFlz/GviFx9yKAXJvMYpaBekQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796250854; 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=fUZzeScLT6hrUJswX5oZCODgZASBz451GYS191xjyQM=; b=n4nfoRDW1t38i6gbmDuBcXVZTvVlkq2iDqa9BCm/zTL8QEOERS9TTOHt42q1LMOxcirV LysCS8x8qjGymxS07m2L2pDvccNBx/obi4XMS8E1aZvYYxxgJn6Sqceum27K+UIThgvGT wExfcoxYsUP3VbhjRiA10MzibICUwcu/JLB7JuUEYRURZzsQ2foQfu76Zva+YWdKGjMGu aYwUuGSe3yA1bE7L6X9HL8uSuH1haulwm1osPahzcOrZjiDcdNZnOuMZ8OdWVxCIoQ6gp PNSyUlW3F2WfClzVuMnR/HoKSxWtLfn/Ke6jRmTb2/F/ktMg84W5gO47hWY0pxflo7A== 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=uGz3dHxf; arc=none smtp.remote-ip=209.85.128.181 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 7654A606A339 for ; Wed, 2 Dec 2026 22:34:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7654A606A339 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=uGz3dHxf Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-8b5f67966adso313357b3.3 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=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=fUZzeScLT6hrUJswX5oZCODgZASBz451GYS191xjyQM=; b=uGz3dHxf6XIn4k8d8Md3+4YOYLZi6HmYjrrdhZuNrhir/yDS4ilzXJuYyZxCEYWa13 Gnf6IYPzcTrg/XESY3V3AqESZzat7Om0Ayh5VqUz9eGz4p1mzE1RecJaxEwP0/7sWrcc 0Ep17se8CcHsFv0hIhzkSNtl8gF4z4djcIeHPHxn3/uT0WQB5WpKoN95CRXc41aXDv0d Z3UT1NpG/nD7VWI+TeN9LaYahVjRAGdUTUhm23Hw8fBJMgFbu8TQlxoafzNW2fdd2miF CERgQWUUe3e/NBcKnU0ug/jUf/VdDYUvGKB+eST+XEKdzwD+74udZLtRgeDIVI+3HF2e jWlA== 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=BJHE3rtNJh3hnT+3zklWgYEtFIN8UJd3u70ozMg0lBUKgj1sm242PFYfrB+4sG+rO+ Rre/mBEyj2Qe+SqK52QkJNt5UlRV76PH+OPBnqYr+6S65DIlj2MeySxOyiOQG04tjKaO IBOsEqapu8vIlYYx6OuBSgAfOpJFxO7L+vlw+a7405Q6BNRflbdiYChS5zuYp3Xqk/P4 g03f0dctqiHgxsPsCZDZPl4qsmd7VNA+V+5r29BUyaDlEiGtMvx0XmPqrjw7HiREEw1N SvmcYj/8vEECsd6wSp/ri0JOdgx1ctlXJ/xAICxs/0DUmRtE6O5BCk0oejRhQ4A7O/YG NAKg== X-Forwarded-Encrypted: i=1; AL+hErGFtxpKeOSBXcT/JkijRAAsHu6WeisWyBPuPdh8u+HHjWY+rM3SIHOWQXoufv/T7wetrMn+jdkysH//sOI=@vger.kernel.org X-Gm-Message-State: APuU4Z/9IW32sjbKpE98NSt78AT6fsShWMQrdLydd0gfBz45lk/eyaMg BwubMnftq8ShXv2l1NdpPEMdqotIPXApgNylUgX8909DWOPGw6LdtVs8 X-Gm-Gg: AZFdTZdDRFP1kvXwuscvccJ/DHfAzQ/Gk8ouGWJ6BjHurREl41DISGLdyOdI3sW3Yx0 eTqO8Kq6vR+jvKQSpb8rFqMt852hfwqCjGQyzDVCduD08kNgC6Gv9D6zZQf2y39sMPKK7gd83nI h6O2Kkt6qycsDxURFORTXjczrb8FbwzPOWBU/YklhBF1D9lw4SFG4gyC+b61zM8J16LhGXZWpv8 zCtwxcxXu5NqUvoOUONVkG/QM0bks70eeaJCygP1Pqb2uMVprCCJ3FLh7Gbva0OeHWsypP/UYjt 1Tq54K345taLEvwLE7RQrO0FwWjNeqpMbadWiFkkn8mrqMaCO7tPxn1UJF8rDn1dKQdnyIckqhk B1kazZDVDVIxp0wqjLCMu6d/ZNOfJWFZ8z5y9Ag9QQdX1hb9H2g2iCglqH9F8lhZYxRfRyJDXt2 fWM+mpUibeOqY++Fq9TT3ktKFZRWJbtZuLGitiYnKMWno21Ld6uGWQwkF31ZutF6HtmkWBErTMK ACqjYqctDA4TT1Qrj1UunQj2HOTXmUhSL/lYn8lJYN0OqCv6YgNR64IpFq4o4nB/5DuUNvLNMU8 Tp733ysC4e6/slonEaN2295hUMqXf+7YcgK6H+hhXQr7dcyOuVLyte+AqeaPue6T7M6Cf0E2M79 bV7Qoy/UsDgrPFvdyFYmyugKmdxuUdd6AuOhUDQAMoG+OF7+sPLT2/K5sxUh7JaF+jqaAQgb2va YyxkH2Vk6V0SJK2in5fw== 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-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-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 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