All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off
@ 2026-11-19  8:24 Prike Liang
  2026-11-19  8:24 ` [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible() Prike Liang
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Prike Liang @ 2026-11-19  8:24 UTC (permalink / raw)
  To: amd-gfx, dri-devel
  Cc: Alexander.Deucher, Christian.Koenig, Harry.Wentland, Sunpeng.Li,
	tzimmermann, ville.syrjala, Prike Liang

drm_crtc_vblank_off() turns off the vblank interrupt even while someone
holds a vblank reference and waits for a vblank. It then wakes up the
vblank wait queue. DRM_IOCTL_WAIT_VBLANK stops waiting at this point,
because its wait condition also checks whether vblank is still enabled.

drm_crtc_wait_one_vblank() only checks whether the vblank count has
changed. Once vblank is off, the count doesn't change, so the woken
waiter sleeps again until the wait times out after one second and warns
"vblank wait timed out". This happens, for example, when the fbdev
damage worker or FBIO_WAITFORVSYNC waits for a vblank while the driver
turns the CRTC off for suspend or a GPU reset.

Make drm_crtc_wait_one_vblank() also stop waiting when vblank is turned
off, and return -EINVAL if no vblank passed, the same error that
drm_vblank_get() returns when vblank is off. The wait condition is
checked before going to sleep, so this also covers vblank being turned
off between drm_vblank_get() and the wait. Waits that see a vblank or
time out behave as before.

The two cases differ in that drm_crtc_wait_one_vblank() warns "vblank
not available" if drm_vblank_get() fails, but doesn't warn if
drm_crtc_vblank_off() ends the wait. That is intentional: it's a
failure to call the function while vblank is off, but a waiter, such as
the fbdev damage worker, can't keep the CRTC from being turned off
meanwhile. The error only tells the caller that no more vblanks are
coming.

version update:
1) https://lists.freedesktop.org/archives/dri-devel/2026-November/616745.html

Fixes: e8450f51a4b3 ("drm/irq: Implement a generic vblank_wait function")
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Prike Liang <Prike.Liang@amd.com>
---
 drivers/gpu/drm/drm_vblank.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index f90fb2d13e42..54118eb1413c 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -1303,7 +1303,8 @@ EXPORT_SYMBOL(drm_crtc_vblank_put);
  *
  * This waits for one vblank to pass on @crtc, using the irq driver interfaces.
  * It is a failure to call this when the vblank irq for @crtc is disabled, e.g.
- * due to lack of driver support or because the crtc is off.
+ * due to lack of driver support or because the crtc is off. The wait also fails
+ * if drm_crtc_vblank_off() disables the vblank irq before a vblank passes.
  *
  * Returns: 0 on success, negative error on failures.
  */
@@ -1323,14 +1324,22 @@ int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
 	last = drm_vblank_count(dev, pipe);
 
 	ret = wait_event_timeout(vblank->queue,
-				 last != drm_vblank_count(dev, pipe),
+				 last != drm_vblank_count(dev, pipe) ||
+				 !READ_ONCE(vblank->enabled),
 				 msecs_to_jiffies(1000));
 
 	drm_WARN(dev, ret == 0, "vblank wait timed out on crtc %i\n", pipe);
 
+	if (!ret)
+		ret = -ETIMEDOUT;
+	else if (last == drm_vblank_count(dev, pipe))
+		ret = -EINVAL; /* drm_crtc_vblank_off() ended the wait */
+	else
+		ret = 0;
+
 	drm_vblank_put(dev, pipe);
 
-	return ret ? 0 : -ETIMEDOUT;
+	return ret;
 }
 EXPORT_SYMBOL(drm_crtc_wait_one_vblank);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-20  2:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  8:24 [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Prike Liang
2026-11-19  8:24 ` [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible() Prike Liang
2026-11-19 14:33   ` Ville Syrjälä
2026-11-19  8:24 ` [PATCH v2 3/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible Prike Liang
2026-11-19 14:40   ` Ville Syrjälä
2026-11-19  8:24 ` [PATCH v2 4/5] drm/amd/display: send the flip event right away if vblank is off Prike Liang
2026-11-19  8:24 ` [PATCH v2 5/5] drm/amd/display: turn vblank off in DRM across GPU reset Prike Liang
2026-11-19  8:56   ` sashiko-bot
2026-11-19 14:31 ` [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Ville Syrjälä
2026-11-20  2:23   ` Liang, Prike

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.