Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] drm/i915/dp: TOCTOU race before hw_done in intel_dp_pcon_frl_recover() - [Medium] drm/i915/dp: missing connected check and lock in intel_dp_pcon_frl_recover() - [Medium] drm/i915/dp: intel_dp_pcon_frl_recover() accesses AUX on suspended display - [Medium] drm/i915/dp: race between intel_dp_pcon_frl_recover() and HPD pulse work - [Low] drm/i915/dp: redundant -EALREADY check in intel_dp_pcon_frl_recover() - [Low] drm/i915/dp: missing Fixes trailer for commit 9488a030ac91 --
commit 1499fb0865199b2ac41ce39175d24f1ae4317106 Author: Ankit Nautiyal <[email protected]> > drm/i915/dp: Retrain the PCON FRL link from the link check work > > When the HDMI link of a PCON goes down while the stream is active, the > HDMI link status change handler restarts the FRL training, or falls back > to TMDS mode, directly from the short pulse handling. That runs without > any modeset lock, so it can race with a modeset that trains the link as > well, and it has no access to the state of the active stream. > > Queue the link check work instead, as it is done for the DP link > retraining, and restart the FRL training there, with the modeset locks > held and only if a stream is active. The work restarts the training only > if the FRL link is not trained and the HDMI link is not active, so it > does nothing after a fallback to TMDS mode. > > This allows to use the state of the active stream for the training in > the following changes. > > Signed-off-by: Ankit Nautiyal <[email protected]> [Severity: Low] This fixes a concurrency bug in intel_dp_handle_hdmi_link_status_change(). Should this include: Fixes: 9488a030ac91 ("drm/i915: Add support for enabling link status and recovery") > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c > b/drivers/gpu/drm/i915/display/intel_dp.c > index 272837cc6efa4..2e92e4898ee6b 100644 > --- a/drivers/gpu/drm/i915/display/intel_dp.c > +++ b/drivers/gpu/drm/i915/display/intel_dp.c > @@ -4637,6 +4637,42 @@ void intel_dp_check_frl_training(struct intel_dp > *intel_dp) > } > } > > +/* > + * Restart FRL training after the HDMI link went down while the stream is > + * active, or fall back to TMDS mode. > + */ > +int intel_dp_pcon_frl_recover(struct intel_encoder *encoder, > + struct drm_modeset_acquire_ctx *ctx) > +{ > + struct intel_display *display = to_intel_display(encoder); > + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); > + u8 pipe_mask; > + int ret; > + > + 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 || > + drm_dp_pcon_hdmi_link_active(&intel_dp->aux)) > + return 0; [Severity: Medium] Can intel_dp_pcon_frl_recover() race with intel_dp_detect() and attempt FRL recovery on a disconnected port? When the connector is disconnected, intel_dp_retrain_link() returns 0 early without taking mode_config.connection_mutex, so intel_dp_link_check() still calls intel_dp_pcon_frl_recover(). This early check then reads downstream_ports, dpcd, and connector->base.display_info without holding connection_mutex, racing with intel_dp_detect(). On disconnect while the CRTC is still active, a long HPD clears frl.is_trained while intel_dp_unset_edid() leaves downstream_ports, dpcd, and display_info populated. A pending link_check_work then passes the early check, takes connection_mutex and crtc->base.mutex, and either writes TMDS fallback DPCD registers to the disconnected port or polls in intel_dp_pcon_start_frl_training() for up to 1.5 seconds while holding those locks. Checking intel_dp_is_connected() and locking connection_mutex before reading the DPCD state would avoid this. [Severity: Medium] Can drm_dp_pcon_hdmi_link_active() issue DP AUX transfers against suspended display hardware on non-TypeC DDI ports? intel_ddi_init() only sets encoder->suspend_complete (which calls intel_encoder_link_check_flush_work()) for TypeC encoders, and __intel_display_driver_pm_suspend() does not flush display->wq.unordered. Moving FRL recovery from dig_port_work onto encoder->link_check_work allows a pending work item to run after display access, IRQs, and power domains are suspended. Because drm_dp_pcon_hdmi_link_active() runs before acquiring connection_mutex and checking pipe_mask == 0, it performs AUX MMIO and runtime PM calls against suspended hardware whenever frl.is_trained is false. Flushing link_check_work for all DDI encoders on suspend and moving the AUX read after the active-pipe check would prevent this. > + > + /* The connection mutex may be held already by the link retraining */ > + ret = drm_modeset_lock(&display->drm->mode_config.connection_mutex, > ctx); > + if (ret && ret != -EALREADY) > + return ret; [Severity: Low] Is the ret != -EALREADY check needed here? With a non-NULL ctx, drm_modeset_lock() already converts -EALREADY to 0 internally in modeset_lock(), so this branch is dead code and "if (ret) return ret;" matches intel_dp_retrain_link() and intel_dp_get_active_pipes(). > + > + ret = intel_dp_get_active_pipes(intel_dp, ctx, &pipe_mask); > + if (ret) > + return ret; > + > + /* Without an active stream the next enable trains the link */ > + if (pipe_mask == 0) > + return 0; > + > + intel_dp_check_frl_training(intel_dp); [Severity: Medium] Can intel_dp_pcon_frl_recover() tear down a working TMDS fallback link because drm_dp_pcon_hdmi_link_active() is checked before wait_for_connector_hw_done()? A non-blocking atomic modeset drops the modeset locks and runs intel_atomic_commit_tail() on display->wq.modeset. If link_check_work runs concurrently, intel_dp_pcon_frl_recover() reads frl.is_trained and DP_PCON_HDMI_TX_LINK_STATUS before intel_dp_get_active_pipes() waits on hw_done, and never re-checks them afterward (unlike intel_dp_retrain_link(), which re-checks intel_dp_needs_link_retrain()): CPU0 (wq.modeset) CPU1 (wq.unordered) intel_atomic_commit_tail() intel_dp_pcon_frl_recover() frl.is_trained == false drm_dp_pcon_hdmi_link_active() -> false intel_dp_check_frl_training() intel_dp_pcon_set_tmds_mode() signal hw_done intel_dp_get_active_pipes() wait_for_connector_hw_done() intel_dp_check_frl_training() drm_dp_pcon_frl_prepare() <-- tears down active TMDS link When the modeset falls back to TMDS mode, frl.is_trained remains false while the HDMI link is active in TMDS mode. intel_dp_check_frl_training() then sees !frl.is_trained and calls drm_dp_pcon_frl_prepare(), disrupting the active display and repeating up to 1.5 seconds of FRL polling under connection_mutex and crtc->base.mutex; the pre-wait AUX read can also race with the in-flight modeset's training. Re-checking frl.is_trained and drm_dp_pcon_hdmi_link_active() after intel_dp_get_active_pipes() would close this window. [Severity: Medium] Can intel_dp_pcon_frl_recover() race with HPD pulse handling on frl.is_trained and DP_PCON_HDMI_LINK_CONFIG_1? Previously, FRL recovery ran in dig_port_work, which serialized it against intel_dp_hpd_pulse() and intel_dp_handle_hdmi_link_status_change(). In encoder->link_check_work, intel_dp_pcon_frl_recover() runs on display->wq.unordered without calling intel_hpd_block(encoder) or sharing a lock with dig_port_work: CPU0 (wq.unordered) CPU1 (hotplug.dp_wq) intel_dp_pcon_frl_recover() ... intel_dp_pcon_start_frl_training() intel_dp_pcon_is_frl_trained() -> true intel_dp_hpd_pulse() (long HPD) frl.is_trained = false frl.is_trained = true <-- overwrites long-HPD reset Losing the long-HPD reset leaves frl.is_trained set, so the next enable skips FRL training even though the HDMI link is down. A concurrent short HPD in intel_dp_handle_hdmi_link_status_change() can also read is_active as false before training finishes, then see frl.is_trained == true and clear DP_PCON_ENABLE_HDMI_LINK via an unlocked read-modify-write, tearing down the freshly trained link. Blocking HPD with intel_hpd_block(encoder) around FRL recovery would serialize it with dig_port_work. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=11
