Fixes for flip_done timed outs and PSR/Replay corruption
[email protected]
maintainercover Fixes for flip_done timed outs and PSR/Replay corruption
From: Leo Li <[email protected]>
This series can be considered as a v3 of this:
https://lore.kernel.org/amd-gfx/[email protected]/
However, the approach to fixing ended up being quite different, hence the new series.
Instead of adding vline2 as an interrupt source, all existing DCN interrupt sources are now combined to be handled in VUPDATE_NO_LOCK. This source cannot be masked by any event (short of disabling the output timing generator), and it fires at the HW latching point for newly programmed double-buffered registers. This should fix a majority of flip_done timeout issues in the wild. See patch 1/3 for details.
Patch 2/3 fixes a PSR/Replay panel corruption, caused by a race between the commit thread arming flip events then programming a flip, v.s. a interrupt handler delivering the armed event. Also it's commit message for details.
Thanks again to everyone who helped with testing and debugging!
P.S. Since the fix is on top of some major refactors, backporting to stable will definitely cause merge conflicts. A v7.0.12 based branch can be found here:
https://gitlab.freedesktop.org/leoli/linux-asdn/-/commits/lileo/flip_done_timeout_corruption_fixes
Leo Li (3):
drm/amd/display: consolidate DCN vblank/flip handling onto
vupdate_no_lock
drm/amd/display: check GRPH_FLIP status before sending event Revert "drm/amd/display: Restore 5s vbl offdelay for NV3x+ DGPUs"
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 75 +++-- .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 75 +++-- .../drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c | 304 +++++++++--------- .../display/amdgpu_dm/amdgpu_dm_irq_params.h | 8 + drivers/gpu/drm/amd/display/dc/core/dc.c | 45 +++ drivers/gpu/drm/amd/display/dc/dc.h | 1 + 6 files changed, 302 insertions(+), 206 deletions(-)
Signature · 1 line
2.54.0
[email protected]
maintainerPATCH 1/3 drm/amd/display: consolidate DCN vblank/flip handling onto vupdate_no_lock
From: Leo Li <[email protected]>
[Why]
On DCN, vblank events were delivered from VSTARTUP/VUPDATE (dm_crtc_high_irq/dm_vupdate_high_irq) and pageflip completion from GRPH_PFLIP (dm_pflip_high_irq). These signals can be masked by hardware by a few things:
* DPG - DCN can Dynamically Power Gate parts of the display pipe when a self-refresh capable eDP is connected. DPG is engaged when there's enough static frames (detected thru drm_vblank_off) Once gated, even though the OTG (output timing generator) is still enabled, VSTARTUP and GRPH_FLIP are masked.
* GSL - Driver can use the Global Sync Lock to block HW from latching onto double-buffered registers during programming, to prevent HW from latching onto a partially programmed state. This will mask VSTARTUP, GRPH_FLIP, and VUPDATE. See dcn20_pipe_control_lock().
* MALL - A DCN accessible cache introduced in DCN32+ DGPUs that can store fb data to allow for longer DRAM sleep. When scanning out from MALL, STARTUP is masked.
When masked, events are never delivered, which can show up as flip_done timeouts in the wild.
However, there is an interrupt source on DCN that is never masked:VUPDATE_NO_LOCK. It's simply an unmasked variant of VUPDATE, which fires while the OTG is active, at the exact point hardware latches double-buffered registers. It is therefore the natural single signal for delivering both vblank and flip-completion events on DCN, and the correct point to timestamp both VRR and non-VRR vblanks.
DCE's interrupt sources are different, it does not have an unmaskable VUPDATE_NO_LOCK. The only unmaskable DCE interrupt is VLINE0, but it can only be programmed as a vline offset from vsync_start, making it unsuitable for VRR. Thus, we keep DCE untouched and use the existing mix of interrupt sources.
[How]
For DCN1 and newer only:
* Factor the body of dm_crtc_high_irq() into dm_crtc_high_irq_handler() and drive it from dm_vupdate_high_irq() (VUPDATE_NO_LOCK). DCE keeps using dm_crtc_high_irq() (VSTARTUP) and dm_pflip_high_irq() (GRPH_PFLIP) unchanged.
* Stop registering VSTARTUP (crtc_irq) and GRPH_PFLIP (pageflip_irq) on DCN, and stop enabling them in amdgpu_dm_crtc_set_vblank() / manage_dm_interrupts(). Enable VUPDATE whenever vblank is enabled on DCN (previously only in VRR mode). The secure-display vline0 interrupt is left untouched.
* VUPDATE_NO_LOCK does not early-fire on an immediate (tearing / async) flip, since HW latches the new address right away. Deliver the flip completion event immediately after programming such flips in amdgpu_dm_commit_planes(), and clear pflip_status so the next vupdate handler does not double-send.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 48 ++- .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 70 +++-- .../drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c | 282 ++++++++---------- 3 files changed, 213 insertions(+), 187 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +43 -5
@@ -3560,14 +3560,22 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,drm_crtc_vblank_on_config (&acrtc->base, &config); -/* Allow RX6xxx, RX7700, RX7800 GPUs to call amdgpu_irq_get.*/ +/* +* Since pflip_high_irq is no longer registered for DCN, Grab an +* extra reference to vupdate irq insteaad to workaround this +* issue: +* https://gitlab.freedesktop.org/drm/amd/-/work_items/3936 +* +* The callbacks to drm_vblank_on/off should really take care of +* this though. +*/ switch (amdgpu_ip_version (adev,DCE_HWIP ,0 )) {case IP_VERSION (3 ,0 ,0 ):case IP_VERSION (3 ,0 ,2 ):case IP_VERSION (3 ,0 ,3 ):case IP_VERSION (3 ,2 ,0 ): -if (amdgpu_irq_get (adev, &adev->pageflip_irq, irq_type)) -drm_err (dev,"DM_IRQ: Cannot get pageflip irq!\n" ); +if (amdgpu_irq_get (adev, &adev->vupdate_irq, irq_type)) +drm_err (dev,"DM_IRQ: Cannot get vupdate irq!\n" );#if defined(CONFIG_DRM_AMD_SECURE_DISPLAY )if (amdgpu_irq_get (adev, &adev->vline0_irq, irq_type))drm_err (dev,"DM_IRQ: Cannot get vline0 irq!\n" );
@@ -3585,8 +3593,8 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,if (amdgpu_irq_put (adev, &adev->vline0_irq, irq_type))drm_err (dev,"DM_IRQ: Cannot put vline0 irq!\n" );#endif -if (amdgpu_irq_put (adev, &adev->pageflip_irq, irq_type)) -drm_err (dev,"DM_IRQ: Cannot put pageflip irq!\n" ); +if (amdgpu_irq_put (adev, &adev->vupdate_irq, irq_type)) +drm_err (dev,"DM_IRQ: Cannot put vupdate irq!\n" ); }drm_crtc_vblank_off (&acrtc->base);
@@ -3599,6 +3607,10 @@ static void dm_update_pflip_irq_state(struct amdgpu_device *adev,int irq_type =amdgpu_display_crtc_idx_to_irq_type (adev, acrtc->crtc_id); +/* GRPH_PFLIP is not used on DCN; nothing to reapply. */ +if (amdgpu_ip_version (adev,DCE_HWIP ,0 ) !=0 ) +return ; +/** * This reads the current state for the IRQ and force reapplies * the setting to hardware.
@@ -4131,6 +4143,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,bool vrr_active =amdgpu_dm_crtc_vrr_active (acrtc_state);bool cursor_update = false;bool pflip_present = false; +bool immediate_flip = false;bool dirty_rects_changed = false;bool updated_planes_and_streams = false;struct {
@@ -4293,6 +4306,8 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, acrtc_state->update_type ==UPDATE_TYPE_FAST &&get_mem_type (old_plane_state->fb) ==get_mem_type (fb); + immediate_flip |= bundle->flip_addrs[planes_count].flip_immediate; + timestamp_ns =ktime_get_ns (); bundle->flip_addrs[planes_count].flip_timestamp_in_us =div_u64 (timestamp_ns,1000 ); bundle->surface_updates[planes_count].flip_addr = &bundle->flip_addrs[planes_count];
@@ -4475,6 +4490,29 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,mutex_unlock (&dm->dc_lock); } +/* +* On DCN, flip completion is normally delivered from VUPDATE_NO_LOCK. +* However, an immediate (tearing / async) flip is latched by HW right +* away and does not wait for the next vupdate, so deliver its +* completion event here, immediately after programming. Clearing +* pflip_status ensures the next dm_vupdate_high_irq() won't double-send. +* +* On DCE, GRPH_PFLIP already fires immediately for immediate flips, so +* this is DCN-only. +*/ +if (immediate_flip &&amdgpu_ip_version (dm->adev,DCE_HWIP ,0 ) !=0 ) { +spin_lock_irqsave (&pcrtc->dev->event_lock, flags); +if (acrtc_attach->pflip_status ==AMDGPU_FLIP_SUBMITTED && + acrtc_attach->event) { +drm_crtc_send_vblank_event (&acrtc_attach->base, + acrtc_attach->event); + acrtc_attach->event =NULL ; +drm_crtc_vblank_put (&acrtc_attach->base); + acrtc_attach->pflip_status =AMDGPU_FLIP_NONE ; + } +spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags); + } +/* * Update cursor state *after* programming all the planes. * This avoids redundant programming in the case where we're going
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +42 -28
88 lines not on this page · raw message
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c +128 -154
328 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
maintainerPATCH 2/3 drm/amd/display: check GRPH_FLIP status before sending event
In reply to [email protected]From: Leo Li <[email protected]>
[Why]
After unifying DCN interrupt sources under VUPDATE_NO_LOCK, we have two remaining issues to clean up:
1. On DCN, flip completion is now delivered from VUPDATE_NO_LOCK (dm_crtc_high_irq_handler) instead of GRPH_PFLIP. But VUPDATE_NO_LOCK fires every frame, regardless of whether a flip has latched.
2. There is a window during commit where a flip is armed (pflip_status = SUBMITTED) but not yet programmed into HW. If the VUPDATE_NO_LOCK fires in that window, it's handler would deliver a flip event to userspace before HW has latched to it. If userspace then renders to what it believes is now the back buffer (but HW is still latched to it!), it will cause display corruption. (This issue seemed to have existed ever since the introduction of pflip_status. Enabling replay or psr extended the duration of this window, and hence made corruption more likely to be observed.)
[How]
* Add a flip_programmed completion. Arm it (reinit_completion) under event_lock together with prepare_flip_isr(), and signal it (complete_all) right after update_planes_and_stream_adapter() programs the flip. It starts in the "completed" state at crtc init.
* Add dc_get_flip_pending_on_otg(), which reads the HUBP flip-pending status straight from HW for the pipe(s) bound to an OTG instance. It is keyed only by otg_inst and does not take or mutate a dc_plane_state, so it is safe to call from the OTG interrupt handler without racing a concurrent commit that may be modifying plane state.
* In the DCN OTG handler, only deliver flip completion once flip_programmed is signalled (try_wait_for_completion) and dc_get_flip_pending_on_otg() reports the flip is no longer pending. Otherwise leave the flip armed and retry on the next vupdate.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 9 ++-- .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 5 +++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c | 34 +++++++++++--- .../display/amdgpu_dm/amdgpu_dm_irq_params.h | 8 ++++ drivers/gpu/drm/amd/display/dc/core/dc.c | 45 +++++++++++++++++++ drivers/gpu/drm/amd/display/dc/dc.h | 1 + 6 files changed, 92 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -4
@@ -4384,17 +4384,17 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* from 0 -> n planes we have to skip a hardware generated event * and rely on sending it from software. */ +spin_lock_irqsave (&pcrtc->dev->event_lock, flags);if (acrtc_attach->base.state->event && acrtc_state->active_planes >0 ) {drm_crtc_vblank_get (pcrtc); -spin_lock_irqsave (&pcrtc->dev->event_lock, flags); -WARN_ON (acrtc_attach->pflip_status !=AMDGPU_FLIP_NONE ); +/* Arm flip completion handling and event delivery */ +reinit_completion (&acrtc_attach->dm_irq_params.flip_programmed);prepare_flip_isr (acrtc_attach); - -spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags); } +spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags);if (acrtc_state->stream) {if (acrtc_state->freesync_vrr_info_changed)
@@ -4468,6 +4468,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, &bundle->stream_update, bundle->surface_updates); updated_planes_and_streams = true; +complete_all (&acrtc_attach->dm_irq_params.flip_programmed);/** * Enable or disable the interrupts on the backend.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +5 -0
@@ -789,6 +789,11 @@ int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm,#ifdef AMD_PRIVATE_COLOR dm_crtc_additional_color_mgmt (&acrtc->base);#endif + +init_completion (&acrtc->dm_irq_params.flip_programmed); +/* No flip is in flight yet; start in the "programmed" state. */ +complete_all (&acrtc->dm_irq_params.flip_programmed); +return 0 ; fail:
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c +28 -6
@@ -1990,14 +1990,36 @@ static void dm_crtc_high_irq_handler(struct amdgpu_device *adev,/* * Deliver pageflip completion events (DCN only). * -* Since GRPH_PFLIP is not used, VUPDATE_NO_LOCK is the flip latch -* point. Deliver any pending pageflip completion event from here. +* On DCN, GRPH_PFLIP is not used; VUPDATE_NO_LOCK is the flip latch +* point, so deliver any pending pageflip completion event from here. +* But only once the armed flip has actually been programmed into HW +* (flip_programmed) and HW has consumed the new address (the OTG no +* longer reports a pending flip). This avoids reporting completion for +* a flip whose address has not yet been latched, which would let +* userspace render over the still-presented buffer and cause +* corruption. * -* NOTE: This can deliver an event for a flip that was armed but not yet -* programmed into HW; that race is closed in a follow-up change by -* checking the programmed flip status. +* Also handle the case here where there aren't any active planes and +* DCN HUBP may be clock-gated, so the flip-pending status may be +* undefined. */ -if (is_dcn && acrtc->pflip_status ==AMDGPU_FLIP_SUBMITTED ) { +if (is_dcn && acrtc->pflip_status ==AMDGPU_FLIP_SUBMITTED && + acrtc->event && +try_wait_for_completion (&acrtc->dm_irq_params.flip_programmed)) { + +if (!dc_get_flip_pending_on_otg (adev->dm.dc, acrtc->otg_inst)) { +drm_crtc_send_vblank_event (&acrtc->base, acrtc->event); + acrtc->event =NULL ; +drm_crtc_vblank_put (&acrtc->base); + acrtc->pflip_status =AMDGPU_FLIP_NONE ; + } +/* +* If the flip is still pending, leave it armed and +* retry on the next vupdate. +*/ + }else if (is_dcn && acrtc->pflip_status ==AMDGPU_FLIP_SUBMITTED && + acrtc->dm_irq_params.active_planes ==0 ) { +if (acrtc->event) {drm_crtc_send_vblank_event (&acrtc->base, acrtc->event); acrtc->event =NULL ;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq_params.h +8 -0
@@ -27,12 +27,20 @@ #ifndef __AMDGPU_DM_IRQ_PARAMS_H__ #define __AMDGPU_DM_IRQ_PARAMS_H__ +#include <linux/completion.h> + #include "amdgpu_dm_crc.h" struct dm_irq_params { u32 last_flip_vblank; struct mod_vrr_params vrr_params; struct dc_stream_state *stream; + + /* + * Completed once an armed flip has actually been programmed into HW. + */ + struct completion flip_programmed; + int active_planes; bool allow_sr_entry; struct mod_freesync_config freesync_config;
drivers/gpu/drm/amd/display/dc/core/dc.c +45 -0
51 lines not on this page · raw message
drivers/gpu/drm/amd/display/dc/dc.h +1 -0
@@ -2990,6 +2990,7 @@ enum dc_irq_source dc_interrupt_to_irq_source( uint32_t ext_id);bool dc_interrupt_set (struct dc *dc,enum dc_irq_source src,bool enable);void dc_interrupt_ack (struct dc *dc,enum dc_irq_source src); +bool dc_get_flip_pending_on_otg (struct dc *dc,int otg_inst);enum dc_irq_source dc_get_hpd_irq_source_at_index (struct dc *dc,uint32_t link_index);
Signature · 1 line
2.54.0
[email protected]
maintainerPATCH 3/3 Revert "drm/amd/display: Restore 5s vbl offdelay for NV3x+ DGPUs"
In reply to [email protected]From: Leo Li <[email protected]>
Now that proper fixes have been found, let's revert this workaround.
This reverts commit 751414c12388ff2b475e15c15d3c817dcf563635.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -15
@@ -3527,21 +3527,9 @@ static void manage_dm_interrupts(struct amdgpu_device *adev,if (acrtc_state) { timing = &acrtc_state->stream->timing; -if (amdgpu_ip_version (adev,DCE_HWIP ,0 ) >= -IP_VERSION (3 ,2 ,0 ) && - !(adev->flags &AMD_IS_APU )) { -/* -* DGPUs NV3x and newer that support idle optimizations -* experience intermittent flip-done timeouts on cursor -* updates. Restore 5s offdelay behavior for now. -* -* Discussion on the issue: -* https://lore.kernel.org/amd-gfx/[email protected]/ -*/ - config.offdelay_ms =5000 ; - config.disable_immediate = false; - }else if (amdgpu_ip_version (adev,DCE_HWIP ,0 ) < -IP_VERSION (3 ,5 ,0 )) { +if (amdgpu_ip_version (adev,DCE_HWIP ,0 ) < +IP_VERSION (3 ,5 ,0 ) || + !(adev->flags &AMD_IS_APU )) {/* * Older HW and DGPU have issues with instant off; * use a 2 frame offdelay.
Signature · 1 line
2.54.0
Re: [PATCH 1/3] drm/amd/display: consolidate DCN vblank/flip handling onto vupdate_no_lock
In reply to [email protected]On 6/16/26 1:18 PM, [email protected] wrote:
[...]
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0@@ -281,7 +281,14 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)drm_crtc_vblank_restore (crtc); }
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 291
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +8
-1-if (dc_supports_vrr (dm->dc->ctx->dce_version)) { +/* +* On DCN, VUPDATE_NO_LOCK is the single OTG interrupt used to deliver +* vblank and pageflip completion events, so enable it whenever vblank +* 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); + }else if (dc_supports_vrr (dm->dc->ctx->dce_version)) {
Hi Leo (dropping Stable),
This arms VUPDATE_NO_LOCK on all of DCN, but amdgpu_dm_handle_vrr_transition() still disables it when switching from VRR active -> inactive. This causes a new flip_done timed out event when a compositor like gamescope disables VRR while it's already active.
I had to fix it up with something like:
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +12 -2
@@ -10085,8 +10085,16 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,struct dm_crtc_state *old_state, struct dm_crtc_state *new_state) { + struct amdgpu_device *adev = dm->adev;bool old_vrr_active =amdgpu_dm_crtc_vrr_active (old_state);bool new_vrr_active =amdgpu_dm_crtc_vrr_active (new_state); +/* +* On DCN, VUPDATE_NO_LOCK is the sole vblank and pageflip completion +* source and amdgpu_dm_crtc_set_vblank() keeps it armed whenever +* vblank is enabled, so it must not be toggled with the VRR state. +* Only DCE gates vupdate on VRR. +*/ +bool vrr_gates_vupdate =amdgpu_ip_version (adev,DCE_HWIP ,0 ) ==0 ;if (!old_vrr_active && new_vrr_active) {/* Transition VRR inactive -> active:
@@ -10097,7 +10105,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,* We also need vupdate irq for the actual core vblank handling * at end of vblank. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 );WARN_ON (drm_crtc_vblank_get (new_state->base.crtc) !=0 );drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR off->on: Get vblank ref\n" , __func__, new_state->base.crtc->base.id);
@@ -10113,7 +10122,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,/* Transition VRR active -> inactive: * Allow vblank irq disable again for fixed refresh rate. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 );drm_crtc_vblank_put (new_state->base.crtc);drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR on->off: Drop vblank ref\n" , __func__, new_state->base.crtc->base.id);
Feel free to fold some version of this into the next version if it makes sense, or pick it up with my s-o-b.
Thanks,
Matthew
Re: [PATCH 2/3] drm/amd/display: check GRPH_FLIP status before sending event
In reply to [email protected]Quoted 5 lines · On 6/16/26 22:18, [email protected] wrote:
* Add a
flip_programmedcompletion. Arm it (reinit_completion) underevent_locktogether withprepare_flip_isr(), and signal it (complete_all) right afterupdate_planes_and_stream_adapter()programs the flip. It starts in the "completed" state at crtc init.
Is the completion really necessary? Wouldn't moving the acrtc->pflip_status = AMDGPU_FLIP_SUBMITTED assignment after the flip programming suffice?
Quoted 16 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1
-2@@ -4384,17 +4384,17 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* from 0 -> n planes we have to skip a hardware generated event * and rely on sending it from software. */ +spin_lock_irqsave (&pcrtc->dev->event_lock, flags);if (acrtc_attach->base.state->event && acrtc_state->active_planes >0 ) {drm_crtc_vblank_get (pcrtc); -spin_lock_irqsave (&pcrtc->dev->event_lock, flags); -WARN_ON (acrtc_attach->pflip_status !=AMDGPU_FLIP_NONE );
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, · line 4400
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3
-2+/* Arm flip completion handling and event delivery */ +reinit_completion (&acrtc_attach->dm_irq_params.flip_programmed);prepare_flip_isr (acrtc_attach); - -spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags); } +spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags);if (acrtc_state->stream) {if (acrtc_state->freesync_vrr_info_changed)
Pulling event_lock out of the if block doesn't make any difference (other than locking it unnecessarily when the block isn't entered :), does it?
Signature · 2 lines
Earthling Michel Dänzer \ GNOME / Xwayland / Mesa developer https://redhat.com \ Libre software enthusiast
Re: [PATCH 2/3] drm/amd/display: check GRPH_FLIP status before sending event
In reply to [email protected]Quoted 8 lines · On 6/16/26 22:18, [email protected] wrote:
2. There is a window during commit where a flip is armed (
pflip_status= SUBMITTED) but not yet programmed into HW. If theVUPDATE_NO_LOCKfires in that window, it's handler would deliver a flip event to userspace before HW has latched to it. If userspace then renders to what it believes is now the back buffer (but HW is still latched to it!), it will cause display corruption. (This issue seemed to have existed ever since the introduction ofpflip_status.
AFAICT this issue was introduced by 1159898a88db ("drm/amd/display: Handle commit plane with no FB.").
pflip_status was already there before DC, and AFAICT amdgpu_flip_work_func has always handled this correctly.
Signature · 2 lines
Earthling Michel Dänzer \ GNOME / Xwayland / Mesa developer https://redhat.com \ Libre software enthusiast
Re: [PATCH 2/3] drm/amd/display: check GRPH_FLIP status before sending event
In reply to Michel DänzerQuoted 8 lines · Michel Dänzer
Quoted 5 lines · On 6/16/26 22:18, [email protected] wrote:
* Add a
flip_programmedcompletion. Arm it (reinit_completion) underevent_locktogether withprepare_flip_isr(), and signal it (complete_all) right afterupdate_planes_and_stream_adapter()programs the flip. It starts in the "completed" state at crtc init.Is the completion really necessary? Wouldn't moving the
acrtc->pflip_status=AMDGPU_FLIP_SUBMITTEDassignment after the flip programming suffice?
Or even just moving the unlocking of event_lock after the flip programming.
Signature · 2 lines
Earthling Michel Dänzer \ GNOME / Xwayland / Mesa developer https://redhat.com \ Libre software enthusiast
Leo Li
maintainerRe: [PATCH 1/3] drm/amd/display: consolidate DCN vblank/flip handling onto vupdate_no_lock
In reply to Matthew SchwartzQuoted 24 lines · Matthew Schwartz
On 6/16/26 1:18 PM, [email protected] wrote:
[...]
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0@@ -281,7 +281,14 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)drm_crtc_vblank_restore (crtc); }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 291
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +8
-1-if (dc_supports_vrr (dm->dc->ctx->dce_version)) { +/* +* On DCN, VUPDATE_NO_LOCK is the single OTG interrupt used to deliver +* vblank and pageflip completion events, so enable it whenever vblank +* 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); + }else if (dc_supports_vrr (dm->dc->ctx->dce_version)) {Hi Leo (dropping Stable),
Quoted 1 line
This arms
VUPDATE_NO_LOCKon all of DCN, butamdgpu_dm_handle_vrr_transition()still disables it when switching from VRR active -> inactive. This causes a newflip_donetimed out event when a compositor like gamescope disables VRR while it's already active.
Good catch, I wonder why the kms_vrr IGT tests did not catch this... I'll roll your fix into v2 with your signed-off-by and co-authored-by.
Thanks,
Leo
Quoted 50 lines
I had to fix it up with something like:
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +12
-2@@ -10085,8 +10085,16 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,struct dm_crtc_state *old_state, struct dm_crtc_state *new_state) { + struct amdgpu_device *adev = dm->adev;bool old_vrr_active =amdgpu_dm_crtc_vrr_active (old_state);bool new_vrr_active =amdgpu_dm_crtc_vrr_active (new_state); +/* +* On DCN, VUPDATE_NO_LOCK is the sole vblank and pageflip completion +* source and amdgpu_dm_crtc_set_vblank() keeps it armed whenever +* vblank is enabled, so it must not be toggled with the VRR state. +* Only DCE gates vupdate on VRR. +*/ +bool vrr_gates_vupdate =amdgpu_ip_version (adev,DCE_HWIP ,0 ) ==0 ;if (!old_vrr_active && new_vrr_active) {/* Transition VRR inactive -> active: @@ -10097,7 +10105,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,* We also need vupdate irq for the actual core vblank handling * at end of vblank. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 );WARN_ON (drm_crtc_vblank_get (new_state->base.crtc) !=0 );drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR off->on: Get vblank ref\n" , __func__, new_state->base.crtc->base.id);@@ -10113,7 +10122,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,/* Transition VRR active -> inactive: * Allow vblank irq disable again for fixed refresh rate. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 );drm_crtc_vblank_put (new_state->base.crtc);drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR on->off: Drop vblank ref\n" , __func__, new_state->base.crtc->base.id);Feel free to fold some version of this into the next version if it makes sense, or pick it up with my s-o-b.
Thanks,
Matthew
Leo Li
maintainerRe: [PATCH 2/3] drm/amd/display: check GRPH_FLIP status before sending event
In reply to Michel DänzerHi Michel, thanks for the review!
Quoted 9 lines · Michel Dänzer
Quoted 8 lines · Michel Dänzer
Quoted 5 lines · On 6/16/26 22:18, [email protected] wrote:
* Add a
flip_programmedcompletion. Arm it (reinit_completion) underevent_locktogether withprepare_flip_isr(), and signal it (complete_all) right afterupdate_planes_and_stream_adapter()programs the flip. It starts in the "completed" state at crtc init.Is the completion really necessary? Wouldn't moving the
acrtc->pflip_status=AMDGPU_FLIP_SUBMITTEDassignment after the flip programming suffice?
I think this would create a window between HW programming and arming acrtc->event and pflip_status, where HW latch (VUPDATE_NO_LOCK) can fire and run the handler:
Thread A: Thread B:
PROGRAM(flip_n)
LATCH(flip_n)
vupdate_no_lock_handler(flip_n) # no event armed; skip sending
ARM(flip_n)
Ah, but the flip_programmed completion has the same issue...
Thread A: Thread B:
INIT_(flip_programmed)
ARM(flip_n)
PROGRAM(flip_n)
LATCH(flip_n)
vupdate_no_lock_handler(flip_n) # flip_programmed not complete; skip sending
COMPLETE(flip_programmed)
Quoted 3 lines
Or even just moving the unlocking of
event_lockafter the flip programming.
I initially thought about doing so. But the possibility of update_planes_and_stream_adapter() sleeping made me think otherwise.
I suppose the worst case scenario with arming acrtc->event/pflip_status after programming is we deliver the event a frame later than it needs to be (which is also the case with the current patch), thus stalling the next commit via flip_done, and making userspace think it missed the programming deadline. That is, if the exact scenario above happens.
If it sounds good to you, I'll roll that into v2 as well.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4
-4@@ -4384,17 +4384,17 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* from 0 -> n planes we have to skip a hardware generated event * and rely on sending it from software. */ +spin_lock_irqsave (&pcrtc->dev->event_lock, flags);if (acrtc_attach->base.state->event && acrtc_state->active_planes >0 ) {drm_crtc_vblank_get (pcrtc); -spin_lock_irqsave (&pcrtc->dev->event_lock, flags); -WARN_ON (acrtc_attach->pflip_status !=AMDGPU_FLIP_NONE ); +/* Arm flip completion handling and event delivery */ +reinit_completion (&acrtc_attach->dm_irq_params.flip_programmed);prepare_flip_isr (acrtc_attach); - -spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags); } +spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags);
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, · line 4400
Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-0if (acrtc_state->stream) {if (acrtc_state->freesync_vrr_info_changed)Pulling
event_lockout of the if block doesn't make any difference (other than locking it unnecessarily when the block isn't entered 🙂, does it?
FWIU the crtc_state->event pointer itself should be guarded under event_lock, since it can be NULL'd concurrently.
- Leo
Re: [PATCH 2/3] drm/amd/display: check GRPH_FLIP status before sending event
Quoted 9 lines · Leo Li
Quoted 8 lines · Michel Dänzer
Quoted 7 lines · Michel Dänzer
Quoted 5 lines · On 6/16/26 22:18, [email protected] wrote:
* Add a
flip_programmedcompletion. Arm it (reinit_completion) underevent_locktogether withprepare_flip_isr(), and signal it (complete_all) right afterupdate_planes_and_stream_adapter()programs the flip. It starts in the "completed" state at crtc init.
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Is the completion really necessary? Wouldn't moving the
acrtc->pflip_status=AMDGPU_FLIP_SUBMITTEDassignment after the flip programming suffice?[...]
Quoted 1 line
Quoted 1 line
Or even just moving the unlocking of
event_lockafter the flip programming.I initially thought about doing so. But the possibility of
update_planes_and_stream_adapter()sleeping made me think otherwise.
That is a problem.
If the flip programming could be done while holding event_lock, this could be made 100% reliable, avoiding the issue below.
Quoted 1 line
I suppose the worst case scenario with arming acrtc->event/pflip_status after programming is we deliver the event a frame later than it needs to be (which is also the case with the current patch), thus stalling the next commit via
flip_done, and making userspace think it missed the programming deadline.
Yep. Hopefully won't happen too often in practice?
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4
-4@@ -4384,17 +4384,17 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* from 0 -> n planes we have to skip a hardware generated event * and rely on sending it from software. */ +spin_lock_irqsave (&pcrtc->dev->event_lock, flags);if (acrtc_attach->base.state->event && acrtc_state->active_planes >0 ) {drm_crtc_vblank_get (pcrtc); -spin_lock_irqsave (&pcrtc->dev->event_lock, flags); -WARN_ON (acrtc_attach->pflip_status !=AMDGPU_FLIP_NONE ); +/* Arm flip completion handling and event delivery */ +reinit_completion (&acrtc_attach->dm_irq_params.flip_programmed);prepare_flip_isr (acrtc_attach); - -spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags); } +spin_unlock_irqrestore (&pcrtc->dev->event_lock, flags);
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, · line 4400
Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-0if (acrtc_state->stream) {if (acrtc_state->freesync_vrr_info_changed)Pulling
event_lockout of the if block doesn't make any difference (other than locking it unnecessarily when the block isn't entered 🙂, does it?FWIU the
crtc_state->eventpointer itself should be guarded underevent_lock, since it can be NULL'd concurrently.
Gotcha, I was fooled by the acrtc_attach->base.state->event disguise. :)
Signature · 2 lines
Earthling Michel Dänzer \ GNOME / Xwayland / Mesa developer https://redhat.com \ Libre software enthusiast
Re: [PATCH 1/3] drm/amd/display: consolidate DCN vblank/flip handling onto vupdate_no_lock
In reply to Leo LiQuoted 27 lines · Leo Li
Quoted 24 lines · Matthew Schwartz
On 6/16/26 1:18 PM, [email protected] wrote:
[...]
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0@@ -281,7 +281,14 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)drm_crtc_vblank_restore (crtc); }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 291
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +8
-1-if (dc_supports_vrr (dm->dc->ctx->dce_version)) { +/* +* On DCN, VUPDATE_NO_LOCK is the single OTG interrupt used to deliver +* vblank and pageflip completion events, so enable it whenever vblank +* 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); + }else if (dc_supports_vrr (dm->dc->ctx->dce_version)) {Hi Leo (dropping Stable),
Quoted 7 lines
Quoted 1 line
This arms
VUPDATE_NO_LOCKon all of DCN, butamdgpu_dm_handle_vrr_transition()still disables it when switching from VRR active -> inactive. This causes a newflip_donetimed out event when a compositor like gamescope disables VRR while it's already active.Good catch, I wonder why the
kms_vrrIGT tests did not catch this... I'll roll your fix into v2 with your signed-off-by and co-authored-by.Thanks,
Leo
The Stable backport is also needed for 7.1.1. I tested it specifically there, and ran into the same exact VRR transition issue, unknowingly. Except in this case, it was with LabWC, configured with VRR set to fullscreen only, so it was disabling it immediately on configure. Oh well. I'm building 7.1.1 with the backport and this workaround rolled into it now, and will report back if there are any further issues.
-Christopher
Quoted 52 lines
Quoted 51 lines
I had to fix it up with something like:
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +12
-2@@ -10085,8 +10085,16 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,struct dm_crtc_state *old_state, struct dm_crtc_state *new_state) { + struct amdgpu_device *adev = dm->adev;bool old_vrr_active =amdgpu_dm_crtc_vrr_active (old_state);bool new_vrr_active =amdgpu_dm_crtc_vrr_active (new_state); +/* +* On DCN, VUPDATE_NO_LOCK is the sole vblank and pageflip completion +* source and amdgpu_dm_crtc_set_vblank() keeps it armed whenever +* vblank is enabled, so it must not be toggled with the VRR state. +* Only DCE gates vupdate on VRR. +*/ +bool vrr_gates_vupdate =amdgpu_ip_version (adev,DCE_HWIP ,0 ) ==0 ;if (!old_vrr_active && new_vrr_active) {/* Transition VRR inactive -> active: @@ -10097,7 +10105,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,* We also need vupdate irq for the actual core vblank handling * at end of vblank. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 );WARN_ON (drm_crtc_vblank_get (new_state->base.crtc) !=0 );drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR off->on: Get vblank ref\n" , __func__, new_state->base.crtc->base.id);@@ -10113,7 +10122,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,/* Transition VRR active -> inactive: * Allow vblank irq disable again for fixed refresh rate. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 );drm_crtc_vblank_put (new_state->base.crtc);drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR on->off: Drop vblank ref\n" , __func__, new_state->base.crtc->base.id);Feel free to fold some version of this into the next version if it makes sense, or pick it up with my s-o-b.
Thanks,
Matthew
Re: [PATCH 1/3] drm/amd/display: consolidate DCN vblank/flip handling onto vupdate_no_lock
Quoted 38 lines · Christopher Snowhill
Quoted 27 lines · Leo Li
Quoted 24 lines · Matthew Schwartz
On 6/16/26 1:18 PM, [email protected] wrote:
[...]
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0@@ -281,7 +281,14 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)drm_crtc_vblank_restore (crtc); }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 291
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +8
-1-if (dc_supports_vrr (dm->dc->ctx->dce_version)) { +/* +* On DCN, VUPDATE_NO_LOCK is the single OTG interrupt used to deliver +* vblank and pageflip completion events, so enable it whenever vblank +* 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); + }else if (dc_supports_vrr (dm->dc->ctx->dce_version)) {Hi Leo (dropping Stable),
Quoted 7 lines
Quoted 1 line
This arms
VUPDATE_NO_LOCKon all of DCN, butamdgpu_dm_handle_vrr_transition()still disables it when switching from VRR active -> inactive. This causes a newflip_donetimed out event when a compositor like gamescope disables VRR while it's already active.Good catch, I wonder why the
kms_vrrIGT tests did not catch this... I'll roll your fix into v2 with your signed-off-by and co-authored-by.Thanks,
Leo
Quoted 8 lines
The Stable backport is also needed for 7.1.1. I tested it specifically there, and ran into the same exact VRR transition issue, unknowingly. Except in this case, it was with LabWC, configured with VRR set to fullscreen only, so it was disabling it immediately on configure. Oh well. I'm building 7.1.1 with the backport and this workaround rolled into it now, and will report back if there are any further issues.
-Christopher
Dang, looks like I don't get a free pass with this patch, since the function in question doesn't plumb that state directly in 7.1.1.
Quoted 53 lines
Quoted 53 lines
Quoted 52 lines
I had to fix it up with something like:
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +12
-2@@ -10085,8 +10085,16 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,struct dm_crtc_state *old_state, struct dm_crtc_state *new_state) { + struct amdgpu_device *adev = dm->adev;bool old_vrr_active =amdgpu_dm_crtc_vrr_active (old_state);bool new_vrr_active =amdgpu_dm_crtc_vrr_active (new_state); +/* +* On DCN, VUPDATE_NO_LOCK is the sole vblank and pageflip completion +* source and amdgpu_dm_crtc_set_vblank() keeps it armed whenever +* vblank is enabled, so it must not be toggled with the VRR state. +* Only DCE gates vupdate on VRR. +*/ +bool vrr_gates_vupdate =amdgpu_ip_version (adev,DCE_HWIP ,0 ) ==0 ;if (!old_vrr_active && new_vrr_active) {/* Transition VRR inactive -> active: @@ -10097,7 +10105,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,* We also need vupdate irq for the actual core vblank handling * at end of vblank. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 );WARN_ON (drm_crtc_vblank_get (new_state->base.crtc) !=0 );drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR off->on: Get vblank ref\n" , __func__, new_state->base.crtc->base.id);@@ -10113,7 +10122,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,/* Transition VRR active -> inactive: * Allow vblank irq disable again for fixed refresh rate. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 );drm_crtc_vblank_put (new_state->base.crtc);drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR on->off: Drop vblank ref\n" , __func__, new_state->base.crtc->base.id);Feel free to fold some version of this into the next version if it makes sense, or pick it up with my s-o-b.
Thanks,
Matthew
Re: [PATCH 1/3] drm/amd/display: consolidate DCN vblank/flip handling onto vupdate_no_lock
Quoted 48 lines · Christopher Snowhill
Quoted 45 lines · Christopher Snowhill
Quoted 27 lines · Leo Li
Quoted 24 lines · Matthew Schwartz
On 6/16/26 1:18 PM, [email protected] wrote:
[...]
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0@@ -281,7 +281,14 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)drm_crtc_vblank_restore (crtc); }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 291
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +8
-1-if (dc_supports_vrr (dm->dc->ctx->dce_version)) { +/* +* On DCN, VUPDATE_NO_LOCK is the single OTG interrupt used to deliver +* vblank and pageflip completion events, so enable it whenever vblank +* 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); + }else if (dc_supports_vrr (dm->dc->ctx->dce_version)) {Hi Leo (dropping Stable),
Quoted 7 lines
Quoted 1 line
This arms
VUPDATE_NO_LOCKon all of DCN, butamdgpu_dm_handle_vrr_transition()still disables it when switching from VRR active -> inactive. This causes a newflip_donetimed out event when a compositor like gamescope disables VRR while it's already active.Good catch, I wonder why the
kms_vrrIGT tests did not catch this... I'll roll your fix into v2 with your signed-off-by and co-authored-by.Thanks,
LeoThe Stable backport is also needed for 7.1.1. I tested it specifically there, and ran into the same exact VRR transition issue, unknowingly. Except in this case, it was with LabWC, configured with VRR set to fullscreen only, so it was disabling it immediately on configure. Oh well. I'm building 7.1.1 with the backport and this workaround rolled into it now, and will report back if there are any further issues.
Quoted 4 lines
Quoted 1 line
-Christopher
Dang, looks like I don't get a free pass with this patch, since the function in question doesn't plumb that state directly in 7.1.1.
Looks like I can do some backporting too. Here's a free backport of the same patch series to 7.1.1:
(quoted diff) +0 -0
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index c198a0b..da7ed11 100644
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -0
@@ -9851,8 +9851,16 @@ static void update_stream_irq_parameters(static void amdgpu_dm_handle_vrr_transition (struct dm_crtc_state *old_state,struct dm_crtc_state *new_state) { +struct amdgpu_device *adev =drm_to_adev (new_state->base.crtc->dev);bool old_vrr_active =amdgpu_dm_crtc_vrr_active (old_state);bool new_vrr_active =amdgpu_dm_crtc_vrr_active (new_state); +/* +* On DCN, VUPDATE_NO_LOCK is the sole vblank and pageflip completion +* source and amdgpu_dm_crtc_set_vblank() keeps it armed whenever +* vblank is enabled, so it must not be toggled with the VRR state. +* Only DCE gates vupdate on VRR. +*/ +bool vrr_gates_vupdate =amdgpu_ip_version (adev,DCE_HWIP ,0 ) ==0 ;if (!old_vrr_active && new_vrr_active) {/* Transition VRR inactive -> active:
@@ -9863,7 +9871,8 @@ static void amdgpu_dm_handle_vrr_transition(struct
dm_crtc_state *old_state,
* We also need vupdate irq for the actual core vblank
handling
* at end of vblank.
*/
- WARN_ON(amdgpu_dm_crtc_set_vupdate_irq(new_state->base.crtc,
true) != 0);
+ if (vrr_gates_vupdate)
+
WARN_ON(amdgpu_dm_crtc_set_vupdate_irq(new_state->base.crtc, true) != 0);
WARN_ON(drm_crtc_vblank_get(new_state->base.crtc) != 0);
drm_dbg_driver(new_state->base.crtc->dev, "%s: crtc=%u VRR
off->on: Get vblank ref\n",
__func__, new_state->base.crtc->base.id);
@@ -9871,7 +9880,8 @@ static void amdgpu_dm_handle_vrr_transition(struct
dm_crtc_state *old_state,
/* Transition VRR active -> inactive:
* Allow vblank irq disable again for fixed refresh rate.
*/- WARN_ON(amdgpu_dm_crtc_set_vupdate_irq(new_state->base.crtc,
false) != 0);
+ if (vrr_gates_vupdate)
+
WARN_ON(amdgpu_dm_crtc_set_vupdate_irq(new_state->base.crtc, false) != 0);
drm_crtc_vblank_put(new_state->base.crtc);
drm_dbg_driver(new_state->base.crtc->dev, "%s: crtc=%u VRR
on->off: Drop vblank ref\n",
__func__, new_state->base.crtc->base.id);Cool, only one line changed. And no need to plumb the function parameter.
Quoted 54 lines
Quoted 54 lines
Quoted 54 lines
Quoted 53 lines
I had to fix it up with something like:
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +12
-2@@ -10085,8 +10085,16 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,struct dm_crtc_state *old_state, struct dm_crtc_state *new_state) { + struct amdgpu_device *adev = dm->adev;bool old_vrr_active =amdgpu_dm_crtc_vrr_active (old_state);bool new_vrr_active =amdgpu_dm_crtc_vrr_active (new_state); +/* +* On DCN, VUPDATE_NO_LOCK is the sole vblank and pageflip completion +* source and amdgpu_dm_crtc_set_vblank() keeps it armed whenever +* vblank is enabled, so it must not be toggled with the VRR state. +* Only DCE gates vupdate on VRR. +*/ +bool vrr_gates_vupdate =amdgpu_ip_version (adev,DCE_HWIP ,0 ) ==0 ;if (!old_vrr_active && new_vrr_active) {/* Transition VRR inactive -> active: @@ -10097,7 +10105,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,* We also need vupdate irq for the actual core vblank handling * at end of vblank. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, true) !=0 );WARN_ON (drm_crtc_vblank_get (new_state->base.crtc) !=0 );drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR off->on: Get vblank ref\n" , __func__, new_state->base.crtc->base.id);@@ -10113,7 +10122,8 @@ static void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm,/* Transition VRR active -> inactive: * Allow vblank irq disable again for fixed refresh rate. */ -WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 ); +if (vrr_gates_vupdate) +WARN_ON (amdgpu_dm_crtc_set_vupdate_irq (new_state->base.crtc, false) !=0 );drm_crtc_vblank_put (new_state->base.crtc);drm_dbg_driver (new_state->base.crtc->dev,"%s: crtc=%u VRR on->off: Drop vblank ref\n" , __func__, new_state->base.crtc->base.id);Feel free to fold some version of this into the next version if it makes sense, or pick it up with my s-o-b.
Thanks,
Matthew