Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Shekhar Chauhan <shekhar.chauhan@intel.com>
To: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>,
	<igt-dev@lists.freedesktop.org>
Cc: <harish.chegondi@intel.com>
Subject: Re: [PATCH v2 5/8] tests/intel/xe_oa: Check vm_ops->access on OA buffer mmaps across unbind
Date: Thu, 26 Nov 2026 11:25:21 +0530	[thread overview]
Message-ID: <a1b6e4de-b536-476b-bd15-bbadb6f3960b@intel.com> (raw)
In-Reply-To: <20261104005505.3232485-15-umesh.nerlige.ramappa@intel.com>


On 11/4/2026 6:25, Umesh Nerlige Ramappa wrote:
> The OA buffer mapping is VM_PFNMAP, so reading it through
> /proc/self/mem goes through the vm_ops->access() of the mapping. Check
> that this works before unbind and fails with EIO after, since access is
> refused once the device is unplugged.
>
> Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
> ---
>   tests/intel/xe_oa.c | 38 ++++++++++++++++++++++++++++++++++++--
>   1 file changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/tests/intel/xe_oa.c b/tests/intel/xe_oa.c
> index e4b63c982200..8474d506612b 100644
> --- a/tests/intel/xe_oa.c
> +++ b/tests/intel/xe_oa.c
> @@ -2831,6 +2831,26 @@ static void probe_stream_after_removal(int fd, const char *when)
>   	igt_assert_eq(err, ENODEV);
>   }
>   
> +/*
> + * Read through /proc/self/mem. The OA buffer mapping is VM_PFNMAP, so this goes through
> + * the vm_ops->access() of the mapping rather than through its page tables.
> + */
> +static ssize_t read_proc_self_mem(const void *vaddr, void *buf, size_t len)
> +{
> +	ssize_t ret;
> +	int fd, err;
> +
> +	fd = open("/proc/self/mem", O_RDONLY);
> +	igt_assert_lte(0, fd);
> +
> +	ret = pread(fd, buf, len, (off_t)(uintptr_t)vaddr);
> +	err = errno;
> +	close(fd);
> +	errno = err;
> +
> +	return ret;
> +}
> +
>   static bool mem_is_zero(const void *vaddr, size_t len)
>   {
>   	const uint8_t *p = vaddr;
> @@ -2868,6 +2888,7 @@ static void unbind_stream_open(struct unbind_stream *s, const struct drm_xe_oa_u
>   	struct intel_xe_perf_metric_set *test_set = oa_unit_metric_set(oau);
>   	uint64_t fmt = test_set->perf_oa_format;
>   	struct drm_xe_oa_stream_info info = {};
> +	uint32_t val;
>   	int n = 0;
>   
>   	s->oa_unit_id = oau->oa_unit_id;
> @@ -2899,6 +2920,9 @@ static void unbind_stream_open(struct unbind_stream *s, const struct drm_xe_oa_u
>   
>   	/* Fault in the mapping while the device is still bound */
>   	(void)READ_ONCE(*(const volatile uint32_t *)s->vaddr);
> +
> +	/* vm_ops->access() works on the mapping while the device is bound */
> +	igt_assert_eq(read_proc_self_mem(s->vaddr, &val, sizeof(val)), sizeof(val));
>   }
>   
>   static void unbind_stream_close(struct unbind_stream *s)
> @@ -2931,6 +2955,8 @@ static void unbind_stream_check_live(struct unbind_stream *s)
>   static void unbind_stream_check_dead(struct unbind_stream *s, const char *when)
>   {
>   	size_t page_size = sysconf(_SC_PAGESIZE);
> +	uint32_t val;
> +	ssize_t ret;
>   	void *vaddr;
>   
>   	igt_debug("[%s] checking stream on oa unit %d\n", when, s->oa_unit_id);
> @@ -2944,6 +2970,13 @@ static void unbind_stream_check_dead(struct unbind_stream *s, const char *when)
>   	igt_assert(mem_is_zero(s->vaddr, page_size));
>   	igt_assert(mem_is_zero((uint8_t *)s->vaddr + s->size - page_size, page_size));
>   
> +	/* vm_ops->access() on the mapping is refused once the device is gone */
> +	ret = read_proc_self_mem(s->vaddr, &val, sizeof(val));
> +	igt_debug("[%s] /proc/self/mem read: ret=%zd errno=%s\n", when, ret,
> +		  ret < 0 ? strerror(errno) : "-");

In patch 2, and even in this patch (at the top), we're always saving 
errno.  Can we do the same here?  Like, err = errno?

-shekhar

> +	igt_assert_eq(ret, -1);
> +	igt_assert_eq(errno, EIO);
> +
>   	/* New mappings are refused */
>   	vaddr = mmap(NULL, s->size, PROT_READ, MAP_PRIVATE, s->fd, 0);
>   	igt_assert(vaddr == MAP_FAILED);
> @@ -2986,8 +3019,9 @@ static void unbind_rebind_recover(void)
>   /**
>    * SUBTEST: unbind-rebind-stream
>    * Description: Open OA streams with mmapped OA buffers and test the effects of unbind
> - *		and rebind: streams die, mmaps read a zeroed dummy page, no new streams can
> - *		be opened on the removed device and the device works after rebind.
> + *		and rebind: streams die, mmaps read a zeroed dummy page and refuse access
> + *		through /proc/self/mem, no new streams can be opened on the removed device
> + *		and the device works after rebind.
>    */
>   static void test_unbind_rebind(const struct drm_xe_oa_unit *oau0, unsigned int flags)
>   {

-- 
Shekhar Chauhan
Linux Graphics Software Engineer
Linux Platform Enabling
Intel Corporation


  reply	other threads:[~2026-11-26  5:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04  0:55 [PATCH v2 0/8] Test unbinding PCI device while OA stream is open Umesh Nerlige Ramappa
2026-11-04  0:55 ` [PATCH v2 1/8] tests/intel/xe_oa: Move device setup and teardown into helpers Umesh Nerlige Ramappa
2026-11-04  0:55 ` [PATCH v2 2/8] tests/intel/xe_oa: Add unbind/rebind test with an open OA stream Umesh Nerlige Ramappa
2026-11-26  7:09   ` Shekhar Chauhan
2026-11-04  0:55 ` [PATCH v2 3/8] tests/intel/xe_oa: Check that a removed device can't open OA streams Umesh Nerlige Ramappa
2026-11-26  7:10   ` Shekhar Chauhan
2026-11-04  0:55 ` [PATCH v2 4/8] tests/intel/xe_oa: Check OA buffer mmaps across unbind Umesh Nerlige Ramappa
2026-11-26  7:10   ` Shekhar Chauhan
2026-11-04  0:55 ` [PATCH v2 5/8] tests/intel/xe_oa: Check vm_ops->access on " Umesh Nerlige Ramappa
2026-11-26  5:55   ` Shekhar Chauhan [this message]
2026-11-04  0:55 ` [PATCH v2 6/8] tests/intel/xe_oa: Check that blocked OA stream waiters are woken up on unbind Umesh Nerlige Ramappa
2026-11-26  6:42   ` Shekhar Chauhan
2026-11-04  0:55 ` [PATCH v2 7/8] tests/intel/xe_oa: Add an exec queue variant to the unbind/rebind test Umesh Nerlige Ramappa
2026-11-26  7:11   ` Shekhar Chauhan
2026-11-04  0:55 ` [PATCH v2 8/8] tests/intel/xe_oa: Add an all OA units " Umesh Nerlige Ramappa
2026-11-26  7:06   ` Shekhar Chauhan
2026-11-04  2:19 ` ✓ Xe.CI.BAT: success for Test unbinding PCI device while OA stream is open (rev2) Patchwork
2026-11-04  2:39 ` ✗ i915.CI.BAT: failure " Patchwork
2026-11-04 17:42 ` ✗ Xe.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=a1b6e4de-b536-476b-bd15-bbadb6f3960b@intel.com \
    --to=shekhar.chauhan@intel.com \
    --cc=harish.chegondi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=umesh.nerlige.ramappa@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox