[PATCH 2/2] drm/msm: Put the VM_BIND queue last in msm_vma_job_free()

From: Jiwoo Kim

Date: Sat Nov 14 2026 - 01:26:20 EST


msm_vma_job_free() puts the job's submitqueue and then wakes up
vm->prealloc_throttle.wait. The job does not hold a reference to the
VM of its own: the VM is kept alive by the context, which the queue
holds a reference to. When the job holds the last reference to the
queue, as it can once the file has been closed, for example when a
cancelled job is freed, the put can drop the last reference to the VM,
and the wakeup then uses a VM that msm_gem_vm_free() has released.

Since commit 01c8d1f385f7 ("drm/msm: RCU-free the scheduler-containing
ring and VM objects"), msm_gem_vm_free() frees the VM with kfree_rcu(),
but msm_vma_job_free() is not in an RCU read-side critical section, so
a grace period can still end before the wakeup, e.g. if the task is
preempted in between. Before that commit, the VM was freed right away.

Put the queue only after the last use of the VM.

This was found with an AI coding assistant, which also drafted this
patch and its changelog. It has not been reproduced, and the change
has only been compile-tested.

Fixes: b74fae5492d1 ("drm/msm: Add VM_BIND throttling")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jiwoo Kim <arpe1618@xxxxxxxxx>
---
Independent of 1/2.

drivers/gpu/drm/msm/msm_gem_vma.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/msm_gem_vma.c b/drivers/gpu/drm/msm/msm_gem_vma.c
index 0cf518420656..b4b284ca5b38 100644
--- a/drivers/gpu/drm/msm/msm_gem_vma.c
+++ b/drivers/gpu/drm/msm/msm_gem_vma.c
@@ -775,7 +775,6 @@ msm_vma_job_free(struct drm_sched_job *_job)
job_foreach_bo (obj, job)
drm_gem_object_put(obj);

- msm_submitqueue_put(job->queue);
dma_fence_put(job->fence);

/* In error paths, we could have unexecuted ops: */
@@ -788,6 +787,12 @@ msm_vma_job_free(struct drm_sched_job *_job)

wake_up(&vm->prealloc_throttle.wait);

+ /*
+ * The queue may hold the last reference to the context, and so to the
+ * VM, so put it only once we are done with the VM.
+ */
+ msm_submitqueue_put(job->queue);
+
kfree(job);
}

--
2.43.0