Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stuart Summers" <stuart.summers@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 13/16] drm/xe: Fall back to CPU copies when the tile cannot blit
Date: Fri, 20 Nov 2026 06:09:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-224536@kernel.org> (raw)
In-Reply-To: <20261120054712.377573-31-stuart.summers@intel.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Critical] drm/xe: out-of-bounds ioremap on non-contiguous VRAM BO in
  ttm_bo_move_memcpy()
- [High] drm/xe: WARN_ON and -EINVAL on VRAM BO clear in xe_bo_move()
  via ttm_bo_move_memcpy()
- [High] drm/xe: invalid xe_bo_vmap() fallback in pinned BO save and
  restore paths
- [High] drm/xe: missing fence wait before synchronous
  ttm_bo_move_memcpy() in xe_bo_move()
- [Medium] drm/xe: unchecked blitter calls in xe_ttm_access_memory() and
  xe_vram_memtest()
--

commit 0cfa915c2d6cb675a189debb683cd051c34415aa
Author: Stuart Summers <stuart.summers@intel.com>

drm/xe: Fall back to CPU copies when the tile cannot blit

This commit adds xe_migrate_can_blit() to detect tiles without a primary GT
and falls back to CPU copies in xe_bo_move(), xe_bo_evict_pinned_copy(),
and xe_bo_restore_pinned().

> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 353ac1e9a9d6f..8a8a034d1edb6 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -1277,6 +1277,19 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
>  		xe_pm_runtime_get_noresume(xe);
>  	}
>  
> +	/*
> +	 * A tile with no copy engine cannot blit, so move the data with the
> +	 * CPU instead.  For VRAM that means going over the PCIe BAR, which is
> +	 * slow, but a device with no graphics IP offers no alternative.
> +	 * ttm_bo_move_memcpy() covers the clear case too, by way of an
> +	 * unpopulated source.
> +	 */
> +	if (!xe_migrate_can_blit(migrate)) {
> +		ret = ttm_bo_move_memcpy(ttm_bo, ctx, new_mem);
> +		xe_pm_runtime_put(xe);
> +		goto out;
> +	}

[Severity: Critical]
Can ttm_bo_move_memcpy() ioremap an overflowed physical address when moving
or clearing a non-contiguous VRAM BO?

User VRAM BOs do not set force_contiguous(bo_flags), so when a VRAM
allocation spans non-adjacent buddy blocks, xe_ttm_vram_mgr_new() leaves
TTM_PL_FLAG_CONTIGUOUS unset and sets vres->base.start to
XE_BO_INVALID_OFFSET (LONG_MAX).  When ttm_bo_move_memcpy() initializes its
linear IO iterator, xe_ttm_io_mem_reserve() shifts mem->start by
PAGE_SHIFT:

drivers/gpu/drm/xe/xe_bo.c:xe_ttm_io_mem_reserve() {
	...
		mem->bus.offset = mem->start << PAGE_SHIFT;

		if (vram->mapping &&
		    mem->placement & TTM_PL_FLAG_CONTIGUOUS)
			mem->bus.addr = (u8 __force *)vram->mapping +
				mem->bus.offset;

		mem->bus.offset += vram->io_start;
		mem->bus.is_iomem = true;
	...
}

Because TTM_PL_FLAG_CONTIGUOUS is clear, mem->bus.addr stays NULL and
mem->bus.offset wraps to vram->io_start - PAGE_SIZE.
ttm_kmap_iter_linear_io_init() then ioremaps mem->size bytes starting at
physical address vram->io_start - PAGE_SIZE, and ttm_move_memcpy() linearly
reads, writes, or zeroes across that address and the start of the VRAM BAR
instead of walking the BO's buddy blocks via xe_res_cursor.

[Severity: High]
Does ttm_bo_move_memcpy() hit WARN_ON(!src_mem) and return -EINVAL when
clearing a newly created VRAM BO?

When a ttm_bo_type_device BO is created in VRAM without
XE_BO_FLAG_DEFER_BACKING, xe_bo_init_locked() validates it while
ttm_bo->resource (old_mem) and ttm_bo->ttm are both NULL.  In xe_bo_move(),
move_lacks_source and needs_clear are both true, so execution reaches
ttm_bo_move_memcpy(), which requires a non-NULL bo->resource:

drivers/gpu/drm/ttm/ttm_bo_util.c:ttm_bo_move_memcpy() {
	...
	struct ttm_resource *src_mem = bo->resource;
	...
	if (WARN_ON(!src_mem))
		return -EINVAL;

Every non-deferred user VRAM BO creation on a tile that cannot blit will
trigger the warning and fail with -EINVAL.

[Severity: High]
Does this path also run ttm_bo_move_memcpy() before waiting for existing
fences on ttm_bo->base.resv?

Unlike xe_migrate_copy() and xe_migrate_clear(), which queue job
dependencies on DMA_RESV_USAGE_BOOKKEEP and DMA_RESV_USAGE_KERNEL fences,
ttm_bo_move_memcpy() copies or zeroes with the CPU immediately and only
waits on bo->base.resv inside ttm_bo_move_sync_cleanup() after
ttm_move_memcpy() has already finished.  When xe_bo_trigger_rebind() skips
its DMA_RESV_USAGE_BOOKKEEP wait (for example on a non-fault-mode VM when
!xe_device_is_l2_flush_optimized(xe)), or when new_mem carries pipelined
DMA_RESV_USAGE_KERNEL eviction fences, the CPU copy runs concurrently with
in-flight GPU work and ignores ctx->no_wait_gpu unless ttm_bo_wait_ctx() is
called first.

> @@ -1578,17 +1591,18 @@ int xe_bo_notifier_unprepare_pinned(struct xe_bo *bo)
>  static int xe_bo_evict_pinned_copy(struct xe_bo *bo, struct xe_bo *backup)
>  {
>  	struct xe_device *xe = xe_bo_device(bo);
> +	struct xe_migrate *migrate;
>  	bool unmap = false;
>  	int ret = 0;
>  
> -	if (xe_bo_is_user(bo) || (bo->flags & XE_BO_FLAG_PINNED_LATE_RESTORE)) {
> -		struct xe_migrate *migrate;
> -		struct dma_fence *fence;
> +	if (bo->tile)
> +		migrate = bo->tile->migrate;
> +	else
> +		migrate = mem_type_to_migrate(xe, bo->ttm.resource->mem_type);
>  
> -		if (bo->tile)
> -			migrate = bo->tile->migrate;
> -		else
> -			migrate = mem_type_to_migrate(xe, bo->ttm.resource->mem_type);
> +	if ((xe_bo_is_user(bo) || (bo->flags & XE_BO_FLAG_PINNED_LATE_RESTORE)) &&
> +	    xe_migrate_can_blit(migrate)) {
> +		struct dma_fence *fence;
>  
>  		xe_assert(xe, bo->ttm.base.resv == backup->ttm.base.resv);
>  		ret = dma_resv_reserve_fences(bo->ttm.base.resv, 1);
> @@ -1717,6 +1731,7 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
>  	};
>  	struct xe_device *xe = ttm_to_xe_device(bo->ttm.bdev);
>  	struct xe_bo *backup = bo->backup_obj;
> +	struct xe_migrate *migrate;
>  	bool unmap = false;
>  	int ret;
>  
> @@ -1731,14 +1746,14 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
>  			goto out_unlock_bo;
>  	}
>  
> -	if (xe_bo_is_user(bo) || (bo->flags & XE_BO_FLAG_PINNED_LATE_RESTORE)) {
> -		struct xe_migrate *migrate;
> -		struct dma_fence *fence;
> +	if (bo->tile)
> +		migrate = bo->tile->migrate;
> +	else
> +		migrate = mem_type_to_migrate(xe, bo->ttm.resource->mem_type);
>  
> -		if (bo->tile)
> -			migrate = bo->tile->migrate;
> -		else
> -			migrate = mem_type_to_migrate(xe, bo->ttm.resource->mem_type);
> +	if ((xe_bo_is_user(bo) || (bo->flags & XE_BO_FLAG_PINNED_LATE_RESTORE)) &&
> +	    xe_migrate_can_blit(migrate)) {
> +		struct dma_fence *fence;

[Severity: High]
Will falling back to the else branch in xe_bo_evict_pinned_copy() and
xe_bo_restore_pinned() trigger drm_WARN_ON() and fail with -EINVAL in
xe_bo_vmap(bo)?

When !xe_migrate_can_blit(migrate), the else branch calls xe_bo_vmap(bo) if
bo->vmap is null, and xe_bo_vmap() rejects any BO that does not have both
XE_BO_FLAG_NEEDS_CPU_ACCESS and force_contiguous(bo->flags):

drivers/gpu/drm/xe/xe_bo.c:xe_bo_vmap() {
	...
	if (drm_WARN_ON(&xe->drm, !(bo->flags & XE_BO_FLAG_NEEDS_CPU_ACCESS) ||
			!force_contiguous(bo->flags)))
		return -EINVAL;

User BOs pinned via xe_bo_pin_external() never have XE_BO_FLAG_PINNED set,
and late-restore kernel BOs such as VF LMEM BOs in pf_provision_vf_lmem()
do not set XE_BO_FLAG_NEEDS_CPU_ACCESS, so force_contiguous(bo->flags) is
false (and their VRAM blocks are not guaranteed to be contiguous), causing
suspend and resume to warn and fail with -EINVAL.

> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index 8fc3e5d500a2b..7e845cbaa0829 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c
> @@ -2155,6 +2155,22 @@ void xe_migrate_wait(struct xe_migrate *m)
>  		dma_fence_wait(m->fence, false);
>  }
>  
> +/**
> + * xe_migrate_can_blit() - Whether a migration context can issue blits
> + * @m: The migration context
> + *
> + * xe_migrate_copy() and xe_migrate_clear() emit blitter commands, which only
> + * the copy engine understands, and the copy engine lives on the primary GT.
> + * A tile without one can still update page tables, so its migration context
> + * is usable, but callers that want to move data have to do it themselves.
> + *
> + * Return: true if blit based copy and clear are available on @m.
> + */
> +bool xe_migrate_can_blit(struct xe_migrate *m)
> +{
> +	return m->tile->primary_gt;
> +}

[Severity: Medium]
Should xe_ttm_access_memory() and xe_vram_memtest() also check
xe_migrate_can_blit()?

In xe_ttm_access_memory(), accesses with len >= SZ_16K unconditionally call
xe_migrate_access_memory() instead of falling through to the CPU BAR memcpy
loop, which emits blitter copy commands onto the migration queue.
Similarly, when CONFIG_DRM_XE_DEBUG_MEM is enabled, xe_vram_memtest() only
checks tile->migrate before calling xe_migrate_clear(), which fails the GPU
clear check and aborts xe_device_probe() with -EIO on a tile without a
primary GT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120054712.377573-18-stuart.summers@intel.com?part=13

  reply	other threads:[~2026-11-20  6:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  5:47 [PATCH 00/16] Work around media 52-bit limitation on CRI Stuart Summers
2026-11-20  5:47 ` [PATCH 01/16] drm/xe/sysctrl: Use preallocated mailbox staging buffers Stuart Summers
2026-11-20  5:52   ` sashiko-bot
2026-11-20  5:47 ` [PATCH 02/16] drm/xe: Process device OOB workarounds during early info init Stuart Summers
2026-11-20  5:47 ` [PATCH 03/16] drm/xe/sysctrl: Restore the SoC remapper on every runtime resume Stuart Summers
2026-11-20  5:47 ` [PATCH 04/16] drm/xe: Add enable_media module parameter Stuart Summers
2026-11-20  5:47 ` [PATCH 05/16] drm/xe: Detect each GMD_ID IP in a loop Stuart Summers
2026-11-20  5:47 ` [PATCH 06/16] drm/xe: Tolerate a missing graphics IP in xe_info_init() Stuart Summers
2026-11-20  5:47 ` [PATCH 07/16] drm/xe: Verify IP presence against GU_CNTL Stuart Summers
2026-11-20  5:47 ` [PATCH 08/16] drm/xe: Guard per-tile primary GT accesses Stuart Summers
2026-11-20  5:47 ` [PATCH 09/16] drm/xe: Stop assuming the root tile has a primary GT Stuart Summers
2026-11-20  5:47 ` [PATCH 10/16] drm/xe: Do not claim flat CCS without a graphics IP Stuart Summers
2026-11-20  5:47 ` [PATCH 11/16] drm/xe: Run page table updates on the media GT when there is no primary Stuart Summers
2026-11-20  6:10   ` sashiko-bot
2026-11-20  5:47 ` [PATCH 12/16] drm/xe: Document that gt_types_allowed=media now probes Stuart Summers
2026-11-20  5:47 ` [PATCH 13/16] drm/xe: Fall back to CPU copies when the tile cannot blit Stuart Summers
2026-11-20  6:09   ` sashiko-bot [this message]
2026-11-20  5:47 ` [PATCH 14/16] drm/xe: Require a fully visible VRAM BAR without a primary GT Stuart Summers
2026-11-20  5:47 ` [PATCH 15/16] drm/xe: Allow probe " Stuart Summers
2026-11-20  5:47 ` [PATCH 16/16] drm/xe: Work around media 52-bit limitation on CRI Stuart Summers
2026-11-20  6:11   ` sashiko-bot

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-224536@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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