Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org,
	"David Hildenbrand (Arm)" <david@kernel.org>,
	"Felix Kuehling" <felix.kuehling@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>
Subject: [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read
Date: Mon, 23 Nov 2026 22:10:18 +0100	[thread overview]
Message-ID: <20261123211018.12339-1-david@kernel.org> (raw)

The oob-read test reads 8 bytes through /proc/self/mem, assuming that
the kernel would reject the entire read with EIO.

However, we have 4 remaining bytes in the 4 KiB mapping we can read, so
it's valid for the kernel to only do a partial read that covers these 4
bytes. Allow that as well.

Otherwise, the test will fail on a kernel with upcoming vm_ops->access
fixes, whereby vm_ops->access is limited to the current VMA, so the
read would continue with the next mapping (if any).

So we have to make sure that nothing is mapped after the GEM mapping.
Let's reserve an 8 KiB memory region, map the GEM object into the first
4 KiB slot, and create a hole by unmapping the second 4 KiB slot.

With the kernel changes in place:

  $ build/tests/gem_mmap_offset --run-subtest oob-read
  [...]
  Using IGT_SRANDOM=1795467759 for randomisation
  Opened device: /dev/dri/card1
  Starting subtest: oob-read
  Subtest oob-read: SUCCESS (0,000s)

Link: https://lore.kernel.org/r/20261122-access_shite-v2-0-808d8d2aa700@kernel.org
Cc: Felix Kuehling <felix.kuehling@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 tests/intel/gem_mmap_offset.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/tests/intel/gem_mmap_offset.c b/tests/intel/gem_mmap_offset.c
index d3c56ab40..e4c0cfbd9 100644
--- a/tests/intel/gem_mmap_offset.c
+++ b/tests/intel/gem_mmap_offset.c
@@ -482,13 +482,29 @@ test_oob_read(int i915)
 	handle = gem_create(i915, 4096);
 
 	for_each_mmap_offset_type(i915, t) {
-		uint32_t *ptr;
+		struct drm_i915_gem_mmap_offset arg = {
+			.handle = handle,
+			.flags = t->type,
+		};
+		void *ptr;
 
-		ptr = __mmap_offset(i915, handle, 0, 4096,
-				    PROT_READ | PROT_WRITE,
-				    t->type);
-		if (!ptr)
+		if (mmap_offset_ioctl(i915, &arg))
+			continue;
+
+		/* Reserve a region for mapping + hole to stop read(). */
+		ptr = mmap(NULL, 8192, PROT_NONE,
+			   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		igt_assert(ptr != MAP_FAILED);
+
+		/* Place our mapping into the first slot. */
+		if (mmap(ptr, 4096, PROT_READ | PROT_WRITE,
+			 MAP_SHARED | MAP_FIXED, i915, arg.offset) == MAP_FAILED) {
+			munmap(ptr, 8192);
 			continue;
+		}
+
+		/* And our hole into the second slot. */
+		munmap(ptr + 4096, 4096);
 
 		memfd = open("/proc/self/mem", O_RDWR);
 		igt_require_f(memfd != -1, "/proc/self/mem\n");
@@ -497,9 +513,14 @@ test_oob_read(int i915)
 		ret = lseek(memfd, addr, SEEK_SET);
 		igt_assert_f(ret != -1, "lseek failed\n");
 
-		/* Triggering the buf (out of bound read) */
+		/*
+		 * Read across the end of the mapping. The read is either
+		 * rejected entirely, or completes partially for the remaining
+		 * 4 bytes in the mapping.
+		 */
 		ret = read(memfd, read_buf, 8);
-		igt_assert(ret == -1 && errno ==  EIO);
+		igt_assert_f((ret == -1 && errno == EIO) || ret == 4,
+			     "ret=%d errno=%d\n", ret, errno);
 
 		munmap(ptr, 4096);
 		close(memfd);
-- 
2.56.1


             reply	other threads:[~2026-11-24  9:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 21:10 David Hildenbrand (Arm) [this message]
2026-11-24  8:46 ` [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read Christian König
2026-11-24  9:41   ` David Hildenbrand (Arm)

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=20261123211018.12339-1-david@kernel.org \
    --to=david@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=felix.kuehling@amd.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=ljs@kernel.org \
    /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