Skip to contentSkip to conversation

drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off

PATCH In review Prike Liang 3 participants 10 messages Nov 19 – Nov 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/5 drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off

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 <[email protected]>
Cc Ville Syrjälä <[email protected]>
Assisted-by Copilot:claude-opus-5.5
---
 drivers/gpu/drm/drm_vblank.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_vblank.c +12 -3
index f90fb2d13e42..54118eb1413c 100644
@@ -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);
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/5 drm/vblank: Add drm_crtc_wait_one_vblank_interruptible()

drm_crtc_wait_one_vblank() waits uninterruptibly and only gives up after one second. That doesn't suit a wait that userspace asks for, such as
FBIO_WAITFORVSYNC: if no vblank interrupt arrives, the task sleeps in D state for the whole second and can't be interrupted, not even by SIGKILL.

Add drm_crtc_wait_one_vblank_interruptible(), a DRM-internal variant of drm_crtc_wait_one_vblank() that a signal can interrupt. It returns -ERESTARTSYS in that case and otherwise behaves like drm_crtc_wait_one_vblank(), which includes ending the wait when vblank is turned off. Move the wait to __drm_crtc_wait_one_vblank(), which implements both functions.

drm_crtc_wait_one_vblank() doesn't change, and drivers keep using it. The new function has no user yet. The next patch uses it in drm_client_modeset_wait_for_vblank().

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

Cc Thomas Zimmermann <[email protected]>
Cc Ville Syrjälä <[email protected]>
Assisted-by Copilot:claude-opus-5.5
---
 drivers/gpu/drm/drm_internal.h |  1 +
 drivers/gpu/drm/drm_vblank.c   | 64 ++++++++++++++++++++++++----------
 2 files changed, 47 insertions(+), 18 deletions(-)
drivers/gpu/drm/drm_internal.h +1 -0
index f893b1e3a596..2be21c20eb78 100644
@@ -115,6 +115,7 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
 int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
 void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
 u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
+int drm_crtc_wait_one_vblank_interruptible(struct drm_crtc *crtc);
 
 /* drm_vblank_work.c */
 static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank)
drivers/gpu/drm/drm_vblank.c +46 -18

90 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v2 2/5
#2 lore raw

Re: [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible()

Quoted 17 lines · Prike Liang

drm_crtc_wait_one_vblank() waits uninterruptibly and only gives up after one second. That doesn't suit a wait that userspace asks for, such as
FBIO_WAITFORVSYNC: if no vblank interrupt arrives, the task sleeps in D state for the whole second and can't be interrupted, not even by SIGKILL.

Add drm_crtc_wait_one_vblank_interruptible(), a DRM-internal variant of drm_crtc_wait_one_vblank() that a signal can interrupt. It returns -ERESTARTSYS in that case and otherwise behaves like drm_crtc_wait_one_vblank(), which includes ending the wait when vblank is turned off. Move the wait to __drm_crtc_wait_one_vblank(), which implements both functions.

drm_crtc_wait_one_vblank() doesn't change, and drivers keep using it. The new function has no user yet. The next patch uses it in drm_client_modeset_wait_for_vblank().

Quoted 7 lines

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

Cc Thomas Zimmermann <[email protected]>
Cc Ville Syrjälä <[email protected]>
Assisted-by Copilot:claude-opus-5.5
Quoted 116 lines
---
 drivers/gpu/drm/drm_internal.h |  1 +
 drivers/gpu/drm/drm_vblank.c   | 64 ++++++++++++++++++++++++----------
 2 files changed, 47 insertions(+), 18 deletions(-)
drivers/gpu/drm/drm_internal.h +1 -0
index f893b1e3a596..2be21c20eb78 100644
@@ -115,6 +115,7 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe);
 int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
 void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
 u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
+int drm_crtc_wait_one_vblank_interruptible(struct drm_crtc *crtc);
 
 /* drm_vblank_work.c */
 static inline void drm_vblank_flush_worker(struct drm_vblank_crtc *vblank)
drivers/gpu/drm/drm_vblank.c +46 -18
index 54118eb1413c..5e247663978a 100644
@@ -1297,22 +1297,12 @@ void drm_crtc_vblank_put(struct drm_crtc *crtc)
 }
 EXPORT_SYMBOL(drm_crtc_vblank_put);
 
-/**
- * drm_crtc_wait_one_vblank - wait for one vblank
- * @crtc: DRM crtc
- *
- * 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. 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.
- */
-int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
+static int __drm_crtc_wait_one_vblank(struct drm_crtc *crtc, bool interruptible)
 {
 	struct drm_device *dev = crtc->dev;
 	int pipe = drm_crtc_index(crtc);
 	struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
+	long timeout = msecs_to_jiffies(1000);
 	int ret;
 	u64 last;
 
@@ -1323,14 +1313,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) ||
-				 !READ_ONCE(vblank->enabled),
-				 msecs_to_jiffies(1000));
+	if (interruptible)
+		timeout = wait_event_interruptible_timeout(vblank->queue,
+							   last != drm_vblank_count(dev, pipe) ||
+							   !READ_ONCE(vblank->enabled),
+							   timeout);
+	else
+		timeout = wait_event_timeout(vblank->queue,
+					     last != drm_vblank_count(dev, pipe) ||
+					     !READ_ONCE(vblank->enabled),
+					     timeout);
 
-	drm_WARN(dev, ret == 0, "vblank wait timed out on crtc %i\n", pipe);
+	drm_WARN(dev, timeout == 0, "vblank wait timed out on crtc %i\n", pipe);
 
-	if (!ret)
+	if (timeout < 0)
+		ret = timeout;
+	else if (!timeout)
 		ret = -ETIMEDOUT;
 	else if (last == drm_vblank_count(dev, pipe))
 		ret = -EINVAL; /* drm_crtc_vblank_off() ended the wait */
@@ -1341,8 +1339,38 @@ int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
 
 	return ret;
 }
+
+/**
+ * drm_crtc_wait_one_vblank - wait for one vblank
+ * @crtc: DRM crtc
+ *
+ * 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. 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.
+ */
+int drm_crtc_wait_one_vblank(struct drm_crtc *crtc)
+{
+	return __drm_crtc_wait_one_vblank(crtc, false);
+}
 EXPORT_SYMBOL(drm_crtc_wait_one_vblank);
 
