Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/i915: intel_atomic_carry_over_state() skips enabled
  DPMS-off CRTCs
- [High] drm/i915: uninitialized max_requested_bpc and scaling_mode on
  created states
- [Medium] drm/i915: missing NV12 link carry-over in
  intel_atomic_carry_over_state()
--

commit 1fe4500ef10219b7da036ae0e043737aa33211ff
Author: Maxime Ripard <[email protected]>

drm/i915: Carry the current state over created states

This commit adds intel_atomic_carry_over_state() to copy the current CRTC
hardware state and plane scaler assignment into newly created states during
DRM_MODE_ATOMIC_RESET commits.

> diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
> b/drivers/gpu/drm/i915/display/intel_display.c
> index 1172e48daf235..d645203104a77 100644
> --- a/drivers/gpu/drm/i915/display/intel_display.c
> +++ b/drivers/gpu/drm/i915/display/intel_display.c
> @@ -6519,6 +6519,116 @@ static int intel_atomic_check_config_and_link(struct 
> intel_atomic_state *state)
>  
>       return ret;
>  }
[ ... ]
> +static int intel_atomic_carry_over_state(struct intel_atomic_state *state)
> +{
> +     struct intel_crtc_state *old_crtc_state, *new_crtc_state;
> +     struct intel_plane_state *old_plane_state, *new_plane_state;
> +     struct intel_crtc *crtc;
> +     struct intel_plane *plane;
> +     int i;
> +
> +     for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
> +                                         new_crtc_state) {
> +             struct intel_crtc_state *carried_state;
> +
> +             if (new_crtc_state->cpu_transcoder != INVALID_TRANSCODER ||
> +                 !old_crtc_state->hw.active)
> +                     continue;

[Severity: High]
Does checking !old_crtc_state->hw.active skip CRTCs that are enabled with
DPMS off (old_crtc_state->hw.enable == true, hw.active == false)?

In i915, pipe configuration, cpu_transcoder, DPLL reservations, DP tunnel
bandwidth, joiner pipes, and plane scalers are all allocated and tracked
whenever crtc_state->hw.enable is true, even while hw.active is false.
When a DRM_MODE_ATOMIC_RESET commit hits an enabled but inactive CRTC,
skipping the carry-over drops intel_dpll and icl_port_dplls without
releasing them (leaking the shared DPLL reservation in
dpll_state->pipe_mask and triggering a WARN in intel_dpll_crtc_get() on
later modesets), loses dp_tunnel_ref and joiner_pipes, and leaves
new_crtc_state->scaler_state empty while the plane loop below still copies
old_plane_state->scaler_id >= 0 into new_plane_state->scaler_id, allowing
intel_atomic_setup_scaler() to assign the same hardware scaler ID twice.
On G4X/VLV/CHV, intel_crtc_prepare_cleared_state() also preserves
crtc_state->wm even on disabled CRTCs.

[ ... ]

> +     for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
> +                                           new_plane_state, i) {
> +             if (new_plane_state->scaler_id < 0 &&
> +                 old_plane_state->scaler_id >= 0)
> +                     new_plane_state->scaler_id =
> +                             old_plane_state->scaler_id;
> +     }

[Severity: Medium]
Should this plane loop also carry over old_plane_state->planar_linked_plane
and old_plane_state->is_y_plane?

On DISPLAY_VER >= 11, scanning out a planar YUV framebuffer links the
visible UV plane to an internal Y plane whose uapi.crtc is NULL, so the Y
plane is not in crtc->state->plane_mask.  When a DRM_MODE_ATOMIC_RESET
commit does not initially include the internal Y plane (for example, from
a DRM lease covering only the primary/UV plane) or switches the UV plane
to a non-planar format, intel_joiner_affected_planes() and
unlink_nv12_plane() rely on new_plane_state->planar_linked_plane and
is_y_plane to pull in and unlink the Y plane:

drivers/gpu/drm/i915/display/intel_plane.c:unlink_nv12_plane() {
        if (!plane_state->planar_linked_plane)
                return;

        plane_state->planar_linked_plane = NULL;

        if (!plane_state->is_y_plane)
                return;
    ...
        crtc_state->enabled_planes &= ~BIT(plane->id);
        crtc_state->active_planes &= ~BIT(plane->id);
}

Because created plane states have planar_linked_plane == NULL and
is_y_plane == false, BIT(y_plane->id) remains set in
new_crtc_state->enabled_planes and active_planes, leaving the Y plane
programmed in hardware or causing icl_check_nv12_planes() to run out of
free Y planes and fail with -EINVAL.

> +
> +     return 0;
> +}

[Severity: High]
Does intel_atomic_carry_over_state() also need to restore connector state
defaults such as max_requested_bpc, max_bpc, and scaling_mode on created
connector states?

At init time, drm_connector_attach_max_bpc_property() initializes
state->max_requested_bpc and state->max_bpc to the connector maximum, and
intel_attach_scaling_mode_property() sets state->scaling_mode to
DRM_MODE_SCALE_ASPECT.  During DRM_MODE_ATOMIC_RESET,
intel_digital_connector_create_state() zero-allocates the connector state
and calls __drm_atomic_helper_connector_state_init(), leaving
max_requested_bpc, max_bpc, and scaling_mode at 0 whenever userspace does
not explicitly set those properties in the reset commit.

As a result, drm_atomic_helper_check_modeset() and
intel_digital_connector_atomic_check() see max_requested_bpc and
scaling_mode change from their previous values and force a modeset on
active CRTCs instead of taking the nomodeset path, and the modeset then
hits MISSING_CASE(0) WARNs and returns -EINVAL in
compute_sink_pipe_bpp() -> bpc_to_bpp() and gmch_panel_fitting().

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/20261124-drm-i915-conversion-state-readout-v1-0-b7132f726...@kernel.org?part=6

Reply via email to