All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ashutosh Dixit <ashutosh.dixit@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Matthew Auld <matthew.auld@intel.com>
Subject: [igt-dev] [PATCH i-g-t] i915: Avoid set_domain -ENOMEM error with large objects
Date: Wed, 31 Mar 2021 17:43:13 -0700	[thread overview]
Message-ID: <20210401004313.65166-1-ashutosh.dixit@intel.com> (raw)
In-Reply-To: <20210330035056.52019-1-ashutosh.dixit@intel.com>

When pread/pwrite are unavailable, the pread/pwrite replacement implemented
in ad5eb02eb3f1 ("lib/ioctl_wrappers: Keep IGT working without pread/pwrite
ioctls") uses gem_set_domain which pins the entire gem object, even when
the actual read/write size is small. This causes gem_set_domain to return
-ENOMEM for large objects with a trace such as:

ioctl_wrappers-CRITICAL: Test assertion failure function gem_set_domain, file ../lib/ioctl_wrappers.c:563:
ioctl_wrappers-CRITICAL: Failed assertion: __gem_set_domain(fd, handle, read, write) == 0
ioctl_wrappers-CRITICAL: Last errno: 12, Cannot allocate memory
ioctl_wrappers-CRITICAL: error: -12 != 0
igt_core-INFO: Stack trace:
igt_core-INFO:   #0 ../lib/igt_core.c:1746 __igt_fail_assert()
igt_core-INFO:   #1 [gem_set_domain+0x44]
igt_core-INFO:   #2 ../lib/ioctl_wrappers.c:367 gem_write()
igt_core-INFO:   #3 ../tests/prime_mmap.c:67 test_aperture_limit()
igt_core-INFO:   #4 ../tests/prime_mmap.c:578 __real_main530()
igt_core-INFO:   #5 ../tests/prime_mmap.c:530 main()

Therefore avoid using the pread/pwrite replacement for large objects, mmap
and write instead. This fixes failures seen in
prime_mmap@test_aperture_limit and gem_exec_params@larger-than-life-batch
when pread/pwrite are unavailable.

v2: Remove fill_bo calls in prime_mmap@test_aperture_limit (Mike Ruhl)
v3: s/gem_mmap__device_coherent/gem_mmap__wc/ (Matt Auld)

Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
---
 tests/i915/gem_exec_params.c |  5 ++++-
 tests/prime_mmap.c           | 25 ++++++++++++++-----------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/tests/i915/gem_exec_params.c b/tests/i915/gem_exec_params.c
index 6840cf40ce..df4c5c8f54 100644
--- a/tests/i915/gem_exec_params.c
+++ b/tests/i915/gem_exec_params.c
@@ -254,9 +254,12 @@ static uint32_t batch_create_size(int fd, uint64_t size)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
 	uint32_t handle;
+	char *ptr;
 
 	handle = gem_create(fd, size);
-	gem_write(fd, handle, 0, &bbe, sizeof(bbe));
+	ptr = gem_mmap__wc(fd, handle, 0, sizeof(bbe), PROT_WRITE);
+	memcpy(ptr, &bbe, sizeof(bbe));
+	munmap(ptr, sizeof(bbe));
 
 	return handle;
 }
diff --git a/tests/prime_mmap.c b/tests/prime_mmap.c
index cdf2d51497..9a783257d4 100644
--- a/tests/prime_mmap.c
+++ b/tests/prime_mmap.c
@@ -68,9 +68,13 @@ fill_bo(uint32_t handle, size_t size)
 }
 
 static void
-fill_bo_cpu(char *ptr)
+fill_bo_cpu(char *ptr, size_t size)
 {
-	memcpy(ptr, pattern, sizeof(pattern));
+	off_t i;
+	for (i = 0; i < size; i += sizeof(pattern))
+	{
+		memcpy(ptr + i, pattern, sizeof(pattern));
+	}
 }
 
 static void
@@ -208,7 +212,7 @@ test_correct_cpu_write(void)
 	igt_assert(ptr != MAP_FAILED);
 
 	/* Fill bo using CPU */
-	fill_bo_cpu(ptr);
+	fill_bo_cpu(ptr, BO_SIZE);
 
 	/* Check pattern correctness */
 	igt_assert(memcmp(ptr, pattern, sizeof(pattern)) == 0);
