dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vladimir Bely" <vlwwwwww@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/msm/gem: defer shared GPU VM teardown until last VMA user
Date: Sun, 29 Nov 2026 00:23:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-239191@kernel.org> (raw)
In-Reply-To: <20261129000944.986285-1-vlwwwwww@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/msm: TOCTOU race on vma_ref across unlocked wait in
  msm_gem_vma_put()
--

commit 465909c901566442dba60b64068077eeb1425e62
Author: Vladimir Bely <vlwwwwww@gmail.com>

drm/msm/gem: defer shared GPU VM teardown until last VMA user

This commit skips tearing down VMAs in the shared global GPU VM during
msm_gem_close() and instead defers the teardown to msm_gem_vma_put() when
vma_ref reaches zero.

> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 6ee0e7d146157..88a46ec3caad1 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c

[ ... ]

> @@ -105,6 +131,23 @@ void msm_gem_vma_put(struct drm_gem_object *obj)
>  	if (atomic_dec_return(&to_msm_bo(obj)->vma_ref))
>  		return;
>  
> +	/*
> +	 * Without per-process pagetables, every context maps the object in
> +	 * the shared global GPU VM, see msm_gem_close().  Drop that mapping,
> +	 * and the reference it holds on the object, once the last user is
> +	 * gone.  Check has_vma() first so GPUs with per-process pagetables
> +	 * don't wait on fences or lock the global GPU VM.
> +	 */
> +	if (priv->gpu && priv->gpu->vm && has_vma(obj, priv->gpu->vm)) {
> +		struct drm_exec exec;
> +
> +		dma_resv_wait_timeout(obj->resv, DMA_RESV_USAGE_BOOKKEEP, false,
> +				      MAX_SCHEDULE_TIMEOUT);
> +		msm_gem_lock_vm_and_obj(&exec, obj, priv->gpu->vm);
> +		put_iova_spaces(obj, priv->gpu->vm, true, "vma_put");
> +		drm_exec_fini(&exec);     /* drop locks */
> +	}
> +
>  	if (!priv->kms)
>  		return;

[Severity: Medium]
Can msm_gem_vma_put() tear down active VMAs in priv->gpu->vm and
priv->kms->vm if vma_ref is incremented again while dma_resv_wait_timeout()
is sleeping unlocked?

For example, an existing drm_framebuffer holds a GEM object reference
without holding vma_ref while unprepared, and a concurrent atomic commit
can prepare it while msm_gem_vma_put() is waiting on fences:

CPU0                                  CPU1
msm_gem_close()
  msm_gem_vma_put()
    atomic_dec_return(&vma_ref) -> 0
    dma_resv_wait_timeout(...)
                                      msm_framebuffer_prepare()
                                        msm_gem_vma_get()
                                          atomic_inc(&vma_ref) -> 1
                                        msm_gem_get_and_pin_iova(...)
    msm_gem_lock_vm_and_obj(...)
    put_iova_spaces(..., gpu->vm, ...)
    drm_exec_fini(&exec)
    msm_gem_lock_vm_and_obj(...)
    put_iova_spaces(..., kms->vm, ...)  <-- unmaps active VMA

Because vma_ref is not re-checked after locking the VM and object,
put_iova_spaces() unmaps and closes VMAs that are back in use, causing
IOMMU faults and causing the later msm_framebuffer_cleanup() ->
msm_gem_unpin_iova() call to miss the closed VMA and leak pin_count.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129000944.986285-1-vlwwwwww@gmail.com?part=1

  reply	other threads:[~2026-11-29  0:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  0:09 [PATCH] drm/msm/gem: defer shared GPU VM teardown until last VMA user Vladimir Bely
2026-11-29  0:23 ` sashiko-bot [this message]
2026-11-29  1:17 ` [PATCH v2] " Vladimir Bely
2026-11-29  1:35   ` sashiko-bot
2026-11-29  8:16   ` kernel test robot
2026-11-29  9:00   ` [PATCH v3] " Vladimir Bely

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-239191@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vlwwwwww@gmail.com \
    /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