dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maxime Ripard" <mripard@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 01/34] drm/bridge-helper: Don't unlock the connection mutex after a backoff
Date: Thu, 29 Oct 2026 07:51:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-188907@kernel.org> (raw)
In-Reply-To: <20261029-drm-state-readout-v7-1-25e5163d75c3@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/bridge-helper: lock drop and NULL deref in drm_bridge_helper_reset_crtc()
--

commit 110ed6cb32b618d9ec32a80d2d60952c2bc006ae
Author: Maxime Ripard <mripard@kernel.org>

drm/bridge-helper: Don't unlock the connection mutex after a backoff

This commit removes the unconditional connection_mutex unlock in
drm_bridge_helper_reset_crtc() and re-acquires connection_mutex after calling
drm_atomic_get_connector_for_encoder(), leaving lock release to the caller via
drm_modeset_drop_locks() or drm_modeset_backoff().

> diff --git a/drivers/gpu/drm/drm_bridge_helper.c b/drivers/gpu/drm/drm_bridge_helper.c
> index 0a3c8fee66b32..6998e7c41d30e 100644
> --- a/drivers/gpu/drm/drm_bridge_helper.c
> +++ b/drivers/gpu/drm/drm_bridge_helper.c

[ ... ]

> @@ -33,26 +37,33 @@ int drm_bridge_helper_reset_crtc(struct drm_bridge *bridge,
>  	struct drm_crtc *crtc;
>  	int ret;
>  
> +	/*
> +	 * Every lock taken with @ctx is released either by a backoff or
> +	 * by the caller through drm_modeset_drop_locks(), so we must not
> +	 * unlock the connection mutex ourselves.
> +	 */
>  	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx);
>  	if (ret)
>  		return ret;
>  
>  	connector = drm_atomic_get_connector_for_encoder(encoder, ctx);
> -	if (IS_ERR(connector)) {
> -		ret = PTR_ERR(connector);
> -		goto out;
> -	}
> +	if (IS_ERR(connector))
> +		return PTR_ERR(connector);
> +
> +	/*
> +	 * drm_atomic_get_connector_for_encoder() may have backed off,
> +	 * releasing the connection mutex in the process. Take it back
> +	 * before looking at the connector state.
> +	 */
> +	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx);
> +	if (ret)
> +		return ret;
>  
> -	if (!connector->state) {
> -		ret = -EINVAL;
> -		goto out;
> -	}
> +	if (!connector->state)
> +		return -EINVAL;
>  
>  	crtc = connector->state->crtc;
> -	ret = drm_atomic_helper_reset_crtc(crtc, ctx);
>  
> -out:
> -	drm_modeset_unlock(&dev->mode_config.connection_mutex);
> -	return ret;
> +	return drm_atomic_helper_reset_crtc(crtc, ctx);

[Severity: High]
Does drm_atomic_get_connector_for_encoder() actually back off on deadlock, or
does it unconditionally unlock connection_mutex before returning?

Looking at drivers/gpu/drm/drm_atomic.c:drm_atomic_get_connector_for_encoder(),
neither it nor drm_atomic_helper_reset_crtc() calls drm_modeset_backoff().
Instead, drm_atomic_get_connector_for_encoder() acquires connection_mutex
(which succeeds as a no-op via -EALREADY when already held in ctx) and then
unconditionally drops it at the end of the function:

drivers/gpu/drm/drm_atomic.c:drm_atomic_get_connector_for_encoder() {
	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx);
	if (ret)
		return ERR_PTR(ret);

	drm_connector_list_iter_begin(dev, &conn_iter);
	drm_for_each_connector_iter(connector, &conn_iter) {
		if (!connector->state)
			continue;

		if (encoder == connector->state->best_encoder) {
			out_connector = connector;
			break;
		}
	}
	drm_connector_list_iter_end(&conn_iter);
	drm_modeset_unlock(&dev->mode_config.connection_mutex);

	return out_connector;
}

Because drm_atomic_get_connector_for_encoder() drops both the connector list
iterator reference and connection_mutex before returning, there is an unlocked
window before drm_bridge_helper_reset_crtc() re-acquires connection_mutex. Also,
if drm_atomic_get_connector_for_encoder() finds no matching connector and
returns ERR_PTR(-EINVAL), connection_mutex has already been unlocked even if
the caller held it in ctx.

If a concurrent modeset or atomic commit runs during that unlocked window (for
example, while sn65dsi83_reset_work() -> sn65dsi83_reset_pipe() ->
drm_bridge_helper_reset_crtc() is executing) and disables the connector or
reassigns it to another encoder, connector->state remains non-NULL while
connector->state->best_encoder and connector->state->crtc can become NULL or
point to a different pipeline.

When drm_bridge_helper_reset_crtc() re-locks connection_mutex, it only checks
if (!connector->state) and neither re-verifies connector->state->best_encoder
== encoder nor checks that crtc is non-NULL before calling
drm_atomic_helper_reset_crtc(crtc, ctx):

drivers/gpu/drm/drm_atomic_helper.c:drm_atomic_helper_reset_crtc() {
	...
	state = drm_atomic_commit_alloc(crtc->dev);
	if (!state)
		return -ENOMEM;
	...
}

Can this race cause a NULL pointer dereference on crtc->dev in
drm_atomic_helper_reset_crtc(), or reset the wrong CRTC?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261029-drm-state-readout-v7-0-25e5163d75c3@kernel.org?part=1

  reply	other threads:[~2026-10-29  7:51 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29  7:33 [PATCH v7 00/34] drm: Implement state readout support Maxime Ripard
2026-10-29  7:33 ` [PATCH v7 01/34] drm/bridge-helper: Don't unlock the connection mutex after a backoff Maxime Ripard
2026-10-29  7:51   ` sashiko-bot [this message]
2026-10-29  7:33 ` [PATCH v7 02/34] drm/tests: hdmi-state-helper: Handle EDEADLK in the 420-only test Maxime Ripard
2026-10-29  7:33 ` [PATCH v7 03/34] drm/tests: hdmi-state-helper: Handle EDEADLK in the color format test Maxime Ripard
2026-10-29  7:33 ` [PATCH v7 04/34] drm/atomic: Fix private obj error handling Maxime Ripard
2026-10-29  7:57   ` sashiko-bot
2026-10-29  7:33 ` [PATCH v7 05/34] drm/atomic: Add drm_private_obj name Maxime Ripard
2026-10-29  7:56   ` sashiko-bot
2026-10-29  7:33 ` [PATCH v7 06/34] drm/bridge: Switch print_state to use bridge name Maxime Ripard
2026-10-29  7:33 ` [PATCH v7 07/34] drm/bridge: Add drm_private_obj_is_bridge() Maxime Ripard
2026-10-29  7:33 ` [PATCH v7 08/34] drm/fb-dma-helper: Handle framebuffers without a GEM object Maxime Ripard
2026-10-29  7:33 ` [PATCH v7 09/34] drm/atomic: Export drm_atomic_*_print_state Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 10/34] drm/atomic_sro: Create drm_atomic_sro_state container Maxime Ripard
2026-10-29  7:50   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 11/34] drm/atomic_sro: Create kernel parameter to force or disable readout Maxime Ripard
2026-10-29  7:46   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 12/34] drm/atomic_sro: Add atomic state readout infrastructure Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 13/34] drm/atomic_sro: Add function to install state into drm objects Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 14/34] drm/atomic_sro: Create documentation Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 15/34] drm/bridge: Handle bridges with hardware state readout Maxime Ripard
2026-10-29  7:59   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 16/34] drm/mode-config: Read out hardware state in drm_mode_config_create_state Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 17/34] drm/atomic_sro: Provide helpers to implement hardware state readout Maxime Ripard
2026-10-29  8:02   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 18/34] drm/mode-config: Introduce hw_reset hook Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 19/34] drm/modeset-helper: Add drm_mode_config_helper_hw_reset() Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 20/34] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2026-10-29  8:05   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 21/34] drm/atomic-state-helper: Provide comparison macros Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 22/34] drm/atomic-state-helper: Provide atomic_compare_state helpers Maxime Ripard
2026-10-29  8:07   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 23/34] drm/atomic-helper: Document State Read-Out as a state initialization approach Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 24/34] drm/tests: kunit: Add a drm_printer helper Maxime Ripard
2026-10-29  7:56   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 25/34] drm/tests: Add tests for the atomic state readout Maxime Ripard
2026-10-29  8:03   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 26/34] drm/encoder: Create atomic_sro_get_current_crtc hook Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 27/34] drm/bridge: display-connector: Implement readout support Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 28/34] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2026-10-29  8:04   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 29/34] drm/tidss: crtc: Add atomic_print_state implementation Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 30/34] drm/tidss: dispc: Improve mode checking logs Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 31/34] drm/tidss: Implement hw_reset Maxime Ripard
2026-10-29  8:09   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 32/34] drm/tidss: Implement readout support Maxime Ripard
2026-10-29  8:22   ` sashiko-bot
2026-10-29  7:34 ` [PATCH v7 33/34] drm/tidss: encoder: Implement atomic_sro_get_current_crtc Maxime Ripard
2026-10-29  7:34 ` [PATCH v7 34/34] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2026-10-29  8:12   ` sashiko-bot
2026-10-29 15:20 ` [PATCH v7 00/34] drm: Implement state readout support Tomi Valkeinen

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-188907@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mripard@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox