* [PATCH v4 0/2] drm/vkms: give every composer user its own switch
@ 2026-11-19 14:49 Oarora Etimis
2026-11-19 14:49 ` [PATCH v4 1/2] drm/vkms: count the composer users Oarora Etimis
2026-11-19 14:49 ` [PATCH v4 2/2] drm/vkms: queue the composer work under the output lock Oarora Etimis
0 siblings, 2 replies; 3+ messages in thread
From: Oarora Etimis @ 2026-11-19 14:49 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Oarora Etimis, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Liviu Dudau, Rodrigo Siqueira
Cc: dri-devel, linux-doc, linux-kernel
The composer has one switch, shared by the CRC reader and the writeback
jobs, so either of them turns it off for the other.
Split it: vkms_output keeps a count of holders, and a get() raises it while a
put() lowers it, so the vblank reference is taken by the first holder and
dropped by the last. The CRC source takes and drops one per open()/release(),
which the core always pairs; each writeback job keeps its own record.
Patch 2 keeps the lock over the frame accounting and the queue, so the state
the timer read is still the state it queues.
---
Changes in v4:
- vkms_composer_get() returns the error from drm_crtc_vblank_get() instead of
a bool, and vkms_set_crc_source() returns it, so a failed take no longer
looks like a successful open followed by a put() with no matching get().
- vkms_crc_parse_source() failing now returns before the composer reference is
touched, instead of falling through to vkms_composer_put().
- the kerneldoc of @composer_users no longer claims a READ_ONCE() that patch 2
removes.
Link to v3: https://patch.msgid.link/20261119-composer-v3-0-dd470a820303@gmail.com
Link to v2: https://patch.msgid.link/20261119-composer-v2-0-a935e9bae6be@gmail.com
Link to v1: https://patch.msgid.link/20261111-composer-v1-1-9d5fa94656f8@gmail.com
---
Oarora Etimis (2):
drm/vkms: count the composer users
drm/vkms: queue the composer work under the output lock
Documentation/gpu/vkms.rst | 5 -----
drivers/gpu/drm/vkms/vkms_composer.c | 39 +++++++++++++++++++++++++++--------
drivers/gpu/drm/vkms/vkms_crtc.c | 5 ++---
drivers/gpu/drm/vkms/vkms_drv.h | 29 ++++++++++++++++++++++----
drivers/gpu/drm/vkms/vkms_writeback.c | 7 ++++---
5 files changed, 61 insertions(+), 24 deletions(-)
---
base-commit: 97429bac371273886238bfcf63d78e7405cacb46
change-id: 20261111-composer-cc9620515bcd
Best regards,
--
Oarora Etimis <oaroraetimis@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v4 1/2] drm/vkms: count the composer users
2026-11-19 14:49 [PATCH v4 0/2] drm/vkms: give every composer user its own switch Oarora Etimis
@ 2026-11-19 14:49 ` Oarora Etimis
2026-11-19 14:49 ` [PATCH v4 2/2] drm/vkms: queue the composer work under the output lock Oarora Etimis
1 sibling, 0 replies; 3+ messages in thread
From: Oarora Etimis @ 2026-11-19 14:49 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Oarora Etimis, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Liviu Dudau, Rodrigo Siqueira
Cc: dri-devel, linux-doc, linux-kernel
The composer has one on/off switch, shared by the CRC reader and the
writeback jobs, so either of them can turn it off for the other. Replace
the switch with a count of users:
- the CRC source takes and drops one reference per open()/release(), and
returns the error of a failed take, so that the open fails instead of
leaving a release without a matching get();
- a writeback job keeps whether the take succeeded and only drops a
reference it actually took, because a job can be cleaned up after a
commit that never reached the composer.
vkms_set_composer() becomes vkms_composer_get() and vkms_composer_put().
Fixes: dbd9d80c1b2e ("drm/vkms: Add support for writeback")
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
Documentation/gpu/vkms.rst | 5 -----
drivers/gpu/drm/vkms/vkms_composer.c | 39 +++++++++++++++++++++++++++--------
drivers/gpu/drm/vkms/vkms_crtc.c | 2 +-
drivers/gpu/drm/vkms/vkms_drv.h | 30 +++++++++++++++++++++++----
drivers/gpu/drm/vkms/vkms_writeback.c | 7 ++++---
5 files changed, 61 insertions(+), 22 deletions(-)
diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
index 1e79e62a6bc4..fe7dc8def44a 100644
--- a/Documentation/gpu/vkms.rst
+++ b/Documentation/gpu/vkms.rst
@@ -246,11 +246,6 @@ module through configfs. Use/Test-cases:
Writeback support
-----------------
-- The writeback and CRC capture operations share the use of composer_enabled
- boolean to ensure vblanks. Probably, when these operations work together,
- composer_enabled needs to refcounting the composer state to proper work.
- [Good to get started]
-
- Add support for cloned writeback outputs and related test cases using a
cloned output in the IGT kms_writeback.
diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
index 0fc915a954ba..9ff9e030ad13 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -711,19 +711,35 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *src_name,
return 0;
}
-void vkms_set_composer(struct vkms_output *out, bool enabled)
+int vkms_composer_get(struct vkms_output *out)
{
- bool old_enabled;
+ unsigned int users;
+ int ret;
- if (enabled)
- drm_crtc_vblank_get(&out->crtc);
+ ret = drm_crtc_vblank_get(&out->crtc);
+ if (ret)
+ return ret;
+
+ spin_lock_irq(&out->lock);
+ users = out->composer_users++;
+ spin_unlock_irq(&out->lock);
+
+ /* All users share a single vblank reference. */
+ if (users)
+ drm_crtc_vblank_put(&out->crtc);
+
+ return 0;
+}
+
+void vkms_composer_put(struct vkms_output *out)
+{
+ unsigned int users;
spin_lock_irq(&out->lock);
- old_enabled = out->composer_enabled;
- out->composer_enabled = enabled;
+ users = --out->composer_users;
spin_unlock_irq(&out->lock);
- if (old_enabled)
+ if (!users)
drm_crtc_vblank_put(&out->crtc);
}
@@ -734,8 +750,13 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)
int ret = 0;
ret = vkms_crc_parse_source(src_name, &enabled);
+ if (ret)
+ return ret;
- vkms_set_composer(out, enabled);
+ if (enabled)
+ return vkms_composer_get(out);
- return ret;
+ vkms_composer_put(out);
+
+ return 0;
}
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index fe17f49305a9..4e15abfd92a0 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -29,7 +29,7 @@ static bool vkms_crtc_handle_vblank_timeout(struct drm_crtc *crtc)
state = output->composer_state;
spin_unlock(&output->lock);
- if (state && output->composer_enabled) {
+ if (state && READ_ONCE(output->composer_users)) {
u64 frame = drm_crtc_accurate_vblank_count(crtc);
/* update frame_start only if a queued vkms_composer_worker()
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index dea6cad3f1b9..4f9f1614281a 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -89,6 +89,8 @@ struct vkms_writeback_job {
struct iosys_map data[DRM_FORMAT_MAX_PLANES];
struct vkms_frame_info wb_frame_info;
pixel_write_t pixel_write;
+ /* Whether this job holds a reference to the composer. */
+ bool composer_wb_holds;
};
/**
@@ -210,8 +212,9 @@ struct vkms_crtc_state {
* vblank timestamps
* @composer_workq: Ordered workqueue for @composer_state.composer_work.
* @lock: Lock used to protect concurrent access to the composer
- * @composer_enabled: Protected by @lock, true when the VKMS composer is active (crc needed or
- * writeback)
+ * @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.
* @composer_state: Protected by @lock, current state of this VKMS output
* @composer_lock: Lock used internally to protect @composer_state members
*/
@@ -222,7 +225,7 @@ struct vkms_output {
struct workqueue_struct *composer_workq;
spinlock_t lock;
- bool composer_enabled;
+ unsigned int composer_users;
struct vkms_crtc_state *composer_state;
spinlock_t composer_lock;
@@ -317,7 +320,26 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
/* Composer Support */
void vkms_composer_worker(struct work_struct *work);
-void vkms_set_composer(struct vkms_output *out, bool enabled);
+
+/**
+ * vkms_composer_get() - Take a composer reference
+ * @out: VKMS output
+ *
+ * The composer stays active while at least one reference is held. Users
+ * whose get() and put() calls are not guaranteed to pair have to keep the
+ * return value and only call vkms_composer_put() for a reference they took.
+ *
+ * Returns: 0 on success, or the error from drm_crtc_vblank_get() if no
+ * reference was taken.
+ */
+int vkms_composer_get(struct vkms_output *out);
+
+/**
+ * vkms_composer_put() - Drop a composer reference
+ * @out: VKMS output
+ */
+void vkms_composer_put(struct vkms_output *out);
+
void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y);
/* Writeback */
diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c
index 858df1f89f66..8891e928930e 100644
--- a/drivers/gpu/drm/vkms/vkms_writeback.c
+++ b/drivers/gpu/drm/vkms/vkms_writeback.c
@@ -118,7 +118,8 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
drm_framebuffer_put(vkmsjob->wb_frame_info.fb);
- vkms_set_composer(vkms_output, false);
+ if (vkmsjob->composer_wb_holds)
+ vkms_composer_put(vkms_output);
kfree(vkmsjob);
}
@@ -141,11 +142,11 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
if (!conn_state)
return;
- vkms_set_composer(output, true);
-
active_wb = conn_state->writeback_job->priv;
wb_frame_info = &active_wb->wb_frame_info;
+ active_wb->composer_wb_holds = !vkms_composer_get(output);
+
spin_lock_irq(&output->composer_lock);
crtc_state->active_writeback = active_wb;
crtc_state->wb_pending = true;
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v4 2/2] drm/vkms: queue the composer work under the output lock
2026-11-19 14:49 [PATCH v4 0/2] drm/vkms: give every composer user its own switch Oarora Etimis
2026-11-19 14:49 ` [PATCH v4 1/2] drm/vkms: count the composer users Oarora Etimis
@ 2026-11-19 14:49 ` Oarora Etimis
1 sibling, 0 replies; 3+ messages in thread
From: Oarora Etimis @ 2026-11-19 14:49 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Oarora Etimis, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Liviu Dudau, Rodrigo Siqueira
Cc: dri-devel, linux-doc, linux-kernel
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@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 14:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 14:49 [PATCH v4 0/2] drm/vkms: give every composer user its own switch Oarora Etimis
2026-11-19 14:49 ` [PATCH v4 1/2] drm/vkms: count the composer users Oarora Etimis
2026-11-19 14:49 ` [PATCH v4 2/2] drm/vkms: queue the composer work under the output lock Oarora Etimis
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.