Skip to contentSkip to conversation

drm/xe: add page size allocation mode control and coverage

PATCH Superseded Nareshkumar Gollakoti 2 participants 10 messages Jul 13

Subsystems (2)

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v5 cover drm/xe: add page size allocation mode control and coverage

Some platforms support multiple page sizes for user BO allocations, including 4K, 64K, 2M, and 1G

For validation and debug, it is useful to control the page size selection policy for user BOs so that specific allocation paths can be exercised deterministically. In particular, this makes it possible to force allocations into 2M-only, 1G-only, or mixed modes.

In mixed mode, allocations are distributed across the supported page sizes in a round-robin manner. For example, for four user BOs, the selected page sizes would be:
- BO1: 4K
- BO2: 64K
- BO3: 2M
- BO4: 1G

This series adds debug page-size allocation control for user BO in xe

This series includes:
- debug control state in xe_device
- a debugfs knob to select allocation mode
- 1G BO alignment flag handling
- debug policy application at user BO create time
- propagation into VMA map flags
- PT bind support for selecting leaf level (4K/64K, 2M, 1G paths)
- add live Kunit coverage for BO page size allocation

The default path is unchanged when the debug control is not enabled.

v2
-- addressed v1 comments at
https://patchwork.freedesktop.org/series/169640/

v3
- refactor the design
- update patches based on review feedback
- due to space missing after drm/xe: it created a new series
https://patchwork.freedesktop.org/series/170246/

v4
- initialize page-size control state before userspace-visible registration
- add Kconfig support before CONFIG_DRM_XE_DEBUG_PAGE_SIZE users
- limit debugfs and BO policy handling to supported dGFX VRAM paths
- add fast-path mode checks and ALIGN() overflow handling
- preserve existing BO NEEDS_* flags
- defer mixed-mode index advancement until successful
BO create ioctl completion
- replace 2M/1G vma_flags propagation with stable target_leaf_level state
- propagate target_leaf_level from bind op to VMA and into PT bind
- allow smaller huge-page fallback and fix clear_pt handling in PT walk
- skip VRAM-only live KUnit tests on non-dGFX
and restore state on all exits

v5
v5:
- Guard debug page-size control support with CONFIG_DRM_XE_DEBUG_PAGE_SIZE
- Fix kernel-doc warnings in xe_device_types.h for page_size_alloc_ctrl
- Keep the normal BO creation path unchanged when no debug mode is selected
- Reword commit messages for clarity and to match the implementation

Nareshkumar Gollakoti (7):
drm/xe: add page size allocation control state to xe_device drm/xe/debugfs: add page-size allocation mode knob drm/xe: add XE_BO_FLAG_NEEDS_1G for minimum page-size sizing drm/xe: apply debug page-size allocation policy to user BOs drm/xe/vm: propagate BO page-size requirements to VMA map flags drm/xe/pt: allow selecting the bind leaf PTE level drm/xe/tests: add live KUnit coverage for BO page-size allocation
modes

 drivers/gpu/drm/xe/Kconfig.debug            |  16 ++
 drivers/gpu/drm/xe/tests/xe_bo.c            | 249 ++++++++++++++++++++
 drivers/gpu/drm/xe/tests/xe_live_test_mod.c |   2 +
 drivers/gpu/drm/xe/xe_bo.c                  | 166 ++++++++++++-
 drivers/gpu/drm/xe/xe_bo.h                  |   1 +
 drivers/gpu/drm/xe/xe_debugfs.c             |  62 +++++
 drivers/gpu/drm/xe/xe_device.c              |  13 +-
 drivers/gpu/drm/xe/xe_device.h              |  30 +++
 drivers/gpu/drm/xe/xe_device_types.h        |  31 +++
 drivers/gpu/drm/xe/xe_pt.c                  |  53 ++++-
 drivers/gpu/drm/xe/xe_vm.c                  |  29 +++
 drivers/gpu/drm/xe/xe_vm_types.h            |   9 +
 12 files changed, 656 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v5 1/7 drm/xe: add page size allocation control state to xe_device

Introduce xe_page_size_alloc_ctrl_mode and add page_size_alloc_ctrl state to struct xe_device along with mutex lock.

The new control supports forcing user BO allocations to 2M pages, forcing them to 1G pages, or using a mixed round-robin mode across 4K, 64K, 2M, and 1G page sizes. Track the current mixed-mode index in xe_device so allocation policy can be applied consistently.

v2
- make cur_index to atomic as update need in later patch to avoid race/concurency (sashiko)
v3
- reworded comments
- protect mode/index updates with a mutex for proper concurrency handling

v4(sashiko)
- move xe_debug_page_size_alloc_ctrl_init() before drm_dev_register(), so mutex and control states are initialized
before any userspace visibility

v5(Himal)
- Guard all the debug page size policy code under CONFIG
- Squash Kconfig patch to have Kconfig entry for DEBUG_PAGE_SIZE
- Add inline to check debug page size support and exact mode configured if it is supported.

---
 drivers/gpu/drm/xe/Kconfig.debug     | 16 ++++++++++++++
 drivers/gpu/drm/xe/xe_device.c       | 13 +++++++++++-
 drivers/gpu/drm/xe/xe_device.h       | 30 +++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_device_types.h | 31 ++++++++++++++++++++++++++++
 4 files changed, 89 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/Kconfig.debug +16 -0
index 01227c77f6d7..79118d9efd93 100644
@@ -86,6 +86,22 @@ config DRM_XE_KUNIT_TEST
 
 	  If in doubt, say "N".
 
+config DRM_XE_DEBUG_PAGE_SIZE
+	bool "Enable debug control for user BO page-size allocation"
+	depends on DRM_XE_DEBUG && DEBUG_FS
+	help
+	  Expose a debugfs knob to override user BO page-size allocation
+	  handling for validation and debug. Supported modes include forced
+	  2M, forced 1G, and a mixed mode that exercises 4K, 64K, 2M, and
+	  1G page-size paths on platforms that support them.
+
+	  This is an unstable debugfs interface intended for development and
+	  validation only. Its layout, contents, and existence may change or
+	  be removed at any time with no regression warranty.
+
+	  Recommended for driver developers only.
+	  If in doubt, say "N".
+
 config DRM_XE_DEBUG_GUC
         bool "Enable extra GuC related debug options"
         depends on DRM_XE_DEBUG
