public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Sharma, Nishit" <nishit.sharma@intel.com>
To: Arvind Yadav <arvind.yadav@intel.com>, <igt-dev@lists.freedesktop.org>
Cc: <matthew.brost@intel.com>, <himal.prasad.ghimiray@intel.com>,
	<thomas.hellstrom@linux.intel.com>, <pravalika.gurram@intel.com>
Subject: Re: [PATCH i-g-t v6 4/9] tests/intel/xe_madvise: Add purged-mmap-blocked subtest
Date: Mon, 6 Apr 2026 18:04:16 +0530	[thread overview]
Message-ID: <41012de6-8a70-49ed-9332-1746598c8e51@intel.com> (raw)
In-Reply-To: <20260325124426.3265234-5-arvind.yadav@intel.com>


On 3/25/2026 6:14 PM, Arvind Yadav wrote:
> Add a new purged-mmap-blocked subtest that triggers an actual purge
> via memory pressure and verifies that mmap() fails with -EINVAL once
> the BO backing store has been permanently discarded.
>
> The purgeable check moved from xe_gem_mmap_offset_ioctl()
> into a new xe_gem_object_mmap() callback, so the blocking point is now
> mmap() itself rather than the mmap offset ioctl:
>
>    - DRM_IOCTL_XE_GEM_MMAP_OFFSET: always succeeds regardless of
>      purgeable state (just returns the pre-allocated offset)
>    - mmap() on DONTNEED BO: fails with -EBUSY (temporary state)
>    - mmap() on purged BO: fails with -EINVAL (permanent, no backing store)
>
> v5:
>    - Add purged-mmap-blocked subtest to verify mmap is blocked after
>      BO backing store is permanently purged.
>
> v6:
>    - DRM_IOCTL_XE_GEM_MMAP_OFFSET always succeeds; the purgeable check
>      now happens in xe_gem_object_mmap() at mmap() time. For purged BOs,
>      assert mmap() fails with -EINVAL.
>
> Cc: Nishit Sharma <nishit.sharma@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> Cc: Pravalika Gurram <pravalika.gurram@intel.com>
> Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
> ---
>   tests/intel/xe_madvise.c | 42 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 42 insertions(+)
>
> diff --git a/tests/intel/xe_madvise.c b/tests/intel/xe_madvise.c
> index de4a6e34c..81e05b6d4 100644
> --- a/tests/intel/xe_madvise.c
> +++ b/tests/intel/xe_madvise.c
> @@ -170,6 +170,42 @@ static void purgeable_setup_simple_bo(int fd, uint32_t *vm, uint32_t *bo,
>   	xe_wait_ufence(fd, &sync_val, 1, 0, NSEC_PER_SEC);
>   }
>   
> +/**
> + * SUBTEST: purged-mmap-blocked
> + * Description: After BO is purged, verify mmap() fails with -EINVAL
> + * Test category: functionality test
> + */
> +static void test_purged_mmap_blocked(int fd)
> +{
> +	uint32_t bo, vm;
> +	uint64_t addr = PURGEABLE_ADDR;
> +	size_t bo_size = PURGEABLE_BO_SIZE;
> +	struct drm_xe_gem_mmap_offset mmo = {};
> +	void *ptr;
> +
> +	purgeable_setup_simple_bo(fd, &vm, &bo, addr, bo_size, false);
> +	if (!purgeable_mark_and_verify_purged(fd, vm, addr, bo_size)) {

This function should be defined in this patch. Going through 
implementation available in Patch-3/9. In that below code used

     vram_size = xe_visible_vram_size(fd, 0);

What it returns in igfx platforms? Instead we can use

/* Purgeable BO either in VRAM or SMEM */
mem_size = xe_has_vram(pf_fd)?xe_visible_vram_size(fd, 
0):igt_get_total_ram_mb() << 20;
         if (vram_size > 0) {
                 /* dGPU: pressure VRAM to trigger purgeable reclaim */
                 mem_size = vram_size;
         } else {
                 /*
                  * iGPU: purgeable BOs reside in system memory. Use *total*
                  * RAM (not just available) as the baseline so that we 
always
                  * over-commit regardless of how much is already in use.
                  */
                 mem_size = igt_get_total_ram_mb() << 20;
         }

> +		gem_close(fd, bo);
> +		xe_vm_destroy(fd, vm);
> +		igt_skip("Unable to induce purge on this platform/config");
> +	}
static bool purgeable_mark_and_verify_purged(int fd, uint32_t vm, 
uint64_t addr, size_t size) --> this should be part of this patch
{
         uint32_t retained;

         /* Mark as DONTNEED */
         retained = xe_vm_madvise_purgeable(fd, vm, addr, size,
  DRM_XE_VMA_PURGEABLE_STATE_DONTNEED);

         if (retained != 1)

So here if BO was purged after above call it'll return 0, so if (0 != 1) 
will be true and it'll return false.

                 return false;

         /* Trigger memory pressure */
         trigger_memory_pressure(fd, vm);

         /* Verify purged */
         retained = xe_vm_madvise_purgeable(fd, vm, addr, size,
  DRM_XE_VMA_PURGEABLE_STATE_WILLNEED);
         return retained == 0;

}

static void test_purged_mmap_blocked(int fd)
{
         uint32_t bo, vm;
         uint64_t addr = PURGEABLE_ADDR;
         size_t bo_size = PURGEABLE_BO_SIZE;
         struct drm_xe_gem_mmap_offset mmo = {};
         void *ptr;

         purgeable_setup_simple_bo(fd, &vm, &bo, addr, bo_size, false);
         if (!purgeable_mark_and_verify_purged(fd, vm, addr, bo_size)) {

Here if returned false from above which is basically if BO was purged 
retained  = 0 then skip is called which is not the intention
                 gem_close(fd, bo);
                 xe_vm_destroy(fd, vm);
                 igt_skip("Unable to induce purge on this platform/config");
         }

         /*
          * Getting the mmap offset is always allowed regardless of 
purgeable
          * state - the blocking happens at mmap() time 
(xe_gem_object_mmap).
          * For a purged BO, mmap() must fail with -EINVAL (no backing 
store).
          */
         mmo.handle = bo;
         igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, 
&mmo), 0);

         ptr = mmap(NULL, bo_size, PROT_READ | PROT_WRITE, MAP_SHARED, 
fd, mmo.offset);
         igt_assert_eq_u64((uint64_t)ptr, (uint64_t)MAP_FAILED);
         igt_assert_eq(errno, EINVAL);

         gem_close(fd, bo);
         xe_vm_destroy(fd, vm);
}


