All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dave Airlie" <airlied@redhat.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 04/19] drm/amd/display/amdgpu_dm: Use DC accessors in audio/color/backlight paths
Date: Thu, 12 Nov 2026 01:50:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-210103@kernel.org> (raw)
In-Reply-To: <20261112-amdgpu-dc-cleanup-v1-4-0fae41718ad2@redhat.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 2 related pre-existing issues it does not
introduce:
- [Critical] drm/amd/display: race and invalid downcast in
  amdgpu_dm_backlight_set_level() [1]
- [Medium] drm/amd/display: swallowed error in
  amdgpu_dm_update_plane_color_mgmt() [2]
--

commit c710d624f30d7a2d26cb80389657ac035d1c1f5e
Author: Dave Airlie <airlied@redhat.com>

drm/amd/display/amdgpu_dm: Use DC accessors in audio/color/backlight paths

This commit replaces direct struct dc member accesses with DC accessor
calls in the audio, backlight, and color management paths.

> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
> index cb74b00723fda..3d268703c5514 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
> @@ -296,7 +296,7 @@ struct dc_stream_state *dm_find_stream_with_link(
>  	struct amdgpu_display_manager *dm,
>  	struct dc_link *link)
>  {
> -	struct dc_state *cur_dc_state = dm->dc->current_state;
> +	struct dc_state *cur_dc_state = dc_get_current_state(dm->dc);
>  	struct dc_stream_state *stream = NULL;
>  	int i;
>  
> @@ -383,7 +383,7 @@ void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
>  	}
>  
>  	mutex_lock(&dm->dc_lock);
> -	if (dm->dc->caps.ips_support && dm->dc->ctx->dmub_srv->idle_allowed) {
> +	if (dc_get_caps(dm->dc)->ips_support && dc_get_ctx(dm->dc)->dmub_srv->idle_allowed) {
>  		dc_allow_idle_optimizations(dm->dc, false);
>  		reallow_idle = true;
>  	}

[Severity: Critical]
This problem wasn't introduced by this patch, but can
amdgpu_dm_backlight_set_level() race with a concurrent atomic commit and
use cur_dc_state or stream after it has been freed [1]?

amdgpu_dm_backlight_set_level() calls dm_find_stream_with_link() before
acquiring dm->dc_lock:

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c:amdgpu_dm_backlight_set_level() {
	...
	list_for_each_entry(connector, &dm->ddev->mode_config.connector_list, head) {
		struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
		...
	}
	...
	link = (struct dc_link *)dm->backlight_link[bl_idx];
	stream = dm_find_stream_with_link(dm, link);
	if (!stream)
		return;
	...
	mutex_lock(&dm->dc_lock);
}

A concurrent commit can replace current_state and release the old state
and its streams while dm_find_stream_with_link() is walking it or before
dm->dc_lock is taken:

CPU0                                  CPU1
amdgpu_dm_backlight_set_level()
  dm_find_stream_with_link()
    cur_dc_state =
      dc_get_current_state(dm->dc)
    stream = cur_dc_state->streams[i]
                                      amdgpu_dm_commit_streams()
                                        mutex_lock(&dm->dc_lock)
                                        dc_commit_streams()
                                          /* replaces current_state,
                                             releases old state/streams */
                                        mutex_unlock(&dm->dc_lock)
  mutex_lock(&dm->dc_lock)
  mod_power_set_backlight_nits(...,
    stream, ...)                      <-- use-after-free

In addition, the loop at the start of amdgpu_dm_backlight_set_level()
walks mode_config.connector_list with list_for_each_entry() instead of
drm_connector_list_iter_begin()/end(), which can race with DP MST
connector removal, and unconditionally calls to_amdgpu_dm_connector() on
every entry, which causes type confusion on DRM_MODE_CONNECTOR_WRITEBACK
connectors (allocated as struct amdgpu_dm_wb_connector).

> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> index f9dc9f46a4460..d86b9611568b8 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c

[ ... ]

> @@ -2156,7 +2162,7 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
>  	struct amdgpu_device *adev = drm_to_adev(crtc->base.state->dev);
>  	struct dm_plane_state *dm_plane_state = to_dm_plane_state(plane_state);
>  	struct drm_color_ctm_3x4 *ctm = NULL;
> -	struct dc_color_caps *color_caps = NULL;
> +	const struct dc_color_caps *color_caps = NULL;
>  	bool has_crtc_cm_degamma;
>  	int ret;
>  
> @@ -2167,7 +2173,7 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
>  	}
>  
>  	if (dc_plane_state->ctx && dc_plane_state->ctx->dc)
> -		color_caps = &dc_plane_state->ctx->dc->caps.color;
> +		color_caps = &dc_get_caps(dc_plane_state->ctx->dc)->color;
>  
>  	/* Initially, we can just bypass the DGM block. */
>  	dc_plane_state->in_transfer_func.type = TF_TYPE_BYPASS;

[Severity: Medium]
This problem wasn't introduced by this patch, but does
amdgpu_dm_update_plane_color_mgmt() swallow errors from
amdgpu_dm_plane_set_colorop_properties() [2]?

At the end of amdgpu_dm_update_plane_color_mgmt():

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c:amdgpu_dm_update_plane_color_mgmt() {
	...
	if (!amdgpu_dm_plane_set_colorop_properties(plane_state, dc_plane_state))
		return 0;

	return amdgpu_dm_plane_set_color_properties(plane_state, dc_plane_state);
}

When plane_state->color_pipeline is set and
amdgpu_dm_plane_set_colorop_properties() fails with a negative error code
(such as -EINVAL or -ENOMEM), the ! check evaluates to false and execution
falls through to amdgpu_dm_plane_set_color_properties(). Because no legacy
color properties are set on a colorop commit, the fallback bypasses the
color blocks and returns 0, causing the atomic commit to succeed with
plane color management silently disabled.

[1] https://sashiko.dev/#/bug/linux-d25140b3-5901-4689-81c3-c3890f66e5a2
[2] https://sashiko.dev/#/bug/linux-2356891c-983c-48f7-a656-56667766fead

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261112-amdgpu-dc-cleanup-v1-0-0fae41718ad2@redhat.com?part=4

  reply	other threads:[~2026-11-12  1:51 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  1:43 [PATCH 00/19] drm/amd/display: refactor DC interfaces to abstract it better Dave Airlie
2026-11-12  1:43 ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 01/19] drm/amd/display: Drop the dead vmid module Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 02/19] drm/amd/display: Add DC accessors as the first step to opaque struct dc Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 03/19] drm/amd/display: Take struct dc in public DSC compute helpers Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 04/19] drm/amd/display/amdgpu_dm: Use DC accessors in audio/color/backlight paths Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:50   ` sashiko-bot [this message]
2026-11-12  1:43 ` [PATCH 05/19] drm/amd/display/amdgpu_dm: Use DC accessors in psr/replay/dmub/hdcp/irq paths Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  2:07   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 06/19] drm/amd/display/amdgpu_dm: Use DC accessors in plane/crtc/helpers paths Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:58   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 07/19] drm/amd/display/amdgpu_dm: Use DC accessors in connector paths Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 08/19] drm/amd/display: Use DC accessors in DAL modules Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 09/19] drm/amd/display/amdgpu_dm: Use DC accessors in debugfs paths Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:53   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 10/19] drm/amd/display/amdgpu_dm: Use DC accessors in the DM core paths Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 11/19] drm/amd/display/amdgpu_dm: Finish DC accessor migration for non-test code Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:53   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 12/19] drm/amd/display: Migrate amdgpu_dm KUnit tests off struct dc internals Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:59   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 13/19] drm/amd/display: Move struct dc out of the public dc.h Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 14/19] drm/amd/display: Restrict the dc directory root to DC-internal builds Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  2:08   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 15/19] drm/amd/display: Add dc_force_max_dramclk for the DP compliance workaround Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  2:02   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 16/19] drm/amd/display: Add DC primitives for ABM hardware programming Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  2:01   ` sashiko-bot
2026-11-12  1:43 ` [PATCH 17/19] drm/amd/display: Replace the dc_get_res_pool accessor with purpose APIs Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  1:43 ` [PATCH 18/19] drm/amd/display: Replace dc_get_config with per-option config reads Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12 20:31   ` Harry Wentland
2026-11-12  1:43 ` [PATCH 19/19] drm/amd/display: Replace dc_get_caps with purpose-built capability queries Dave Airlie
2026-11-12  1:43   ` Dave Airlie via B4 Relay
2026-11-12  2:14   ` sashiko-bot
2026-11-12 19:41   ` Harry Wentland

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-210103@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=airlied@redhat.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --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.