drivers/gpu/drm/xe/xe_device.c +12 -1
index c9fa4bfed2b9..78dab9ae4f1b 100644
@@ -923,6 +923,15 @@ static void xe_device_wedged_fini(struct drm_device *drm, void *arg)
 		xe_pm_runtime_put(xe);
 }
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+static void xe_debug_page_size_alloc_ctrl_init(struct xe_device *xe)
+{
+	mutex_init(&xe->page_size_alloc_ctrl.lock);
+	xe->page_size_alloc_ctrl.mode = XE_PAGE_SIZE_ALLOC_CTRL_MODE_NONE;
+	xe->page_size_alloc_ctrl.cur_index = 0;
+}
+#endif
+
 int xe_device_probe(struct xe_device *xe)
 {
 	struct xe_tile *tile;
@@ -1074,7 +1083,9 @@ int xe_device_probe(struct xe_device *xe)
 	err = xe_psmi_init(xe);
 	if (err)
 		return err;
-
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+	xe_debug_page_size_alloc_ctrl_init(xe);
+#endif
 	err = drm_dev_register(&xe->drm, 0);
 	if (err)
 		return err;
drivers/gpu/drm/xe/xe_device.h +30 -0
index a03760d0ce38..df574738e3f5 100644
@@ -212,6 +212,36 @@ static inline bool xe_device_wedged(struct xe_device *xe)
 	return atomic_read(&xe->wedged.flag);
 }
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+static inline bool xe_debug_page_size_supported(struct xe_device *xe)
+{
+	return IS_DGFX(xe);
+}
+
+static inline bool xe_debug_exact_page_size_mode(struct xe_device *xe)
+{
+	enum xe_page_size_alloc_ctrl_mode mode;
+
+	if (!xe_debug_page_size_supported(xe))
+		return false;
+
+	mode = READ_ONCE(xe->page_size_alloc_ctrl.mode);
+
+	return mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M ||
+	       mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G;
+}
+#else
+static inline bool xe_debug_page_size_supported(struct xe_device *xe)
+{
+	return false;
+}
+
+static inline bool xe_debug_exact_page_size_mode(struct xe_device *xe)
+{
+	return false;
+}
+#endif
+
 void xe_device_set_wedged_method(struct xe_device *xe, unsigned long method);
 void xe_device_declare_wedged(struct xe_device *xe);
 int xe_device_validate_wedged_mode(struct xe_device *xe, unsigned int mode);
drivers/gpu/drm/xe/xe_device_types.h +31 -0
index 022e08205897..2210da37c9a9 100644
@@ -61,6 +61,23 @@ enum xe_wedged_mode {
 	XE_WEDGED_MODE_UPON_ANY_HANG_NO_RESET = 2,
 };
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+/**
+ * enum xe_page_size_alloc_ctrl_mode - User BO page-size allocation control modes
+ * @XE_PAGE_SIZE_ALLOC_CTRL_MODE_NONE: Use the normal allocation policy
+ * @XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M: Force user BO allocations to 2M pages
+ * @XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G: Force user BO allocations to 1G pages
+ * @XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED: Select page sizes in round-robin order
+ *     (4K, 64K, 2M, 1G)
+ */
+enum xe_page_size_alloc_ctrl_mode {
+	XE_PAGE_SIZE_ALLOC_CTRL_MODE_NONE = 0,
+	XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M,
+	XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G,
+	XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED
+};
+#endif
+
 #define XE_BO_INVALID_OFFSET	LONG_MAX
 
 #define GRAPHICS_VER(xe) ((xe)->info.graphics_verx100 / 100)
