mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	"Carlos Santa" <carlos.santa@intel.com>,
	"Ryan Neph" <ryanneph@google.com>,
	"Natalie Vock" <nat@pixelcluster.dev>,
	"Arun Pravin" <arunpravin.paneerselvam@amd.com>,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	linux-kernel@vger.kernel.org,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH v6 32/35] drm/xe: Finalize defrag-IOVA moves with post-copy job
Date: Fri, 4 Dec 2026 20:09:25 -0800	[thread overview]
Message-ID: <axOOdXaadIxl3EhP@nvishwa1-desk> (raw)
In-Reply-To: <20261203202352.4153159-33-matthew.brost@intel.com>

On Thu, Dec 03, 2026 at 12:23:49PM -0800, Matthew Brost wrote:
>Wire up end-to-end defrag for IOVA-mapped BOs. A defrag move
>is eligible whenever the destination TT is IOVA mapped. The
>packed-copy step moves only changed pages; the IOVA reservation
>is transferred to the new backing so device-visible addresses
>are preserved, avoiding GPU rebind overhead.
>
>Add xe_bo_defrag_use_iova() to select the IOVA defrag path.
>Add xe_bo_defrag_iova_copy() to drive the move: diff new vs
>stashed old TT, link changed pages packed, blit them, then
>queue a post-copy finalize job.
>
>The finalize job tears down the temporary packed mapping,
>transfers the full old TT reservation to the new one, and
>relinks the copied pages at natural offsets.
>
>Borrowed pages skip the copy and simply adopt the old
>reservation.
>
>Since reservation transfer preserves device-visible addresses,
>xe_bo_trigger_rebind() skips drm_gpuvm_bo_evict() marking for
>dma-fence mode VMs; GPU PTEs stay valid, and exec already waits
>on the kernel fences of all external BOs.
>
>Preempt-fence mode VMs are still marked evicted. For an external
>BO the move's kernel fence lands in the BO's own dma-resv, and
>only the rebind chains it into the VM's dma-resv, which is what
>the preempt rebind worker and xe_vm_add_compute_exec_queue()
>wait on. Defrag targets 3D (dma-fence mode) workloads, so the
>needless rebind of compute VMs is accepted rather than teaching
>the preempt paths to wait on external BO kernel fences.
>
>v5:
> - Assert of move always happens (Sashiko)
> - All call drm_gpuvm_bo_evict a preempt VMs (Sashiko)
>
>Cc: Carlos Santa <carlos.santa@intel.com>
>Cc: Ryan Neph <ryanneph@google.com>
>Cc: Natalie Vock <nat@pixelcluster.dev>
>Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
>Cc: Matthew Auld <matthew.auld@intel.com>
>Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>Cc: Maxime Ripard <mripard@kernel.org>
>Cc: Thomas Zimmermann <tzimmermann@suse.de>
>Cc: David Airlie <airlied@gmail.com>
>Cc: Simona Vetter <simona@ffwll.ch>
>Cc: dri-devel@lists.freedesktop.org
>Cc: linux-kernel@vger.kernel.org
>Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>Signed-off-by: Matthew Brost <matthew.brost@intel.com>

LGTM.
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>

