From: "Sharma, Nishit" <nishit.sharma@intel.com>
To: "Gurram, Pravalika" <pravalika.gurram@intel.com>,
"Yadav, Arvind" <arvind.yadav@intel.com>,
"igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>
Cc: "Brost, Matthew" <matthew.brost@intel.com>,
"Ghimiray, Himal Prasad" <himal.prasad.ghimiray@intel.com>,
"thomas.hellstrom@linux.intel.com"
<thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH i-g-t v3 3/8] tests/intel/xe_madvise: Add dontneed-before-mmap subtest
Date: Mon, 23 Feb 2026 11:19:54 +0530 [thread overview]
Message-ID: <bf1586d7-6753-488b-8ea6-d5bbb41dfb66@intel.com> (raw)
In-Reply-To: <BL1PR11MB5525EA60CF564CF51C1A85E18477A@BL1PR11MB5525.namprd11.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 8777 bytes --]
On 2/23/2026 10:39 AM, Gurram, Pravalika wrote:
>
>> -----Original Message-----
>> From: Yadav, Arvind<arvind.yadav@intel.com>
>> Sent: Tuesday, 17 February, 2026 08:04 AM
>> To:igt-dev@lists.freedesktop.org
>> Cc: Brost, Matthew<matthew.brost@intel.com>; Ghimiray, Himal Prasad
>> <himal.prasad.ghimiray@intel.com>;thomas.hellstrom@linux.intel.com;
>> Sharma, Nishit<nishit.sharma@intel.com>; Gurram, Pravalika
>> <pravalika.gurram@intel.com>
>> Subject: [PATCH i-g-t v3 3/8] tests/intel/xe_madvise: Add dontneed-before-
>> mmap subtest
>>
>> This test validates kernel behavior when mapping a BO that was already
>> marked as purgeable and purged before mmap. After purging the BO under
>> memory pressure, the test attempts to mmap and access it. The kernel should
>> trigger SIGBUS or SIGSEGV when accessing the purged mapping, confirming
>> that purged memory is properly invalidated.
>>
>> Cc: Nishit Sharma<nishit.sharma@intel.com>
>> Cc: Pravalika Gurram<pravalika.gurram@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>
>> Signed-off-by: Arvind Yadav<arvind.yadav@intel.com>
>> ---
>> tests/intel/xe_madvise.c | 219
>> +++++++++++++++++++++++++++++++++++++++
>> tests/meson.build | 1 +
>> 2 files changed, 220 insertions(+)
>> create mode 100644 tests/intel/xe_madvise.c
>>
>> diff --git a/tests/intel/xe_madvise.c b/tests/intel/xe_madvise.c new file mode
>> 100644 index 000000000..7dbe70f42
>> --- /dev/null
>> +++ b/tests/intel/xe_madvise.c
>> @@ -0,0 +1,219 @@
>> +// SPDX-License-Identifier: MIT
>> +/*
>> + * Copyright © 2025 Intel Corporation
>> + */
>> +
>> +/**
>> + * TEST: Validate purgeable BO madvise functionality
>> + * Category: Core
>> + * Mega feature: General Core features
>> + * Sub-category: Memory management tests
>> + * Functionality: madvise, purgeable
>> + */
>> +
>> +#include "igt.h"
>> +#include "xe_drm.h"
>> +
>> +#include "xe/xe_ioctl.h"
>> +#include "xe/xe_query.h"
>> +
>> +/* Purgeable test constants */
>> +#define PURGEABLE_ADDR 0x1a0000
>> +#define PURGEABLE_BO_SIZE 4096
>> +
>> +/**
>> + * trigger_memory_pressure - Fill VRAM + 25% to force purgeable reclaim
>> + * @fd: DRM file descriptor
>> + * @vm: VM handle (unused, kept for API compatibility)
>> + *
>> + * Allocates BOs in a temporary VM until VRAM is overcommitted,
>> + * forcing the kernel to purge DONTNEED-marked BOs.
>> + */
>> +static void trigger_memory_pressure(int fd, uint32_t vm) {
>> + uint64_t vram_size, overpressure;
>> + const uint64_t chunk = 8ull << 20; /* 8 MiB */
>> + int max_objs, n = 0;
>> + uint32_t *handles;
>> + uint64_t total;
>> + void *p;
>> + uint32_t handle, temp_vm;
>> +
>> + /* Use a separate VM so pressure BOs don't affect the test VM */
>> + temp_vm = xe_vm_create(fd, 0, 0);
>> +
>> + vram_size = xe_visible_vram_size(fd, 0);
>> + /* Scale overpressure to 25% of VRAM, minimum 64MB */
>> + overpressure = vram_size / 4;
>> + if (overpressure < (64 << 20))
>> + overpressure = 64 << 20;
>> +
>> + max_objs = (vram_size + overpressure) / chunk + 1;
>> + handles = malloc(max_objs * sizeof(*handles));
>> + igt_assert(handles);
>> +
>> + total = 0;
>> + while (total < vram_size + overpressure && n < max_objs) {
>> + handle = xe_bo_create(fd, temp_vm, chunk,
>> + vram_if_possible(fd, 0),
>> +
>> DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
>> + handles[n++] = handle;
>> + total += chunk;
>> +
>> + p = xe_bo_map(fd, handle, chunk);
>> + igt_assert(p != MAP_FAILED);
>> +
>> + /* Fault in all pages so they actually consume VRAM */
>> + memset(p, 0xCD, chunk);
>> + munmap(p, chunk);
>> + }
>> +
>> + /* Allow shrinker time to process pressure */
>> + usleep(100000);
>> +
>> + for (int i = 0; i < n; i++)
>> + gem_close(fd, handles[i]);
>> +
>> + free(handles);
>> +
>> + xe_vm_destroy(fd, temp_vm);
>> +}
>> +
>> +static jmp_buf jmp;
>> +
>> +__noreturn static void sigtrap(int sig) {
>> + siglongjmp(jmp, sig);
>> +}
>> +
>> +/**
>> + * purgeable_mark_and_verify_purged - Mark DONTNEED, pressure, check
>> +purged
>> + * @fd: DRM file descriptor
>> + * @vm: VM handle
>> + * @addr: Virtual address of the BO
>> + * @size: Size of the BO
>> + *
>> + * Returns true if the BO was purged under memory pressure.
>> + */
>> +static bool purgeable_mark_and_verify_purged(int fd, uint32_t vm,
>> +uint64_t addr, size_t size) {
>> + uint32_t retained;
>> +
>> + /* Mark as DONTNEED */
>> + retained = xe_vm_madvise_purgeable(fd, vm, addr, size,
>> +
>> DRM_XE_VMA_PURGEABLE_STATE_DONTNEED);
>> + if (retained != 1)
>> + 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;
>> +}
>> +
>> +/**
>> + * purgeable_setup_simple_bo - Setup VM and bind a single BO
>> + * @fd: DRM file descriptor
>> + * @vm: Output VM handle
>> + * @bo: Output BO handle
>> + * @addr: Virtual address to bind at
>> + * @size: Size of the BO
>> + * @use_scratch: Whether to use scratch page flag
>> + *
>> + * Helper to create VM, BO, and bind it at the specified address.
>> + */
>> +static void purgeable_setup_simple_bo(int fd, uint32_t *vm, uint32_t *bo,
>> + uint64_t addr, size_t size, bool
>> use_scratch) {
>> + struct drm_xe_sync sync = {
>> + .type = DRM_XE_SYNC_TYPE_USER_FENCE,
>> + .flags = DRM_XE_SYNC_FLAG_SIGNAL,
>> + .timeline_value = 1,
>> + };
>> + uint64_t sync_val = 0;
>> +
>> + *vm = xe_vm_create(fd, use_scratch ?
>> DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE : 0, 0);
>> + *bo = xe_bo_create(fd, *vm, size, vram_if_possible(fd, 0),
>> +
>> DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
>> +
>> + sync.addr = to_user_pointer(&sync_val);
>> + xe_vm_bind_async(fd, *vm, 0, *bo, 0, addr, size, &sync, 1);
>> + xe_wait_ufence(fd, &sync_val, 1, 0, NSEC_PER_SEC); }
>> +
>> +/**
>> + * SUBTEST: dontneed-before-mmap
>> + * Description: Mark BO as DONTNEED before mmap, verify mmap fails or
>> +SIGBUS on access
>> + * Test category: functionality test
>> + */
>> +static void test_dontneed_before_mmap(int fd, struct
>> +drm_xe_engine_class_instance *hwe) {
>> + uint32_t bo, vm;
>> + uint64_t addr = PURGEABLE_ADDR;
>> + size_t bo_size = PURGEABLE_BO_SIZE;
>> + void *map;
>> +
>> + purgeable_setup_simple_bo(fd, &vm, &bo, addr, bo_size, false);
>> + if (!purgeable_mark_and_verify_purged(fd, vm, addr, bo_size))
>> + igt_skip("Unable to induce purge on this platform/config");
No cleanup before igt_skip() or it's handled somewhere. gem_close(fd,
bo) and xe_vm_destroy(fd, vm);
>> +
>> + /* mmap the purged BO - access should trigger SIGBUS */
>> + map = xe_bo_map(fd, bo, bo_size);
Should check igt_assert(map != MAP_FAILED) before using it below.
>> +
>> + {
>> + sighandler_t old_sigsegv, old_sigbus;
>> + char *ptr = (char *)map;
>> + int sig;
>> +
>> + old_sigsegv = signal(SIGSEGV, (__sighandler_t)sigtrap);
>> + old_sigbus = signal(SIGBUS, (__sighandler_t)sigtrap);
>> +
>> + sig = sigsetjmp(jmp, SIGBUS | SIGSEGV);
>> + switch (sig) {
>> + case SIGBUS:
>> + case SIGSEGV:
>> + /* Expected - purged BO access failed */
>> + break;
>> + case 0:
>> + *ptr = 0;
>> + __attribute__ ((fallthrough));
why this __attribute__? Any compiler warning? Can't it be handled like
case 0:
default:
*ptr = 0;
igt_assert_f(false, "Access to purged mmap should trigger SIGBUS, got
sig=%d\n", sig);
break;
as you are doing intentional fallout from case 0 to default?
>> + default:
>> + igt_assert_f(false,
>> + "Access to purged mmap should trigger
>> SIGBUS, got sig=%d\n",
>> + sig);
>> + break;
>> + }
>> +
>> + signal(SIGBUS, old_sigbus);
>> + signal(SIGSEGV, old_sigsegv);
>> + munmap(map, bo_size);
>> + }
>> +
>> + gem_close(fd, bo);
>> + xe_vm_destroy(fd, vm);
>> +}
>> +
>> +int igt_main()
>> +{
>> + struct drm_xe_engine_class_instance *hwe;
>> + int fd;
>> +
>> + igt_fixture() {
>> + fd = drm_open_driver(DRIVER_XE);
>> + xe_device_get(fd);
>> + }
>> +
>> + igt_subtest("dontneed-before-mmap")
>> + xe_for_each_engine(fd, hwe) {
>> + test_dontneed_before_mmap(fd, hwe);
>> + break;
>> + }
>> +
>> + igt_fixture() {
>> + xe_device_put(fd);
>> + drm_close_driver(fd);
>> + }
>> +}
> Reviewed-by: Pravalika Gurram<pravalika.gurram@intel.com>
>> diff --git a/tests/meson.build b/tests/meson.build index
>> 0ad728b87..9d41d7de6 100644
>> --- a/tests/meson.build
>> +++ b/tests/meson.build
>> @@ -313,6 +313,7 @@ intel_xe_progs = [
>> 'xe_huc_copy',
>> 'xe_intel_bb',
>> 'xe_live_ktest',
>> + 'xe_madvise',
>> 'xe_media_fill',
>> 'xe_mmap',
>> 'xe_module_load',
>> --
>> 2.43.0
[-- Attachment #2: Type: text/html, Size: 11063 bytes --]
next prev parent reply other threads:[~2026-02-23 5:50 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 2:34 [PATCH i-g-t v3 0/8] tests/xe: Add purgeable memory madvise tests for system allocator Arvind Yadav
2026-02-17 2:34 ` [PATCH i-g-t v3 1/8] drm-uapi/xe_drm: Add UAPI support for purgeable buffer objects Arvind Yadav
2026-02-18 11:22 ` Kamil Konieczny
2026-02-23 4:29 ` Gurram, Pravalika
2026-02-23 9:33 ` Yadav, Arvind
2026-02-17 2:34 ` [PATCH i-g-t v3 2/8] lib/xe: Add purgeable memory ioctl support Arvind Yadav
2026-02-23 4:30 ` Gurram, Pravalika
2026-02-17 2:34 ` [PATCH i-g-t v3 3/8] tests/intel/xe_madvise: Add dontneed-before-mmap subtest Arvind Yadav
2026-02-19 4:58 ` Gurram, Pravalika
2026-02-20 6:06 ` Yadav, Arvind
2026-02-23 5:09 ` Gurram, Pravalika
2026-02-23 5:49 ` Sharma, Nishit [this message]
2026-02-23 9:36 ` Yadav, Arvind
2026-02-17 2:34 ` [PATCH i-g-t v3 4/8] tests/intel/xe_madvise: Add dontneed-after-mmap subtest Arvind Yadav
2026-02-19 5:01 ` Gurram, Pravalika
2026-02-20 6:13 ` Yadav, Arvind
2026-02-23 5:10 ` Gurram, Pravalika
2026-02-23 5:52 ` Sharma, Nishit
2026-02-23 9:37 ` Yadav, Arvind
2026-02-17 2:34 ` [PATCH i-g-t v3 5/8] tests/intel/xe_madvise: Add dontneed-before-exec subtest Arvind Yadav
2026-02-23 5:10 ` Gurram, Pravalika
2026-02-23 6:06 ` Sharma, Nishit
2026-02-23 9:45 ` Yadav, Arvind
2026-02-17 2:34 ` [PATCH i-g-t v3 6/8] tests/intel/xe_madvise: Add dontneed-after-exec subtest Arvind Yadav
2026-02-23 5:11 ` Gurram, Pravalika
2026-02-23 7:04 ` Sharma, Nishit
2026-02-24 4:07 ` Yadav, Arvind
2026-02-17 2:34 ` [PATCH i-g-t v3 7/8] tests/intel/xe_madvise: Add per-vma-tracking subtest Arvind Yadav
2026-02-23 5:11 ` Gurram, Pravalika
2026-02-23 7:17 ` Sharma, Nishit
2026-02-24 4:08 ` Yadav, Arvind
2026-02-17 2:34 ` [PATCH i-g-t v3 8/8] tests/intel/xe_madvise: Add per-vma-protection subtest Arvind Yadav
2026-02-23 5:12 ` Gurram, Pravalika
2026-02-23 7:25 ` Sharma, Nishit
2026-02-17 3:25 ` ✓ Xe.CI.BAT: success for tests/xe: Add purgeable memory madvise tests for system allocator (rev3) Patchwork
2026-02-17 4:22 ` ✓ Xe.CI.FULL: " Patchwork
2026-02-17 8:57 ` ✓ i915.CI.BAT: " Patchwork
2026-02-17 10:50 ` ✗ i915.CI.Full: failure " 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=bf1586d7-6753-488b-8ea6-d5bbb41dfb66@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