Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tejas Upadhyay <tejas.upadhyay@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Tejas Upadhyay <tejas.upadhyay@intel.com>
Subject: [i-g-t] tests/intel/xe_mempage_offline: Add fault-inject based page offline tests
Date: Thu, 16 Jul 2026 15:27:04 +0530	[thread overview]
Message-ID: <20260716095703.1543088-2-tejas.upadhyay@intel.com> (raw)

Add IGT tests for VRAM page offlining using the kernel's fault-inject
infrastructure (inject_mempage_offline). Tests exercise:

- inject-single-page: Inject one fault via auto-pick ("0"), verify
  page appears in vram_bad_pages sysfs with 'R' (reserved) flag
- inject-duplicate-page: Re-inject the same PFN, verify soft→hard
  promotion returns -EEXIST and page count stays unchanged

The trigger file (inject_mempage_offline_trigger) accepts:
- "0"      : auto-pick last unallocated VRAM page
- "0xPFN"  : inject fault at a specific PFN address

If CONFIG_FAULT_INJECTION_DEBUG_FS is enabled, the fault-inject
probability/times knobs are configured first. If unavailable
(only CONFIG_FAULT_INJECTION), the trigger injects directly.

Requires CRI platform with CONFIG_FAULT_INJECTION enabled.

Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
---
 tests/intel/xe_mempage_offline.c | 195 +++++++++++++++++++++++++++++++
 tests/meson.build                |   1 +
 2 files changed, 196 insertions(+)
 create mode 100644 tests/intel/xe_mempage_offline.c

diff --git a/tests/intel/xe_mempage_offline.c b/tests/intel/xe_mempage_offline.c
new file mode 100644
index 000000000..ae9ce981d
--- /dev/null
+++ b/tests/intel/xe_mempage_offline.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+/**
+ * TEST: VRAM page offline injection and verification
+ * Category: Core
+ * Mega feature: General Core features
+ * Sub-category: RAS
+ * Functionality: memory page offline
+ * Test category: functionality test
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "igt.h"
+#include "igt_debugfs.h"
+#include "igt_device.h"
+#include "igt_sysfs.h"
+
+#include "xe/xe_query.h"
+
+#define FAULT_INJECT_DIR	"inject_mempage_offline"
+#define TRIGGER_FILE		"inject_mempage_offline_trigger"
+#define VRAM_BAD_PAGES		"device/vram_bad_pages"
+
+static int count_bad_pages(int sysfs_fd)
+{
+	char buf[4096];
+	int len, count = 0;
+	char *line;
+
+	len = igt_sysfs_read(sysfs_fd, VRAM_BAD_PAGES, buf, sizeof(buf) - 1);
+	if (len <= 0)
+		return 0;
+
+	buf[len] = '\0';
+
+	/* Each entry line has format: "0x%08x : 0x%08x : %c\n" */
+	line = buf;
+	while ((line = strchr(line, '\n')) != NULL) {
+		count++;
+		line++;
+	}
+
+	/* Subtract the header line (max_pages : XXXX) */
+	if (count > 0)
+		count--;
+
+	return count;
+}
+
+static bool bad_page_has_flag(int sysfs_fd, char flag)
+{
+	char buf[4096];
+	int len;
+	char *p;
+
+	len = igt_sysfs_read(sysfs_fd, VRAM_BAD_PAGES, buf, sizeof(buf) - 1);
+	if (len <= 0)
+		return false;
+
+	buf[len] = '\0';
+
+	/* Look for the flag character after last ':' on entry lines */
+	p = buf;
+	while ((p = strstr(p, " : ")) != NULL) {
+		p += 3;
+		if (*p == flag)
+			return true;
+	}
+
+	return false;
+}
+
+static uint64_t get_last_bad_page_pfn(int sysfs_fd)
+{
+	char buf[4096];
+	int len;
+	char *line, *last_entry = NULL;
+	uint64_t pfn = 0;
+
+	len = igt_sysfs_read(sysfs_fd, VRAM_BAD_PAGES, buf, sizeof(buf) - 1);
+	if (len <= 0)
+		return 0;
+
+	buf[len] = '\0';
+
+	/* Find last entry line (format: "0x%08llx : 0x%08llx : %c\n") */
+	line = buf;
+	while (*line) {
+		if (line[0] == '0' && line[1] == 'x')
+			last_entry = line;
+		line = strchr(line, '\n');
+		if (!line)
+			break;
+		line++;
+	}
+
+	if (last_entry)
+		sscanf(last_entry, "0x%lx", &pfn);
+
+	return pfn;
+}
+
+static void inject_fault(int fd)
+{
+	/* Use fault-inject knobs if available, otherwise trigger directly */
+	if (igt_debugfs_exists(fd, FAULT_INJECT_DIR "/probability", O_WRONLY)) {
+		igt_debugfs_write(fd, FAULT_INJECT_DIR "/probability", "100");
+		igt_debugfs_write(fd, FAULT_INJECT_DIR "/times", "1");
+		igt_debugfs_write(fd, FAULT_INJECT_DIR "/verbose", "1");
+	}
+	__igt_debugfs_write(fd, TRIGGER_FILE, "0", 1);
+}
+
+/**
+ * SUBTEST: inject-single-page
+ * Description: Inject a single VRAM page fault and verify it appears in vram_bad_pages
+ */
+
+/**
+ * SUBTEST: inject-duplicate-page
+ * Description: Inject two pages and verify both appear in vram_bad_pages
+ */
+
+int igt_main()
+{
+	int fd;
+	int sysfs_fd;
+	uint16_t devid;
+
+	igt_fixture() {
+		fd = drm_open_driver(DRIVER_XE);
+		devid = intel_get_drm_devid(fd);
+		igt_require(intel_get_device_info(devid)->is_crescentisland);
+		igt_require(igt_debugfs_exists(fd, TRIGGER_FILE, O_WRONLY));
+		sysfs_fd = igt_sysfs_open(fd);
+		igt_assert(sysfs_fd >= 0);
+	}
+
+	igt_subtest("inject-single-page") {
+		int initial_count, after_count;
+
+		initial_count = count_bad_pages(sysfs_fd);
+		inject_fault(fd);
+		after_count = count_bad_pages(sysfs_fd);
+		igt_assert_eq(after_count, initial_count + 1);
+		igt_assert(bad_page_has_flag(sysfs_fd, 'R'));
+	}
+
+	igt_subtest("inject-duplicate-page") {
+		int initial_count, after_count;
+		uint64_t pfn;
+		char pfn_str[32];
+		int debugfs_fd, ret;
+
+		initial_count = count_bad_pages(sysfs_fd);
+
+		/* First injection — auto-pick unallocated page */
+		inject_fault(fd);
+		after_count = count_bad_pages(sysfs_fd);
+		igt_assert_eq(after_count, initial_count + 1);
+
+		/* Get PFN of the page just injected */
+		pfn = get_last_bad_page_pfn(sysfs_fd);
+		igt_assert(pfn != 0);
+
+		/*
+		 * Re-inject same PFN — should return -EEXIST (soft→hard
+		 * promotion). Write to trigger with the PFN value.
+		 */
+		snprintf(pfn_str, sizeof(pfn_str), "0x%lx", pfn);
+		debugfs_fd = igt_debugfs_open(fd, TRIGGER_FILE, O_WRONLY);
+		igt_assert(debugfs_fd >= 0);
+		ret = write(debugfs_fd, pfn_str, strlen(pfn_str));
+		igt_assert(ret < 0 && errno == EEXIST);
+		close(debugfs_fd);
+
+		/* Count should not change — same page, not a new one */
+		after_count = count_bad_pages(sysfs_fd);
+		igt_assert_eq(after_count, initial_count + 1);
+	}
+
+	igt_fixture() {
+		igt_debugfs_write(fd, FAULT_INJECT_DIR "/probability", "0");
+		close(sysfs_fd);
+		drm_close_driver(fd);
+	}
+}
diff --git a/tests/meson.build b/tests/meson.build
index d73aaecd9..c75633684 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -318,6 +318,7 @@ intel_xe_progs = [
 	'xe_live_ktest',
 	'xe_madvise',
 	'xe_media_fill',
+        'xe_mempage_offline',
 	'xe_mmap',
         'xe_module_load',
         'xe_multigpu_svm',
-- 
2.52.0


             reply	other threads:[~2026-07-16  9:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  9:57 Tejas Upadhyay [this message]
2026-07-16 12:00 ` ✓ Xe.CI.BAT: success for tests/intel/xe_mempage_offline: Add fault-inject based page offline tests Patchwork
2026-07-16 12:19 ` ✓ i915.CI.BAT: " Patchwork
2026-07-16 15:56 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-07-16 18:21 ` ✗ 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=20260716095703.1543088-2-tejas.upadhyay@intel.com \
    --to=tejas.upadhyay@intel.com \
    --cc=igt-dev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox