mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harry Wentland <harry.wentland@amd.com>
To: Maxime Ripard <mripard@kernel.org>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Louis Chauvet <louis.chauvet@bootlin.com>,
	Haneen Mohammed <hamohammed.sa@gmail.com>,
	Melissa Wen <melissa.srw@gmail.com>
Cc: "Daniel Stone" <daniels@collabora.com>,
	"Jocelyn Falempe" <jfalempe@redhat.com>,
	"Jonas Ådahl" <jadahl@redhat.com>,
	"Michel Dänzer" <mdaenzer@redhat.com>,
	"Pekka Paalanen" <pekka.paalanen@collabora.com>,
	"Sebastian Wick" <sebastian.wick@redhat.com>,
	"Simon Ser" <contact@emersion.fr>,
	"Victoria Brekenfeld" <victoria@system76.com>,
	"Xaver Hugl" <xaver.hugl@kde.org>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	"Leo Li" <sunpeng.li@amd.com>,
	"Rodrigo Siqueira" <siqueira@igalia.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v12 5/9] drm/amd/display: Take over the current stream and dc_state
Date: Tue, 1 Dec 2026 16:39:48 -0500	[thread overview]
Message-ID: <7addb297-9e8b-4693-891f-4128814d6f63@amd.com> (raw)
In-Reply-To: <20261120-drm-reset-state-flag-v12-5-42d63d7417fc@kernel.org>



On 2026-11-20 08:10, Maxime Ripard wrote:
> drm_atomic_commit_fill_with_defaults() builds its commits out of
> states created through atomic_create_state() instead of duplicating
> the current state. A created state comes with no stream nor dc_state,
> while a duplicated state carries the ones in use, with their
> reference.
> 
> The update passes of amdgpu_dm_atomic_check() release the stream and
> dc_state in use and clear the pointer of the new state, on top of the
> reference the current state drops when it gets destroyed. Those
> releases are only balanced if the new state brought a reference of
> its own, so a commit that disables or reconfigures a live CRTC or
> plane through a created state over-releases and frees the stream
> early, leading to a use-after-free when the current state gets
> destroyed. The paths that keep a CRTC or a plane enabled without a
> modeset also work on the stream and dc_state through the new state,
> and hit BUG_ON(dm_new_crtc_state->stream == NULL) since it never had
> one.
> 
> Take the stream and dc_state of the current state over, with a
> reference, at the beginning of amdgpu_dm_atomic_check(), like a
> duplicated state would have carried them. This has to happen before
> the update passes clear the stream of the new states: past that
> point, a state whose stream was cleared can't be told apart from a
> created one.
> 
> Signed-off-by: Maxime Ripard <mripard@kernel.org>

Reviewed-by: Harry Wentland <harry.wentland@amd.com>

Harry

