Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/imagination: pvr_queue_fence_release() leaks context when
  unplugged
--

commit 9773b5621e802ef35e9ac3c4db81027170ee1477
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
fence->release_work when the DRM device is marked 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 taking the else branch leak fence->queue->ctx on runtime device loss
as well as on driver unbind?

pvr_device_lost() calls drm_dev_unplug() at runtime when a GPU hard reset
or MMU flush fails, while the device is still bound and sched_wq is still
active.  Every pvr_queue_fence released after pvr_device_lost() (or after
drm_dev_unplug() in pvr_remove()) will skip pvr_context_put(), so
pvr_context_release() never runs.

That leaves the context's queues, firmware objects and ctx->vm_ctx
allocated, triggering WARN_ON(!list_empty(&pvr_dev->fw_dev.fw_objs.list))
in pvr_fw_fini() and WARN_ON(!xa_empty(&pvr_dev->ctx_ids)) in
pvr_context_device_fini() on unbind, and keeps ctx->vm_ctx->gpuvm_mgr's
drm_device reference alive so struct pvr_device is never freed.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/010101a211d07798-70c4219d-e457-43d8-835c-321a7c035057-000...@us-west-2.amazonses.com?part=1

Reply via email to