[PATCH v2 11/11] drm/panfrost: Name the BOs around an unhandled page fault
From: Arun Iyengar via B4 Relay
Date: Thu Nov 12 2026 - 04:31:39 EST
From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
An unhandled GPU page fault only reports the faulting VA. That does not
tell a GPU access just past the end of a buffer (a userspace or hardware
overrun) from a stale or garbage pointer.
After the fault report, look the address up in the faulting address
space and print the BO that contains it, or else the nearest BO below
and above it: VA range, size, the distance of the fault from it,
heap/noexec, and the label userspace gave it (Mesa labels its BOs with
their use, format and size). A BO that has been freed is no longer in the
address space, so an access to it shows up as a hole between its
neighbours. Mappings whose last reference is gone, which stay in the
address space until their teardown takes mm_lock, are skipped. For an
OpenCL image read on a Mali-G31 this gave (with an earlier version of
this patch, which also printed whether the BO was mapped):
panfrost 1800000.gpu: Unhandled Page fault in AS0 at VA 0x000000000A181000
...
panfrost 1800000.gpu: fault bo: below: VA [0xa041000-0xa181000) size 0x140000, fault at end+0x0, mapped, noexec, label "Texture format=r32g32b32_sint extent=25x128x32 array_size=1 mip_count=0 samples=0 modifier=0x0"
that is, the texture unit reading past the end of a 96-bit-per-texel
texture, which userspace can avoid by padding such textures.
Only the unhandled fault path is affected; heap growth faults are not.
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 88 +++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index 684735937..9c255daf2 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -601,6 +601,93 @@ addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr)
return mapping;
}
+static void panfrost_mmu_print_fault_bo(struct panfrost_device *pfdev,
+ struct panfrost_gem_mapping *m,
+ u64 addr, const char *where)
+{
+ struct panfrost_gem_object *bo = m->obj;
+ u64 start = m->mmnode.start << PAGE_SHIFT;
+ u64 end = (m->mmnode.start + m->mmnode.size) << PAGE_SHIFT;
+ u64 dist = addr < start ? start - addr : addr >= end ? addr - end : addr - start;
+
+ mutex_lock(&bo->label.lock);
+ dev_err(pfdev->base.dev,
+ "fault bo: %s: VA [0x%llx-0x%llx) size 0x%zx, fault at %s0x%llx%s%s, label \"%s\"\n",
+ where, start, end, bo->base.base.size,
+ addr < start ? "-" : addr >= end ? "end+" : "start+", dist,
+ bo->is_heap ? ", heap" : "", bo->noexec ? ", noexec" : "",
+ bo->label.str ? bo->label.str : "");
+ mutex_unlock(&bo->label.lock);
+}
+
+/*
+ * Report the BOs around an unhandled fault address in the faulting address
+ * space: the one containing it (if any), else the nearest one below and above.
+ * An access just past the end of a BO that a hole follows is a GPU overrun of
+ * that BO (userspace or hardware); an address far from any BO is a garbage
+ * pointer, or a stale one: a BO that has been freed has left the address
+ * space, and its range shows up as a hole between its neighbours.
+ */
+static void panfrost_mmu_report_fault_bos(struct panfrost_device *pfdev,
+ int as, u64 addr)
+{
+ struct panfrost_gem_mapping *below = NULL, *above = NULL;
+ u64 offset = addr >> PAGE_SHIFT;
+ struct drm_mm_node *node;
+ struct panfrost_mmu *mmu;
+ bool inside = false;
+
+ spin_lock(&pfdev->as_lock);
+ list_for_each_entry(mmu, &pfdev->as_lru_list, list) {
+ if (as == mmu->as)
+ goto found_mmu;
+ }
+ spin_unlock(&pfdev->as_lock);
+ dev_err(pfdev->base.dev, "fault bo: no context holds AS%d\n", as);
+ return;
+
+found_mmu:
+ spin_lock(&mmu->mm_lock);
+ /* The node list is sorted by address. A mapping whose last reference
+ * is gone is being freed, and only waits for mm_lock to leave the
+ * list: skip it.
+ */
+ drm_mm_for_each_node(node, &mmu->mm) {
+ struct panfrost_gem_mapping *m = drm_mm_node_to_panfrost_mapping(node);
+
+ if (!kref_read(&m->refcount))
+ continue;
+ if (node->start > offset) {
+ above = m;
+ break;
+ }
+ below = m;
+ }
+ if (below) {
+ inside = offset < below->mmnode.start + below->mmnode.size;
+ if (inside)
+ above = NULL;
+ if (!kref_get_unless_zero(&below->refcount))
+ below = NULL;
+ }
+ if (above && !kref_get_unless_zero(&above->refcount))
+ above = NULL;
+ spin_unlock(&mmu->mm_lock);
+ spin_unlock(&pfdev->as_lock);
+
+ if (!below && !above)
+ dev_err(pfdev->base.dev, "fault bo: AS%d has no BO\n", as);
+ if (below) {
+ panfrost_mmu_print_fault_bo(pfdev, below, addr,
+ inside ? "inside" : "below");
+ panfrost_gem_mapping_put(below);
+ }
+ if (above) {
+ panfrost_mmu_print_fault_bo(pfdev, above, addr, "above");
+ panfrost_gem_mapping_put(above);
+ }
+}
+
#define NUM_FAULT_PAGES (SZ_2M / PAGE_SIZE)
/*
@@ -984,6 +1071,7 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data)
exception_type, panfrost_exception_name(exception_type),
access_type, access_type_name(pfdev, fault_status),
source_id);
+ panfrost_mmu_report_fault_bos(pfdev, as, addr);
spin_lock(&pfdev->as_lock);
/* Ignore MMU interrupts on this AS until it's been
--
2.55.0