@@ -474,6 +491,20 @@ struct xe_device {
 	/** @late_bind: xe mei late bind interface */
 	struct xe_late_bind late_bind;
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+	/**
+	 * @page_size_alloc_ctrl: User BO page-size allocation
+	 * debug control state
+	 */
+	struct {
+		/** @mode: xe page size allocation control mode */
+		enum xe_page_size_alloc_ctrl_mode mode;
+		/** @cur_index: Round-robin index used by mixed mode */
+		u32 cur_index;
+		/** @lock: Protects @mode and @cur_index */
+		struct mutex lock;
+	} page_size_alloc_ctrl;
+#endif
 	/** @oa: oa observation subsystem */
 	struct xe_oa oa;
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH v5 2/7 drm/xe/debugfs: add page-size allocation mode knob

In reply to Nareshkumar Gollakoti

Expose a debugfs control to override the page-size allocation mode used for user BOs.

The interface allows switching between the default allocation policy, forced 2M, forced 1G, and mixed allocation modes at runtime. This provides a simple way to validate behavior and debug page-size-dependent allocation flows.

The debugfs entry is built only when CONFIG_DRM_XE_DEBUG_PAGE_SIZE is enabled.

v2
- update changelog to match mutex-based cur_index handling
- reset cur_index when switching to mixed mode (sashiko)

v3
- add CONFIG guard for page-size allocation debugfs support (Himal)
- create debugfs entry under CONFIG_DRM_XE_DEBUG_PAGE_SIZE

v4
- reorderd this patch with kconfig patch to ensure patch builds
- Gurding this debug knob for only discrete graphics

v5(Himal)
- Guard all page size calls with CONFIG_DRM_XE_DEBUG_PAGE_SIZE

---
 drivers/gpu/drm/xe/xe_debugfs.c | 62 +++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
drivers/gpu/drm/xe/xe_debugfs.c +62 -0
index 8c391c7b017a..dcc01336538d 100644
@@ -564,6 +564,56 @@ static const struct file_operations disable_late_binding_fops = {
 	.write = disable_late_binding_set,
 };
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+static ssize_t page_size_alloc_mode_show(struct file *f, char __user *ubuf,
+					 size_t size, loff_t *pos)
+{
+	struct xe_device *xe = file_inode(f)->i_private;
+	char buf[32];
+	int len;
+
+	mutex_lock(&xe->page_size_alloc_ctrl.lock);
+
+	len = scnprintf(buf, sizeof(buf), "%u\n",
+			xe->page_size_alloc_ctrl.mode);
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+
+	return simple_read_from_buffer(ubuf, size, pos, buf, len);
+}
+
+static ssize_t page_size_alloc_mode_set(struct file *f, const char __user *ubuf,
+					size_t size, loff_t *pos)
+{
+	struct xe_device *xe = file_inode(f)->i_private;
+	unsigned int val;
+	int ret;
+
+	ret = kstrtouint_from_user(ubuf, size, 0, &val);
+	if (ret)
+		return ret;
+
+	if (val > XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED)
+		return -EINVAL;
+
+	mutex_lock(&xe->page_size_alloc_ctrl.lock);
+
+	if (val == XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED)
+		xe->page_size_alloc_ctrl.cur_index = 0;
+
+	xe->page_size_alloc_ctrl.mode = (enum xe_page_size_alloc_ctrl_mode)val;
+
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+
+	return size;
+}
+
+static const struct file_operations page_size_alloc_mode_fops = {
+	.owner = THIS_MODULE,
+	.read = page_size_alloc_mode_show,
+	.write = page_size_alloc_mode_set,
+};
+#endif
+
 void xe_debugfs_register(struct xe_device *xe)
 {
 	struct ttm_device *bdev = &xe->ttm;
@@ -616,6 +666,18 @@ void xe_debugfs_register(struct xe_device *xe)
 
 	debugfs_create_file("disable_late_binding", 0600, root, xe,
 			    &disable_late_binding_fops);
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+	/*
+	 * Expose a debugfs knob to control user BO page-size allocation:
+	 * 0 - default behavior
+	 * 1 - force 2M page allocations
+	 * 2 - force 1G page allocations
+	 * 3 - mixed mode: select 4K, 64K, 2M, and 1G in round-robin order
+	 */
+	if (IS_DGFX(xe))
+		debugfs_create_file("page_size_alloc_mode", 0600, root, xe,
+				    &page_size_alloc_mode_fops);
+#endif
 
 	/*
 	 * Don't expose page reclaim configuration file if not supported by the
Signature · 1 line
2.43.0
#3 lore raw

PATCH v5 3/7 drm/xe: add XE_BO_FLAG_NEEDS_1G for minimum page-size sizing

In reply to Nareshkumar Gollakoti

Add XE_BO_FLAG_NEEDS_1G to mark BOs that require 1G minimum page-size sizing.

Update xe_bo_init_locked() to honor the new flag in the existing VRAM/stolen-memory minimum page-size sizing path. When XE_BO_FLAG_NEEDS_1G is set, the BO size is rounded up to 1G. Otherwise, the existing 2M and 64K sizing behavior is preserved.

If multiple minimum page-size flags are set, the largest requirement takes precedence: 1G over 2M over 64K.

v3
- commit message reworded

---
 drivers/gpu/drm/xe/xe_bo.c | 12 ++++++++++--
 drivers/gpu/drm/xe/xe_bo.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +10 -2
index 4c80bac67622..9dbf59fad421 100644
@@ -2323,8 +2323,16 @@ struct xe_bo *xe_bo_init_locked(struct xe_device *xe, struct xe_bo *bo,
 	if (flags & (XE_BO_FLAG_VRAM_MASK | XE_BO_FLAG_STOLEN) &&
 	    !(flags & XE_BO_FLAG_IGNORE_MIN_PAGE_SIZE) &&
 	    ((xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K) ||
-	     (flags & (XE_BO_FLAG_NEEDS_64K | XE_BO_FLAG_NEEDS_2M)))) {
-		size_t align = flags & XE_BO_FLAG_NEEDS_2M ? SZ_2M : SZ_64K;
+	     (flags & (XE_BO_FLAG_NEEDS_64K | XE_BO_FLAG_NEEDS_2M |
+		       XE_BO_FLAG_NEEDS_1G)))) {
+		size_t align;
+
+		if (flags & XE_BO_FLAG_NEEDS_1G)
+			align = SZ_1G;
+		else if (flags & XE_BO_FLAG_NEEDS_2M)
+			align = SZ_2M;
+		else
+			align = SZ_64K;
 
 		aligned_size = ALIGN(size, align);
 		if (type != ttm_bo_type_device)
drivers/gpu/drm/xe/xe_bo.h +1 -0
index 6340317f7d2e..d5d023cac367 100644
@@ -52,6 +52,7 @@
 #define XE_BO_FLAG_CPU_ADDR_MIRROR	BIT(24)
 #define XE_BO_FLAG_FORCE_USER_VRAM	BIT(25)
 #define XE_BO_FLAG_NO_COMPRESSION	BIT(26)
+#define XE_BO_FLAG_NEEDS_1G		BIT(27)
 
 /* this one is trigger internally only */
 #define XE_BO_FLAG_INTERNAL_TEST	BIT(30)
Signature · 1 line
2.43.0
#4 lore raw

PATCH v5 4/7 drm/xe: apply debug page-size allocation policy to user BOs

In reply to Nareshkumar Gollakoti

Apply the debug page-size allocation policy during user BO creation.

When page-size allocation control is enabled, override the user BO page-size selection flags based on the selected debug mode and round the requested size up to the corresponding granularity:
- 2M mode selects 2M handling
- 1G mode selects 1G handling
- mixed mode selects the page size from the current mixed-mode index

This is intended for internal debug and validation flows. When the control mode is left at the default setting, the normal user BO creation path is unchanged.

v2
- ensure debug page-size allocation does not affect the default path (sashiko)
- rework synchronization for concurrent access (sashiko)
- refactor commit message for readability

v3
- update user BO size alignment based on debug policy mode
- reword commit message
- ensure normal user flow is unchanged when debug policy is disabled

v4(sashiko)
- limit debug page-size policy application to VRAM BOs
- do not override preexisting page-size requirement flags
- advance mixed-mode index only after successful
BO create ioctl completion
- add overflow checks before ALIGN() in debug page-size handling
- ensure CONFIG_DRM_XE_DEBUG_PAGE_SIZE enabled and it is dgfx

v5(Himal)
v5:
- Guard debug page-size policy paths with CONFIG_DRM_XE_DEBUG_PAGE_SIZE
- Leave the normal BO creation path unchanged
when no debug mode is selected

---
 drivers/gpu/drm/xe/xe_bo.c | 154 +++++++++++++++++++++++++++++++++++++
 1 file changed, 154 insertions(+)
drivers/gpu/drm/xe/xe_bo.c +154 -0
index 9dbf59fad421..bccc3611dca3 100644
@@ -2612,6 +2612,148 @@ static struct xe_bo *xe_bo_create_novm(struct xe_device *xe, struct xe_tile *til
 	return ret ? ERR_PTR(ret) : bo;
 }
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+static void xe_bo_debug_mixed_mode_cur_index_advance(struct xe_device *xe)
+{
+	if (!IS_DGFX(xe) ||
+	    READ_ONCE(xe->page_size_alloc_ctrl.mode) !=
+	    XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED)
+		return;
+
+	mutex_lock(&xe->page_size_alloc_ctrl.lock);
+	if (xe->page_size_alloc_ctrl.mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED)
+		xe->page_size_alloc_ctrl.cur_index++;
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+}
+
+static bool xe_size_align_overflows(size_t size, size_t align)
+{
+	return size > SIZE_MAX - (align - 1);
+}
+
+static u32 get_flag_from_cur_index_in_mixed_mode(struct xe_device *xe, size_t *align_size,
+						 int *err)
+{
+	static const u32 map[4] = {
+		0, /* default mode 4K */
+		XE_BO_FLAG_NEEDS_64K,
+		XE_BO_FLAG_NEEDS_2M,
+		XE_BO_FLAG_NEEDS_1G,
+	};
+	u32 idx;
+
+	lockdep_assert_held(&xe->page_size_alloc_ctrl.lock);
+
+	*err = 0;
+	idx = xe->page_size_alloc_ctrl.cur_index % ARRAY_SIZE(map);
+
+	if (!map[idx])
+		return 0;
+
+	if (map[idx] == XE_BO_FLAG_NEEDS_64K) {
+		if (xe_size_align_overflows(*align_size, SZ_64K)) {
+			*err = -EINVAL;
+			return 0;
+		}
+		*align_size = ALIGN(*align_size, SZ_64K);
+		return map[idx];
+	}
+
+	if (map[idx] == XE_BO_FLAG_NEEDS_2M) {
+		if (xe_size_align_overflows(*align_size, SZ_2M)) {
+			*err = -EINVAL;
+			return 0;
+		}
+		*align_size = ALIGN(*align_size, SZ_2M);
+		return map[idx];
+	}
+
+	if (map[idx] == XE_BO_FLAG_NEEDS_1G) {
+		if (xe_size_align_overflows(*align_size, SZ_1G)) {
+			*err = -EINVAL;
+			return 0;
+		}
+		*align_size = ALIGN(*align_size, SZ_1G);
+		return map[idx];
+	}
+
+	return 0;
+}
+
+static int xe_bo_apply_debug_page_size_policy(struct xe_device *xe,
+					      u32 *bo_flags,
+					      size_t *size)
+{
+	enum xe_page_size_alloc_ctrl_mode mode;
+	u32 want = 0;
+	size_t align_size = *size;
+	int err = 0;
+
+	if (!IS_DGFX(xe))
+		return 0;
+	/*
+	 * The debug page-size policy is only meaningful for BOs placed in
+	 * VRAM, where the downstream BO init path can
+	 * actually honor the corresponding minimum page-size requirement.
+	 */
+	if (!(*bo_flags & XE_BO_FLAG_VRAM_MASK))
+		return 0;
+
+	/*
+	 * Do not override existing page-size requirement flags, since they
+	 * may reflect functional requirements for specific BO types.
+	 */
+	if (*bo_flags & (XE_BO_FLAG_NEEDS_64K |
+			 XE_BO_FLAG_NEEDS_2M |
+			 XE_BO_FLAG_NEEDS_1G))
+		return 0;
+
+	if (!READ_ONCE(xe->page_size_alloc_ctrl.mode))
+		return 0;
+
+	mutex_lock(&xe->page_size_alloc_ctrl.lock);
+
+	mode = xe->page_size_alloc_ctrl.mode;
+	if (mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_NONE) {
+		goto out_unlock;
+	} else if (mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M) {
+		if (xe_size_align_overflows(align_size, SZ_2M)) {
+			err = -EINVAL;
+			goto out_unlock;
+		}
+		want = XE_BO_FLAG_NEEDS_2M;
+		align_size = ALIGN(align_size, SZ_2M);
+	} else if (mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G) {
+		if (xe_size_align_overflows(align_size, SZ_1G)) {
+			err = -EINVAL;
+			goto out_unlock;
+		}
+		want = XE_BO_FLAG_NEEDS_1G;
+		align_size = ALIGN(align_size, SZ_1G);
+	} else if (mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED) {
+		want = get_flag_from_cur_index_in_mixed_mode(xe, &align_size, &err);
+		if (err)
+			goto out_unlock;
+	} else {
+		goto out_unlock;
+	}
+
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+
+	*bo_flags |= want;
+	/*
+	 * Apply the debug page-size policy by rounding the user BO size up to
+	 * the selected granularity.
+	 */
+	*size = align_size;
+	return err;
+
+out_unlock:
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+	return err;
+}
+#endif
+
 /**
  * xe_bo_create_user() - Create a user BO
  * @xe: The xe device.
@@ -2632,9 +2774,18 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe,
 				u32 flags, struct drm_exec *exec)
 {
 	struct xe_bo *bo;
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+	int err;
+#endif
 
 	flags |= XE_BO_FLAG_USER;
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+
+	err = xe_bo_apply_debug_page_size_policy(xe, &flags, &size);
+	if (err)
+		return ERR_PTR(err);
+#endif
 	if (vm || exec) {
 		xe_assert(xe, exec);
 		bo = __xe_bo_create_locked(xe, NULL, vm, size, 0, ~0ULL,
@@ -3449,6 +3600,9 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
 	if (err)
 		goto out_bulk;
 
+#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
+	xe_bo_debug_mixed_mode_cur_index_advance(xe);
+#endif
 	args->handle = handle;
 	goto out_put;
 
Signature · 1 line
2.43.0
#5 lore raw

PATCH v5 5/7 drm/xe/vm: propagate BO page-size requirements to VMA map flags

In reply to Nareshkumar Gollakoti

Propagate user BO page-size requirement flags into VM bind map operations.

When a user BO carries a page-size requirement flag, set the corresponding VMA PTE flag during bind-op construction. This covers 64K, 2M, and 1G page sizes and allows the debug page-size allocation policy selected at BO creation time to be reflected in page-table mapping behavior.

v3
- BO page-size requirement overrides prior map-state flags
- reword commit message
v4
- address review feedback on XE_VMA_CREATE_MASK dependency
- carry 2M/1G request state in target_leaf_level instead of vma_flags
- propagate target_leaf_level from bind op to VMA state
- avoid using accumulated gpuva.flags as future bind policy input v5
- v5:
- Reword the commit message to match the target_leaf_level-based implementation
- Clarify that BO page-size requirements are propagated through bind-op and VMA state

---
 drivers/gpu/drm/xe/xe_vm.c       | 29 +++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vm_types.h |  9 +++++++++
 2 files changed, 38 insertions(+)
drivers/gpu/drm/xe/xe_vm.c +29 -0
index 080c2fff0e95..dcca70ed9141 100644
@@ -2390,6 +2390,23 @@ static void xe_svm_prefetch_gpuva_ops_fini(struct drm_gpuva_ops *ops)
 	}
 }
 
+static void xe_vma_apply_debug_page_size_flag(struct xe_vma_op *op,
+					      struct xe_bo *bo)
+{
+	if (!bo)
+		return;
+
+	if (!(bo->flags & XE_BO_FLAG_USER))
+		return;
+
+	op->map.target_leaf_level = 0;
+
+	if (bo->flags & XE_BO_FLAG_NEEDS_1G)
+		op->map.target_leaf_level = 2;
+	else if (bo->flags & XE_BO_FLAG_NEEDS_2M)
+		op->map.target_leaf_level = 1;
+}
+
 /*
  * Create operations list from IOCTL arguments, setup operations fields so parse
  * and commit steps are decoupled from IOCTL arguments. This step can fail.
@@ -2485,6 +2502,12 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_vma_ops *vops,
 			op->map.pat_index = pat_index;
 			op->map.invalidate_on_bind =
 				__xe_vm_needs_clear_scratch_pages(vm, flags);
+			/*
+			 * Propagate debug BO page-size requirement into the VMA bind operation
+			 * for user BO binds.
+			 */
+			if (xe_debug_page_size_supported(vm->xe))
+				xe_vma_apply_debug_page_size_flag(op, bo);
 		} else if (__op->op == DRM_GPUVA_OP_PREFETCH) {
 			struct xe_vma *vma = gpuva_to_vma(op->base.prefetch.va);
 			struct xe_tile *tile;
@@ -2848,6 +2871,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
 				if (IS_ERR(vma))
 					return PTR_ERR(vma);
 
+				vma->target_leaf_level = old->target_leaf_level;
+
 				op->remap.prev = vma;
 
 				/*
@@ -2878,6 +2903,8 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
 				if (IS_ERR(vma))
 					return PTR_ERR(vma);
 
+				vma->target_leaf_level = old->target_leaf_level;
+
 				op->remap.next = vma;
 
 				/*
@@ -4762,6 +4789,7 @@ static int xe_vm_alloc_vma(struct xe_vm *vm,
 				 * unmapping.
 				 */
 				op->map.vma_flags |= vma_flags & XE_VMA_CREATE_MASK;
+				op->map.target_leaf_level = vma->target_leaf_level;
 			}
 		}
 		print_op(vm->xe, __op);
