From: Arun Iyengar <[email protected]>
addr_to_mapping() takes a reference on the mapping it finds in the
address space's drm_mm with kref_get(). But the last reference is
dropped before panfrost_gem_teardown_mapping() removes the node from the
drm_mm under mm_lock, so the lookup can find a mapping whose refcount is
zero. kref_get() revives it, the release still frees it and drops the
BO, and the fault handler maps pages into a BO that is being freed.
This takes a GPU fault on a heap BO while its last handle and last job
reference go away, so a job that uses a heap BO it does not list;
userspace on the render node can submit that.
Use kref_get_unless_zero(); the fault is then reported as unhandled.
Found by code review, after Sashiko reported the same pattern in new
code of this series. Not reproduced.
Fixes: bdefca2d8dc0 ("drm/panfrost: Add the panfrost_gem_mapping concept")
Cc: [email protected]
Link: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Arun Iyengar <[email protected]>
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c
b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index faa62643c..d0c6b6635 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -576,7 +576,11 @@ addr_to_mapping(struct panfrost_device *pfdev, int as, u64
addr)
offset < (node->start + node->size)) {
mapping = drm_mm_node_to_panfrost_mapping(node);
- kref_get(&mapping->refcount);
+ /* The node stays in the mm after the last reference is
+ * dropped: don't revive a mapping that is being freed.
+ */
+ if (!kref_get_unless_zero(&mapping->refcount))
+ mapping = NULL;
break;
}
}
--
2.55.0