Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v12 23/23] drm/bridge: synopsys: dw-dp: Retrain on hotplug with pre-enabled link
Date: Sat, 14 Nov 2026 05:25:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-214174@kernel.org> (raw)
In-Reply-To: <20261114-synopsys-dw-dp-improvements-v12-23-d42d3dc5bdd4@collabora.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/bridge: dw-dp: dw_dp_hpd_work() retrains link before
  parsing sink DPCD
- [Medium] drm/bridge: dw-dp: unlocked link state check and TOCTOU in
  dw_dp_link_retrain()
--

commit ecb979561e6b36e93516c81e2368f1af68040e73
Author: Yury Smirnov <yurymonzon@gmail.com>

drm/bridge: synopsys: dw-dp: Retrain on hotplug with pre-enabled link

This commit retrains an already-enabled DisplayPort link on a long HPD
pulse when a sink is detected before sending the DRM hotplug event.

> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-dp.c b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> index bf3a53463394f..b245d62009139 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> @@ -2394,6 +2394,12 @@ static void dw_dp_hpd_work(struct work_struct *work)
>  				dev_warn(dp->dev, "Retrain link failed\n");
>  		}
>  	} else {
> +		if (dp->link.enabled && dw_dp_hpd_detect(dp)) {
> +			ret = dw_dp_link_retrain(dp);
> +			if (ret)
> +				dev_warn(dp->dev, "Retrain link failed\n");
> +		}
> +
>  		drm_helper_hpd_irq_event(dp->bridge.dev);
>  	}
>  }

[Severity: High]
Should dw_dp_link_retrain() run after drm_helper_hpd_irq_event() rather
than before it?

Connector detection in drm_helper_hpd_irq_event() invokes
dw_dp_bridge_detect() -> dw_dp_hpd_detect_link() -> dw_dp_link_parse(),
which calls dw_dp_link_reset() (zeroing link->rate, link->lanes, and
link->caps) and then reads the sink's DPCD capabilities.

If a previous unplug detection failed after dw_dp_link_reset() (for
example, on a DP branch device or USB-C adapter when sink_count dropped to
0 and dw_dp_link_parse() returned -ENODEV), dp->link.rate and
dp->link.lanes are still 0 when the sink is replugged.  Calling
dw_dp_link_retrain() first then runs dw_dp_phy_configure(dp, 0, 0, false),
putting the PHY into P3 powerdown with all lanes disabled and failing link
training before dw_dp_link_parse() has re-read the DPCD.

Even when dp->link was not zeroed, retraining before
drm_helper_hpd_irq_event() trains against stale DPCD capabilities without
transitioning the replugged sink to DP_SET_POWER_D0 via
drm_dp_link_power_up(), and the subsequent dw_dp_link_parse() call in
drm_helper_hpd_irq_event() immediately resets dp->link and overwrites any
downgraded link->rate.

[Severity: Medium]
Can dw_dp_link_retrain() race with a concurrent atomic disable and train a
link whose PHY has already been powered off?

dw_dp_hpd_work() checks dp->link.enabled and dw_dp_link_retrain() checks
dw_dp_needs_link_retrain() before acquiring
dev->mode_config.connection_mutex, and neither is rechecked after acquiring
the lock:

CPU0 (kworker)                    CPU1 (modeset)
dw_dp_hpd_work()
  if (dp->link.enabled && ...)
  dw_dp_link_retrain()
    dw_dp_needs_link_retrain()
                                  dw_dp_bridge_atomic_disable()
                                    dw_dp_link_disable()
                                      dw_dp_phy_xmit_enable(dp, 0)
                                      phy_power_off(dp->phy)
                                      link->enabled = false
    drm_modeset_lock(&connection_mutex)
    dw_dp_link_train()
      dw_dp_phy_configure()       <-- configures powered-off PHY

Rechecking dp->link.enabled and dw_dp_needs_link_retrain() after locking
connection_mutex would close this window.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114-synopsys-dw-dp-improvements-v12-0-d42d3dc5bdd4@collabora.com?part=23

      reply	other threads:[~2026-11-14  5:25 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  5:00 [PATCH v12 00/23] Synopsys DisplayPort Controller improvements for Rockchip platforms Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 01/23] drm/bridge: synopsys: dw-dp: Register DP AUX on bridge attach Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 02/23] drm/bridge: synopsys: dw-dp: Fix incorrect resource lifetimes in bind callback Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 03/23] drm/bridge: synopsys: dw-dp: Fix error handling for DP link enablement Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 04/23] drm/bridge: synopsys: dw-dp: Document missing reset line deassert Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 05/23] drm/bridge: synopsys: dw-dp: Add missing mutex cleanups on module removal Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 06/23] drm/bridge: synopsys: dw-dp: Fix AUX transfer timeout race condition Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 07/23] drm/bridge: synopsys: dw-dp: Fix support for short I2C reads Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 08/23] drm/bridge: synopsys: dw-dp: Free output_fmts when none are valid Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 09/23] drm/bridge: synopsys: dw-dp: Support MEDIA_BUS_FMT_FIXED Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 10/23] drm/bridge: synopsys: dw-dp: Add follow-up bridge support Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 11/23] drm/bridge: Add out-of-band HPD notify handler Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 12/23] drm/bridge: synopsys: dw-dp: Support software triggered OOB HPD Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 13/23] drm/rockchip: dw_dp: Implement out-of-band HPD handling Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 14/23] drm/bridge: synopsys: dw-dp: Add Runtime PM support Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 15/23] drm/rockchip: dw_dp: Add runtime " Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 16/23] drm/rockchip: dw_dp: Add system " Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 17/23] drm/bridge: synopsys: dw-dp: Protect sdp_reg_bank from concurrent access Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 18/23] drm/bridge: synopsys: dw-dp: Drop useless reservation of first slot Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 19/23] drm/bridge: synopsys: dw-dp: Clear only enabled SDPs on atomic disable Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 20/23] drm/bridge: synopsys: dw-dp: Use regmap_set_bits in dw_dp_send_sdp Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 21/23] dt-bindings: display: rockchip: dw-dp: Fix sound DAI cells Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 22/23] drm/bridge: synopsys: dw-dp: Add audio support Sebastian Reichel
2026-11-14  5:00 ` [PATCH v12 23/23] drm/bridge: synopsys: dw-dp: Retrain on hotplug with pre-enabled link Sebastian Reichel
2026-11-14  5:25   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-214174@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebastian.reichel@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox