[PATCH v4 8/9] drm/meson: publish pending OSD updates with the flip event
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Fri Dec 4 00:41:56 PST 2026
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/meson: meson_crtc_irq() drops event_lock and event before
VD1 flush
- [Medium] drm/meson: TOCTOU check on vsync_disabled in meson_crtc_irq()
drops event
--
commit 65ec299b4ffcf639c6c3baf341647b074e7a0c1f
Author: Guillaume La Roque <glaroque at baylibre.com>
drm/meson: publish pending OSD updates with the flip event
This commit moves flip event capture from atomic_begin into atomic_flush
so pending OSD1 updates and the flip event are published together under
event_lock, and snapshots the event in meson_crtc_irq() while consuming
the OSD1 register cache.
> diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
> index 70acb034b8125..6fefae5387668 100644
> --- a/drivers/gpu/drm/meson/meson_crtc.c
> +++ b/drivers/gpu/drm/meson/meson_crtc.c
[ ... ]
> @@ -400,8 +390,13 @@ void meson_crtc_irq(struct meson_drm *priv)
> priv->afbcd.ops->enable(priv);
> meson_crtc->vsync_forced = true;
> }
> + }
> + priv->viu.osd[0].commit = false;
>
> - priv->viu.osd[0].commit = false;
> + /* Complete only the event associated with the updates just applied. */
> + if (!meson_crtc->vsync_disabled) {
> + event = meson_crtc->event;
> + meson_crtc->event = NULL;
> }
>
> spin_unlock_irqrestore(&priv->drm->event_lock, flags);
[Severity: Medium]
Can dropping event_lock here split an atomic commit across two vblanks
when VD1 is active?
CPU0 (meson_crtc_irq) CPU1 (meson_crtc_atomic_flush)
lock(event_lock)
osd[0].commit == false
event = NULL
unlock(event_lock)
lock(event_lock)
osd[0].commit = true
vd1_commit = true
meson_crtc->event = E1
unlock(event_lock)
if (vd1_enabled && vd1_commit)
program VD1 registers <-- VD1 applied on vblank N without OSD1 or E1
vd1_commit = false
Because meson_crtc_irq() now snapshots meson_crtc->event and drops
event_lock before checking priv->viu.vd1_commit, a concurrent atomic
commit can have its VD1 update programmed on vblank N while its OSD1
update and flip event wait for vblank N+1. For a VD1-only commit, the
flip completion event and vblank timestamp are reported one frame late.
[ ... ]
> @@ -681,10 +676,9 @@ void meson_crtc_irq(struct meson_drm *priv)
> drm_crtc_handle_vblank(priv->crtc);
>
> spin_lock_irqsave(&priv->drm->event_lock, flags);
> - if (meson_crtc->event) {
> - drm_crtc_send_vblank_event(priv->crtc, meson_crtc->event);
> + if (event) {
> + drm_crtc_send_vblank_event(priv->crtc, event);
> drm_crtc_vblank_put(priv->crtc);
> - meson_crtc->event = NULL;
> }
> spin_unlock_irqrestore(&priv->drm->event_lock, flags);
> }
[Severity: Medium]
Can the second meson_crtc->vsync_disabled check right above
drm_crtc_handle_vblank() drop a detached event and leak the vblank
refcount?
CPU0 (meson_crtc_irq) CPU1 (meson_crtc_atomic_disable)
lock(event_lock)
if (!vsync_disabled)
event = meson_crtc->event
meson_crtc->event = NULL
unlock(event_lock)
drm_crtc_vblank_off()
meson_crtc_disable_vblank()
vsync_disabled = true
if (vsync_disabled)
return; <-- event and vblank refcount leaked
After a drm_crtc_commit_wait() timeout,
drm_atomic_helper_wait_for_dependencies() proceeds into atomic_disable
without synchronizing against priv->vsync_irq, so drm_crtc_vblank_off()
can set vsync_disabled concurrently with meson_crtc_irq(). Returning
early after detaching event leaks the drm_pending_vblank_event, leaves
commit->flip_done unsignaled, and skips drm_crtc_vblank_put().
Separately, meson_crtc->vsync_disabled is read under event_lock and
unlocked in meson_crtc_irq(), while meson_crtc_enable_vblank() and
meson_crtc_disable_vblank() write it under vbl_lock and
vblank_time_lock without event_lock, creating a data race during idle
vblank disable.
Sampling vsync_disabled once with READ_ONCE()/WRITE_ONCE(), or
completing a non-NULL detached event before returning, would avoid both
issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-meson-g12a-osd2-v4-0-ad356340dbd6@baylibre.com?part=8
More information about the linux-amlogic
mailing list