@@ -236,7 +240,7 @@ test_forked_cpu_write(void)
 	igt_fork(childno, 1) {
 		ptr = mmap(NULL, BO_SIZE, PROT_READ | PROT_WRITE , MAP_SHARED, dma_buf_fd, 0);
 		igt_assert(ptr != MAP_FAILED);
-		fill_bo_cpu(ptr);
+		fill_bo_cpu(ptr, BO_SIZE);
 
 		igt_assert(memcmp(ptr, pattern, sizeof(pattern)) == 0);
 		munmap(ptr, BO_SIZE);
@@ -452,20 +456,19 @@ test_aperture_limit(void)
 	uint64_t size2 = (gem_mappable_aperture_size(fd) * 3) / 8;
 
 	handle1 = gem_create(fd, size1);
-	fill_bo(handle1, BO_SIZE);
-
-	dma_buf_fd1 = prime_handle_to_fd(fd, handle1);
+	dma_buf_fd1 = prime_handle_to_fd_for_mmap(fd, handle1);
 	igt_assert(errno == 0);
-	ptr1 = mmap(NULL, size1, PROT_READ, MAP_SHARED, dma_buf_fd1, 0);
+	ptr1 = mmap(NULL, size1, PROT_READ | PROT_WRITE, MAP_SHARED, dma_buf_fd1, 0);
 	igt_assert(ptr1 != MAP_FAILED);
+	fill_bo_cpu(ptr1, BO_SIZE);
 	igt_assert(memcmp(ptr1, pattern, sizeof(pattern)) == 0);
 
 	handle2 = gem_create(fd, size1);
-	fill_bo(handle2, BO_SIZE);
-	dma_buf_fd2 = prime_handle_to_fd(fd, handle2);
+	dma_buf_fd2 = prime_handle_to_fd_for_mmap(fd, handle2);
 	igt_assert(errno == 0);
-	ptr2 = mmap(NULL, size2, PROT_READ, MAP_SHARED, dma_buf_fd2, 0);
+	ptr2 = mmap(NULL, size2, PROT_READ | PROT_WRITE, MAP_SHARED, dma_buf_fd2, 0);
 	igt_assert(ptr2 != MAP_FAILED);
+	fill_bo_cpu(ptr2, BO_SIZE);
 	igt_assert(memcmp(ptr2, pattern, sizeof(pattern)) == 0);
 
 	igt_assert(memcmp(ptr1, ptr2, BO_SIZE) == 0);
-- 
2.31.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2021-04-01  0:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30  3:50 [igt-dev] [PATCH i-g-t] i915: Avoid set_domain -ENOMEM error with huge buffers Ashutosh Dixit
2021-03-30  4:26 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2021-03-30  5:27 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2021-03-30  5:44   ` Dixit, Ashutosh
2021-03-30 18:06     ` Vudum, Lakshminarayana
2021-03-30 10:28 ` [igt-dev] [PATCH i-g-t] " Matthew Auld
2021-03-30 19:31   ` Dixit, Ashutosh
2021-03-31  9:02     ` Matthew Auld
2021-04-01  0:45       ` Dixit, Ashutosh
2021-04-01 12:49         ` Ruhl, Michael J
2021-04-01 19:25           ` Dixit, Ashutosh
2021-04-01 21:11             ` Ruhl, Michael J
2021-04-07  7:51   ` Daniel Vetter
2021-03-30 15:07 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2021-03-30 16:14 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2021-03-30 22:02 ` [igt-dev] [PATCH i-g-t] i915: Avoid set_domain -ENOMEM error with large objects Ashutosh Dixit
2021-03-31  7:52 ` [igt-dev] ✓ Fi.CI.BAT: success for i915: Avoid set_domain -ENOMEM error with huge buffers (rev2) Patchwork
2021-03-31  8:52 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2021-04-01  0:43 ` Ashutosh Dixit [this message]
2021-04-01 10:22 ` [igt-dev] ✓ Fi.CI.BAT: success for i915: Avoid set_domain -ENOMEM error with huge buffers (rev3) Patchwork
2021-04-01 12:36 ` [igt-dev] ✓ Fi.CI.IGT: " 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=20210401004313.65166-1-ashutosh.dixit@intel.com \
    --to=ashutosh.dixit@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=matthew.auld@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.