All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matthew Brost" <matthew.brost@intel.com>,
	intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 29/33] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies
Date: Wed, 02 Dec 2026 00:17:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-244480@kernel.org> (raw)
In-Reply-To: <20261201234915.3305331-30-matthew.brost@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/xe: commit message contradicts CCS and skip logic in
  __xe_migrate_copy()
- [Low] drm/xe: duplicated logic in emit_ccs_copy_chunks() and defrag
  copy wrappers
--

commit 681da51913c9f8bb7ed8b338e9df09061c4b206e
Author: Matthew Brost <matthew.brost@intel.com>

drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies

This commit teaches __xe_migrate_copy() to copy changed pages from their
natural source offsets into a packed destination IOVA prefix, and exposes
this mode via xe_migrate_copy_defrag_iova().

> - Size the destination PTE update for each chunk from the changed-page
>   count (xe_migrate_count_changed_pages()) rather than the full chunk,
>   and skip the destination PTEs entirely for an all-borrowed chunk.
>
> - 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. The
>   all-borrowed skip leaves the packed destination cursor untouched.
>
> Expose this via xe_migrate_copy_defrag_iova(). It is only valid when the
> BO needs no CCS pass, since the separate CCS pass migrates aux state for
> all pages and would require the full destination mapping. The existing
> xe_migrate_copy_defrag() (full destination mapping) remains the path for
> CCS BOs and the non-IOVA fallback.

[Severity: Medium]
Does the commit message match the implementation on CCS support and
all-borrowed chunks?

xe_migrate_copy_defrag_iova() takes a need_ccs parameter and runs a second
XE_MIGRATE_COPY_DEFRAG_CCS pass with dst_packed_pages using the new
emit_ccs_copy_chunks() helper and ccs_pack path in __xe_migrate_copy().

Also, the post-pte_update_size() all-borrowed chunk skip (if
(skip_borrowed && !ndata_blits)) is removed in favor of fast-forwarding
leading borrowed pages up front via xe_migrate_leading_borrowed_pages(),
after which __xe_migrate_copy() asserts that nchg and ndata_blits are
non-zero.

> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index 43267bc0f5e08..8cb4a8c182ec0 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c

[ ... ]

> @@ -1276,9 +1342,71 @@ static u32 emit_copy_chunks(struct xe_gt *gt, struct xe_bb *bb,
>  
>  		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;
> +	}
> +
> +	return nblits;
> +}
> +
> +/*
> + * emit_ccs_copy_chunks() - Emit the indirect CCS aux copies for one packed
> + * defrag L0 chunk, skipping borrowed pages.
> + * @gt: The GT.
> + * @bb: The batch buffer to emit into, or NULL to only count the copies needed.
> + * @src_L0_ofs: GPU offset of the source pages mapped (comp PAT) for this chunk.
> + * @dst_L0_ofs: GPU offset of the destination pages mapped (comp PAT) for this
> + *	        chunk (the packed changed-page prefix).
> + * @src_L0: Byte size of the L0 chunk (page aligned).
> + * @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.
> + *
> + * Companion to emit_copy_chunks() 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; only the changed runs are copied, from the source
> + * at its natural offset to the destination at its packed offset.
> + *
> + * Return: The number of CCS copies emitted (or that would be emitted when @bb
> + * is NULL).
> + */
> +static u32 emit_ccs_copy_chunks(struct xe_gt *gt, struct xe_bb *bb,
> +				u64 src_L0_ofs, u64 dst_L0_ofs, u32 src_L0,
> +				struct ttm_tt *src_tt, struct ttm_tt *dst_tt,
> +				pgoff_t start_page)
> +{
> +	u32 npages = src_L0 >> PAGE_SHIFT;
> +	u32 i = 0, pack = 0, nblits = 0;
> +
> +	while (i < npages) {
> +		u32 run = 0;
> +
> +		/* Skip a run of borrowed pages (src and dst alias). */
> +		if (src_tt->pages[start_page + i] ==
> +		    dst_tt->pages[start_page + i]) {
> +			i++;
> +			continue;
> +		}
> +
> +		/* Coalesce a run of pages whose aux must be migrated. */
> +		while (i + run < npages &&
> +		       src_tt->pages[start_page + i + run] !=
> +		       dst_tt->pages[start_page + i + run])
> +			run++;
> +
> +		if (bb)
> +			emit_copy_ccs(gt, bb,
> +				      dst_L0_ofs + (u64)pack * PAGE_SIZE, true,
> +				      src_L0_ofs + (u64)i * PAGE_SIZE, true,
> +				      run * PAGE_SIZE);
> +		nblits++;
> +		pack += run;
>  		i += run;
>  	}
>  
>  	return nblits;
>  }

[ ... ]

> @@ -1711,13 +1912,62 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m,
>  					 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, 0,
> +				  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, 0,
> +				   XE_MIGRATE_COPY_DEFRAG_CCS, false);
> +	if (IS_ERR(fence2))
> +		dma_fence_wait(fence, false);
> +	dma_fence_put(fence);
> +
> +	return fence2;
> +}
> +
> +/**
> + * 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().
> + * @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, 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);
>  	dma_fence_put(fence);
>  
>  	return fence2;
>  }

[Severity: Low]
This isn't a bug, but emit_ccs_copy_chunks() and
xe_migrate_copy_defrag_iova() duplicate existing helpers.

emit_ccs_copy_chunks() repeats the run-coalescing loop of
emit_copy_chunks(), differing only in calling emit_copy_ccs() instead of
emit_copy() when bb is non-NULL (__xe_migrate_copy() already calls
emit_copy_chunks() with bb == NULL to count the runs for ccs_pack).
Likewise, xe_migrate_copy_defrag() can just call
xe_migrate_copy_defrag_iova(m, bo, src, dst, src_tt, 0, need_ccs).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201234915.3305331-1-matthew.brost@intel.com?part=29

  reply	other threads:[~2026-12-02  0:18 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 23:48 [PATCH v4 00/33] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Matthew Brost
2026-12-01 23:48 ` [PATCH v4 01/33] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-12-01 23:48 ` [PATCH v4 02/33] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-12-01 23:48 ` [PATCH v4 03/33] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-12-01 23:48 ` [PATCH v4 04/33] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-12-01 23:59   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 05/33] drm/ttm: Support defragmentation moves Matthew Brost
2026-12-01 23:48 ` [PATCH v4 06/33] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-12-02  0:06   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 07/33] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-12-02  0:27   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-01 23:48 ` [PATCH v4 09/33] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-12-02  0:23   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 10/33] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-12-02  0:15   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 11/33] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
2026-12-01 23:48 ` [PATCH v4 12/33] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
2026-12-01 23:48 ` [PATCH v4 13/33] drm/xe: Flush L2 asynchronously in xe_bo_trigger_rebind() Matthew Brost
2026-12-02  0:19   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 14/33] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-12-02  0:17   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 15/33] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-12-01 23:48 ` [PATCH v4 16/33] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-12-02  0:19   ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 17/33] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-12-02  0:16   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 18/33] drm/xe: Add a page defragmentation worker Matthew Brost
2026-12-02  0:23   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 19/33] drm/xe: Add defrag GT stats Matthew Brost
2026-12-01 23:49 ` [PATCH v4 20/33] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-12-02  0:12   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 21/33] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-12-02  0:24   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 22/33] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-02  0:09   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 23/33] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-02  0:15   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 24/33] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-12-01 23:49 ` [PATCH v4 25/33] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-12-01 23:49 ` [PATCH v4 26/33] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-12-02  1:03   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 27/33] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-12-01 23:49 ` [PATCH v4 28/33] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-12-01 23:49 ` [PATCH v4 29/33] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-12-02  0:17   ` sashiko-bot [this message]
2026-12-01 23:49 ` [PATCH v4 30/33] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
2026-12-02  1:03   ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 31/33] drm/xe: Grow the USM batch pool to 2M and map it via a single PDE Matthew Brost
2026-12-01 23:49 ` [PATCH v4 32/33] drm/xe: Add bo_defrag debugfs entry Matthew Brost
2026-12-01 23:49 ` [PATCH v4 33/33] drm/xe: Make BO defrag tunables configurable via sysfs Matthew Brost
2026-12-02  0:20   ` sashiko-bot
2026-12-01 23:58 ` ✗ CI.checkpatch: warning for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Patchwork
2026-12-02  0:00 ` ✓ CI.KUnit: success " Patchwork
2026-12-02  0:38 ` ✓ Xe.CI.BAT: " Patchwork

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=sashiko-outbox-244480@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.