Skip to contentSkip to conversation

lib/ioctl_wrappers: Keep IGT working without pread/pwrite ioctls

PATCH In review Ashutosh Dixit 4 participants 6 messages Sep 30, 2020 – Jan 11, 2021 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/ioctl_wrappers: Keep IGT working without pread/pwrite ioctls

The general direction at this time is to phase out pread/write ioctls and not support them in future products. This means IGT must handle the absence of these ioctls. This patch does this by modifying gem_read() and gem_write() to do the read/write using the pread/pwrite ioctls first but when these ioctls are unavailable fall back to doing the read/write using a combination of mmap and memcpy.

Callers who must absolutely use the pread/pwrite ioctls (such as tests which test these ioctls or must otherwise only use the pread/pwrite ioctls) must use gem_require_pread_pwrite() to skip when these ioctls are not available.

v1: Removed __gem_pread, gem_pread, __gem_pwrite and gem_pwrite
introduced previously since they are not necessary, gem_require_pread_pwrite is sufficient
v2: Fix CI failures in gem_advise and gen9_exec_parse by introducing
gem_require_pread_pwrite
v3: Skip mmap for 0 length read/write's
v4: Remove redundant igt_assert's
v5: Re-run
v6: s/EOPNOTSUPP/-EOPNOTSUPP/

---
 lib/ioctl_wrappers.c                        | 135 +++++++++++++++++++-
 lib/ioctl_wrappers.h                        |   3 +
 tests/i915/gem_madvise.c                    |   2 +
 tests/i915/gem_partial_pwrite_pread.c       |   1 +
 tests/i915/gem_pread.c                      |   1 +
 tests/i915/gem_pread_after_blit.c           |   1 +
 tests/i915/gem_pwrite.c                     |   1 +
 tests/i915/gem_pwrite_snooped.c             |   1 +
 tests/i915/gem_readwrite.c                  |   1 +
 tests/i915/gem_set_tiling_vs_pwrite.c       |   1 +
 tests/i915/gem_tiled_partial_pwrite_pread.c |   1 +
 tests/i915/gem_tiled_pread_basic.c          |   1 +
 tests/i915/gem_tiled_pread_pwrite.c         |   1 +
 tests/i915/gem_userptr_blits.c              |   2 +
 tests/i915/gen9_exec_parse.c                |   4 +-
 15 files changed, 149 insertions(+), 7 deletions(-)
lib/ioctl_wrappers.c +129 -6
index edac50f0f..ac77b3eb6 100644
@@ -55,6 +55,7 @@
 #include "igt_debugfs.h"
 #include "igt_sysfs.h"
 #include "config.h"
+#include "i915/gem_mman.h"
 
 #ifdef HAVE_VALGRIND
 #include <valgrind/valgrind.h>
@@ -323,6 +324,70 @@ void gem_close(int fd, uint32_t handle)
 	do_ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close_bo);
 }
 
+static bool is_cache_coherent(int fd, uint32_t handle)
+{
+	return gem_get_caching(fd, handle) != I915_CACHING_NONE;
+}
+
+static void mmap_write(int fd, uint32_t handle, uint64_t offset,
+		       const void *buf, uint64_t length)
+{
+	void *map = NULL;
+
+	if (!length)
+		return;
+
+	if (is_cache_coherent(fd, handle)) {
+		/* offset arg for mmap functions must be 0 */
+		map = __gem_mmap__cpu_coherent(fd, handle, 0, offset + length,
+					       PROT_READ | PROT_WRITE);
+		if (map)
+			gem_set_domain(fd, handle,
+				       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+	}
+
+	if (!map) {
+		map = __gem_mmap_offset__wc(fd, handle, 0, offset + length,
+					    PROT_READ | PROT_WRITE);
+		if (!map)
+			map = gem_mmap__wc(fd, handle, 0, offset + length,
+					   PROT_READ | PROT_WRITE);
+		gem_set_domain(fd, handle,
+			       I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
+	}
+
+	memcpy(map + offset, buf, length);
+	munmap(map, offset + length);
+}
+
+static void mmap_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
+{
+	void *map = NULL;
+
+	if (!length)
+		return;
+
+	if (gem_has_llc(fd) || is_cache_coherent(fd, handle)) {
+		/* offset arg for mmap functions must be 0 */
+		map = __gem_mmap__cpu_coherent(fd, handle, 0,
+					       offset + length, PROT_READ);
+		if (map)
+			gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, 0);
+	}
+
+	if (!map) {
+		map = __gem_mmap_offset__wc(fd, handle, 0, offset + length,
+					    PROT_READ);
+		if (!map)
+			map = gem_mmap__wc(fd, handle, 0, offset + length,
+					   PROT_READ);
+		gem_set_domain(fd, handle, I915_GEM_DOMAIN_WC, 0);
+	}
+
+	memcpy(buf, map + offset, length);
+	munmap(map, offset + length);
+}
+
 int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length)
 {
 	struct drm_i915_gem_pwrite gem_pwrite;
@@ -348,12 +413,18 @@ int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint6
  * @buf: pointer to the data to write into the buffer
  * @length: size of the subrange
  *
- * This wraps the PWRITE ioctl, which is to upload a linear data to a subrange
- * of a gem buffer object.
+ * Method to write to a gem object. Uses the PWRITE ioctl when it is
+ * available, else it uses mmap + memcpy to upload linear data to a
+ * subrange of a gem buffer object.
  */
 void gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length)
 {
-	igt_assert_eq(__gem_write(fd, handle, offset, buf, length), 0);
+	int ret = __gem_write(fd, handle, offset, buf, length);
+
+	igt_assert(ret == 0 || ret == -EOPNOTSUPP);
+
+	if (ret == -EOPNOTSUPP)
+		mmap_write(fd, handle, offset, buf, length);
 }
 
 int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
@@ -380,12 +451,64 @@ int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t len
  * @buf: pointer to the data to read into
  * @length: size of the subrange
  *
- * This wraps the PREAD ioctl, which is to download a linear data to a subrange
- * of a gem buffer object.
+ * Method to read from a gem object. Uses the PREAD ioctl when it is
+ * available, else it uses mmap + memcpy to download linear data from a
+ * subrange of a gem buffer object.
  */
 void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
 {
-	igt_assert_eq(__gem_read(fd, handle, offset, buf, length), 0);
+	int ret = __gem_read(fd, handle, offset, buf, length);
+
+	igt_assert(ret == 0 || ret == -EOPNOTSUPP);
+
+	if (ret == -EOPNOTSUPP)
+		mmap_read(fd, handle, offset, buf, length);
+}
+
+/**
+ * gem_has_pwrite
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether pwrite ioctl is supported
+ */
+bool gem_has_pwrite(int fd)
+{
+	uint32_t handle = gem_create(fd, 4096);
+	int buf, ret;
+
+	ret = __gem_write(fd, handle, 0, &buf, sizeof(buf));
+	gem_close(fd, handle);
+
+	return ret != -EOPNOTSUPP;
+}
+
+/**
+ * gem_has_pread
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether pread ioctl is supported
+ */
+bool gem_has_pread(int fd)
+{
+	uint32_t handle = gem_create(fd, 4096);
+	int buf, ret;
+
+	ret = __gem_read(fd, handle, 0, &buf, sizeof(buf));
+	gem_close(fd, handle);
+
+	return ret != -EOPNOTSUPP;
+}
+
+/**
+ * gem_require_pread_pwrite
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether pread/pwrite ioctls are supported
+ * and skip if they are not
+ */
+void gem_require_pread_pwrite(int fd)
+{
+	igt_require(gem_has_pread(fd) && gem_has_pwrite(fd));
 }
 
 int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write)
lib/ioctl_wrappers.h +3 -0
index b76bea564..81166000a 100644
@@ -71,6 +71,9 @@ int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint6
 void gem_write(int fd, uint32_t handle, uint64_t offset,  const void *buf, uint64_t length);
 int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length);
 void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length);
+bool gem_has_pwrite(int fd);
+bool gem_has_pread(int fd);
+void gem_require_pread_pwrite(int fd);
 int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
 void gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
 int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns);
tests/i915/gem_madvise.c +2 -0
index 54c9befff..92e1c5192 100644
@@ -154,6 +154,7 @@ dontneed_before_pwrite(void)
 	uint32_t bbe = MI_BATCH_BUFFER_END;
 	uint32_t handle;
 
+	gem_require_pread_pwrite(fd);
 	handle = gem_create(fd, OBJECT_SIZE);
 	gem_madvise(fd, handle, I915_MADV_DONTNEED);
 
@@ -170,6 +171,7 @@ dontneed_before_exec(void)
 	struct drm_i915_gem_exec_object2 exec;
 	uint32_t buf[] = { MI_BATCH_BUFFER_END, 0 };
 
+	gem_require_pread_pwrite(fd);
 	memset(&execbuf, 0, sizeof(execbuf));
 	memset(&exec, 0, sizeof(exec));
 
tests/i915/gem_partial_pwrite_pread.c +1 -0
index b10284721..fd7b19f31 100644
@@ -281,6 +281,7 @@ igt_main
 		data.drm_fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(data.drm_fd);
 		gem_require_blitter(data.drm_fd);
+		gem_require_pread_pwrite(data.drm_fd);
 
 		data.devid = intel_get_drm_devid(data.drm_fd);
 		data.bops = buf_ops_create(data.drm_fd);
tests/i915/gem_pread.c +1 -0
index 6d12b8e9f..db1eacedc 100644
@@ -149,6 +149,7 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
+		gem_require_pread_pwrite(fd);
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
tests/i915/gem_pread_after_blit.c +1 -0
index 81454c930..5c99d0887 100644
@@ -212,6 +212,7 @@ igt_main
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
+		gem_require_pread_pwrite(fd);
 
 		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
 		drm_intel_bufmgr_gem_enable_reuse(bufmgr);
tests/i915/gem_pwrite.c +1 -0
index e491263fd..eea51f978 100644
@@ -317,6 +317,7 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
+		gem_require_pread_pwrite(fd);
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
tests/i915/gem_pwrite_snooped.c +1 -0
index 4a3395241..a2eca6afc 100644
@@ -132,6 +132,7 @@ igt_simple_main
 	fd = drm_open_driver(DRIVER_INTEL);
 	igt_require_gem(fd);
 	gem_require_blitter(fd);
+	gem_require_pread_pwrite(fd);
 
 	devid = intel_get_drm_devid(fd);
 	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
tests/i915/gem_readwrite.c +1 -0
index 6b2977c1c..ca31741c6 100644
@@ -83,6 +83,7 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
+		gem_require_pread_pwrite(fd);
 
 		handle = gem_create(fd, OBJECT_SIZE);
 	}
tests/i915/gem_set_tiling_vs_pwrite.c +1 -0
index 302ea24b6..8f38c9b9b 100644
@@ -55,6 +55,7 @@ igt_simple_main
 
 	fd = drm_open_driver(DRIVER_INTEL);
 	igt_require(gem_available_fences(fd) > 0);
