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 v2 1/2] drm/vkms: count the composer users
Date: Thu, 19 Nov 2026 13:09:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-223149@kernel.org> (raw)
In-Reply-To: <20261119-composer-v2-1-a935e9bae6be@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/vkms: race on *held in vkms_composer_get() and
  vkms_composer_put()
--

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

drm/vkms: count the composer users

This commit replaces the single composer_enabled boolean with a reference
count of active composer users and per-user hold flags so CRC capture and
writeback jobs do not disable the composer for each other.

> diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
> index 0fc915a954bad..24b8436eaa74d 100644
> --- a/drivers/gpu/drm/vkms/vkms_composer.c
> +++ b/drivers/gpu/drm/vkms/vkms_composer.c
> @@ -711,19 +711,39 @@ 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)
> +void vkms_composer_get(struct vkms_output *out, bool *held)
>  {
> -	bool old_enabled;
> +	unsigned int users;
>  
> -	if (enabled)
> -		drm_crtc_vblank_get(&out->crtc);
> +	if (*held)
> +		return;
> +
> +	if (drm_crtc_vblank_get(&out->crtc))
> +		return;
> +
> +	spin_lock_irq(&out->lock);
> +	*held = true;
> +	users = out->composer_users++;
> +	spin_unlock_irq(&out->lock);
> +
> +	/* All users share a single vblank reference. */
> +	if (users)
> +		drm_crtc_vblank_put(&out->crtc);
> +}
> +
> +void vkms_composer_put(struct vkms_output *out, bool *held)
> +{
> +	unsigned int users;
> +
> +	if (!*held)
> +		return;
>  
>  	spin_lock_irq(&out->lock);
> -	old_enabled = out->composer_enabled;
> -	out->composer_enabled = enabled;
> +	*held = false;
> +	users = --out->composer_users;
>  	spin_unlock_irq(&out->lock);
>  
> -	if (old_enabled)
> +	if (!users)
>  		drm_crtc_vblank_put(&out->crtc);
>  }

[Severity: Medium]
Can concurrent calls to vkms_composer_get() and vkms_composer_put() race on
*held because it is checked outside out->lock and not re-checked after taking
the lock?

In drivers/gpu/drm/drm_debugfs_crc.c, crtc_crc_release() clears crc->opened
and drops crc->lock before calling crtc->funcs->set_crc_source(crtc, NULL),
while crtc_crc_open() sets crc->opened and drops crc->lock before calling
crtc->funcs->set_crc_source(crtc, crc->source).  Two tasks opening and
closing the CRC debugfs file can therefore call vkms_set_crc_source()
concurrently with &out->composer_crc_hold:

CPU0                                  CPU1
crtc_crc_release()
  crc->opened = false
  vkms_set_crc_source(..., NULL)
    vkms_composer_put()
      if (!*held) [false]
                                      crtc_crc_open()
                                        vkms_set_crc_source(..., "auto")
                                          vkms_composer_get()
                                            if (*held)
                                              return;  <-- skips get
      spin_lock_irq(&out->lock)
      *held = false
      users = --out->composer_users
      spin_unlock_irq(&out->lock)
      drm_crtc_vblank_put(&out->crtc)

This leaves the newly opened CRC reader active with composer_users == 0 and
vblanks disabled.  Two concurrent puts or gets can likewise both pass the
unlocked check and double-decrement or double-increment out->composer_users,
underflowing the counter or leaking a composer and vblank reference.

Re-checking *held under out->lock (and dropping the vblank reference in
vkms_composer_get() if *held became true in the meantime) would avoid the
race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-composer-v2-0-a935e9bae6be@gmail.com?part=1

  reply	other threads:[~2026-11-19 13:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:55 [PATCH v2 0/2] drm/vkms: give every composer user its own switch Oarora Etimis
2026-11-19 12:55 ` [PATCH v2 1/2] drm/vkms: count the composer users Oarora Etimis
2026-11-19 13:09   ` sashiko-bot [this message]
2026-11-19 12:55 ` [PATCH v2 2/2] drm/vkms: queue the composer work under the output lock 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-223149@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.