From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398798; b=FatZ4/njYFqNmZmOVSu/wazdlYvNxTkzoIoIrDhzUaECHC411IKGxhENiUEM8hCuCQ9n wiym17u8cAM84QB7+mVfsUwoi/5LT4tMKR8l1a66j/YCDDxDxuT/4BXTaMA3vlmrnPPvZ E7oCmjpYGPYpEh2njUgrz5X+O66kKmvHT/b5lYJfORDG1UrUi4VbWXWCDfH5XDhvDLGNA UhcEF4c0wrabqpNwq5+olLw4DgbtJPc29aZ02mRLqOjLg7RVaJCjAkBmziwpjsZHsOmp/ kAsZdZWn4dOgO0PzxW5PfDOPcMVVjpfUSiCKMuwSXWsHMdp6URRwrX3khXu3xE7/XVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398798; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=YmwLudIFMh+L5MNj+tofm73YqndVYsMmyRI3pVzsgC0=; b=4e7nu/zRIj9lONFImJ8IQQP8YUQaYG1M0JTJvESsIUPqUvudNmonlshs1ejl6H8NoNeI JcIr7Xfv2RfAJBb0uC98ZKr0YXBmWvHtCWvJFsT+qJsFaU7ebBl4svxxQ7qOTfI89OC7L aKys6oICtd2rTKo9/tXSB15uYvvkz5RlOfPUbca592chzHqDjgIOTWjop+W5U9tchepH9 cV29tuBTXfaTe2dfJLxZSpKtM0kW5kVnAo6OUXsEIPKNK2QV2inRf1LtvH8cf4BNGkQhh 127ikOhkdhnK1Hh58AnIFi0eiy+k9nni2yKZTyys3wp1dE3+CaBbh21EJ3pdv3W0ipQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YNa7v528; arc=none smtp.remote-ip=192.198.163.4 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.4]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 423A6606A322 for ; Fri, 4 Dec 2026 15:39:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 423A6606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YNa7v528 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796398797; x=1827934797; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=8IDJoK8mKEoq5XLHI9/56gscQ/c61KCXHrztLlg/Dxc=; b=YNa7v528voFrweOsjCq1yIxj4vjGm6pqnLSjFPbXIj2D7yEqGsJN7hcm sDoxDKSGyyrN7CrWOOhUHIWu2xsCeut4Dej+cdUkPoydnylxHqvx6SqGp /0UmX5Im9spNixP3VUDknVvRH1vjXujZygfVI52I9Pd7o30KlASQS/JmC BRdC+9IbRnO6vSJ5wOX9dlO6LLoMW6SzGp+/3ScQutnn6ySYIKYQu8DzU szB37pHFfO54CiOUpEbJvmwuHQvDO7Ybj2msfUlU00eL52kBtQfsRwGvj SlkehBQhzJYulN0g164LEdHItzwf+G7u3y/28oBZTYaLdzSKFHZWdeivA w==; X-CSE-ConnectionGUID: CEN2oRO8QNidaabyXQTqiQ== X-CSE-MsgGUID: 1C4Df8q7RZe6En81QtexeQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="137259" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="137259" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa114.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 07:39:45 -0800 X-CSE-ConnectionGUID: zR+lzSvqRTCrjIsU5oW0dQ== X-CSE-MsgGUID: eXohXc6mSoSXJ15qsdSW0w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="13974794" Received: from conormcd-mobl2.ger.corp.intel.com (HELO [10.245.245.12]) ([10.245.245.12]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 07:39:42 -0800 Message-ID: Date: Fri, 4 Dec 2026 15:39:39 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 31/35] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies To: Matthew Brost , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Carlos Santa , Ryan Neph , Natalie Vock , Arun Pravin , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , linux-kernel@vger.kernel.org, =?UTF-8?Q?Thomas_Hellstr=C3=B6m?= References: <20261203202352.4153159-1-matthew.brost@intel.com> <20261203202352.4153159-32-matthew.brost@intel.com> Content-Language: en-GB From: Matthew Auld In-Reply-To: <20261203202352.4153159-32-matthew.brost@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 03/12/2026 20:23, Matthew Brost wrote: > A defrag move with IOVA enabled only DMA-maps the changed (non-borrowed) > pages of the new tt, packed contiguously into the front of its IOVA > reservation (xe_tt_map_iova_copy()). The GPU copy therefore has an > asymmetric geometry: the source is read from the old tt at its natural > page offsets (via the old tt's full IOVA), while the destination only > exposes the changed pages, packed. > > Teach __xe_migrate_copy() about this packed-destination mode: > > - Add a @dst_packed_pages argument. When non-zero the destination tt > cursor walks just that many packed pages and the source (not the > destination) drives the chunk size, so the smaller packed prefix never > clamps the source walk. > > - Size the destination PTE update for each chunk from the changed-page > count (xe_migrate_count_changed_pages()) rather than the full chunk. > Leading borrowed pages of each chunk are skipped up front > (xe_migrate_leading_borrowed_pages()) so every emitted chunk starts > on a changed page and has a non-empty packed destination. > > - Extend emit_copy_chunks() with a @pack_dst flag so each emitted run is > blitted from its natural source offset into a running packed > destination offset that only advances for changed runs, and with a > @ccs flag so the same runs can be emitted as indirect -> indirect CCS > aux copies. > > Expose this via xe_migrate_copy_defrag_iova(). When the BO has flat-CCS > state a second pass migrates the aux state of the changed runs through > their (packed) data mappings with the compression PAT set. The aux > state follows the physical page, and borrowed pages share the same > physical page on both sides, so they are skipped in both passes. > xe_migrate_copy_defrag() becomes a wrapper passing a zero packed page > count, i.e. a fully mapped destination, and remains the path for the > non-IOVA fallback. > > No users yet; xe_bo_move() is wired to this path in a later patch. > > v4: > - Remove some now dead code (Niranjana) > > Cc: Carlos Santa > Cc: Ryan Neph > Cc: Natalie Vock > Cc: Arun Pravin > Cc: Matthew Auld > Cc: Maarten Lankhorst > Cc: Maxime Ripard > Cc: Thomas Zimmermann > Cc: David Airlie > Cc: Simona Vetter > Cc: dri-devel@lists.freedesktop.org > Cc: linux-kernel@vger.kernel.org > Cc: Thomas Hellström > Signed-off-by: Matthew Brost > --- > drivers/gpu/drm/xe/xe_migrate.c | 251 ++++++++++++++++++++++++++++---- > drivers/gpu/drm/xe/xe_migrate.h | 8 + > 2 files changed, 230 insertions(+), 29 deletions(-) > > diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c > index 6f88aa210ec3..d6c6ef17d4d9 100644 > --- a/drivers/gpu/drm/xe/xe_migrate.c > +++ b/drivers/gpu/drm/xe/xe_migrate.c > @@ -1228,6 +1228,64 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb, > emit_xy_fast_copy(gt, bb, src_ofs, dst_ofs, size, pitch); > } > > +/* > + * xe_migrate_count_changed_pages() - Count non-borrowed pages in a defrag chunk. > + * @src_tt: Source (old) tt providing the page pointers. > + * @dst_tt: Destination (new) tt providing the page pointers. > + * @start_page: Page offset of this L0 chunk within the tt page arrays. > + * @npages: Number of pages in the L0 chunk. > + * > + * A defragmentation move may harvest already beneficial-order chunks from the > + * old tt, so the new tt references (borrows) some of the same physical pages. > + * Count the pages that actually differ (src page != dst page) within the chunk. > + * > + * Return: The number of non-borrowed (changed) pages. > + */ > +static u32 xe_migrate_count_changed_pages(struct ttm_tt *src_tt, > + struct ttm_tt *dst_tt, > + pgoff_t start_page, u32 npages) > +{ > + u32 i, nchg = 0; > + > + for (i = 0; i < npages; i++) > + if (src_tt->pages[start_page + i] != > + dst_tt->pages[start_page + i]) > + nchg++; > + > + return nchg; > +} > + > +/* > + * xe_migrate_leading_borrowed_pages() - Count the run of borrowed pages at the > + * head of the remaining copy. > + * @src_tt: Source (old) tt providing the page pointers. > + * @dst_tt: Destination (new) tt providing the page pointers. > + * @start_page: Page offset of the next page to copy within the tt page arrays. > + * @max_pages: Pages left to copy. > + * > + * A defragmentation move borrows the already beneficial-order chunks from the > + * old tt, so the new tt references (borrows) the same physical pages for the > + * unchanged majority of a large object. Those pages alias on both the source > + * and destination GPU mappings and need no copy. Count how many consecutive > + * pages starting at @start_page are borrowed so the caller can advance past the > + * whole run at once instead of rediscovering it one L0 chunk at a time. > + * > + * Return: The number of leading borrowed (src page == dst page) pages, capped > + * at @max_pages. > + */ > +static u32 xe_migrate_leading_borrowed_pages(struct ttm_tt *src_tt, > + struct ttm_tt *dst_tt, > + pgoff_t start_page, u32 max_pages) > +{ > + u32 n = 0; > + > + while (n < max_pages && > + src_tt->pages[start_page + n] == dst_tt->pages[start_page + n]) > + n++; > + > + return n; > +} > + > /* > * emit_copy_chunks() - Emit the data blits for one defrag chunk, skipping > * borrowed pages. > @@ -1239,6 +1297,11 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb, > * @src_tt: Source (old) tt providing the page pointers. > * @dst_tt: Destination (new) tt providing the page pointers. > * @start_page: Page offset of this chunk within the tt page arrays. > + * @pack_dst: If true the destination only maps the changed pages packed > + * contiguously, so the destination offset advances by changed-page > + * runs instead of tracking the source page index. > + * @ccs: If true emit indirect -> indirect CCS aux copies instead of data > + * blits. Requires @pack_dst. > * > * A defragmentation move may harvest already beneficial-order chunks from the > * old tt, so the new tt references (borrows) some of the same physical pages. > @@ -1247,16 +1310,27 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb, > * only blit runs of pages that actually differ (src page != dst page), > * coalescing contiguous to-copy pages into a single blit. > * > - * Return: The number of blits emitted (or that would be emitted when @bb is > + * When @pack_dst is set the source pages are read from their natural offsets > + * (@src_ofs + page index) while the destination pages were packed into a > + * contiguous prefix, so the destination offset is a running counter that only > + * advances for emitted (changed) runs. > + * > + * When @ccs is set the same runs are used for the packed defrag CCS pass. The > + * flat-CCS aux state is migrated indirectly through the data-page mappings, so > + * it follows the physical page regardless of the (packed) GPU VA layout. > + * Borrowed pages alias the same physical page on both sides, so their aux is > + * already identical and is skipped as well. > + * > + * Return: The number of copies emitted (or that would be emitted when @bb is > * NULL). > */ > static u32 emit_copy_chunks(struct xe_gt *gt, struct xe_bb *bb, > u64 src_ofs, u64 dst_ofs, u32 src_bytes, > struct ttm_tt *src_tt, struct ttm_tt *dst_tt, > - pgoff_t start_page) > + pgoff_t start_page, bool pack_dst, bool ccs) > { > u32 npages = src_bytes >> PAGE_SHIFT; > - u32 i = 0, nblits = 0; > + u32 i = 0, pack = 0, nblits = 0; > > while (i < npages) { > u32 run = 0; > @@ -1274,11 +1348,18 @@ static u32 emit_copy_chunks(struct xe_gt *gt, struct xe_bb *bb, > dst_tt->pages[start_page + i + run]) > run++; > > - if (bb) > + if (bb && ccs) > + emit_copy_ccs(gt, bb, > + dst_ofs + (u64)pack * PAGE_SIZE, true, > + src_ofs + (u64)i * PAGE_SIZE, true, > + run * PAGE_SIZE); > + else if (bb) > emit_copy(gt, bb, src_ofs + (u64)i * PAGE_SIZE, > - dst_ofs + (u64)i * PAGE_SIZE, > + dst_ofs + > + (u64)(pack_dst ? pack : i) * PAGE_SIZE, > run * PAGE_SIZE, XE_PAGE_SIZE); > nblits++; > + pack += run; > i += run; > } > > @@ -1388,6 +1469,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > struct ttm_resource *src, > struct ttm_resource *dst, > struct ttm_tt *src_tt, > + pgoff_t dst_packed_pages, > enum xe_migrate_copy_mode mode, > bool intr) > { > @@ -1425,6 +1507,23 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > */ > struct ttm_tt *dst_tt = dst_bo->ttm.ttm; > bool skip_borrowed = defrag_copy; > + /* > + * Defrag-IOVA copy: the destination tt only maps the changed > + * (non-borrowed) pages, packed contiguously into the first > + * @dst_packed_pages pages of its IOVA. The source is read from the old > + * tt at natural offsets and each changed run is blitted into the packed > + * destination prefix. > + */ > + bool pack_dst = dst_packed_pages != 0; > + /* > + * Packed defrag CCS pass: migrate the flat-CCS aux state of the changed > + * pages only, from the source at its natural offset to the destination > + * packed prefix. Borrowed pages share the physical page (and thus its > + * aux) on both sides, so they are skipped exactly like the data pass. > + */ > + bool ccs_pack = defrag_ccs && pack_dst; > + /* Per-run, borrowed-skipping defrag emission (data or packed CCS). */ > + bool defrag_runs = skip_borrowed || ccs_pack; > > /* > * For decompression operation, always use the compression PAT index. > @@ -1456,7 +1555,9 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > else > xe_res_first(src, 0, size, &src_it); > if (!dst_is_vram && dst->mem_type != XE_PL_STOLEN) > - xe_res_first_tt(dst_bo->ttm.ttm, 0, size, &dst_it); > + xe_res_first_tt(dst_bo->ttm.ttm, 0, > + pack_dst ? (u64)dst_packed_pages << PAGE_SHIFT : > + size, &dst_it); > else > xe_res_first(dst, 0, size, &dst_it); > > @@ -1477,29 +1578,84 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > u32 pte_flags; > pgoff_t start_page = (xe_bo_size(src_bo) - size) >> PAGE_SHIFT; > u32 ndata_blits = 1; > + u32 nchg = 0; > + u64 dst_size; > > bool usm = xe->info.has_usm; > u32 avail_pts = max_mem_transfer_per_pass(xe) / LEVEL0_PAGE_TABLE_ENCODE_SIZE; For the pure data copy pass there is no CCS involved so we maybe no need to cap this at 4M on lnl+ ? For __xe_migrate_copy() wondering if it might make sense to split out the defrag stuff into its own function? __xe_migrate_copy() is even harder to follow now, with all the different flows in there. Reviewed-by: Matthew Auld > > + /* > + * Defrag fast-forward: the new (destination) tt borrows the > + * unchanged beneficial-order chunks from the old tt, so for a > + * large object the bulk of the copy is borrowed pages that alias > + * the same memory on both sides. Skip the entire leading > + * borrowed run in a single cursor stride rather than discovering > + * it one (8 MB) L0 chunk at a time - each such pass would > + * otherwise pay xe_migrate_res_sizes() + pte_update_size() + a > + * full chunk walk only to copy nothing. The non-vram tt cursors > + * are normally advanced by emit_pte(); replicate that with > + * xe_res_next(). In pack_dst mode the destination only maps the > + * changed pages, so its cursor must not advance for borrowed > + * pages. > + */ > + if (defrag_runs) { > + u32 brun = xe_migrate_leading_borrowed_pages(src_tt, > + dst_tt, > + start_page, > + size >> PAGE_SHIFT); > + > + if (brun) { > + u64 brun_bytes = (u64)brun << PAGE_SHIFT; > + > + xe_res_next(&src_it, brun_bytes); > + if (!pack_dst) > + xe_res_next(&dst_it, brun_bytes); > + size -= brun_bytes; > + continue; > + } > + } > + > src_L0 = xe_migrate_res_sizes(m, &src_it); > dst_L0 = xe_migrate_res_sizes(m, &dst_it); > > drm_dbg(&xe->drm, "Pass %u, sizes: %llu & %llu\n", > pass++, src_L0, dst_L0); > > - src_L0 = min(src_L0, dst_L0); > + /* > + * In pack_dst mode the destination is the (smaller) packed > + * prefix, so it must not clamp the source chunk size; the > + * source drives the walk and the destination is sized > + * independently from the changed-page count below. > + */ > + if (!pack_dst) > + src_L0 = min(src_L0, dst_L0); > > pte_flags = src_is_vram ? PTE_UPDATE_FLAG_IS_VRAM : 0; > pte_flags |= use_comp_pat ? PTE_UPDATE_FLAG_IS_COMP_PTE : 0; > batch_size += pte_update_size(m, pte_flags, src, &src_it, &src_L0, > &src_L0_ofs, &src_L0_pt, 0, 0, > avail_pts); > + /* > + * The source chunk size may have been clamped above, so derive > + * the packed destination size from the changed-page count of > + * the final chunk. > + */ > + if (pack_dst) { > + nchg = xe_migrate_count_changed_pages(src_tt, dst_tt, > + start_page, > + src_L0 >> PAGE_SHIFT); > + /* Leading borrowed pages were skipped above. */ > + xe_assert(xe, nchg); > + dst_size = (u64)nchg << PAGE_SHIFT; > + } else { > + dst_size = src_L0; > + } > if (copy_only_ccs) { > dst_L0_ofs = src_L0_ofs; > } else { > pte_flags = dst_is_vram ? PTE_UPDATE_FLAG_IS_VRAM : 0; > batch_size += pte_update_size(m, pte_flags, dst, > - &dst_it, &src_L0, > + &dst_it, &dst_size, > &dst_L0_ofs, &dst_L0_pt, > 0, avail_pts, avail_pts); > } > @@ -1519,26 +1675,18 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > * is split into one command per run of non-borrowed pages, so > * size for the number of runs actually needed. > */ > - if (skip_borrowed) > + if (defrag_runs) { > ndata_blits = emit_copy_chunks(gt, NULL, 0, 0, src_L0, > - src_tt, dst_tt, start_page); > - > - /* > - * If every page in this chunk was borrowed there is nothing to > - * copy: don't build a batch or issue any GPU commands, just > - * advance the cursors past the chunk. The non-vram tt cursors > - * would otherwise be advanced by emit_pte(). > - */ > - if (skip_borrowed && !ndata_blits) { > - xe_res_next(&src_it, src_L0); > - xe_res_next(&dst_it, src_L0); > - size -= src_L0; > - continue; > + src_tt, dst_tt, start_page, > + pack_dst, false); > + /* Leading borrowed pages were skipped above. */ > + xe_assert(xe, ndata_blits); > } > > batch_size += ((copy_only_ccs || defrag_ccs) ? 0 : > ndata_blits * emit_copy_cmd_len(xe)) + > - ((needs_ccs_emit ? EMIT_COPY_CCS_DW : 0)); > + (ccs_pack ? ndata_blits * EMIT_COPY_CCS_DW : > + (needs_ccs_emit ? EMIT_COPY_CCS_DW : 0)); > > bb = __xe_bb_new(gt, batch_size, usm, !fence && intr); > if (IS_ERR(bb)) { > @@ -1558,7 +1706,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > else if (!copy_only_ccs) > emit_pte(m, bb, dst_L0_pt, dst_is_vram, > copy_system_ccs || defrag_ccs, > - &dst_it, src_L0, dst); > + &dst_it, dst_size, dst); > > if (copy_system_ccs) > emit_pte(m, bb, ccs_pt, false, false, &ccs_it, ccs_size, src); > @@ -1568,16 +1716,23 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m, > > if (skip_borrowed) > emit_copy_chunks(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, > - src_tt, dst_tt, start_page); > + src_tt, dst_tt, start_page, pack_dst, > + false); > else if (!copy_only_ccs && !defrag_ccs) > emit_copy(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, XE_PAGE_SIZE); > > - if (needs_ccs_emit) > + if (ccs_pack) { > + if (emit_copy_chunks(gt, bb, src_L0_ofs, dst_L0_ofs, > + src_L0, src_tt, dst_tt, > + start_page, true, true)) > + flush_flags = MI_FLUSH_DW_CCS; > + } else if (needs_ccs_emit) { > flush_flags = xe_migrate_ccs_copy(m, bb, src_L0_ofs, > IS_DGFX(xe) ? src_is_vram : src_is_pltt, > dst_L0_ofs, > IS_DGFX(xe) ? dst_is_vram : dst_is_pltt, > src_L0, ccs_ofs, copy_ccs); > + } > > job = xe_bb_create_migration_job(m->q, bb, > xe_migrate_batch_base(m, usm), > @@ -1679,7 +1834,7 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m, > bool copy_only_ccs, > bool intr) > { > - return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, NULL, > + return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, NULL, 0, > copy_only_ccs ? XE_MIGRATE_COPY_CCS_ONLY : > XE_MIGRATE_COPY_NORMAL, intr); > } > @@ -1727,15 +1882,53 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m, > struct ttm_resource *dst, > struct ttm_tt *src_tt, > bool need_ccs) > +{ > + return xe_migrate_copy_defrag_iova(m, bo, src, dst, src_tt, 0, > + need_ccs); > +} > + > +/** > + * xe_migrate_copy_defrag_iova() - Copy a defrag move into a packed IOVA dst. > + * @m: The migration context. > + * @bo: The buffer object being defragmented. > + * @src: The source (old) TTM resource. > + * @dst: The destination (new) TTM resource. > + * @src_tt: The stashed source (old) tt providing the page pointers, fully > + * IOVA-mapped at natural offsets. > + * @dst_packed_pages: Number of changed pages packed into the destination tt's > + * IOVA prefix by xe_tt_map_iova_copy(), or 0 if the destination is fully > + * mapped (see xe_migrate_copy_defrag()). > + * @need_ccs: Whether the BO has flat-CCS aux state that must be migrated too. > + * > + * Defrag copy variant for IOVA-mapped BOs where the destination only maps the > + * changed (non-borrowed) pages, packed contiguously into the first > + * @dst_packed_pages of its IOVA. The source is read from the old tt at its > + * natural offsets and each changed run is blitted into the packed destination > + * prefix. When @need_ccs is set a second pass migrates the flat-CCS aux state > + * of the same changed pages indirectly through their (packed) data mappings; > + * borrowed pages share the physical page and its aux, so only the changed runs > + * are touched. > + * > + * Return: Pointer to a dma_fence representing the last copy batch, or an error > + * pointer on failure. > + */ > +struct dma_fence *xe_migrate_copy_defrag_iova(struct xe_migrate *m, > + struct xe_bo *bo, > + struct ttm_resource *src, > + struct ttm_resource *dst, > + struct ttm_tt *src_tt, > + pgoff_t dst_packed_pages, > + bool need_ccs) > { > struct dma_fence *fence2, *fence = > - __xe_migrate_copy(m, bo, bo, src, dst, src_tt, > + __xe_migrate_copy(m, bo, bo, src, dst, src_tt, dst_packed_pages, > XE_MIGRATE_COPY_DEFRAG_DATA, false); > > if (IS_ERR(fence) || !need_ccs) > return fence; > > fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_tt, > + dst_packed_pages, > XE_MIGRATE_COPY_DEFRAG_CCS, false); > if (IS_ERR(fence2)) > dma_fence_wait(fence, false); > @@ -1759,7 +1952,7 @@ struct dma_fence *xe_migrate_resolve(struct xe_migrate *m, > struct xe_bo *bo, > struct ttm_resource *res) > { > - return __xe_migrate_copy(m, bo, bo, res, res, NULL, > + return __xe_migrate_copy(m, bo, bo, res, res, NULL, 0, > XE_MIGRATE_COPY_VRAM_RESOLVE, true); > } > > diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h > index c410652641f5..3a9e9276e699 100644 > --- a/drivers/gpu/drm/xe/xe_migrate.h > +++ b/drivers/gpu/drm/xe/xe_migrate.h > @@ -68,6 +68,14 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m, > struct ttm_tt *src_tt, > bool need_ccs); > > +struct dma_fence *xe_migrate_copy_defrag_iova(struct xe_migrate *m, > + struct xe_bo *bo, > + struct ttm_resource *src, > + struct ttm_resource *dst, > + struct ttm_tt *src_tt, > + pgoff_t dst_packed_pages, > + bool need_ccs); > + > struct dma_fence *xe_migrate_resolve(struct xe_migrate *m, > struct xe_bo *bo, > struct ttm_resource *res);