+	gem_require_pread_pwrite(fd);
 
 	for (int i = 0; i < OBJECT_SIZE/4; i++)
 		data[i] = i;
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -0
index 7de5358b2..0c4545990 100644
@@ -270,6 +270,7 @@ igt_main
 		igt_require_gem(fd);
 		gem_require_mappable_ggtt(fd);
 		gem_require_blitter(fd);
+		gem_require_pread_pwrite(fd);
 
 		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
 		//drm_intel_bufmgr_gem_enable_reuse(bufmgr);
tests/i915/gem_tiled_pread_basic.c +1 -0
index 7cb644104..f8f73c03a 100644
@@ -127,6 +127,7 @@ igt_simple_main
 	igt_require(gem_available_fences(fd) > 0);
 	handle = create_bo(fd);
 	igt_require(gem_get_tiling(fd, handle, &tiling, &swizzle));
+	gem_require_pread_pwrite(fd);
 
 	devid = intel_get_drm_devid(fd);
 
tests/i915/gem_tiled_pread_pwrite.c +1 -0
index f58048faa..28490840f 100644
@@ -114,6 +114,7 @@ igt_simple_main
 	
 	fd = drm_open_driver(DRIVER_INTEL);
 	igt_require(gem_available_fences(fd) > 0);
+	gem_require_pread_pwrite(fd);
 
 	count = gem_available_fences(fd) + 1;
 	intel_require_memory(2 * count, sizeof(linear), CHECK_RAM);
tests/i915/gem_userptr_blits.c +2 -0
index 268423dcd..0ccfdbd9c 100644
@@ -890,6 +890,7 @@ static int test_forbidden_ops(int fd)
 	uint32_t handle;
 	void *ptr;
 
+	gem_require_pread_pwrite(fd);
 	igt_assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0);
 	gem_userptr(fd, ptr, PAGE_SIZE, 0, userptr_flags, &handle);
 
@@ -1416,6 +1417,7 @@ static void test_readonly_pwrite(int i915)
 	 */
 
 	igt_require(igt_setup_clflush());
+	gem_require_pread_pwrite(i915);
 
 	sz = 16 << 12;
 	pages = mmap(NULL, sz, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
tests/i915/gen9_exec_parse.c +3 -1
index 7ddb5bf2b..cfb6de080 100644
@@ -1104,8 +1104,10 @@ igt_main
 			   -EINVAL);
 	}
 
-	igt_subtest("batch-invalid-length")
+	igt_subtest("batch-invalid-length") {
+		gem_require_pread_pwrite(i915);
 		test_invalid_length(i915, handle);
+	}
 
 	igt_subtest("basic-rejected")
 		test_rejected(i915, handle, false);
Signature · 6 lines
2.26.2.108.g048abe1751

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

[igt-dev] ✓ Fi.CI.BAT: success for lib/ioctl_wrappers: Keep IGT working without pread/pwrite ioctls (rev6)

== Series Details ==

== Series Details ==

Series: lib/ioctl_wrappers: Keep IGT working without pread/pwrite ioctls (rev6)
URL : https://patchwork.freedesktop.org/series/81384/
State : success

== Summary ==

CI Bug Log - changes from IGT_5793 -> IGTPW_5026
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/index.html

Known issues
------------

