* [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible()
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 ` 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
` (3 subsequent siblings)
4 siblings, 1 reply; 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_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 <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_internal.h | 1 +
drivers/gpu/drm/drm_vblank.c | 64 ++++++++++++++++++++++++----------
2 files changed, 47 insertions(+), 18 deletions(-)
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index f893b1e3a596..2be21c20eb78 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -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)
diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 54118eb1413c..5e247663978a 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -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
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/5] drm/vblank: Add drm_crtc_wait_one_vblank_interruptible()
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ä
0 siblings, 0 replies; 10+ messages in thread
From: Ville Syrjälä @ 2026-11-19 14:33 UTC (permalink / raw)
To: Prike Liang
Cc: amd-gfx, dri-devel, Alexander.Deucher, Christian.Koenig,
Harry.Wentland, Sunpeng.Li, tzimmermann
On Thu, Nov 19, 2026 at 04:24:21PM +0800, Prike Liang wrote:
> 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 <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>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
> drivers/gpu/drm/drm_internal.h | 1 +
> drivers/gpu/drm/drm_vblank.c | 64 ++++++++++++++++++++++++----------
> 2 files changed, 47 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
> index f893b1e3a596..2be21c20eb78 100644
> --- a/drivers/gpu/drm/drm_internal.h
> +++ b/drivers/gpu/drm/drm_internal.h
> @@ -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)
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 54118eb1413c..5e247663978a 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -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
> --
> 2.34.1
--
Ville Syrjälä
Intel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible
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 8:24 ` 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
` (2 subsequent siblings)
4 siblings, 1 reply; 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
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 <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_client_modeset.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_client_modeset.c b/drivers/gpu/drm/drm_client_modeset.c
index 0080a8e9556a..b475b8dbdb17 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 3/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible
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ä
0 siblings, 0 replies; 10+ messages in thread
From: Ville Syrjälä @ 2026-11-19 14:40 UTC (permalink / raw)
To: Prike Liang
Cc: amd-gfx, dri-devel, Alexander.Deucher, Christian.Koenig,
Harry.Wentland, Sunpeng.Li, tzimmermann
On Thu, Nov 19, 2026 at 04:24:22PM +0800, Prike Liang wrote:
> 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.
>
> 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...
>
> Version update:
> 1) https://lists.freedesktop.org/archives/dri-devel/2026-November/616727.html
>
> 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>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
> drivers/gpu/drm/drm_client_modeset.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_client_modeset.c b/drivers/gpu/drm/drm_client_modeset.c
> index 0080a8e9556a..b475b8dbdb17 100644
> --- a/drivers/gpu/drm/drm_client_modeset.c
> +++ b/drivers/gpu/drm/drm_client_modeset.c
> @@ -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);
>
> --
> 2.34.1
--
Ville Syrjälä
Intel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 4/5] drm/amd/display: send the flip event right away if vblank is off
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 8:24 ` [PATCH v2 3/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible Prike Liang
@ 2026-11-19 8:24 ` 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 14:31 ` [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Ville Syrjälä
4 siblings, 0 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, Harry Wentland, Leo Li
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 <harry.wentland@amd.com>
Cc: Leo Li <sunpeng.li@amd.com>
Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Prike Liang <Prike.Liang@amd.com>
---
.../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(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 3d2201285888..3bf6b407bfdf 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
index d400a223f1ad..99f2a6a41970 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
@@ -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),
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 5/5] drm/amd/display: turn vblank off in DRM across GPU reset
2026-11-19 8:24 [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Prike Liang
` (2 preceding siblings ...)
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 ` 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ä
4 siblings, 1 reply; 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, Harry Wentland, Leo Li,
Christian König, Alex Deucher
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 <harry.wentland@amd.com>
Cc: Leo Li <sunpeng.li@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Prike Liang <Prike.Liang@amd.com>
---
.../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(+)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 3bf6b407bfdf..35bbdbe0ff1d 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -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;
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
index c2b6d4abd9c7..75a5c0309998 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
@@ -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);
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
index 99f2a6a41970..2cfdd3a77521 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
@@ -5415,6 +5415,113 @@ static void dm_test_gpureset_toggle_interrupts_dcn(struct kunit *test)
dm_gpureset_toggle_interrupts(adev, state, true);
}
+/* Tests for dm_gpureset_toggle_vblank() */
+
+/*
+ * One stream on the OTG of the CRTC from dm_test_irq_mgmt_ctx_alloc(), which
+ * is enabled with a 1080p60 mode and has its vblank set up like on a regular
+ * CRTC enable: timestamping constants first, then manage_dm_interrupts().
+ */
+static struct dc_state *dm_test_gpureset_vblank_state(struct kunit *test,
+ struct dm_test_irq_mgmt_ctx *ctx)
+{
+ struct drm_display_mode *mode = &ctx->acrtc_state->base.adjusted_mode;
+ struct dc_state *state = dm_kunit_alloc_dc_state(test);
+
+ mode->crtc_clock = 148500;
+ mode->crtc_htotal = 2200;
+ mode->crtc_vtotal = 1125;
+ ctx->acrtc->base.state = &ctx->acrtc_state->base;
+ ctx->acrtc->base.enabled = true;
+ drm_calc_timestamping_constants(&ctx->acrtc->base, mode);
+ ctx->adev->ip_versions[DCE_HWIP][0] = IP_VERSION(3, 1, 2);
+ manage_dm_interrupts(ctx->adev, ctx->acrtc, ctx->acrtc_state);
+
+ state->stream_count = 1;
+ state->stream_status[0].primary_otg_inst = ctx->acrtc->otg_inst;
+
+ return state;
+}
+
+/**
+ * dm_test_gpureset_toggle_vblank_off - Test vblank is off while streams are down
+ * @test: The KUnit test context
+ *
+ * drm_crtc_vblank_get() has to fail, or vblank waiters such as the fbdev
+ * damage worker sleep until they time out.
+ */
+static void dm_test_gpureset_toggle_vblank_off(struct kunit *test)
+{
+ struct dm_test_irq_mgmt_ctx *ctx = dm_test_irq_mgmt_ctx_alloc(test);
+ struct dc_state *state = dm_test_gpureset_vblank_state(test, ctx);
+ struct drm_crtc *crtc = &ctx->acrtc->base;
+
+ KUNIT_ASSERT_EQ(test, drm_crtc_vblank_get(crtc), 0);
+ drm_crtc_vblank_put(crtc);
+
+ dm_gpureset_toggle_vblank(ctx->adev, state, false);
+
+ KUNIT_EXPECT_FALSE(test, ctx->adev->ddev.vblank[0].enabled);
+ KUNIT_EXPECT_EQ(test, drm_crtc_vblank_get(crtc), -EINVAL);
+}
+
+/**
+ * dm_test_gpureset_toggle_vblank_on - Test vblank comes back with its config and mode
+ * @test: The KUnit test context
+ */
+static void dm_test_gpureset_toggle_vblank_on(struct kunit *test)
+{
+ struct dm_test_irq_mgmt_ctx *ctx = dm_test_irq_mgmt_ctx_alloc(test);
+ struct dc_state *state = dm_test_gpureset_vblank_state(test, ctx);
+ struct drm_crtc *crtc = &ctx->acrtc->base;
+
+ dm_gpureset_toggle_vblank(ctx->adev, state, false);
+ dm_gpureset_toggle_vblank(ctx->adev, state, true);
+
+ /* manage_dm_interrupts() derived this off delay from the timing. */
+ KUNIT_EXPECT_EQ(test, ctx->adev->ddev.vblank[0].config.offdelay_ms, 34);
+ /* Vblank timestamps need the mode that drm_crtc_vblank_off() cleared. */
+ KUNIT_EXPECT_EQ(test, ctx->adev->ddev.vblank[0].hwmode.crtc_clock, 148500);
+ KUNIT_ASSERT_EQ(test, drm_crtc_vblank_get(crtc), 0);
+ drm_crtc_vblank_put(crtc);
+}
+
+/**
+ * dm_test_gpureset_toggle_vblank_no_crtc - Test streams without a CRTC are skipped
+ * @test: The KUnit test context
+ */
+static void dm_test_gpureset_toggle_vblank_no_crtc(struct kunit *test)
+{
+ struct dm_test_irq_mgmt_ctx *ctx = dm_test_irq_mgmt_ctx_alloc(test);
+ struct dc_state *state = dm_test_gpureset_vblank_state(test, ctx);
+ struct drm_crtc *crtc = &ctx->acrtc->base;
+
+ state->stream_status[0].primary_otg_inst = ctx->acrtc->otg_inst + 1;
+
+ dm_gpureset_toggle_vblank(ctx->adev, state, false);
+
+ KUNIT_ASSERT_EQ(test, drm_crtc_vblank_get(crtc), 0);
+ drm_crtc_vblank_put(crtc);
+}
+
+/**
+ * dm_test_gpureset_toggle_vblank_crtc_disabled - Test a disabled CRTC stays off
+ * @test: The KUnit test context
+ *
+ * A modeset that waits for the reset to finish may be turning the CRTC off.
+ */
+static void dm_test_gpureset_toggle_vblank_crtc_disabled(struct kunit *test)
+{
+ struct dm_test_irq_mgmt_ctx *ctx = dm_test_irq_mgmt_ctx_alloc(test);
+ struct dc_state *state = dm_test_gpureset_vblank_state(test, ctx);
+
+ dm_gpureset_toggle_vblank(ctx->adev, state, false);
+ ctx->acrtc->base.enabled = false;
+ dm_gpureset_toggle_vblank(ctx->adev, state, true);
+
+ KUNIT_EXPECT_EQ(test, drm_crtc_vblank_get(&ctx->acrtc->base), -EINVAL);
+}
+
static struct kunit_case amdgpu_dm_tests[] = {
/* Simple DM callbacks */
KUNIT_CASE(dm_test_wait_for_idle),
@@ -5669,6 +5776,11 @@ static struct kunit_case amdgpu_dm_tests[] = {
KUNIT_CASE(dm_test_initialize_plane_overlay),
/* dm_gpureset_toggle_interrupts */
KUNIT_CASE(dm_test_gpureset_toggle_interrupts_dcn),
+ /* dm_gpureset_toggle_vblank */
+ KUNIT_CASE(dm_test_gpureset_toggle_vblank_off),
+ KUNIT_CASE(dm_test_gpureset_toggle_vblank_on),
+ KUNIT_CASE(dm_test_gpureset_toggle_vblank_no_crtc),
+ KUNIT_CASE(dm_test_gpureset_toggle_vblank_crtc_disabled),
{}
};
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 5/5] drm/amd/display: turn vblank off in DRM across GPU reset
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
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-19 8:56 UTC (permalink / raw)
To: Prike Liang, amd-gfx, dri-devel
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 <Prike.Liang@amd.com>
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.
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 4184d8fda10ea..b39c975e0e33a 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -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++) {
> + 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.
> +
> + /*
> + * 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?
> +
> + /* 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.
> @@ -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?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119082424.554841-1-Prike.Liang@amd.com?part=5
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off
2026-11-19 8:24 [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Prike Liang
` (3 preceding siblings ...)
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 14:31 ` Ville Syrjälä
2026-11-20 2:23 ` Liang, Prike
4 siblings, 1 reply; 10+ messages in thread
From: Ville Syrjälä @ 2026-11-19 14:31 UTC (permalink / raw)
To: Prike Liang
Cc: amd-gfx, dri-devel, Alexander.Deucher, Christian.Koenig,
Harry.Wentland, Sunpeng.Li, tzimmermann
On Thu, Nov 19, 2026 at 04:24:20PM +0800, Prike Liang wrote:
> 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.
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
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> *
> * 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
--
Ville Syrjälä
Intel
^ permalink raw reply [flat|nested] 10+ messages in thread* RE: [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off
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
0 siblings, 0 replies; 10+ messages in thread
From: Liang, Prike @ 2026-11-20 2:23 UTC (permalink / raw)
To: Ville Syrjälä
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
Deucher, Alexander, Koenig, Christian, Wentland, Harry,
Li, Sun peng (Leo), tzimmermann@suse.de
AMD General
> -----Original Message-----
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Sent: Thursday, November 19, 2026 10:31 PM
> To: Liang, Prike <Prike.Liang@amd.com>
> Cc: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; Deucher,
> Alexander <Alexander.Deucher@amd.com>; Koenig, Christian
> <Christian.Koenig@amd.com>; Wentland, Harry <Harry.Wentland@amd.com>; Li,
> Sun peng (Leo) <Sunpeng.Li@amd.com>; tzimmermann@suse.de
> Subject: Re: [PATCH v2 1/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when
> vblank is turned off
>
> On Thu, Nov 19, 2026 at 04:24:20PM +0800, Prike Liang wrote:
> > 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.
>
> 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.
Thank you for the detail review, and I will reword the comment log.
Regards,
Prike
> Apart from that, this looks pretty good to me
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> > *
> > * 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
>
> --
> Ville Syrjälä
> Intel
^ permalink raw reply [flat|nested] 10+ messages in thread