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>,
	 Mark Yacoub <markyacoub@google.com>
Subject: [PATCH i-g-t 1/2] lib/igt_kms: Reset leftover COLOR_PIPELINE
Date: Sat, 14 Nov 2026 17:29:01 -0500	[thread overview]
Message-ID: <20261114222902.1404033-2-gildekel@google.com> (raw)
In-Reply-To: <20261114222902.1404033-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 on every plane
where it isn't 0. If that commit fails, retry plane by plane and only
log failures, so a driver that rejects the reset can't break unrelated
tests. 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 and rejects COLOR_ENCODING and COLOR_RANGE, which
tests that don't use color pipelines still set.

Cc: Melissa Wen <mwen@igalia.com>
Cc: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>
Cc: Swati Sharma <swati2.sharma@intel.com>
Cc: Mark Yacoub <markyacoub@google.com>
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Gil Dekel <gildekel@google.com>
---
 lib/igt_kms.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 915c6a8a2..541dd8c35 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -3110,6 +3110,122 @@ static int crtc_pipe_compare(const void *_a, const void *_b)
 	return a->hardware_pipe - b->hardware_pipe;
 }
 
+static bool planes_expose_color_pipeline(int drm_fd,
+					 const drmModePlaneRes *plane_res)
+{
+	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))
+			return true;
+
+	return false;
+}
+
+static int commit_plane_color_pipeline_bypass(int drm_fd,
+					      const uint32_t *plane_ids,
+					      const uint32_t *prop_ids,
+					      int count)
+{
+	drmModeAtomicReq *req = drmModeAtomicAlloc();
+	int ret;
+
+	igt_assert(req);
+
+	for (int i = 0; i < count; i++)
+		igt_assert_lte(0, drmModeAtomicAddProperty(req, plane_ids[i],
+							   prop_ids[i], 0));
+
+	ret = drmModeAtomicCommit(drm_fd, req, DRM_MODE_ATOMIC_ALLOW_MODESET,
+				  NULL);
+	drmModeAtomicFree(req);
+
+	return ret;
+}
+
+/*
+ * 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 rejects
+ * COLOR_ENCODING and COLOR_RANGE, which legacy tests rely on.
+ */
+static void igt_reset_plane_color_pipelines(int drm_fd)
+{
+	drmModePlaneRes *plane_res;
+	uint32_t *plane_ids, *prop_ids;
+	bool cap_was_set;
+	int count = 0, ret;
+
+	plane_res = drmModeGetPlaneResources(drm_fd);
+	if (!plane_res)
+		return;
+
+	if (!plane_res->count_planes) {
+		drmModeFreePlaneResources(plane_res);
+		return;
+	}
+
+	cap_was_set = planes_expose_color_pipeline(drm_fd, plane_res);
+	if (!cap_was_set &&
+	    drmSetClientCap(drm_fd, DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE, 1)) {
+		drmModeFreePlaneResources(plane_res);
+		return;
+	}
+
+	plane_ids = calloc(plane_res->count_planes, sizeof(*plane_ids));
+	prop_ids = calloc(plane_res->count_planes, sizeof(*prop_ids));
+	igt_assert(plane_ids && prop_ids);
+
+	for (int i = 0; i < plane_res->count_planes; i++) {
+		uint32_t prop_id;
+		uint64_t value;
+
+		if (!kmstest_get_property(drm_fd, plane_res->planes[i],
+					  DRM_MODE_OBJECT_PLANE, "COLOR_PIPELINE",
+					  &prop_id, &value, NULL) || !value)
+			continue;
+
+		igt_debug("Plane %u: resetting leaked COLOR_PIPELINE %" PRIu64
+			  " to Bypass\n", plane_res->planes[i], value);
+		plane_ids[count] = plane_res->planes[i];
+		prop_ids[count] = prop_id;
+		count++;
+	}
+
+	if (count) {
+		ret = commit_plane_color_pipeline_bypass(drm_fd, plane_ids,
+							 prop_ids, count);
+		if (ret)
+			igt_debug("Resetting %d COLOR_PIPELINE(s) at once failed: %s\n",
+				  count, strerror(-ret));
+
+		/* Retry plane by plane so one bad plane can't block the rest. */
+		for (int i = 0; ret && i < count; i++) {
+			int plane_ret;
+
+			plane_ret = commit_plane_color_pipeline_bypass(drm_fd,
+								       &plane_ids[i],
+								       &prop_ids[i],
+								       1);
+			if (plane_ret)
+				igt_info("Plane %u: failed to reset COLOR_PIPELINE to Bypass: %s\n",
+					 plane_ids[i], strerror(-plane_ret));
+		}
+	}
+
+	free(plane_ids);
+	free(prop_ids);
+
+	if (!cap_was_set)
+		drmSetClientCap(drm_fd, DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE, 0);
+
+	drmModeFreePlaneResources(plane_res);
+}
+
 /**
  * igt_display_require:
  * @display: a pointer to an #igt_display_t structure
@@ -3195,6 +3311,10 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	if (drmSetClientCap(drm_fd, LOCAL_DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT, 1) == 0)
 		display->has_virt_cursor_plane = 1;
 
+	/* 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 = drmModeGetPlaneResources(display->drm_fd);
 	igt_assert(plane_resources);
 
-- 
Gil Dekel, Software Engineer, Google / ChromeOS Display and Graphics


  reply	other threads:[~2026-11-16  5:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 22:29 [PATCH i-g-t 0/2] lib/igt_kms: Reset leftover KMS color state Gil Dekel
2026-11-14 22:29 ` Gil Dekel [this message]
2026-11-14 22:29 ` [PATCH i-g-t 2/2] lib/igt_kms: Reset connector Colorspace Gil Dekel
2026-11-15  0:18 ` [PATCH i-g-t v2 0/2] lib/igt_kms: Reset leftover color state Gil Dekel
2026-11-15  0:18   ` [PATCH i-g-t v2 1/2] lib/igt_kms: Reset leftover COLOR_PIPELINE Gil Dekel
2026-11-15  0:18   ` [PATCH i-g-t v2 2/2] lib/igt_kms: Reset connector Colorspace Gil Dekel
2026-11-16  8:36 ` ✓ Xe.CI.BAT: success for lib/igt_kms: Reset leftover KMS color state Patchwork
2026-11-16  8:43 ` ✓ i915.CI.BAT: " Patchwork
2026-11-16 10:56 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-11-16 12:23 ` ✗ i915.CI.Full: " 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=20261114222902.1404033-2-gildekel@google.com \
    --to=gildekel@google.com \
    --cc=chaitanya.kumar.borah@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --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