Yes, that leak (including the drm_gpuvm -> drm_dev_put() reference on
pvr_dev, and on pvr_device_lost() as well as pvr_remove()) is
intentional here.
pvr_queue_fence_release() runs under rcu_read_lock(), and
pvr_context_release() tears down FW objects against kernel_vm_ctx and
fw_mm, which pvr_remove() -> pvr_device_fini() destroys after
drm_dev_unplug(). Avoiding the leak cleanly requires moving device
teardown to drmm_ / refcounted lifetime (noted in [PATCH 0/2]), which
was left out so these use-after-free fixes remain minimal and
backportable.
On 2026-11-25 19:42, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/imagination: context and drm_device leak in
pvr_queue_fence_release()
--
commit 98562e29f0071aecadfba68150e688168073f7c8
Author: Lewis Lakerink <[email protected]>
drm/imagination: guard fence release against device removal
This commit guards work queueing in pvr_queue_fence_release() with
drm_dev_enter(), freeing the fence directly and skipping
pvr_context_put()
when the device is unplugged.
diff --git a/drivers/gpu/drm/imagination/pvr_queue.c
b/drivers/gpu/drm/imagination/pvr_queue.c
index 34b826381aa2b..2a6bfb090fadd 100644
--- a/drivers/gpu/drm/imagination/pvr_queue.c
+++ b/drivers/gpu/drm/imagination/pvr_queue.c
[ ... ]
@@ -122,8 +123,19 @@ static void pvr_queue_fence_release(struct
dma_fence *f)
{
struct pvr_queue_fence *fence = container_of(f, struct
pvr_queue_fence, base);
struct pvr_device *pvr_dev = fence->queue->ctx->pvr_dev;
+ int idx;
- queue_work(pvr_dev->sched_wq, &fence->release_work);
+ /*
+ * Fences held by drm_syncobj are released in drm_file_free() before
+ * postclose. After unplug, sched_wq and kernel_vm_ctx may already
be
+ * torn down; free the fence directly and leak the context
reference.
+ */
+ if (drm_dev_enter(from_pvr_device(pvr_dev), &idx)) {
+ queue_work(pvr_dev->sched_wq, &fence->release_work);
+ drm_dev_exit(idx);
+ } else {
+ dma_fence_free(&fence->base);
+ }
}
[Severity: High]
Does leaking the fence->queue->ctx reference here also permanently leak
pvr_dev and trigger teardown warnings?
drm_dev_unplug() is called not only during pvr_remove(), but also at
runtime when a GPU reset or MMU flush fails:
drivers/gpu/drm/imagination/pvr_power.c:pvr_device_lost() {
if (!pvr_dev->lost) {
pvr_dev->lost = true;
drm_dev_unplug(from_pvr_device(pvr_dev));
}
}
Once unplugged, dropping the context reference in the else branch
prevents
pvr_context_release() from ever running. That leaves the context in
pvr_dev->ctx_ids and its firmware objects in fw_objs.list and
fw_dev->fw_mm
(triggering WARN_ONs in pvr_fw_fini() and pvr_context_device_fini()),
and
never drops ctx->vm_ctx, whose drm_gpuvm manager and GEM objects hold
drm_device references that prevent drm_dev_release() from freeing
pvr_dev.