+/**
+ * drm_crtc_wait_one_vblank_interruptible - wait for one vblank, interruptibly
+ * @crtc: DRM crtc
+ *
+ * Like drm_crtc_wait_one_vblank(), but a signal interrupts the wait.
+ *
+ * Returns: 0 on success, -ERESTARTSYS if a signal interrupted the wait,
+ * negative error on other failures.
+ */
+int drm_crtc_wait_one_vblank_interruptible(struct drm_crtc *crtc)
+{
+	return __drm_crtc_wait_one_vblank(crtc, true);
+}
+
 /**
  * drm_crtc_vblank_off - disable vblank events on a CRTC
  * @crtc: CRTC in question
Signature · 1 line
2.34.1
Signature · 2 lines
Ville Syrjälä
Intel
#3 lore raw

PATCH v2 3/5 drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible

In reply to Prike Liang

FBIO_WAITFORVSYNC calls drm_client_modeset_wait_for_vblank(), which waits with drm_crtc_wait_one_vblank(). That wait is uninterruptible and only gives up after one second. If no vblank interrupt arrives, for example while the driver resets the display hardware, the caller sleeps in D state for the whole second and can't be interrupted, not even by SIGKILL.

DRM_IOCTL_WAIT_VBLANK waits interruptibly, and so do fbdev drivers that implement FBIO_WAITFORVSYNC themselves, such as atyfb and matroxfb.

Use drm_crtc_wait_one_vblank_interruptible() in drm_client_modeset_wait_for_vblank(). Return -ERESTARTSYS when a signal interrupts the wait, so that the ioctl returns to userspace or is restarted. Timeouts and disabled CRTCs are still not reported.

The fbdev damage worker also calls drm_client_modeset_wait_for_vblank(), but it runs in a kernel thread, which doesn't receive signals, so its wait doesn't change.

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

Cc Thomas Zimmermann <[email protected]>
Cc Ville Syrjälä <[email protected]>
Assisted-by Copilot:claude-opus-5.5
---
 drivers/gpu/drm/drm_client_modeset.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_client_modeset.c +6 -4
index 0080a8e9556a..b475b8dbdb17 100644
@@ -1301,10 +1301,11 @@ EXPORT_SYMBOL(drm_client_modeset_dpms);
  *
  * Block the caller until the given CRTC has seen a VBLANK. Do nothing
  * if the CRTC is disabled. If there's another DRM master present, fail
- * with -EBUSY.
+ * with -EBUSY. A signal interrupts the wait.
  *
  * Returns:
- * 0 on success, or negative error code otherwise.
+ * 0 on success, -ERESTARTSYS if a signal interrupted the wait, or
+ * negative error code otherwise.
  */
 int drm_client_modeset_wait_for_vblank(struct drm_client_dev *client, unsigned int crtc_index)
 {
@@ -1328,13 +1329,14 @@ int drm_client_modeset_wait_for_vblank(struct drm_client_dev *client, unsigned i
 	 */
 	ret = drm_crtc_vblank_get(crtc);
 	if (!ret) {
-		drm_crtc_wait_one_vblank(crtc);
+		ret = drm_crtc_wait_one_vblank_interruptible(crtc);
 		drm_crtc_vblank_put(crtc);
 	}
 
 	drm_master_internal_release(dev);
 
-	return 0;
+	/* Only report interruption by a signal, not timeouts. */
+	return ret == -ERESTARTSYS ? ret : 0;
 }
 EXPORT_SYMBOL(drm_client_modeset_wait_for_vblank);
 
Signature · 1 line
2.34.1
Reviewed-by on v2 3/5
#4 lore raw

Re: [PATCH v2 3/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible

Quoted 9 lines · Prike Liang

FBIO_WAITFORVSYNC calls drm_client_modeset_wait_for_vblank(), which waits with drm_crtc_wait_one_vblank(). That wait is uninterruptible and only gives up after one second. If no vblank interrupt arrives, for example while the driver resets the display hardware, the caller sleeps in D state for the whole second and can't be interrupted, not even by SIGKILL.

DRM_IOCTL_WAIT_VBLANK waits interruptibly, and so do fbdev drivers that implement FBIO_WAITFORVSYNC themselves, such as atyfb and matroxfb.

So we have precedent. Good.

Quoted 9 lines

Use drm_crtc_wait_one_vblank_interruptible() in drm_client_modeset_wait_for_vblank(). Return -ERESTARTSYS when a signal interrupts the wait, so that the ioctl returns to userspace or is restarted. Timeouts and disabled CRTCs are still not reported.

The fbdev damage worker also calls drm_client_modeset_wait_for_vblank(), but it runs in a kernel thread, which doesn't receive signals, so its wait doesn't change.

The damage workers recent unilateral use of vblank waits is bugging me. Enabling vblanks has hardware side effects on i915/xe that we probably don't want there. Need to take a look at demidlayering that at some point...

Quoted 8 lines

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

Cc Thomas Zimmermann <[email protected]>
Cc Ville Syrjälä <[email protected]>
Assisted-by Copilot:claude-opus-5.5
Quoted 41 lines
---
 drivers/gpu/drm/drm_client_modeset.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_client_modeset.c +6 -4
index 0080a8e9556a..b475b8dbdb17 100644
@@ -1301,10 +1301,11 @@ EXPORT_SYMBOL(drm_client_modeset_dpms);
  *
  * Block the caller until the given CRTC has seen a VBLANK. Do nothing
  * if the CRTC is disabled. If there's another DRM master present, fail
- * with -EBUSY.
+ * with -EBUSY. A signal interrupts the wait.
  *
  * Returns:
- * 0 on success, or negative error code otherwise.
+ * 0 on success, -ERESTARTSYS if a signal interrupted the wait, or
+ * negative error code otherwise.
  */
 int drm_client_modeset_wait_for_vblank(struct drm_client_dev *client, unsigned int crtc_index)
 {
@@ -1328,13 +1329,14 @@ int drm_client_modeset_wait_for_vblank(struct drm_client_dev *client, unsigned i
 	 */
 	ret = drm_crtc_vblank_get(crtc);
 	if (!ret) {
-		drm_crtc_wait_one_vblank(crtc);
+		ret = drm_crtc_wait_one_vblank_interruptible(crtc);
 		drm_crtc_vblank_put(crtc);
 	}
 
 	drm_master_internal_release(dev);
 
-	return 0;
+	/* Only report interruption by a signal, not timeouts. */
+	return ret == -ERESTARTSYS ? ret : 0;
 }
 EXPORT_SYMBOL(drm_client_modeset_wait_for_vblank);
 
Signature · 1 line
2.34.1
Signature · 2 lines
Ville Syrjälä
Intel
#5 lore raw

PATCH v2 4/5 drm/amd/display: send the flip event right away if vblank is off

In reply to Prike Liang

dm_arm_vblank_event_pre_programming() takes a vblank reference for a page flip or cursor update that carries an event, and the handler that later sends the event drops that reference again. The return value of drm_crtc_vblank_get() is ignored, though. If vblank is off, the event is armed anyway, and the handler that eventually sends it drops a reference that was never taken, which unbalances the vblank refcount.

That can't happen today: DM only turns vblank off for a CRTC that it disables, and a disabled CRTC has no active planes. The next patch also turns vblank off while a GPU reset has the streams stopped, though. Page flips that don't modify the DC state skip amdgpu_dm_commit_streams() and only take dc_lock after this point, so they still get here while the reset holds it.

Send the event right away when no vblank reference can be taken, like drm_crtc_vblank_off() does for queued vblank events. No vblank interrupt could deliver it in that case anyway.

Add a KUnit test for it.

Cc Harry Wentland <[email protected]>
Cc Leo Li <[email protected]>
Assisted-by Copilot:claude-opus-5.5
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 15 ++++++++--
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 29 +++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +13 -2
index 3d2201285888..3bf6b407bfdf 100644
@@ -3824,6 +3824,11 @@ EXPORT_IF_KUNIT(dm_arm_vblank_event);
  * Grab a reference on the vblank counter if a page flip or cursor update is to
  * be programmed. Do this before programming so the HW is not in any
  * idle-optimized state (such as PSR).
+ *
+ * If vblank is off, no vblank interrupt can deliver the event, and the
+ * handlers that send it would drop a reference that was never taken. Send
+ * the event right away instead, like drm_crtc_vblank_off() does for queued
+ * vblank events.
  */
 STATIC_IFN_KUNIT void dm_arm_vblank_event_pre_programming(struct amdgpu_crtc *acrtc,
 							  struct dm_crtc_state *acrtc_state,
@@ -3835,8 +3840,14 @@ STATIC_IFN_KUNIT void dm_arm_vblank_event_pre_programming(struct amdgpu_crtc *ac
 	if (!acrtc->base.state->event || acrtc_state->active_planes == 0)
 		return;
 
-	if (pflip_update || cursor_update)
-		drm_crtc_vblank_get(&acrtc->base);
+	if (!pflip_update && !cursor_update)
+		return;
+
+	if (drm_crtc_vblank_get(&acrtc->base)) {
+		drm_crtc_send_vblank_event(&acrtc->base,
+					   acrtc->base.state->event);
+		acrtc->base.state->event = NULL;
+	}
 }
 EXPORT_IF_KUNIT(dm_arm_vblank_event_pre_programming);
 
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +29 -0
index d400a223f1ad..99f2a6a41970 100644
@@ -1813,6 +1813,34 @@ static void dm_test_arm_vblank_pre_programming_update(struct kunit *test)
 	drm_crtc_vblank_put(&ctx->acrtc->base);
 }
 
+/**
+ * dm_test_arm_vblank_pre_programming_vblank_off - Test the event is sent with vblank off
+ * @test: The KUnit test context
+ *
+ * No vblank interrupt can deliver the event, and the handlers that send it
+ * must not drop a vblank reference that was never taken.
+ */
+static void dm_test_arm_vblank_pre_programming_vblank_off(struct kunit *test)
+{
+	struct dm_test_vblank_ctx *ctx = dm_test_vblank_ctx_alloc(test);
+	struct drm_vblank_crtc *vblank;
+
+	KUNIT_ASSERT_EQ(test, drm_vblank_init(&ctx->adev->ddev, 1), 0);
+	vblank = drm_crtc_vblank_crtc(&ctx->acrtc->base);
+	drm_crtc_vblank_off(&ctx->acrtc->base);
+
+	/* Sending an event that has no file frees it. */
+	ctx->acrtc_state->base.event = kzalloc_obj(*ctx->event, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, ctx->acrtc_state->base.event);
+
+	dm_test_arm_vblank_pre_programming(ctx, true, false);
+
+	KUNIT_EXPECT_NULL(test, ctx->acrtc_state->base.event);
+	/* Only drm_crtc_vblank_off() holds a reference. */
+	KUNIT_EXPECT_EQ(test, atomic_read(&vblank->refcount), 1);
+	kfree(ctx->acrtc_state->base.event);
+}
+
 /**
  * dm_test_arm_vblank_event_no_event - Test a commit without an event is a no-op
  * @test: The KUnit test context
@@ -5481,6 +5509,7 @@ static struct kunit_case amdgpu_dm_tests[] = {
 	KUNIT_CASE(dm_test_arm_vblank_pre_programming_no_event),
 	KUNIT_CASE(dm_test_arm_vblank_pre_programming_no_planes),
 	KUNIT_CASE(dm_test_arm_vblank_pre_programming_update),
+	KUNIT_CASE(dm_test_arm_vblank_pre_programming_vblank_off),
 	/* dm_update_pflip_irq_state */
 	KUNIT_CASE(dm_test_update_pflip_irq_state_dcn),
 	KUNIT_CASE(dm_test_update_pflip_irq_state_dce),
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 5/5 drm/amd/display: turn vblank off in DRM across GPU reset

In reply to Prike Liang

For a GPU reset, dm_suspend() stops all streams with amdgpu_dm_commit_zero_streams() and toggles the OTG interrupts directly, and dm_resume() restores the cached DC state the same way. Neither goes through manage_dm_interrupts(), so DRM is never told that vblank stops: drm_crtc_vblank_get() keeps succeeding while no vblank interrupt can arrive until the streams are back.

Since commit ebc3351cc4a9 ("drm/amdgpu: remove suspend/resume DRM clients during GPU recovery"), the fbdev client keeps running during recovery, and its damage worker rate-limits display updates with drm_client_modeset_wait_for_vblank(). Every display update during the reset then waits for a vblank that never comes, until the wait times out and warns:

amdgpu 0000:03:00.0: [drm] vblank wait timed out on crtc 0

  WARNING: drivers/gpu/drm/drm_vblank.c:1320 at drm_crtc_wait_one_vblank+0x194/0x200
  Workqueue: events drm_fb_helper_damage_work
  Call Trace:
   drm_client_modeset_wait_for_vblank+0x63/0x80
   drm_fb_helper_damage_work+0x89/0x1a0

FBIO_WAITFORVSYNC runs into the same timeout, and DRM_IOCTL_WAIT_VBLANK sleeps until its own 3 second timeout.

Do what a regular CRTC disable does: call drm_crtc_vblank_off() for the CRTCs of the cached DC state before their streams are stopped, and drm_crtc_vblank_on_config() with their existing configuration once the streams and interrupts are restored. drm_crtc_vblank_get() then fails for the duration of the reset, so drm_client_modeset_wait_for_vblank() doesn't wait at all, and DRM_IOCTL_WAIT_VBLANK waiters are woken up. Page flips that get to amdgpu_dm_commit_planes() meanwhile have their event sent right away, see the previous patch.

drm_crtc_vblank_off() also clears the vblank timestamping constants, which a modeset sets again before it turns vblank back on. Recompute them from the CRTC state after the reset as well; otherwise the vblank timestamp query in drm_crtc_vblank_on_config() warns about an uninitialized mode.

A modeset that waits for dc_lock during the reset may be turning one of these CRTCs off. Leave vblank off for a CRTC that is no longer enabled; amdgpu_dm_crtc_set_vblank() would refuse to enable vblank on it anyway.

Neither call can block on the reset: drm_crtc_vblank_off() only takes spinlocks and flushes the DRM vblank worker, which DM doesn't use, and amdgpu_dm_crtc_set_vblank() doesn't queue vblank_control_work during a reset. Unlike suspending the DRM clients, this doesn't make recovery wait for anything that may itself depend on the reset.

Add KUnit tests for the new helper.

Fixes ebc3351cc4a9 ("drm/amdgpu: remove suspend/resume DRM clients during GPU recovery")
Cc Harry Wentland <[email protected]>
Cc Leo Li <[email protected]>
Cc Christian König <[email protected]>
Cc Alex Deucher <[email protected]>
Assisted-by Copilot:claude-opus-5.5
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  52 ++++++++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |   1 +
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 112 ++++++++++++++++++
 3 files changed, 165 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +52 -0
index 3bf6b407bfdf..35bbdbe0ff1d 100644
@@ -1502,6 +1502,56 @@ STATIC_IFN_KUNIT void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev,
 }
 EXPORT_IF_KUNIT(dm_gpureset_toggle_interrupts);
 
+/**
+ * dm_gpureset_toggle_vblank() - Turn DRM vblank off or on around a GPU reset
+ * @adev: amdgpu device
+ * @state: DC state whose streams the reset stops and restores
+ * @enable: false before the streams are stopped, true once they are restored
+ *
+ * The GPU reset path stops and restores the streams through DC directly and
+ * bypasses manage_dm_interrupts(). Turn vblank off in DRM like a CRTC
+ * disable does, so that drm_crtc_vblank_get() fails while no vblank
+ * interrupt can arrive, instead of letting vblank waiters such as the fbdev
+ * damage worker sleep until they time out.
+ */
+STATIC_IFN_KUNIT void dm_gpureset_toggle_vblank(struct amdgpu_device *adev,
+						struct dc_state *state, bool enable)
+{
+	struct drm_vblank_crtc_config config;
+	struct amdgpu_crtc *acrtc;
+	int i;
+
+	for (i = 0; i < state->stream_count; i++) {
+		int otg_inst = state->stream_status[i].primary_otg_inst;
+
+		acrtc = amdgpu_dm_get_crtc_by_otg_inst(adev, otg_inst);
+		if (!acrtc)
+			continue;
+
+		if (!enable) {
+			drm_crtc_vblank_off(&acrtc->base);
+			continue;
+		}
+
+		/*
+		 * A modeset waiting for dc_lock may be turning the CRTC off,
+		 * and amdgpu_dm_crtc_set_vblank() refuses to enable vblank on
+		 * it then. Leave its vblank off.
+		 */
+		if (!acrtc->base.enabled)
+			continue;
+
+		/* drm_crtc_vblank_off() cleared the timestamping constants. */
+		drm_calc_timestamping_constants(&acrtc->base,
+						&acrtc->base.state->adjusted_mode);
+
+		/* Keep the off delay that manage_dm_interrupts() configured. */
+		config = drm_crtc_vblank_crtc(&acrtc->base)->config;
+		drm_crtc_vblank_on_config(&acrtc->base, &config);
+	}
+}
+EXPORT_IF_KUNIT(dm_gpureset_toggle_vblank);
+
 DEFINE_FREE(state_release, struct dc_state *, dc_state_release(_T))
 
 STATIC_IFN_KUNIT enum dc_status amdgpu_dm_commit_zero_streams(struct dc *dc)
@@ -1636,6 +1686,7 @@ static int dm_suspend(struct amdgpu_ip_block *ip_block)
 			return -ENOMEM;
 		}
 
+		dm_gpureset_toggle_vblank(adev, dm->cached_dc_state, false);
 		dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, false);
 
 		res = amdgpu_dm_commit_zero_streams(dm->dc);
