Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/igt_power: Fix crash on Xe devices by initializing xe_device cache
@ 2026-05-18 12:32 Sebastian Brzezinka
  2026-05-19  1:22 ` ✓ Xe.CI.BAT: success for " Patchwork
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Sebastian Brzezinka @ 2026-05-18 12:32 UTC (permalink / raw)
  To: igt-dev; +Cc: Sebastian Brzezinka, kamil.konieczny, ashutosh.dixit

Opening a DRM device with plain open() does not initialize the Xe device
cache. When igt_power_open() calls is_intel_dgfx() -> xe_has_vram(), it
uses find_in_cache() which asserts the cache entry exists, causing a crash
on Xe devices with: xe_query-CRITICAL: Failed assertion: xe_dev

Fix this by opening the device with O_RDWR (required for DRM ioctls),
calling xe_device_get() for Xe devices to populate the cache before
calling igt_power_open(), and calling xe_device_put() on cleanup for
proper cache management.

Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
---
 tools/igt_power.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/tools/igt_power.c b/tools/igt_power.c
index 6dd180d34..11da0430b 100644
--- a/tools/igt_power.c
+++ b/tools/igt_power.c
@@ -11,6 +11,7 @@
 
 #include "drmtest.h"
 #include "igt_power.h"
+#include "xe/xe_query.h"
 
 struct measurement {
 	int battery_index;
@@ -38,12 +39,15 @@ static bool prepare(struct measurement *m)
 		int ret, fd = -1;
 
 		if (m->drm_device) {
-			fd = open(m->drm_device, O_RDONLY);
+			fd = open(m->drm_device, O_RDWR);
 			if (fd < 0) {
 				fprintf(stderr, "Unable to open drm device %s (%d)\n",
 					m->drm_device, -errno);
 				return false;
 			}
+
+			if (is_xe_device(fd))
+				xe_device_get(fd);
 		}
 
 		ret = igt_power_open(fd, &m->power, m->rapl_domain);
@@ -54,12 +58,20 @@ static bool prepare(struct measurement *m)
 			else
 				fprintf(stderr, "Unable to open rapl domain %s (%d)\n",
 					m->rapl_domain, ret);
-			close(fd);
+			if (fd >= 0) {
+				if (is_xe_device(fd))
+					xe_device_put(fd);
+				close(fd);
+			}
 
 			return false;
 		}
 
-		close(fd);
+		if (fd >= 0) {
+			if (is_xe_device(fd))
+				xe_device_put(fd);
+			close(fd);
+		}
 	}
 
 	return true;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-05-19 20:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 12:32 [PATCH] tools/igt_power: Fix crash on Xe devices by initializing xe_device cache Sebastian Brzezinka
2026-05-19  1:22 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-05-19  1:43 ` ✓ i915.CI.BAT: " Patchwork
2026-05-19  9:19 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-05-19 10:23 ` [PATCH] " Krzysztof Karas
2026-05-19 10:28   ` Sebastian Brzezinka
2026-05-19 10:52 ` Zbigniew Kempczyński
2026-05-19 11:28 ` Kamil Konieczny
2026-05-19 11:47   ` Sebastian Brzezinka
2026-05-19 20:55 ` ✗ i915.CI.Full: failure for " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox