Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gil Dekel <gildekel@google.com>
To: igt-dev@lists.freedesktop.org
Cc: Gil Dekel <gildekel@google.com>, Melissa Wen <mwen@igalia.com>,
	 Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>,
	Swati Sharma <swati2.sharma@intel.com>,
	 Kamil Konieczny <kamil.konieczny@linux.intel.com>,
	Mark Yacoub <markyacoub@google.com>
Subject: [PATCH i-g-t v3 1/2] lib/igt_kms: Reset leftover COLOR_PIPELINE
Date: Tue,  1 Dec 2026 16:50:36 -0500	[thread overview]
Message-ID: <20261201215037.3329830-2-gildekel@google.com> (raw)
In-Reply-To: <20261201215037.3329830-1-gildekel@google.com>

The plane COLOR_PIPELINE property is only visible to clients that set
DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE. Most tests don't, so a pipeline
left active by the previous KMS client stays applied to every plane
they scan out, and IGT has no way to see it. igt_plane_reset() already
resets COLOR_PIPELINE, but only when the test enabled the cap before
igt_display_require().

The kernel keeps plane state when a client closes its fd, so a color
pipeline a compositor selected stays active after it exits unless it
puts the planes back to Bypass first. Anything a test then scans out
on those planes goes through that color transform. On an xe laptop,
two planes were still on non-Bypass pipelines after the compositor was
stopped.

In igt_display_require(), before the planes are initialized, turn the
cap on for a moment and commit COLOR_PIPELINE = 0 plane by plane for
every plane where it isn't 0, stopping at the first -EACCES if the
caller is not DRM master. Warn on other commit failures without
aborting so one bad plane can't block resetting the rest. Then turn
the cap off again unless a plane already exposed COLOR_PIPELINE, which
means the caller had enabled it: with the cap on the kernel hides
COLOR_ENCODING and COLOR_RANGE from property enumeration, which tests
that don't use color pipelines still rely on.

Cc: Melissa Wen <mwen@igalia.com>
Cc: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>
Cc: Swati Sharma <swati2.sharma@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Mark Yacoub <markyacoub@google.com>
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Gil Dekel <gildekel@google.com>
---

Notes:
    v3 (Melissa):
    - Reset leaked planes plane-by-plane directly and stop on -EACCES.
    - Log leaked resets with igt_info(), non-EACCES failures with
      igt_warn(), and -EACCES with igt_debug().
    - Correct commit message and comment: cap hides (not rejects) legacy
      COLOR_ENCODING and COLOR_RANGE from property enumeration.
    v2:
    - Reuse plane_resources from igt_display_require() without helper
      functions or temporary id arrays.

 lib/igt_kms.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 9c4c9b8ff..b88c33d99 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -3126,6 +3126,74 @@ static int crtc_pipe_compare(const void *_a, const void *_b)
 	return a->hardware_pipe - b->hardware_pipe;
 }
 
+/*
+ * Put every plane COLOR_PIPELINE back to Bypass (0).
+ *
+ * COLOR_PIPELINE is only visible with DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE,
+ * so a pipeline left active by a previous client (e.g. a compositor that
+ * was killed) is invisible to IGT and alters every plane it scans out.
+ * Enable the cap just for this reset, then drop it again unless the
+ * caller had already enabled it: with the cap set the kernel hides
+ * COLOR_ENCODING and COLOR_RANGE from property enumeration, which legacy
+ * tests rely on.
+ */
+static void igt_reset_plane_color_pipelines(int drm_fd,
+					    const drmModePlaneRes *plane_res)
+{
+	bool cap_was_set = false;
+
+	for (int i = 0; i < plane_res->count_planes; i++) {
+		if (kmstest_get_property(drm_fd, plane_res->planes[i],
+					 DRM_MODE_OBJECT_PLANE,
+					 "COLOR_PIPELINE", NULL, NULL, NULL)) {
+			cap_was_set = true;
+			break;
+		}
+	}
+
+	if (!cap_was_set &&
+	    drmSetClientCap(drm_fd, DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE, 1))
+		return;
+
+	for (int i = 0; i < plane_res->count_planes; i++) {
+		drmModeAtomicReq *req;
+		uint32_t prop_id;
+		uint64_t value;
+		int ret;
+
+		if (!kmstest_get_property(drm_fd, plane_res->planes[i],
+					  DRM_MODE_OBJECT_PLANE,
+					  "COLOR_PIPELINE",
+					  &prop_id, &value, NULL) || !value)
+			continue;
+
+		req = drmModeAtomicAlloc();
+		igt_assert(req);
+		igt_assert_lte(0, drmModeAtomicAddProperty(req,
+							   plane_res->planes[i],
+							   prop_id, 0));
+		ret = drmModeAtomicCommit(drm_fd, req,
+					  DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
+		drmModeAtomicFree(req);
+		if (ret == -EACCES) {
+			igt_debug("Skipping COLOR_PIPELINE reset: %s\n",
+				  strerror(-ret));
+			break;
+		}
+		if (ret)
+			igt_warn("Plane %u: failed to reset COLOR_PIPELINE %" PRIu64
+				 " to Bypass: %s\n",
+				 plane_res->planes[i], value, strerror(-ret));
+		else
+			igt_info("Plane %u: reset leaked COLOR_PIPELINE %" PRIu64
+				 " to Bypass\n",
+				 plane_res->planes[i], value);
+	}
+
+	if (!cap_was_set)
+		drmSetClientCap(drm_fd, DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE, 0);
+}
+
 /**
  * igt_display_require:
  * @display: a pointer to an #igt_display_t structure
@@ -3214,6 +3282,10 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	plane_resources = drmModeGetPlaneResources(display->drm_fd);
 	igt_assert(plane_resources);
 
+	/* Before igt_crtc_init(), so plane props are read with the caller's caps. */
+	if (display->is_atomic)
+		igt_reset_plane_color_pipelines(drm_fd, plane_resources);
+
 	display->n_planes = plane_resources->count_planes;
 	display->planes = calloc(display->n_planes, sizeof(igt_plane_t));
 	igt_assert_f(display->planes, "Failed to allocate memory for %d planes\n", display->n_planes);
-- 
Gil Dekel, Senior SWE, Google | Android Laptops & Tablets Display


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

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 21:50 [PATCH i-g-t v3 0/2] lib/igt_kms: Reset leftover color state Gil Dekel
2026-12-01 21:50 ` Gil Dekel [this message]
2026-12-04 18:24   ` [PATCH i-g-t v3 1/2] lib/igt_kms: Reset leftover COLOR_PIPELINE Melissa Wen
2026-12-01 21:50 ` [PATCH i-g-t v3 2/2] lib/igt_kms: Reset connector Colorspace Gil Dekel
2026-12-04 18:05   ` Melissa Wen
2026-12-01 22:20 ` ✓ Xe.CI.BAT: success for lib/igt_kms: Reset leftover color state Patchwork
2026-12-01 22:39 ` ✓ i915.CI.BAT: " Patchwork
2026-12-02 18:10 ` ✓ Xe.CI.FULL: " Patchwork
2026-12-02 23:27 ` ✗ 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=20261201215037.3329830-2-gildekel@google.com \
    --to=gildekel@google.com \
    --cc=chaitanya.kumar.borah@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=markyacoub@google.com \
    --cc=mwen@igalia.com \
    --cc=swati2.sharma@intel.com \
    /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