Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ville Syrjala <ville.syrjala@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	Maxime Ripard <mripard@kernel.org>,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: [PATCH 2/2] drm/atomic: WARN about invalid drm_foo_get_state() usage
Date: Fri, 17 Oct 2025 19:33:27 +0300	[thread overview]
Message-ID: <20251017163327.9074-2-ville.syrjala@linux.intel.com> (raw)
In-Reply-To: <20251017163327.9074-1-ville.syrjala@linux.intel.com>

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

drm_{crtc,plane,connector,private_obj}_get_state() must not
be called after the atomic check phase. At that point the commit
has been carved in stone and no new objects must be introduced
into it. WARN if anyone attempts to violate this rule.

Cc: Maxime Ripard <mripard@kernel.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_atomic.c | 8 ++++++++
 include/drm/drm_atomic.h     | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 5d31b20e67ab..e05820b18832 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -200,6 +200,8 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state)
 
 	drm_dbg_atomic(dev, "Clearing atomic state %p\n", state);
 
+	state->checked = false;
+
 	for (i = 0; i < state->num_connector; i++) {
 		struct drm_connector *connector = state->connectors[i].ptr;
 
@@ -348,6 +350,7 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,
 	struct drm_crtc_state *crtc_state;
 
 	WARN_ON(!state->acquire_ctx);
+	drm_WARN_ON(state->dev, state->checked);
 
 	crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 	if (crtc_state)
@@ -528,6 +531,7 @@ drm_atomic_get_plane_state(struct drm_atomic_state *state,
 	struct drm_plane_state *plane_state;
 
 	WARN_ON(!state->acquire_ctx);
+	drm_WARN_ON(state->dev, state->checked);
 
 	/* the legacy pointers should never be set */
 	WARN_ON(plane->fb);
@@ -837,6 +841,7 @@ drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
 	struct drm_private_state *obj_state;
 
 	WARN_ON(!state->acquire_ctx);
+	drm_WARN_ON(state->dev, state->checked);
 
 	obj_state = drm_atomic_get_new_private_obj_state(state, obj);
 	if (obj_state)
@@ -1131,6 +1136,7 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state,
 	struct drm_connector_state *connector_state;
 
 	WARN_ON(!state->acquire_ctx);
+	drm_WARN_ON(state->dev, state->checked);
 
 	ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
 	if (ret)
@@ -1543,6 +1549,8 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
 		     requested_crtc, affected_crtc);
 	}
 
+	state->checked = true;
+
 	return 0;
 }
 EXPORT_SYMBOL(drm_atomic_check_only);
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 155e82f87e4d..2e433d44658d 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -523,6 +523,14 @@ struct drm_atomic_state {
 	 */
 	bool duplicated : 1;
 
+	/**
+	 * @checked:
+	 *
+	 * Indicates the state has been checked and thus must no longer
+	 * be mutated. For internal use only, do not consult from drivers.
+	 */
+	bool checked : 1;
+
 	/**
 	 * @planes:
 	 *
-- 
2.49.1


  reply	other threads:[~2025-10-17 16:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17 16:33 [PATCH 1/2] drm/atomic: WARN about missing acquire_ctx in drm_atomic_get_private_obj_state() Ville Syrjala
2025-10-17 16:33 ` Ville Syrjala [this message]
2025-10-20  7:29   ` [PATCH 2/2] drm/atomic: WARN about invalid drm_foo_get_state() usage Maxime Ripard
2025-10-28 20:52     ` Ville Syrjälä
2025-10-17 17:36 ` ✗ i915.CI.BAT: failure for series starting with [1/2] drm/atomic: WARN about missing acquire_ctx in drm_atomic_get_private_obj_state() Patchwork
2025-10-20  7:29 ` [PATCH 1/2] " Maxime Ripard
2025-10-21 14:05 ` ✗ i915.CI.BAT: failure for series starting with [1/2] drm/atomic: WARN about missing acquire_ctx in drm_atomic_get_private_obj_state() (rev2) Patchwork
2025-10-23 18:07 ` ✓ i915.CI.BAT: success for series starting with [1/2] drm/atomic: WARN about missing acquire_ctx in drm_atomic_get_private_obj_state() (rev3) Patchwork
2025-10-24  7:12 ` ✗ i915.CI.Full: failure " Patchwork

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=20251017163327.9074-2-ville.syrjala@linux.intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=mripard@kernel.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