From: Oarora Etimis <oaroraetimis@gmail.com>
To: Aditya Tipre <tipreaditya@gmail.com>, louis.chauvet@bootlin.com
Cc: dri-devel@lists.freedesktop.org, hamohammed.sa@gmail.com,
simona@ffwll.ch, melissa.srw@gmail.com, corbet@lwn.net,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] drm/vkms: Keep composition enabled for concurrent users
Date: Sun, 29 Nov 2026 21:00:44 +0100 [thread overview]
Message-ID: <9cd4ada9-00e1-4032-84a4-7ccd12b54f35@gmail.com> (raw)
In-Reply-To: <20261129184141.14809-1-tipreaditya@gmail.com>
Hello,
On 11/29/26 7:41 PM, Aditya Tipre wrote:
> From: atipre <tipreaditya@gmail.com>
>
> CRC capture and writeback share composer_enabled. Cleaning up a writeback
> clears this flag even when CRC capture is still active. The composer then
> stops producing CRC samples while the CRC data file remains open. Cleanup
> of a prepared but uncommitted writeback can also disable composition for
> another user.
>
> Replace the shared boolean with a user count protected by the output lock.
> Hold one vblank reference for the combined lifetime of all composer users,
> refunding redundant references when concurrent first users race. Track
> whether each writeback job acquired a composer reference so its cleanup
> only releases a reference it owns. Propagate CRC acquisition errors and
> signal a failed writeback's own fence before cleaning up the unqueued job.
> Read the user count under the output lock in the vblank callback and remove
> the resolved documentation TODO.
>
> A local IGT kms_writeback@writeback-preserves-crc regression times out
> reading CRCs on the unmodified kernel and passes with this change on ARM64
> QEMU with one and two CPUs. All four existing applicable writeback subtests
> also pass; two unsupported XRGB2101010 subtests skip on both kernels.
>
> Fixes: dbd9d80c1b2e ("drm/vkms: Add support for writeback")
> Signed-off-by: atipre <tipreaditya@gmail.com>
> ---
> Resending the October 25 submission; no changes to the code or commit
> message.
>
> Retested on November 29 against mainline
> ca20d5a011d35fc25e328fe31ac47f7aae557c5a (7.4-rc4), using the
> posted IGT v4 series based on c9e2cc3119d9. Fresh baseline and patched
> ARM64 kernels used the same configuration, with lockdep and atomic-sleep
> checks enabled. With one and two CPUs in QEMU/HVF:
> - The standalone regression times out reading CRCs on baseline and passes
> with the fix.
> - The full writeback suite reproduces the same distinction; all four
> existing applicable subtests pass on both kernels. The two unsupported
> XRGB2101010 subtests skip on both.
> - No kernel WARN, Oops, panic, or hung-task diagnostics were detected.
>
> Both normal kernel builds and a focused W=1 VKMS build pass without
> compiler warnings. An initial full-tree W=1 attempt stopped on existing
> ARM64 syscall-table override-init diagnostics before applying the patch.
>
> Original submission:
> https://lore.kernel.org/dri-devel/20261025194727.89093-1-tipreaditya@gmail.com/
>
> The accompanying IGT regression is now available as v4:
> https://lore.kernel.org/dri-devel/20261129180700.89278-1-tipreaditya@gmail.com/
>
> There is also an overlapping composer-user series:
> https://lore.kernel.org/dri-devel/20261119-composer-v4-0-5973fc9296ee@gmail.com/
> Please advise which implementation should move forward and how best to
> coordinate.
>
> Documentation/gpu/vkms.rst | 5 ---
> drivers/gpu/drm/vkms/vkms_composer.c | 47 ++++++++++++++++++++++-----
> drivers/gpu/drm/vkms/vkms_crtc.c | 5 +--
> drivers/gpu/drm/vkms/vkms_drv.h | 9 ++---
> drivers/gpu/drm/vkms/vkms_writeback.c | 21 ++++++++++--
> 5 files changed, 64 insertions(+), 23 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..5860e86e66b6 100644
> --- a/drivers/gpu/drm/vkms/vkms_composer.c
> +++ b/drivers/gpu/drm/vkms/vkms_composer.c
> @@ -711,19 +711,44 @@ 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;
> + bool already_enabled;
> + int ret;
>
> - if (enabled)
> - drm_crtc_vblank_get(&out->crtc);
> + spin_lock_irq(&out->lock);
> + if (out->composer_users) {
> + out->composer_users++;
> + spin_unlock_irq(&out->lock);
> + return 0;
> + }
> + spin_unlock_irq(&out->lock);
> +
> + ret = drm_crtc_vblank_get(&out->crtc);
> + if (ret)
> + return ret;
>
> spin_lock_irq(&out->lock);
> - old_enabled = out->composer_enabled;
> - out->composer_enabled = enabled;
> + already_enabled = out->composer_users != 0;
> + out->composer_users++;
> spin_unlock_irq(&out->lock);
>
> - if (old_enabled)
> + /* Another user may have enabled composition while we got vblank. */
> + if (already_enabled)
> + drm_crtc_vblank_put(&out->crtc);
> +
> + return 0;
> +}
> +
> +void vkms_composer_put(struct vkms_output *out)
> +{
> + bool last_user;
> +
> + spin_lock_irq(&out->lock);
> + last_user = --out->composer_users == 0;
> + spin_unlock_irq(&out->lock);
> +
> + if (last_user)
> drm_crtc_vblank_put(&out->crtc);
> }
>
> @@ -734,8 +759,12 @@ 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..69ec6b14a864 100644
> --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> @@ -17,7 +17,7 @@ static bool vkms_crtc_handle_vblank_timeout(struct drm_crtc *crtc)
> {
> struct vkms_output *output = drm_crtc_to_vkms_output(crtc);
> struct vkms_crtc_state *state;
> - bool ret, fence_cookie;
> + bool ret, fence_cookie, composer_enabled;
>
> fence_cookie = dma_fence_begin_signalling();
>
> @@ -27,9 +27,10 @@ static bool vkms_crtc_handle_vblank_timeout(struct drm_crtc *crtc)
> DRM_ERROR("vkms failure on handling vblank");
>
> state = output->composer_state;
> + composer_enabled = output->composer_users != 0;
> spin_unlock(&output->lock);
>
> - if (state && output->composer_enabled) {
> + if (state && composer_enabled) {
> 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 381483aa4fb0..4919d8036668 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.h
> +++ b/drivers/gpu/drm/vkms/vkms_drv.h
> @@ -89,6 +89,7 @@ struct vkms_writeback_job {
> struct iosys_map data[DRM_FORMAT_MAX_PLANES];
> struct vkms_frame_info wb_frame_info;
> pixel_write_t pixel_write;
> + bool composer_ref;
> };
>
> /**
> @@ -210,8 +211,7 @@ 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: Protected by @lock, number of CRC capture and writeback users
> * @composer_state: Protected by @lock, current state of this VKMS output
> * @composer_lock: Lock used internally to protect @composer_state members
> */
> @@ -222,7 +222,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 +317,8 @@ 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);
> +int vkms_composer_get(struct vkms_output *out);
> +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 ecf29a2c0c8e..584a71862aaf 100644
> --- a/drivers/gpu/drm/vkms/vkms_writeback.c
> +++ b/drivers/gpu/drm/vkms/vkms_writeback.c
> @@ -1,5 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0+
>
> +#include <linux/dma-fence.h>
> #include <linux/iosys-map.h>
>
> #include <drm/drm_atomic.h>
> @@ -118,7 +119,9 @@ 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);
> + /* Prepared jobs can be cleaned up without ever being committed. */
> + if (vkmsjob->composer_ref)
> + vkms_composer_put(vkms_output);
> kfree(vkmsjob);
> }
>
> @@ -137,13 +140,25 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
> struct vkms_writeback_job *active_wb;
> struct vkms_frame_info *wb_frame_info;
> u32 wb_format = fb->format->format;
> + int ret;
>
> if (!conn_state)
> return;
>
> - vkms_set_composer(output, true);
> -
> active_wb = conn_state->writeback_job->priv;
> + ret = vkms_composer_get(output);
> + if (ret) {
> + struct drm_writeback_job *job = conn_state->writeback_job;
> +
> + conn_state->writeback_job = NULL;
> + if (job->out_fence) {
> + dma_fence_set_error(job->out_fence, ret);
> + dma_fence_signal(job->out_fence);
> + }
> + drm_writeback_cleanup_job(job);
> + return;
> + }
> + active_wb->composer_ref = true;
> wb_frame_info = &active_wb->wb_frame_info;
>
> spin_lock_irq(&output->composer_lock);
vkms_wb_atomic_commit() is a void hook with no failure channel.
drm_crtc_vblank_get() can fail only if vblank is unsupported, the pipe
index is invalid, vblank is off while its refcount is non-zero, or the
CRTC's enable_vblank callback fails. VKMS initializes vblank at probe,
passes the CRTC's own index, wires enable_vblank to
drm_crtc_vblank_helper_enable_vblank_timer (which always returns 0), and
drm_atomic_connector_check() rejects a writeback job on an inactive
CRTC; none of those conditions is reachable in vkms_wb_atomic_commit().
vkms_composer_get() therefore always succeeds at that call site, and the
dma_fence_set_error()/signal()/cleanup path is unreachable there.
prev parent reply other threads:[~2026-11-29 20:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 19:47 [PATCH] drm/vkms: Keep composition enabled for concurrent users atipre
2026-11-29 18:41 ` [PATCH RESEND] " Aditya Tipre
2026-11-29 20:00 ` Oarora Etimis [this message]
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=9cd4ada9-00e1-4032-84a4-7ccd12b54f35@gmail.com \
--to=oaroraetimis@gmail.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=louis.chauvet@bootlin.com \
--cc=melissa.srw@gmail.com \
--cc=simona@ffwll.ch \
--cc=tipreaditya@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