@@ -1975,6 +2026,7 @@ static int dm_resume(struct amdgpu_ip_block *ip_block)
 		dm_gpureset_commit_state(dm->cached_dc_state, dm);
 
 		dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, true);
+		dm_gpureset_toggle_vblank(adev, dm->cached_dc_state, true);
 
 		dc_state_release(dm->cached_dc_state);
 		dm->cached_dc_state = NULL;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -0
index c2b6d4abd9c7..75a5c0309998 100644
@@ -1354,6 +1354,7 @@ void mmhub_read_system_context(struct amdgpu_device *adev,
 			       struct dc_phy_addr_space_config *pa_config);
 int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm);
 void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev, struct dc_state *state, bool enable);
+void dm_gpureset_toggle_vblank(struct amdgpu_device *adev, struct dc_state *state, bool enable);
 enum dc_status amdgpu_dm_commit_zero_streams(struct dc *dc);
 int dm_cache_state(struct amdgpu_device *adev);
 void dm_destroy_cached_state(struct amdgpu_device *adev);
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +112 -0

124 lines not on this page · raw message

Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v2 5/5] drm/amd/display: turn vblank off in DRM across GPU reset

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/amd/display: active_vblank_irq_count leak in dm_gpureset_toggle_vblank() - [High]…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] drm/amd/display: active_vblank_irq_count leak in dm_gpureset_toggle_vblank()
- [High] drm/amd/display: race and UAF on acrtc->base.state in dm_gpureset_toggle_vblank()
- [Medium] drm/amd/display: dm_gpureset_toggle_vblank() enables vblank on DPMS-off CRTC
- [Medium] drm/amd/display: missing vblank rollback in dm_suspend() on reset error path
--

