Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] drm/i915/dp: intel_dp_check_frl_training() leaves stale FRL
  state on failure
- [Medium] drm/i915/dp: intel_dp_pcon_frl_recover() fails with zero
  frl_rate_gbps
- [Medium] drm/i915/dp: HPD pulse races with FRL training on frl state
  and DPCD
- [Medium] drm/i915/dp: unlocked read and TOCTOU in
  intel_dp_pcon_frl_recover()
- [Medium] drm/i915/dp: intel_dp_pcon_frl_recover() may see zero
  frl_rate_gbps
--

commit c3d65efbf1eff2d1822dd7d0fa85881a9934f871
Author: Ankit Nautiyal <[email protected]>

drm/i915/dp: Store the PCON FRL rate in the crtc state

This commit computes the PCON FRL rate in intel_dp_pcon_compute_config(),
stores it in crtc_state->pcon_config.frl_rate_gbps, and uses it during FRL
training and recovery.  It also retrains an already-trained FRL link when a
new stream requires a higher rate and clears frl.trained_rate_gbps on long
HPD.

> diff --git a/drivers/gpu/drm/i915/display/intel_dp.c 
> b/drivers/gpu/drm/i915/display/intel_dp.c
> index 2e92e4898ee6b..da3aeba84c602 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp.c

[ ... ]

> @@ -4507,23 +4510,19 @@ intel_dp_pcon_is_frl_trained(struct intel_dp 
> *intel_dp,
>       return false;
>  }
>  
> -static int intel_dp_pcon_start_frl_training(struct intel_dp *intel_dp)
> +static int intel_dp_pcon_start_frl_training(struct intel_dp *intel_dp,
> +                                         const struct intel_crtc_state 
> *crtc_state)
>  {
>       struct intel_display *display = to_intel_display(intel_dp);
>  #define TIMEOUT_FRL_READY_MS 500
>  #define TIMEOUT_HDMI_LINK_ACTIVE_MS 1000
> -     int max_frl_bw, max_pcon_frl_bw, max_edid_frl_bw, ret;
> +     int max_frl_bw, ret;
>       u8 max_frl_bw_mask = 0, frl_trained_mask;
>       bool is_active;
>  
> -     max_pcon_frl_bw = intel_dp->dfp.pcon_max_frl_bw;
> -     drm_dbg(display->drm, "PCON max rate = %d Gbps\n", max_pcon_frl_bw);
> -
> -     max_edid_frl_bw = intel_dp_hdmi_sink_max_frl(intel_dp);
> -     drm_dbg(display->drm, "Sink max rate from EDID = %d Gbps\n",
> -             max_edid_frl_bw);
> -
> -     max_frl_bw = min(max_edid_frl_bw, max_pcon_frl_bw);
> +     max_frl_bw = crtc_state->pcon_config.frl_rate_gbps;
> +     drm_dbg(display->drm, "FRL max rate = %d Gbps (PCON max rate = %d 
> Gbps)\n",
> +             max_frl_bw, intel_dp->dfp.pcon_max_frl_bw);
>  
>       if (max_frl_bw <= 0)
>               return -EINVAL;

[Severity: Medium]
Can crtc_state->pcon_config.frl_rate_gbps be 0 here for a BIOS-inherited
state?

pcon_config is not read out from hardware during
intel_modeset_readout_hw_state(), and intel_dp_initial_fastset_check() does
not force a full modeset for uncompressed DP-to-HDMI PCON outputs.  Once
intel_dp_detect() populates the HDMI 2.1 sink caps, an inactive HDMI link
handled by intel_dp_pcon_frl_recover() passes that inherited crtc_state here,
causing intel_dp_pcon_start_frl_training() to return -EINVAL and fall back to
TMDS mode instead of recovering FRL.

[ ... ]

> @@ -4607,7 +4606,8 @@ int intel_dp_pcon_set_tmds_mode(struct intel_dp 
> *intel_dp)
>       return 0;
>  }
>  
> -void intel_dp_check_frl_training(struct intel_dp *intel_dp)
> +void intel_dp_check_frl_training(struct intel_dp *intel_dp,
> +                              const struct intel_crtc_state *crtc_state)
>  {
>       struct intel_display *display = to_intel_display(intel_dp);
>  
> @@ -4617,11 +4617,15 @@ void intel_dp_check_frl_training(struct intel_dp 
> *intel_dp)
>        * -sink is HDMI2.1
>        */
>       if (!(intel_dp->downstream_ports[2] & DP_PCON_SOURCE_CTL_MODE) ||
> -         !intel_dp_is_hdmi_2_1_sink(intel_dp) ||
> -         intel_dp->frl.is_trained)
> +         !intel_dp_is_hdmi_2_1_sink(intel_dp))
>               return;
>  
> -     if (intel_dp_pcon_start_frl_training(intel_dp) < 0) {
> +     /* A link trained at a lower rate than the stream needs has to be 
> retrained */
> +     if (intel_dp->frl.is_trained &&
> +         intel_dp->frl.trained_rate_gbps >= 
> crtc_state->pcon_config.frl_rate_gbps)
> +             return;
> +
> +     if (intel_dp_pcon_start_frl_training(intel_dp, crtc_state) < 0) {
>               int ret, mode;
>  
>               drm_dbg(display->drm,

[Severity: Medium]
Does this leave intel_dp->frl.is_trained and intel_dp->frl.trained_rate_gbps
stale if retraining to a higher rate fails?

When retraining runs with frl.is_trained already true,
drm_dp_pcon_frl_prepare() clears DP_PCON_ENABLE_HDMI_LINK and tears down the
previous FRL link.  If training then fails and intel_dp_check_frl_training()
switches the PCON to TMDS mode without clearing frl.is_trained and
frl.trained_rate_gbps, later modesets requesting at most the old rate take
the early return and stay stuck in TMDS mode, and intel_dp_pcon_frl_recover()
skips recovery.  Resetting both fields before drm_dp_pcon_frl_prepare() would
keep software state in sync with hardware.

> @@ -4646,6 +4650,7 @@ int intel_dp_pcon_frl_recover(struct intel_encoder 
> *encoder,
>  {
>       struct intel_display *display = to_intel_display(encoder);
>       struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
> +     struct intel_crtc *crtc;
>       u8 pipe_mask;
>       int ret;
>  
> @@ -4668,7 +4673,10 @@ int intel_dp_pcon_frl_recover(struct intel_encoder 
> *encoder,
>       if (pipe_mask == 0)
>               return 0;
>  
> -     intel_dp_check_frl_training(intel_dp);
> +     /* The stream is on the pipe of the connector's CRTC, locked above */
> +     crtc = intel_crtc_for_pipe(display, ffs(pipe_mask) - 1);
> +
> +     intel_dp_check_frl_training(intel_dp, 
> to_intel_crtc_state(crtc->base.state));
>  
>       return 0;
>  }

[Severity: Medium]
Can intel_dp_pcon_frl_recover() pass a crtc_state whose
pcon_config.frl_rate_gbps was computed as 0 before EDID detection?

During intel_display_driver_probe(), intel_initial_commit() runs before
intel_hpd_init() and intel_dp_set_edid().  Even on a Type-C port where
intel_ddi_initial_fastset_check() forces a full modeset,
intel_dp_is_hdmi_2_1_sink() is still false during that commit, leaving
frl_rate_gbps at 0 while intel_dp_stop_link_train() queues link_check_work.
Once intel_dp_detect() populates the HDMI 2.1 sink caps,
intel_dp_pcon_frl_recover() runs with frl_rate_gbps == 0, fails with -EINVAL,
and demotes the link to TMDS mode instead of training FRL.

[Severity: Medium]
Can intel_dp_pcon_frl_recover() tear down an active TMDS link because
drm_dp_pcon_hdmi_link_active() is not re-checked after
intel_dp_get_active_pipes()?

CPU0 (commit worker)                CPU1 (link_check_work)
intel_atomic_commit_tail()          intel_dp_pcon_frl_recover()
  ...                                 if (frl.is_trained ||
                                          drm_dp_pcon_hdmi_link_active())
                                        /* link not active yet */
                                      intel_dp_get_active_pipes()
                                        wait_for_connector_hw_done()
  intel_dp_check_frl_training()
    intel_dp_pcon_start_frl_training() /* fails */
    intel_dp_pcon_set_tmds_mode()
  /* hw_done signalled */
                                        /* unblocks, no re-check */
                                      intel_dp_check_frl_training()
                                        drm_dp_pcon_frl_prepare()
                                          <-- tears down active TMDS link

Because intel_dp_get_active_pipes() waits in wait_for_connector_hw_done() for
in-flight nonblocking commits, an initial check before that wait is stale by
the time it returns.  Additionally, when intel_dp_retrain_link() returns
early on !intel_dp_is_connected(intel_dp) without locking
mode_config.connection_mutex, intel_dp_pcon_frl_recover() reads
downstream_ports, dpcd, pcon_dsc_dpcd, and connector->base.display_info
before acquiring connection_mutex, racing with intel_dp_detect().

[ ... ]

> @@ -7237,6 +7245,7 @@ intel_dp_hpd_pulse(struct intel_digital_port *dig_port, 
> bool long_hpd)
>                * the next enable.
>                */
>               intel_dp->frl.is_trained = false;
> +             intel_dp->frl.trained_rate_gbps = 0;
>  
>               return IRQ_NONE;
>       }

[Severity: Medium]
Can concurrent HPD pulses race with FRL retraining on intel_dp->frl and
DP_PCON_HDMI_LINK_CONFIG_1?

intel_hpd_block() is not called until intel_dp_start_link_train(), after
intel_dp_check_frl_training(), and i915_digport_work_func() runs
intel_dp_hpd_pulse() without modeset locks:

CPU0 (modeset)                  CPU1 (i915_digport_work_func)
intel_dp_check_frl_training()
  /* is_trained still true */
  intel_dp_pcon_start_frl_training()
    drm_dp_pcon_frl_prepare()
      /* HDMI link inactive */
    drm_dp_pcon_frl_enable()
                                intel_dp_hpd_pulse()
                                  intel_dp_handle_hdmi_link_status_change()
                                    /* sees is_trained && !is_active */
                                    clear DP_PCON_ENABLE_HDMI_LINK
                                      <-- aborts FRL training
                                    frl.is_trained = false

During a rate-upgrade retrain, drm_dp_pcon_frl_prepare() drops the HDMI link
while frl.is_trained is still true and polls for up to 1.5 s, allowing a
short HPD to clear DP_PCON_ENABLE_HDMI_LINK mid-training or clobber
frl.is_trained after training succeeds.  Similarly, a long HPD resets
frl.is_trained then frl.trained_rate_gbps in reverse order from
intel_dp_pcon_start_frl_training() with no lock, which can leave is_trained
true with trained_rate_gbps == 0 or lose the disconnect reset.

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

Reply via email to