All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maarten Lankhorst" <dev@lankhorst.se>, intel-xe@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v5 2/5] drm/xe/migrate: Support copying between sysmem and stolen
Date: Fri, 13 Nov 2026 13:05:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-212805@kernel.org> (raw)
In-Reply-To: <20261113124453.144408-9-dev@lankhorst.se>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/xe/migrate: is_devmem() checks bo->ttm.resource instead of
  res
- [High] drm/xe/migrate: NULL deref and broken PTEs for stolen on
  pre-1270 GPUs
--

commit 3c7e5791762e378b27bc3e708f8e54449d9a1afa
Author: Maarten Lankhorst <dev@lankhorst.se>

drm/xe/migrate: Support copying between sysmem and stolen

This commit updates xe_migrate to disallow identity mapping for
XE_PL_STOLEN and adds an is_devmem() helper to handle stolen device
memory during migration copies and clears.

> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index 19c37eb315893..23b8f50d1ba21 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c
[ ... ]
> @@ -1206,6 +1210,14 @@ static u32 xe_migrate_ccs_copy(struct xe_migrate *m,
>  	return flush_flags;
>  }
>  
> +static bool is_devmem(struct xe_bo *bo, struct ttm_resource *res)
> +{
> +	if (mem_type_is_vram(res->mem_type))
> +		return true;
> +
> +	return xe_bo_is_stolen_devmem(bo);
> +}

[Severity: High]
Does is_devmem() cause a NULL pointer dereference in xe_bo_sg() when
migrating or clearing an XE_PL_STOLEN BO on platforms with graphics
version < 12.70 (such as TGL, ADL, DG1, or DG2)?

mem_type_is_vram() explicitly excludes XE_PL_STOLEN, and
xe_bo_is_stolen_devmem() returns false when GRAPHICS_VERx100(xe) < 1270,
so is_devmem() returns false for stolen memory on those platforms.
__xe_migrate_copy() and xe_migrate_clear() then take the non-VRAM path
and call xe_res_first_sg(xe_bo_sg(bo), ...), but stolen BOs are managed
with use_tt = false and have bo->ttm.ttm == NULL:

drivers/gpu/drm/xe/xe_bo.c:xe_bo_sg() {
	struct ttm_tt *tt = bo->ttm.ttm;
	struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);

	return xe_tt->sg;
}

In addition, emit_pte() only adds vram_region_gpu_offset(res) (which
returns mgr->stolen_base for XE_PL_STOLEN) inside the if (is_vram)
block alongside devmem = true, whereas pre-12.70 integrated stolen
memory needs xe_res_first() and vram_region_gpu_offset(res) without
setting XE_PPGTT_PTE_DM, and pre-12.70 discrete stolen memory (DG1, DG2)
resides in LMEM and needs both.

>  static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
>  					   struct xe_bo *src_bo,
>  					   struct xe_bo *dst_bo,
> @@ -1226,8 +1238,8 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
>  	int err;
>  	bool src_is_pltt = src->mem_type == XE_PL_TT;
>  	bool dst_is_pltt = dst->mem_type == XE_PL_TT;
> -	bool src_is_vram = mem_type_is_vram(src->mem_type);
> -	bool dst_is_vram = mem_type_is_vram(dst->mem_type);
> +	bool src_is_vram = is_devmem(src_bo, src);
> +	bool dst_is_vram = is_devmem(dst_bo, dst);

[Severity: High]
When moving or evicting a BO between XE_PL_STOLEN and XE_PL_TT, does
is_devmem() inspect bo->ttm.resource instead of the passed-in res?

xe_bo_is_stolen_devmem() calls xe_bo_is_stolen(), which checks
bo->ttm.resource->mem_type == XE_PL_STOLEN rather than res->mem_type.
During xe_bo_move(), xe_migrate_copy(migrate, bo, bo, old_mem, new_mem,
...) and xe_migrate_clear(migrate, bo, new_mem, ...) run before
bo->ttm.resource is updated to new_mem.

If a stolen BO is evicted from XE_PL_STOLEN (src) to XE_PL_TT (dst),
is_devmem(dst_bo, dst) sees bo->ttm.resource->mem_type == XE_PL_STOLEN
and returns true for the XE_PL_TT destination.  __xe_migrate_copy() then
initializes dst_it with xe_res_first(dst, ...) (which sets
dst_it.mem_type = XE_PL_TT and dst_it.size = size), passes
PTE_UPDATE_FLAG_IS_VRAM to pte_update_size(), and because
xe_migrate_allow_identity() returns true for dst_it.mem_type !=
XE_PL_STOLEN, calls xe_migrate_vram_ofs() and dereferences a NULL
xe->mem.vram on integrated GPUs.  Conversely, moving from XE_PL_TT to
XE_PL_STOLEN or clearing a newly allocated XE_PL_STOLEN resource while
bo->ttm.resource is NULL or XE_PL_TT returns false from is_devmem() and
calls xe_bo_sg() on a stolen BO.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113124453.144408-7-dev@lankhorst.se?part=2

  reply	other threads:[~2026-11-13 13:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 12:44 [PATCH v5 0/5] drm/xe/display: Transparant fallback from stolen to sysmem Maarten Lankhorst
2026-11-13 12:44 ` [PATCH v5 1/5] drm/xe/display: Avoid using stolen memory for framebuffer when media gt exists Maarten Lankhorst
2026-11-13 12:44 ` [PATCH v5 2/5] drm/xe/migrate: Support copying between sysmem and stolen Maarten Lankhorst
2026-11-13 13:05   ` sashiko-bot [this message]
2026-11-13 12:44 ` [PATCH v5 3/5] drm/xe: Raise gt frequency slightly earlier Maarten Lankhorst
2026-11-13 13:30   ` Ville Syrjälä
2026-11-13 12:44 ` [PATCH v5 4/5] HACK: Always fallback Maarten Lankhorst
2026-11-13 12:50   ` sashiko-bot
2026-11-13 12:44 ` [PATCH v5 5/5] drm/i915: Introduce intel_bo_fbdev_bios_fb_takeover() Maarten Lankhorst
2026-11-13 13:21   ` Ville Syrjälä
2026-11-13 13:22   ` sashiko-bot
2026-11-13 13:22 ` ✗ CI.checkpatch: warning for drm/xe/display: Transparant fallback from stolen to sysmem. (rev5) Patchwork
2026-11-13 13:24 ` ✓ CI.KUnit: success " Patchwork
2026-11-13 13:53 ` ✓ i915.CI.BAT: success for drm/xe/display: Transparant fallback from stolen to sysmem. (rev4) Patchwork
2026-11-13 13:56 ` ✗ Xe.CI.BAT: failure for drm/xe/display: Transparant fallback from stolen to sysmem. (rev5) 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-212805@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dev@lankhorst.se \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --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.