> ---
> 
> To: Harry Wentland <harry.wentland@amd.com>
> To: Leo Li <sunpeng.li@amd.com>
> To: Rodrigo Siqueira <siqueira@igalia.com>
> To: Alex Deucher <alexander.deucher@amd.com>
> To: Christian König <christian.koenig@amd.com>
> Cc: amd-gfx@lists.freedesktop.org
> ---
>   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 50 +++++++++++++++++++++++
>   1 file changed, 50 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 0ea45ab12119..b2eddb87dd5c 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -6279,10 +6279,60 @@ STATIC_IFN_KUNIT int amdgpu_dm_atomic_check(struct drm_device *dev,
>   	struct drm_dp_mst_topology_state *mst_state;
>   	struct dsc_mst_fairness_vars vars[MAX_PIPES] = {0};
>   
>   	trace_amdgpu_dm_atomic_check_begin(state);
>   
> +	/*
> +	 * A CRTC or a plane that stays enabled keeps its stream and
> +	 * dc_state: a duplicated state carries them over, with their
> +	 * reference, but a state created through atomic_create_state()
> +	 * comes with neither. Take them over from the current state,
> +	 * with a reference, like a duplicated state would.
> +	 *
> +	 * The reference is needed when the update passes below
> +	 * reconfigure the CRTC or plane: they release the stream and
> +	 * dc_state in use and clear the pointer of the new state then,
> +	 * on top of the reference the current state drops when it gets
> +	 * destroyed, so that release is only balanced if the new state
> +	 * brought a reference of its own. The pointer is needed when
> +	 * they don't: the paths that keep a CRTC or a plane enabled
> +	 * without a modeset work on the stream and dc_state through
> +	 * the new state.
> +	 *
> +	 * A stream or a dc_state in the current state means the CRTC
> +	 * or the plane is enabled, since they are cleared when it gets
> +	 * disabled, so the conditions below already single out the
> +	 * live objects. They deliberately don't check whether this
> +	 * commit keeps them enabled on top of that: the update passes
> +	 * release the stream and dc_state of the CRTC or plane being
> +	 * disabled too, so their new state has to bring the reference
> +	 * just the same.
> +	 *
> +	 * This has to run before the update passes below clear the
> +	 * stream of the new states: past that point, a state whose
> +	 * stream was cleared can't be told apart from a created one.
> +	 */
> +	for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
> +		dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
> +		dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
> +
> +		if (!dm_new_crtc_state->stream && dm_old_crtc_state->stream) {
> +			dm_new_crtc_state->stream = dm_old_crtc_state->stream;
> +			dc_stream_retain(dm_new_crtc_state->stream);
> +		}
> +	}
> +
> +	for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
> +		struct dm_plane_state *dm_old_plane_state = to_dm_plane_state(old_plane_state);
> +		struct dm_plane_state *dm_new_plane_state = to_dm_plane_state(new_plane_state);
> +
> +		if (!dm_new_plane_state->dc_state && dm_old_plane_state->dc_state) {
> +			dm_new_plane_state->dc_state = dm_old_plane_state->dc_state;
> +			dc_plane_state_retain(dm_new_plane_state->dc_state);
> +		}
> +	}
> +
>   	ret = drm_atomic_helper_check_modeset(dev, state);
>   	if (ret) {
>   		drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed: %pe\n", ERR_PTR(ret));
>   		goto fail;
>   	}
> 


  reply	other threads:[~2026-12-01 21:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 13:10 [PATCH v12 0/9] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-11-20 13:10 ` [PATCH v12 1/9] drm/lease: Add a helper to tell whether a lease was revoked Maxime Ripard
2026-12-01  8:48   ` Thomas Zimmermann
2026-11-20 13:10 ` [PATCH v12 2/9] drm/atomic: Add drm_atomic_implements_create_state() helper Maxime Ripard
2026-12-01  8:54   ` Thomas Zimmermann
2026-12-01  9:20     ` Maxime Ripard
2026-11-20 13:10 ` [PATCH v12 3/9] drm/atomic: Allow filling a commit with pristine object states Maxime Ripard
2026-12-01  9:08   ` Thomas Zimmermann
2026-12-01  9:52     ` Maxime Ripard
2026-11-20 13:10 ` [PATCH v12 4/9] drm/tests: atomic: Add tests for drm_atomic_commit_fill_with_defaults() Maxime Ripard
2026-11-20 13:10 ` [PATCH v12 5/9] drm/amd/display: Take over the current stream and dc_state Maxime Ripard
2026-12-01 21:39   ` Harry Wentland [this message]
2026-11-20 13:10 ` [PATCH v12 6/9] drm/vc4: Carry the HVS channel over to created CRTC states Maxime Ripard
2026-11-20 13:10 ` [PATCH v12 7/9] drm/msm/dpu1: Carry the mixers " Maxime Ripard
2026-11-20 13:10 ` [PATCH v12 8/9] drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-12-01  9:19   ` Thomas Zimmermann
2026-11-20 13:10 ` [PATCH v12 9/9] drm/vkms: Add driver-specific plane property for testing Maxime Ripard

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=7addb297-9e8b-4693-891f-4128814d6f63@amd.com \
    --to=harry.wentland@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=contact@emersion.fr \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hamohammed.sa@gmail.com \
    --cc=jadahl@redhat.com \
    --cc=jfalempe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=louis.chauvet@bootlin.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mdaenzer@redhat.com \
    --cc=melissa.srw@gmail.com \
    --cc=mripard@kernel.org \
    --cc=pekka.paalanen@collabora.com \
    --cc=sebastian.wick@redhat.com \
    --cc=simona@ffwll.ch \
    --cc=siqueira@igalia.com \
    --cc=sunpeng.li@amd.com \
    --cc=tzimmermann@suse.de \
    --cc=victoria@system76.com \
    --cc=xaver.hugl@kde.org \
    /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

all inboxes | Powered by JetHome®