All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Damon Ding" <damon.ding@rock-chips.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 19/20] drm/bridge: analogix_dp: Handle HPD notification from downstream bridge
Date: Wed, 25 Nov 2026 11:48:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-233284@kernel.org> (raw)
In-Reply-To: <20261125112141.1434903-20-damon.ding@rock-chips.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/bridge: analogix_dp: redundant AUX probes in detect and
  analogix_dp_bridge_notify()
- [Medium] drm/bridge: analogix_dp: bypassed HPD check and static poll
  in analogix_dp_get_plug_in_status()
- [Medium] drm/bridge: analogix_dp: unsynchronized concurrent updates to
  dp->connection_notified
- [Medium] drm/bridge: analogix_dp: late hpd_notify_mode init leaves HPD
  IRQ enabled on suspend
--

commit 2e833b8add367c84281267efb779f7ba405e5a0d
Author: Damon Ding <damon.ding@rock-chips.com>

drm/bridge: analogix_dp: Handle HPD notification from downstream bridge

This commit adds an hpd_notify_mode for pipelines where a downstream bridge
provides HPD notifications without detection, muting native HPD interrupts
and probing the sink over AUX to cache and report connection status.

Link: https://lore.kernel.org/all/5609825.iZASKD2KPV@diego/

> diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> index 7ab183f72eb63..49d0eba74e7f0 100644
> --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> @@ -48,7 +48,7 @@ static const bool verify_fast_training;
>   */
>  static bool analogix_dp_supports_hpd(struct analogix_dp_device *dp)
>  {
> -	if (dp->force_connected_mode || dp->force_hpd)
> +	if (dp->force_connected_mode || dp->force_hpd || dp->hpd_notify_mode)
>  		return false;
>  
>  	if (dp->hpd_gpiod)
> @@ -86,10 +86,29 @@ static void analogix_dp_init_dp(struct analogix_dp_device *dp)
>  	analogix_dp_init_aux(dp);
>  }
>  
> +static bool analogix_dp_probe_sink(struct analogix_dp_device *dp)
> +{
> +	u8 dpcd_rev = 0;
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(dp->dev);
> +	if (ret)
> +		return false;
> +
> +	ret = drm_dp_dpcd_readb(&dp->aux, DP_DPCD_REV, &dpcd_rev);
> +
> +	pm_runtime_put_autosuspend(dp->dev);
> +
> +	return ret == 1 && dpcd_rev != 0;
> +}
> +
>  static int analogix_dp_detect_hpd(struct analogix_dp_device *dp)
>  {
>  	int timeout_loop = 0;
>  
> +	if (dp->hpd_notify_mode)
> +		return 0;
> +
>  	while (timeout_loop < DP_TIMEOUT_LOOP_COUNT) {
>  		if (analogix_dp_get_plug_in_status(dp) == 0)
>  			return 0;
> @@ -940,6 +959,13 @@ analogix_dp_bridge_detect(struct drm_bridge *bridge, struct drm_connector *conne
>  	struct analogix_dp_device *dp = to_dp(bridge);
>  	enum drm_connector_status status = connector_status_disconnected;
>  
> +	if (dp->hpd_notify_mode) {
> +		dp->connection_notified = analogix_dp_probe_sink(dp);
> +
> +		return dp->connection_notified ? connector_status_connected :
> +						 connector_status_disconnected;
> +	}
> +
>  	if (dp->force_connected_mode)
>  		return connector_status_connected;

[Severity: Medium]
Can concurrent calls to analogix_dp_bridge_detect() and
analogix_dp_bridge_notify() race when updating dp->connection_notified?

drm_dp_dpcd_readb() only holds dp->aux.hw_mutex across the AUX transaction
inside analogix_dp_probe_sink(), and drm_bridge_connector_handle_hpd()
calls drm_bridge_connector_hpd_notify() without holding
dev->mode_config.connection_mutex:

CPU0                                  CPU1
analogix_dp_bridge_detect()
  analogix_dp_probe_sink()
    drm_dp_dpcd_readb() -> true
                                      drm_bridge_connector_handle_hpd()
                                        ...
                                        analogix_dp_bridge_notify()
                                          analogix_dp_probe_sink()
                                            drm_dp_dpcd_readb() -> false
                                          dp->connection_notified = false
  dp->connection_notified = true  <-- overwrites newer result

In the reverse interleaving, analogix_dp_bridge_notify() can also overwrite
dp->connection_notified between the store and the load in
analogix_dp_bridge_detect().

[ ... ]

> @@ -1000,6 +1041,7 @@ static int analogix_dp_bridge_attach(struct drm_bridge *bridge,
>  		 * accurate hotplug state.
>  		 */
>  		dp->force_connected_mode = analogix_dp_bridge_force_connected(dp);
> +		dp->hpd_notify_mode = analogix_dp_has_downstream_hpd(dp);
>  	}
>  
>  	return 0;

[Severity: Medium]
What happens if the device runtime-resumes for an AUX transfer before
analogix_dp_bridge_attach() sets dp->hpd_notify_mode?

analogix_dp_probe() enables runtime PM, analogix_dp_finish_probe() calls
devm_of_dp_aux_populate_bus(), and analogix_dp_bind() calls
drm_dp_aux_register() before drm_bridge_attach().  On RK3576_EDP and
RK3588_EDP, a runtime resume during that window runs with
dp->hpd_notify_mode still false, so analogix_dp_resume() unmutes native HPD
interrupts, enables dp->irq, and sets dp->hpd_irq_enabled = true:

drivers/gpu/drm/bridge/analogix/analogix_dp_core.c:analogix_dp_resume() {
	...
	if (analogix_dp_require_pm_for_hpd_irq(dp) && !dp->hpd_irq_enabled) {
		enable_irq(dp->irq);
		dp->hpd_irq_enabled = true;
	}
}

Once analogix_dp_bridge_attach() sets dp->hpd_notify_mode = true,
analogix_dp_supports_hpd() and analogix_dp_require_pm_for_hpd_irq() return
false.  When the device later suspends, analogix_dp_suspend() skips
disable_irq(dp->irq) even though dp->hpd_irq_enabled is true, leaving
dp->irq enabled with native HPD interrupts unmuted while the PHY and clock
are powered off.

> @@ -1296,6 +1338,17 @@ static void analogix_dp_bridge_atomic_post_disable(struct drm_bridge *bridge,
>  		DRM_ERROR("Failed to enable psr (%d)\n", ret);
>  }
>  
> +static void analogix_dp_bridge_notify(struct drm_bridge *bridge, struct drm_connector *connector,
> +				      enum drm_connector_status status)
> +{
> +	struct analogix_dp_device *dp = to_dp(bridge);
> +
> +	if (!dp->hpd_notify_mode)
> +		return;
> +
> +	dp->connection_notified = analogix_dp_probe_sink(dp);
> +}

[Severity: High]
Does probing the sink in both analogix_dp_bridge_detect() and
analogix_dp_bridge_notify() cause redundant AUX transfers and multi-second
timeout storms on unplug?

In drm_bridge_connector_detect_ctx(), calling detect->funcs->detect() is
immediately followed by drm_bridge_connector_hpd_notify():

drivers/gpu/drm/display/drm_bridge_connector.c:drm_bridge_connector_detect_ctx() {
	if (detect) {
		status = detect->funcs->detect(detect, connector);
		...
		drm_bridge_connector_hpd_notify(connector, status);
	}
}

Because analogix_dp_bridge_detect() always probes the sink instead of using
dp->connection_notified, every detect call runs analogix_dp_probe_sink()
twice back-to-back.  On an unplug notification,
drm_bridge_connector_handle_hpd() also calls analogix_dp_bridge_notify()
with connector_status_disconnected (which is ignored) before triggering
hotplug detection, running three full AUX probes in a row.  When no sink is
connected, each analogix_dp_probe_sink() call retries 32 times in
drm_dp_dpcd_access(), and each attempt in analogix_dp_transfer() waits up
to 20 ms for RPLY_RECEIV, logs a dev_err timeout message, and resets the
AUX channel.

[ ... ]

> diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
> index af5e5a8ec88d6..125f4fecbaa28 100644
> --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
> +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
[ ... ]
> @@ -533,16 +533,15 @@ int analogix_dp_get_plug_in_status(struct analogix_dp_device *dp)
>  {
>  	u32 reg;
>  
> -	if (dp->hpd_gpiod) {
> -		if (gpiod_get_value(dp->hpd_gpiod))
> -			return 0;
> -	} else {
> -		reg = readl(dp->reg_base + ANALOGIX_DP_SYS_CTL_3);
> -		if (reg & HPD_STATUS)
> -			return 0;
> -	}
> +	if (dp->hpd_gpiod)
> +		return gpiod_get_value(dp->hpd_gpiod) ? 0 : -EINVAL;
> +
> +	if (dp->hpd_notify_mode)
> +		return dp->connection_notified ? 0 : -EINVAL;
> +
> +	reg = readl(dp->reg_base + ANALOGIX_DP_SYS_CTL_3);
>  
> -	return -EINVAL;
> +	return (reg & HPD_STATUS) ? 0 : -EINVAL;
>  }

[Severity: Medium]
Is this dp->connection_notified check in analogix_dp_get_plug_in_status()
bypassed by analogix_dp_detect_hpd(), while leaving
analogix_dpaux_wait_hpd_asserted() polling a static variable?

Because analogix_dp_detect_hpd() returns 0 at the top when
dp->hpd_notify_mode is true, it never calls
analogix_dp_get_plug_in_status().  Callers such as analogix_dp_set_bridge()
and analogix_dpaux_transfer() will therefore treat HPD as asserted and
proceed into link training or AUX transfers even when
dp->connection_notified is false.

Meanwhile, the only remaining caller of analogix_dp_get_plug_in_status() in
hpd_notify_mode is analogix_dpaux_wait_hpd_asserted(), which polls
analogix_dp_get_plug_in_status() with readx_poll_timeout().  Since nothing
updates dp->connection_notified during that loop, it just spins until
wait_us expires whenever dp->connection_notified is false on entry.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125112141.1434903-1-damon.ding@rock-chips.com?part=19

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

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 11:21 [PATCH v7 00/20] Add HPD support for Rockchip Analogix DP Damon Ding
2026-11-25 11:21 ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 01/20] drm/bridge: Select VIDEOMODE_HELPERS for DRM_OF_DISPLAY_MODE_BRIDGE Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 02/20] drm/bridge: analogix_dp: Drop the redundant pm_runtime_mark_last_busy() calls Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 03/20] drm/bridge: analogix_dp: Use bridge->next_bridge instead of plat_data field Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 04/20] drm/bridge: analogix_dp: Restrict forced connected status to panel endpoints Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 05/20] drm/bridge: analogix_dp: Take a runtime PM reference in bridge detect Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 06/20] drm/bridge: analogix_dp: Return bitmask from analogix_dp_get_irq_type() Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 07/20] drm/bridge: analogix_dp: Check all negative return values for &analogix_dp_device.irq Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 08/20] drm/bridge: analogix_dp: Add IRQF_ONESHOT and simplify IRQ handling Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:31   ` sashiko-bot
2026-11-25 11:21 ` [PATCH v7 09/20] drm/bridge: analogix_dp: Extend clear_hotplug_interrupts to accept IRQ bitmask Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 10/20] drm/bridge: analogix_dp: Extend mute/unmute HPD interrupts to accept irq bitmask Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 11/20] drm/bridge: analogix_dp: Simplify analogix_dp_config_interrupt() Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 12/20] drm/bridge: analogix_dp: Use platform-specific HPD detection scheme Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 13/20] drm/bridge: analogix_dp: Skip native HPD interrupt ops for GPIO HPD Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 14/20] drm/rockchip: analogix_dp: Unbind bridge when connector init fails Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 15/20] drm/exynos: exynos_dp: " Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 16/20] drm/bridge: analogix_dp: Move IRQ enable/disable to bind/unbind Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 17/20] drm/bridge: analogix_dp: Manage pm runtime and IRQ for native HPD pin detection Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:41   ` sashiko-bot
2026-11-26  3:58     ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 18/20] drm/bridge: analogix_dp: Declare DRM_BRIDGE_OP_HPD for hotplug reporting Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 19/20] drm/bridge: analogix_dp: Handle HPD notification from downstream bridge Damon Ding
2026-11-25 11:21   ` Damon Ding
2026-11-25 11:48   ` sashiko-bot [this message]
2026-11-26  8:06     ` Damon Ding
2026-11-25 11:21 ` [PATCH v7 20/20] MAINTAINERS: Add entry for Analogix DP controller bridge Damon Ding
2026-11-25 11:21   ` Damon Ding
  -- strict thread matches above, loose matches on Subject: below --
2026-11-27 18:24 [PATCH v7 12/20] drm/bridge: analogix_dp: Use platform-specific HPD detection scheme kernel test robot
2026-11-30  5:47 ` Dan Carpenter
2026-11-30  5:47 ` Dan Carpenter

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-233284@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon.ding@rock-chips.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.