Hi Prike,

Thanks for the fix. Would !in_hardirq() be better than in_task() here?

The vblank-disable timer also reaches this callback via
vblank_disable_fn() -> drm_vblank_disable_and_save() ->
drm_update_vblank_count(). In softirq context, in_task() is false,
so the proposed check also bypasses the reset semaphore for timer reads.
Using !in_hardirq() would protect that path while preserving the hard-IRQ
bypass.

What do you think?

Thanks, Vitaly

On 2026-11-11 03:55, Prike Liang wrote:
> amdgpu_get_vblank_counter_kms() returns the cached vblank->last instead
> of reading the hardware counter whenever it can't take
> reset_domain->sem for reading. The vblank interrupt reads the counter
> through the same callback via drm_crtc_handle_vblank(), so once GPU
> recovery holds the semaphore for writing, every vblank interrupt sees
> diff == 0 and the DRM vblank count stops advancing. The CRTCs keep
> scanning out until dm_suspend() turns vblank off and stops the streams,
> though, which only happens after the rest of the recovery preparation.
>
> Vblank waits in that window don't see a vblank anymore. They only end
> when dm_suspend() turns vblank off, or after a second with the
> "vblank wait timed out" warning if that takes longer. The fbdev damage
> worker is likely to be waiting already, because recovery prints
> "GPU reset begin!" right before it takes the semaphore.
>
> Vblank interrupts only arrive while a CRTC is scanning out, so the
> interrupt path can read the hardware counter.
> amdgpu_device_skip_hw_access() likewise only checks the reset semaphore
> in task context. Only back off in task context, so the interrupt path
> keeps the count moving until DM turns vblank off.
>
> Fixes: f2bc71d16e73 ("drm/amdgpu: serialize vblank counter reads against GPU 
> reset")
> Cc: Vitaly Prosyak <[email protected]>
> Cc: James Lin <[email protected]>
> Cc: Leo Li <[email protected]>
> Assisted-by: Copilot:claude-opus-5.5
> Signed-off-by: Prike Liang <[email protected]>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 25 ++++++++++++++++++++++---
>  1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 14a72a406d37..06e539c4c3ea 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1692,6 +1692,7 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)
>       struct drm_device *dev = crtc->dev;
>       unsigned int pipe = crtc->index;
>       struct amdgpu_device *adev = drm_to_adev(dev);
> +     bool locked = false;
>       int vpos, hpos, stat;
>       u32 count;
>  
> @@ -1699,9 +1700,26 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc 
> *crtc)
>               DRM_ERROR("Invalid crtc %u\n", pipe);
>               return -EINVAL;
>       }
> -     if (!down_read_trylock(&adev->reset_domain->sem))
> -             return drm_crtc_vblank_count(crtc);
>  
> +     /*
> +      * A GPU reset is in progress and the display hardware cannot be read
> +      * safely. Return the hardware counter value DRM already cached rather
> +      * than the software vblank count: the core feeds this callback's
> +      * result back into vblank->last, and a software count lives in a
> +      * different numeric domain, which later trips
> +      * drm_WARN_ON_ONCE(cur_vblank != vblank->last) in
> +      * drm_update_vblank_count().
> +      *
> +      * Only task context has to back off. Vblank interrupts only arrive
> +      * while a CRTC is scanning out, so the interrupt path can read the
> +      * hardware, and it has to keep counting: vblank waits that already
> +      * sleep when a reset takes the semaphore never complete otherwise.
> +      */
> +     if (in_task()) {
> +             if (!down_read_trylock(&adev->reset_domain->sem))
> +                     return drm_crtc_vblank_crtc(crtc)->last;
> +             locked = true;
> +     }
>  
>       /* The hw increments its frame counter at start of vsync, not at start
>        * of vblank, as is required by DRM core vblank counter handling.
> @@ -1747,7 +1765,8 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)
>               DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n");
>       }
>  
> -     up_read(&adev->reset_domain->sem);
> +     if (locked)
> +             up_read(&adev->reset_domain->sem);
>       return count;
>  }
>  

Reply via email to