* [PATCH v13 0/9] drm: Add DRM_MODE_ATOMIC_RESET flag
@ 2026-12-03 14:07 Maxime Ripard
2026-12-03 14:07 ` [PATCH v13 5/9] drm/amd/display: Take over the current stream and dc_state Maxime Ripard
0 siblings, 1 reply; 3+ messages in thread
From: Maxime Ripard @ 2026-12-03 14:07 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter,
Louis Chauvet, Haneen Mohammed, Melissa Wen
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard, Daniel Stone, Leo Li, Rodrigo Siqueira,
Alex Deucher, Christian König, amd-gfx, Dave Stevenson,
Maíra Canal, Raspberry Pi Kernel Maintenance, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, freedreno,
Oarora Etimis
Hi,
Userspace currently has no atomic way to bring a display pipeline back
to a pristine state. A compositor that wants to start from a known
baseline must explicitly set every property on every KMS object to its
default value, which requires tracking which properties exist and what
their defaults are. This is fragile and must be updated every time a
new property is added to the kernel.
This series introduces a new DRM_MODE_ATOMIC_RESET flag for the
atomic ioctl. When set, the kernel fills the commit with default
states for all KMS objects before applying the properties supplied in
the request. Properties not explicitly included remain at their
defaults. This allows userspace to describe the desired end state
declaratively, without caring about the current state or the full set
of properties.
A driver-specific property is added to vkms planes for testing.
Standard properties are impractical for this: compositors like Mutter
enumerate all known properties, making it hard to isolate the reset
behavior in a test.
Mutter has a working implementation using the new flag, with a
vkms-based test exercising the reset behavior:
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/5309
And we have IGT tests as well:
https://lore.kernel.org/r/20261112162147.766264-1-mripard@kernel.org/
Let me know what you think,
Maxime
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
Changes in v13:
- Return EACCES when accessing a resource we don't have a lease for,
instead of ENOENT
- Use a scoped mutex for drm_lease_revoked()
- Link to v12: https://lore.kernel.org/r/20261120-drm-reset-state-flag-v12-0-42d63d7417fc@kernel.org
Changes in v12:
- Re-add drm_lease flag to differentiate an empty from a revoked lease
- Link to v11: https://lore.kernel.org/r/20261116-drm-reset-state-flag-v11-0-378b3f7bef32@kernel.org
Changes in v11:
- Reorder object state allocations to be more robust against lease revocation
- Bring back lease revocation check
- Link to v10: https://lore.kernel.org/r/20261112-drm-reset-state-flag-v10-0-cefaa1ed056d@kernel.org
Changes in v10:
- Stop trying to make partial lease work, they aren't meant to exist, so
we can simply error out when they happen
- More tests for zpos and color management
- Fix DPU1 issues reported by sashiko
- Link to v9: https://lore.kernel.org/r/20261110-drm-reset-state-flag-v9-0-ddb0e26324a0@kernel.org
Changes in v9:
- Add a flag to know if leases have been revoked or are empty
- Handle the situation where a leased plane or connector being reset
would disable an unleased CRTC
- Add more kunit tests to cover the new issues reported by sashiko
- Fix reset-related bugs in amdgpu, vc4 and msm DPU
- Add a vc4 kunit test for its reset related bug
- Link to v8: https://lore.kernel.org/r/20261106-drm-reset-state-flag-v8-0-50fd046b705f@kernel.org
Changes in v8:
- Fix more leases issues
- Drop applied patches
- Link to v7: https://lore.kernel.org/r/20261030-drm-reset-state-flag-v7-0-4e55eaeae683@kernel.org
Changes in v7:
- Fix a whole bunch of sashiko issues to deal with color_mgmt_changed,
leases, partially leased devices (like a plane leased but it's crtc
isn't) and the interaction with PAGE_FLIP_EVENT better
- Fix crtc create_state implementation for ssd130x
- Actually make it possible for a compositor to recreate the same whole
state without passing ALLOW_MODESET
- Fix EDEADLK bugs with kunit tests
- Don't report DRM_CAP_ATOMIC_RESET on !atomic drivers
- Fix error handling in vkms for the new property
- Add more kunit tests for the new corner cases
- Link to v6: https://lore.kernel.org/r/20261022-drm-reset-state-flag-v6-0-f36d640b7e76@kernel.org
Changes in v6:
- If using a lease, only considered the leased objects
- Fix amdgpu plane atomic_create_state implementation
- Link to v5: https://lore.kernel.org/r/20261016-drm-reset-state-flag-v5-0-dad2d64b693b@kernel.org
Changes in v5:
- Fix bisection issue
- Improve the documentation
- Fix connector hotplugging issue
- Added kunit tests for drm_atomic_commit_fill_with_defaults()
- Link to v4: https://lore.kernel.org/r/20260918-drm-reset-state-flag-v4-0-5ad106370f05@kernel.org
Changes in v4:
- Improve the drm_atomic_get_private_obj_state and
drm_atomic_get_connector_state array reallocations
- Return void on functions to insert an object state into a commit when
it cannot fail
- Rename drm_atomic_can_create_state() into
drm_atomic_implements_create_state()
- Move capability check from drm_atomic_commit_fill_with_defaults to its
caller
- Added IGT test
- Link to v3: https://lore.kernel.org/r/20260908-drm-reset-state-flag-v3-0-905570f387a4@kernel.org
Changes in v3:
- Rebased on top of the latest atomic_create_state series
- Sebastian Wick created and tested this work with mutter and vkms
- Fix colorop locking
- Link to v2: https://lore.kernel.org/r/20260812-drm-reset-state-flag-v2-0-e96ce13317dd@kernel.org
Changes in v2:
- Fix bisection
- Add capability to let userspace know if it can reset the state
- Link to v1: https://lore.kernel.org/r/20260708-drm-reset-state-flag-v1-0-c37dc985485d@kernel.org
---
Maxime Ripard (8):
drm/lease: Add a helper to tell whether a lease was revoked
drm/atomic: Add drm_atomic_implements_create_state() helper
drm/atomic: Allow filling a commit with pristine object states
drm/tests: atomic: Add tests for drm_atomic_commit_fill_with_defaults()
drm/amd/display: Take over the current stream and dc_state
drm/vc4: Carry the HVS channel over to created CRTC states
drm/msm/dpu1: Carry the mixers over to created CRTC states
drm/vkms: Add driver-specific plane property for testing
Sebastian Wick (1):
drm/atomic-uapi: Add DRM_MODE_ATOMIC_RESET flag
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 50 +++
drivers/gpu/drm/drm_atomic.c | 373 +++++++++++++++++++
drivers/gpu/drm/drm_atomic_uapi.c | 44 ++-
drivers/gpu/drm/drm_ioctl.c | 5 +
drivers/gpu/drm/drm_lease.c | 29 ++
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 23 ++
drivers/gpu/drm/tests/drm_atomic_test.c | 435 +++++++++++++++++++++-
drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c | 105 ++++++
drivers/gpu/drm/vc4/vc4_kms.c | 16 +-
drivers/gpu/drm/vkms/vkms_drv.h | 3 +
drivers/gpu/drm/vkms/vkms_plane.c | 63 +++-
include/drm/drm_atomic.h | 4 +
include/drm/drm_auth.h | 11 +
include/drm/drm_lease.h | 2 +
include/uapi/drm/drm.h | 10 +
include/uapi/drm/drm_mode.h | 22 +-
16 files changed, 1185 insertions(+), 10 deletions(-)
---
base-commit: 1beb2c8b02e989c172f00d24993adb8ce3248eaf
change-id: 20260708-drm-reset-state-flag-2fb2b5711f97
Best regards,
--
Maxime Ripard <mripard@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v13 5/9] drm/amd/display: Take over the current stream and dc_state
2026-12-03 14:07 [PATCH v13 0/9] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
@ 2026-12-03 14:07 ` Maxime Ripard
2026-12-03 15:40 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Maxime Ripard @ 2026-12-03 14:07 UTC (permalink / raw)
To: Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter,
Louis Chauvet, Haneen Mohammed, Melissa Wen
Cc: Daniel Stone, Harry Wentland, Jocelyn Falempe, Jonas Ådahl,
Michel Dänzer, Pekka Paalanen, Sebastian Wick, Simon Ser,
Victoria Brekenfeld, Xaver Hugl, dri-devel, linux-kernel,
Maxime Ripard, Leo Li, Rodrigo Siqueira, Alex Deucher,
Christian König, amd-gfx
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>
---
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 019022fba6f1..91d0ce7830f0 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;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v13 5/9] drm/amd/display: Take over the current stream and dc_state
2026-12-03 14:07 ` [PATCH v13 5/9] drm/amd/display: Take over the current stream and dc_state Maxime Ripard
@ 2026-12-03 15:40 ` sashiko-bot
0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-03 15:40 UTC (permalink / raw)
To: Maxime Ripard; +Cc: dri-devel, amd-gfx
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/amd/display: amdgpu_dm_atomic_check() drops connector
freesync_capable
- [Medium] drm/amd/display: amdgpu_dm_atomic_check() drops CRTC
mpo_requested flag
- [Medium] drm/amd/display: amdgpu_dm_atomic_check() zeroes MST pbn and
vcpi_slots
- [Medium] drm/amd/display: amdgpu_dm_atomic_check() drops
freesync_config and crc_skip
--
commit bd2a6eec10d32cb9ed251de4423a0475cf93f1eb
Author: Maxime Ripard <mripard@kernel.org>
drm/amd/display: Take over the current stream and dc_state
This commit copies dm_old_crtc_state->stream and
dm_old_plane_state->dc_state (with their references) into newly created
atomic states at the start of amdgpu_dm_atomic_check().
> 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 019022fba6f1e..91d0ce7830f01 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -6281,6 +6281,56 @@ STATIC_IFN_KUNIT int amdgpu_dm_atomic_check(struct drm_device *dev,
>
> trace_amdgpu_dm_atomic_check_begin(state);
>
[ ... ]
> + 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);
> + }
> + }
[Severity: Medium]
Should this loop also preserve dm_old_crtc_state->mpo_requested?
amdgpu_dm_crtc_create_state() leaves mpo_requested false. When a reset
commit keeps an active overlay plane without a plane reset,
dm_update_plane_state() returns early before setting mpo_requested, so
the flag stays false on the swapped-in CRTC state and later commits.
fill_dc_dirty_rects() then skips MPO bounding-box dirty rectangles and
PSR-SU pause handling, causing display artifacts on PSR-SU and Panel
Replay panels.
[Severity: Medium]
Does this also drop dm_crtc_state->freesync_config and crc_skip_count?
On a non-modeset reset commit with FreeSync Video Mode active,
amdgpu_dm_get_freesync_config_for_crtc() sees a zeroed freesync_config
instead of VRR_STATE_ACTIVE_FIXED, disabling FreeSync Video Mode and
making amdgpu_dm_handle_vrr_transition() drop the VRR vblank reference.
Zeroing crc_skip_count also causes amdgpu_dm_crtc_handle_crc_irq() to
drop the next two frames during active CRC capture.
> +
> + 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);
> + }
> + }
[Severity: High]
Does omitting a connector takeover loop clear
dm_connector_state->freesync_capable?
freesync_capable is sink capability metadata populated during EDID
probing by amdgpu_dm_update_freesync_caps(), so
amdgpu_dm_connector_atomic_create_state() leaves it false. On any reset
commit, amdgpu_dm_get_freesync_config_for_crtc() then disables VRR.
Once that state is swapped in, subsequent duplicated commits inherit
freesync_capable as false, permanently disabling FreeSync and Panel
Replay (in amdgpu_dm_link_supports_replay()) until the next hotplug or
reprobe.
[Severity: Medium]
Can a non-modeset reset commit also zero dm_connector_state->pbn and
vcpi_slots on active DP-MST connectors?
amdgpu_dm_connector_atomic_create_state() zeroes both fields, and
dm_encoder_helper_atomic_check() returns early without recomputing them
when neither connectors_changed nor mode_changed is set.
On a later suspend/resume, drm_atomic_helper_suspend() saves that zeroed
state with state->duplicated set, so dm_encoder_helper_atomic_check()
skips recalculating pbn and passes 0 to drm_dp_atomic_find_time_slots(),
breaking DP-MST resume.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-drm-reset-state-flag-v13-0-b09f19f64e64@kernel.org?part=5
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 15:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 14:07 [PATCH v13 0/9] drm: Add DRM_MODE_ATOMIC_RESET flag Maxime Ripard
2026-12-03 14:07 ` [PATCH v13 5/9] drm/amd/display: Take over the current stream and dc_state Maxime Ripard
2026-12-03 15:40 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox