[PATCH igt] igt: Check the physical swizzle status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The kernel tries to hide L-shaped memory with asymmetric swizzling from
userspace by reporting lies through the get-tiling interface. Check for
these lies by comparing the reported swizzle with the actual swizzle,
and only run swizzling tests where we know the underlying physical
swizzling.

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
---
 lib/igt_draw.c                | 10 +++++-----
 lib/igt_sysfs.c               |  3 ++-
 lib/ioctl_wrappers.c          | 23 +++++++++++++++++++----
 lib/ioctl_wrappers.h          |  2 +-
 tests/gem_tiled_pread_basic.c |  2 +-
 5 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index 45fa10f..3afb827 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -246,7 +246,7 @@ static void draw_rect_mmap_cpu(int fd, struct buf_data *buf, struct rect *rect,
 
 	gem_set_domain(fd, buf->handle, I915_GEM_DOMAIN_CPU,
 		       I915_GEM_DOMAIN_CPU);
-	gem_get_tiling(fd, buf->handle, &tiling, &swizzle);
+	igt_require(gem_get_tiling(fd, buf->handle, &tiling, &swizzle));
 
 	/* We didn't implement suport for the older tiling methods yet. */
 	if (tiling != I915_TILING_NONE)
@@ -295,7 +295,7 @@ static void draw_rect_mmap_wc(int fd, struct buf_data *buf, struct rect *rect,
 
 	gem_set_domain(fd, buf->handle, I915_GEM_DOMAIN_GTT,
 		       I915_GEM_DOMAIN_GTT);
-	gem_get_tiling(fd, buf->handle, &tiling, &swizzle);
+	igt_require(gem_get_tiling(fd, buf->handle, &tiling, &swizzle));
 
 	/* We didn't implement suport for the older tiling methods yet. */
 	if (tiling != I915_TILING_NONE)
@@ -392,7 +392,7 @@ static void draw_rect_pwrite(int fd, struct buf_data *buf,
 {
 	uint32_t tiling, swizzle;
 
-	gem_get_tiling(fd, buf->handle, &tiling, &swizzle);
+	igt_require(gem_get_tiling(fd, buf->handle, &tiling, &swizzle));
 
 	switch (tiling) {
 	case I915_TILING_NONE:
@@ -419,7 +419,7 @@ static void draw_rect_blt(int fd, struct cmd_data *cmd_data,
 	uint32_t tiling, swizzle;
 	int pitch;
 
-	gem_get_tiling(fd, buf->handle, &tiling, &swizzle);
+	igt_require(gem_get_tiling(fd, buf->handle, &tiling, &swizzle));
 
 	dst = gem_handle_to_libdrm_bo(cmd_data->bufmgr, fd, "", buf->handle);
 	igt_assert(dst);
@@ -483,7 +483,7 @@ static void draw_rect_render(int fd, struct cmd_data *cmd_data,
 		    rect->w % (32 / buf->bpp) != 0 ||
 		    rect->h % (32 / buf->bpp) != 0);
 
-	gem_get_tiling(fd, buf->handle, &tiling, &swizzle);
+	igt_require(gem_get_tiling(fd, buf->handle, &tiling, &swizzle));
 
 	/* We create a temporary buffer and copy from it using rendercopy. */
 	tmp.size = rect->w * rect->h * pixel_size;
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 612de75..c19821d 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -148,7 +148,8 @@ int igt_sysfs_open_parameters(int device)
 	if (dir < 0)
 		return -1;
 
-	params = openat(dir, "device/driver/module/parameters", O_RDONLY);
+	params = -1;
+	//params = openat(dir, "device/driver/module/parameters", O_RDONLY);
 	close(dir);
 
 	if (params < 0) { /* builtin? */
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 8632878..95bc5e2 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -111,6 +111,19 @@ gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd, const char *name, uint
 	return bo;
 }
 
+static int
+__gem_get_tiling(int fd, struct drm_i915_gem_get_tiling *arg)
+{
+	int err;
+
+	err = 0;
+	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_GET_TILING, arg))
+		err = -errno;
+	errno = 0;
+
+	return err;
+}
+
 /**
  * gem_get_tiling:
  * @fd: open i915 drm file descriptor
@@ -119,21 +132,23 @@ gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd, const char *name, uint
  * @swizzle: (out) bit 6 swizzle mode
  *
  * This wraps the GET_TILING ioctl.
+ *
+ * Returns whether the actual physical tiling matches the reported tiling.
  */
-void
+bool
 gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle)
 {
 	struct drm_i915_gem_get_tiling get_tiling;
-	int ret;
 
 	memset(&get_tiling, 0, sizeof(get_tiling));
 	get_tiling.handle = handle;
 
-	ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling);
-	igt_assert(ret == 0);
+	igt_assert_eq(__gem_get_tiling(fd, &get_tiling), 0);
 
 	*tiling = get_tiling.tiling_mode;
 	*swizzle = get_tiling.swizzle_mode;
+
+	return get_tiling.phys_swizzle_mode == get_tiling.swizzle_mode;
 }
 
 int __gem_set_tiling(int fd, uint32_t handle, uint32_t tiling, uint32_t stride)
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 42dc3cb..465f760 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -53,7 +53,7 @@ drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd,
 /* ioctl_wrappers.c:
  *
  * ioctl wrappers and similar stuff for bare metal testing */
-void gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle);
+bool gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle);
 void gem_set_tiling(int fd, uint32_t handle, uint32_t tiling, uint32_t stride);
 int __gem_set_tiling(int fd, uint32_t handle, uint32_t tiling, uint32_t stride);
 
diff --git a/tests/gem_tiled_pread_basic.c b/tests/gem_tiled_pread_basic.c
index 1dfd87c..bad3650 100644
--- a/tests/gem_tiled_pread_basic.c
+++ b/tests/gem_tiled_pread_basic.c
@@ -121,7 +121,7 @@ igt_simple_main
 	fd = drm_open_driver(DRIVER_INTEL);
 
 	handle = create_bo(fd);
-	gem_get_tiling(fd, handle, &tiling, &swizzle);
+	igt_require(gem_get_tiling(fd, handle, &tiling, &swizzle));
 
 	devid = intel_get_drm_devid(fd);
 
-- 
2.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux