AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Prike Liang <Prike.Liang@amd.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	Alexander.Deucher@amd.com, Christian.Koenig@amd.com,
	Harry.Wentland@amd.com, Sunpeng.Li@amd.com, tzimmermann@suse.de
Subject: Re: [PATCH RESEND 2/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off
Date: Wed, 18 Nov 2026 17:29:42 +0200	[thread overview]
Message-ID: <av3EZjSWFetO7U3e@intel.com> (raw)
In-Reply-To: <20261111085534.514957-2-Prike.Liang@amd.com>

On Wed, Nov 11, 2026 at 04:55:31PM +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() and drm_crtc_wait_one_vblank_interruptible()
> only check 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(), which implements both functions, 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, time out or are interrupted behave as before.
> 
> Fixes: e8450f51a4b3 ("drm/irq: Implement a generic vblank_wait function")
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Assisted-by: Copilot:claude-opus-5.5
> Signed-off-by: Prike Liang <Prike.Liang@amd.com>
> ---
>  drivers/gpu/drm/drm_vblank.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index c3c9afc08ed2..5e247663978a 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -1315,21 +1315,29 @@ static int __drm_crtc_wait_one_vblank(struct drm_crtc *crtc, bool interruptible)
>  
>  	if (interruptible)
>  		timeout = wait_event_interruptible_timeout(vblank->queue,
> -							   last != drm_vblank_count(dev, pipe),
> +							   last != drm_vblank_count(dev, pipe) ||
> +							   !READ_ONCE(vblank->enabled),
>  							   timeout);
>  	else
>  		timeout = wait_event_timeout(vblank->queue,
> -					     last != drm_vblank_count(dev, pipe),
> +					     last != drm_vblank_count(dev, pipe) ||
> +					     !READ_ONCE(vblank->enabled),
>  					     timeout);
>  
>  	drm_WARN(dev, timeout == 0, "vblank wait timed out on crtc %i\n", pipe);
>  
> -	drm_vblank_put(dev, pipe);
> -
>  	if (timeout < 0)
> -		return timeout;
> +		ret = timeout;
> +	else if (!timeout)
> +		ret = -ETIMEDOUT;
> +	else if (last == drm_vblank_count(dev, pipe))
> +		ret = -EINVAL; /* drm_crtc_vblank_off() ended the wait */

The error matches the one you get from drm_vblank_get() if calling this
when the vblank has been already turned off prior to the wait. Not sure
if we might want a different error value? Perhaps not. The ioctl does
return with success for a terminated wait, but I suppose having the
internal one return with an error will let the caller know that vblanks
are no longer available, so seems like a OK choice to me.

What is different between the two drm_vblank_get() failing vs.
terminating early due to _off() is that drm_vblank_get() failing will
WARN, terminating the vblank early does not. I take it that is the
behaviour you are after here. I think that difference is worth pointing
in the commit message, so we know it's intentional.

I think you should probably reorder the series and move this to be the
first patch so that it could even be backported without having to bring
the interruptible variant along for the ride.

> +	else
> +		ret = 0;
>  
> -	return timeout ? 0 : -ETIMEDOUT;
> +	drm_vblank_put(dev, pipe);
> +
> +	return ret;
>  }
>  
>  /**
> @@ -1338,7 +1346,8 @@ static int __drm_crtc_wait_one_vblank(struct drm_crtc *crtc, bool interruptible)
>   *
>   * 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.
>   */
> -- 
> 2.34.1

-- 
Ville Syrjälä
Intel

  parent reply	other threads:[~2026-11-18 15:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  8:55 [PATCH RESEND 1/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible Prike Liang
2026-11-11  8:55 ` [PATCH RESEND 2/5] drm/vblank: Stop drm_crtc_wait_one_vblank() when vblank is turned off Prike Liang
2026-11-18  9:01   ` Liang, Prike
2026-11-18 15:29   ` Ville Syrjälä [this message]
2026-11-11  8:55 ` [PATCH RESEND 3/5] drm/amd/display: send the flip event right away if vblank is off Prike Liang
2026-11-11  8:55 ` [PATCH RESEND 4/5] drm/amd/display: turn vblank off in DRM across GPU reset Prike Liang
2026-11-11  8:55 ` [PATCH RESEND 5/5] drm/amdgpu: keep reading the vblank counter in IRQ context during reset Prike Liang
2026-11-12  2:52   ` vitaly prosyak
2026-11-16 13:25     ` Liang, Prike
2026-11-16 20:15       ` vitaly prosyak
2026-11-18  7:18 ` [PATCH RESEND 1/5] drm/client: Make the FBIO_WAITFORVSYNC vblank wait interruptible Liang, Prike
2026-11-18 15:13 ` Ville Syrjälä

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=av3EZjSWFetO7U3e@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Harry.Wentland@amd.com \
    --cc=Prike.Liang@amd.com \
    --cc=Sunpeng.Li@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox