From: sashiko-bot@kernel.org
To: "Vladimir Bely" <vlwwwwww@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 1/2] drm/msm/gem: defer shared GPU VM teardown until last VMA user
Date: Fri, 04 Dec 2026 23:41:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-250812@kernel.org> (raw)
In-Reply-To: <20261204231058.699120-2-vlwwwwww@gmail.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] drm/msm: unbounded uninterruptible fence wait in
msm_gem_vma_put()
- [Medium] drm/msm: has_vma() locks obj->resv on per-process pagetable
GPUs
- [Medium] drm/msm: uninterruptible fence wait under modeset lock in
msm_gem_vma_put()
- [Medium] drm/msm: unchecked msm_gem_lock_vm_and_obj() return in
msm_gem_vma_put()
- [Medium] drm/msm/gem: blocking GPU fence wait and VM unmap in
msm_gem_vma_put()
- [Low] drm/msm: stale vma_ref comments only mention kms->vm
--
commit 04b8493963f48ed195419d586c3d301c918f3f68
Author: Vladimir Bely <vlwwwwww@gmail.com>
drm/msm/gem: defer shared GPU VM teardown until last VMA user
This commit skips per-handle VMA teardown in msm_gem_close() when ctx->vm
is the shared priv->gpu->vm, and instead tears down that mapping in
msm_gem_vma_put() once vma_ref drops to zero.
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 6ee0e7d146157..aac5926fbc904 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -53,8 +53,21 @@ static int msm_gem_open(struct drm_gem_object *obj, struct drm_file *file)
> static void put_iova_spaces(struct drm_gem_object *obj, struct drm_gpuvm *vm,
> bool close, const char *reason);
>
> +static bool has_vma(struct drm_gem_object *obj, struct drm_gpuvm *vm)
> +{
> + struct drm_gpuvm_bo *vm_bo;
> +
> + msm_gem_lock(obj);
> + vm_bo = drm_gpuvm_bo_find(vm, obj);
> + drm_gpuvm_bo_put(vm_bo);
> + msm_gem_unlock(obj);
> +
> + return !!vm_bo;
> +}
[Severity: Medium]
Does has_vma() still acquire obj->resv on GPUs with per-process pagetables?
msm_gpu_init() unconditionally creates priv->gpu->vm for kernel buffers on
a6xx/a7xx/a8xx as well, so priv->gpu && priv->gpu->vm is always true in
msm_gem_vma_put(). Every final vma_ref drop therefore takes
dma_resv_lock(obj->resv) and walks obj->gpuva.list.
For MSM_BO_NO_SHARE buffers, obj->resv aliases the process-wide ctx->vm
reservation lock used on every submit and VM_BIND ioctl, adding lock
contention on handle closes that previously took no locks.
[ ... ]
> @@ -105,6 +127,39 @@ 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.
> + */
[Severity: Low]
The comment above msm_gem_vma_get() in msm_gem.c ("Get/put for kms->vm
VMA") and the kernel-doc for msm_gem_object::vma_ref in msm_gem.h still
only mention kms->vm, even though vma_ref now also governs priv->gpu->vm
teardown.
> + if (priv->gpu && priv->gpu->vm && has_vma(obj, priv->gpu->vm)) {
> + struct drm_exec exec;
> +
> + for (;;) {
> + dma_resv_wait_timeout(obj->resv,
> + DMA_RESV_USAGE_BOOKKEEP, false,
> + MAX_SCHEDULE_TIMEOUT);
[Severity: Medium]
Can this uninterruptible fence wait now sleep while drm_modeset_lock is
held?
If a synchronous atomic commit is interrupted by a signal during
drm_atomic_helper_wait_for_fences(dev, state, true), the error path runs
drm_atomic_helper_unprepare_planes() -> msm_framebuffer_cleanup() ->
msm_gem_vma_put() while still holding drm_modeset_lock.
When the GEM handle was already closed, vma_ref drops to zero and this
re-enters an uninterruptible wait on the same unsignaled fence, turning a
signal-aborted commit into an unkillable wait that blocks other modesets
and VT switches.
> + if (atomic_read(&to_msm_bo(obj)->vma_ref))
> + return;
> +
> + msm_gem_lock_vm_and_obj(&exec, obj, priv->gpu->vm);
[Severity: Medium]
What happens if msm_gem_lock_vm_and_obj() fails with -ENOMEM here?
drm_exec_lock_obj() can return -ENOMEM without holding either lock when
allocating exec->objects fails (for instance, during exit_files() of an
OOM-killed process whose ALLOC_OOM reserves are exhausted).
Ignoring the return value lets put_iova_spaces() unlink and free VMAs from
the shared priv->gpu->vm without holding obj->resv or the VM lock, risking
rb-tree and list corruption against concurrent contexts.
> + if (atomic_read(&to_msm_bo(obj)->vma_ref)) {
> + drm_exec_fini(&exec);
> + return;
> + }
> + if (dma_resv_test_signaled(obj->resv,
> + DMA_RESV_USAGE_BOOKKEEP)) {
> + put_iova_spaces(obj, priv->gpu->vm, true,
> + "vma_put");
> + drm_exec_fini(&exec);
> + break;
> + }
[Severity: Medium]
Is it safe to block on GPU fences, the global priv->gpu->vm lock, and
synchronous IOMMU unmap inside msm_gem_vma_put()?
msm_atomic_commit_tail() -> msm_framebuffer_cleanup() runs before
drm_atomic_helper_commit_cleanup_done(), so an active or hung GPU job on an
old scanout BO whose handle was already closed stalls subsequent commits in
stall_checks().
Likewise, delayed_fput() -> msm_gem_dmabuf_release() drains deferred file
closes serially on a single global work item, so blocking here stalls
unrelated deferred file releases system-wide. Deferring shared GPU VMA
teardown to a worker or fence callback would avoid blocking both paths.
> + drm_exec_fini(&exec);
> + }
> + }
[Severity: High]
Can this unbounded retry loop livelock on a foreign imported dma-buf?
msm_gem_import() sets obj->resv = dmabuf->resv, while each import gets an
independent vma_ref. Once vma_ref reaches zero, nothing can raise it
again, yet another dma-buf holder can keep attaching unsignaled fences to
dmabuf->resv via DMA_BUF_IOCTL_IMPORT_SYNC_FILE or another GPU context.
When a new fence lands while dma_resv_wait_timeout() sleeps on an earlier
one, dma_resv_test_signaled() sees the new fence under the lock and loops
indefinitely in uninterruptible sleep, hanging msm_gem_close() in D state
or wedging atomic commit_work.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204231058.699120-1-vlwwwwww@gmail.com?part=1
parent reply other threads:[~2026-12-04 23:41 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20261204231058.699120-2-vlwwwwww@gmail.com>]
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-250812@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