From: Matthew Brost <matthew.brost@intel.com>
To: "Summers, Stuart" <stuart.summers@intel.com>
Cc: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH] drm/xe: Remove the 256G VRAM limit in the identity map
Date: Thu, 3 Dec 2026 16:28:19 -0800 [thread overview]
Message-ID: <axIJIwm91zFmjaXe@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <7e2844dfecd6b30dfe9b80f576b1f50f58b8f208.camel@intel.com>
On Thu, Dec 03, 2026 at 05:21:33PM -0700, Summers, Stuart wrote:
> At a high level this looks ok to me. I have a couple comments below,
> but I don't quite have time to finish up a couple review details. I'll
> try to get here tonight, otherwise I'll have to respond in the morning
> with a full R-B, assuming the below comments are addressed.
>
> On Wed, 2026-12-02 at 09:41 -0800, Matthew Brost wrote:
> > 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);
>
> Shouldn't this be xe_vram_region_usable_size()? Particularly if we're
> adding the flat ccs size below which was taken off during the vram
> init.
>
Yes, it should be usable. Will fix.
> > + 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),
>
> I know we're doing an assert of this against the MAX_NUM_PTEs above,
> but I'm a little worried about all the rounding you're doing.
>
> Also shouldn't this be ROUND_UP_ULL - oh I see this is type casting
> inside the round_up function so seems ok.
>
ROUND_UP_ULL isn't a macro?
https://elixir.bootlin.com/linux/v7.4-rc2/C/ident/ROUND_UP_ULL
Matt
> Thanks,
> Stuart
>
> > 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
>
next prev parent reply other threads:[~2026-12-04 0:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-04 4:10 ` Matthew Brost
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=axIJIwm91zFmjaXe@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=stuart.summers@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