Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <intel-xe@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v5 18/36] drm/xe: Add a page defragmentation worker
Date: Wed, 2 Dec 2026 17:00:19 -0800	[thread overview]
Message-ID: <axC/I8X4Cy4EnwxX@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <sashiko-outbox-246810@kernel.org>

On Thu, Dec 03, 2026 at 12:12:43AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] drm/xe: missing wedge and shutdown checks for
>   xe_bo_defrag_worker()

Looks valid, will fix.

> - [High] drm/xe: sliced defrag of FlatCCS BOs hits WARN_ON in
>   __xe_migrate_copy()

Flagged in prior patch, fixing.

> - [Medium] drm/xe: stop defrag worker in xe_device_shutdown() before GT
>   reset and FLR

Looks valid, will fix.

Matt

> --
> 
> commit 2827cf9a3258f09b55ed0523757aafd710c5214d
> Author: Matthew Brost <matthew.brost@intel.com>
> 
> drm/xe: Add a page defragmentation worker
> 
> This commit adds a delayed worker that walks the per-device defrag list and
> attempts to reallocate and GPU-copy BO backing pages at the device's
> beneficial order in budget-limited slices.
> 
> > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> > index 85fb888d5db4e..5944077ba997d 100644
> > --- a/drivers/gpu/drm/xe/xe_bo.c
> > +++ b/drivers/gpu/drm/xe/xe_bo.c
> 
> [ ... ]
> 
> > @@ -1292,6 +1457,216 @@ static void xe_bo_defrag_update(struct xe_bo *bo)
> 
> [ ... ]
> 
> > +static void xe_bo_defrag_worker(struct work_struct *w)
> > +{
> > +	struct delayed_work *dwork = to_delayed_work(w);
> > +	struct xe_device *xe =
> > +		container_of(dwork, struct xe_device, mem.defrag.worker);
> > +	u64 defrag_bytes = 0;
> > +	bool requeue = false;
> > +	int idx;
> > +
> > +	if (!drm_dev_enter(&xe->drm, &idx))
> > +		return;
> > +
> > +	if (!xe_pm_runtime_get_if_active(xe)) {
> 
> [Severity: High]
> Can xe_bo_defrag_worker() replace live BO contents with uninitialized pages
> when the device is wedged?
> 
> When xe_wedge_declare() or prepare_device_for_reset() runs, xe_wedge_get()
> holds a runtime PM reference, so xe_pm_runtime_get_if_active() still succeeds
> while tile->migrate->q is marked wedged or killed.  ttm_bo_validate() then
> allocates uninitialized beneficial-order pages for the new bo->ttm and calls
> xe_bo_move() -> xe_migrate_copy_defrag().  In guc_exec_queue_run_job(),
> hardware submission is skipped for wedged/killed queues while job->fence is
> still returned, so ttm_bo_move_accel_cleanup() commits the uncopied new
> bo->ttm and frees defrag_old_tt once TDR signals job->fence with -ETIME.
> 
> Should xe_bo_defrag_worker() check xe_wedged(xe) (or should
> xe_wedge_declare() and prepare_device_for_reset() stop the defrag worker)?
> 
> [ ... ]
> 
> > +		/*
> > +		 * Bound the per-BO move to the run's remaining byte budget. A
> > +		 * large object is upgraded in budget-sized slices across runs;
> > +		 * the slices already upgraded come back as free already-
> > +		 * beneficial harvests, so each run only spends budget on new
> > +		 * forward progress.
> > +		 */
> > +		ret = xe_bo_defrag_one(xe, bo, XE_BO_DEFRAG_SIZE_LIMIT - defrag_bytes,
> > +				       &consumed, &needs_more);
> > +		defrag_bytes += consumed;
> > +
> > +		if (ret || needs_more) {
> 
> [Severity: High]
> Can sliced defragmentation of a large FlatCCS BO hit XE_WARN_ON(!fence) in
> __xe_migrate_copy() and get stuck at the head of xe->mem.defrag.list?
> 
> For compressible BOs on integrated FlatCCS platforms, xe_ttm_tt_create()
> appends extra_pages beyond xe_bo_size(bo) to tt->num_pages (reaching 2MB or
> more once xe_bo_size(bo) is at least 1GB on Xe2 iGPU).  Slicing such a BO in
> XE_BO_DEFRAG_SIZE_LIMIT passes upgrades the data pages in
> [0, xe_bo_size(bo)) first, leaving only the trailing extra_pages sub-optimal
> with TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED still set.
> 
> On the next pass, ttm_pool_alloc() borrows all data pages from defrag_old_tt
> and reallocates only the trailing extra_pages.  Because __xe_migrate_copy()
> iterates over xe_bo_size(src_bo) during the XE_MIGRATE_COPY_DEFRAG_DATA pass,
> emit_copy_chunks() finds no unborrowed data pages, leaving fence NULL:
> 
> drivers/gpu/drm/xe/xe_migrate.c:__xe_migrate_copy() {
>     ...
> 	if (XE_WARN_ON(!fence))
> 		return ERR_PTR(-EINVAL);
> }
> 
> The move fails with -EINVAL and restores defrag_old_tt with the failed-order
> flag still set, so the BO remains at the head of xe->mem.defrag.list,
> triggering the warning on every retry and starving any BOs queued behind it.
> 
> [ ... ]
> 
> > diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> > index 67d648833030c..637f9e71e78b0 100644
> > --- a/drivers/gpu/drm/xe/xe_device.c
> > +++ b/drivers/gpu/drm/xe/xe_device.c
> 
> [ ... ]
> 
> > @@ -1445,9 +1456,12 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr)
> >  	u8 id;
> >  	int err;
> >  
> > +	/* No defrag moves (GPU copies) while suspending or across FLR. */
> > +	xe_bo_defrag_suspend(xe);
> > +
> >  	err = xe_pxp_pm_suspend(xe->pxp);
> 
> [Severity: Medium]
> Should xe_device_shutdown() also call xe_bo_defrag_suspend(xe)?
> 
> During system shutdown, pci_device_shutdown() calls pm_runtime_resume() right
> before xe_pci_shutdown() -> xe_device_shutdown().  If the device was runtime
> suspended with a non-empty defrag list, xe_pm_runtime_resume() calls
> xe_bo_defrag_kick(xe), arming xe_bo_defrag_worker() to run and issue GPU
> migration copies while xe_device_shutdown() suspends IRQs, resets GTs and
> runs __xe_driver_flr().
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=18

  reply	other threads:[~2026-12-03  1:00 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 23:32 [PATCH v5 00/36] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Matthew Brost
2026-12-02 23:32 ` [PATCH v5 01/36] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-12-02 23:32 ` [PATCH v5 02/36] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-12-02 23:32 ` [PATCH v5 03/36] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-12-02 23:32 ` [PATCH v5 04/36] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-12-02 23:32 ` [PATCH v5 05/36] drm/ttm: Support defragmentation moves Matthew Brost
2026-12-02 23:32 ` [PATCH v5 06/36] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-12-02 23:32 ` [PATCH v5 07/36] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore Matthew Brost
2026-12-02 23:32 ` [PATCH v5 08/36] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-12-02 23:32 ` [PATCH v5 09/36] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-02 23:32 ` [PATCH v5 10/36] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-12-02 23:57   ` sashiko-bot
2026-12-03  0:08     ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-12-02 23:59   ` sashiko-bot
2026-12-03  0:16     ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 12/36] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
2026-12-02 23:33 ` [PATCH v5 13/36] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
2026-12-03  0:25   ` Niranjana Vishwanathapura
2026-12-03  0:29     ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 14/36] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-12-02 23:53   ` sashiko-bot
2026-12-03  0:34     ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 15/36] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-12-02 23:33 ` [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-12-02 23:55   ` sashiko-bot
2026-12-03  0:45     ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 17/36] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-12-02 23:52   ` sashiko-bot
2026-12-03  0:52     ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 18/36] drm/xe: Add a page defragmentation worker Matthew Brost
2026-12-03  0:12   ` sashiko-bot
2026-12-03  1:00     ` Matthew Brost [this message]
2026-12-02 23:33 ` [PATCH v5 19/36] drm/xe: Add defrag GT stats Matthew Brost
2026-12-02 23:33 ` [PATCH v5 20/36] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-12-02 23:33 ` [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-12-02 23:56   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 22/36] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-02 23:33 ` [PATCH v5 23/36] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-02 23:33 ` [PATCH v5 24/36] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-12-02 23:33 ` [PATCH v5 25/36] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-12-02 23:33 ` [PATCH v5 26/36] drm/xe: Don't DMA map tt pages after device unplug Matthew Brost
2026-12-02 23:52   ` sashiko-bot
2026-12-03  1:12     ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 27/36] drm/xe/display: Flush cleanup work on unregister Matthew Brost
2026-12-02 23:58   ` sashiko-bot
2026-12-03  1:13     ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 28/36] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned() Matthew Brost
2026-12-02 23:33 ` [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-12-03  0:06   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 30/36] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-12-02 23:33 ` [PATCH v5 31/36] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-12-02 23:33 ` [PATCH v5 32/36] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-12-02 23:33 ` [PATCH v5 33/36] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
2026-12-03  0:18   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 34/36] drm/xe: Grow the USM batch pool to 2M and map it via a single PDE Matthew Brost
2026-12-02 23:33 ` [PATCH v5 35/36] drm/xe: Add bo_defrag debugfs entry Matthew Brost
2026-12-02 23:33 ` [PATCH v5 36/36] drm/xe: Make BO defrag tunables configurable via sysfs Matthew Brost
2026-12-03  0:21 ` ✗ CI.checkpatch: warning for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2) Patchwork
2026-12-03  0:23 ` ✓ CI.KUnit: success " Patchwork
2026-12-03  0:56 ` ✓ 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=axC/I8X4Cy4EnwxX@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=dri-devel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox