drm/msm/dpu: count the pending frame before kicking it off
Subsystems (4)
PATCH 1/1 drm/msm/dpu: count the pending frame before kicking it off
dpu_crtc_commit_kickoff() increments frame_pending only after dpu_encoder_kickoff() has sent the frame to the hardware. If the frame completes before the increment, dpu_crtc_frame_event_work() sees frame_pending == 0 and ignores the frame-done event. The increment that follows is never matched, so the count stays one too high until dpu_crtc_disable() resets it.
With frame_pending stuck at 1 or more:
- dpu_encoder_resource_control(FRAME_DONE) sees a pending count above 1 on every frame and never queues delayed_off_work. A video-mode encoder therefore never reaches ENTER_IDLE and keeps its vsync interrupt registered for as long as the display is on.
- dpu_crtc_frame_event_work() never sees the count drop to zero, so dpu_core_perf_crtc_release_bw() is never called.
On an X1E80100 laptop with a 120 Hz eDP panel this left the vsync interrupt firing 120 times a second on an idle desktop: 14,407 vblank callbacks against 21 commits in 120 s, with no vblank events requested by userspace. Every frame-done took the frame_event_more_pending path (591 of 591 in one trace) and the encoder never entered idle. After a suspend cycle reset the count, the same desktop showed 3 commits, 3 frame_event_done, 3 encoder idle transitions and 25 MDSS interrupts in 60 s.
Until commit ad06972d5365 ("drm/msm/dpu: Reorder encoder kickoff for CWB") the increment came before the kickoff. Move it back there, and undo it if the clone-mode kickoff fails before touching the hardware.
---
Tested on a Dell XPS 13 9345 (X1E80100, 120 Hz eDP, video mode) with v7.3-rc6 based kernels. With this patch the count no longer leaks in normal use: a 120 s trace 50 minutes after boot showed 22 commits, 22 frame_event_done and 22 encoder idle transitions; about 2 hours after boot there were 27,479 vblanks against 16,693 commits over 6,040 s, where a leaked count gives about 725,000. Not tested: clone mode or writeback, which this machine does not have.
Jun Nie's "drm/msm/dpu: delete timeout timer when encoder is not busy"
[1] hits the same window: the frame-done interrupt arriving before dpu_crtc_commit_kickoff() gets past dpu_encoder_kickoff().
[1] https://lore.kernel.org/r/[email protected]
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +11 -7
@@ -1105,9 +1105,19 @@ void dpu_crtc_commit_kickoff(struct drm_crtc *crtc) } } +/* The frame-done event may be handled before the kickoff below returns. */ +if (atomic_inc_return (&dpu_crtc->frame_pending) ==1 ) { +/* acquire bandwidth and other resources */ +DRM_DEBUG_ATOMIC ("crtc%d first commit\n" , crtc->base.id); + }else { +DRM_DEBUG_ATOMIC ("crtc%d commit\n" , crtc->base.id); + } +if (drm_crtc_in_clone_mode (crtc->state)) { -if (dpu_crtc_kickoff_clone_mode (crtc)) +if (dpu_crtc_kickoff_clone_mode (crtc)) { +atomic_dec (&dpu_crtc->frame_pending); goto end; + } }else {/* * Encoder will flush/start now, unless it has a tx pending.
@@ -1126,12 +1136,6 @@ void dpu_crtc_commit_kickoff(struct drm_crtc *crtc) } } -if (atomic_inc_return (&dpu_crtc->frame_pending) ==1 ) { -/* acquire bandwidth and other resources */ -DRM_DEBUG_ATOMIC ("crtc%d first commit\n" , crtc->base.id); - }else -DRM_DEBUG_ATOMIC ("crtc%d commit\n" , crtc->base.id); - dpu_crtc->play_count++;reinit_completion (&dpu_crtc->frame_done_comp);
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
Signature · 1 line
2.56.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] drm/msm/dpu: bandwidth leak due to missed frame_pending 0-transition in error path --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/msm/dpu: bandwidth leak due to missed frame_pending 0-transition in error path --
commit 09d9db34ac4a7e898d02571dc93cd542a14a8979
Author: Michael Burch <[email protected]>
drm/msm/dpu: count the pending frame before kicking it off
This commit moves the increment of frame_pending in dpu_crtc_commit_kickoff() to occur before kickoff to prevent event worker races. It also adds a rollback decrement in the clone mode error path.
Quoted 4 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +0
-0
[ ... ]
Quoted 6 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +2
-0@@ -1105,9 +1105,19 @@ void dpu_crtc_commit_kickoff(struct drm_crtc *crtc) } } +/* The frame-done event may be handled before the kickoff below returns. */ +if (atomic_inc_return (&dpu_crtc->frame_pending) ==1 ) {
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c void dpu_crtc_commit_kickoff(struct drm_crtc *crtc) · line 1118
Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +8
-1+/* acquire bandwidth and other resources */ +DRM_DEBUG_ATOMIC ("crtc%d first commit\n" , crtc->base.id); + }else { +DRM_DEBUG_ATOMIC ("crtc%d commit\n" , crtc->base.id); + } +if (drm_crtc_in_clone_mode (crtc->state)) { -if (dpu_crtc_kickoff_clone_mode (crtc)) +if (dpu_crtc_kickoff_clone_mode (crtc)) { +atomic_dec (&dpu_crtc->frame_pending);
[Severity: Medium]
Does this unconditional atomic_dec() bypass the 0-transition check required to release CRTC bandwidth, causing a bandwidth leak?
If Frame N-1 is executing and Frame N is committed, dpu_crtc_commit_kickoff() bumps frame_pending to 2. If dpu_crtc_kickoff_clone_mode() fails, it decrements the count back.
If the hardware interrupt for Frame N-1 fires concurrently and its event worker runs, it will decrement the count to 1, skipping the dpu_core_perf_crtc_release_bw() call that requires a 1-to-0 transition.
The error path then blindly decrements the count to 0 with atomic_dec() and also skips the dpu_core_perf_crtc_release_bw() call, permanently leaking the allocated bandwidth until the CRTC is fully disabled.
Quoted 2 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c +1
-0goto end; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1