Skip to contentSkip to conversation

drm/msm/dpu: keep vblank enabled when entering self refresh

PATCH In review Ramón Jesús Miranda 3 participants 5 messages Oct 18 – Oct 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/msm/dpu: keep vblank enabled when entering self refresh

When the CRTC is disabled to enter self refresh, dpu_crtc_disable() only checks old_crtc_state->self_refresh_active, which covers leaving self refresh, and calls drm_crtc_vblank_off() otherwise. The atomic helper then expects vblank to remain enabled for a self refresh "disable" and warns:

driver disabled vblank in self-refresh

  WARNING: drivers/gpu/drm/drm_atomic_helper.c:1296 at
  drm_atomic_helper_commit_crtc_disable+0x1c0/0x1f8 [drm_kms_helper]

Skip drm_crtc_vblank_off() when the new state enters self refresh, as other drivers supporting self refresh do. drm_crtc_vblank_on() in the enable path is safe either way, it only drops the reference taken by drm_crtc_vblank_off().

Seen at every boot on a Microsoft Surface Pro 11 (X1E80100, Samsung OLED eDP panel) with eDP PSR enabled; with this change the warning is gone and self refresh keeps working.

Assisted-by Claude:claude-opus-5-5

---

drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +7 -2
@@ -1212,8 +1212,13 @@
 		return;
 	}
 
-	/* Disable/save vblank irq handling */
-	drm_crtc_vblank_off(crtc);
+	/*
+	 * Disable/save vblank irq handling, unless we are entering self
+	 * refresh: the DRM core expects vblank to stay enabled then and
+	 * warns ("driver disabled vblank in self-refresh") otherwise.
+	 */
+	if (!crtc->state->self_refresh_active)
+		drm_crtc_vblank_off(crtc);
 
 	drm_for_each_encoder_mask(encoder, crtc->dev,
 				  old_crtc_state->encoder_mask) {
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] drm/msm/dpu: missing drm_crtc_vblank_off() in dpu_crtc_disable() from PSR - [High] drm/msm/dpu…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] drm/msm/dpu: missing drm_crtc_vblank_off() in dpu_crtc_disable() from PSR
- [High] drm/msm/dpu: keeping vblank on in dpu_crtc_disable() causes unclocked MMIO --

commit 520cd497636d4c5f54127317e7ab1594f34dcf4a
Author: Ramón Jesús Miranda <[email protected]>

drm/msm/dpu: keep vblank enabled when entering self refresh

This commit skips calling drm_crtc_vblank_off() in dpu_crtc_disable() when entering self-refresh so that vblank remains enabled and avoids the warning in drm_atomic_helper_commit_crtc_disable().

Quoted 7 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +0 -0
index 77a2d1f6700d0..eedcd21b936c2 100644
@@ -1212,8 +1212,13 @@ static void dpu_crtc_disable(struct drm_crtc *crtc,
 		return;
 	}

drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c static void dpu_crtc_disable(struct drm_crtc *crtc, · line 1221

Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +7 -2
 
-	/* Disable/save vblank irq handling */
-	drm_crtc_vblank_off(crtc);
+	/*
+	 * Disable/save vblank irq handling, unless we are entering self
+	 * refresh: the DRM core expects vblank to stay enabled then and
+	 * warns ("driver disabled vblank in self-refresh") otherwise.
+	 */
+	if (!crtc->state->self_refresh_active)
+		drm_crtc_vblank_off(crtc);

[Severity: High]
What happens if the CRTC is later disabled while it is in self-refresh mode (for example via DPMS off, blanking, modeset, or system suspend, where old_crtc_state->self_refresh_active is true and new_crtc_state->self_refresh_active is false)?

Earlier in dpu_crtc_disable(), the old_crtc_state->self_refresh_active branch detaches the encoder and returns early:

drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c:dpu_crtc_disable()

	if (old_crtc_state->self_refresh_active) {
		drm_for_each_encoder_mask(encoder, crtc->dev,
					old_crtc_state->encoder_mask) {
			dpu_encoder_assign_crtc(encoder, NULL);
		}
		return;
	}

Because drm_crtc_vblank_off(crtc) was skipped when entering self-refresh and the subsequent disable returns early without calling drm_crtc_vblank_off(crtc) either, won't drm_atomic_helper_commit_crtc_disable() see drm_crtc_vblank_get(crtc) return 0 instead of -EINVAL and trigger:

	WARN_ONCE(ret != -EINVAL, "driver forgot to call drm_crtc_vblank_off()\n");

while leaving vblank enabled on the disabled CRTC after dpu_enc->crtc has been cleared to NULL? With the encoder detached, subsequent calls to dpu_crtc_get_vblank_counter() or dpu_crtc_get_scanout_position() will log "no encoder found for crtc", and dpu_encoder_toggle_vblank_for_crtc() will no longer match dpu_enc->crtc == crtc to disable the vblank IRQ or drop phys_enc->vblank_refcount.

[Severity: High]
Also, is it safe to leave DRM vblank enabled across self-refresh entry while the DPU encoder, CRTC, and clocks are powered down?

When entering self-refresh, dpu_encoder_virt_atomic_disable() stops the timing engine, disables encoder IRQs, and drops the encoder runtime PM reference via _dpu_encoder_resource_disable(), and dpu_crtc_disable() drops the CRTC runtime PM reference via pm_runtime_put_sync(crtc->dev->dev).

Because dpu_kms sets dev->vblank_disable_immediate = true, vblank->enabled is false and vblank->refcount is 0 when the idle timer enters self-refresh. With drm_crtc_vblank_off(crtc) skipped here, drm_atomic_helper_commit_crtc_disable() immediately calls:

	drm_crtc_vblank_get(crtc)
	  -> drm_vblank_enable()
	    -> msm_crtc_enable_vblank()
	      -> vblank_ctrl_queue_work(priv, crtc, true)
	drm_crtc_vblank_put(crtc)

Since disable_immediate is set, drm_crtc_vblank_put() leaves vblank->enabled as true (waiting for a hardware vblank interrupt that cannot fire while the timing generator is stopped), and vblank_ctrl_worker runs asynchronously on priv->kms->wq without holding a runtime PM reference:

	vblank_ctrl_worker()
	  -> dpu_crtc_vblank(crtc, true)
	    -> dpu_encoder_toggle_vblank_for_crtc()
	      -> dpu_encoder_phys_vid_control_vblank_irq()
	        -> dpu_core_irq_register_callback()
	          -> dpu_hw_intr_enable_irq_locked()

Once msm_atomic_commit_tail() finishes and drops the last runtime PM reference in dpu_kms_disable_commit(), dpu_runtime_suspend() disables the DPU clocks. Can vblank_ctrl_worker (or userspace calling DRM_IOCTL_WAIT_VBLANK or DRM_IOCTL_CRTC_GET_SEQUENCE while in PSR) then perform unclocked MMIO writes in dpu_hw_intr_enable_irq_locked() and unclocked MMIO reads of INTF_LINE_COUNT in dpu_crtc_get_scanout_position() -> dpu_hw_intf_get_line_count(), while also incrementing phys_enc->vblank_refcount on the disabled encoder?

Quoted 3 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +0 -0
 	drm_for_each_encoder_mask(encoder, crtc->dev,
 				  old_crtc_state->encoder_mask) {

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

Thanks for the review. Both points look right to me: the self refresh exit path in dpu_crtc_disable() returns early without drm_crtc_vblank_off(), and with vblank_disable_immediate the vblank worker can end up touching DPU interrupt registers after the last runtime PM reference is gone.

Please consider this patch withdrawn. I will look at keeping the vblank IRQ path consistent with the self refresh entry/exit (and the runtime PM reference) and send a v2 if I get it right.

Thanks,
Ramón

#3 lore raw
In reply to Ramón Jesús Miranda
Quoted 15 lines · Ramón Jesús Miranda

When the CRTC is disabled to enter self refresh, dpu_crtc_disable() only checks old_crtc_state->self_refresh_active, which covers leaving self refresh, and calls drm_crtc_vblank_off() otherwise. The atomic helper then expects vblank to remain enabled for a self refresh "disable" and warns:

driver disabled vblank in self-refresh

  WARNING: drivers/gpu/drm/drm_atomic_helper.c:1296 at
  drm_atomic_helper_commit_crtc_disable+0x1c0/0x1f8 [drm_kms_helper]

Skip drm_crtc_vblank_off() when the new state enters self refresh, as other drivers supporting self refresh do. drm_crtc_vblank_on() in the enable path is safe either way, it only drops the reference taken by drm_crtc_vblank_off().

Quoted 7 lines

Seen at every boot on a Microsoft Surface Pro 11 (X1E80100, Samsung OLED eDP panel) with eDP PSR enabled; with this change the warning is gone and self refresh keeps working.

Assisted-by Claude:claude-opus-5-5

---

FWIW this is not enough to get self-refresh to work on the Glymur Zenbook A16 and the 8280-based x13s, the screen stays black if there's no updates (it worked on the latter in the past). Dmitry promised to take a look one day.

Konrad

#4 lore raw
Quoted 4 lines · Konrad Dybcio

FWIW this is not enough to get self-refresh to work on the Glymur Zenbook A16 and the 8280-based x13s, the screen stays black if there's no updates (it worked on the latter in the past). Dmitry promised to take a look one day.

Thanks. For the record, I had already withdrawn this patch after the sashiko-bot review (the self refresh exit path, and the vblank worker touching DPU registers after the last runtime PM reference is gone). It was never meant to make self refresh work, only to avoid the atomic helper warning about vblank being disabled on a self refresh "disable".

I have no fix for the black screen, but I am happy to test whatever Dmitry comes up with on the Surface Pro 11 (x1e80100, OLED eDP panel).

Ramón