Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe: Remove the 256G VRAM limit in the identity map
@ 2026-12-02 17:41 Matthew Brost
  2026-12-02 17:51 ` ✓ CI.KUnit: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Matthew Brost @ 2026-12-02 17:41 UTC (permalink / raw)
  To: intel-xe

Dynamically allocate additional migration VM level-2 pages (1 GB leaf
entries), allowing the identity map to support an arbitrary amount of
VRAM instead of being limited to 256G.

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/xe/xe_migrate.c | 83 ++++++++++++++++++++++++++-------
 1 file changed, 65 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 23575f9dc651..45096d3db817 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -265,7 +265,11 @@ struct xe_migrate {
 #define NUM_PT_SLOTS 48
 #define LEVEL0_PAGE_TABLE_ENCODE_SIZE SZ_2M
 #define MAX_NUM_PTE 512
-#define IDENTITY_OFFSET 256ULL
+/*
+ * VRAM identity map starts at 512GiB, i.e. level-3 PDE 1. Each 512GiB chunk
+ * uses a dedicated level-2 PT, appended after NUM_PT_SLOTS in the PT BO.
+ */
+#define IDENTITY_OFFSET 512ULL
 
 /*
  * Although MI_STORE_DATA_IMM's "length" field is 10-bits, 0x3FE is the largest
@@ -370,9 +374,24 @@ static u64 xe_migrate_vram_ofs(struct xe_device *xe, u64 addr, bool is_comp_pte)
 	return addr + (identity_offset << xe_pt_shift(2));
 }
 
+static u32 xe_migrate_identity_num_l2_pts(struct xe_device *xe)
+{
+	u64 num_gb;
+
+	if (!IS_DGFX(xe))
+		return 0;
+
+	num_gb = DIV_ROUND_UP_ULL(xe_vram_region_actual_physical_size(xe->mem.vram),
+				  SZ_1G);
+	if (GRAPHICS_VER(xe) >= 20 && xe_device_has_flat_ccs(xe))
+		num_gb *= 2;
+
+	return DIV_ROUND_UP_ULL(num_gb, MAX_NUM_PTE);
+}
+
 static void xe_migrate_program_identity(struct xe_device *xe, struct xe_vm *vm, struct xe_bo *bo,
-					u64 map_ofs, u64 vram_offset, u16 pat_index, u64 pt_2m_ofs,
-					u64 pt_4k_ofs)
+					u64 l2_pt_ofs, u64 vram_offset, u16 pat_index,
+					u64 pt_2m_ofs, u64 pt_4k_ofs)
 {
 	struct xe_vram_region *vram = xe->mem.vram;
 	resource_size_t dpa_base = xe_vram_region_dpa_base(vram);
@@ -381,7 +400,8 @@ static void xe_migrate_program_identity(struct xe_device *xe, struct xe_vm *vm,
 	u64 vram_limit = xe_vram_region_usable_size(vram) + dpa_base;
 	u32 level = 2;
 
-	ofs = map_ofs + XE_PAGE_SIZE * level + vram_offset * 8;
+	/* Identity level-2 PTs are contiguous, so this may span several PTs */
+	ofs = l2_pt_ofs + (vram_offset - IDENTITY_OFFSET) * 8;
 	flags = vm->pt_ops->pte_encode_addr(xe, 0, pat_index, level,
 					    true, 0);
 
@@ -434,6 +454,7 @@ static int xe_migrate_pt_bo_alloc(struct xe_tile *tile, struct xe_migrate *m,
 {
 	struct xe_bo *bo, *batch = tile->mem.kernel_bb_pool->bo;
 	u32 num_entries = NUM_PT_SLOTS;
+	u32 num_identity_pts = xe_migrate_identity_num_l2_pts(vm->xe);
 
 	/* Can't bump NUM_PT_SLOTS too high */
 	BUILD_BUG_ON(NUM_PT_SLOTS > SZ_2M/XE_PAGE_SIZE);
@@ -443,8 +464,12 @@ static int xe_migrate_pt_bo_alloc(struct xe_tile *tile, struct xe_migrate *m,
 	/* Need to be sure everything fits in the first PT, or create more */
 	xe_tile_assert(tile, m->batch_base_ofs + xe_bo_size(batch) < SZ_2M);
 
+	/* Level-3 PDE 0 is used for the kernel mappings */
+	xe_tile_assert(tile, num_identity_pts < MAX_NUM_PTE);
+
 	bo = xe_bo_create_pin_map(vm->xe, tile, vm,
-				  num_entries * XE_PAGE_SIZE,
+				  num_entries * XE_PAGE_SIZE +
+				  round_up((u64)num_identity_pts * XE_PAGE_SIZE, SZ_64K),
 				  ttm_bo_type_kernel,
 				  XE_BO_FLAG_VRAM_IF_DGFX(tile) |
 				  XE_BO_FLAG_PAGETABLE, exec);
@@ -469,9 +494,10 @@ static void xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
 	u32 map_ofs, level, i;
 	struct xe_bo *bo = m->pt_bo, *batch = tile->mem.kernel_bb_pool->bo;
 	u64 entry;
+	u64 pt_slots_end = NUM_PT_SLOTS * XE_PAGE_SIZE;
 
 	/* PT44..PT47 reserved for 4K and 2M identity map */
-	u64 l1_pt_ofs = xe_bo_size(bo) - 5 * XE_PAGE_SIZE;
+	u64 l1_pt_ofs = pt_slots_end - 5 * XE_PAGE_SIZE;
 
 	entry = vm->pt_ops->pde_encode_bo(bo, l1_pt_ofs);
 	xe_pt_write(xe, &xe_vm_pt_root(vm, id)->bo->vmap, 0, entry);
@@ -567,15 +593,37 @@ static void xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
 		  | XE_PTE_NULL);
 	m->cleared_mem_ofs = (255ULL << xe_pt_shift(level));
 
-	/* Identity map the entire vram at 256GiB offset */
+	/* Identity map the entire vram at 512GiB offset */
 	if (IS_DGFX(xe)) {
-		u64 pt46_ofs = xe_bo_size(bo) - 2 * XE_PAGE_SIZE;
+		u64 pt44_ofs = pt_slots_end - 4 * XE_PAGE_SIZE;
+		u64 pt45_ofs = pt_slots_end - 3 * XE_PAGE_SIZE;
+		u64 pt46_ofs = pt_slots_end - 2 * XE_PAGE_SIZE;
+		u64 pt47_ofs = pt_slots_end - XE_PAGE_SIZE;
+		u32 num_identity_pts = xe_migrate_identity_num_l2_pts(xe);
 		resource_size_t actual_phy_size = xe_vram_region_actual_physical_size(xe->mem.vram);
+		u64 identity_pts_ofs = pt_slots_end;
+
+		xe_tile_assert(tile, num_level >= 3);
+		xe_tile_assert(tile, xe_bo_size(bo) >= identity_pts_ofs +
+			       (u64)num_identity_pts * XE_PAGE_SIZE);
+
+		/* Hook identity level-2 PTs into level-3 PDEs 1..num_identity_pts */
+		for (i = 0; i < num_identity_pts; i++) {
+			u32 idx = IDENTITY_OFFSET / MAX_NUM_PTE + i;
+
+			entry = vm->pt_ops->pde_encode_bo(bo, identity_pts_ofs +
+							  (u64)i * XE_PAGE_SIZE);
+			if (num_level == 3)
+				xe_pt_write(xe, &xe_vm_pt_root(vm, id)->bo->vmap,
+					    idx, entry);
+			else
+				xe_map_wr(xe, &bo->vmap, map_ofs + XE_PAGE_SIZE * 3 +
+					  idx * 8, u64, entry);
+		}
 
-		u64 pt44_ofs = xe_bo_size(bo) - 4 * XE_PAGE_SIZE;
-		xe_migrate_program_identity(xe, vm, bo, map_ofs, IDENTITY_OFFSET,
-					    pat_index, pt46_ofs, pt44_ofs);
-		xe_assert(xe, actual_phy_size <= (MAX_NUM_PTE - IDENTITY_OFFSET) * SZ_1G);
+		xe_migrate_program_identity(xe, vm, bo, identity_pts_ofs,
+					    IDENTITY_OFFSET, pat_index, pt46_ofs,
+					    pt44_ofs);
 
 		/*
 		 * Identity map the entire vram for compressed pat_index for xe2+
@@ -585,13 +633,10 @@ static void xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
 			u16 comp_pat_index = xe_cache_pat_idx(xe, XE_CACHE_NONE_COMPRESSION);
 			u64 vram_offset = IDENTITY_OFFSET +
 				DIV_ROUND_UP_ULL(actual_phy_size, SZ_1G);
-			u64 pt47_ofs = xe_bo_size(bo) - XE_PAGE_SIZE;
 
-			xe_assert(xe, actual_phy_size <= (MAX_NUM_PTE - IDENTITY_OFFSET -
-							  IDENTITY_OFFSET / 2) * SZ_1G);
-			u64 pt45_ofs = xe_bo_size(bo) - 3 * XE_PAGE_SIZE;
-			xe_migrate_program_identity(xe, vm, bo, map_ofs, vram_offset,
-						    comp_pat_index, pt47_ofs, pt45_ofs);
+			xe_migrate_program_identity(xe, vm, bo, identity_pts_ofs,
+						    vram_offset, comp_pat_index,
+						    pt47_ofs, pt45_ofs);
 		}
 	}
 
@@ -599,6 +644,8 @@ static void xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
 	 * Example layout created above, with root level = 3:
 	 * [PT0...PT7]: kernel PT's for copy/clear; 64 or 4KiB PTE's
 	 * [PT41 = PDE 0] [PT44...PT47 = 4K and 2M vram identity maps]
+	 * [PT48...]: dGPU only, level-2 PTs for the 1GiB vram identity maps,
+	 *            hooked into level-3 PDE 1 onward (512GiB+ VA)
 	 *
 	 * This makes the lowest part of the VM point to the pagetables.
 	 * Hence the lowest 2M in the vm should point to itself, with a few writes
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04  4:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 17:41 [PATCH] drm/xe: Remove the 256G VRAM limit in the identity map Matthew Brost
2026-12-02 17:51 ` ✓ CI.KUnit: success for " Patchwork
2026-12-02 18:24 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-03 14:39 ` ✓ Xe.CI.FULL: " Patchwork
2026-12-04  0:21 ` [PATCH] " Summers, Stuart
2026-12-04  0:28   ` Matthew Brost
2026-12-04  4:10     ` Matthew Brost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox