[PATCH v4 2/2] drm/vkms: queue the composer work under the output lock
From: Oarora Etimis
Date: Thu Nov 19 2026 - 09:56:21 EST
vkms_crtc_handle_vblank_timeout() reads output->composer_state under
output->lock, then drops the lock and queues a work item that lives inside
that state. The commit that retires the state frees it after flush_work(),
which does not wait for a work item that has not been queued yet, so the
queue can land on freed memory. A legacy cursor update and a CRTC disable
both complete flip_done without waiting for a vblank, which is what makes
the window reachable.
Hold the lock across the frame accounting - including
drm_crtc_accurate_vblank_count() - and the queue, so the state that was
read is still the state that gets queued.
Fixes: 88ad7f3a5660 ("drm/vkms: Reduce critical section in vblank_simulate")
Signed-off-by: Oarora Etimis <oaroraetimis@xxxxxxxxx>
---
drivers/gpu/drm/vkms/vkms_crtc.c | 5 ++---
drivers/gpu/drm/vkms/vkms_drv.h | 3 +--
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 4e15abfd92a0..d2c6ffbad07c 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -27,9 +27,7 @@ static bool vkms_crtc_handle_vblank_timeout(struct drm_crtc *crtc)
DRM_ERROR("vkms failure on handling vblank");
state = output->composer_state;
- spin_unlock(&output->lock);
-
- if (state && READ_ONCE(output->composer_users)) {
+ if (state && output->composer_users) {
u64 frame = drm_crtc_accurate_vblank_count(crtc);
/* update frame_start only if a queued vkms_composer_worker()
@@ -49,6 +47,7 @@ static bool vkms_crtc_handle_vblank_timeout(struct drm_crtc *crtc)
if (!ret)
DRM_DEBUG_DRIVER("Composer worker already queued\n");
}
+ spin_unlock(&output->lock);
dma_fence_end_signalling(fence_cookie);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 4f9f1614281a..290eeb988498 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -213,8 +213,7 @@ struct vkms_crtc_state {
* @composer_workq: Ordered workqueue for @composer_state.composer_work.
* @lock: Lock used to protect concurrent access to the composer
* @composer_users: Number of users that currently hold a composer reference; the composer
- * is active only while it is non-zero. Updated under @lock and read with
- * READ_ONCE() from the vblank timeout.
+ * is active only while it is non-zero. Updated and read under @lock.
* @composer_state: Protected by @lock, current state of this VKMS output
* @composer_lock: Lock used internally to protect @composer_state members
*/
--
2.56.1