From: Arvind Yadav <arvind.yadav@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com,
thomas.hellstrom@linux.intel.com, nishit.sharma@intel.com,
pravalika.gurram@intel.com
Subject: [i-g-t 1/3] tests/intel/xe_madvise: Add multi-region-partial-unmap-no-gpu subtest
Date: Mon, 6 Apr 2026 15:24:06 +0530 [thread overview]
Message-ID: <20260406095410.1274177-2-arvind.yadav@intel.com> (raw)
In-Reply-To: <20260406095410.1274177-1-arvind.yadav@intel.com>
Verify PAT preservation on partial unmap without GPU access.
Set PAT=UC on multiple regions, unmap a subset, and verify that
remaining mapped regions retain PAT=UC.
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: Nishit Sharma <nishit.sharma@intel.com>
Cc: Pravalika Gurram <pravalika.gurram@intel.com>
Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
---
tests/intel/xe_madvise.c | 138 +++++++++++++++++++++++++++++++++++++++
1 file changed, 138 insertions(+)
diff --git a/tests/intel/xe_madvise.c b/tests/intel/xe_madvise.c
index 2375f5475..37411f342 100644
--- a/tests/intel/xe_madvise.c
+++ b/tests/intel/xe_madvise.c
@@ -17,6 +17,11 @@
#include "xe/xe_ioctl.h"
#include "xe/xe_query.h"
#include "lib/igt_syncobj.h"
+#include "intel_pat.h"
+
+/* SVM madvise test constants */
+#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull
+#define FIVE_SEC (5LL * NSEC_PER_SEC)
static bool xe_has_purgeable_support(int fd)
{
@@ -775,6 +780,136 @@ out:
igt_skip("Unable to induce purge on this platform/config");
}
+/**
+ * SUBTEST: multi-region-partial-unmap-no-gpu
+ * Description: Verify only unmapped regions are reset on partial unmap
+ * without GPU access.
+ * Test category: functionality test
+ */
+static void
+test_multi_region_partial_unmap_no_gpu(int fd)
+{
+ static const int unmap_regions[] = {2, 5, 8};
+ static const int num_regions = 10;
+ const size_t region_size = SZ_1M;
+ const size_t total_size = num_regions * region_size;
+ const int num_unmap = ARRAY_SIZE(unmap_regions);
+ struct drm_xe_sync sync[1] = {
+ { .type = DRM_XE_SYNC_TYPE_USER_FENCE,
+ .flags = DRM_XE_SYNC_FLAG_SIGNAL,
+ .timeline_value = USER_FENCE_VALUE },
+ };
+ struct drm_xe_mem_range_attr *attrs;
+ struct drm_xe_madvise madvise;
+ uint32_t num_ranges;
+ uint64_t vm_sync = 0;
+ uint8_t pat_uc;
+ uint32_t va_bits;
+ void *base_addr;
+ uint32_t vm;
+ int i, j;
+
+ pat_uc = intel_get_pat_idx_uc(fd);
+ va_bits = xe_va_bits(fd);
+
+ vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE |
+ DRM_XE_VM_CREATE_FLAG_FAULT_MODE, 0);
+
+ base_addr = mmap(NULL, total_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ igt_assert(base_addr != MAP_FAILED);
+
+ /* Bind address space with CPU_ADDR_MIRROR and MADVISE_AUTORESET */
+ sync[0].addr = to_user_pointer(&vm_sync);
+ __xe_vm_bind_assert(fd, vm, 0,
+ 0, 0, 0, 0x1ull << va_bits,
+ DRM_XE_VM_BIND_OP_MAP,
+ DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR |
+ DRM_XE_VM_BIND_FLAG_MADVISE_AUTORESET,
+ sync, 1, 0, 0);
+ xe_wait_ufence(fd, &vm_sync, USER_FENCE_VALUE, 0, FIVE_SEC);
+
+ /* Set PAT=UC on the entire 10MB region */
+ memset(&madvise, 0, sizeof(madvise));
+ madvise.vm_id = vm;
+ madvise.start = to_user_pointer(base_addr);
+ madvise.range = total_size;
+ madvise.type = DRM_XE_MEM_RANGE_ATTR_PAT;
+ madvise.pat_index.val = pat_uc;
+ igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_MADVISE, &madvise), 0);
+
+ /* Verify PAT=UC across all regions */
+ attrs = xe_vm_get_mem_attr_values_in_range(fd, vm,
+ to_user_pointer(base_addr),
+ total_size, &num_ranges);
+ igt_assert_f(attrs && num_ranges > 0,
+ "Expected at least 1 range after setting PAT\n");
+ for (i = 0; i < num_ranges; i++) {
+ uint8_t got = attrs[i].pat_index.val;
+
+ if (got != pat_uc) {
+ free(attrs);
+ igt_assert_f(false, "range[%d]: expected UC=%u got %u\n",
+ i, pat_uc, got);
+ }
+ }
+ free(attrs);
+
+ /* Partially unmap non-sequential regions: 2, 5, 8 */
+ for (i = 0; i < num_unmap; i++)
+ igt_assert_eq(munmap(base_addr + (unmap_regions[i] * region_size), region_size), 0);
+
+ /* Remaining mapped regions must still have PAT=UC */
+ for (i = 0; i < num_regions; i++) {
+ bool is_unmapped = false;
+
+ for (j = 0; j < num_unmap; j++) {
+ if (unmap_regions[j] == i) {
+ is_unmapped = true;
+ break;
+ }
+ }
+
+ if (is_unmapped)
+ continue;
+
+ attrs = xe_vm_get_mem_attr_values_in_range(fd, vm,
+ to_user_pointer(base_addr +
+ (i * region_size)),
+ region_size, &num_ranges);
+ igt_assert_f(attrs && num_ranges > 0,
+ "Region %d: mapped region lost attributes after partial unmap\n", i);
+ for (j = 0; j < num_ranges; j++) {
+ uint8_t got = attrs[j].pat_index.val;
+
+ if (got != pat_uc) {
+ free(attrs);
+ igt_assert_f(false,
+ "Region %d range[%d]: PAT changed to %u after partial unmap, expected UC=%u\n",
+ i, j, got, pat_uc);
+ }
+ }
+ free(attrs);
+ }
+
+ /* Cleanup remaining mapped regions */
+ for (i = 0; i < num_regions; i++) {
+ bool is_unmapped = false;
+
+ for (j = 0; j < num_unmap; j++) {
+ if (unmap_regions[j] == i) {
+ is_unmapped = true;
+ break;
+ }
+ }
+
+ if (!is_unmapped)
+ munmap(base_addr + (i * region_size), region_size);
+ }
+
+ xe_vm_destroy(fd, vm);
+}
+
int igt_main()
{
struct drm_xe_engine_class_instance *hwe;
@@ -829,6 +964,9 @@ int igt_main()
break;
}
+ igt_subtest("multi-region-partial-unmap-no-gpu")
+ test_multi_region_partial_unmap_no_gpu(fd);
+
igt_fixture() {
xe_device_put(fd);
drm_close_driver(fd);
--
2.43.0
next prev parent reply other threads:[~2026-04-06 9:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 9:54 [i-g-t 0/3] tests/xe: Add IGT coverage for SVM madvise autoreset on unmap Arvind Yadav
2026-04-06 9:54 ` Arvind Yadav [this message]
2026-04-06 9:54 ` [i-g-t 2/3] tests/intel/xe_madvise: Add single-vma-full-unmap-no-gpu subtest Arvind Yadav
2026-04-06 9:54 ` [i-g-t 3/3] tests/intel/xe_madvise: Add multi-region-partial-unmap subtest Arvind Yadav
2026-04-06 10:04 ` ✗ Fi.CI.BUILD: failure for tests/xe: Add IGT coverage for SVM madvise autoreset on unmap 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=20260406095410.1274177-2-arvind.yadav@intel.com \
--to=arvind.yadav@intel.com \
--cc=himal.prasad.ghimiray@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=nishit.sharma@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