Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/msm/dpu: unconditional cross-CRTC vblank wait in
  dpu_kms_prepare_commit()
- [High] drm/msm/dpu: unserialized cross-CRTC SSPP handoff in single
  atomic commit
--

commit a58356a3168d597e094d7d9c722e69170e0b36c9
Author: Nabige Aala <[email protected]>

drm/msm: serialize cross-CRTC SSPP reassignment to fix underrun

This commit vetoes async updates when SSPP ownership changes across CRTCs
and tracks CRTC commits in dpu_global_state->pending_commits so subsequent
commits wait for prior resource updates to complete.

> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c 
> b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
> index cc86e06790c4f..0950983c29112 100644
> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
> @@ -356,6 +356,9 @@ dpu_kms_global_duplicate_state(struct drm_private_obj 
> *obj)
>  
>       __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
>  
> +     /* The new state will track its own commits during commit setup. */
> +     memset(state->pending_commits, 0, sizeof(state->pending_commits));
> +
>       return &state->base;
>  }

[ ... ]

> @@ -462,6 +471,77 @@ static int dpu_kms_check_mode_changed(struct msm_kms 
> *kms, struct drm_atomic_com
>       return 0;
>  }
>  
> +static int dpu_kms_atomic_commit_setup(struct msm_kms *kms,
> +                                    struct drm_atomic_commit *state)
> +{
> +     struct dpu_kms *dpu_kms = to_dpu_kms(kms);
> +     struct drm_private_state *priv_state;
> +     struct dpu_global_state *global_state;
> +     struct drm_crtc_state *crtc_state;
> +     struct drm_crtc *crtc;
> +     int i;
> +
> +     priv_state = drm_atomic_get_new_private_obj_state(state, 
> &dpu_kms->global_state);
> +     if (!priv_state)
> +             return 0;
> +
> +     global_state = to_dpu_global_state(priv_state);
> +     for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
> +             if (crtc_state->commit)
> +                     global_state->pending_commits[drm_crtc_index(crtc)] =
> +                             drm_crtc_commit_get(crtc_state->commit);
> +     }
> +
> +     return 0;
> +}
> +
> +static void dpu_kms_prepare_commit(struct msm_kms *kms, struct 
> drm_atomic_commit *state)
> +{
> +     struct dpu_kms *dpu_kms = to_dpu_kms(kms);
> +     struct drm_private_state *priv_state;
> +     struct dpu_global_state *global_state;
> +     unsigned int i;
> +     int ret;
> +
> +     priv_state = drm_atomic_get_old_private_obj_state(state, 
> &dpu_kms->global_state);
> +     if (!priv_state)
> +             return;
> +
> +     global_state = to_dpu_global_state(priv_state);
> +     /*
> +      * Virtual planes on different CRTCs can reuse the same SSPP. The
> +      * per-CRTC and per-plane dependencies do not cover that handoff.
> +      * Wait for the previous resource update before programming hardware.
> +      */
> +     for (i = 0; i < ARRAY_SIZE(global_state->pending_commits); i++) {
> +             if (!global_state->pending_commits[i])
> +                     continue;
> +
> +             ret = drm_crtc_commit_wait(global_state->pending_commits[i]);
> +             if (ret)
> +                     drm_err(kms->dev, "CRTC %u resource commit wait timed 
> out\n", i);
> +     }
> +}

[Severity: High]
Does dpu_kms_prepare_commit() serialize every plane update across all
CRTCs even when no SSPP changes ownership?

In dpu_crtc_atomic_check(), any commit with planes_changed or zpos_changed
calls dpu_crtc_reassign_planes() or dpu_crtc_assign_planes(), both of
which call dpu_kms_get_global_state() and duplicate dpu_kms->global_state:

drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c:dpu_crtc_atomic_check() {
        ...
        if (crtc_state->planes_changed || crtc_state->zpos_changed) {
                if (dpu_use_virtual_planes)
                        rc = dpu_crtc_reassign_planes(crtc, crtc_state);
                else
                        rc = dpu_crtc_assign_planes(crtc, crtc_state);
                if (rc < 0)
                        return rc;
        }
        ...
}

Because dpu_kms_atomic_commit_setup() records crtc_state->commit whenever
global_state is present in the atomic state, and non-async commits only
signal flip_done and hw_done after wait_flush() finishes waiting for
vblank, every ordinary page flip on one CRTC forces the next page flip or
cursor update on another CRTC to block in drm_crtc_commit_wait() until the
first CRTC's vblank completes.  This throttles independent displays (such
as a 120Hz panel paired with a 60Hz external monitor) to each other's
vblank.  Note that if dpu_kms_prepare_commit() is changed to wait only
when sspp_to_crtc_id[] changes, dpu_kms_global_duplicate_state() also
cannot unconditionally zero all of pending_commits[], or an intermediate
commit on an unrelated CRTC would drop the pending commit reference before
the destination CRTC waits on it.

[Severity: High]
Can an SSPP still be reassigned across two active CRTCs without waiting
for the source CRTC's vblank when both CRTCs are updated in the same
atomic commit?

When a single atomic commit updates planes on both CRTC 0 and CRTC 1,
dpu_crtc_reassign_planes() runs for CRTC 0 first and calls
dpu_rm_release_all_sspp(), clearing global_state->sspp_to_crtc_id[i] = 0
in the new global state.  When dpu_crtc_reassign_planes() then runs for
CRTC 1 in the same atomic_check, dpu_rm_try_sspp() only checks whether
global_state->sspp_to_crtc_id[i] is non-zero in the new state and can
immediately assign that same SSPP to CRTC 1.

During commit, dpu_kms_prepare_commit() only waits on
old_priv_state->pending_commits[] from prior commits, which are already
complete.  drm_atomic_helper_commit_planes() then programs the shared SSPP
registers for CRTC 1 and flushes both CRTCs before CRTC 0 has latched the
SSPP detach at its next vblank, allowing both CRTCs to drive the same SSPP
simultaneously and trigger an underrun.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to