All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oarora Etimis" <oaroraetimis@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/4] drm/vkms: use the gamma LUT of the state being composed
Date: Sun, 08 Nov 2026 19:39:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-203984@kernel.org> (raw)
In-Reply-To: <20261108-lut-v1-1-f762d70ae4cd@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] drm/vkms: race condition publishing writeback job in
  vkms_wb_atomic_commit() [1]
--

commit e2d912779c4a80188eb9913ca9ba97afaaba49ac
Author: Oarora Etimis <oaroraetimis@gmail.com>

drm/vkms: use the gamma LUT of the state being composed

This commit reads the gamma LUT from crtc_state->base.gamma_lut rather than
crtc->state->gamma_lut in vkms_composer_worker() and clears the LUT fields
when no LUT is present.

> diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
> index 0fc915a954bad..1d5658bbd493b 100644
> --- a/drivers/gpu/drm/vkms/vkms_composer.c
> +++ b/drivers/gpu/drm/vkms/vkms_composer.c
> @@ -609,6 +609,7 @@ void vkms_composer_worker(struct work_struct *work)
>  							  struct vkms_crtc_state,
>  							  composer_work);
>  	struct drm_crtc *crtc = crtc_state->base.crtc;
> +	struct drm_property_blob *gamma_lut = crtc_state->base.gamma_lut;
>  	struct vkms_writeback_job *active_wb = crtc_state->active_writeback;

[Severity: Critical]
This problem wasn't introduced by this patch, but can vkms_composer_worker()
race with vkms_wb_atomic_commit() on crtc_state->active_writeback [1]?

vkms_composer_worker() reads crtc_state->active_writeback before taking
out->composer_lock to read crtc_state->wb_pending, while
vkms_wb_atomic_commit() publishes both under output->composer_lock before
queuing and initializing the job:

drivers/gpu/drm/vkms/vkms_writeback.c:vkms_wb_atomic_commit() {
    ...
	spin_lock_irq(&output->composer_lock);
	crtc_state->active_writeback = active_wb;
	crtc_state->wb_pending = true;
	spin_unlock_irq(&output->composer_lock);
	drm_writeback_queue_job(wb_conn, connector_state);
	active_wb->pixel_write = get_pixel_write_function(wb_format);
	drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height);
	drm_rect_init(&wb_frame_info->dst, 0, 0, crtc_width, crtc_height);
}

When a writeback commit runs while the vblank timer and composer worker are
already active (for example, with CRC capture enabled), the two contexts can
interleave:

CPU0                                  CPU1 (kworker)
vkms_wb_atomic_commit()               vkms_composer_worker()
  spin_lock_irq(&composer_lock)
  crtc_state->active_writeback = ...
  crtc_state->wb_pending = true
  spin_unlock_irq(&composer_lock)
  drm_writeback_queue_job(...)
                                        active_wb =
                                          crtc_state->active_writeback
                                        spin_lock_irq(&composer_lock)
                                        wb_pending = crtc_state->wb_pending
                                        spin_unlock_irq(&composer_lock)
                                        compose_active_planes(active_wb, ...)
                                        drm_writeback_signal_completion(...)
                                          ...
                                            vkms_wb_cleanup_job()
                                              kfree(active_wb)
  active_wb->pixel_write = ...
    <-- use-after-free

Depending on where the worker interleaves, it can also read a NULL or stale
active_wb before composer_lock is taken, hit WARN_ON(!active_wb->pixel_write)
in check_format_funcs(), or call drm_writeback_signal_completion() before
drm_writeback_queue_job(), which triggers WARN_ON(!job) and clears wb_pending
so the queued job never completes.

Initializing active_wb and calling drm_writeback_queue_job() before
publishing active_writeback and wb_pending under composer_lock, and reading
crtc_state->active_writeback under composer_lock in vkms_composer_worker(),
would avoid these races.

[1] https://sashiko.dev/#/bug/linux-420d0359-9fcb-45d5-af1b-74704c78f447

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261108-lut-v1-0-f762d70ae4cd@gmail.com?part=1

  reply	other threads:[~2026-11-08 19:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08 19:33 [PATCH 0/4] drm/vkms: speed up composition with a precomputed gamma LUT Oarora Etimis
2026-11-08 19:33 ` [PATCH 1/4] drm/vkms: use the gamma LUT of the state being composed Oarora Etimis
2026-11-08 19:39   ` sashiko-bot [this message]
2026-11-08 19:33 ` [PATCH 2/4] drm/vkms: precompute the gamma LUT for every channel value Oarora Etimis
2026-11-08 19:33 ` [PATCH 3/4] drm/vkms: add a KUnit test for the precomputed LUT table Oarora Etimis
2026-11-08 19:33 ` [PATCH 4/4] drm/ci: drop the kms_plane pixel-format xfails for vkms Oarora Etimis

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-203984@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=oaroraetimis@gmail.com \
    --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.