>---
> drivers/gpu/drm/xe/xe_bo.c | 340 +++++++++++++++++++++++++++++++++++--
> 1 file changed, 326 insertions(+), 14 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
>index cc419939dddb..d5d27727c910 100644
>--- a/drivers/gpu/drm/xe/xe_bo.c
>+++ b/drivers/gpu/drm/xe/xe_bo.c
>@@ -16,6 +16,7 @@
> #include <drm/drm_gem_ttm_helper.h>
> #include <drm/drm_managed.h>
> #include <drm/drm_print.h>
>+#include <drm/gpu_scheduler.h>
> #include <drm/ttm/ttm_backup.h>
> #include <drm/ttm/ttm_device.h>
> #include <drm/ttm/ttm_placement.h>
>@@ -28,6 +29,7 @@
> #include <trace/events/gpu_mem.h>
>
> #include "xe_device.h"
>+#include "xe_dep_job_types.h"
> #include "xe_dep_scheduler.h"
> #include "xe_dma_buf.h"
> #include "xe_drm_client.h"
>@@ -573,7 +575,6 @@ static void xe_tt_unaccount_iova(struct xe_device *xe,
>  * @xe_tt->iova_dma_pages[]. Used to (re)derive accounting that exactly matches
>  * the pages a tt is actually mapped with.
>  */
>-__maybe_unused
> static void xe_tt_account_iova_pages(struct xe_device *xe,
> 				     struct xe_ttm_tt *xe_tt)
> {
>@@ -598,7 +599,6 @@ static void xe_tt_unaccount_iova(struct xe_device *xe,
> {
> }
>
>-__maybe_unused
> static void xe_tt_account_iova_pages(struct xe_device *xe,
> 				     struct xe_ttm_tt *xe_tt)
> {
>@@ -905,7 +905,6 @@ struct xe_tt_iova_copy {
>  * differ. Coalesce contiguous changed folios into runs and, for each run,
>  * invoke @fn. Returns the total number of changed pages.
>  */
>-__maybe_unused
> static pgoff_t xe_tt_iova_walk_changed(struct ttm_tt *new_tt,
> 				       struct ttm_tt *old_tt,
> 				       void (*fn)(pgoff_t start, pgoff_t count,
>@@ -954,7 +953,6 @@ struct xe_tt_iova_run_collect {
> };
>
> /* Geometrically grow @arr (element size @elem) to hold at least @need slots. */
>-__maybe_unused
> static int xe_tt_iova_grow(void **arr, unsigned int *cap, unsigned int need,
> 			   size_t elem)
> {
>@@ -977,7 +975,6 @@ static int xe_tt_iova_grow(void **arr, unsigned int *cap, unsigned int need,
> 	return 0;
> }
>
>-__maybe_unused
> static void xe_tt_iova_store_run(pgoff_t start, pgoff_t count, void *arg)
> {
> 	struct xe_tt_iova_run_collect *c = arg;
>@@ -1032,7 +1029,6 @@ static void xe_tt_iova_store_run(pgoff_t start, pgoff_t count, void *arg)
>  *
>  * Return: 0 on success, -ENOMEM on allocation failure.
>  */
>-__maybe_unused
> static int xe_tt_iova_copy_init(struct ttm_tt *new_tt, struct ttm_tt *old_tt,
> 				struct xe_tt_iova_copy *copy)
> {
>@@ -1068,7 +1064,6 @@ static int xe_tt_iova_copy_init(struct ttm_tt *new_tt, struct ttm_tt *old_tt,
>  * xe_tt_iova_copy_fini() - Release a struct xe_tt_iova_copy
>  * @copy: The copy description to release.
>  */
>-__maybe_unused
> static void xe_tt_iova_copy_fini(struct xe_tt_iova_copy *copy)
> {
> 	kfree(copy->runs);
>@@ -1099,7 +1094,6 @@ static void xe_tt_iova_copy_fini(struct xe_tt_iova_copy *copy)
>  * Return: 0 on success, negative error code on failure (any partial linkage is
>  * unwound).
>  */
>-__maybe_unused
> static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt,
> 			       const struct xe_tt_iova_copy *copy)
> {
>@@ -1152,6 +1146,130 @@ static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt,
> 	return ret;
> }
>
>+/**
>+ * struct xe_iova_defrag_job - Post-copy finalize job for an IOVA defrag move.
>+ *
>+ * After the GPU defrag copy into the packed copy-step mapping completes, this
>+ * dependency job runs the CPU-side IOMMU fixups at the point of no failure:
>+ * tear down the temporary packed mapping, then per changed run unlink the old
>+ * pages and link the new pages into the (transferred) reservation at their
>+ * natural offset.
>+ */
>+struct xe_iova_defrag_job {
>+	/** @dep: base generic dependency Xe job. */
>+	struct xe_dep_job dep;
>+	/** @xe: The xe device. */
>+	struct xe_device *xe;
>+	/** @new_tt: The destination tt being finalized (owns the reservation). */
>+	struct ttm_tt *new_tt;
>+	/**
>+	 * @copy_iova: Snapshot of the new tt's temporary IOVA reservation that
>+	 * held the packed copy-step mapping. Destroyed by the job (the new tt
>+	 * itself adopts the old tt's reservation at job creation).
>+	 */
>+	struct dma_iova_state copy_iova;
>+	/** @copy_bytes: Byte length of the packed copy-step mapping. */
>+	size_t copy_bytes;
>+	/** @copy: Changed-page description; the job owns and frees @copy.runs. */
>+	struct xe_tt_iova_copy copy;
>+};
>+
>+static struct dma_fence *xe_iova_defrag_job_run(struct xe_dep_job *dep_job)
>+{
>+	struct xe_iova_defrag_job *job =
>+		container_of(dep_job, typeof(*job), dep);
>+	struct xe_device *xe = job->xe;
>+	struct device *dev = xe->drm.dev;
>+	struct xe_ttm_tt *xe_tt =
>+		container_of(job->new_tt, struct xe_ttm_tt, ttm);
>+	unsigned int r, l;
>+
>+	/*
>+	 * Tear down the temporary packed copy-step mapping and free its
>+	 * reservation. The new tt has already adopted the old tt's full
>+	 * reservation (transferred at job creation), so this only touches the
>+	 * snapshot taken before the transfer.
>+	 *
>+	 * This mapping was the GPU blit's write destination, so tear it down
>+	 * with attrs 0 (not DMA_ATTR_SKIP_CPU_SYNC): for non-coherent or
>+	 * bounced (SWIOTLB) mappings the device->CPU copy-back / cache sync of
>+	 * the freshly copied data happens during unlink, exactly as
>+	 * xe_tt_unmap_iova() does. Skipping it would silently drop the
>+	 * defragmented data on those configs.
>+	 */
>+	dma_iova_destroy(dev, &job->copy_iova, job->copy_bytes,
>+			 DMA_BIDIRECTIONAL, 0);
>+
>+	/*
>+	 * For each changed run, unlink the old pages (still linked from the
>+	 * adopted reservation).
>+	 */
>+	for (r = 0; r < job->copy.nr_runs; r++) {
>+		size_t off = (size_t)job->copy.runs[r].start << PAGE_SHIFT;
>+		size_t len = (size_t)job->copy.runs[r].count << PAGE_SHIFT;
>+
>+		dma_iova_unlink(dev, &xe_tt->iova, off, len,
>+				DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
>+	}
>+
>+	/*
>+	 * Relink the freshly copied new pages from the snapshot captured at job
>+	 * creation. The destination tt's page array may have been mutated (or
>+	 * torn down) by TTM since then, so it is never dereferenced here.
>+	 * Borrowed pages are shared with the old tt and stay correctly linked
>+	 * for free, so the snapshot only covers the changed runs.
>+	 */
>+	for (l = 0; l < job->copy.nr_links; l++) {
>+		int ret = dma_iova_link(dev, &xe_tt->iova,
>+					job->copy.links[l].phys,
>+					job->copy.links[l].offset,
>+					job->copy.links[l].len,
>+					DMA_BIDIRECTIONAL,
>+					DMA_ATTR_SKIP_CPU_SYNC);
>+		/*
>+		 * Point of no failure: the data is already copied and the
>+		 * reservation ownership has been transferred. A relink failure
>+		 * leaves a hole in the mapping; there is no safe recovery, so
>+		 * just warn.
>+		 */
>+		drm_WARN_ON(&xe->drm, ret);
>+	}
>+
>+	/* Sync the relinked changed runs into the device's view. */
>+	for (r = 0; r < job->copy.nr_runs; r++) {
>+		size_t off = (size_t)job->copy.runs[r].start << PAGE_SHIFT;
>+		size_t len = (size_t)job->copy.runs[r].count << PAGE_SHIFT;
>+
>+		/*
>+		 * Point of no failure (as with the relink above): warn on a
>+		 * sync error so a stale IOMMU cache does not fail silently.
>+		 */
>+		drm_WARN_ON(&xe->drm, dma_iova_sync(dev, &xe_tt->iova, off, len));
>+	}
>+
>+	/*
>+	 * All work is synchronous CPU-side IOMMU fixup, so there is no hardware
>+	 * fence to wait on; returning NULL makes the scheduler signal the job's
>+	 * finished fence immediately.
>+	 */
>+	return NULL;
>+}
>+
>+static void xe_iova_defrag_job_free(struct xe_dep_job *dep_job)
>+{
>+	struct xe_iova_defrag_job *job =
>+		container_of(dep_job, typeof(*job), dep);
>+
>+	xe_tt_iova_copy_fini(&job->copy);
>+	drm_sched_job_cleanup(&job->dep.drm);
>+	kfree(job);
>+}
>+
>+static const struct xe_dep_job_ops xe_iova_defrag_job_ops = {
>+	.run_job = xe_iova_defrag_job_run,
>+	.free_job = xe_iova_defrag_job_free,
>+};
>+
> /*
>  * xe_tt_iova_transfer - Transfer a full IOVA reservation old_tt -> new_tt.
>  *
>@@ -1168,7 +1286,6 @@ static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt,
>  * folio walk of the new tt keeps xe->mem.dma_mapped_pages[] exact while the new
>  * mapping lives, rather than carrying the old tt's stale distribution.
>  */
>-__maybe_unused
> static void xe_tt_iova_transfer(struct xe_device *xe,
> 				struct xe_ttm_tt *new_tt,
> 				struct xe_ttm_tt *old_tt)
>@@ -1184,6 +1301,157 @@ static void xe_tt_iova_transfer(struct xe_device *xe,
> 	old_tt->use_iova = false;
> }
>
>+/*
>+ * xe_bo_defrag_iova_copy - Run an IOVA defrag move with a packed copy mapping.
>+ *
>+ * Only the changed (non-borrowed) pages of @new_tt are DMA mapped, packed
>+ * contiguously into the front of its reservation, the GPU copy blits them from
>+ * the old tt at natural offsets, and a post-copy finalize job adopts the old
>+ * tt's full reservation and relinks the changed runs. Returns the finalize
>+ * job's finished fence (the fence the move waits on), or an ERR_PTR on failure
>+ * with all partial state unwound.
>+ */
>+static struct dma_fence *
>+xe_bo_defrag_iova_copy(struct xe_device *xe, struct xe_migrate *migrate,
>+		       struct xe_bo *bo, struct ttm_resource *old_mem,
>+		       struct ttm_resource *new_mem, struct ttm_tt *old_tt,
>+		       bool handle_system_ccs)
>+{
>+	struct ttm_tt *new_tt = bo->ttm.ttm;
>+	struct xe_ttm_tt *new_xe_tt = container_of(new_tt, struct xe_ttm_tt, ttm);
>+	struct xe_ttm_tt *old_xe_tt = container_of(old_tt, struct xe_ttm_tt, ttm);
>+	struct drm_sched_entity *entity =
>+		xe_dep_scheduler_entity(xe->mem.defrag.iova_sched);
>+	struct xe_iova_defrag_job *job;
>+	struct dma_fence *copy_fence;
>+	struct dma_fence *fence;
>+	struct xe_tt_iova_copy copy;
>+	int err;
>+
>+	xe_assert(xe, new_xe_tt->iova_eligible && !new_xe_tt->use_iova);
>+	xe_assert(xe, old_xe_tt->use_iova && old_xe_tt->iova_linked);
>+
>+	err = xe_tt_iova_copy_init(new_tt, old_tt, &copy);
>+	if (err)
>+		return ERR_PTR(err);
>+
>+	/*
>+	 * TTM fails a defrag move that (re)allocates no chunk, so at least one
>+	 * page always differs from the old tt.
>+	 */
>+	if (XE_WARN_ON(!copy.nr_changed)) {
>+		err = -EINVAL;
>+		goto err_copy;
>+	}
>+
>+	err = xe_tt_map_iova_copy(xe, new_tt, &copy);
>+	if (err)
>+		goto err_copy;
>+
>+	copy_fence = xe_migrate_copy_defrag_iova(migrate, bo, old_mem, new_mem,
>+						 old_tt, copy.nr_changed,
>+						 handle_system_ccs);
>+	if (IS_ERR(copy_fence)) {
>+		err = PTR_ERR(copy_fence);
>+		goto err_unmap;
>+	}
>+
>+	job = kzalloc(sizeof(*job), GFP_KERNEL);
>+	if (!job) {
>+		err = -ENOMEM;
>+		goto err_fence;
>+	}
>+
>+	job->dep.ops = &xe_iova_defrag_job_ops;
>+	job->xe = xe;
>+	job->new_tt = new_tt;
>+	job->copy_iova = new_xe_tt->iova;
>+	job->copy_bytes = (size_t)copy.nr_changed << PAGE_SHIFT;
>+	job->copy = copy;
>+
>+	err = drm_sched_job_init(&job->dep.drm, entity, 1, NULL, 0);
>+	if (err)
>+		goto err_job;
>+
>+	err = drm_sched_job_add_dependency(&job->dep.drm,
>+					   dma_fence_get(copy_fence));
>+	if (err)
>+		goto err_job_init;
>+
>+	/*
>+	 * Point of no failure: transfer the old tt's full reservation to the
>+	 * new tt. The finalize job (already armed below) destroys the packed
>+	 * copy mapping snapshot and relinks the changed runs.
>+	 */
>+	xe_tt_iova_transfer(xe, new_xe_tt, old_xe_tt);
>+	memset(&copy, 0, sizeof(copy)); /* ownership moved to the job */
>+
>+	drm_sched_job_arm(&job->dep.drm);
>+	fence = dma_fence_get(&job->dep.drm.s_fence->finished);
>+	drm_sched_entity_push_job(&job->dep.drm);
>+
>+	dma_fence_put(copy_fence);
>+
>+	return fence;
>+
>+err_job_init:
>+	drm_sched_job_cleanup(&job->dep.drm);
>+err_job:
>+	kfree(job);
>+err_fence:
>+	/*
>+	 * The GPU copy into the packed destination mapping was already
>+	 * submitted; it must finish before we tear that mapping down below,
>+	 * otherwise the blit would fault or scribble on unmapped IOVA. (Reached
>+	 * only with a valid, submitted copy_fence; the IS_ERR(copy_fence) case
>+	 * jumps straight to err_unmap with no GPU work in flight.)
>+	 */
>+	dma_fence_wait(copy_fence, false);
>+	dma_fence_put(copy_fence);
>+err_unmap:
>+	dma_iova_unlink(xe->drm.dev, &new_xe_tt->iova, 0,
>+			(size_t)copy.nr_changed << PAGE_SHIFT,
>+			DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
>+	dma_iova_free(xe->drm.dev, &new_xe_tt->iova);
>+	new_xe_tt->use_iova = false;
>+err_copy:
>+	xe_tt_iova_copy_fini(&copy);
>+	return ERR_PTR(err);
>+}
>+
>+/*
>+ * xe_bo_defrag_use_iova - Whether a defrag move should use the packed IOVA path.
>+ *
>+ * Eligible when the move is a defrag (stashed old tt) and the destination tt is
>+ * IOVA mapped. The IOVA reservation is transferred to the new backing, so the
>+ * device-visible addresses are preserved and no GPU rebind is needed (see
>+ * xe_bo_trigger_rebind()); this makes the path worthwhile regardless of BO
>+ * size. A flat-CCS aux pass, if needed, is migrated packed alongside the data
>+ * (changed pages only), so it does not disqualify the path. Otherwise the
>+ * full-mapping defrag path is used.
>+ */
>+static bool xe_bo_defrag_use_iova(struct ttm_buffer_object *ttm_bo)
>+{
>+	struct xe_ttm_tt *xe_tt, *old_xe_tt;
>+
>+	if (!ttm_bo->defrag_old_tt || !ttm_bo->ttm)
>+		return false;
>+
>+	xe_tt = container_of(ttm_bo->ttm, struct xe_ttm_tt, ttm);
>+	old_xe_tt = container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm);
>+
>+	/*
>+	 * The old tt must hold a live IOVA mapping (the packed copy reads its
>+	 * IOVA and the finalize job transfers its reservation to the new tt),
>+	 * and the new tt must be eligible to take the temporary copy-step
>+	 * reservation. Eligibility is a deterministic per-device decision taken
>+	 * at tt creation, so for a given BO the old and new tt always agree;
>+	 * the explicit old-tt check guards against ever routing a sg-fallback
>+	 * old tt into xe_tt_iova_transfer() (which would copy an invalid iova).
>+	 */
>+	return xe_tt->iova_eligible && old_xe_tt->use_iova;
>+}
>+
> /*
>  * Account ttm pages against the device shrinker's shrinkable and
>  * purgeable counts.
>@@ -1570,6 +1838,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
> 	struct drm_gem_object *obj = &bo->ttm.base;
> 	struct drm_gpuvm_bo *vm_bo;
> 	bool idle = false;
>+	bool defrag_iova;
> 	int ret = 0;
>
> 	dma_resv_assert_held(bo->ttm.base.resv);
>@@ -1582,18 +1851,48 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
> 		dma_resv_iter_end(&cursor);
> 	}
>
>+	/*
>+	 * A defrag move that reallocates IOVA-mapped backing preserves the
>+	 * device-visible addresses: the IOVA reservation is transferred from
>+	 * the old to the new tt, so the existing GPU PTEs stay valid and the
>+	 * BO must not be marked evicted (the rebind paths in xe_exec_ioctl()
>+	 * and preempt_rebind_work_func() would otherwise needlessly rebind).
>+	 * Preempt fences still need to be triggered, and fault-mode / L2
>+	 * flush-optimized configs still need a TLB invalidation below, so only
>+	 * the eviction marking is skipped (except on L2 flush-optimized HW,
>+	 * where that invalidation zaps the PTEs of a dma-resv VM).
>+	 *
>+	 * Preempt-fence mode VMs are still marked evicted: for an external BO
>+	 * the move's kernel fence lands in the BO's own dma-resv, which only
>+	 * the rebind (chaining it into the VM's dma-resv) makes
>+	 * preempt_rebind_work_func() and xe_vm_add_compute_exec_queue() wait
>+	 * for. Defrag targets 3D (dma-fence mode) workloads, whose exec waits
>+	 * on the kernel fences of all external BOs, so the needless rebind of
>+	 * compute VMs is accepted rather than teaching the preempt paths to
>+	 * wait as well.
>+	 */
>+	defrag_iova = xe_bo_defrag_use_iova(&bo->ttm);
>+
> 	drm_gem_for_each_gpuvm_bo(vm_bo, obj) {
> 		struct xe_vm *vm = gpuvm_to_vm(vm_bo->vm);
> 		struct drm_gpuva *gpuva;
>
> 		if (!xe_vm_in_fault_mode(vm)) {
>-			drm_gpuvm_bo_evict(vm_bo, true);
>+			if (!defrag_iova || xe_vm_in_preempt_fence_mode(vm))
>+				drm_gpuvm_bo_evict(vm_bo, true);
> 			/*
> 			 * L2 cache may not be flushed, so ensure that is done in
> 			 * xe_vm_invalidate_vma() below
> 			 */
> 			if (!xe_device_is_l2_flush_optimized(xe))
> 				continue;
>+
>+			/*
>+			 * The invalidation below zaps the PTEs, so a defrag-IOVA
>+			 * BO must be rebound after all.
>+			 */
>+			if (defrag_iova && !xe_vm_in_preempt_fence_mode(vm))
>+				drm_gpuvm_bo_evict(vm_bo, true);
> 		}
>
> 		if (!idle) {
>@@ -2506,6 +2805,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
> 	bool has_defrag_old_tt = !!ttm_bo->defrag_old_tt;
> 	bool handle_system_ccs = (!IS_DGFX(xe) && xe_bo_needs_ccs_pages(bo) &&
> 				  ttm && ttm_tt_is_populated(ttm)) ? true : false;
>+	bool defrag_iova = xe_bo_defrag_use_iova(ttm_bo);
> 	int ret = 0;
>
> 	/*
>@@ -2578,7 +2878,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
> 	needs_clear = (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) ||
> 		(!ttm && ttm_bo->type == ttm_bo_type_device);
>
>-	if (new_mem->mem_type == XE_PL_TT) {
>+	/*
>+	 * For a defrag move using the packed IOVA path the destination tt is
>+	 * not fully mapped here; only the changed pages are mapped (packed) for
>+	 * the copy, and the finalize job establishes the full mapping.
>+	 */
>+	if (new_mem->mem_type == XE_PL_TT && !defrag_iova) {
> 		ret = xe_tt_map(xe, ttm);
> 		if (ret)
> 			goto out;
>@@ -2711,9 +3016,16 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
> 		fence = xe_migrate_clear(migrate, bo, new_mem, flags,
> 					 ctx->interruptible);
> 	} else if (has_defrag_old_tt) {
>-		fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem,
>-					       ttm_bo->defrag_old_tt,
>-					       handle_system_ccs);
>+		if (defrag_iova)
>+			fence = xe_bo_defrag_iova_copy(xe, migrate, bo, old_mem,
>+						       new_mem,
>+						       ttm_bo->defrag_old_tt,
>+						       handle_system_ccs);
>+		else
>+			fence = xe_migrate_copy_defrag(migrate, bo, old_mem,
>+						       new_mem,
>+						       ttm_bo->defrag_old_tt,
>+						       handle_system_ccs);
> 	} else {
> 		fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem,
> 					handle_system_ccs, ctx->interruptible);
>-- 
>2.34.1
>

      reply	other threads:[~2026-12-05  4:09 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261203202352.4153159-1-matthew.brost@intel.com>
2026-12-03 20:23 ` [PATCH v6 01/35] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-12-03 20:23 ` [PATCH v6 02/35] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-12-04 13:12   ` Natalie Vock
2026-12-04 17:36     ` Matthew Brost
2026-12-03 20:23 ` [PATCH v6 03/35] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-12-04 13:16   ` Natalie Vock
2026-12-03 20:23 ` [PATCH v6 04/35] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-12-04 13:39   ` Natalie Vock
2026-12-03 20:23 ` [PATCH v6 05/35] drm/ttm: Support defragmentation moves Matthew Brost
2026-12-04 14:04   ` Natalie Vock
2026-12-04 19:17     ` Matthew Brost
2026-12-03 20:23 ` [PATCH v6 06/35] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-12-03 20:23 ` [PATCH v6 07/35] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore Matthew Brost
2026-12-03 21:00   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 08/35] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-12-03 23:11   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 09/35] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-03 20:23 ` [PATCH v6 10/35] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-12-04  2:37   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 11/35] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-12-04  3:39   ` Niranjana Vishwanathapura
2026-12-04  4:20     ` Matthew Brost
2026-12-03 20:23 ` [PATCH v6 14/35] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-12-04 20:00   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 15/35] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-12-03 20:23 ` [PATCH v6 16/35] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-12-04  4:54   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 17/35] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-12-04 21:13   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 18/35] drm/xe: Add a page defragmentation worker Matthew Brost
2026-12-04 21:22   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 19/35] drm/xe: Add defrag GT stats Matthew Brost
2026-12-03 20:23 ` [PATCH v6 20/35] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-12-03 20:23 ` [PATCH v6 21/35] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-12-04 21:33   ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 22/35] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-03 20:23 ` [PATCH v6 23/35] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-03 20:23 ` [PATCH v6 24/35] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-12-03 20:23 ` [PATCH v6 25/35] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-12-03 20:23 ` [PATCH v6 28/35] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-12-04 11:57   ` Matthew Auld
2026-12-03 20:23 ` [PATCH v6 29/35] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-12-03 20:23 ` [PATCH v6 30/35] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-12-03 20:23 ` [PATCH v6 31/35] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-12-04 15:39   ` Matthew Auld
2026-12-03 20:23 ` [PATCH v6 32/35] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
2026-12-05  4:09   ` Niranjana Vishwanathapura [this message]

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=axOOdXaadIxl3EhP@nvishwa1-desk \
    --to=niranjana.vishwanathapura@intel.com \
    --cc=airlied@gmail.com \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=carlos.santa@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthew.auld@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=mripard@kernel.org \
    --cc=nat@pixelcluster.dev \
    --cc=ryanneph@google.com \
    --cc=simona@ffwll.ch \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tzimmermann@suse.de \
    /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

all inboxes | Powered by JetHome®