From: sashiko-bot@kernel.org
To: "Jiwoo Kim" <arpe1618@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 2/5] drm/msm: Mark the VM unusable on out-of-order VM_BIND unmaps
Date: Wed, 18 Nov 2026 02:45:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-219981@kernel.org> (raw)
In-Reply-To: <20261118020716.1698-3-arpe1618@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/msm: unmapped VMAs left in pgtables on msm_ioctl_vm_bind()
failure
- [Medium] drm/msm: missed msm_gem_vm_unusable() when vm_ops is empty on
error
--
commit eeb2166c9690535d4ade679e940123eb63eece51
Author: Jiwoo Kim <arpe1618@gmail.com>
drm/msm: Mark the VM unusable on out-of-order VM_BIND unmaps
This commit tracks whether a VM_BIND job's map operations have been applied
to the page tables and marks the VM unusable when an unmap runs out of
order or when msm_ioctl_vm_bind() fails after queuing page table updates.
Link: https://lore.kernel.org/r/CACSVV00ZppfBKwsHJ+NBYBB7a2f3g1O=6J4Gt1m_A74fudZQoQ@mail.gmail.com
> diff --git a/drivers/gpu/drm/msm/msm_gem_vma.c b/drivers/gpu/drm/msm/msm_gem_vma.c
> index 2f0698df1a9a0..228c16a3d9e49 100644
> --- a/drivers/gpu/drm/msm/msm_gem_vma.c
> +++ b/drivers/gpu/drm/msm/msm_gem_vma.c
[ ... ]
> @@ -783,10 +876,14 @@ msm_vma_job_free(struct drm_sched_job *_job)
> while (!list_empty(&job->vm_ops)) {
> struct msm_vm_op *op =
> list_first_entry(&job->vm_ops, struct msm_vm_op, node);
> + if (op->op == MSM_VM_OP_UNMAP)
> + vm_bind_done_put(op->unmap.map_done);
> list_del(&op->node);
> kfree(op);
> }
>
> + vm_bind_done_put(job->bind_done);
> +
> wake_up(&vm->prealloc_throttle.wait);
>
> kfree(job);
[Severity: High]
When msm_ioctl_vm_bind() fails after msm_gem_vm_sm_step_unmap() or
msm_gem_vm_sm_step_remap() has queued an MSM_VM_OP_UNMAP, does discarding
the unexecuted unmap ops here leave the closed VMA's pages mapped in
vm->mmu?
Both step functions set msm_vma->mapped = false and call
msm_gem_vma_close(), which removes the VMA from job->vm and unlinks it from
the GEM object's vm_bo before the job is pushed. If a later operation in
vm_bind_job_prepare() or sync_file_create() fails, msm_vma_job_free() frees
the queued MSM_VM_OP_UNMAP without unmapping its range from vm->mmu. If
that range was already mapped by an earlier job, its PTEs remain active in
vm->mmu while no VMA remains on obj->gpuva.list, so when the shrinker later
evicts or purges the unpinned object via msm_gem_evict() or msm_gem_purge(),
put_iova_spaces() does not unmap the range before put_pages() frees the
backing pages.
In addition, msm_gem_vm_unusable() writes vm->unusable = true outside
vm->mmu_lock (and returns before taking vm->mmu_lock when vm->log is NULL
or empty), while msm_vma_job_run() does not hold the VM dma_resv lock. An
earlier job that maps the closed VMA can therefore run msm_vma_job_run()
concurrently, observe vm->unusable == false, and map the pages into vm->mmu
even if the VMA was not yet mapped when msm_ioctl_vm_bind() failed.
[ ... ]
> @@ -1604,6 +1709,15 @@ msm_ioctl_vm_bind(struct drm_device *dev, void *data, struct drm_file *file)
> if (ret)
> vm_bind_job_unpin_objects(job);
>
> + /*
> + * A job that fails after it queued pgtable updates is freed without
> + * applying them, so the VM no longer matches its pgtables, and a
> + * later unmap of one of its VMAs would be taken for an out of order
> + * one.
> + */
> + if (ret && !list_empty(&job->vm_ops))
> + msm_gem_vm_unusable(job->vm);
> +
> drm_exec_fini(&exec);
> out_unlock:
> mutex_unlock(&queue->lock);
[Severity: Medium]
Can msm_ioctl_vm_bind() still fail after mutating job->vm while
job->vm_ops is empty, leaving the modified VM usable?
In msm_gem_vm_sm_step_map(), vma_from_op() inserts the new VMA into job->vm
with mapped = false before vm_op_enqueue() is called:
drivers/gpu/drm/msm/msm_gem_vma.c:msm_gem_vm_sm_step_map() {
vma = vma_from_op(arg, &op->map);
if (WARN_ON(IS_ERR(vma)))
return PTR_ERR(vma);
...
ret = vm_op_enqueue(arg, (struct msm_vm_op){
...
});
if (ret)
return ret;
}
If vm_op_enqueue() fails with -ENOMEM on the first step of op 0, both i == 0
in vm_bind_job_prepare() and list_empty(&job->vm_ops) are true, so neither
check calls msm_gem_vm_unusable(). If op 0 was MSM_VM_BIND_OP_MAP_NULL,
the unmapped VMA stays in job->vm with vm_bo == NULL; a subsequent ioctl
that remaps that range will then reach msm_gem_vm_sm_step_remap() with
!mapped and call drm_gpuvm_bo_evict(vm_bo, true), dereferencing NULL.
The same check also misses failures in op 0 or sync_file_create() after
op 0 modified job->vm without queueing a vm_op (such as closing an
already-unmapped VMA or updating flags in place via arg->kept). Conversely,
when vm_bind_job_prepare() fails at i > 0 with a non-empty job->vm_ops, both
vm_bind_job_prepare() and msm_ioctl_vm_bind() call msm_gem_vm_unusable(),
dumping the VM log twice.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118020716.1698-1-arpe1618@gmail.com?part=2
next prev parent reply other threads:[~2026-11-18 2:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 2:07 [PATCH v4 0/5] drm/msm: Fix VM_BIND job, queue and entity lifetimes Jiwoo Kim
2026-11-18 2:07 ` [PATCH v4 1/5] drm/msm: Wait for VM_BIND jobs in msm_gem_vm_close() Jiwoo Kim
2026-11-18 2:07 ` [PATCH v4 2/5] drm/msm: Mark the VM unusable on out-of-order VM_BIND unmaps Jiwoo Kim
2026-11-18 2:45 ` sashiko-bot [this message]
2026-11-18 2:07 ` [PATCH v4 3/5] drm/msm: Release the pins and ops of a killed VM_BIND job Jiwoo Kim
2026-11-18 2:07 ` [PATCH v4 4/5] drm/msm: Destroy the VM_BIND entity when its queue is closed Jiwoo Kim
2026-11-18 2:07 ` [PATCH v4 5/5] drm/msm: Put the VM_BIND queue last when freeing a VM_BIND job Jiwoo Kim
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-219981@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=arpe1618@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.