Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/msm/dp: unbalanced link and PHY teardown when atomic_enable fails - [High] drm/msm/dp: race on power_on in msm_dp_hpd_unplug_handle() exits powered PHY --
commit 0a488765100dee43f3575efbfcd59d2d2be4bb48 Author: Gianfranco Mariotti <[email protected]> drm/msm/dp: keep PHY initialized while plugged across link unprepare This commit keeps the DP PHY initialized across link unprepare while a sink remains plugged in, exits the PHY on unplug when power_on is false, and balances PHY exit and init across runtime PM suspend and resume. > diff --git a/drivers/gpu/drm/msm/dp/dp_display.c > b/drivers/gpu/drm/msm/dp/dp_display.c > index a48f42a173657..d3f4b5a9e723f 100644 > --- a/drivers/gpu/drm/msm/dp/dp_display.c > +++ b/drivers/gpu/drm/msm/dp/dp_display.c > @@ -483,8 +483,7 @@ static int msm_dp_hpd_unplug_handle(struct > msm_dp_display_private *dp) > if (!dp->msm_dp_display.is_edp) > drm_edid_connector_update(dp->msm_dp_display.connector, NULL); > > - /* triggered by irq_hdp with sink_count = 0 */ > - if (dp->link->sink_count == 0) > + if (!dp->msm_dp_display.power_on) > msm_dp_display_host_phy_exit(dp); > > dp->link->has_sink_count = false; [Severity: High] Can an unplug during modeset enable cause msm_dp_hpd_unplug_handle() to exit the PHY while it is powered on and msm_dp_ctrl_on_stream() is running? msm_dp_display_prepare_link() powers on the PHY and enables link clocks under dp->plugged_lock, then drops the lock while msm_dp_display->power_on is still false. msm_dp_display_enable() then runs msm_dp_ctrl_on_stream() and sets power_on = true without holding dp->plugged_lock: CPU0 CPU1 msm_dp_display_atomic_enable() msm_dp_display_prepare_link() lock(&dp->plugged_lock) msm_dp_ctrl_on_link() phy_power_on(phy) unlock(&dp->plugged_lock) msm_dp_hpd_unplug_handle() lock(&dp->plugged_lock) if (!dp->msm_dp_display.power_on) msm_dp_display_host_phy_exit(dp) ... phy_exit(phy) <-- PHY is powered on msm_dp_display_enable() msm_dp_ctrl_on_stream() msm_dp_display->power_on = true This resets the PHY/PLL and calls phy_exit() while phy->power_count is 1 and msm_dp_ctrl_on_stream() is accessing link and stream registers clocked by the PHY PLL. [ ... ] > @@ -1533,19 +1534,21 @@ static void msm_dp_display_unprepare(struct > msm_dp_display_private *dp) > { > struct msm_dp *msm_dp_display = &dp->msm_dp_display; > > - /* dongle is still connected but sinks are disconnected */ > - if (dp->link->sink_count == 0) > - msm_dp_link_psm_config(dp->link, &dp->panel->link_info, true); > + scoped_guard(mutex, &dp->plugged_lock) { > + /* dongle is still connected but sinks are disconnected */ > + if (dp->link->sink_count == 0 && dp->plugged) > + msm_dp_link_psm_config(dp->link, &dp->panel->link_info, > + true); > > - msm_dp_ctrl_off_link(dp->ctrl, dp->panel); > + msm_dp_ctrl_off_link(dp->ctrl, dp->panel); > > - if (dp->link->sink_count == 0) > - /* re-init the PHY so that we can listen to Dongle disconnect */ > - msm_dp_ctrl_reinit_phy(dp->ctrl); > - else > + /* Keep PHY initialized for AUX and IRQ_HPD while a sink > remains plugged */ > msm_dp_display_host_phy_exit(dp); > + if (dp->plugged) > + msm_dp_display_host_phy_init(dp); > > - msm_dp_display->power_on = false; > + msm_dp_display->power_on = false; > + } [Severity: High] What happens in msm_dp_display_atomic_post_disable() when an earlier msm_dp_display_atomic_enable() failed and left msm_dp_display->power_on false? If msm_dp_display_prepare_link() fails (returning -ENOTCONN or failing link training in msm_dp_ctrl_on_link(), where msm_dp_ctrl_deinitialize_mainlink() already disables link clocks and calls phy_power_off()), a later msm_dp_display_atomic_post_disable() still calls msm_dp_display_unprepare() unconditionally. Because msm_dp_display_unprepare() does not check power_on, msm_dp_ctrl_off_link() accesses REG_DP_MAINLINK_CTRL with link clocks off, calls clk_bulk_disable_unprepare() on already-disabled link clocks, and calls phy_power_off() when phy->power_count is already 0 (decrementing it to -1 so subsequent phy_power_on() calls never invoke phy->ops->power_on()). Conversely, if msm_dp_display_prepare_link() succeeds (leaving the PHY powered on) and msm_dp_display_enable() fails in msm_dp_ctrl_on_stream(), power_on is also false, so an unplug or the eDP msm_dp_hpd_unplug_handle() call at the start of msm_dp_display_atomic_post_disable() now sees !dp->msm_dp_display.power_on and calls msm_dp_display_host_phy_exit() -> phy_exit() before msm_dp_display_unprepare() calls phy_power_off(). -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=8
