dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lewis Lakerink" <lewis@retsim.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/imagination: guard fence release against device removal
Date: Wed, 25 Nov 2026 08:42:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-232926@kernel.org> (raw)
In-Reply-To: <010101a211d07983-72e5379a-adfd-4134-b23d-3e2b1422bc2e-000000@us-west-2.amazonses.com>

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 <lewis@retsim.com>

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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/010101a211d07983-72e5379a-adfd-4134-b23d-3e2b1422bc2e-000000@us-west-2.amazonses.com?part=1

  parent reply	other threads:[~2026-11-25  8:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261125082637.2839673-1-lewis@retsim.com>
2026-11-25  8:26 ` [PATCH 1/2] drm/imagination: guard fence release against device removal Lewis Lakerink
2026-11-26  8:28   ` sashiko-bot
2026-11-25  8:26 ` [PATCH 2/2] drm/imagination: quiesce queues before device teardown Lewis Lakerink
2026-11-26  8:46   ` sashiko-bot
     [not found] ` <010101a211d07983-72e5379a-adfd-4134-b23d-3e2b1422bc2e-000000@us-west-2.amazonses.com>
2026-11-25  8:42   ` sashiko-bot [this message]
2026-11-25  8:47     ` [PATCH 1/2] drm/imagination: guard fence release against device removal lewis
     [not found] ` <010101a211d07b13-42cf1386-97c8-41d3-8eca-2e56ccb33258-000000@us-west-2.amazonses.com>
2026-11-25  8:55   ` [PATCH 2/2] drm/imagination: quiesce queues before device teardown sashiko-bot

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=sashiko-outbox-232926@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lewis@retsim.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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