@@ -4808,6 +4836,7 @@ static int xe_vm_alloc_vma(struct xe_vm *vm,
 			 */
 			if (is_madvise)
 				xe_vma_mem_attr_copy(&vma->attr, &tmp_attr);
+			vma->target_leaf_level = op->map.target_leaf_level;
 		}
 	}
 
drivers/gpu/drm/xe/xe_vm_types.h +9 -0
index 635ed29b9a69..c94328662dfc 100644
@@ -174,6 +174,13 @@ struct xe_vma {
 	 * and encoding of the PTEs for this vma.
 	 */
 	struct xe_vma_mem_attr attr;
+	/**
+	 * @target_leaf_level: requested PT leaf level for this VMA
+	 *
+	 * 0 for normal 4K/64K mappings, 1 for 2M huge-page mappings,
+	 * and 2 for 1G huge-page mappings.
+	 */
+	u8 target_leaf_level;
 };
 
 /**
@@ -422,6 +429,8 @@ struct xe_vma_op_map {
 	bool request_decompress;
 	/** @pat_index: The pat index to use for this operation. */
 	u16 pat_index;
+	/** @target_leaf_level: requested PT leaf level for this operation */
+	u8 target_leaf_level;
 };
 
 /** struct xe_vma_op_remap - VMA remap operation */
Signature · 1 line
2.43.0
#6 lore raw

PATCH v5 6/7 drm/xe/pt: allow selecting the bind leaf PTE level

In reply to Nareshkumar Gollakoti

Add a target_leaf_level field to the page-table bind walk and use it to control the level at which leaf entries are emitted.

By default, the bind walk emits level-0 leaf PTEs and relies on xe_pt_hugepte_possible() to select huge mappings when possible. Add an explicit target leaf level so the walk can stop earlier when the VMA requests a larger mapping size.

Use level 1 for 2M PDE mappings and level 2 for 1G PDP mappings, while keeping level 0 for normal mappings. The existing huge-page heuristic is preserved for the default level-0 path.

This allows the bind path to emit 2M and 1G leaf entries when requested by the VMA, while still validating alignment and size requirements.

v2
- avoid using max_level to control walk depth
- use target_leaf_level to preserve the normal walk behavior
- keep the default huge-page heuristic only for the level-0 path
- refine commit message

v3
- reword commit message

v4
- allow fallback to smaller huge-page levels for non-zero target_leaf_level
- avoid constraining clear_pt walks by target_leaf_level

v5(Himal)
- Restrict only intended level in debug page size policy mode
- Allow the normal path to proceed smoothly when
no debug page-size mode is selected.

---
 drivers/gpu/drm/xe/xe_pt.c | 53 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +51 -2
index e466f714bf86..a476e9a3860f 100644
@@ -302,6 +302,13 @@ struct xe_pt_stage_bind_walk {
 	bool needs_64K;
 	/** @clear_pt: clear page table entries during the bind walk */
 	bool clear_pt;
+	/** @target_leaf_level: Page-table level at which to emit leaf PTEs
+	 * 0 for normal 4K/64K mappings, 1 for 2M huge pages, and 2 for 1G huge
+	 * pages. The walk still traverses from the root down; this field tells
+	 * xe_pt_stage_bind_entry() to treat the selected level as a leaf instead
+	 * of descending further.
+	 */
+	u32 target_leaf_level;
 	/**
 	 * @vma: VMA being mapped
 	 */
@@ -514,6 +521,37 @@ xe_pt_is_pte_ps64K(u64 addr, u64 next, struct xe_pt_stage_bind_walk *xe_walk)
 	return xe_walk->found_64K;
 }
 
