All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	"Felix Kuehling" <felix.kuehling@amd.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read
Date: Tue, 24 Nov 2026 10:54:50 +0000	[thread overview]
Message-ID: <awVlaeEQSpee2cI2@gremlin> (raw)
In-Reply-To: <20261123211018.12339-1-david@kernel.org>

On Mon, Nov 23, 2026 at 10:10:18PM +0100, David Hildenbrand (Arm) wrote:
> 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>

It's funny how these things can ripple out, but very much seems a correct
change!

Acked-by: Lorenzo Stoakes (ARM) <ljs@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
>

--
Cheers, Lorenzo

  parent reply	other threads:[~2026-11-24 10:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 21:10 [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read David Hildenbrand (Arm)
2026-11-24  8:46 ` Christian König
2026-11-24  9:41   ` David Hildenbrand (Arm)
2026-11-24 10:54 ` Lorenzo Stoakes (ARM) [this message]
2026-11-24 16:58 ` Kamil Konieczny
2026-11-25 14:26   ` David Hildenbrand (Arm)
2026-11-25 14:17 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-11-25 14:41 ` ✓ i915.CI.BAT: " Patchwork
2026-11-25 20:42 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-11-26 17:38 ` ✗ i915.CI.Full: " 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=awVlaeEQSpee2cI2@gremlin \
    --to=ljs@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=david@kernel.org \
    --cc=felix.kuehling@amd.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.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 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.