drm/amd/display: Fix flip-done timeouts on mode1 reset
[email protected]
maintainerPATCH 1/1 drm/amd/display: Fix flip-done timeouts on mode1 reset
From: Leo Li <[email protected]>
The vblank on/off callbacks mixed use of amdgpu_irq_get/put() and amdgpu_dm_crtc_set_vupdate_irq() to enable and disable IRQs.
With get/put, base driver will callback into DC to disable IRQs when refcount == 0. With set_vupdate_irq(), DC is called directly to disable IRQs, bypassing base driver's refcount tracking.
During gpu reset, base driver can restore IRQs via amdgpu_irq_gpu_reset_resume_helper() > amdgpu_irq_update(). So if get/put() is not used (i.e. refcount == 0), then vupdate_irq will be disabled.
This is problematic if DRM requests vblank on before amdgpu_irq_update() is called: drm_vblank_on() > set_vupdate_irq() enables vupdate_irq, but the refcount is still 0. gpu_reset_resume_helper() > irq_update() then immediately disables it, thus leading to flip done timeouts.
This is made worse on DCN since VUPDATE_NO_LOCK is the only IRQ enabled. Prior to 8382cd234981, a combination of GRPH_FLIP and VSTARTUP IRQs were used, and they used get/put(). This explains why 8382cd234981 exposed this issue.
Fix by using get/put() instead of set_vupdate_irq(). DCE is unchanged, since it relies on unbalanced enable/disable calls based on VRR status, and hence requires direct set_vupdate_irq(). Plus, it also uses GRPH_FLIP and VLINE IRQs, which are properly tracked by get/put().
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +11 -2
@@ -287,10 +287,19 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)* is enabled. On DCE, vupdate is only needed in VRR mode. */ if (amdgpu_ip_version (adev,DCE_HWIP ,0 ) !=0 ) { - rc =amdgpu_dm_crtc_set_vupdate_irq (crtc, enable); +if (enable) { + rc =amdgpu_irq_get (adev, &adev->vupdate_irq, irq_type); +drm_dbg_vbl (crtc->dev,"Get vupdate_irq ret=%d\n" , rc); + }else { + rc =amdgpu_irq_put (adev, &adev->vupdate_irq, irq_type); +drm_dbg_vbl (crtc->dev,"Put vupdate_irq ret=%d\n" , rc); + } }else if (dc_supports_vrr (dm->dc->ctx->dce_version)) {if (enable) { -/* vblank irq on -> Only need vupdate irq in vrr mode */ +/* vblank irq on -> Only need vupdate irq in vrr mode +* Not ref-counted since we need explicit enable/disable +* for DCE VRR handling +*/ if (amdgpu_dm_crtc_vrr_active (acrtc_state)) rc =amdgpu_dm_crtc_set_vupdate_irq (crtc, true); }else {
Signature · 1 line
2.54.0
Quoted 42 lines · On 7/23/26 13:01, [email protected] wrote:
From: Leo Li <[email protected]>
The vblank on/off callbacks mixed use of amdgpu_irq_get/put() and
amdgpu_dm_crtc_set_vupdate_irq()to enable and disable IRQs.With get/put, base driver will callback into DC to disable IRQs when refcount == 0. With
set_vupdate_irq(), DC is called directly to disable IRQs, bypassing base driver's refcount tracking.During gpu reset, base driver can restore IRQs via
amdgpu_irq_gpu_reset_resume_helper()>amdgpu_irq_update(). So if get/put() is not used (i.e. refcount == 0), thenvupdate_irqwill be disabled.This is problematic if DRM requests vblank on before
amdgpu_irq_update()is called:drm_vblank_on()>set_vupdate_irq()enablesvupdate_irq, but the refcount is still 0.gpu_reset_resume_helper()>irq_update()then immediately disables it, thus leading to flip done timeouts.This is made worse on DCN since
VUPDATE_NO_LOCKis the only IRQ enabled. Prior to8382cd234981, a combination ofGRPH_FLIPand VSTARTUP IRQs were used, and they used get/put(). This explains why8382cd234981exposed this issue.Fix by using get/put() instead of
set_vupdate_irq(). DCE is unchanged, since it relies on unbalanced enable/disable calls based on VRR status, and hence requires directset_vupdate_irq(). Plus, it also usesGRPH_FLIPand VLINE IRQs, which are properly tracked by get/put().Fixes 8382cd234981 ("drm/amd/display: consolidate DCN vblank/flip handling onto vupdate_no_lock")Signed-off-by Leo Li <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0@@ -287,10 +287,19 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)* is enabled. On DCE, vupdate is only needed in VRR mode.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) · line 296
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +7
-1*/ if (amdgpu_ip_version (adev,DCE_HWIP ,0 ) !=0 ) { - rc =amdgpu_dm_crtc_set_vupdate_irq (crtc, enable); +if (enable) { + rc =amdgpu_irq_get (adev, &adev->vupdate_irq, irq_type); +drm_dbg_vbl (crtc->dev,"Get vupdate_irq ret=%d\n" , rc); + }else { + rc =amdgpu_irq_put (adev, &adev->vupdate_irq, irq_type); +drm_dbg_vbl (crtc->dev,"Put vupdate_irq ret=%d\n" , rc); + }
For completeness in error handling, shouldn't you pass up the return code on non-zero? It looks like it could pass up to DRM core then.
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +4
-1}else if (dc_supports_vrr (dm->dc->ctx->dce_version)) {if (enable) { -/* vblank irq on -> Only need vupdate irq in vrr mode */ +/* vblank irq on -> Only need vupdate irq in vrr mode +* Not ref-counted since we need explicit enable/disable +* for DCE VRR handling +*/ if (amdgpu_dm_crtc_vrr_active (acrtc_state)) rc =amdgpu_dm_crtc_set_vupdate_irq (crtc, true); }else {
Leo Li
maintainerQuoted 17 lines · Mario Limonciello
Quoted 8 lines
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c index 05d6915f9a6b0..079d4ccc88da6 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
@@ -287,10 +287,19 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)
* is enabled. On DCE, vupdate is only needed in VRR mode.
*/
if (amdgpu_ip_version(adev, DCE_HWIP, 0) != 0) {Quoted 8 lines
- rc = amdgpu_dm_crtc_set_vupdate_irq(crtc, enable); + if (enable) {
+ rc = amdgpu_irq_get(adev, &adev->vupdate_irq, irq_type); + drm_dbg_vbl(crtc->dev, "Get vupdate_irq ret=%d\n", rc); + } else {
+ rc = amdgpu_irq_put(adev, &adev->vupdate_irq, irq_type); + drm_dbg_vbl(crtc->dev, "Put vupdate_irq ret=%d\n", rc); + }
Quoted 1 line
For completeness in error handling, shouldn't you pass up the return code on non-zero? It looks like it could pass up to DRM core then.
It's not shown in the context here, but the rc is passed up later:
https://elixir.bootlin.com/linux/v7.2-rc4/source/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c#L295
- Leo
Quoted 11 lines
Quoted 11 lines
} else if (dc_supports_vrr(dm->dc->ctx->dce_version)) { if (enable) {
- /* vblank irq on -> Only need vupdate irq in vrr mode */ + /* vblank irq on -> Only need vupdate irq in vrr mode + * Not ref-counted since we need explicit enable/disable + * for DCE VRR handling
+ */
if (amdgpu_dm_crtc_vrr_active(acrtc_state)) rc = amdgpu_dm_crtc_set_vupdate_irq(crtc, true); } else {
Mario Limonciello
Reviewed-byQuoted 20 lines · Leo Li
Quoted 17 lines · Mario Limonciello
Quoted 16 lines
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c index 05d6915f9a6b0..079d4ccc88da6 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
@@ -287,10 +287,19 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)
* is enabled. On DCE, vupdate is only needed in VRR mode.
*/
if (amdgpu_ip_version(adev, DCE_HWIP, 0) != 0) {
- rc = amdgpu_dm_crtc_set_vupdate_irq(crtc, enable);
+ if (enable) {
+ rc = amdgpu_irq_get(adev, &adev->vupdate_irq, irq_type);
+ drm_dbg_vbl(crtc->dev, "Get vupdate_irq ret=%d\n", rc);
+ } else {
+ rc = amdgpu_irq_put(adev, &adev->vupdate_irq, irq_type);
+ drm_dbg_vbl(crtc->dev, "Put vupdate_irq ret=%d\n", rc);
+ }
Quoted 7 lines
Quoted 1 line
For completeness in error handling, shouldn't you pass up the return code on non-zero? It looks like it could pass up to DRM core then.
It's not shown in the context here, but the rc is passed up later:
https://elixir.bootlin.com/linux/v7.2-rc4/source/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c#L295- Leo
Ah got it, thanks. No concerns.
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
} else if (dc_supports_vrr(dm->dc->ctx->dce_version)) { if (enable) {
- /* vblank irq on -> Only need vupdate irq in vrr mode */ + /* vblank irq on -> Only need vupdate irq in vrr mode + * Not ref-counted since we need explicit enable/disable + * for DCE VRR handling
+ */
if (amdgpu_dm_crtc_vrr_active(acrtc_state)) rc = amdgpu_dm_crtc_set_vupdate_irq(crtc, true); } else {
Quoted 23 lines · Mario Limonciello
Quoted 22 lines · Leo Li
Quoted 18 lines · Mario Limonciello
Quoted 8 lines
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c index 05d6915f9a6b0..079d4ccc88da6 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
@@ -287,10 +287,19 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)
* is enabled. On DCE, vupdate is only needed in VRR mode.
*/
if (amdgpu_ip_version(adev, DCE_HWIP, 0) != 0) {Quoted 8 lines
- rc = amdgpu_dm_crtc_set_vupdate_irq(crtc, enable); + if (enable) {
+ rc = amdgpu_irq_get(adev, &adev->vupdate_irq, irq_type); + drm_dbg_vbl(crtc->dev, "Get vupdate_irq ret=%d\n", rc); + } else {
+ rc = amdgpu_irq_put(adev, &adev->vupdate_irq, irq_type); + drm_dbg_vbl(crtc->dev, "Put vupdate_irq ret=%d\n", rc); + }For completeness in error handling, shouldn't you pass up the return code on non-zero? It looks like it could pass up to DRM core then.
Quoted 8 lines
Quoted 5 lines
It's not shown in the context here, but the rc is passed up later:
https://elixir.bootlin.com/linux/v7.2-rc4/source/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c#L295- Leo
Ah got it, thanks. No concerns.
Reviewed-by Mario Limonciello (AMD) <[email protected]>
Merged into asdn, thanks!
- Leo
Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
} else if (dc_supports_vrr(dm->dc->ctx->dce_version)) { if (enable) {
- /* vblank irq on -> Only need vupdate irq in vrr mode */ + /* vblank irq on -> Only need vupdate irq in vrr mode + * Not ref-counted since we need explicit enable/disable + * for DCE VRR handling
+ */
if (amdgpu_dm_crtc_vrr_active(acrtc_state)) rc = amdgpu_dm_crtc_set_vupdate_irq(crtc, true); } else {