commit 55fe8aa3c39160c8faed0a29af7b0acd9dcda97b
Author: Prike Liang <[email protected]>

drm/amd/display: turn vblank off in DRM across GPU reset

This commit adds dm_gpureset_toggle_vblank() to call drm_crtc_vblank_off() before stopping streams in dm_suspend() and drm_crtc_vblank_on_config() after restoring them in dm_resume() during a GPU reset, along with KUnit tests.

Quoted 28 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +20 -0
index 4184d8fda10ea..b39c975e0e33a 100644
@@ -1494,6 +1494,56 @@ STATIC_IFN_KUNIT void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev,
 }
 EXPORT_IF_KUNIT(dm_gpureset_toggle_interrupts);
 
+/**
+ * dm_gpureset_toggle_vblank() - Turn DRM vblank off or on around a GPU reset
+ * @adev: amdgpu device
+ * @state: DC state whose streams the reset stops and restores
+ * @enable: false before the streams are stopped, true once they are restored
+ *
+ * The GPU reset path stops and restores the streams through DC directly and
+ * bypasses manage_dm_interrupts(). Turn vblank off in DRM like a CRTC
+ * disable does, so that drm_crtc_vblank_get() fails while no vblank
+ * interrupt can arrive, instead of letting vblank waiters such as the fbdev
+ * damage worker sleep until they time out.
+ */
+STATIC_IFN_KUNIT void dm_gpureset_toggle_vblank(struct amdgpu_device *adev,
+						struct dc_state *state, bool enable)
+{
+	struct drm_vblank_crtc_config config;
+	struct amdgpu_crtc *acrtc;
+	int i;
+
+	for (i = 0; i < state->stream_count; i++) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c STATIC_IFN_KUNIT void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev, · line 1526

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10 -0
+		int otg_inst = state->stream_status[i].primary_otg_inst;
+
+		acrtc = amdgpu_dm_get_crtc_by_otg_inst(adev, otg_inst);
+		if (!acrtc)
+			continue;
+
+		if (!enable) {
+			drm_crtc_vblank_off(&acrtc->base);
+			continue;
+		}

[Severity: High]
Does turning vblank off during reset leak dm->active_vblank_irq_count and leave acrtc->ism out of idle when vblank was enabled before the reset?

Before the reset starts, enabling vblank queues vblank_control_work with enable = true to amdgpu_dm_crtc_vblank_control_worker(), which increments dm->active_vblank_irq_count and sends DM_ISM_EVENT_EXIT_IDLE_REQUESTED.

When dm_suspend() calls drm_crtc_vblank_off() during reset, drm_vblank_disable_and_save() calls amdgpu_dm_crtc_set_vblank(crtc, false) and sets vblank->enabled = false, but amdgpu_dm_crtc_set_vblank() returns early without queuing vblank_control_work because amdgpu_in_reset(adev) is true. drm_crtc_vblank_off() then wakes any waiters (such as drm_fb_helper_damage_work), which drop their vblank references. When dm_resume() later calls drm_crtc_vblank_on_config(), vblank->refcount is 0 and config.offdelay_ms is non-zero, so vblank->enabled stays false and no matching disable work is ever queued. Because dm_ism_commit_idle_optimization_state() requires dm->active_vblank_irq_count == 0, display idle power optimizations remain blocked after the reset.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c STATIC_IFN_KUNIT void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev, · line 1546

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +12 -0
+
+		/*
+		 * A modeset waiting for dc_lock may be turning the CRTC off,
+		 * and amdgpu_dm_crtc_set_vblank() refuses to enable vblank on
+		 * it then. Leave its vblank off.
+		 */
+		if (!acrtc->base.enabled)
+			continue;
+
+		/* drm_crtc_vblank_off() cleared the timestamping constants. */
+		drm_calc_timestamping_constants(&acrtc->base,
+						&acrtc->base.state->adjusted_mode);

[Severity: High]
Can reading acrtc->base.state->adjusted_mode here race with a concurrent atomic commit and cause a use-after-free?

acrtc->base.state is protected by acrtc->base.mutex, while dm_resume() only holds dm->dc_lock. Since 1a2b3c4d5e6f is not blocking DRM clients during recovery (ebc3351cc4a9 ("drm/amdgpu: remove suspend/resume DRM clients during GPU recovery")), a non-modeset commit on the active CRTC that updates no enabled planes (planes_count == 0 with acrtc_state->active_planes > 0 in amdgpu_dm_commit_planes()) never takes dm->dc_lock:

CPU0 CPU1
drm_atomic_helper_commit()
drm_atomic_helper_swap_state()

    /* swaps acrtc->base.state */
                                      dm_resume()
                                        dm_gpureset_toggle_vblank(..., true)
                                          mode = &acrtc->base.state->adjusted_mode
  commit_tail()
    amdgpu_dm_atomic_commit_tail()
    drm_atomic_commit_put()
      amdgpu_dm_crtc_destroy_state()
        kfree(old_crtc_state)
                                          drm_calc_timestamping_constants(..., mode)
                                            <-- use-after-free

Even for a modeset commit turning the CRTC off that later waits on dm->dc_lock in amdgpu_dm_commit_streams(), drm_atomic_helper_swap_state() installs the disabled new_crtc_state (with adjusted_mode.crtc_clock == 0) before commit_tail() runs drm_atomic_helper_update_legacy_modeset_state() to clear acrtc->base.enabled, so dm_gpureset_toggle_vblank() can still see acrtc->base.enabled == true while reading the zeroed new_crtc_state. Could dm_gpureset_toggle_vblank() derive the timing from the cached dc_stream_state in state->streams[i] instead of dereferencing acrtc->base.state?

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c STATIC_IFN_KUNIT void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev, · line 1553

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7 -0
+
+		/* Keep the off delay that manage_dm_interrupts() configured. */
+		config = drm_crtc_vblank_crtc(&acrtc->base)->config;
+		drm_crtc_vblank_on_config(&acrtc->base, &config);
+	}
+}
+EXPORT_IF_KUNIT(dm_gpureset_toggle_vblank);

[Severity: Medium]
Can a concurrent DPMS-off commit waiting on dm->dc_lock leave DRM vblank enabled on an inactive CRTC?

For a DPMS-off commit (new_crtc_state->enable == true, new_crtc_state->active == false), drm_atomic_helper_update_legacy_modeset_state() keeps acrtc->base.enabled as true. In amdgpu_dm_commit_streams(), the commit first calls manage_dm_interrupts(adev, acrtc, NULL) (turning vblank off) and then blocks on mutex_lock(&dm->dc_lock) to disable the cursor before remove_stream() sets acrtc->otg_inst = -1:

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:amdgpu_dm_commit_streams() {
    ...
		if (old_crtc_state->active &&
		    (!new_crtc_state->active ||
		     drm_atomic_crtc_needs_modeset(new_crtc_state))) {
			manage_dm_interrupts(adev, acrtc, NULL);
			amdgpu_dm_ism_flush(&acrtc->ism);
			dc_stream_release(dm_old_crtc_state->stream);
		}
    ...
		if (old_crtc_state->active && !new_crtc_state->active) {
			struct dc_cursor_position position;

			memset(&position, 0, sizeof(position));
			mutex_lock(&dm->dc_lock);
    ...
}

While the commit is blocked there, acrtc->otg_inst still matches the cached stream and acrtc->base.enabled is true, so dm_gpureset_toggle_vblank() calls drm_crtc_vblank_on_config(). When dm_resume() drops dm->dc_lock, the DPMS-off commit finishes removing the stream without calling manage_dm_interrupts() again, leaving drm_crtc_vblank_get() succeeding on a CRTC with no active stream.

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_suspend(struct amdgpu_ip_block *ip_block) · line 1684

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
@@ -1628,6 +1678,7 @@ static int dm_suspend(struct amdgpu_ip_block *ip_block)
 			return -ENOMEM;
 		}
 
+		dm_gpureset_toggle_vblank(adev, dm->cached_dc_state, false);
 		dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, false);
 
 		res = amdgpu_dm_commit_zero_streams(dm->dc);

[Severity: Medium]
If amdgpu_dm_commit_zero_streams() fails right after this, dm_suspend() frees dm->cached_dc_state and returns -EINVAL without re-enabling vblank (or interrupts). Because amdgpu_ip_block_suspend() leaves ip_block->status.hw set to true on error, amdgpu_device_ip_resume_phase3() skips dm_resume(), leaving DRM vblank permanently off on the active CRTCs. Should dm_gpureset_toggle_vblank() and dm_gpureset_toggle_interrupts() be rolled back on that error path, or called after amdgpu_dm_commit_zero_streams() succeeds?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Reviewed-by on v2 1/5
#8 lore raw
In reply to Prike Liang
Quoted 44 lines · 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 <[email protected]>
Cc Ville Syrjälä <[email protected]>
Assisted-by Copilot:claude-opus-5.5
---
 drivers/gpu/drm/drm_vblank.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_vblank.c +0 -0
index f90fb2d13e42..54118eb1413c 100644

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_vblank_put); · line 1307

Quoted 6 lines
drivers/gpu/drm/drm_vblank.c +2 -1
@@ -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.

The "The wait also fails ..." wording feels a bit vague to me. Maybe something like "The wait terminates early with an error if drm_crtc_vblank_off() ..." ?

If you do decide to change the wording remember to carry it through to the other patches when rebasing them.

Apart from that, this looks pretty good to me

Quoted 30 lines
drivers/gpu/drm/drm_vblank.c +10 -2
  *
  * 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);
 
Signature · 1 line
2.34.1
Signature · 2 lines
Ville Syrjälä
Intel
#9 lore raw

AMD General

Quoted 72 lines

-----Original Message-----
From: Ville Syrjälä <[email protected]>
Sent: Thursday, November 19, 2026 10:31 PM
To: Liang, Prike <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Wentland, Harry <[email protected]>; Li, Sun peng (Leo) <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off

Quoted 48 lines · 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 <[email protected]>
Cc Ville Syrjälä <[email protected]>
Assisted-by Copilot:claude-opus-5.5
---
 drivers/gpu/drm/drm_vblank.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_vblank.c index f90fb2d13e42..54118eb1413c 100644

drivers/gpu/drm/drm_vblank.c EXPORT_SYMBOL(drm_crtc_vblank_put); · line 1308

Quoted 7 lines
drivers/gpu/drm/drm_vblank.c +3 -1
@@ -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.

The "The wait also fails ..." wording feels a bit vague to me. Maybe something like "The wait terminates early with an error if drm_crtc_vblank_off() ..." ?

Quoted 2 lines

If you do decide to change the wording remember to carry it through to the other patches when rebasing them.

Thank you for the detail review, and I will reword the comment log.

Regards,
Prike

Quoted 37 lines

Apart from that, this looks pretty good to me

Quoted 29 lines
drivers/gpu/drm/drm_vblank.c +10 -3
  *
  * 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);
 
--
Quoted 1 line

2.34.1

--
Ville Syrjälä
Intel