> +
> +	/*
> +	 * Getting the mmap offset is always allowed regardless of purgeable
> +	 * state - the blocking happens at mmap() time (xe_gem_object_mmap).
> +	 * For a purged BO, mmap() must fail with -EINVAL (no backing store).
> +	 */
> +	mmo.handle = bo;
> +	igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &mmo), 0);
> +
> +	ptr = mmap(NULL, bo_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, mmo.offset);
> +	igt_assert_eq_u64((uint64_t)ptr, (uint64_t)MAP_FAILED);
> +	igt_assert_eq(errno, EINVAL);
> +
> +	gem_close(fd, bo);
> +	xe_vm_destroy(fd, vm);
> +}
> +
>   /**
>    * SUBTEST: dontneed-before-mmap
>    * Description: Mark BO as DONTNEED before mmap, verify mmap() fails with -EBUSY
> @@ -226,6 +262,12 @@ int igt_main()
>   			break;
>   		}
>   
> +	igt_subtest("purged-mmap-blocked")
> +		xe_for_each_engine(fd, hwe) {
> +			test_purged_mmap_blocked(fd);
> +			break;
> +		}
> +
>   	igt_fixture() {
>   		xe_device_put(fd);
>   		drm_close_driver(fd);

  reply	other threads:[~2026-04-06 12:34 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 12:44 [PATCH i-g-t v6 0/9] tests/xe: Add purgeable memory madvise tests for system allocator Arvind Yadav
2026-03-25 12:44 ` [PATCH i-g-t v6 1/9] drm-uapi/xe_drm: Add UAPI support for purgeable buffer objects Arvind Yadav
2026-04-06  5:23   ` Sharma, Nishit
2026-04-06  6:00     ` Yadav, Arvind
2026-03-25 12:44 ` [PATCH i-g-t v6 2/9] lib/xe: Add purgeable memory ioctl support Arvind Yadav
2026-04-06  6:59   ` Sharma, Nishit
2026-04-07  3:18     ` Yadav, Arvind
2026-03-25 12:44 ` [PATCH i-g-t v6 3/9] tests/intel/xe_madvise: Add dontneed-before-mmap subtest Arvind Yadav
2026-04-06  9:53   ` Sharma, Nishit
2026-04-06 10:30     ` Sharma, Nishit
2026-04-07  4:21       ` Yadav, Arvind
2026-03-25 12:44 ` [PATCH i-g-t v6 4/9] tests/intel/xe_madvise: Add purged-mmap-blocked subtest Arvind Yadav
2026-04-06 12:34   ` Sharma, Nishit [this message]
2026-04-07  5:09     ` Yadav, Arvind
2026-03-25 12:44 ` [PATCH i-g-t v6 5/9] tests/intel/xe_madvise: Add dontneed-after-mmap subtest Arvind Yadav
2026-04-06 13:33   ` Sharma, Nishit
2026-04-07  5:15     ` Yadav, Arvind
2026-03-25 12:44 ` [PATCH i-g-t v6 6/9] tests/intel/xe_madvise: Add dontneed-before-exec subtest Arvind Yadav
2026-04-06 16:48   ` Sharma, Nishit
2026-04-07  5:29     ` Yadav, Arvind
2026-03-25 12:44 ` [PATCH i-g-t v6 7/9] tests/intel/xe_madvise: Add dontneed-after-exec subtest Arvind Yadav
2026-04-07 14:51   ` Sharma, Nishit
2026-03-25 12:44 ` [PATCH i-g-t v6 8/9] tests/intel/xe_madvise: Add per-vma-tracking subtest Arvind Yadav
2026-04-07  7:20   ` Sharma, Nishit
2026-04-07  8:49     ` Yadav, Arvind
2026-03-25 12:44 ` [PATCH i-g-t v6 9/9] tests/intel/xe_madvise: Add per-vma-protection subtest Arvind Yadav
2026-04-07  7:31   ` Sharma, Nishit
2026-04-07  8:54     ` Yadav, Arvind
2026-03-25 22:59 ` ✓ Xe.CI.BAT: success for tests/xe: Add purgeable memory madvise tests for system allocator (rev6) Patchwork
2026-03-25 23:15 ` ✓ i915.CI.BAT: " Patchwork
2026-03-26  9:19 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-03-26 11:22 ` ✓ i915.CI.Full: success " 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=41012de6-8a70-49ed-9332-1746598c8e51@intel.com \
    --to=nishit.sharma@intel.com \
    --cc=arvind.yadav@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=pravalika.gurram@intel.com \
    --cc=thomas.hellstrom@linux.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