+static bool xe_pt_huge_leaf_allowed(u64 addr, u64 next, unsigned int level,
+				    struct xe_pt_stage_bind_walk *xe_walk)
+{
+	if (xe_walk->clear_pt)
+		return xe_pt_hugepte_possible(addr, next, level, xe_walk);
+
+	if (!xe_debug_page_size_supported(xe_walk->vm->xe))
+		return xe_pt_hugepte_possible(addr, next, level, xe_walk);
+
+	if (!xe_walk->target_leaf_level)
+		return xe_pt_hugepte_possible(addr, next, level, xe_walk);
+
+	if (level == xe_walk->target_leaf_level)
+		return xe_pt_hugepte_possible(addr, next, level, xe_walk);
+
+	return false;
+}
+
+static bool xe_pt_exact_leaf_required_but_invalid(u64 addr, u64 next,
+						  unsigned int level,
+						  struct xe_pt_stage_bind_walk *xe_walk)
+{
+	struct xe_device *xe = xe_walk->vm->xe;
+
+	return !xe_walk->clear_pt &&
+		xe_debug_exact_page_size_mode(xe) &&
+		xe_walk->target_leaf_level &&
+		level == xe_walk->target_leaf_level &&
+		!xe_pt_hugepte_possible(addr, next, level, xe_walk);
+}
+
 static int
 xe_pt_stage_bind_entry(struct xe_ptw *parent, pgoff_t offset,
 		       unsigned int level, u64 addr, u64 next,
@@ -531,8 +569,18 @@ xe_pt_stage_bind_entry(struct xe_ptw *parent, pgoff_t offset,
 	int ret = 0;
 	u64 pte;
 
-	/* Is this a leaf entry ?*/
-	if (level == 0 || xe_pt_hugepte_possible(addr, next, level, xe_walk)) {
+	if (xe_pt_exact_leaf_required_but_invalid(addr, next, level, xe_walk))
+		return -EINVAL;
+
+	/*
+	 * Is this a leaf entry?
+	 * Always create a 4K leaf at level 0. For huge pages (level > 0),
+	 * validate alignment and size with xe_pt_hugepte_possible().
+	 * When target_leaf_level is non-zero, only that huge-page level is
+	 * accepted for normal bind walks. Clear walks remain unconstrained so
+	 * existing huge leaves can be cleared without descending further.
+	 */
+	if (level == 0 || xe_pt_huge_leaf_allowed(addr, next, level, xe_walk)) {
 		struct xe_res_cursor *curs = xe_walk->curs;
 		struct xe_bo *bo = xe_vma_bo(xe_walk->vma);
 		bool is_null_or_purged = xe_vma_is_null(xe_walk->vma) ||
@@ -774,6 +822,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
 		xe_svm_notifier_unlock(vm);
 	}
 
+	xe_walk.target_leaf_level = vma->target_leaf_level;
 	xe_walk.needs_64K = (vm->flags & XE_VM_FLAG_64K);
 	if (clear_pt)
 		goto walk_pt;
Signature · 1 line
2.43.0
#7 lore raw

PATCH v5 7/7 drm/xe/tests: add live KUnit coverage for BO page-size allocation modes

In reply to Nareshkumar Gollakoti

Add live KUnit coverage for the debug-controlled BO page-size allocation modes.

The new tests cover forced 2M mode, forced 1G mode,
and mixed mode. They verify that user BO creation applies the expected NEEDS_* flags, that no unexpected page-size flags are added in the forced modes, that BO size is rounded as expected, and that page_alignment matches the selected leaf size.

The mixed-mode test does not assume a strict per-allocation rotation sequence, since the device-global mixed-mode index may be perturbed by concurrent BO creation on a live system. Instead,
it validates that each allocation results in
one valid mixed-mode page-size outcome.

Treat transient VRAM allocation failures as skipped test cases so the tests can run in varying live environments without producing false failures.

v3
- address review comments
- rework mixed-mode test to avoid assuming strict rotation order
- reword commit message
v4
- skip VRAM-targeted live tests on non-dGFX devices v5
- advance the mixed-mode index in the test

---
 drivers/gpu/drm/xe/tests/xe_bo.c            | 249 ++++++++++++++++++++
 drivers/gpu/drm/xe/tests/xe_live_test_mod.c |   2 +
 2 files changed, 251 insertions(+)
drivers/gpu/drm/xe/tests/xe_bo.c +249 -0
index 49c95ed67d7e..4a5c6a263ab8 100644
@@ -22,6 +22,240 @@
 #include "xe_pci.h"
 #include "xe_pm.h"
 
+struct page_size_alloc_saved {
+	enum xe_page_size_alloc_ctrl_mode mode;
+	u32 cur_index;
+};
+
+/* Caller must hold xe->page_size_alloc_ctrl.lock. */
+static void page_size_alloc_save(struct xe_device *xe,
+				 struct page_size_alloc_saved *s)
+{
+	s->mode = xe->page_size_alloc_ctrl.mode;
+	s->cur_index = xe->page_size_alloc_ctrl.cur_index;
+}
+
+static void page_size_alloc_restore(struct xe_device *xe,
+				    const struct page_size_alloc_saved *s)
+{
+	mutex_lock(&xe->page_size_alloc_ctrl.lock);
+	xe->page_size_alloc_ctrl.mode = s->mode;
+	xe->page_size_alloc_ctrl.cur_index = s->cur_index;
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+}
+
+/* Map a NEEDS_* flag to the expected leaf size and request size. */
+struct leaf_info {
+	u64 leaf;
+	u64 alloc_size;
+	u32 flag;
+	const char *name;
+};
+
+static const struct leaf_info leaf_2m = {
+	.leaf = SZ_2M,
+	.alloc_size = SZ_2M - PAGE_SIZE,
+	.flag = XE_BO_FLAG_NEEDS_2M,
+	.name = "2M",
+};
+
+static const struct leaf_info leaf_1g = {
+	.leaf = SZ_1G,
+	.alloc_size = SZ_1G - PAGE_SIZE,
+	.flag = XE_BO_FLAG_NEEDS_1G,
+	.name = "1G",
+};
+
+static void run_only_leaf(struct kunit *test,
+			  enum xe_page_size_alloc_ctrl_mode mode,
+			  const struct leaf_info *li)
+{
+	struct xe_device *xe = test->priv;
+	struct page_size_alloc_saved saved;
+	struct xe_bo *bo;
+	struct ttm_buffer_object *ttm_bo;
+	u32 other_flags;
+
+	if (!IS_ENABLED(CONFIG_DRM_XE_DEBUG_PAGE_SIZE)) {
+		kunit_skip(test, "CONFIG_DRM_XE_DEBUG_PAGE_SIZE not enabled");
+		return;
+	}
+
+	if (!IS_DGFX(xe)) {
+		kunit_skip(test, "requires dGFX VRAM");
+		return;
+	}
+
+	mutex_lock(&xe->page_size_alloc_ctrl.lock);
+	page_size_alloc_save(xe, &saved);
+	xe->page_size_alloc_ctrl.mode = mode;
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+
+	bo = xe_bo_create_user(xe, NULL, li->alloc_size,
+			       DRM_XE_GEM_CPU_CACHING_WC,
+			       XE_BO_FLAG_VRAM0, NULL);
+	if (IS_ERR(bo)) {
+		page_size_alloc_restore(xe, &saved);
+		if (PTR_ERR(bo) == -ENOSPC) {
+			kunit_skip(test,
+				   "no contiguous %s VRAM available right now",
+				   li->name);
+			return;
+		}
+
+		KUNIT_FAIL(test, "%s BO alloc failed: %pe", li->name, bo);
+		return;
+	}
+
+	ttm_bo = &bo->ttm;
+
+	/* 1) The mode added the right NEEDS_* flag. */
+	KUNIT_EXPECT_TRUE_MSG(test, bo->flags & li->flag,
+			      "%s: flag missing, flags=0x%x",
+			      li->name, bo->flags);
+
+	/* 2) No other NEEDS_* flags accidentally tagged on. */
+	other_flags = (XE_BO_FLAG_NEEDS_64K |
+		       XE_BO_FLAG_NEEDS_2M |
+		       XE_BO_FLAG_NEEDS_1G) & ~li->flag;
+	KUNIT_EXPECT_FALSE_MSG(test, bo->flags & other_flags,
+			       "%s: stray flags=0x%x",
+			       li->name, bo->flags);
+	/* 3) BO size was rounded up to the expected leaf size. */
+	KUNIT_EXPECT_EQ_MSG(test, xe_bo_size(bo), li->leaf,
+			    "%s: bo size=%llu expected=%llu",
+			    li->name,
+			    (u64)xe_bo_size(bo),
+			    (u64)li->leaf);
+	/*
+	 * 4) Allocator honored the requested alignment.
+	 * ttm_bo->page_alignment is stored in PAGE_SIZE units, so compare against
+	 * the expected leaf size converted with >> PAGE_SHIFT.
+	 */
+	KUNIT_EXPECT_EQ_MSG(test, ttm_bo->page_alignment,
+			    li->leaf >> PAGE_SHIFT,
+			    "%s: page_alignment=%u pages expected=%llu pages",
+			    li->name, ttm_bo->page_alignment,
+			    (u64)(li->leaf >> PAGE_SHIFT));
+
+	xe_bo_put(bo);
+	page_size_alloc_restore(xe, &saved);
+}
+
+static void xe_bo_page_size_alloc_only_2m(struct kunit *test)
+{
+	run_only_leaf(test, XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M, &leaf_2m);
+}
+
+static void xe_bo_page_size_alloc_only_1g(struct kunit *test)
+{
+	run_only_leaf(test, XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G, &leaf_1g);
+}
+
+static void xe_bo_page_size_alloc_mixed_bos(struct kunit *test)
+{
+	struct xe_device *xe = test->priv;
+	struct page_size_alloc_saved saved;
+	struct xe_bo *bo;
+	struct ttm_buffer_object *ttm_bo;
+	u32 all_flags = XE_BO_FLAG_NEEDS_64K | XE_BO_FLAG_NEEDS_2M |
+			XE_BO_FLAG_NEEDS_1G;
+	u32 flags;
+	u64 expected_align;
+	int i;
+	const int n = 4;
+
+	if (!IS_ENABLED(CONFIG_DRM_XE_DEBUG_PAGE_SIZE)) {
+		kunit_skip(test, "CONFIG_DRM_XE_DEBUG_PAGE_SIZE not enabled");
+		return;
+	}
+
+	if (!IS_DGFX(xe)) {
+		kunit_skip(test, "requires dGFX VRAM");
+		return;
+	}
+
+	mutex_lock(&xe->page_size_alloc_ctrl.lock);
+	page_size_alloc_save(xe, &saved);
+	xe->page_size_alloc_ctrl.mode = XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED;
+	xe->page_size_alloc_ctrl.cur_index = 0;
+	mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+
+	for (i = 0; i < n; i++) {
+		/*
+		 * Request a size valid for any mixed-mode slot. Since cur_index is
+		 * device-global and may be perturbed by concurrent allocations on
+		 * a live system, do not assume this iteration will see a specific
+		 * slot.
+		 */
+		bo = xe_bo_create_user(xe, NULL, SZ_1G,
+				       DRM_XE_GEM_CPU_CACHING_WC,
+				       XE_BO_FLAG_VRAM0, NULL);
+		if (IS_ERR(bo)) {
+			int err = PTR_ERR(bo);
+
+			page_size_alloc_restore(xe, &saved);
+			if (err == -ENOSPC) {
+				kunit_skip(test,
+					   "mixed mode BO allocation unavailable: %d",
+					   err);
+				return;
+			}
+		KUNIT_FAIL(test, "iter=%d alloc failed: %pe", i, bo);
+		return;
+		}
+
+		mutex_lock(&xe->page_size_alloc_ctrl.lock);
+		xe->page_size_alloc_ctrl.mode = XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED;
+		xe->page_size_alloc_ctrl.cur_index = i;
+		mutex_unlock(&xe->page_size_alloc_ctrl.lock);
+
+		ttm_bo = &bo->ttm;
+		flags = bo->flags & all_flags;
+		/*
+		 * Mixed mode may result in:
+		 * 0-> default/4K
+		 * XE_BO_FLAG_NEEDS_64K
+		 * XE_BO_FLAG_NEEDS_2M
+		 * XE_BO_FLAG_NEEDS_1G
+		 * Any other combination is invalid.
+		 */
+		if (flags == 0) {
+			expected_align = SZ_4K;
+		} else if (flags == XE_BO_FLAG_NEEDS_64K) {
+			expected_align = SZ_64K;
+		} else if (flags == XE_BO_FLAG_NEEDS_2M) {
+			expected_align = SZ_2M;
+		} else if (flags == XE_BO_FLAG_NEEDS_1G) {
+			expected_align = SZ_1G;
+		} else {
+			KUNIT_FAIL(test,
+				   "iter=%d invalid mixed-mode flags: 0x%x",
+				   i, flags);
+			xe_bo_put(bo);
+			page_size_alloc_restore(xe, &saved);
+			return;
+		}
+		/*
+		 * BO size should remain valid for the selected mode. Since the
+		 * request is SZ_1G, it should remain unchanged regardless of the
+		 * selected page-size policy.
+		 */
+		KUNIT_EXPECT_EQ_MSG(test, xe_bo_size(bo), (u64)SZ_1G,
+				    "iter=%d size=%llu expected=%llu",
+				    i,
+				    (u64)xe_bo_size(bo),
+				    (u64)SZ_1G);
+		KUNIT_EXPECT_EQ_MSG(test, ttm_bo->page_alignment,
+				    expected_align >> PAGE_SHIFT,
+				    "iter=%d flags=0x%x page_alignment=%u pages expected=%llu pages",
+				    i, flags, ttm_bo->page_alignment,
+				    (u64)(expected_align >> PAGE_SHIFT));
+		xe_bo_put(bo);
+	}
+	page_size_alloc_restore(xe, &saved);
+}
+
 static int ccs_test_migrate(struct xe_tile *tile, struct xe_bo *bo,
 			    bool clear, u64 get_val, u64 assign_val,
 			    struct kunit *test, struct drm_exec *exec)
@@ -609,6 +843,21 @@ static struct kunit_case xe_bo_tests[] = {
 	{}
 };
 
+static struct kunit_case xe_bo_page_size_alloc_cases[] = {
+	KUNIT_CASE_PARAM(xe_bo_page_size_alloc_only_2m,   xe_pci_live_device_gen_param),
+	KUNIT_CASE_PARAM(xe_bo_page_size_alloc_only_1g,   xe_pci_live_device_gen_param),
+	KUNIT_CASE_PARAM(xe_bo_page_size_alloc_mixed_bos,   xe_pci_live_device_gen_param),
+	{}
+};
+
+VISIBLE_IF_KUNIT
+struct kunit_suite xe_bo_page_size_alloc_suite = {
+	.name = "xe_bo_page_size_alloc",
+	.test_cases = xe_bo_page_size_alloc_cases,
+	.init = xe_kunit_helper_xe_device_live_test_init,
+};
+EXPORT_SYMBOL_IF_KUNIT(xe_bo_page_size_alloc_suite);
+
 VISIBLE_IF_KUNIT
 struct kunit_suite xe_bo_test_suite = {
 	.name = "xe_bo",
drivers/gpu/drm/xe/tests/xe_live_test_mod.c +2 -0
index c55e46f1ae92..3d48a92e1201 100644
@@ -11,6 +11,7 @@ extern struct kunit_suite xe_dma_buf_test_suite;
 extern struct kunit_suite xe_migrate_test_suite;
 extern struct kunit_suite xe_mocs_test_suite;
 extern struct kunit_suite xe_guc_g2g_test_suite;
+extern struct kunit_suite xe_bo_page_size_alloc_suite;
 
 kunit_test_suite(xe_bo_test_suite);
 kunit_test_suite(xe_bo_shrink_test_suite);
@@ -18,6 +19,7 @@ kunit_test_suite(xe_dma_buf_test_suite);
 kunit_test_suite(xe_migrate_test_suite);
 kunit_test_suite(xe_mocs_test_suite);
 kunit_test_suite(xe_guc_g2g_test_suite);
+kunit_test_suite(xe_bo_page_size_alloc_suite);
 
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.43.0
#8 lore raw

✗ CI.checkpatch: warning for drm/xe: add page size allocation mode control and coverage (rev3)

In reply to Nareshkumar Gollakoti
== Series Details ==

== Series Details ==

Series: drm/xe: add page size allocation mode control and coverage (rev3)
URL : https://patchwork.freedesktop.org/series/168905/
State : warning

== Summary ==

+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 061140b9bc586ae7f40abc1249c97e1cc72d1b9d
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 14212074064d448d2cc69d5243c80cbd89ca2b66

Author: Nareshkumar Gollakoti <[email protected]>
Date:   Mon Jul 13 23:46:05 2026 +0530

drm/xe/tests: add live KUnit coverage for BO page-size allocation modes

Add live KUnit coverage for the debug-controlled BO
page-size allocation modes.

The new tests cover forced 2M mode, forced 1G mode,
and mixed mode. They verify that user BO creation applies the expected NEEDS_* flags, that no unexpected page-size flags are added in the forced modes, that BO size is rounded as expected, and that page_alignment matches the selected leaf size.

The mixed-mode test does not assume a strict per-allocation rotation sequence, since the device-global mixed-mode index may be perturbed by concurrent BO creation on a live system. Instead,
it validates that each allocation results in
one valid mixed-mode page-size outcome.

Treat transient VRAM allocation failures as skipped test cases so the tests can run in varying live environments without producing false failures.

v3
- address review comments
- rework mixed-mode test to avoid assuming strict rotation order
- reword commit message
v4
- skip VRAM-targeted live tests on non-dGFX devices v5
- advance the mixed-mode index in the test

+ /mt/dim checkpatch b4ff3505d3eacce720d43e24651ce84f2a0d7f56 drm-intel c249539cb2f0 drm/xe: add page size allocation control state to xe_device 60932a6b8998 drm/xe/debugfs: add page-size allocation mode knob 92ee91c8357d drm/xe: add XE_BO_FLAG_NEEDS_1G for minimum page-size sizing 9b1d0b97a633 drm/xe: apply debug page-size allocation policy to user BOs fcba96e1d0d0 drm/xe/vm: propagate BO page-size requirements to VMA map flags 1493a2ae76ae drm/xe/pt: allow selecting the bind leaf PTE level 14212074064d drm/xe/tests: add live KUnit coverage for BO page-size allocation modes -:312: WARNING:AVOID_EXTERNS: externs should be avoided in .c files #312: FILE: drivers/gpu/drm/xe/tests/xe_live_test_mod.c:14:
+extern struct kunit_suite xe_bo_page_size_alloc_suite;

total: 0 errors, 1 warnings, 0 checks, 275 lines checked

#9 lore raw

✗ CI.KUnit: failure for drm/xe: add page size allocation mode control and coverage (rev3)

In reply to Nareshkumar Gollakoti
== Series Details ==

== Series Details ==

Series: drm/xe: add page size allocation mode control and coverage (rev3)
URL : https://patchwork.freedesktop.org/series/168905/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:In file included from ../drivers/gpu/drm/xe/xe_bo.c:4057:
../drivers/gpu/drm/xe/tests/xe_bo.c:26:43: error: field ‘mode’ has incomplete type
26 | enum xe_page_size_alloc_ctrl_mode mode;
| ^~~~
../drivers/gpu/drm/xe/tests/xe_bo.c: In function ‘page_size_alloc_save’:
../drivers/gpu/drm/xe/tests/xe_bo.c:34:21: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
34 | s->mode = xe->page_size_alloc_ctrl.mode;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:35:26: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
35 | s->cur_index = xe->page_size_alloc_ctrl.cur_index;
| ^~
In file included from ../include/linux/seqlock.h:20,

                 from ../include/linux/mmzone.h:17,
                 from ../include/linux/gfp.h:7,
                 from ../include/linux/mm.h:8,
                 from ../include/linux/pagemap.h:8,
                 from ../include/drm/ttm/ttm_tt.h:30,
                 from ../drivers/gpu/drm/xe/xe_bo.h:9,
                 from ../drivers/gpu/drm/xe/xe_bo.c:6:

../drivers/gpu/drm/xe/tests/xe_bo.c: In function ‘page_size_alloc_restore’:
../drivers/gpu/drm/xe/tests/xe_bo.c:41:23: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
41 | mutex_lock(&xe->page_size_alloc_ctrl.lock);
| ^~
../include/linux/mutex.h:193:44: note: in definition of macro ‘mutex_lock’
193 | #define mutex_lock(lock) mutex_lock_nested(lock, 0)
| ^~~~
../drivers/gpu/drm/xe/tests/xe_bo.c:42:11: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
42 | xe->page_size_alloc_ctrl.mode = s->mode;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:43:11: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
43 | xe->page_size_alloc_ctrl.cur_index = s->cur_index;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:44:25: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
44 | mutex_unlock(&xe->page_size_alloc_ctrl.lock);
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c: At top level:
../drivers/gpu/drm/xe/tests/xe_bo.c:70:61: error: parameter 2 (‘mode’) has incomplete type

   70 |                           enum xe_page_size_alloc_ctrl_mode mode,
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
../drivers/gpu/drm/xe/tests/xe_bo.c:69:13: error: function declaration isn’t a prototype [-Werror=strict-prototypes]
   69 | static void run_only_leaf(struct kunit *test,
      |             ^~~~~~~~~~~~~

../drivers/gpu/drm/xe/tests/xe_bo.c: In function ‘run_only_leaf’:
../drivers/gpu/drm/xe/tests/xe_bo.c:89:23: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
89 | mutex_lock(&xe->page_size_alloc_ctrl.lock);
| ^~
../include/linux/mutex.h:193:44: note: in definition of macro ‘mutex_lock’
193 | #define mutex_lock(lock) mutex_lock_nested(lock, 0)
| ^~~~
../drivers/gpu/drm/xe/tests/xe_bo.c:91:11: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
91 | xe->page_size_alloc_ctrl.mode = mode;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:92:25: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
92 | mutex_unlock(&xe->page_size_alloc_ctrl.lock);
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c: In function ‘xe_bo_page_size_alloc_only_2m’:
../drivers/gpu/drm/xe/tests/xe_bo.c:147:29: error: ‘XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M’ undeclared (first use in this function)

  147 |         run_only_leaf(test, XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M, &leaf_2m);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_bo.c:147:29: note: each undeclared identifier is reported only once for each function it appears in
../drivers/gpu/drm/xe/tests/xe_bo.c: In function ‘xe_bo_page_size_alloc_only_1g’:
../drivers/gpu/drm/xe/tests/xe_bo.c:152:29: error: ‘XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G’ undeclared (first use in this function)
  152 |         run_only_leaf(test, XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G, &leaf_1g);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/gpu/drm/xe/tests/xe_bo.c: In function ‘xe_bo_page_size_alloc_mixed_bos’:
../drivers/gpu/drm/xe/tests/xe_bo.c:178:23: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
178 | mutex_lock(&xe->page_size_alloc_ctrl.lock);
| ^~
../include/linux/mutex.h:193:44: note: in definition of macro ‘mutex_lock’
193 | #define mutex_lock(lock) mutex_lock_nested(lock, 0)
| ^~~~
../drivers/gpu/drm/xe/tests/xe_bo.c:180:11: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
180 | xe->page_size_alloc_ctrl.mode = XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:180:41: error: ‘XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED’ undeclared (first use in this function)

  180 |         xe->page_size_alloc_ctrl.mode = XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED;
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/gpu/drm/xe/tests/xe_bo.c:181:11: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
181 | xe->page_size_alloc_ctrl.cur_index = 0;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:182:25: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
182 | mutex_unlock(&xe->page_size_alloc_ctrl.lock);
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:208:31: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
208 | mutex_lock(&xe->page_size_alloc_ctrl.lock);
| ^~
../include/linux/mutex.h:193:44: note: in definition of macro ‘mutex_lock’
193 | #define mutex_lock(lock) mutex_lock_nested(lock, 0)
| ^~~~
../drivers/gpu/drm/xe/tests/xe_bo.c:209:19: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
209 | xe->page_size_alloc_ctrl.mode = XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:210:19: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
210 | xe->page_size_alloc_ctrl.cur_index = i;
| ^~
../drivers/gpu/drm/xe/tests/xe_bo.c:211:33: error: ‘struct xe_device’ has no member named ‘page_size_alloc_ctrl’
211 | mutex_unlock(&xe->page_size_alloc_ctrl.lock);
| ^~
cc1: some warnings being treated as errors
make[7]: *** [../scripts/Makefile.build:289: drivers/gpu/drm/xe/xe_bo.o] Error 1
make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:549: drivers/gpu/drm/xe] Error 2
make[6]: *** Waiting for unfinished jobs....
make[5]: *** [../scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[4]: *** [../scripts/Makefile.build:549: drivers/gpu] Error 2
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [../scripts/Makefile.build:549: drivers] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [/kernel/Makefile:2184: .] Error 2
make[1]: *** [/kernel/Makefile:248: __sub-make] Error 2
make: *** [Makefile:248: __sub-make] Error 2

[18:22:48] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[18:22:53] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel