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 <[email protected]> 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/[email protected]?part=1