Here are the changes found in IGTPW_5026 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- fi-byt-j1900: [PASS][1] -> [DMESG-WARN][2] ([i915#1982]) +1 similar issue
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/fi-byt-j1900/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/fi-byt-j1900/igt@[email protected]

#### Possible fixes ####

* igt@debugfs_test@read_all_entries:
- fi-bsw-nick: [INCOMPLETE][3] ([i915#1250] / [i915#1436]) -> [PASS][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/fi-bsw-nick/igt@debugfs_test@read_all_entries.html
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/fi-bsw-nick/igt@debugfs_test@read_all_entries.html

* igt@i915_selftest@live@gt_pm:
- {fi-kbl-7560u}: [DMESG-FAIL][5] ([i915#2524]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/fi-kbl-7560u/igt@i915_selftest@live@gt_pm.html
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/fi-kbl-7560u/igt@i915_selftest@live@gt_pm.html

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- fi-bsw-n3050: [DMESG-WARN][7] ([i915#1982]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/fi-bsw-n3050/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/fi-bsw-n3050/igt@[email protected]
- fi-bsw-kefka: [DMESG-WARN][9] ([i915#1982]) -> [PASS][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/fi-bsw-kefka/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/fi-bsw-kefka/igt@[email protected]

* igt@kms_flip@basic-flip-vs-wf_vblank@b-edp1:
- fi-icl-u2: [DMESG-WARN][11] ([i915#1982]) -> [PASS][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/fi-icl-u2/igt@kms_flip@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/fi-icl-u2/igt@kms_flip@[email protected]

#### Warnings ####

* igt@i915_pm_rpm@module-reload:
- fi-kbl-guc: [DMESG-FAIL][13] ([i915#2203]) -> [DMESG-WARN][14] ([i915#2203])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/fi-kbl-guc/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/fi-kbl-guc/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[i915#1250]: https://gitlab.freedesktop.org/drm/intel/issues/1250
[i915#1436]: https://gitlab.freedesktop.org/drm/intel/issues/1436
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#2203]: https://gitlab.freedesktop.org/drm/intel/issues/2203
[i915#2524]: https://gitlab.freedesktop.org/drm/intel/issues/2524

Participating hosts (46 -> 37)
------------------------------

Missing (9): fi-ilk-m540 fi-tgl-dsi fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-kbl-x1275 fi-byt-clapper fi-bdw-samus

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_5793 -> IGTPW_5026

CI-20190529: 20190529
CI_DRM_9075: fd24361b2b76956b5c056bc430a4c77edecb7744 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_5026: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/index.html
IGT_5793: c34792447c9fc4d05dd75873cdb99d9ffe57ea23 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/index.html

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#2 lore raw

[igt-dev] ✓ Fi.CI.IGT: success for lib/ioctl_wrappers: Keep IGT working without pread/pwrite ioctls (rev6)

In reply to Ashutosh Dixit
== Series Details ==

== Series Details ==

Series: lib/ioctl_wrappers: Keep IGT working without pread/pwrite ioctls (rev6)
URL : https://patchwork.freedesktop.org/series/81384/
State : success

== Summary ==

CI Bug Log - changes from IGT_5793_full -> IGTPW_5026_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/index.html

Known issues
------------

Here are the changes found in IGTPW_5026_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gen9_exec_parse@allowed-all:
- shard-kbl: [PASS][1] -> [DMESG-WARN][2] ([i915#1436] / [i915#716])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-kbl2/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-kbl3/igt@[email protected]

* igt@i915_pm_dc@dc5-psr:
- shard-iclb: [PASS][3] -> [FAIL][4] ([i915#1899])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb6/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb2/igt@[email protected]

* igt@kms_big_fb@linear-64bpp-rotate-180:
- shard-iclb: [PASS][5] -> [DMESG-WARN][6] ([i915#1982])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb1/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb3/igt@[email protected]

* igt@kms_cursor_edge_walk@pipe-b-128x128-bottom-edge:
- shard-apl: [PASS][7] -> [DMESG-WARN][8] ([i915#1635] / [i915#1982])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-apl1/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-apl2/igt@[email protected]

* igt@kms_cursor_legacy@flip-vs-cursor-crc-legacy:
- shard-snb: [PASS][9] -> [SKIP][10] ([fdo#109271]) +1 similar issue
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-snb5/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-snb7/igt@[email protected]

* igt@kms_flip@flip-vs-suspend@c-dp1:
- shard-kbl: [PASS][11] -> [DMESG-WARN][12] ([i915#180]) +2 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-kbl6/igt@kms_flip@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-kbl1/igt@kms_flip@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-render:
- shard-kbl: [PASS][13] -> [DMESG-WARN][14] ([i915#1982])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-kbl3/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-render.html
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-kbl4/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-render.html

* igt@kms_frontbuffer_tracking@fbcpsr-1p-rte:
- shard-tglb: [PASS][15] -> [DMESG-WARN][16] ([i915#1982]) +2 similar issues
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-tglb3/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-tglb8/igt@[email protected]

* igt@kms_psr@psr2_cursor_mmap_cpu:
- shard-iclb: [PASS][17] -> [SKIP][18] ([fdo#109441]) +1 similar issue
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb2/igt@kms_psr@psr2_cursor_mmap_cpu.html
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb4/igt@kms_psr@psr2_cursor_mmap_cpu.html

* igt@kms_setmode@basic:
- shard-apl: [PASS][19] -> [FAIL][20] ([i915#1635] / [i915#31])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-apl2/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-apl3/igt@[email protected]

* igt@kms_vblank@pipe-b-accuracy-idle:
- shard-glk: [PASS][21] -> [FAIL][22] ([i915#43])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-glk5/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-glk9/igt@[email protected]

* igt@perf@non-sampling-read-error:
- shard-tglb: [PASS][23] -> [SKIP][24] ([i915#405])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-tglb1/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-tglb1/igt@[email protected]
- shard-apl: [PASS][25] -> [SKIP][26] ([fdo#109271] / [i915#1635])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-apl7/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-apl3/igt@[email protected]
- shard-glk: [PASS][27] -> [SKIP][28] ([fdo#109271])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-glk9/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-glk6/igt@[email protected]
- shard-hsw: [PASS][29] -> [SKIP][30] ([fdo#109271])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-hsw4/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-hsw4/igt@[email protected]
- shard-kbl: [PASS][31] -> [SKIP][32] ([fdo#109271])
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-kbl6/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-kbl3/igt@[email protected]
- shard-iclb: [PASS][33] -> [SKIP][34] ([i915#405])
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb5/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb8/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_reloc@basic-many-active@rcs0:
- shard-apl: [FAIL][35] ([i915#1635] / [i915#2389]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-apl1/igt@gem_exec_reloc@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-apl7/igt@gem_exec_reloc@[email protected]

* igt@gem_exec_reloc@basic-many-active@vecs0:
- shard-glk: [FAIL][37] ([i915#2389]) -> [PASS][38] +1 similar issue
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-glk2/igt@gem_exec_reloc@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-glk4/igt@gem_exec_reloc@[email protected]

* igt@gem_exec_whisper@basic-contexts-priority-all:
- shard-glk: [DMESG-WARN][39] ([i915#118] / [i915#95]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-glk2/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-glk5/igt@[email protected]

* igt@i915_pm_dc@dc6-psr:
- shard-iclb: [FAIL][41] ([i915#454]) -> [PASS][42]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb4/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb7/igt@[email protected]

* igt@kms_big_fb@linear-8bpp-rotate-180:
- shard-kbl: [DMESG-WARN][43] ([i915#1982]) -> [PASS][44]
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-kbl4/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-kbl2/igt@[email protected]

* igt@kms_flip@dpms-vs-vblank-race@a-hdmi-a1:
- shard-glk: [DMESG-WARN][45] ([i915#1982]) -> [PASS][46]
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-glk3/igt@kms_flip@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-glk2/igt@kms_flip@[email protected]

* igt@kms_flip@plain-flip-fb-recreate-interruptible@a-hdmi-a1:
- shard-glk: [FAIL][47] ([i915#2122]) -> [PASS][48]
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-glk2/igt@kms_flip@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-glk5/igt@kms_flip@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-shrfb-draw-mmap-gtt:
- shard-iclb: [DMESG-WARN][49] ([i915#1982]) -> [PASS][50]
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb2/igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-shrfb-draw-mmap-gtt.html
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb2/igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-shrfb-draw-mmap-gtt.html

* igt@kms_frontbuffer_tracking@fbc-2p-primscrn-cur-indfb-draw-render:
- shard-glk: [FAIL][51] ([i915#49]) -> [PASS][52]
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-glk8/igt@kms_frontbuffer_tracking@fbc-2p-primscrn-cur-indfb-draw-render.html
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-glk4/igt@kms_frontbuffer_tracking@fbc-2p-primscrn-cur-indfb-draw-render.html

* igt@kms_frontbuffer_tracking@fbc-rgb565-draw-pwrite:
- shard-tglb: [DMESG-WARN][53] ([i915#1982]) -> [PASS][54]
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-tglb7/igt@[email protected]
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-tglb8/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-suspend:
- shard-kbl: [INCOMPLETE][55] ([i915#155]) -> [PASS][56]
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-kbl6/igt@[email protected]
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-kbl2/igt@[email protected]

* igt@kms_hdr@bpc-switch-suspend:
- shard-kbl: [DMESG-WARN][57] ([i915#180]) -> [PASS][58] +5 similar issues
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-kbl2/igt@[email protected]
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-kbl3/igt@[email protected]

* igt@kms_panel_fitting@atomic-fastset:
- shard-iclb: [FAIL][59] ([i915#83]) -> [PASS][60]
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb1/igt@[email protected]
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb1/igt@[email protected]

* igt@kms_psr2_su@page_flip:
- shard-iclb: [SKIP][61] ([fdo#109642] / [fdo#111068]) -> [PASS][62]
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb4/igt@kms_psr2_su@page_flip.html
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb2/igt@kms_psr2_su@page_flip.html

* igt@kms_psr@psr2_suspend:
- shard-iclb: [SKIP][63] ([fdo#109441]) -> [PASS][64] +1 similar issue
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb4/igt@kms_psr@psr2_suspend.html
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb2/igt@kms_psr@psr2_suspend.html

#### Warnings ####

* igt@gem_eio@in-flight-suspend:
- shard-tglb: [DMESG-WARN][65] ([i915#1436] / [i915#1602] / [i915#1887] / [i915#2411]) -> [DMESG-WARN][66] ([i915#2411])
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-tglb3/igt@[email protected]
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-tglb3/igt@[email protected]

* igt@i915_pm_dc@dc3co-vpb-simulation:
- shard-iclb: [SKIP][67] ([i915#658]) -> [SKIP][68] ([i915#588])
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-iclb7/igt@[email protected]
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-iclb2/igt@[email protected]

* igt@kms_content_protection@atomic:
- shard-apl: [TIMEOUT][69] ([i915#1319] / [i915#1635] / [i915#1958]) -> [FAIL][70] ([fdo#110321] / [fdo#110336] / [i915#1635])
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-apl3/igt@[email protected]
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-apl7/igt@[email protected]

* igt@kms_content_protection@lic:
- shard-apl: [FAIL][71] ([fdo#110321] / [i915#1635]) -> [TIMEOUT][72] ([i915#1319] / [i915#1635] / [i915#1958])
[71]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-apl1/igt@[email protected]
[72]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-apl1/igt@[email protected]

* igt@kms_plane@plane-panning-bottom-right-suspend-pipe-a-planes:
- shard-tglb: [DMESG-WARN][73] ([i915#2411]) -> [INCOMPLETE][74] ([i915#456])
[73]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_5793/shard-tglb1/igt@[email protected]
[74]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/shard-tglb2/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#109642]: https://bugs.freedesktop.org/show_bug.cgi?id=109642
[fdo#110321]: https://bugs.freedesktop.org/show_bug.cgi?id=110321
[fdo#110336]: https://bugs.freedesktop.org/show_bug.cgi?id=110336
[fdo#111068]: https://bugs.freedesktop.org/show_bug.cgi?id=111068
[i915#118]: https://gitlab.freedesktop.org/drm/intel/issues/118
[i915#1319]: https://gitlab.freedesktop.org/drm/intel/issues/1319
[i915#1436]: https://gitlab.freedesktop.org/drm/intel/issues/1436
[i915#155]: https://gitlab.freedesktop.org/drm/intel/issues/155
[i915#1602]: https://gitlab.freedesktop.org/drm/intel/issues/1602
[i915#1635]: https://gitlab.freedesktop.org/drm/intel/issues/1635
[i915#180]: https://gitlab.freedesktop.org/drm/intel/issues/180
[i915#1887]: https://gitlab.freedesktop.org/drm/intel/issues/1887
[i915#1899]: https://gitlab.freedesktop.org/drm/intel/issues/1899
[i915#1958]: https://gitlab.freedesktop.org/drm/intel/issues/1958
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#2122]: https://gitlab.freedesktop.org/drm/intel/issues/2122
[i915#2389]: https://gitlab.freedesktop.org/drm/intel/issues/2389
[i915#2411]: https://gitlab.freedesktop.org/drm/intel/issues/2411
[i915#2521]: https://gitlab.freedesktop.org/drm/intel/issues/2521
[i915#31]: https://gitlab.freedesktop.org/drm/intel/issues/31
[i915#405]: https://gitlab.freedesktop.org/drm/intel/issues/405
[i915#43]: https://gitlab.freedesktop.org/drm/intel/issues/43
[i915#454]: https://gitlab.freedesktop.org/drm/intel/issues/454
[i915#456]: https://gitlab.freedesktop.org/drm/intel/issues/456
[i915#49]: https://gitlab.freedesktop.org/drm/intel/issues/49
[i915#588]: https://gitlab.freedesktop.org/drm/intel/issues/588
[i915#658]: https://gitlab.freedesktop.org/drm/intel/issues/658
[i915#716]: https://gitlab.freedesktop.org/drm/intel/issues/716
[i915#83]: https://gitlab.freedesktop.org/drm/intel/issues/83
[i915#95]: https://gitlab.freedesktop.org/drm/intel/issues/95

Participating hosts (8 -> 8)
------------------------------

No changes in participating hosts

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_5793 -> IGTPW_5026

CI-20190529: 20190529
CI_DRM_9075: fd24361b2b76956b5c056bc430a4c77edecb7744 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_5026: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/index.html
IGT_5793: c34792447c9fc4d05dd75873cdb99d9ffe57ea23 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5026/index.html

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#3 lore raw
In reply to Ashutosh Dixit

Quoting Ashutosh Dixit (2020-09-30 04:40:29)

Quoted 6 lines

The general direction at this time is to phase out pread/write ioctls and not support them in future products. This means IGT must handle the absence of these ioctls. This patch does this by modifying gem_read() and gem_write() to do the read/write using the pread/pwrite ioctls first but when these ioctls are unavailable fall back to doing the read/write using a combination of mmap and memcpy.

Note that not all pread/pwrite can be replaced by a mmap(bo) + mempcy. Removing pread/pwrite support for arbitrary bo is a significant ABI regression.
-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#4 lore raw
Quoted 9 lines · Chris Wilson

Quoting Ashutosh Dixit (2020-09-30 04:40:29)

Quoted 6 lines

The general direction at this time is to phase out pread/write ioctls and not support them in future products. This means IGT must handle the absence of these ioctls. This patch does this by modifying gem_read() and gem_write() to do the read/write using the pread/pwrite ioctls first but when these ioctls are unavailable fall back to doing the read/write using a combination of mmap and memcpy.

Quoted 3 lines

Note that not all pread/pwrite can be replaced by a mmap(bo) + mempcy. Removing pread/pwrite support for arbitrary bo is a significant ABI regression.

Dave Airlie NAK'd pread/pwrite for discrete here:

https://lists.freedesktop.org/archives/intel-gfx/2020-July/244677.html

Also UMD's are not using them anymore so the thinking is we would discontinue pread/pwrite in i915 for future generations but retain them for previous generations.
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

Acked-by on v1 1/1
#5 lore raw
In reply to Ashutosh Dixit
Quoted 13 lines

The general direction at this time is to phase out pread/write ioctls and not support them in future products. This means IGT must handle the absence of these ioctls. This patch does this by modifying gem_read() and gem_write() to do the read/write using the pread/pwrite ioctls first but when these ioctls are unavailable fall back to doing the read/write using a combination of mmap and memcpy.

Callers who must absolutely use the pread/pwrite ioctls (such as tests which test these ioctls or must otherwise only use the pread/pwrite ioctls) must use gem_require_pread_pwrite() to skip when these ioctls are not available.

Quoted 9 lines

v1: Removed __gem_pread, gem_pread, __gem_pwrite and gem_pwrite
introduced previously since they are not necessary, gem_require_pread_pwrite is sufficient
v2: Fix CI failures in gem_advise and gen9_exec_parse by introducing
gem_require_pread_pwrite
v3: Skip mmap for 0 length read/write's
v4: Remove redundant igt_assert's
v5: Re-run
v6: s/EOPNOTSUPP/-EOPNOTSUPP/

There appears to be some push back on landing this,

If there are testing reasons for keeping pread/pwrite then they should be done with a test interface via debugfs or hidden behind a big unstable testing trapdoor, not a uAPI for other userpsace to use.

Dave.

Quoted 375 lines
---
 lib/ioctl_wrappers.c                        | 135 +++++++++++++++++++-
 lib/ioctl_wrappers.h                        |   3 +
 tests/i915/gem_madvise.c                    |   2 +
 tests/i915/gem_partial_pwrite_pread.c       |   1 +
 tests/i915/gem_pread.c                      |   1 +
 tests/i915/gem_pread_after_blit.c           |   1 +
 tests/i915/gem_pwrite.c                     |   1 +
 tests/i915/gem_pwrite_snooped.c             |   1 +
 tests/i915/gem_readwrite.c                  |   1 +
 tests/i915/gem_set_tiling_vs_pwrite.c       |   1 +
 tests/i915/gem_tiled_partial_pwrite_pread.c |   1 +
 tests/i915/gem_tiled_pread_basic.c          |   1 +
 tests/i915/gem_tiled_pread_pwrite.c         |   1 +
 tests/i915/gem_userptr_blits.c              |   2 +
 tests/i915/gen9_exec_parse.c                |   4 +-
 15 files changed, 149 insertions(+), 7 deletions(-)
lib/ioctl_wrappers.c +129 -6
index edac50f0f..ac77b3eb6 100644
@@ -55,6 +55,7 @@
 #include "igt_debugfs.h"
 #include "igt_sysfs.h"
 #include "config.h"
+#include "i915/gem_mman.h"
 
 #ifdef HAVE_VALGRIND
 #include <valgrind/valgrind.h>
@@ -323,6 +324,70 @@ void gem_close(int fd, uint32_t handle)
 	do_ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close_bo);
 }
 
+static bool is_cache_coherent(int fd, uint32_t handle)
+{
+	return gem_get_caching(fd, handle) != I915_CACHING_NONE;
+}
+
+static void mmap_write(int fd, uint32_t handle, uint64_t offset,
+		       const void *buf, uint64_t length)
+{
+	void *map = NULL;
+
+	if (!length)
+		return;
+
+	if (is_cache_coherent(fd, handle)) {
+		/* offset arg for mmap functions must be 0 */
+		map = __gem_mmap__cpu_coherent(fd, handle, 0, offset + length,
+					       PROT_READ | PROT_WRITE);
+		if (map)
+			gem_set_domain(fd, handle,
+				       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+	}
+
+	if (!map) {
+		map = __gem_mmap_offset__wc(fd, handle, 0, offset + length,
+					    PROT_READ | PROT_WRITE);
+		if (!map)
+			map = gem_mmap__wc(fd, handle, 0, offset + length,
+					   PROT_READ | PROT_WRITE);
+		gem_set_domain(fd, handle,
+			       I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
+	}
+
+	memcpy(map + offset, buf, length);
+	munmap(map, offset + length);
+}
+
+static void mmap_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
+{
+	void *map = NULL;
+
+	if (!length)
+		return;
+
+	if (gem_has_llc(fd) || is_cache_coherent(fd, handle)) {
+		/* offset arg for mmap functions must be 0 */
+		map = __gem_mmap__cpu_coherent(fd, handle, 0,
+					       offset + length, PROT_READ);
+		if (map)
+			gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, 0);
+	}
+
+	if (!map) {
+		map = __gem_mmap_offset__wc(fd, handle, 0, offset + length,
+					    PROT_READ);
+		if (!map)
+			map = gem_mmap__wc(fd, handle, 0, offset + length,
+					   PROT_READ);
+		gem_set_domain(fd, handle, I915_GEM_DOMAIN_WC, 0);
+	}
+
+	memcpy(buf, map + offset, length);
+	munmap(map, offset + length);
+}
+
 int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length)
 {
 	struct drm_i915_gem_pwrite gem_pwrite;
@@ -348,12 +413,18 @@ int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint6
  * @buf: pointer to the data to write into the buffer
  * @length: size of the subrange
  *
- * This wraps the PWRITE ioctl, which is to upload a linear data to a subrange
- * of a gem buffer object.
+ * Method to write to a gem object. Uses the PWRITE ioctl when it is
+ * available, else it uses mmap + memcpy to upload linear data to a
+ * subrange of a gem buffer object.
  */
 void gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length)
 {
-	igt_assert_eq(__gem_write(fd, handle, offset, buf, length), 0);
+	int ret = __gem_write(fd, handle, offset, buf, length);
+
+	igt_assert(ret == 0 || ret == -EOPNOTSUPP);
+
+	if (ret == -EOPNOTSUPP)
+		mmap_write(fd, handle, offset, buf, length);
 }
 
 int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
@@ -380,12 +451,64 @@ int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t len
  * @buf: pointer to the data to read into
  * @length: size of the subrange
  *
- * This wraps the PREAD ioctl, which is to download a linear data to a subrange
- * of a gem buffer object.
+ * Method to read from a gem object. Uses the PREAD ioctl when it is
+ * available, else it uses mmap + memcpy to download linear data from a
+ * subrange of a gem buffer object.
  */
 void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length)
 {
-	igt_assert_eq(__gem_read(fd, handle, offset, buf, length), 0);
+	int ret = __gem_read(fd, handle, offset, buf, length);
+
+	igt_assert(ret == 0 || ret == -EOPNOTSUPP);
+
+	if (ret == -EOPNOTSUPP)
+		mmap_read(fd, handle, offset, buf, length);
+}
+
+/**
+ * gem_has_pwrite
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether pwrite ioctl is supported
+ */
+bool gem_has_pwrite(int fd)
+{
+	uint32_t handle = gem_create(fd, 4096);
+	int buf, ret;
+
+	ret = __gem_write(fd, handle, 0, &buf, sizeof(buf));
+	gem_close(fd, handle);
+
+	return ret != -EOPNOTSUPP;
+}
+
+/**
+ * gem_has_pread
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether pread ioctl is supported
+ */
+bool gem_has_pread(int fd)
+{
+	uint32_t handle = gem_create(fd, 4096);
+	int buf, ret;
+
+	ret = __gem_read(fd, handle, 0, &buf, sizeof(buf));
+	gem_close(fd, handle);
+
+	return ret != -EOPNOTSUPP;
+}
+
+/**
+ * gem_require_pread_pwrite
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether pread/pwrite ioctls are supported
+ * and skip if they are not
+ */
+void gem_require_pread_pwrite(int fd)
+{
+	igt_require(gem_has_pread(fd) && gem_has_pwrite(fd));
 }
 
 int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write)
lib/ioctl_wrappers.h +3 -0
index b76bea564..81166000a 100644
@@ -71,6 +71,9 @@ int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint6
 void gem_write(int fd, uint32_t handle, uint64_t offset,  const void *buf, uint64_t length);
 int __gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length);
 void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length);
+bool gem_has_pwrite(int fd);
+bool gem_has_pread(int fd);
+void gem_require_pread_pwrite(int fd);
 int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
 void gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
 int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns);
tests/i915/gem_madvise.c +2 -0
index 54c9befff..92e1c5192 100644
@@ -154,6 +154,7 @@ dontneed_before_pwrite(void)
 	uint32_t bbe = MI_BATCH_BUFFER_END;
 	uint32_t handle;
 
+	gem_require_pread_pwrite(fd);
 	handle = gem_create(fd, OBJECT_SIZE);
 	gem_madvise(fd, handle, I915_MADV_DONTNEED);
 
@@ -170,6 +171,7 @@ dontneed_before_exec(void)
 	struct drm_i915_gem_exec_object2 exec;
 	uint32_t buf[] = { MI_BATCH_BUFFER_END, 0 };
 
+	gem_require_pread_pwrite(fd);
 	memset(&execbuf, 0, sizeof(execbuf));
 	memset(&exec, 0, sizeof(exec));
 
tests/i915/gem_partial_pwrite_pread.c +1 -0
index b10284721..fd7b19f31 100644
@@ -281,6 +281,7 @@ igt_main
 		data.drm_fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(data.drm_fd);
 		gem_require_blitter(data.drm_fd);
+		gem_require_pread_pwrite(data.drm_fd);
 
 		data.devid = intel_get_drm_devid(data.drm_fd);
 		data.bops = buf_ops_create(data.drm_fd);
tests/i915/gem_pread.c +1 -0
index 6d12b8e9f..db1eacedc 100644
@@ -149,6 +149,7 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
+		gem_require_pread_pwrite(fd);
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
tests/i915/gem_pread_after_blit.c +1 -0
index 81454c930..5c99d0887 100644
@@ -212,6 +212,7 @@ igt_main
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
+		gem_require_pread_pwrite(fd);
 
 		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
 		drm_intel_bufmgr_gem_enable_reuse(bufmgr);
tests/i915/gem_pwrite.c +1 -0
index e491263fd..eea51f978 100644
@@ -317,6 +317,7 @@ igt_main_args("s:", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
+		gem_require_pread_pwrite(fd);
 
 		dst = gem_create(fd, object_size);
 		src = malloc(object_size);
tests/i915/gem_pwrite_snooped.c +1 -0
index 4a3395241..a2eca6afc 100644
@@ -132,6 +132,7 @@ igt_simple_main
 	fd = drm_open_driver(DRIVER_INTEL);
 	igt_require_gem(fd);
 	gem_require_blitter(fd);
+	gem_require_pread_pwrite(fd);
 
 	devid = intel_get_drm_devid(fd);
 	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
tests/i915/gem_readwrite.c +1 -0
index 6b2977c1c..ca31741c6 100644
@@ -83,6 +83,7 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
+		gem_require_pread_pwrite(fd);
 
 		handle = gem_create(fd, OBJECT_SIZE);
 	}
tests/i915/gem_set_tiling_vs_pwrite.c +1 -0
index 302ea24b6..8f38c9b9b 100644
@@ -55,6 +55,7 @@ igt_simple_main
 
 	fd = drm_open_driver(DRIVER_INTEL);
 	igt_require(gem_available_fences(fd) > 0);
+	gem_require_pread_pwrite(fd);
 
 	for (int i = 0; i < OBJECT_SIZE/4; i++)
 		data[i] = i;
tests/i915/gem_tiled_partial_pwrite_pread.c +1 -0
index 7de5358b2..0c4545990 100644
@@ -270,6 +270,7 @@ igt_main
 		igt_require_gem(fd);
 		gem_require_mappable_ggtt(fd);
 		gem_require_blitter(fd);
+		gem_require_pread_pwrite(fd);
 
 		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
 		//drm_intel_bufmgr_gem_enable_reuse(bufmgr);
tests/i915/gem_tiled_pread_basic.c +1 -0
index 7cb644104..f8f73c03a 100644
@@ -127,6 +127,7 @@ igt_simple_main
 	igt_require(gem_available_fences(fd) > 0);
 	handle = create_bo(fd);
 	igt_require(gem_get_tiling(fd, handle, &tiling, &swizzle));
+	gem_require_pread_pwrite(fd);
 
 	devid = intel_get_drm_devid(fd);
 
tests/i915/gem_tiled_pread_pwrite.c +1 -0
index f58048faa..28490840f 100644
@@ -114,6 +114,7 @@ igt_simple_main
 
 	fd = drm_open_driver(DRIVER_INTEL);
 	igt_require(gem_available_fences(fd) > 0);
+	gem_require_pread_pwrite(fd);
 
 	count = gem_available_fences(fd) + 1;
 	intel_require_memory(2 * count, sizeof(linear), CHECK_RAM);
tests/i915/gem_userptr_blits.c +2 -0
index 268423dcd..0ccfdbd9c 100644
@@ -890,6 +890,7 @@ static int test_forbidden_ops(int fd)
 	uint32_t handle;
 	void *ptr;
 
+	gem_require_pread_pwrite(fd);
 	igt_assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0);
 	gem_userptr(fd, ptr, PAGE_SIZE, 0, userptr_flags, &handle);
 
@@ -1416,6 +1417,7 @@ static void test_readonly_pwrite(int i915)
 	 */
 
 	igt_require(igt_setup_clflush());
+	gem_require_pread_pwrite(i915);
 
 	sz = 16 << 12;
 	pages = mmap(NULL, sz, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
tests/i915/gen9_exec_parse.c +0 -0
index 7ddb5bf2b..cfb6de080 100644
@@ -1104,8 +1104,10 @@ igt_main
 			   -EINVAL);

tests/i915/gen9_exec_parse.c igt_main · line 1113

Quoted 10 lines
tests/i915/gen9_exec_parse.c +3 -1
 	}
 
-	igt_subtest("batch-invalid-length")
+	igt_subtest("batch-invalid-length") {
+		gem_require_pread_pwrite(i915);
 		test_invalid_length(i915, handle);
+	}
 
 	igt_subtest("basic-rejected")
 		test_rejected(i915, handle, false);

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev