From: Matt Turner <mattst88@gmail.com>
To: "Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Pierre-Eric Pelloux-Prayer" <pierre-eric.pelloux-prayer@amd.com>,
"Le Ma" <le.ma@amd.com>, "Lijo Lazar" <lijo.lazar@amd.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, Matt Turner <mattst88@gmail.com>,
Gregoire Pean <gpean@netflix.com>
Subject: [PATCH 1/3] drm/amdgpu: fix IB content read in the devcoredump
Date: Wed, 02 Dec 2026 17:34:10 -0500 [thread overview]
Message-ID: <20261202-amdgpu-devcoredump-fixes-v1-1-59f622a29769@gmail.com> (raw)
In-Reply-To: <20261202-amdgpu-devcoredump-fixes-v1-0-59f622a29769@gmail.com>
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 <gpean@netflix.com>
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
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
next prev parent reply other threads:[~2026-12-02 22:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 22:34 [PATCH 0/3] drm/amdgpu: devcoredump and reset fixes Matt Turner
2026-12-02 22:34 ` Matt Turner [this message]
2026-12-02 22:34 ` [PATCH 2/3] drm/amdgpu: clear stale JPEG and VCN1 IP dump pointers Matt Turner
2026-12-02 22:34 ` [PATCH 3/3] drm/amdgpu: don't unmap legacy queues through MES during reset Matt Turner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202-amdgpu-devcoredump-fixes-v1-1-59f622a29769@gmail.com \
--to=mattst88@gmail.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gpean@netflix.com \
--cc=le.ma@amd.com \
--cc=lijo.lazar@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pierre-eric.pelloux-prayer@amd.com \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®