Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matthew Auld" <matthew.auld@intel.com>, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2 5/6] drm/xe/bb: drop per-batch prefetch padding
Date: Fri, 27 Nov 2026 12:33:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-237412@kernel.org> (raw)
In-Reply-To: <20261127-migrate-bb-optimise-v2-5-808d0d520ddb@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe: batch size underestimation in pte_update_cmd_size()
  for non-4K pages
--

commit 8de4bf033cf5665a8ffaac384549e82ba2ea902c
Author: Matthew Auld <matthew.auld@intel.com>

drm/xe/bb: drop per-batch prefetch padding

This commit drops the per-batch bb_prefetch() padding from __xe_bb_new(),
relying on the 4K guard region at the end of the suballocation pool BO to
cover hardware CS prefetch.

Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/9644

> diff --git a/drivers/gpu/drm/xe/xe_bb.c b/drivers/gpu/drm/xe/xe_bb.c
> index 6308a1dca4647..bcb3a56995a6f 100644
> --- a/drivers/gpu/drm/xe/xe_bb.c
> +++ b/drivers/gpu/drm/xe/xe_bb.c
> @@ -14,20 +14,6 @@
>  #include "xe_sched_job.h"
>  #include "xe_vm_types.h"
>  
> -static int bb_prefetch(struct xe_gt *gt)
> -{
> -	struct xe_device *xe = gt_to_xe(gt);
> -
> -	if (GRAPHICS_VERx100(xe) >= 1250 && xe_gt_is_main_type(gt))
> -		/*
> -		 * RCS and CCS require 1K, although other engines would be
> -		 * okay with 512.
> -		 */
> -		return SZ_1K;
> -	else
> -		return SZ_512;
> -}
> -
>  struct xe_bb *__xe_bb_new(struct xe_gt *gt, u32 dwords, bool usm, bool intr)
>  {
>  	struct xe_tile *tile = gt_to_tile(gt);
> @@ -38,13 +24,13 @@ struct xe_bb *__xe_bb_new(struct xe_gt *gt, u32 dwords, bool usm, bool intr)
>  		return ERR_PTR(-ENOMEM);
>  
>  	/*
> -	 * We need to allocate space for the requested number of dwords,
> -	 * one additional MI_BATCH_BUFFER_END dword, and additional buffer
> -	 * space to accommodate the platform-specific hardware prefetch
> -	 * requirements.
> +	 * We need to allocate space for the requested number of dwords and
> +	 * one additional MI_BATCH_BUFFER_END dword. Hardware CS prefetch
> +	 * at the end of the pool BO is covered by the SZ_4K guard region
> +	 * reserved by xe_sa_bo_manager_init().
>  	 */
>  	bb->bo = xe_sa_bo_new(!usm ? tile->mem.kernel_bb_pool : gt->usm.bb_pool,
> -			      4 * (dwords + 1) + bb_prefetch(gt), intr);
> +			      4 * (dwords + 1), intr);
>  	if (IS_ERR(bb->bo)) {
>  		err = PTR_ERR(bb->bo);
>  		goto err;
> @@ -129,7 +115,7 @@ __xe_bb_create_job(struct xe_exec_queue *q, struct xe_bb *bb, u64 *addr)
>  	if (bb->len == 0 || bb->cs[bb->len - 1] != MI_BATCH_BUFFER_END)
>  		bb->cs[bb->len++] = MI_BATCH_BUFFER_END;
>  
> -	xe_gt_assert(q->gt, bb->len * 4 + bb_prefetch(q->gt) <= size);
> +	xe_gt_assert(q->gt, bb->len * 4 <= size);
>  
>  	xe_sa_bo_flush_write(bb->bo);

[Severity: Medium]
Without the trailing bb_prefetch() padding, can build_pt_update_batch_sram()
overflow bb->bo when PAGE_SIZE > 4K?

pte_update_cmd_size() sizes the batch assuming each MI_STORE_DATA_IMM
command writes up to MAX_PTE_PER_SDI (510) entries, whereas
build_pt_update_batch_sram() rounds level-0 chunks down to a multiple of
PAGE_SIZE / XE_PAGE_SIZE (496 entries on 64K pages, 508 on 16K pages):

drivers/gpu/drm/xe/xe_migrate.c:pte_update_cmd_size() {
    ...
	num_dword = (1 + 2) * DIV_U64_ROUND_UP(entries, MAX_PTE_PER_SDI);
	num_dword += entries * 2;
    ...
}

drivers/gpu/drm/xe/xe_migrate.c:build_pt_update_batch_sram() {
    ...
	while (ptes) {
		u32 chunk = min(MAX_PTE_PER_SDI, ptes);

		if (!level)
			chunk = ALIGN_DOWN(chunk, PAGE_SIZE / XE_PAGE_SIZE);

		bb->cs[bb->len++] = MI_STORE_DATA_IMM | MI_SDI_NUM_QW(chunk);
    ...
}

When the smaller chunk size requires an extra 3-dword MI_STORE_DATA_IMM
header (for example, migrating 63 64K pages = 1008 4K PTEs emits 3 headers
instead of 2), bb->cs writes 12 bytes past the end of bb->bo, triggering
the xe_gt_assert() in __xe_bb_create_job() and truncating the last 3
dwords of the batch when xe_sa_bo_flush_write() copies drm_suballoc_size()
bytes to VRAM.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-migrate-bb-optimise-v2-0-808d0d520ddb@intel.com?part=5

  reply	other threads:[~2026-11-27 12:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:14 [PATCH v2 0/6] Interruptible bb wait + related bits Matthew Auld
2026-11-27 12:14 ` [PATCH v2 1/6] drm/xe/sa: allow callers to specify interruptible suballocator waits Matthew Auld
2026-11-27 12:14 ` [PATCH v2 2/6] drm/xe/migrate: plumb interruptible wait flag to clear and copy Matthew Auld
2026-11-27 12:14 ` [PATCH v2 3/6] drm/xe/migrate: avoid interruptible waits once passes are in flight Matthew Auld
2026-11-27 12:14 ` [PATCH v2 4/6] drm/xe/migrate: optimise chunk sizes for identity VRAM clears Matthew Auld
2026-11-27 12:14 ` [PATCH v2 5/6] drm/xe/bb: drop per-batch prefetch padding Matthew Auld
2026-11-27 12:33   ` sashiko-bot [this message]
2026-11-27 12:14 ` [PATCH v2 6/6] drm/xe/sa: remove unused shadow BO and two-step bb helpers Matthew Auld
2026-11-27 12:27 ` ✓ CI.KUnit: success for Interruptible bb wait + related bits (rev2) 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-237412@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox