* [PATCH v5 00/36] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs
@ 2026-12-02 23:32 Matthew Brost
2026-12-02 23:32 ` [PATCH v5 01/36] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
` (38 more replies)
0 siblings, 39 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
The overarching goal of this series is to never enter reclaim for
higher-order allocations in the foreground - i.e., on any user-facing
path (gem_create, BO moves / validation, exec, faults) where a stall
could ultimately delay a page flip. Foreground allocations try the
beneficial order opportunistically and fall back to lower orders rather
than entering direct reclaim / compaction. The aggressive reclaim needed
to obtain high-order pages is pushed into the background (defrag), and
that work is likewise done outside the dma-resv lock, since holding the
reservation while reclaiming could just as easily stall a page flip.
Keeping the dma-resv hold time as short as possible remains desirable
and falls out of the same design.
Two related mechanisms fall out of that goal:
- Out-of-lock backing. Page allocation and DMA mapping are the dominant
cost of gem_create and of BO moves, and doing them under the dma-resv
lock serializes otherwise-independent clients. This series preallocates
the backing pages (and, where applicable, builds the DMA/IOVA mapping)
outside the lock, then transfers the result into the BO under a brief
lock hold. Foreground preallocation backs off reclaim at the beneficial
order, so the user gets a fast IOCTL return even under memory pressure.
- Page defragmentation. A BO allocated without high-order reclaim may
end up with scattered, sub-optimally-ordered backing, costing TLB
efficiency for its entire lifetime. TTM grows the plumbing to track
order-failure and to re-back a populated BO in place at the beneficial
order, and Xe wires up a background delayed worker that is allowed to
reclaim aggressively for high-order pages - outside the dma-resv lock -
and then promotes such BOs on the GPU under a brief lock hold, off the
hot path and without stalling the submitting thread or the display.
Testing
=======
- 3D benchmarks on Ubuntu and on Android, with memory intentionally
fragmented by a separate program at launch (plus beneficial-order
error injection). BOs are initially backed at a sub-optimal order and
scores start lower; the background defrag worker then promotes the
backing to the beneficial order and scores climb back in line with the
unfragmented baseline.
- IGT:
https://patchwork.freedesktop.org/patch/739052/?series=170046&rev=2
Matt
v3:
- Fix valid raised raised by Sashiko on v2
v4:
- Rebase + address v3 feedback
v5:
- Address Sashiko feedback, includes 3 standaline fixes flagged
Matthew Brost (34):
drm/ttm/pool: Allow backing off reclaim at the beneficial order
drm/ttm/pool: Add ttm_pool_page_order_nodma() helper
drm/ttm: Record sub-optimal page order allocations in ttm_tt
drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc()
drm/ttm: Support defragmentation moves
drm/ttm: Add fault injection for beneficial-order allocation failures
drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted
restore
drm/ttm: Harvest beneficial-order pages on defragmentation moves
drm/ttm: Bound page (re)allocation per defragmentation move
drm/ttm: Preallocate beneficial-order defrag pages outside the lock
drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
drm/xe: Track BOs backed at a sub-optimal page order
drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies
drm/xe: Handle defrag moves in xe_bo_move()
drm/xe: Skip self-copies for borrowed pages on defrag moves
drm/xe: Add a page defragmentation worker
drm/xe: Add defrag GT stats
drm/xe: Add Kconfig.profile options for BO defrag configuration
drm/xe: Defrag using out-of-lock page preallocation
drm/xe: Add defrag profiling tracepoints
drm/xe: Preallocate system BO backing outside the dma-resv lock
drm/xe: Add tracepoint for xe_gem_create_ioctl
drm/xe: Add IOVA-based xe_res_cursor variant
drm/xe: Don't DMA map tt pages after device unplug
drm/xe/display: Flush cleanup work on unregister
drm/xe: Lock the bo in xe_bo_dma_unmap_pinned()
drm/xe: Use IOVA-based DMA mapping for eligible tt BOs
drm/xe: Add per-device dependency scheduler for IOVA defrag finalize
drm/xe: Add packed copy-step IOVA mapping for defrag
drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies
drm/xe: Finalize defrag-IOVA moves with post-copy job
drm/xe: Grow the USM batch pool to 2M and map it via a single PDE
drm/xe: Add bo_defrag debugfs entry
drm/xe: Make BO defrag tunables configurable via sysfs
Thomas Hellström (2):
drm/gpusvm: Add a DMA-mapping accounting callback
drm/xe: Add debugfs stats for DMA-mapped pages per order
drivers/gpu/drm/drm_gpusvm.c | 41 +-
drivers/gpu/drm/ttm/ttm_bo.c | 108 +-
drivers/gpu/drm/ttm/ttm_bo_util.c | 23 +-
drivers/gpu/drm/ttm/ttm_pool.c | 1020 +++++++-
drivers/gpu/drm/ttm/ttm_tt.c | 67 +
drivers/gpu/drm/xe/Kconfig.profile | 36 +
drivers/gpu/drm/xe/display/xe_display.c | 8 +
drivers/gpu/drm/xe/tests/xe_bo.c | 12 +-
drivers/gpu/drm/xe/tests/xe_dma_buf.c | 4 +-
drivers/gpu/drm/xe/tests/xe_migrate.c | 15 +-
drivers/gpu/drm/xe/xe_bo.c | 3077 +++++++++++++++++++----
drivers/gpu/drm/xe/xe_bo.h | 35 +-
drivers/gpu/drm/xe/xe_bo_types.h | 6 +
drivers/gpu/drm/xe/xe_debugfs.c | 35 +
drivers/gpu/drm/xe/xe_device.c | 46 +-
drivers/gpu/drm/xe/xe_device_sysfs.c | 122 +
drivers/gpu/drm/xe/xe_device_types.h | 78 +
drivers/gpu/drm/xe/xe_dma_buf.c | 3 +-
drivers/gpu/drm/xe/xe_ggtt.c | 2 +-
drivers/gpu/drm/xe/xe_gt.c | 4 +-
drivers/gpu/drm/xe/xe_gt_stats.c | 5 +
drivers/gpu/drm/xe/xe_gt_stats_types.h | 21 +
drivers/gpu/drm/xe/xe_migrate.c | 491 +++-
drivers/gpu/drm/xe/xe_migrate.h | 17 +
drivers/gpu/drm/xe/xe_pm.c | 12 +
drivers/gpu/drm/xe/xe_pt.c | 2 +-
drivers/gpu/drm/xe/xe_res_cursor.h | 52 +-
drivers/gpu/drm/xe/xe_sriov_vf_ccs.c | 17 +-
drivers/gpu/drm/xe/xe_sriov_vf_ccs.h | 23 +
drivers/gpu/drm/xe/xe_svm.c | 8 +-
drivers/gpu/drm/xe/xe_svm.h | 4 +-
drivers/gpu/drm/xe/xe_trace_bo.h | 87 +
drivers/gpu/drm/xe/xe_userptr.c | 63 +
drivers/gpu/drm/xe/xe_userptr.h | 7 +
include/drm/drm_gpusvm.h | 19 +
include/drm/ttm/ttm_bo.h | 66 +
include/drm/ttm/ttm_pool.h | 46 +
include/drm/ttm/ttm_tt.h | 44 +-
38 files changed, 5044 insertions(+), 682 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 59+ messages in thread
* [PATCH v5 01/36] drm/ttm/pool: Allow backing off reclaim at the beneficial order
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 02/36] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
` (37 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Allocating at the pool's beneficial order normally uses
__GFP_RETRY_MAYFAIL to push hard for a contiguous high-order page. When
beneficial-order allocations have recently been failing, this retry just
burns CPU cycles in reclaim/compaction before falling back to a smaller
order anyway.
Add a beneficial_reclaim_backoff flag to struct ttm_operation_ctx and
plumb it through to ttm_pool_alloc_page(). When set, the beneficial
order is treated like the orders we already consider not worth stalling
for: __GFP_RECLAIM is cleared so the allocation skips reclaim/compaction
entirely, and the __GFP_NORETRY clearing / __GFP_RETRY_MAYFAIL promotion
is skipped. Together this makes the allocator back off quickly to a
smaller order instead of stalling.
This is a no-op until a caller opts in.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 12 ++++++++----
include/drm/ttm/ttm_bo.h | 7 +++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 6894536e85ce..16fd125d7375 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -160,7 +160,8 @@ static int ttm_pool_nid(struct ttm_pool *pool)
/* Allocate pages of size 1 << order with the given gfp_flags */
static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,
- unsigned int order)
+ unsigned int order,
+ bool beneficial_reclaim_backoff)
{
const unsigned int beneficial_order = ttm_pool_beneficial_order(pool);
unsigned long attr = DMA_ATTR_FORCE_CONTIGUOUS;
@@ -180,10 +181,12 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,
* Do not add latency to the allocation path for allocations orders
* device tolds us do not bring them additional performance gains.
*/
- if (order && beneficial_order && order != beneficial_order)
+ if (order && beneficial_order &&
+ (beneficial_reclaim_backoff || order != beneficial_order))
gfp_flags &= ~__GFP_RECLAIM;
- if (beneficial_order && order == beneficial_order) {
+ if (!beneficial_reclaim_backoff &&
+ beneficial_order && order == beneficial_order) {
gfp_flags &= ~__GFP_NORETRY;
gfp_flags |= __GFP_RETRY_MAYFAIL;
}
@@ -830,7 +833,8 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
if (!p) {
page_caching = ttm_cached;
allow_pools = false;
- p = ttm_pool_alloc_page(pool, gfp_flags, order);
+ p = ttm_pool_alloc_page(pool, gfp_flags, order,
+ ctx->beneficial_reclaim_backoff);
}
/* If that fails, lower the order if possible and retry. */
if (!p) {
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 53d130a02111..cd3d3980dbce 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -187,6 +187,13 @@ struct ttm_operation_ctx {
* when multiple BOs share the same reservation object @resv.
*/
bool allow_res_evict;
+ /**
+ * @beneficial_reclaim_backoff: Back off from direct reclaim at the
+ * pool's beneficial order. Useful when beneficial-order allocation has
+ * recently been failing, to avoid burning CPU cycles in
+ * reclaim/compaction before falling back to a smaller order anyway.
+ */
+ bool beneficial_reclaim_backoff;
/**
* @resv: Reservation object to be used together with
* @allow_res_evict.
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 02/36] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 03/36] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
` (36 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
TTM records the allocation order of a multi-order page in page->private at
allocation time. For pools that do not use dma_alloc the order is stored
directly, while dma_alloc pools store a struct ttm_pool_dma pointer there
instead. Drivers that do their own DMA mapping (e.g. Xe) need the per-page
order to walk a populated ttm_tt one chunk at a time, but cannot rely on
folio_order(): TTM allocates high-order pages with alloc_pages_node()
without __GFP_COMP, so they are not compound and folio_order() always
returns 0.
Expose ttm_pool_page_order_nodma(), a thin wrapper that returns the order
recorded in page->private. It is only valid for pages from a pool that does
not use dma_alloc; whether a TTM device uses dma_alloc is fixed at ttm
device init time, so callers know from their device configuration that this
helper applies. Use it from the existing internal ttm_pool_page_order() to
keep a single source of truth.
v4:
- const struct page (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 25 ++++++++++++++++++++++++-
include/drm/ttm/ttm_pool.h | 2 ++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 16fd125d7375..c6fbcdba9bdb 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -477,6 +477,29 @@ static unsigned int ttm_pool_shrink(int nid, unsigned long num_to_free)
return num_pages;
}
+/**
+ * ttm_pool_page_order_nodma() - Allocation order of a non-dma_alloc TTM page
+ * @p: The page to query.
+ *
+ * Return the allocation order that the TTM pool allocator recorded in
+ * @p->private at allocation time. This only works for pages that were
+ * allocated from a pool which does *not* use dma_alloc (i.e. pages backed by
+ * alloc_pages_node()), where TTM stores the order directly in page->private.
+ *
+ * For dma_alloc pools, page->private instead holds a struct ttm_pool_dma
+ * pointer and this helper must not be used. Whether a TTM device uses
+ * dma_alloc is fixed at ttm device init time, so callers are expected to know
+ * from their TTM device configuration that their pages are not dma_alloc
+ * backed before using this helper.
+ *
+ * Return: The allocation order of the page.
+ */
+unsigned int ttm_pool_page_order_nodma(const struct page *p)
+{
+ return p->private;
+}
+EXPORT_SYMBOL(ttm_pool_page_order_nodma);
+
/* Return the allocation order based for a page */
static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p)
{
@@ -486,7 +509,7 @@ static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p)
return dma->vaddr & ~PAGE_MASK;
}
- return p->private;
+ return ttm_pool_page_order_nodma(p);
}
/*
diff --git a/include/drm/ttm/ttm_pool.h b/include/drm/ttm/ttm_pool.h
index bb6347e5b297..429f4f987a19 100644
--- a/include/drm/ttm/ttm_pool.h
+++ b/include/drm/ttm/ttm_pool.h
@@ -94,6 +94,8 @@ long ttm_pool_backup(struct ttm_pool *pool, struct ttm_tt *ttm,
int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
const struct ttm_operation_ctx *ctx);
+unsigned int ttm_pool_page_order_nodma(const struct page *p);
+
int ttm_pool_mgr_init(void);
void ttm_pool_mgr_fini(void);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 03/36] drm/ttm: Record sub-optimal page order allocations in ttm_tt
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 04/36] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
` (35 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
When __ttm_pool_alloc() fails to allocate a chunk at the device's
beneficial order and falls back to a smaller order, the object ends up
backed by a sub-optimal set of pages. Nothing currently records this, so
a driver has no way to know an object would benefit from being re-backed
with beneficial-order pages later.
Add TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED to struct ttm_tt page_flags,
cleared at the start of every fresh allocation (in both ttm_pool_alloc()
and ttm_pool_restore_and_alloc()). Set it in __ttm_pool_alloc() when an
allocation at exactly the beneficial order fails before dropping to a
lower order.
Drivers can use this hint to queue the buffer object for later
defragmentation.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 13 +++++++++++++
include/drm/ttm/ttm_tt.h | 24 +++++++++++++++++++++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index c6fbcdba9bdb..e06bd3cf6855 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -812,6 +812,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
struct ttm_pool_alloc_state *alloc,
struct ttm_pool_tt_restore *restore)
{
+ const unsigned int beneficial_order = ttm_pool_beneficial_order(pool);
enum ttm_caching page_caching;
gfp_t gfp_flags = GFP_USER;
pgoff_t caching_divide;
@@ -862,6 +863,16 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
/* If that fails, lower the order if possible and retry. */
if (!p) {
if (order) {
+ /*
+ * Failing to allocate at the device's beneficial
+ * order means we are about to back this object
+ * with a sub-optimal (smaller order) set of
+ * pages. Record it so the driver can later try to
+ * defragment the object back to beneficial order.
+ */
+ if (beneficial_order && order == beneficial_order)
+ tt->page_flags |=
+ TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
--order;
page_caching = tt->caching;
allow_pools = true;
@@ -926,6 +937,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
if (WARN_ON(ttm_tt_is_backed_up(tt)))
return -EINVAL;
+ tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
ttm_pool_alloc_state_init(tt, &alloc);
return __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
@@ -958,6 +970,7 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
if (!restore) {
gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
+ tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
ttm_pool_alloc_state_init(tt, &alloc);
if (ctx->gfp_retry_mayfail)
gfp |= __GFP_RETRY_MAYFAIL;
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 406437ad674b..ce7533677d77 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -90,6 +90,14 @@ struct ttm_tt {
* TTM_TT_FLAG_BACKED_UP: TTM internal only. This is set if the
* struct ttm_tt has been (possibly partially) backed up.
*
+ * TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED: Set by the TTM pool allocator
+ * when at least one chunk that could have been allocated at the pool's
+ * beneficial order had to fall back to a smaller order. This indicates
+ * that a sub-optimal set of pages was chosen for this object, and can
+ * be used by drivers to queue the buffer object for later
+ * defragmentation. Drivers should access this via the
+ * ttm_tt_is_beneficial_order_failed() helper.
+ *
* TTM_TT_FLAG_PRIV_POPULATED: TTM internal only. DO NOT USE. This is
* set by TTM after ttm_tt_populate() has successfully returned, and is
* then unset when TTM calls ttm_tt_unpopulate().
@@ -101,8 +109,9 @@ struct ttm_tt {
#define TTM_TT_FLAG_EXTERNAL_MAPPABLE BIT(3)
#define TTM_TT_FLAG_DECRYPTED BIT(4)
#define TTM_TT_FLAG_BACKED_UP BIT(5)
+#define TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED BIT(6)
-#define TTM_TT_FLAG_PRIV_POPULATED BIT(6)
+#define TTM_TT_FLAG_PRIV_POPULATED BIT(7)
uint32_t page_flags;
/** @num_pages: Number of pages in the page array. */
uint32_t num_pages;
@@ -179,6 +188,19 @@ static inline void ttm_tt_clear_backed_up(struct ttm_tt *tt)
tt->page_flags &= ~TTM_TT_FLAG_BACKED_UP;
}
+/**
+ * ttm_tt_is_beneficial_order_failed() - Whether the tt is backed at a
+ * sub-optimal page order
+ * @tt: The struct ttm_tt.
+ *
+ * Return: true if the pool allocator had to fall back below the pool's
+ * beneficial order when backing this tt, false otherwise.
+ */
+static inline bool ttm_tt_is_beneficial_order_failed(const struct ttm_tt *tt)
+{
+ return tt->page_flags & TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
+}
+
/**
* ttm_tt_create
*
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 04/36] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc()
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
` (2 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 05/36] drm/ttm: Support defragmentation moves Matthew Brost
` (34 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
__ttm_pool_alloc() walks the page orders in a single loop whose body is
about to grow several defragmentation phases (reusing old pages, a move
budget, out-of-lock preallocation and fault injection). Left inline these
interleave into one deeply nested block of gotos and combinatorial
conditionals that is hard to follow and extend.
Factor the loop's working state into a struct ttm_pool_alloc_iter and
pull the per-order page acquisition and order-fallback into small phase
helpers, so the main loop reads as a short sequence of named steps. This
is a pure refactor with no functional change; subsequent patches extend
the iterator with their defrag phases rather than nesting more logic into
the loop.
v4:
- Drop restore field from iterator (Niranjana)
v5:
- Drop kernel style comment (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 157 ++++++++++++++++++++++-----------
1 file changed, 104 insertions(+), 53 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index e06bd3cf6855..a053d78191f6 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -807,18 +807,100 @@ static unsigned int ttm_pool_alloc_find_order(unsigned int highest,
return min_t(unsigned int, highest, __fls(alloc->remaining_pages));
}
+/*
+ * struct ttm_pool_alloc_iter - Working state for the __ttm_pool_alloc() loop
+ *
+ * Bundles the immutable inputs and the mutable per-order state that the
+ * allocation phase helpers share, so the main loop reads as a short sequence
+ * of named phases rather than one deeply nested block.
+ */
+struct ttm_pool_alloc_iter {
+ /* Immutable for the duration of the allocation. */
+ struct ttm_pool *pool;
+ struct ttm_tt *tt;
+ const struct ttm_operation_ctx *ctx;
+ struct ttm_pool_alloc_state *alloc;
+ unsigned int beneficial_order;
+ gfp_t gfp_flags;
+
+ /* Mutated as the loop walks the orders. */
+ unsigned int order;
+ enum ttm_caching page_caching;
+ bool allow_pools;
+ struct page *p;
+};
+
+/*
+ * Acquire a single page for the current order, leaving it in @it->p (NULL on
+ * failure). Tries a same-order pool page, then a fresh system allocation.
+ */
+static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
+{
+ struct ttm_pool_type *pt;
+
+ /* First, try to allocate a page from a pool if one exists. */
+ it->p = NULL;
+ pt = ttm_pool_select_type(it->pool, it->page_caching, it->order);
+ if (!it->p && pt && it->allow_pools)
+ it->p = ttm_pool_type_take(pt, ttm_pool_nid(it->pool));
+
+ /*
+ * If that fails or previously failed, allocate from system. Note that
+ * this also disallows additional pool allocations using write-back
+ * cached pools of the same order.
+ */
+ if (!it->p) {
+ it->page_caching = ttm_cached;
+ it->allow_pools = false;
+ it->p = ttm_pool_alloc_page(it->pool, it->gfp_flags, it->order,
+ it->ctx->beneficial_reclaim_backoff);
+ }
+}
+
+/*
+ * The current order could not be satisfied. Lower it and retry, recording a
+ * sub-optimal backing (so the driver can later re-defrag) when we drop below
+ * the beneficial order.
+ *
+ * Returns 0 to retry the (lowered) order, or a negative errno.
+ */
+static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
+{
+ if (!it->order)
+ return -ENOMEM;
+
+ /*
+ * Failing to allocate at the device's beneficial order means we are
+ * about to back this object with a sub-optimal (smaller order) set of
+ * pages. Record it so the driver can later try to defragment the object
+ * back to beneficial order.
+ */
+ if (it->beneficial_order && it->order == it->beneficial_order)
+ it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
+
+ it->order--;
+ it->page_caching = it->tt->caching;
+ it->allow_pools = true;
+
+ return 0;
+}
+
static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
const struct ttm_operation_ctx *ctx,
struct ttm_pool_alloc_state *alloc,
struct ttm_pool_tt_restore *restore)
{
- const unsigned int beneficial_order = ttm_pool_beneficial_order(pool);
- enum ttm_caching page_caching;
+ struct ttm_pool_alloc_iter it = {
+ .pool = pool,
+ .tt = tt,
+ .ctx = ctx,
+ .alloc = alloc,
+ .beneficial_order = ttm_pool_beneficial_order(pool),
+ .page_caching = tt->caching,
+ .allow_pools = true,
+ };
gfp_t gfp_flags = GFP_USER;
pgoff_t caching_divide;
- unsigned int order;
- bool allow_pools;
- struct page *p;
int r;
WARN_ON(!alloc->remaining_pages || ttm_tt_is_populated(tt));
@@ -835,59 +917,28 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
else
gfp_flags |= GFP_HIGHUSER;
- page_caching = tt->caching;
- allow_pools = true;
- for (order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc);
- alloc->remaining_pages;
- order = ttm_pool_alloc_find_order(order, alloc)) {
- struct ttm_pool_type *pt;
-
- /* First, try to allocate a page from a pool if one exists. */
- p = NULL;
- pt = ttm_pool_select_type(pool, page_caching, order);
- if (pt && allow_pools)
- p = ttm_pool_type_take(pt, ttm_pool_nid(pool));
+ it.gfp_flags = gfp_flags;
- /*
- * If that fails or previously failed, allocate from system.
- * Note that this also disallows additional pool allocations using
- * write-back cached pools of the same order. Consider removing
- * that behaviour.
- */
- if (!p) {
- page_caching = ttm_cached;
- allow_pools = false;
- p = ttm_pool_alloc_page(pool, gfp_flags, order,
- ctx->beneficial_reclaim_backoff);
- }
- /* If that fails, lower the order if possible and retry. */
- if (!p) {
- if (order) {
- /*
- * Failing to allocate at the device's beneficial
- * order means we are about to back this object
- * with a sub-optimal (smaller order) set of
- * pages. Record it so the driver can later try to
- * defragment the object back to beneficial order.
- */
- if (beneficial_order && order == beneficial_order)
- tt->page_flags |=
- TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
- --order;
- page_caching = tt->caching;
- allow_pools = true;
- continue;
- }
- r = -ENOMEM;
- goto error_free_all;
+ for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc);
+ alloc->remaining_pages;
+ it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
+ /* Acquire a page (pool / system) for this order. */
+ ttm_pool_iter_acquire_page(&it);
+ if (!it.p) {
+ r = ttm_pool_iter_lower_order(&it);
+ if (r)
+ goto error_free_all;
+ continue;
}
- r = ttm_pool_page_allocated(pool, order, p, page_caching, alloc,
- restore);
+
+ r = ttm_pool_page_allocated(pool, it.order, it.p,
+ it.page_caching, alloc, restore);
if (r)
goto error_free_page;
if (ttm_pool_restore_valid(restore)) {
- r = ttm_pool_restore_commit(restore, tt->backup, ctx, alloc);
+ r = ttm_pool_restore_commit(restore, tt->backup, ctx,
+ alloc);
if (r)
goto error_free_all;
}
@@ -903,7 +954,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
return 0;
error_free_page:
- ttm_pool_free_page(pool, page_caching, order, p, false);
+ ttm_pool_free_page(pool, it.page_caching, it.order, it.p, false);
error_free_all:
if (tt->restore)
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 05/36] drm/ttm: Support defragmentation moves
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
` (3 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 06/36] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
` (33 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Add infrastructure to let a driver re-back an already-resident BO with
fresh pages (e.g. at a more beneficial order) by reusing the normal move
machinery.
Add ctx->defrag, which makes ttm_bo_validate() skip the "current
resource already compatible" short-circuit so a move is forced even when
placement is unchanged. In ttm_bo_handle_move_mem(), when defragging a
populated BO, stash the old tt, create and populate a fresh one
(allocating new backing), and hand the old tt to the driver move
callback via bo->defrag_old_tt for copying. On success the old tt is
unpopulated and freed; if populate or the move fails, the freshly
allocated backing is discharged and the BO is restored to its original
tt and placement.
The old tt is handed off through bo->defrag_old_tt (reservation-lock
protected) rather than the operation context. The pointer describes BO
state for the duration of the move, so keeping it on the buffer object
is better layering and lets ttm_bo_move_accel_cleanup() pick it up.
Because a defrag move commonly fails (beneficial-order pages are often
unavailable) and then leaves the BO untouched on its original backing,
defer ttm_bo_unmap_virtual() for the defrag case until the new backing
has been populated and the move is about to commit. Ordinary moves still
unmap up front. This avoids needlessly zapping and refaulting every
userspace mapping on the common failure path where nothing moved.
Teach ttm_bo_move_accel_cleanup()'s ghost path about defrag: instead of
tearing the move's source tt down synchronously, hand bo->defrag_old_tt
to the ghost object so it is kept populated until the copy fence signals
and then unbound and destroyed asynchronously, while the BO keeps its
new tt. This lets a driver pipeline defrag teardown behind the GPU copy
rather than blocking on it.
This is driver-opt-in and a no-op unless ctx->defrag is set.
v4:
- Single unmap (Niranjana)
- Warn on defrag_old_tt in TTM memcpy (Niranjana)
- comment around -ENOMEM in ttm_pool_iter_lower_order (Niranjana)
- warn on defrag in ttm_bo_bounce_temp_buffer (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 90 ++++++++++++++++++++++++++++---
drivers/gpu/drm/ttm/ttm_bo_util.c | 18 +++++--
drivers/gpu/drm/ttm/ttm_pool.c | 10 +++-
include/drm/ttm/ttm_bo.h | 17 ++++++
4 files changed, 123 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 53c68e29ebc2..a32b78c80989 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -125,49 +125,119 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
{
struct ttm_device *bdev = bo->bdev;
bool old_use_tt, new_use_tt;
+ bool defrag;
int ret;
old_use_tt = !bo->resource || ttm_manager_type(bdev, bo->resource->mem_type)->use_tt;
new_use_tt = ttm_manager_type(bdev, mem->mem_type)->use_tt;
- ttm_bo_unmap_virtual(bo);
+ /*
+ * Only the BO that is the actual defrag target (moved in place via
+ * ttm_bo_validate(), evict == false) is being defragmented. The same
+ * ctx->defrag is threaded into evictions triggered while allocating
+ * that target's new backing (ttm_bo_evict_alloc()), so guard against
+ * an unrelated victim BO (evict == true) being misclassified as a
+ * defrag move and needlessly reallocating its backing.
+ */
+ defrag = ctx->defrag && !evict && new_use_tt && bo->ttm &&
+ ttm_tt_is_populated(bo->ttm);
/*
* Create and bind a ttm if required.
*/
if (new_use_tt) {
+ struct ttm_tt *defrag_old_tt = NULL;
+
+ /*
+ * For a defrag move, stash the current populated tt and force a
+ * fresh one to be created and populated (at beneficial order).
+ * The old tt is handed to the driver move callback to copy the
+ * contents from, and freed once the move completes.
+ */
+ if (defrag) {
+ defrag_old_tt = bo->ttm;
+ bo->ttm = NULL;
+ }
+
/* Zero init the new TTM structure if the old location should
* have used one as well.
*/
- ret = ttm_tt_create(bo, old_use_tt);
- if (ret)
+ ret = ttm_tt_create(bo, old_use_tt && !defrag_old_tt);
+ if (ret) {
+ if (defrag_old_tt)
+ bo->ttm = defrag_old_tt;
goto out_err;
+ }
- if (mem->mem_type != TTM_PL_SYSTEM) {
+ if (defrag_old_tt || mem->mem_type != TTM_PL_SYSTEM) {
ret = ttm_bo_populate(bo, ctx);
- if (ret)
+ if (ret) {
+ /*
+ * Discharge the freshly allocated backing and
+ * leave the BO on its original tt/placement.
+ */
+ if (defrag_old_tt) {
+ ttm_tt_destroy(bo->bdev, bo->ttm);
+ bo->ttm = defrag_old_tt;
+ }
goto out_err;
+ }
}
+
+ bo->defrag_old_tt = defrag_old_tt;
}
ret = dma_resv_reserve_fences(bo->base.resv, 1);
if (ret)
goto out_err;
+ /*
+ * Only tear down mappings after populate succeeds, as population can
+ * commonly fail during defragmentation moves.
+ */
+ ttm_bo_unmap_virtual(bo);
+
ret = bdev->funcs->move(bo, evict, ctx, mem, hop);
if (ret) {
- if (ret == -EMULTIHOP)
+ if (ret == -EMULTIHOP) {
+ /*
+ * A defrag move targets the BO's current placement and
+ * must complete in a single hop. A driver requesting a
+ * bounce here is unsupported: restore the original
+ * backing and fail the defrag rather than retrying the
+ * multihop with ctx->defrag still set, which would
+ * misclassify the bounce as another defrag move and
+ * overwrite/leak bo->defrag_old_tt.
+ */
+ if (unlikely(defrag)) {
+ WARN_ON_ONCE(1);
+ ret = -EINVAL;
+ goto out_err;
+ }
return ret;
+ }
goto out_err;
}
+ if (bo->defrag_old_tt) {
+ ttm_tt_unpopulate(bo->bdev, bo->defrag_old_tt);
+ ttm_tt_destroy(bo->bdev, bo->defrag_old_tt);
+ bo->defrag_old_tt = NULL;
+ }
+
ctx->bytes_moved += bo->base.size;
return 0;
out_err:
- if (!old_use_tt)
+ if (bo->defrag_old_tt) {
+ /* Failed defrag move: restore the original backing. */
ttm_bo_tt_destroy(bo);
+ bo->ttm = bo->defrag_old_tt;
+ bo->defrag_old_tt = NULL;
+ } else if (!old_use_tt) {
+ ttm_bo_tt_destroy(bo);
+ }
return ret;
}
@@ -339,6 +409,10 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo,
struct ttm_resource *hop_mem;
int ret;
+ /* We shouldn't be bouncing temp buffers during a defrag */
+ if (WARN_ON(ctx->defrag))
+ return -EINVAL;
+
hop_placement.num_placement = 1;
hop_placement.placement = hop;
@@ -1090,7 +1164,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
force_space = false;
do {
/* Check whether we need to move buffer. */
- if (bo->resource &&
+ if (bo->resource && !ctx->defrag &&
ttm_resource_compatible(bo->resource, placement,
force_space))
return 0;
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 8c5de3a0506f..21a25048d64d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -161,7 +161,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
bool clear;
int ret = 0;
- if (WARN_ON(!src_mem))
+ if (WARN_ON(!src_mem) || WARN_ON(bo->defrag_old_tt))
return -EINVAL;
src_man = ttm_manager_type(bdev, src_mem->mem_type);
@@ -653,10 +653,22 @@ static int ttm_bo_move_to_ghost(struct ttm_buffer_object *bo,
* bo to be unbound and destroyed.
*/
- if (dst_use_tt)
+ if (bo->defrag_old_tt) {
+ /*
+ * Defrag move: @bo already points at the freshly allocated,
+ * beneficial-order tt that the move copied into. Hand the old
+ * tt (the move's source) to the ghost so it is kept populated
+ * until @fence signals and then unbound and destroyed, instead
+ * of being torn down synchronously. @bo keeps its new tt.
+ */
+ ghost_obj->ttm = bo->defrag_old_tt;
+ ghost_obj->defrag_old_tt = NULL;
+ bo->defrag_old_tt = NULL;
+ } else if (dst_use_tt) {
ghost_obj->ttm = NULL;
- else
+ } else {
bo->ttm = NULL;
+ }
dma_resv_unlock(&ghost_obj->base._resv);
ttm_bo_put(ghost_obj);
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index a053d78191f6..182e84efcd92 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -875,9 +875,17 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
* pages. Record it so the driver can later try to defragment the object
* back to beneficial order.
*/
- if (it->beneficial_order && it->order == it->beneficial_order)
+ if (it->beneficial_order && it->order == it->beneficial_order) {
it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
+ /*
+ * If we are defragmenting, we only want beneficial_order, so
+ * any failure is treated as -ENOMEM.
+ */
+ if (it->ctx->defrag)
+ return -ENOMEM;
+ }
+
it->order--;
it->page_caching = it->tt->caching;
it->allow_pools = true;
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index cd3d3980dbce..c5205b8e8f10 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -135,6 +135,16 @@ struct ttm_buffer_object {
* reservation lock.
*/
struct sg_table *sg;
+
+ /**
+ * @defrag_old_tt: Used internally during a defrag move to hand the BO's
+ * previous, populated struct ttm_tt to the driver's move callback so
+ * that it can copy the contents into the freshly allocated
+ * beneficial-order backing. Set by TTM, consumed by the driver; the old
+ * tt is freed (or restored on failure) by TTM once the move completes.
+ * Protected by the reservation lock.
+ */
+ struct ttm_tt *defrag_old_tt;
};
#define TTM_BO_MAP_IOMEM_MASK 0x80
@@ -194,6 +204,13 @@ struct ttm_operation_ctx {
* reclaim/compaction before falling back to a smaller order anyway.
*/
bool beneficial_reclaim_backoff;
+ /**
+ * @defrag: Defragmentation pass. Attempt a move even when the bo's
+ * current resource is already compatible with the requested placement,
+ * so that the backing store can be reallocated at the pool's beneficial
+ * order.
+ */
+ bool defrag;
/**
* @resv: Reservation object to be used together with
* @allow_res_evict.
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 06/36] drm/ttm: Add fault injection for beneficial-order allocation failures
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
` (4 preceding siblings ...)
2026-12-02 23:32 ` [PATCH v5 05/36] drm/ttm: Support defragmentation moves Matthew Brost
@ 2026-12-02 23:32 ` 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
` (32 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Add a beneficial_order_fault_inject debugfs fault attribute, mirroring
backup_fault_inject, that forces allocation at (or above) the device's
beneficial order to fail in __ttm_pool_alloc(). When triggered, both the
pool take and the system page allocation are skipped for that order, so
the allocation falls into the existing lower-the-order path that sets
the TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED tt page flag (and bails out with
-ENOMEM for defrag moves).
This lets the TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED tracking and the
driver-side defrag path be exercised deterministically, without having to
drive the system into real memory fragmentation to provoke a sub-optimal
backing.
The knob is registered at
/sys/kernel/debug/ttm/beneficial_order_fault_inject and compiles out
when CONFIG_FAULT_INJECTION is disabled.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 35 ++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 182e84efcd92..4e146798848a 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -53,6 +53,7 @@
#ifdef CONFIG_FAULT_INJECTION
#include <linux/fault-inject.h>
static DECLARE_FAULT_ATTR(backup_fault_inject);
+static DECLARE_FAULT_ATTR(beneficial_order_fault_inject);
/*
* Exposed to ttm_backup.c so a mid-compound subpage can be made to fail
@@ -827,21 +828,34 @@ struct ttm_pool_alloc_iter {
unsigned int order;
enum ttm_caching page_caching;
bool allow_pools;
+ bool fail_beneficial;
struct page *p;
};
/*
* Acquire a single page for the current order, leaving it in @it->p (NULL on
- * failure). Tries a same-order pool page, then a fresh system allocation.
+ * failure). Tries a same-order pool page, then a fresh system allocation. Fault
+ * injection can force the beneficial-order paths to "fail".
*/
static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
{
struct ttm_pool_type *pt;
- /* First, try to allocate a page from a pool if one exists. */
it->p = NULL;
+
+ /*
+ * Fault injection: pretend allocation at (or above) the device's
+ * beneficial order failed, forcing a sub-optimal backing. Exercises the
+ * beneficial_order_failed tracking and the driver defrag path without
+ * driving the system into real fragmentation.
+ */
+ it->fail_beneficial = IS_ENABLED(CONFIG_FAULT_INJECTION) &&
+ it->beneficial_order && it->order >= it->beneficial_order &&
+ should_fail(&beneficial_order_fault_inject, 1);
+
+ /* First, try to allocate a page from a pool if one exists. */
pt = ttm_pool_select_type(it->pool, it->page_caching, it->order);
- if (!it->p && pt && it->allow_pools)
+ if (!it->p && pt && it->allow_pools && !it->fail_beneficial)
it->p = ttm_pool_type_take(pt, ttm_pool_nid(it->pool));
/*
@@ -849,7 +863,7 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
* this also disallows additional pool allocations using write-back
* cached pools of the same order.
*/
- if (!it->p) {
+ if (!it->p && !it->fail_beneficial) {
it->page_caching = ttm_cached;
it->allow_pools = false;
it->p = ttm_pool_alloc_page(it->pool, it->gfp_flags, it->order,
@@ -866,6 +880,9 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
*/
static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
{
+ bool at_beneficial = it->beneficial_order &&
+ it->order == it->beneficial_order;
+
if (!it->order)
return -ENOMEM;
@@ -875,7 +892,7 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
* pages. Record it so the driver can later try to defragment the object
* back to beneficial order.
*/
- if (it->beneficial_order && it->order == it->beneficial_order) {
+ if (it->fail_beneficial || at_beneficial) {
it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
/*
@@ -886,7 +903,10 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
return -ENOMEM;
}
- it->order--;
+ if (it->fail_beneficial)
+ it->order = it->beneficial_order - 1;
+ else
+ it->order--;
it->page_caching = it->tt->caching;
it->allow_pools = true;
@@ -1623,6 +1643,9 @@ int ttm_pool_mgr_init(void)
#ifdef CONFIG_FAULT_INJECTION
fault_create_debugfs_attr("backup_fault_inject", ttm_debugfs_root,
&backup_fault_inject);
+ fault_create_debugfs_attr("beneficial_order_fault_inject",
+ ttm_debugfs_root,
+ &beneficial_order_fault_inject);
#endif
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 07/36] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore
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
` (5 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 08/36] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
` (31 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
__ttm_pool_alloc() fills a tt with a non-increasing order walk starting
at MAX_PAGE_ORDER, so every order-k chunk lands at a 2^k-aligned offset
in the tt. ttm_pool_restore_and_alloc() however may be interrupted
(e.g. -EINTR from ttm_pool_restore_commit()) and later resume
__ttm_pool_alloc() at a non-zero offset. The walk then restarts at
MAX_PAGE_ORDER, bounded only by the number of remaining pages, and can
place a large chunk at an unaligned offset (e.g. an order-9 chunk at
offset 256 after an order-8 fallback).
That is harmless today, but upcoming defragmentation support relies on
chunks being self-aligned to borrow whole chunks from an old tt at the
same offset. Cap the starting order by the alignment of the offset being
resumed at, which keeps the invariant at negligible cost: at worst an
interrupted restore misses a single larger order.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 4e146798848a..5c7fec62aa30 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -927,6 +927,8 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
.page_caching = tt->caching,
.allow_pools = true,
};
+ pgoff_t off = tt->num_pages - alloc->remaining_pages;
+ unsigned int start_order = MAX_PAGE_ORDER;
gfp_t gfp_flags = GFP_USER;
pgoff_t caching_divide;
int r;
@@ -947,7 +949,17 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
it.gfp_flags = gfp_flags;
- for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc);
+ /*
+ * Keep chunks self-aligned (an order-k chunk at a 2^k-aligned offset):
+ * the order walk below is non-increasing, so that holds as long as it
+ * starts at an order @off is aligned to. @off is only non-zero when
+ * resuming an interrupted restore, which would otherwise restart at
+ * MAX_PAGE_ORDER and could place a large chunk at an unaligned offset.
+ */
+ if (off)
+ start_order = min_t(unsigned int, start_order, __ffs(off));
+
+ for (it.order = ttm_pool_alloc_find_order(start_order, alloc);
alloc->remaining_pages;
it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
/* Acquire a page (pool / system) for this order. */
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 08/36] drm/ttm: Harvest beneficial-order pages on defragmentation moves
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
` (6 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 09/36] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
` (30 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
A defragmentation move relocates a populated tt into a freshly allocated
one so that sub-beneficial-order chunks can be upgraded to the device's
beneficial order. Previously, if allocation could not complete entirely
at beneficial order, the move failed and all progress was discarded.
Instead, once allocation has successfully upgraded part of the object,
the remainder of the old tt is harvested to complete the new tt. Thread
the BO's old, still-populated tt into the page allocator via a new
ttm_operation_ctx::defrag_old_tt. While allocation is still proceeding,
any existing chunk already at (or above) the beneficial order is reused
directly instead of being reallocated. If allocation later has to fall
back below beneficial_order after making partial progress, the remainder
of the old tt is harvested instead of failing the move. This preserves
the beneficial-order upgrades already made while leaving the rest of the
object unchanged, allowing subsequent defragmentation attempts to make
additional forward progress.
Harvesting only borrows the pages; they remain owned by the old tt until
the move commits. This keeps every unwind path non-destructive: if the
(re)allocation or the move later fails, the new tt is torn down without
freeing the borrowed pages and the old tt is restored fully intact.
Ownership of the shared pages is transferred to the new tt only once the
move has committed. ttm_tt_defrag_disown_borrowed() implements both
directions of the transfer by clearing a tt's slots for every page it
shares with the other tt (same struct page at the same index), so that
tt's teardown leaves the shared pages alone and each page is freed
exactly once by its owner:
- on the alloc unwind and the failed-move paths, the new tt disowns the
borrowed pages, leaving the old tt as the sole owner;
- on the successful-move paths (synchronous teardown and the pipelined
ghost-object teardown), the old tt disowns the now-transferred pages,
leaving the new tt as the sole owner.
Detecting shared pages by same-index struct page identity needs no extra
per-tt bookkeeping, since two distinct allocations never alias. This is
safe with drivers, such as Xe, that build their own per-tt sg table and
DMA-map it independently: each tt maps and unmaps its own sg, so sharing
the underlying pages between tts is DMA-clean.
This is a no-op unless ctx->defrag_old_tt is set, which only happens on a
defragmentation move.
v4:
- Check for backup handle in ttm_pool_harvest_remaining (Niranjana)
v5:
- Harden harvest code around index / order assumptions (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 20 ++-
drivers/gpu/drm/ttm/ttm_bo_util.c | 5 +
drivers/gpu/drm/ttm/ttm_pool.c | 259 ++++++++++++++++++++++++++++--
drivers/gpu/drm/ttm/ttm_tt.c | 67 ++++++++
include/drm/ttm/ttm_bo.h | 12 ++
include/drm/ttm/ttm_tt.h | 2 +
6 files changed, 348 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index a32b78c80989..67a97a5e0dfb 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -171,7 +171,14 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
}
if (defrag_old_tt || mem->mem_type != TTM_PL_SYSTEM) {
+ /*
+ * Let the page allocator harvest already
+ * beneficial-order chunks out of the old tt to back
+ * the new one, rather than reallocating them.
+ */
+ ctx->defrag_old_tt = defrag_old_tt;
ret = ttm_bo_populate(bo, ctx);
+ ctx->defrag_old_tt = NULL;
if (ret) {
/*
* Discharge the freshly allocated backing and
@@ -221,6 +228,12 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
}
if (bo->defrag_old_tt) {
+ /*
+ * Successful defrag move: any pages the new tt borrowed from the
+ * old tt are now owned by the new tt. Disown them from the old
+ * tt before it is torn down so they are not freed.
+ */
+ ttm_tt_defrag_disown_borrowed(bo->defrag_old_tt, bo->ttm);
ttm_tt_unpopulate(bo->bdev, bo->defrag_old_tt);
ttm_tt_destroy(bo->bdev, bo->defrag_old_tt);
bo->defrag_old_tt = NULL;
@@ -231,7 +244,12 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
out_err:
if (bo->defrag_old_tt) {
- /* Failed defrag move: restore the original backing. */
+ /*
+ * Failed defrag move: drop any pages the new tt borrowed from
+ * the old tt (still owned by the old tt) before destroying the
+ * new tt, then restore the original backing.
+ */
+ ttm_tt_defrag_disown_borrowed(bo->ttm, bo->defrag_old_tt);
ttm_bo_tt_destroy(bo);
bo->ttm = bo->defrag_old_tt;
bo->defrag_old_tt = NULL;
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 21a25048d64d..4799b06fbb1a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -660,7 +660,12 @@ static int ttm_bo_move_to_ghost(struct ttm_buffer_object *bo,
* tt (the move's source) to the ghost so it is kept populated
* until @fence signals and then unbound and destroyed, instead
* of being torn down synchronously. @bo keeps its new tt.
+ *
+ * Any pages the new tt borrowed from the old tt are now owned by
+ * the new tt; disown them from the old tt so the ghost teardown
+ * leaves them alone.
*/
+ ttm_tt_defrag_disown_borrowed(bo->defrag_old_tt, bo->ttm);
ghost_obj->ttm = bo->defrag_old_tt;
ghost_obj->defrag_old_tt = NULL;
bo->defrag_old_tt = NULL;
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 5c7fec62aa30..c60be4a013f1 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -808,6 +808,160 @@ static unsigned int ttm_pool_alloc_find_order(unsigned int highest,
return min_t(unsigned int, highest, __fls(alloc->remaining_pages));
}
+/*
+ * Defragmentation page harvesting.
+ *
+ * A defrag move relocates a populated tt into a freshly allocated one in order
+ * to upgrade sub-beneficial-order chunks to the device's beneficial order.
+ * Chunks in the old tt (ctx->defrag_old_tt) that are ALREADY at the beneficial
+ * order do not need to be reallocated: their physical pages can simply be
+ * transferred ("harvested") into the new tt at the same offset, avoiding the
+ * alloc/free churn that is significant for large buffers.
+ *
+ * Harvesting only borrows the pages: the new tt simply references the old tt's
+ * pages, which remain owned by the old tt. This keeps the unwind paths simple -
+ * if the (re)allocation or the move later fails, the new tt is torn down without
+ * freeing the borrowed pages and the old tt is restored fully intact. Ownership
+ * of the shared pages is transferred to the new tt only once the move has
+ * committed, via ttm_tt_defrag_disown_borrowed() (see ttm_tt.c).
+ */
+
+/*
+ * Return the allocation order of the old tt chunk whose head sits at @off, or 0
+ * if the slot is empty / backed up. @cursor monotonically tracks the old chunk
+ * boundary and must be advanced past every offset that has already been
+ * queried; a page order may only be read from a chunk head page, hence the lazy
+ * walk.
+ *
+ * Old tt chunks are self-aligned (see __ttm_pool_alloc()) and defrag only ever
+ * advances @off by whole old chunks or by fresh chunks at least as large as the
+ * old chunks they replace, so @off is always an old chunk boundary. Should that
+ * invariant ever break, borrowing from @off would split an old chunk (treating
+ * its tail pages as order-0 chunks) and corrupt page ownership between the old
+ * and new tt, so fail the move instead.
+ *
+ * Returns: the old chunk order, or -EINVAL if @off is not an old chunk head.
+ */
+static int ttm_pool_defrag_old_order(struct ttm_pool *pool,
+ struct ttm_tt *old_tt,
+ pgoff_t off, pgoff_t *cursor)
+{
+ struct page *p;
+
+ while (*cursor < off) {
+ p = old_tt->pages[*cursor];
+ *cursor += (!p || ttm_backup_page_ptr_is_handle(p)) ? 1 :
+ 1UL << ttm_pool_page_order(pool, p);
+ }
+
+ if (WARN_ON_ONCE(*cursor != off))
+ return -EINVAL;
+
+ p = old_tt->pages[off];
+ if (!p || ttm_backup_page_ptr_is_handle(p))
+ return 0;
+
+ return ttm_pool_page_order(pool, p);
+}
+
+/*
+ * Borrow an already beneficial-order chunk from the old tt into @alloc. The
+ * pages stay owned by the old tt until the move commits.
+ */
+static int ttm_pool_harvest_page(struct ttm_tt *old_tt, unsigned int order,
+ pgoff_t off, struct ttm_pool_alloc_state *alloc)
+{
+ pgoff_t nr = 1UL << order;
+ int r;
+
+ /*
+ * A harvested chunk keeps the (same) bo's caching, so the deferred
+ * caching range is consistent here; flush it before committing, exactly
+ * like the caching-consistent path in ttm_pool_page_allocated().
+ */
+ r = ttm_pool_apply_caching(alloc);
+ if (r)
+ return r;
+
+ /*
+ * The borrowed chunk's page pointers (consecutive struct pages of one
+ * compound allocation) and dma addresses already sit contiguously in
+ * the old tt at @off. Copy the whole run with memcpy() instead of the
+ * per-page increment loop in ttm_pool_allocated_page_commit(): for a
+ * large defrag the borrowed pages dominate the new tt, so this turns
+ * the populate fill from O(num_pages) individual stores into a handful
+ * of bulk copies.
+ */
+ memcpy(alloc->pages, &old_tt->pages[off], nr * sizeof(*alloc->pages));
+ alloc->pages += nr;
+ alloc->remaining_pages -= nr;
+
+ if (alloc->dma_addr) {
+ memcpy(alloc->dma_addr, &old_tt->dma_address[off],
+ nr * sizeof(*alloc->dma_addr));
+ alloc->dma_addr += nr;
+ }
+
+ alloc->caching_divide = alloc->pages;
+
+ return 0;
+}
+
+static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
+ struct ttm_tt *old_tt, pgoff_t off,
+ pgoff_t *cursor,
+ struct ttm_pool_alloc_state *alloc)
+{
+ /*
+ * @off is always an old-tt chunk head here, never a tail page. This
+ * holds because:
+ * - Old chunks are self-aligned: the order walk in __ttm_pool_alloc()
+ * is non-increasing and starts at an order the current offset is
+ * aligned to, so an order-k chunk sits at a 2^k-aligned offset.
+ * - Fresh defrag allocations are only made where the old chunk is
+ * below the beneficial order, at an order >= the beneficial order
+ * and aligned to it, so they cover whole old chunks and never stop
+ * in the middle of one; old chunks at or above the beneficial order
+ * are always harvested whole by ttm_pool_iter_reuse_old().
+ * ttm_pool_defrag_old_order() verifies this against @cursor and fails
+ * the move rather than ever borrowing a tail page.
+ */
+ while (alloc->remaining_pages) {
+ int order = ttm_pool_defrag_old_order(pool, old_tt, off,
+ cursor);
+ pgoff_t nr;
+ int r;
+
+ if (order < 0)
+ return order;
+ nr = 1UL << order;
+
+ r = ttm_pool_harvest_page(old_tt, order, off, alloc);
+ if (r)
+ return r;
+
+ off += nr;
+ }
+
+ return 0;
+}
+
+/**
+ * enum ttm_pool_iter_action - Outcome of a per-order allocation phase
+ * @TTM_POOL_ITER_FILL: A page (@it->p) was acquired; proceed to fill it in.
+ * @TTM_POOL_ITER_RETRY: Loop state was adjusted (e.g. order lowered or a chunk
+ * harvested); re-enter the loop body for the next order.
+ * @TTM_POOL_ITER_STOP: The allocation is complete; stop the loop.
+ *
+ * Phase helpers return one of these (>= 0) on success, or a negative errno on
+ * failure (the caller then unwinds via error_free_all).
+ */
+enum ttm_pool_iter_action {
+ TTM_POOL_ITER_FILL,
+ TTM_POOL_ITER_RETRY,
+ TTM_POOL_ITER_STOP,
+};
+
/*
* struct ttm_pool_alloc_iter - Working state for the __ttm_pool_alloc() loop
*
@@ -821,6 +975,7 @@ struct ttm_pool_alloc_iter {
struct ttm_tt *tt;
const struct ttm_operation_ctx *ctx;
struct ttm_pool_alloc_state *alloc;
+ struct ttm_tt *defrag_old_tt;
unsigned int beneficial_order;
gfp_t gfp_flags;
@@ -829,9 +984,52 @@ struct ttm_pool_alloc_iter {
enum ttm_caching page_caching;
bool allow_pools;
bool fail_beneficial;
+ unsigned int alloc_count;
+ pgoff_t old_cursor;
struct page *p;
};
+/*
+ * Defrag move: reuse an already beneficial-order chunk from the old tt at this
+ * offset rather than reallocating it. Harvest whatever order the old chunk has
+ * (>= beneficial order), which may exceed the order the new tt would otherwise
+ * pick. An order below beneficial_order is only reused for the unaligned tail
+ * (where there is no benefit to reallocating). Only borrows the pages; the alloc
+ * unwind path can drop them again.
+ *
+ * Returns TTM_POOL_ITER_RETRY when a chunk was harvested, TTM_POOL_ITER_FILL to
+ * fall through to a fresh allocation, or a negative errno.
+ */
+static int ttm_pool_iter_reuse_old(struct ttm_pool_alloc_iter *it)
+{
+ int harvest_order;
+ pgoff_t off;
+ int r;
+
+ if (!it->defrag_old_tt || !it->beneficial_order)
+ return TTM_POOL_ITER_FILL;
+
+ off = it->tt->num_pages - it->alloc->remaining_pages;
+ harvest_order = ttm_pool_defrag_old_order(it->pool, it->defrag_old_tt,
+ off, &it->old_cursor);
+ if (harvest_order < 0)
+ return harvest_order;
+
+ if (harvest_order < it->beneficial_order &&
+ it->order >= it->beneficial_order)
+ return TTM_POOL_ITER_FILL;
+
+ it->order = harvest_order;
+ r = ttm_pool_harvest_page(it->defrag_old_tt, it->order, off, it->alloc);
+ if (r)
+ return r;
+
+ it->page_caching = it->tt->caching;
+ it->allow_pools = true;
+
+ return TTM_POOL_ITER_RETRY;
+}
+
/*
* Acquire a single page for the current order, leaving it in @it->p (NULL on
* failure). Tries a same-order pool page, then a fresh system allocation. Fault
@@ -874,9 +1072,10 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
/*
* The current order could not be satisfied. Lower it and retry, recording a
* sub-optimal backing (so the driver can later re-defrag) when we drop below
- * the beneficial order.
+ * the beneficial order. For a defrag move that has already made partial
+ * progress, harvest the remaining old pages and stop instead.
*
- * Returns 0 to retry the (lowered) order, or a negative errno.
+ * Returns TTM_POOL_ITER_RETRY, TTM_POOL_ITER_STOP, or a negative errno.
*/
static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
{
@@ -886,21 +1085,30 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
if (!it->order)
return -ENOMEM;
- /*
- * Failing to allocate at the device's beneficial order means we are
- * about to back this object with a sub-optimal (smaller order) set of
- * pages. Record it so the driver can later try to defragment the object
- * back to beneficial order.
- */
if (it->fail_beneficial || at_beneficial) {
it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
- /*
- * If we are defragmenting, we only want beneficial_order, so
- * any failure is treated as -ENOMEM.
- */
- if (it->ctx->defrag)
+ if (it->alloc_count && it->defrag_old_tt) {
+ pgoff_t off = it->tt->num_pages -
+ it->alloc->remaining_pages;
+ int r;
+
+ r = ttm_pool_harvest_remaining(it->pool,
+ it->defrag_old_tt, off,
+ &it->old_cursor,
+ it->alloc);
+ if (r)
+ return r;
+
+ return TTM_POOL_ITER_STOP;
+ } else if (it->defrag_old_tt) {
+ /*
+ * If we are defragmenting, we only want
+ * beneficial_order, so any failure is treated as
+ * -ENOMEM.
+ */
return -ENOMEM;
+ }
}
if (it->fail_beneficial)
@@ -910,7 +1118,7 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
it->page_caching = it->tt->caching;
it->allow_pools = true;
- return 0;
+ return TTM_POOL_ITER_RETRY;
}
static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
@@ -923,6 +1131,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
.tt = tt,
.ctx = ctx,
.alloc = alloc,
+ .defrag_old_tt = restore ? NULL : ctx->defrag_old_tt,
.beneficial_order = ttm_pool_beneficial_order(pool),
.page_caching = tt->caching,
.allow_pools = true,
@@ -955,6 +1164,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
* starts at an order @off is aligned to. @off is only non-zero when
* resuming an interrupted restore, which would otherwise restart at
* MAX_PAGE_ORDER and could place a large chunk at an unaligned offset.
+ * Defrag relies on this to borrow whole old chunks.
*/
if (off)
start_order = min_t(unsigned int, start_order, __ffs(off));
@@ -962,13 +1172,22 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
for (it.order = ttm_pool_alloc_find_order(start_order, alloc);
alloc->remaining_pages;
it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
+ /* Reuse an already beneficial-order chunk from the old tt. */
+ r = ttm_pool_iter_reuse_old(&it);
+ if (r < 0)
+ goto error_free_all;
+ if (r == TTM_POOL_ITER_RETRY)
+ continue;
+
/* Acquire a page (pool / system) for this order. */
ttm_pool_iter_acquire_page(&it);
if (!it.p) {
r = ttm_pool_iter_lower_order(&it);
- if (r)
+ if (r < 0)
goto error_free_all;
- continue;
+ if (r == TTM_POOL_ITER_RETRY)
+ continue;
+ break; /* TTM_POOL_ITER_STOP */
}
r = ttm_pool_page_allocated(pool, it.order, it.p,
@@ -982,6 +1201,8 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
if (r)
goto error_free_all;
}
+
+ it.alloc_count++;
}
r = ttm_pool_apply_caching(alloc);
@@ -1000,6 +1221,12 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
if (tt->restore)
return r;
+ /*
+ * Drop any pages borrowed from the old tt during a defrag move: they are
+ * still owned by the old tt and must not be freed here.
+ */
+ ttm_tt_defrag_disown_borrowed(tt, it.defrag_old_tt);
+
caching_divide = alloc->caching_divide - tt->pages;
ttm_pool_free_range(pool, tt, tt->caching, 0, caching_divide);
ttm_pool_free_range(pool, tt, ttm_cached, caching_divide,
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index b645a1818184..2388ff794a59 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -450,6 +450,73 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
}
EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_tt_unpopulate);
+/**
+ * ttm_tt_defrag_disown_borrowed() - Drop borrowed defrag pages from a tt
+ * @tt: The tt to drop the borrowed page references from.
+ * @src: The tt the pages may have been harvested from, or NULL.
+ *
+ * During a defragmentation move the freshly (re)allocated tt may harvest
+ * already beneficial-order chunks from the BO's old tt, sharing the underlying
+ * pages instead of reallocating them. Until the move commits these pages stay
+ * owned by the old tt. Clearing a tt's slots for every page it shares with
+ * @src (the same struct page at the same index) makes that tt's teardown leave
+ * the shared pages alone, so they are freed exactly once by their owner.
+ *
+ * This is used both to unwind a failed defrag move (disown the borrowed pages
+ * from the new tt, leaving the old tt intact) and to commit a successful one
+ * (disown the now-transferred pages from the old tt, leaving them owned by the
+ * new tt).
+ */
+void ttm_tt_defrag_disown_borrowed(struct ttm_tt *tt, const struct ttm_tt *src)
+{
+ pgoff_t i = 0, run_start = 0;
+ bool in_run = false;
+
+ if (!tt || !src)
+ return;
+
+ /*
+ * Borrowing happens at chunk granularity: a borrowed chunk shares the
+ * same struct page on both tts across its whole allocation order, while
+ * a non-borrowed chunk differs across its whole order. Stride by @src's
+ * chunk order instead of walking every page, coalescing the borrowed
+ * (matching) chunks into runs and clearing each run with a single
+ * memset rather than a per-page store. @src is a fully populated,
+ * non-dma_alloc tt (the defrag path), so its page order is recorded in
+ * page->private and read via ttm_pool_page_order_nodma().
+ */
+ while (i < tt->num_pages) {
+ struct page *sp = src->pages[i];
+ unsigned int order = sp ? ttm_pool_page_order_nodma(sp) : 0;
+ pgoff_t nr = 1UL << order;
+
+ if (sp && tt->pages[i] == sp) {
+ if (!in_run) {
+ run_start = i;
+ in_run = true;
+ }
+ } else if (in_run) {
+ memset(&tt->pages[run_start], 0,
+ (i - run_start) * sizeof(*tt->pages));
+ if (tt->dma_address)
+ memset(&tt->dma_address[run_start], 0,
+ (i - run_start) *
+ sizeof(*tt->dma_address));
+ in_run = false;
+ }
+
+ i += nr;
+ }
+
+ if (in_run) {
+ memset(&tt->pages[run_start], 0,
+ (i - run_start) * sizeof(*tt->pages));
+ if (tt->dma_address)
+ memset(&tt->dma_address[run_start], 0,
+ (i - run_start) * sizeof(*tt->dma_address));
+ }
+}
+
#ifdef CONFIG_DEBUG_FS
/* Test the shrinker functions and dump the result */
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index c5205b8e8f10..22d12fea6f3c 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -211,6 +211,18 @@ struct ttm_operation_ctx {
* order.
*/
bool defrag;
+ /**
+ * @defrag_old_tt: During a defragmentation move, the bo's existing
+ * (populated) tt that is being relocated. The page allocator may
+ * harvest already beneficial-order chunks from this tt to back the new
+ * tt instead of reallocating them, avoiding alloc/free churn for large
+ * buffers. Harvested pages are only borrowed: they stay owned by
+ * @defrag_old_tt until the move commits, at which point
+ * ttm_tt_defrag_disown_borrowed() clears the old tt's slots for the
+ * transferred pages so they are not freed when the old tt is torn down.
+ * NULL for non-defrag operations.
+ */
+ struct ttm_tt *defrag_old_tt;
/**
* @resv: Reservation object to be used together with
* @allow_res_evict.
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index ce7533677d77..55c35bcf134d 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -284,6 +284,8 @@ int ttm_tt_populate(struct ttm_device *bdev, struct ttm_tt *ttm,
*/
void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm);
+void ttm_tt_defrag_disown_borrowed(struct ttm_tt *tt, const struct ttm_tt *src);
+
/**
* ttm_tt_mark_for_clear - Mark pages for clearing on populate.
*
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 09/36] drm/ttm: Bound page (re)allocation per defragmentation move
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
` (7 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 10/36] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
` (29 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
A defragmentation move reallocates an object's backing at the device's
beneficial order and harvests whatever the allocator cannot upgrade from
the old tt. For a very large object this can reallocate (and have the
driver re-copy) the entire backing in one move, which is expensive and
can stall concurrent work for an unbounded stretch.
Add an optional per-move byte budget so a large object can be upgraded in
slices across successive moves. Plumb a new
ttm_operation_ctx::defrag_bytes_remaining through to the pool allocator:
only pages actually (re)allocated at the beneficial order are charged
against it; pages harvested (borrowed) from defrag_old_tt are free and do
not count. Once the budget is exhausted the allocator stops upgrading and
completes the new tt by harvesting the remainder of the old tt as-is,
marking the tt sub-optimal (TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED) so the
driver re-queues it and a later move resumes the upgrade. The slices
already upgraded come back as free already-beneficial harvests on the
next pass, so each move spends budget only on new forward progress.
The allocator decrements the budget as it allocates and writes the unused
remainder back on success, letting the caller compute how many bytes were
actually spent. A value of 0 means unlimited (upgrade the whole object in
one move), preserving the previous behaviour. This is only consulted on a
defragmentation move, i.e. when defrag_old_tt is set.
v4:
- Allow suboptimal to be NULL (Niranjana)
- Reject defrag_bytes_remaining less than zero (Niranjana)
- Move num_pages outside of loop (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 103 +++++++++++++++++++++++++++++++--
include/drm/ttm/ttm_bo.h | 14 +++++
2 files changed, 113 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index c60be4a013f1..79538d776dde 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -92,6 +92,11 @@ struct ttm_pool_dma {
* @dma_addr: Pointer to the next tt dma_address entry to populate if any.
* @remaining_pages: Remaining pages to populate.
* @tt_caching: The requested cpu-caching for the pages allocated.
+ * @defrag_bytes_remaining: Byte budget for newly (re)allocated pages on a
+ * defragmentation move, seeded from ttm_operation_ctx::defrag_bytes_remaining.
+ * Pages harvested (borrowed) from the old tt are free and do not count; once
+ * this drops to zero the allocator stops upgrading and harvests the remainder.
+ * On completion it holds the unused budget. 0 means unlimited (no defrag cap).
*/
struct ttm_pool_alloc_state {
struct page **pages;
@@ -99,6 +104,7 @@ struct ttm_pool_alloc_state {
dma_addr_t *dma_addr;
pgoff_t remaining_pages;
enum ttm_caching tt_caching;
+ s64 defrag_bytes_remaining;
};
/**
@@ -796,6 +802,7 @@ static void ttm_pool_alloc_state_init(const struct ttm_tt *tt,
alloc->dma_addr = tt->dma_address;
alloc->remaining_pages = tt->num_pages;
alloc->tt_caching = tt->caching;
+ alloc->defrag_bytes_remaining = 0;
}
/*
@@ -910,8 +917,13 @@ static int ttm_pool_harvest_page(struct ttm_tt *old_tt, unsigned int order,
static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
struct ttm_tt *old_tt, pgoff_t off,
pgoff_t *cursor,
- struct ttm_pool_alloc_state *alloc)
+ struct ttm_pool_alloc_state *alloc,
+ bool *suboptimal)
{
+ unsigned int beneficial = ttm_pool_beneficial_order(pool);
+ pgoff_t bnr = 1UL << beneficial;
+ pgoff_t num_pages = off + alloc->remaining_pages;
+
/*
* @off is always an old-tt chunk head here, never a tail page. This
* holds because:
@@ -936,6 +948,20 @@ static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
return order;
nr = 1UL << order;
+ /*
+ * Only report a sub-optimal backing when a chunk we cannot
+ * upgrade (out of budget/prealloc) sits in a beneficial-order
+ * aligned region that fully fits in the tt: that region could
+ * have been upgraded with more budget. A chunk below the
+ * beneficial order is expected for the unaligned tail (the last
+ * partial beneficial-order region) and for already beneficial-
+ * order harvests - neither leaves real defrag work, so they must
+ * not flag the tt for re-queue.
+ */
+ if (suboptimal && beneficial && order < beneficial &&
+ round_down(off, bnr) + bnr <= num_pages)
+ *suboptimal = true;
+
r = ttm_pool_harvest_page(old_tt, order, off, alloc);
if (r)
return r;
@@ -978,6 +1004,7 @@ struct ttm_pool_alloc_iter {
struct ttm_tt *defrag_old_tt;
unsigned int beneficial_order;
gfp_t gfp_flags;
+ bool defrag_capped;
/* Mutated as the loop walks the orders. */
unsigned int order;
@@ -989,6 +1016,44 @@ struct ttm_pool_alloc_iter {
struct page *p;
};
+/*
+ * Defrag move budget exhausted: the upgrade can make no further progress this
+ * pass. Snapshot @defrag_capped is set only when a byte budget was in force at
+ * entry.
+ */
+static bool ttm_pool_iter_defrag_exhausted(const struct ttm_pool_alloc_iter *it)
+{
+ if (!it->defrag_old_tt)
+ return false;
+
+ return it->defrag_capped && it->alloc->defrag_bytes_remaining <= 0;
+}
+
+/*
+ * Complete the new tt by harvesting the rest of the old tt as-is (borrowing its
+ * pages, including any still below beneficial order). Never fall back to in-lock
+ * reclaim for the shortfall - that would reintroduce the stall we preallocated
+ * to avoid. Only re-queue (flag) the tt when the harvested remainder is
+ * genuinely sub-optimal; if every remaining old chunk was already at beneficial
+ * order the move fully upgraded the object.
+ */
+static int ttm_pool_iter_harvest_rest(struct ttm_pool_alloc_iter *it)
+{
+ pgoff_t off = it->tt->num_pages - it->alloc->remaining_pages;
+ bool suboptimal = false;
+ int r;
+
+ r = ttm_pool_harvest_remaining(it->pool, it->defrag_old_tt, off,
+ &it->old_cursor, it->alloc, &suboptimal);
+ if (r)
+ return r;
+
+ if (suboptimal)
+ it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
+
+ return 0;
+}
+
/*
* Defrag move: reuse an already beneficial-order chunk from the old tt at this
* offset rather than reallocating it. Harvest whatever order the old chunk has
@@ -1096,7 +1161,7 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
r = ttm_pool_harvest_remaining(it->pool,
it->defrag_old_tt, off,
&it->old_cursor,
- it->alloc);
+ it->alloc, NULL);
if (r)
return r;
@@ -1157,6 +1222,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
gfp_flags |= GFP_HIGHUSER;
it.gfp_flags = gfp_flags;
+ it.defrag_capped = it.defrag_old_tt && alloc->defrag_bytes_remaining > 0;
/*
* Keep chunks self-aligned (an order-k chunk at a 2^k-aligned offset):
@@ -1172,6 +1238,18 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
for (it.order = ttm_pool_alloc_find_order(start_order, alloc);
alloc->remaining_pages;
it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
+ /*
+ * Out of defrag budget: harvest the rest of the old tt as-is and
+ * stop (the tt is re-queued if the remainder is still
+ * sub-optimal).
+ */
+ if (ttm_pool_iter_defrag_exhausted(&it)) {
+ r = ttm_pool_iter_harvest_rest(&it);
+ if (r)
+ goto error_free_all;
+ break;
+ }
+
/* Reuse an already beneficial-order chunk from the old tt. */
r = ttm_pool_iter_reuse_old(&it);
if (r < 0)
@@ -1202,6 +1280,15 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
goto error_free_all;
}
+ /*
+ * Charge a newly (re)allocated chunk against the defrag move
+ * budget. Harvested chunks borrow the old tt's pages for free
+ * and never reach here.
+ */
+ if (it.defrag_capped)
+ alloc->defrag_bytes_remaining -=
+ (s64)(1UL << it.order) << PAGE_SHIFT;
+
it.alloc_count++;
}
@@ -1251,14 +1338,22 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
struct ttm_operation_ctx *ctx)
{
struct ttm_pool_alloc_state alloc;
+ int ret;
- if (WARN_ON(ttm_tt_is_backed_up(tt)))
+ if (WARN_ON(ttm_tt_is_backed_up(tt)) ||
+ WARN_ON(ctx->defrag_bytes_remaining < 0))
return -EINVAL;
tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
ttm_pool_alloc_state_init(tt, &alloc);
+ alloc.defrag_bytes_remaining = ctx->defrag_bytes_remaining;
+
+ ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
+
+ /* Report the unused defrag budget back to the caller. */
+ ctx->defrag_bytes_remaining = alloc.defrag_bytes_remaining;
- return __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
+ return ret;
}
EXPORT_SYMBOL(ttm_pool_alloc);
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 22d12fea6f3c..4ab67d6a926e 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -223,6 +223,20 @@ struct ttm_operation_ctx {
* NULL for non-defrag operations.
*/
struct ttm_tt *defrag_old_tt;
+ /**
+ * @defrag_bytes_remaining: Byte budget for newly allocated pages during
+ * a defragmentation move. Only pages that are actually (re)allocated at
+ * the beneficial order count against it; pages harvested (borrowed) from
+ * @defrag_old_tt are free and do not. When the budget is exhausted the
+ * pool allocator stops upgrading and completes the new tt by harvesting
+ * the remainder of @defrag_old_tt, marking the tt sub-optimal so the
+ * driver can resume on a later pass. The allocator decrements this as it
+ * allocates, so on return it holds the unused budget (which the caller
+ * can use to compute how many bytes were spent). A value of 0 means
+ * unlimited (upgrade the whole object). Only consulted when
+ * @defrag_old_tt is set.
+ */
+ s64 defrag_bytes_remaining;
/**
* @resv: Reservation object to be used together with
* @allow_res_evict.
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 10/36] drm/ttm: Preallocate beneficial-order defrag pages outside the lock
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
` (8 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:57 ` sashiko-bot
2026-12-02 23:32 ` [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
` (28 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Defragmentation moves reallocate a BO's backing at the pool's beneficial
order. On a fragmented system those high-order allocations frequently
stall in direct reclaim/compaction, and they run under the BO dma-resv
lock, holding up concurrent rendering. The defrag worker does not care
how long the work takes; it only cares about minimizing locked time.
Add a preallocation bag so the expensive allocations can be hoisted out
of the lock:
- struct ttm_pool_prealloc carries beneficial-order pages preallocated
outside the lock; ttm_pool_prealloc_fill()/_fini() allocate and
release them. __ttm_pool_alloc() consumes them via ctx->prealloc.
- Apply the requested cpu-caching to the bag pages during fill, so the
set_memory_*() cost is paid outside the lock too; consumed pages are
already cache-consistent and leftovers are restored to write-back on
free. Bag pages are never highmem so the kernel mapping is always
valid for set_memory_*().
- Record the exact number of sub-optimal pages on the tt
(nr_suboptimal_pages) at populate time so a defrag pass can size its
prealloc precisely instead of guessing.
- Once a defrag move exhausts the prealloc bag, harvest the remainder
of the old tt rather than entering reclaim under the lock, and flag
the tt sub-optimal so the driver re-queues it for a later pass.
This keeps all reclaim/compaction stalls and cache mode changes out of
the dma-resv critical section: lock-held time then tracks only the bytes
actually copied.
v4:
- skip p->count check in ttm_pool_iter_defrag_exhausted (Sashiko, Niranjana)
- Adjust nr_suboptimal_pages kernel doc (Niranjana)
v5:
- Do no include unaligned tail pages in nr_suboptimal_pages (Sashiko)
- Fail with -ENOMEM if alloc_count == 0, i.e., no progress (Sashiko)
- Count nr_suboptimal_pages when pages committed (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 279 +++++++++++++++++++++++++++++++--
include/drm/ttm/ttm_bo.h | 13 ++
include/drm/ttm/ttm_pool.h | 29 ++++
include/drm/ttm/ttm_tt.h | 18 +++
4 files changed, 324 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 79538d776dde..fa76f880d563 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -97,6 +97,13 @@ struct ttm_pool_dma {
* Pages harvested (borrowed) from the old tt are free and do not count; once
* this drops to zero the allocator stops upgrading and harvests the remainder.
* On completion it holds the unused budget. 0 means unlimited (no defrag cap).
+ * @nr_suboptimal_pages: Number of pages backed below the pool's beneficial
+ * order that a defrag move could upgrade (see ttm_pool_account_chunk()).
+ * Recorded by the pool allocator after populate; a defrag pass reads it to size
+ * its out-of-lock preallocation exactly.
+ * @first_page: The tt's first page pointer, to derive the current offset.
+ * @num_pages: Number of pages in the tt.
+ * @beneficial_order: The pool's beneficial order.
*/
struct ttm_pool_alloc_state {
struct page **pages;
@@ -105,6 +112,10 @@ struct ttm_pool_alloc_state {
pgoff_t remaining_pages;
enum ttm_caching tt_caching;
s64 defrag_bytes_remaining;
+ u32 nr_suboptimal_pages;
+ struct page **first_page;
+ pgoff_t num_pages;
+ unsigned int beneficial_order;
};
/**
@@ -594,6 +605,27 @@ static pgoff_t ttm_pool_unmap_and_free(struct ttm_pool *pool, struct page *page,
return nr;
}
+/*
+ * Account a chunk of @nr pages about to be committed at the current offset.
+ * Only chunks below the beneficial order that sit in a beneficial-order aligned
+ * region fully inside the tt count as sub-optimal: the unaligned trailing tail
+ * can never be backed at the beneficial order, so counting it would make a
+ * defrag pass preallocate a chunk it can never consume.
+ *
+ * Called from the commit step itself (before any restore snapshot is taken), so
+ * the count can never be lost when an interrupted restore is resumed.
+ */
+static void ttm_pool_account_chunk(struct ttm_pool_alloc_state *alloc,
+ pgoff_t nr)
+{
+ pgoff_t bnr = 1UL << alloc->beneficial_order;
+ pgoff_t off = alloc->pages - alloc->first_page;
+
+ if (alloc->beneficial_order && nr < bnr &&
+ round_down(off, bnr) + bnr <= alloc->num_pages)
+ alloc->nr_suboptimal_pages += nr;
+}
+
/* Populate the page-array using the most recent allocated multi-order page. */
static void ttm_pool_allocated_page_commit(struct page *allocated,
dma_addr_t first_dma,
@@ -602,6 +634,8 @@ static void ttm_pool_allocated_page_commit(struct page *allocated,
{
pgoff_t i;
+ ttm_pool_account_chunk(alloc, nr);
+
for (i = 0; i < nr; ++i)
*alloc->pages++ = allocated++;
@@ -794,7 +828,8 @@ static void ttm_pool_free_range(struct ttm_pool *pool, struct ttm_tt *tt,
}
}
-static void ttm_pool_alloc_state_init(const struct ttm_tt *tt,
+static void ttm_pool_alloc_state_init(struct ttm_pool *pool,
+ const struct ttm_tt *tt,
struct ttm_pool_alloc_state *alloc)
{
alloc->pages = tt->pages;
@@ -803,6 +838,10 @@ static void ttm_pool_alloc_state_init(const struct ttm_tt *tt,
alloc->remaining_pages = tt->num_pages;
alloc->tt_caching = tt->caching;
alloc->defrag_bytes_remaining = 0;
+ alloc->nr_suboptimal_pages = 0;
+ alloc->first_page = tt->pages;
+ alloc->num_pages = tt->num_pages;
+ alloc->beneficial_order = ttm_pool_beneficial_order(pool);
}
/*
@@ -899,6 +938,7 @@ static int ttm_pool_harvest_page(struct ttm_tt *old_tt, unsigned int order,
* the populate fill from O(num_pages) individual stores into a handful
* of bulk copies.
*/
+ ttm_pool_account_chunk(alloc, nr);
memcpy(alloc->pages, &old_tt->pages[off], nr * sizeof(*alloc->pages));
alloc->pages += nr;
alloc->remaining_pages -= nr;
@@ -972,6 +1012,176 @@ static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
return 0;
}
+unsigned int ttm_pool_prealloc_order(struct ttm_pool *pool)
+{
+ return ttm_pool_beneficial_order(pool);
+}
+EXPORT_SYMBOL(ttm_pool_prealloc_order);
+
+/*
+ * Build the gfp flags used for the high-order, possibly reclaiming, beneficial
+ * order page allocations, matching the in-line defrag alloc path.
+ */
+static gfp_t ttm_pool_prealloc_gfp(struct ttm_pool *pool)
+{
+ gfp_t gfp = GFP_USER;
+
+ /*
+ * No highmem: prealloc applies caching in bulk via set_pages_array_*()
+ * on the kernel mapping, so the pages must be permanently mapped.
+ */
+ if (ttm_pool_uses_dma32(pool))
+ gfp |= GFP_DMA32;
+
+ return gfp;
+}
+
+/*
+ * Apply a tt's cpu-caching to a batch of freshly system-allocated (write-back)
+ * prealloc pages in one shot. @cpages is an unpacked array of @ncpages
+ * individual 4K pages (the constituent pages of the mixed-order chunks, expanded
+ * so set_pages_array_*() sees one entry per page), since the packed prealloc bag
+ * holds multi-order chunks. Prealloc pages are never highmem (see
+ * ttm_pool_prealloc_gfp), so their kernel mapping is valid. No-op for cached
+ * pages and on non-x86. Returns non-zero if the caching change failed (the
+ * caller drops the whole bag and falls back to in-line allocation).
+ */
+static int ttm_pool_prealloc_apply_caching(enum ttm_caching caching,
+ struct page **cpages,
+ unsigned int ncpages)
+{
+#ifdef CONFIG_X86
+ if (!ncpages)
+ return 0;
+
+ switch (caching) {
+ case ttm_cached:
+ break;
+ case ttm_write_combined:
+ return set_pages_array_wc(cpages, ncpages);
+ case ttm_uncached:
+ return set_pages_array_uc(cpages, ncpages);
+ }
+#endif
+ return 0;
+}
+
+/* Expand an @order chunk into its constituent 4K pages for bulk caching. */
+static void ttm_pool_prealloc_stage_caching(struct page **cpages,
+ unsigned int *ncpages,
+ struct page *p, unsigned int order)
+{
+ unsigned int i, nr = 1u << order;
+
+ for (i = 0; i < nr; i++)
+ cpages[(*ncpages)++] = p + i;
+}
+
+/**
+ * ttm_pool_prealloc_fill() - Preallocate beneficial-order pages outside any lock
+ * @pool: The pool to allocate from.
+ * @tt_caching: The requested cpu-caching for the pages allocated.
+ * @pp: Prealloc bag to fill; @pp->order is set to the beneficial order.
+ * @count: Number of beneficial-order chunks to attempt.
+ *
+ * Allocate up to @count beneficial-order chunks, parking them in @pp for a
+ * later __ttm_pool_alloc() defrag move to consume under the dma-resv lock. May
+ * sleep/reclaim freely as it runs unlocked. A short fill is fine: once the bag
+ * is drained the move harvests the remainder of the old tt as-is (never
+ * allocating in-line under the lock) and leaves the tt flagged for a later
+ * pass. A move that ends up allocating no chunk at all fails with -ENOMEM.
+ * DMA-alloc pools are not supported (count stays 0). Returns 0 (release with
+ * ttm_pool_prealloc_fini()).
+ */
+int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
+ struct ttm_pool_prealloc *pp, unsigned int count)
+{
+ unsigned int order = ttm_pool_beneficial_order(pool);
+ gfp_t gfp = ttm_pool_prealloc_gfp(pool);
+ struct page **cpages = NULL;
+ unsigned int ncpages = 0;
+ int r;
+
+ pp->pages = NULL;
+ pp->order = order;
+ pp->caching = tt_caching;
+ pp->count = 0;
+ pp->used = 0;
+
+ /* Nothing to gain without a beneficial order or for DMA-alloc pools. */
+ if (!order || !count || ttm_pool_uses_dma_alloc(pool))
+ return 0;
+
+ pp->pages = kvzalloc_objs(*pp->pages, count);
+ if (!pp->pages)
+ return 0;
+
+ /*
+ * Every chunk is a fresh write-back system page of @order that needs a
+ * caching change; collect their constituent pages into an unpacked
+ * scratch array and issue a single set_pages_array_*() after the fill.
+ * Cached tts need no change (and non-x86 handles caching at map time).
+ */
+ if (IS_ENABLED(CONFIG_X86) && tt_caching != ttm_cached) {
+ cpages = kvzalloc_objs(*cpages, (size_t)count << order);
+ if (!cpages) {
+ kvfree(pp->pages);
+ pp->pages = NULL;
+ return 0;
+ }
+ }
+
+ while (pp->count < count) {
+ struct page *p = ttm_pool_alloc_page(pool, gfp, order, false);
+
+ if (!p)
+ break;
+
+ pp->pages[pp->count++] = p;
+ if (cpages)
+ ttm_pool_prealloc_stage_caching(cpages, &ncpages, p,
+ order);
+ }
+
+ /*
+ * Apply the requested caching to every collected page in one shot. On
+ * failure the pages' caching is indeterminate, so drop the whole bag
+ * (freeing restores write-back) and let the consumer allocate in-line.
+ */
+ r = ttm_pool_prealloc_apply_caching(tt_caching, cpages, ncpages);
+ kvfree(cpages);
+ if (r) {
+ unsigned int i;
+
+ for (i = 0; i < pp->count; i++)
+ ttm_pool_free_page(pool, tt_caching, order,
+ pp->pages[i], false);
+ pp->count = 0;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(ttm_pool_prealloc_fill);
+
+/**
+ * ttm_pool_prealloc_fini() - Release unconsumed preallocated pages
+ * @pool: The pool the pages came from.
+ * @pp: Prealloc bag to drain. Consumed pages (< @used) are now owned by the tt.
+ */
+void ttm_pool_prealloc_fini(struct ttm_pool *pool, struct ttm_pool_prealloc *pp)
+{
+ unsigned int i;
+
+ for (i = pp->used; i < pp->count; ++i)
+ ttm_pool_free_page(pool, pp->caching, pp->order, pp->pages[i],
+ false);
+ kvfree(pp->pages);
+ pp->pages = NULL;
+ pp->count = 0;
+ pp->used = 0;
+}
+EXPORT_SYMBOL(ttm_pool_prealloc_fini);
+
/**
* enum ttm_pool_iter_action - Outcome of a per-order allocation phase
* @TTM_POOL_ITER_FILL: A page (@it->p) was acquired; proceed to fill it in.
@@ -1002,6 +1212,7 @@ struct ttm_pool_alloc_iter {
const struct ttm_operation_ctx *ctx;
struct ttm_pool_alloc_state *alloc;
struct ttm_tt *defrag_old_tt;
+ struct ttm_pool_prealloc *prealloc;
unsigned int beneficial_order;
gfp_t gfp_flags;
bool defrag_capped;
@@ -1017,16 +1228,20 @@ struct ttm_pool_alloc_iter {
};
/*
- * Defrag move budget exhausted: the upgrade can make no further progress this
- * pass. Snapshot @defrag_capped is set only when a byte budget was in force at
- * entry.
+ * Defrag move budget exhausted, or the out-of-lock prealloc bag ran dry: the
+ * upgrade can make no further progress this pass. Snapshot @defrag_capped is
+ * set only when a byte budget was in force at entry.
*/
static bool ttm_pool_iter_defrag_exhausted(const struct ttm_pool_alloc_iter *it)
{
+ const struct ttm_pool_prealloc *pp = it->prealloc;
+
if (!it->defrag_old_tt)
return false;
+ if (it->defrag_capped && it->alloc->defrag_bytes_remaining <= 0)
+ return true;
- return it->defrag_capped && it->alloc->defrag_bytes_remaining <= 0;
+ return pp && pp->used >= pp->count;
}
/*
@@ -1085,7 +1300,8 @@ static int ttm_pool_iter_reuse_old(struct ttm_pool_alloc_iter *it)
return TTM_POOL_ITER_FILL;
it->order = harvest_order;
- r = ttm_pool_harvest_page(it->defrag_old_tt, it->order, off, it->alloc);
+ r = ttm_pool_harvest_page(it->defrag_old_tt, it->order, off,
+ it->alloc);
if (r)
return r;
@@ -1097,11 +1313,13 @@ static int ttm_pool_iter_reuse_old(struct ttm_pool_alloc_iter *it)
/*
* Acquire a single page for the current order, leaving it in @it->p (NULL on
- * failure). Tries a same-order pool page, then a fresh system allocation. Fault
- * injection can force the beneficial-order paths to "fail".
+ * failure). Tries, in order: a beneficial-order page preallocated outside the
+ * dma-resv lock (defrag), a same-order pool page, then a fresh system
+ * allocation. Fault injection can force the beneficial-order paths to "fail".
*/
static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
{
+ struct ttm_pool_prealloc *pp = it->prealloc;
struct ttm_pool_type *pt;
it->p = NULL;
@@ -1116,7 +1334,18 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
it->beneficial_order && it->order >= it->beneficial_order &&
should_fail(&beneficial_order_fault_inject, 1);
- /* First, try to allocate a page from a pool if one exists. */
+ /*
+ * Defrag move: consume a beneficial-order page preallocated outside the
+ * dma-resv lock instead of allocating one in-line (which may stall in
+ * reclaim/compaction). Falls through once the bag is empty.
+ */
+ if (pp && !it->fail_beneficial && it->order >= it->beneficial_order &&
+ pp->used < pp->count) {
+ it->order = it->beneficial_order;
+ it->p = pp->pages[pp->used++];
+ it->page_caching = it->tt->caching;
+ }
+
pt = ttm_pool_select_type(it->pool, it->page_caching, it->order);
if (!it->p && pt && it->allow_pools && !it->fail_beneficial)
it->p = ttm_pool_type_take(pt, ttm_pool_nid(it->pool));
@@ -1197,6 +1426,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
.ctx = ctx,
.alloc = alloc,
.defrag_old_tt = restore ? NULL : ctx->defrag_old_tt,
+ .prealloc = restore ? NULL : ctx->prealloc,
.beneficial_order = ttm_pool_beneficial_order(pool),
.page_caching = tt->caching,
.allow_pools = true,
@@ -1239,8 +1469,8 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
alloc->remaining_pages;
it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
/*
- * Out of defrag budget: harvest the rest of the old tt as-is and
- * stop (the tt is re-queued if the remainder is still
+ * Out of defrag budget/prealloc: harvest the rest of the old tt
+ * as-is and stop (the tt is re-queued if the remainder is still
* sub-optimal).
*/
if (ttm_pool_iter_defrag_exhausted(&it)) {
@@ -1257,7 +1487,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
if (r == TTM_POOL_ITER_RETRY)
continue;
- /* Acquire a page (pool / system) for this order. */
+ /* Acquire a page (prealloc / pool / system) for this order. */
ttm_pool_iter_acquire_page(&it);
if (!it.p) {
r = ttm_pool_iter_lower_order(&it);
@@ -1292,6 +1522,17 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
it.alloc_count++;
}
+ /*
+ * A defrag move that (re)allocated nothing - e.g. an empty or
+ * unconsumable prealloc bag - would merely re-borrow the whole old tt.
+ * Fail it rather than commit a zero-progress move that still unmaps
+ * user mappings and triggers driver move/rebind work.
+ */
+ if (it.defrag_old_tt && !it.alloc_count) {
+ r = -ENOMEM;
+ goto error_free_all;
+ }
+
r = ttm_pool_apply_caching(alloc);
if (r)
goto error_free_all;
@@ -1345,7 +1586,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
return -EINVAL;
tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
- ttm_pool_alloc_state_init(tt, &alloc);
+ ttm_pool_alloc_state_init(pool, tt, &alloc);
alloc.defrag_bytes_remaining = ctx->defrag_bytes_remaining;
ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
@@ -1353,6 +1594,9 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
/* Report the unused defrag budget back to the caller. */
ctx->defrag_bytes_remaining = alloc.defrag_bytes_remaining;
+ if (!ret)
+ tt->nr_suboptimal_pages = alloc.nr_suboptimal_pages;
+
return ret;
}
EXPORT_SYMBOL(ttm_pool_alloc);
@@ -1384,7 +1628,7 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
- ttm_pool_alloc_state_init(tt, &alloc);
+ ttm_pool_alloc_state_init(pool, tt, &alloc);
if (ctx->gfp_retry_mayfail)
gfp |= __GFP_RETRY_MAYFAIL;
@@ -1414,11 +1658,16 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
kfree(tt->restore);
tt->restore = NULL;
+ tt->nr_suboptimal_pages = alloc.nr_suboptimal_pages;
return 0;
}
}
- return __ttm_pool_alloc(pool, tt, ctx, &alloc, restore);
+ ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, restore);
+ if (!ret)
+ tt->nr_suboptimal_pages = alloc.nr_suboptimal_pages;
+
+ return ret;
}
/**
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 4ab67d6a926e..3055cc411d73 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -237,6 +237,19 @@ struct ttm_operation_ctx {
* @defrag_old_tt is set.
*/
s64 defrag_bytes_remaining;
+ /**
+ * @prealloc: Pages preallocated outside the dma-resv lock for a defrag
+ * move. The pool allocator consumes these instead of allocating fresh
+ * beneficial-order pages under the lock, moving the (potentially
+ * reclaim/compaction stalling) high-order allocations out of the
+ * critical section. NULL means allocate in-line as usual. The pool
+ * never allocates in-line once the bag is drained: the remainder is
+ * harvested from the old tt as-is, and a defrag move that allocates no
+ * chunk fails with -ENOMEM. The allocator consumes it for
+ * beneficial-order chunks of any populate; drivers only set it for a
+ * defrag move.
+ */
+ struct ttm_pool_prealloc *prealloc;
/**
* @resv: Reservation object to be used together with
* @allow_res_evict.
diff --git a/include/drm/ttm/ttm_pool.h b/include/drm/ttm/ttm_pool.h
index 429f4f987a19..3f2e51151af9 100644
--- a/include/drm/ttm/ttm_pool.h
+++ b/include/drm/ttm/ttm_pool.h
@@ -81,6 +81,35 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
struct ttm_operation_ctx *ctx);
void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt);
+/**
+ * struct ttm_pool_prealloc - Pages preallocated outside the dma-resv lock
+ * @pages: Array of @count beneficial-order pages (or fewer if a fill fell
+ * short); each entry is the head page of a 1 << @order chunk.
+ * @order: Page order of every preallocated chunk.
+ * @caching: CPU caching applied to the pages, so leftovers can be restored
+ * to write-back before being freed.
+ * @count: Number of valid entries in @pages.
+ * @used: Number of entries already consumed by the pool allocator.
+ *
+ * Defrag pages are interchangeable, so only a count of beneficial-order chunks
+ * is needed. ttm_pool_prealloc_fill() populates this outside the lock and
+ * __ttm_pool_alloc() drains it; any unused tail is released by
+ * ttm_pool_prealloc_fini().
+ */
+struct ttm_pool_prealloc {
+ struct page **pages;
+ unsigned int order;
+ enum ttm_caching caching;
+ unsigned int count;
+ unsigned int used;
+};
+
+int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
+ struct ttm_pool_prealloc *pp, unsigned int count);
+void ttm_pool_prealloc_fini(struct ttm_pool *pool,
+ struct ttm_pool_prealloc *pp);
+unsigned int ttm_pool_prealloc_order(struct ttm_pool *pool);
+
void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
int nid, unsigned int alloc_flags);
void ttm_pool_fini(struct ttm_pool *pool);
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 55c35bcf134d..6e82d0309b05 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -135,6 +135,13 @@ struct ttm_tt {
enum ttm_caching caching;
/** @restore: Partial restoration from backup state. TTM private */
struct ttm_pool_tt_restore *restore;
+ /**
+ * @nr_suboptimal_pages: Number of pages backed below the pool's
+ * beneficial order. Recorded by the pool allocator after populate; a
+ * defrag pass reads it to size its out-of-lock preallocation rounding
+ * up. Only relavent if TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED is set.
+ */
+ u32 nr_suboptimal_pages;
};
/**
@@ -201,6 +208,17 @@ static inline bool ttm_tt_is_beneficial_order_failed(const struct ttm_tt *tt)
return tt->page_flags & TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
}
+/**
+ * ttm_tt_suboptimal_pages() - Pages backed below the pool's beneficial order
+ * @tt: The struct ttm_tt.
+ *
+ * Return: Number of pages a defrag move would (re)allocate at beneficial order.
+ */
+static inline u32 ttm_tt_suboptimal_pages(const struct ttm_tt *tt)
+{
+ return tt->nr_suboptimal_pages;
+}
+
/**
* ttm_tt_create
*
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
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
` (9 preceding siblings ...)
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:32 ` Matthew Brost
2026-12-02 23:59 ` sashiko-bot
2026-12-02 23:32 ` [PATCH v5 12/36] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
` (27 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
ttm_pool_prealloc_fill() lets a driver preallocate beneficial-order pages
outside the dma-resv lock for a defragmentation move, so the high-order
allocations that may stall in reclaim/compaction happen off the critical
section. That bag is deliberately partial: it holds only interchangeable
beneficial-order chunks and the allocator consumes it opportunistically,
falling back to in-line allocation for everything else.
An ordinary populate of a system-memory buffer object has the same
problem - the whole backing is allocated under the dma-resv lock - but no
way to move it out of the critical section, because the existing bag does
not cover sub-beneficial orders and does not describe a full tt.
Add a "full" flavour of the same preallocation mechanism:
- struct ttm_pool_prealloc gains a @full flag. In full mode the bag is
an ordered tiling of an entire tt at mixed orders (pool pages
included), rather than a set of interchangeable beneficial-order
chunks. The per-chunk order is recorded on the page itself and read
back at consume time, so no parallel order array is needed.
- ttm_pool_prealloc_fill_full() allocates the whole backing for a tt of
@num_pages pages up front, mirroring the in-line allocator's order
walk (highest order first, capped by the remaining page count). It
reuses the existing unlocked helpers (ttm_pool_prealloc_gfp(),
ttm_pool_set_caching()) via a new ttm_pool_take_page() helper that
tries a same-order pool page before a fresh system allocation.
- ttm_pool_prealloc_fini() frees any unconsumed tail at each chunk's own
order when @full.
- ttm_pool_prealloc_fill_full() takes a @beneficial_reclaim_backoff
argument, plumbed to ttm_pool_alloc_page(), that lets the caller
allocate higher-order chunks without aggressive reclaim/compaction.
This suits a driver that upgrades suboptimal pages to beneficial order
in place later (e.g. via a background defragmenter) and so has no need
to stall the user context reclaiming for contiguity up front.
- __ttm_pool_alloc() consumes a full bag with a single early branch in
ttm_pool_iter_acquire_page(): install the next chunk as-is (order
taken from the page) and return; once the best-effort bag is drained
the loop falls through to normal in-line allocation. The defrag
harvest and reuse-old phases are inert here as there is no
defrag_old_tt.
Like the defrag bag, this is best-effort: a short fill is fine (the pool
allocates the shortfall in-line) and DMA-alloc pools are unsupported
(caching is applied on the kernel mapping). No functional change for
existing users; the new fill routine has no in-tree caller yet.
v4:
- Reject prealloc / TT caching mismatches (Niranjana)
v5:
- Fix kernel doc (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/ttm/ttm_pool.c | 237 ++++++++++++++++++++++++++++++++-
include/drm/ttm/ttm_bo.h | 23 ++--
include/drm/ttm/ttm_pool.h | 27 +++-
3 files changed, 264 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index fa76f880d563..7b1736324f7e 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -1107,6 +1107,7 @@ int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
pp->caching = tt_caching;
pp->count = 0;
pp->used = 0;
+ pp->full = false;
/* Nothing to gain without a beneficial order or for DMA-alloc pools. */
if (!order || !count || ttm_pool_uses_dma_alloc(pool))
@@ -1163,6 +1164,189 @@ int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
}
EXPORT_SYMBOL(ttm_pool_prealloc_fill);
+/*
+ * Acquire a single *@order chunk, trying a same-order pool page first (already
+ * carries @caching) then a fresh system allocation (write-back). Runs unlocked.
+ * When @beneficial_reclaim_backoff is set, higher-order system allocations skip
+ * aggressive reclaim/compaction (see ttm_pool_alloc_page()).
+ *
+ * A fresh system page is write-back and needs the tt's caching applied later in
+ * bulk; *@need_caching is set true for it and false for a (pre-cached) pool
+ * page.
+ *
+ * On a genuine failure *@order is left untouched (the caller lowers it by one
+ * and retries). Fault injection instead pretends allocation at (or above) the
+ * beneficial order failed and lowers *@order to the beneficial order, so the
+ * caller's next attempt lands below it - mirroring the in-line acquire path's
+ * fail_beneficial jump and exercising the beneficial_order_failed tracking
+ * without driving the system into real fragmentation.
+ *
+ * Returns NULL if no page of *@order could be obtained.
+ */
+static struct page *ttm_pool_take_page(struct ttm_pool *pool,
+ enum ttm_caching caching,
+ unsigned int *order, gfp_t gfp,
+ bool *need_caching,
+ bool beneficial_reclaim_backoff)
+{
+ unsigned int beneficial = ttm_pool_beneficial_order(pool);
+ struct ttm_pool_type *pt;
+ struct page *p;
+
+ *need_caching = false;
+
+ if (IS_ENABLED(CONFIG_FAULT_INJECTION) && beneficial &&
+ *order >= beneficial &&
+ should_fail(&beneficial_order_fault_inject, 1)) {
+ *order = beneficial;
+ return NULL;
+ }
+
+ pt = ttm_pool_select_type(pool, caching, *order);
+ if (pt) {
+ p = ttm_pool_type_take(pt, ttm_pool_nid(pool));
+ if (p)
+ return p; /* pool page already carries @caching */
+ }
+
+ p = ttm_pool_alloc_page(pool, gfp, *order, beneficial_reclaim_backoff);
+ if (!p)
+ return NULL;
+
+ /* Fresh system page is write-back; caller applies @caching in bulk. */
+ *need_caching = true;
+ return p;
+}
+
+/**
+ * ttm_pool_prealloc_fill_full() - Preallocate a whole tt's backing outside any
+ * lock
+ * @pool: The pool to allocate from.
+ * @tt_caching: The requested cpu-caching for the pages allocated.
+ * @pp: Prealloc bag to fill; marked @full and tiled with mixed-order chunks.
+ * @num_pages: Number of 4K pages the tt needs backed.
+ * @beneficial_reclaim_backoff: Do not perform aggressive reclaim at the
+ * beneficial order.
+ *
+ * Unlike ttm_pool_prealloc_fill() (which parks a bag of interchangeable
+ * beneficial-order defrag chunks), this allocates the ENTIRE backing for a tt
+ * of @num_pages pages up front, at whatever mix of orders is available (pool
+ * pages included), so that the subsequent __ttm_pool_alloc() under the dma-resv
+ * lock merely installs the pages without stalling in reclaim/compaction. The
+ * chunk orders mirror the in-line allocator's order walk; each chunk's order is
+ * recorded on the page itself and read back at consume time.
+ *
+ * May sleep/reclaim freely as it runs unlocked. When
+ * @beneficial_reclaim_backoff is set, higher-order chunks are taken without
+ * aggressive reclaim/compaction: the caller relies on a background
+ * defragmenter to upgrade to beneficial-order pages in place later, so there
+ * is no need to stall the user context reclaiming for contiguity here. A short
+ * fill is fine: the pool falls back to in-line allocation for the shortfall.
+ * DMA-alloc pools are not supported (the bag stays empty). Returns 0 (release
+ * with ttm_pool_prealloc_fini()).
+ */
+int ttm_pool_prealloc_fill_full(struct ttm_pool *pool,
+ enum ttm_caching tt_caching,
+ struct ttm_pool_prealloc *pp,
+ unsigned int num_pages,
+ bool beneficial_reclaim_backoff)
+{
+ gfp_t gfp = ttm_pool_prealloc_gfp(pool) | __GFP_ZERO |
+ __GFP_RETRY_MAYFAIL | __GFP_NOWARN;
+ unsigned int highest = MAX_PAGE_ORDER;
+ unsigned int remaining = num_pages;
+ struct page **cpages = NULL;
+ unsigned int ncpages = 0;
+ int r;
+
+ pp->pages = NULL;
+ pp->order = 0;
+ pp->caching = tt_caching;
+ pp->count = 0;
+ pp->used = 0;
+ pp->full = true;
+
+ /* Caching is applied on the kernel mapping, so DMA-alloc is unsupported. */
+ if (!num_pages || ttm_pool_uses_dma_alloc(pool))
+ return 0;
+
+ /* Worst case is one order-0 chunk per page. */
+ pp->pages = kvzalloc_objs(*pp->pages, num_pages);
+ if (!pp->pages)
+ return 0;
+
+ /*
+ * Fresh write-back chunks get their caching changed in a single
+ * set_pages_array_*() after the fill; collect their constituent pages
+ * into an unpacked scratch array (one entry per 4K page) since the
+ * packed bag holds mixed-order chunks. Cached tts and pool pages need
+ * no change (and non-x86 handles caching at map time).
+ */
+ if (IS_ENABLED(CONFIG_X86) && tt_caching != ttm_cached) {
+ cpages = kvzalloc_objs(*cpages, num_pages);
+ if (!cpages) {
+ kvfree(pp->pages);
+ pp->pages = NULL;
+ return 0;
+ }
+ }
+
+ while (remaining) {
+ unsigned int order = min_t(unsigned int, highest,
+ __fls(remaining));
+ bool need_caching;
+ struct page *p;
+
+ for (;;) {
+ p = ttm_pool_take_page(pool, tt_caching, &order, gfp,
+ &need_caching,
+ beneficial_reclaim_backoff);
+ if (p)
+ break;
+ if (!order)
+ goto apply_caching; /* short fill */
+ /*
+ * Genuine failure: retry one order down. A fault
+ * injection lowered @order to the beneficial order
+ * above, so this drops it below - landing on a
+ * sub-optimal (defrag-worthy) chunk.
+ */
+ order--;
+ }
+
+ pp->pages[pp->count++] = p;
+ if (cpages && need_caching)
+ ttm_pool_prealloc_stage_caching(cpages, &ncpages, p,
+ order);
+ remaining -= 1u << order;
+ highest = order;
+ }
+
+apply_caching:
+ /*
+ * Apply the requested caching to every collected page in one shot. On
+ * failure the pages' caching is indeterminate, so drop the whole bag
+ * (freeing restores write-back) and let the consumer allocate in-line.
+ */
+ r = ttm_pool_prealloc_apply_caching(tt_caching, cpages, ncpages);
+ kvfree(cpages);
+ if (r) {
+ unsigned int i;
+
+ for (i = 0; i < pp->count; i++) {
+ struct page *p = pp->pages[i];
+
+ ttm_pool_free_page(pool, tt_caching,
+ ttm_pool_page_order_nodma(p), p,
+ false);
+ }
+ pp->count = 0;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(ttm_pool_prealloc_fill_full);
+
/**
* ttm_pool_prealloc_fini() - Release unconsumed preallocated pages
* @pool: The pool the pages came from.
@@ -1172,9 +1356,13 @@ void ttm_pool_prealloc_fini(struct ttm_pool *pool, struct ttm_pool_prealloc *pp)
{
unsigned int i;
- for (i = pp->used; i < pp->count; ++i)
- ttm_pool_free_page(pool, pp->caching, pp->order, pp->pages[i],
- false);
+ for (i = pp->used; i < pp->count; ++i) {
+ struct page *p = pp->pages[i];
+ unsigned int order = pp->full ?
+ ttm_pool_page_order_nodma(p) : pp->order;
+
+ ttm_pool_free_page(pool, pp->caching, order, p, false);
+ }
kvfree(pp->pages);
pp->pages = NULL;
pp->count = 0;
@@ -1313,9 +1501,10 @@ static int ttm_pool_iter_reuse_old(struct ttm_pool_alloc_iter *it)
/*
* Acquire a single page for the current order, leaving it in @it->p (NULL on
- * failure). Tries, in order: a beneficial-order page preallocated outside the
- * dma-resv lock (defrag), a same-order pool page, then a fresh system
- * allocation. Fault injection can force the beneficial-order paths to "fail".
+ * failure). Tries, in order: a chunk from a full out-of-lock prealloc (populate
+ * of the whole tt), a beneficial-order page preallocated outside the dma-resv
+ * lock (defrag), a same-order pool page, then a fresh system allocation. Fault
+ * injection can force the beneficial-order paths to "fail".
*/
static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
{
@@ -1324,6 +1513,39 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
it->p = NULL;
+ /*
+ * Full prealloc: the entire backing was allocated (pool + system, at
+ * mixed orders) outside the dma-resv lock. Install the next chunk as-is,
+ * taking its order from the page. Falls through to in-line allocation
+ * once the best-effort bag is drained.
+ */
+ if (pp && pp->full && pp->used < pp->count) {
+ it->fail_beneficial = false;
+ it->p = pp->pages[pp->used++];
+ it->order = ttm_pool_page_order_nodma(it->p);
+ it->page_caching = it->tt->caching;
+
+ /*
+ * The full prealloc tiles at whatever orders were available
+ * without stalling in reclaim. A sub-beneficial chunk only
+ * means a sub-optimal backing (defrag-worthy) when it sits in a
+ * beneficial-order aligned region that fully fits in the tt -
+ * that region could have been a beneficial-order page. A low
+ * order in the unaligned trailing tail is expected and must not
+ * flag the tt (mirrors ttm_pool_harvest_remaining()).
+ */
+ if (it->beneficial_order && it->order < it->beneficial_order) {
+ pgoff_t bnr = 1UL << it->beneficial_order;
+ pgoff_t off = it->tt->num_pages -
+ it->alloc->remaining_pages;
+
+ if (round_down(off, bnr) + bnr <= it->tt->num_pages)
+ it->tt->page_flags |=
+ TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
+ }
+ return;
+ }
+
/*
* Fault injection: pretend allocation at (or above) the device's
* beneficial order failed, forcing a sub-optimal backing. Exercises the
@@ -1582,7 +1804,8 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
int ret;
if (WARN_ON(ttm_tt_is_backed_up(tt)) ||
- WARN_ON(ctx->defrag_bytes_remaining < 0))
+ WARN_ON(ctx->defrag_bytes_remaining < 0) ||
+ WARN_ON(ctx->prealloc && ctx->prealloc->caching != tt->caching))
return -EINVAL;
tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 3055cc411d73..51c4ebd477b3 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -238,16 +238,19 @@ struct ttm_operation_ctx {
*/
s64 defrag_bytes_remaining;
/**
- * @prealloc: Pages preallocated outside the dma-resv lock for a defrag
- * move. The pool allocator consumes these instead of allocating fresh
- * beneficial-order pages under the lock, moving the (potentially
- * reclaim/compaction stalling) high-order allocations out of the
- * critical section. NULL means allocate in-line as usual. The pool
- * never allocates in-line once the bag is drained: the remainder is
- * harvested from the old tt as-is, and a defrag move that allocates no
- * chunk fails with -ENOMEM. The allocator consumes it for
- * beneficial-order chunks of any populate; drivers only set it for a
- * defrag move.
+ * @prealloc: Pages preallocated outside the dma-resv lock. The pool
+ * allocator consumes these instead of allocating under the lock, moving
+ * the (potentially reclaim/compaction stalling) allocations out of the
+ * critical section. NULL means allocate in-line as usual. Two flavours,
+ * distinguished by ttm_pool_prealloc::full:
+ * - defrag bag (full=false): a bag of interchangeable beneficial-order
+ * chunks consumed only for beneficial-order chunks of a defrag move.
+ * - full tiling (full=true): the entire backing of the tt, at mixed
+ * orders, consumed for every chunk of an ordinary populate.
+ * For a full tiling the allocator falls back to in-line allocation
+ * for any shortfall. For a defrag bag it never allocates in-line:
+ * once the bag is drained the remainder is harvested from the old tt
+ * as-is, and a defrag move that allocates no chunk fails with -ENOMEM.
*/
struct ttm_pool_prealloc *prealloc;
/**
diff --git a/include/drm/ttm/ttm_pool.h b/include/drm/ttm/ttm_pool.h
index 3f2e51151af9..dc2fc4e855b2 100644
--- a/include/drm/ttm/ttm_pool.h
+++ b/include/drm/ttm/ttm_pool.h
@@ -83,18 +83,27 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt);
/**
* struct ttm_pool_prealloc - Pages preallocated outside the dma-resv lock
- * @pages: Array of @count beneficial-order pages (or fewer if a fill fell
- * short); each entry is the head page of a 1 << @order chunk.
- * @order: Page order of every preallocated chunk.
+ * @pages: Array of @count preallocated chunks; each entry is the head page of a
+ * chunk. In defrag mode every chunk is @order pages; in @full mode the
+ * chunks tile a whole tt at mixed orders and the per-chunk order is read
+ * back from the page itself.
+ * @order: Page order of every preallocated chunk (defrag mode only; 0 in @full
+ * mode where each chunk carries its own order).
* @caching: CPU caching applied to the pages, so leftovers can be restored
* to write-back before being freed.
* @count: Number of valid entries in @pages.
* @used: Number of entries already consumed by the pool allocator.
+ * @full: When set the bag holds a full, mixed-order tiling of an entire tt
+ * (produced by ttm_pool_prealloc_fill_full()) rather than a bag of
+ * interchangeable beneficial-order defrag chunks. The pool allocator
+ * then drains the bag in order for every populate, taking each chunk's
+ * order from the page, and falls back to in-line allocation only for any
+ * shortfall.
*
* Defrag pages are interchangeable, so only a count of beneficial-order chunks
- * is needed. ttm_pool_prealloc_fill() populates this outside the lock and
- * __ttm_pool_alloc() drains it; any unused tail is released by
- * ttm_pool_prealloc_fini().
+ * is needed. ttm_pool_prealloc_fill() / ttm_pool_prealloc_fill_full() populate
+ * this outside the lock and __ttm_pool_alloc() drains it; any unused tail is
+ * released by ttm_pool_prealloc_fini().
*/
struct ttm_pool_prealloc {
struct page **pages;
@@ -102,10 +111,16 @@ struct ttm_pool_prealloc {
enum ttm_caching caching;
unsigned int count;
unsigned int used;
+ bool full;
};
int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
struct ttm_pool_prealloc *pp, unsigned int count);
+int ttm_pool_prealloc_fill_full(struct ttm_pool *pool,
+ enum ttm_caching tt_caching,
+ struct ttm_pool_prealloc *pp,
+ unsigned int num_pages,
+ bool beneficial_reclaim_backoff);
void ttm_pool_prealloc_fini(struct ttm_pool *pool,
struct ttm_pool_prealloc *pp);
unsigned int ttm_pool_prealloc_order(struct ttm_pool *pool);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 12/36] drm/gpusvm: Add a DMA-mapping accounting callback
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
` (10 preceding siblings ...)
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:32 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 13/36] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
` (26 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:32 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Thomas Hellström, Natalie Vock, Arun Pravin,
Niranjana Vishwanathapura
From: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Drivers that use the GPU SVM core to DMA-map system memory for GPU
access may want to keep track of how many pages they have mapped, for
example to expose statistics or to detect leaks. Doing this accounting
in the driver around drm_gpusvm_get_pages() / drm_gpusvm_unmap_pages()
is error prone: the number, order and kind of the dma_addr[] entries can
change between map and unmap (migration, partial unmaps, the iova vs
non-iova paths), which makes symmetric accounting hard to get right.
Add an optional @dma_map_account callback to struct drm_gpusvm_ops and
invoke it once per &drm_pagemap_addr entry at the exact points where the
entry is DMA-mapped (sign == +1) in drm_gpusvm_get_pages() and unmapped
(sign == -1) in __drm_gpusvm_unmap_pages(). Since the map error path and
every unmap/free path funnel through __drm_gpusvm_unmap_pages() for the
entries that were actually mapped, the accounting is symmetric by
construction. The callback receives the full &drm_pagemap_addr so the
driver can use the order and the proto field to distinguish system
memory mappings from device interconnect mappings.
The callback must also be usable by the core drm_gpusvm_pages-only API
(mm == NULL), as used e.g. for userptr-style mappings. Relax
drm_gpusvm_init() to allow such users to pass a restricted @ops that
only implements the page-level hooks; the full-SVM hooks (@invalidate)
and the chunk configuration must still be unset in that mode.
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/drm_gpusvm.c | 41 ++++++++++++++++++++++++++++--------
include/drm/drm_gpusvm.h | 19 +++++++++++++++++
2 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
index de2fa2684e84..92f46aad71f3 100644
--- a/drivers/gpu/drm/drm_gpusvm.c
+++ b/drivers/gpu/drm/drm_gpusvm.c
@@ -503,8 +503,16 @@ int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
return -EINVAL;
mmgrab(mm);
} else {
- /* No full SVM mode, only core drm_gpusvm_pages API. */
- if (ops || num_chunks || mm_range || notifier_size)
+ /*
+ * No full SVM mode, only core drm_gpusvm_pages API. A
+ * restricted @ops that only implements the page-level hooks
+ * (e.g. @dma_map_account) is allowed; the full-SVM hooks must
+ * not be set.
+ */
+ if (num_chunks || mm_range || notifier_size)
+ return -EINVAL;
+ if (ops && (ops->invalidate || ops->range_alloc ||
+ ops->range_free))
return -EINVAL;
}
@@ -1240,9 +1248,12 @@ static void __drm_gpusvm_unmap_pages(struct drm_gpusvm *gpusvm,
struct drm_gpusvm_pages_flags flags = {
.__flags = svm_pages->flags.__flags,
};
+ bool contiguous;
const struct drm_pagemap_addr *addrs =
- drm_gpusvm_pages_first_dma(svm_pages, NULL);
+ drm_gpusvm_pages_first_dma(svm_pages, &contiguous);
bool use_iova = dma_use_iova(&svm_pages->state);
+ bool needs_account = gpusvm->ops &&
+ gpusvm->ops->dma_map_account;
/*
* IOVA is reserved for the whole range but only the linked
@@ -1260,14 +1271,18 @@ static void __drm_gpusvm_unmap_pages(struct drm_gpusvm *gpusvm,
/*
* With IOVA and no device page the unlink above tore every
- * entry down, and that is also when the range may be folded
- * to one entry, which must not be walked per entry. dpagemap
- * is set before the first device_map(), so it is also right
- * on the error path, where the flags are not published yet.
+ * entry down, but the per-entry walk is still needed when the
+ * driver accounts the mappings. A folded (inline) mapping has
+ * a single entry describing the whole range, so it must be
+ * re-read for every iteration instead of indexed by @j.
+ * dpagemap is set before the first device_map(), so it is also
+ * right on the error path, where the flags are not published
+ * yet.
*/
for (i = 0, j = 0;
- (!use_iova || dpagemap) && i < npages; j++) {
- const struct drm_pagemap_addr *addr = &addrs[j];
+ (!use_iova || dpagemap || needs_account) && i < npages; j++) {
+ const struct drm_pagemap_addr *addr =
+ contiguous ? &addrs[0] : &addrs[j];
if (addr->proto == DRM_INTERCONNECT_SYSTEM) {
/*
@@ -1283,6 +1298,10 @@ static void __drm_gpusvm_unmap_pages(struct drm_gpusvm *gpusvm,
} else if (dpagemap && dpagemap->ops->device_unmap)
dpagemap->ops->device_unmap(dpagemap,
dev, addr);
+
+ if (needs_account)
+ gpusvm->ops->dma_map_account(gpusvm, addr, -1);
+
i += 1 << addr->order;
}
@@ -1705,6 +1724,10 @@ static int drm_gpusvm_dma_map_pages(struct drm_gpusvm *gpusvm,
(addr, DRM_INTERCONNECT_SYSTEM, order,
dma_dir);
}
+ if (gpusvm->ops && gpusvm->ops->dma_map_account)
+ gpusvm->ops->dma_map_account(gpusvm,
+ &svm_pages->dma_addr[j],
+ 1);
i += 1 << order;
num_dma_mapped = i;
flags.has_dma_mapping = true;
diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h
index b43432af5637..fb6c1fa78e2d 100644
--- a/include/drm/drm_gpusvm.h
+++ b/include/drm/drm_gpusvm.h
@@ -75,6 +75,25 @@ struct drm_gpusvm_ops {
void (*invalidate)(struct drm_gpusvm *gpusvm,
struct drm_gpusvm_notifier *notifier,
const struct mmu_notifier_range *mmu_range);
+
+ /**
+ * @dma_map_account: Account a DMA-mapping change (optional)
+ * @gpusvm: Pointer to the GPU SVM
+ * @addr: The address descriptor of the chunk being (un)mapped
+ * @sign: +1 when @addr has just been DMA-mapped, -1 when it is being
+ * unmapped
+ *
+ * Called once per &drm_pagemap_addr entry, when the entry is
+ * DMA-mapped by drm_gpusvm_get_pages() (@sign == +1) and when it is
+ * unmapped (@sign == -1), so the driver can keep symmetric accounting
+ * of the pages it has mapped for GPU access. The @addr->proto field
+ * can be used to distinguish system-memory mappings from device
+ * interconnect mappings. May be provided in both full SVM mode and the
+ * core drm_gpusvm_pages-only mode.
+ */
+ void (*dma_map_account)(struct drm_gpusvm *gpusvm,
+ const struct drm_pagemap_addr *addr,
+ int sign);
};
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 13/36] drm/xe: Add debugfs stats for DMA-mapped pages per order
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
` (11 preceding siblings ...)
2026-12-02 23:32 ` [PATCH v5 12/36] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-03 0:25 ` Niranjana Vishwanathapura
2026-12-02 23:33 ` [PATCH v5 14/36] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
` (25 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel; +Cc: Thomas Hellström, Natalie Vock, Arun Pravin
From: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Expose per-page-order DMA mapping counts for the system memory that the
xe driver maps for GPU access, split into two categories: TTM buffer
objects, and the GPU SVM / userptr ranges (which share a single
drm_gpusvm instance per VM).
The stats are visible at:
<debugfs>/dri/<N>/dma_mapped_pages
and are broken out into two rows (bo, svm/userptr), one column per page
order, mirroring the layout of the TTM pool page_pool stat.
For TTM BOs the per-order counts are derived from the DMA scatter-gather
table: each mapped segment is physically contiguous, so its page count is
split into the largest power-of-two runs (a segment of N pages contributes
a 2^k chunk for the largest k with 2^k <= N, repeated for the remainder).
Driving the accounting off the sg table rather than the pages[] array keeps
it correct even when pages[] entries are cleared while still DMA-mapped,
as happens on the defrag page-borrowing path. Dma-buf BOs are not
accounted for in dma_mapped_pages stats.
For the SVM and userptr ranges the accounting is driven by the
drm_gpusvm @dma_map_account callback, which fires once per dma_addr[]
entry at the exact point the entry is DMA-mapped and unmapped. This
makes the accounting symmetric by construction and avoids driver-side
walks that could drift across migration, partial unmaps and the iova vs
non-iova paths. Only DRM_INTERCONNECT_SYSTEM entries are real DMA maps
and counted; device interconnect (VRAM, P2P) entries are skipped, so the
counter reflects only system pages actually mapped through the DMA layer.
The callback is shared between the full SVM instance (fault mode) and the
core drm_gpusvm_pages-only instance used for userptr, so userptr
mappings are accounted in both the CONFIG_DRM_XE_GPUSVM=y and =n (but
CONFIG_DRM_GPUSVM=y) configurations, into the same svm/userptr counter.
Since the counts are only ever consumed through debugfs, gate the counter
storage and all accounting on CONFIG_DEBUG_FS so that builds without
debugfs carry no extra atomic traffic or device state; the drm_gpusvm
callback is simply left unregistered in that case.
On device teardown assert that every counter has returned to zero, to
catch any unbalanced accounting (a leaked DMA mapping) during testing.
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 53 ++++++++++++++++++++---
drivers/gpu/drm/xe/xe_debugfs.c | 26 ++++++++++++
drivers/gpu/drm/xe/xe_device.c | 24 +++++++++++
drivers/gpu/drm/xe/xe_device_types.h | 17 ++++++++
drivers/gpu/drm/xe/xe_svm.c | 8 +++-
drivers/gpu/drm/xe/xe_svm.h | 4 +-
drivers/gpu/drm/xe/xe_userptr.c | 63 ++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_userptr.h | 7 ++++
8 files changed, 194 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index c89b39b503fe..ff5610ba4b74 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -398,6 +398,50 @@ struct xe_ttm_tt {
bool purgeable;
};
+/*
+ * xe_tt_account_dma_pages - account DMA-mapped tt pages per order
+ * @xe: the xe device
+ * @xe_tt: the xe_ttm_tt whose sg table to walk
+ * @sign: +1 to add, -1 to subtract
+ *
+ * Walk the tt's DMA scatter-gather table and split each (physically
+ * contiguous) segment into the largest power-of-two page runs: a segment of N
+ * pages contributes a 2^k chunk for the largest k with 2^k <= N, repeated for
+ * the remainder. Accumulate the count of 2^k pages into
+ * xe->mem.dma_mapped_pages[k]. Driving this off the sg table rather than
+ * tt->pages keeps the accounting correct even when pages[] entries are cleared
+ * while still DMA-mapped (e.g. the defrag page-borrowing path).
+ */
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static void xe_tt_account_dma_pages(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt, int sign)
+{
+ struct scatterlist *sg;
+ unsigned int i;
+
+ for_each_sgtable_sg(xe_tt->sg, sg, i) {
+ unsigned long nr_pages = sg->length >> PAGE_SHIFT;
+
+ while (nr_pages) {
+ unsigned int order = min_t(unsigned int,
+ __fls(nr_pages),
+ MAX_PAGE_ORDER);
+ unsigned long chunk = 1UL << order;
+
+ atomic_long_add((long)chunk * sign,
+ &xe->mem.dma_mapped_pages[order]);
+
+ nr_pages -= chunk;
+ }
+ }
+}
+#else
+static void xe_tt_account_dma_pages(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt, int sign)
+{
+}
+#endif
+
static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
{
struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
@@ -427,6 +471,7 @@ static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
return ret;
}
+ xe_tt_account_dma_pages(xe, xe_tt, 1);
return 0;
}
@@ -435,6 +480,7 @@ static void xe_tt_unmap_sg(struct xe_device *xe, struct ttm_tt *tt)
struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
if (xe_tt->sg) {
+ xe_tt_account_dma_pages(xe, xe_tt, -1);
dma_unmap_sgtable(xe->drm.dev, xe_tt->sg,
DMA_BIDIRECTIONAL, 0);
sg_free_table(xe_tt->sg);
@@ -1890,11 +1936,8 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo)
ttm_bo->sg = NULL;
xe_tt->sg = NULL;
} else if (xe_tt->sg) {
- dma_unmap_sgtable(ttm_to_xe_device(ttm_bo->bdev)->drm.dev,
- xe_tt->sg,
- DMA_BIDIRECTIONAL, 0);
- sg_free_table(xe_tt->sg);
- xe_tt->sg = NULL;
+ xe_tt_unmap_sg(ttm_to_xe_device(ttm_bo->bdev),
+ &xe_tt->ttm);
}
}
diff --git a/drivers/gpu/drm/xe/xe_debugfs.c b/drivers/gpu/drm/xe/xe_debugfs.c
index bc62d1054d29..be533435097f 100644
--- a/drivers/gpu/drm/xe/xe_debugfs.c
+++ b/drivers/gpu/drm/xe/xe_debugfs.c
@@ -8,6 +8,7 @@
#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/debugfs.h>
+#include <linux/mmzone.h>
#include <linux/fault-inject.h>
#include <linux/string_helpers.h>
@@ -349,6 +350,28 @@ static int dgfx_pcie_link_residencies_show(struct seq_file *m, void *data)
return 0;
}
+static int dma_mapped_pages_show(struct seq_file *m, void *data)
+{
+ struct xe_device *xe = m->private;
+ unsigned int i;
+
+ seq_printf(m, "%-11s ", "");
+ for (i = 0; i < NR_PAGE_ORDERS; i++)
+ seq_printf(m, " ---%2u---", i);
+ seq_printf(m, "\n%-11s:", "bo");
+ for (i = 0; i < NR_PAGE_ORDERS; i++)
+ seq_printf(m, " %8ld",
+ atomic_long_read(&xe->mem.dma_mapped_pages[i]));
+ seq_printf(m, "\n%-11s:", "svm/userptr");
+ for (i = 0; i < NR_PAGE_ORDERS; i++)
+ seq_printf(m, " %8ld",
+ atomic_long_read(&xe->mem.dma_mapped_pages_svm[i]));
+ seq_puts(m, "\n");
+
+ return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(dma_mapped_pages);
+
static const struct drm_info_list debugfs_list[] = {
{"info", info, 0},
{ .name = "sriov_info", .show = sriov_info, },
@@ -768,6 +791,9 @@ void xe_debugfs_register(struct xe_device *xe)
xe_ttm_vram_debugfs_init(xe, root);
+ debugfs_create_file("dma_mapped_pages", 0444, root, xe,
+ &dma_mapped_pages_fops);
+
for_each_tile(tile, xe, tile_id)
xe_tile_debugfs_register(tile);
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 86de5f183c0a..781324ef950d 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -382,6 +382,28 @@ bool xe_device_is_admin_only(const struct xe_device *xe)
/* Number of allocated struct xe_device */
static atomic_t xe_device_count;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static void xe_device_assert_dma_pages_zero(struct xe_device *xe)
+{
+ unsigned int i;
+
+ /*
+ * All BOs, userptr VMAs and SVM ranges must have been torn down by the
+ * time the device is destroyed, so every DMA-mapped-pages counter must
+ * have returned to zero. A non-zero value indicates unbalanced
+ * accounting, i.e. a missing unmap-side decrement.
+ */
+ for (i = 0; i < NR_PAGE_ORDERS; i++) {
+ xe_assert(xe, !atomic_long_read(&xe->mem.dma_mapped_pages[i]));
+ xe_assert(xe, !atomic_long_read(&xe->mem.dma_mapped_pages_svm[i]));
+ }
+}
+#else
+static void xe_device_assert_dma_pages_zero(struct xe_device *xe)
+{
+}
+#endif
+
static void xe_device_destroy(struct drm_device *dev, void *dummy)
{
struct xe_device *xe = to_xe_device(dev);
@@ -405,6 +427,8 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
ttm_device_fini(&xe->ttm);
+ xe_device_assert_dma_pages_zero(xe);
+
if (atomic_dec_and_test(&xe_device_count))
wake_up_var(&xe_device_count);
}
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index e4e2fba44c8e..f00fc544d21c 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -6,6 +6,7 @@
#ifndef _XE_DEVICE_TYPES_H_
#define _XE_DEVICE_TYPES_H_
+#include <linux/mmzone.h>
#include <linux/pci.h>
#include <linux/workqueue.h>
@@ -307,6 +308,22 @@ struct xe_device {
struct xe_shrinker *shrinker;
/** @mem.stolen_mgr: stolen memory manager. */
struct xe_ttm_stolen_mgr *stolen_mgr;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+ /**
+ * @mem.dma_mapped_pages: number of DMA-mapped pages per page
+ * order currently live for this device, for TTM BOs. Only
+ * accounted when CONFIG_DEBUG_FS is enabled, since it is solely
+ * exposed through debugfs.
+ */
+ atomic_long_t dma_mapped_pages[NR_PAGE_ORDERS];
+ /**
+ * @mem.dma_mapped_pages_svm: number of DMA-mapped pages per
+ * page order currently live for this device, for SVM ranges
+ * and userptr VMAs (both share a single drm_gpusvm instance).
+ * Only accounted when CONFIG_DEBUG_FS is enabled.
+ */
+ atomic_long_t dma_mapped_pages_svm[NR_PAGE_ORDERS];
+#endif
} mem;
/** @sriov: device level virtualization data */
diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
index bc6902b5bf57..3f90b8314132 100644
--- a/drivers/gpu/drm/xe/xe_svm.c
+++ b/drivers/gpu/drm/xe/xe_svm.c
@@ -24,6 +24,7 @@
#include "xe_tile.h"
#include "xe_tlb_inval.h"
#include "xe_ttm_vram_mgr.h"
+#include "xe_userptr.h"
#include "xe_vm.h"
#include "xe_vm_types.h"
#include "xe_vram_types.h"
@@ -850,6 +851,9 @@ static const struct drm_gpusvm_ops gpusvm_ops = {
.range_alloc = xe_svm_range_alloc,
.range_free = xe_svm_range_free,
.invalidate = xe_svm_invalidate,
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+ .dma_map_account = xe_userptr_dma_map_account,
+#endif
};
static const unsigned long fault_chunk_sizes[] = {
@@ -947,8 +951,8 @@ int xe_svm_init(struct xe_vm *vm)
}
} else {
err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
- NULL, 0, 0, 0, NULL,
- NULL, 0);
+ NULL, 0, 0, 0,
+ xe_userptr_gpusvm_ops_get(), NULL, 0);
if (err)
goto out_err;
}
diff --git a/drivers/gpu/drm/xe/xe_svm.h b/drivers/gpu/drm/xe/xe_svm.h
index ffc1cc808102..f8b908a74ba9 100644
--- a/drivers/gpu/drm/xe/xe_svm.h
+++ b/drivers/gpu/drm/xe/xe_svm.h
@@ -249,6 +249,7 @@ struct drm_pagemap *xe_drm_pagemap_from_fd(int fd, u32 region_instance);
#else
#include <linux/interval_tree.h>
+#include "xe_userptr.h"
#include "xe_vm.h"
struct drm_pagemap_addr;
@@ -296,7 +297,8 @@ int xe_svm_init(struct xe_vm *vm)
{
#if IS_ENABLED(CONFIG_DRM_GPUSVM)
return drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
- NULL, 0, 0, 0, NULL, NULL, 0);
+ NULL, 0, 0, 0,
+ xe_userptr_gpusvm_ops_get(), NULL, 0);
#else
return 0;
#endif
diff --git a/drivers/gpu/drm/xe/xe_userptr.c b/drivers/gpu/drm/xe/xe_userptr.c
index 39806ca9f54a..28770bffeced 100644
--- a/drivers/gpu/drm/xe/xe_userptr.c
+++ b/drivers/gpu/drm/xe/xe_userptr.c
@@ -8,9 +8,72 @@
#include <linux/mm.h>
+#include <drm/drm_pagemap.h>
+
#include "xe_tlb_inval.h"
#include "xe_trace_bo.h"
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+/*
+ * xe_userptr_dma_map_account() - drm_gpusvm DMA-mapping accounting callback
+ * @gpusvm: The GPU SVM the mapping belongs to
+ * @addr: The address descriptor of the chunk being (un)mapped
+ * @sign: +1 when @addr was DMA-mapped, -1 when it is being unmapped
+ *
+ * Account, per page order, the system-memory pages DMA-mapped for GPU access
+ * through the drm_gpusvm_pages instance shared by userptr (and, in fault mode,
+ * SVM). Only DRM_INTERCONNECT_SYSTEM entries are real DMA maps and counted;
+ * device interconnect (VRAM, P2P) entries are skipped. The counts are solely
+ * exposed through debugfs, so the callback is only registered when
+ * CONFIG_DEBUG_FS is enabled.
+ */
+void xe_userptr_dma_map_account(struct drm_gpusvm *gpusvm,
+ const struct drm_pagemap_addr *addr,
+ int sign)
+{
+ struct xe_vm *vm = container_of(gpusvm, struct xe_vm, svm.gpusvm);
+ unsigned int order = addr->order;
+
+ if (addr->proto != DRM_INTERCONNECT_SYSTEM)
+ return;
+
+ /*
+ * The CPU-PTE map order reported by hmm can exceed MAX_PAGE_ORDER
+ * (e.g. an order-18 1GB mapping), so clamp the array index to avoid an
+ * out-of-bounds access. Clamping is symmetric across the +1/-1 calls,
+ * so the per-order counters stay balanced.
+ */
+ order = min(order, (unsigned int)NR_PAGE_ORDERS - 1);
+
+ atomic_long_add((long)(1UL << addr->order) * sign,
+ &vm->xe->mem.dma_mapped_pages_svm[order]);
+}
+
+static const struct drm_gpusvm_ops xe_userptr_gpusvm_ops = {
+ .dma_map_account = xe_userptr_dma_map_account,
+};
+#endif
+
+/**
+ * xe_userptr_gpusvm_ops_get() - Accounting ops for the simple gpusvm instance
+ *
+ * The core drm_gpusvm_pages-only instance used for userptr (and, in fault
+ * mode, shared with SVM) is initialised with these ops so that DMA-mapped
+ * system pages are accounted and exposed through debugfs. Returns NULL when
+ * CONFIG_DEBUG_FS is disabled, in which case no accounting is kept and the
+ * instance is initialised without ops.
+ *
+ * Return: Pointer to the restricted &drm_gpusvm_ops, or NULL.
+ */
+const struct drm_gpusvm_ops *xe_userptr_gpusvm_ops_get(void)
+{
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+ return &xe_userptr_gpusvm_ops;
+#else
+ return NULL;
+#endif
+}
+
static void xe_userptr_assert_in_notifier(struct xe_vm *vm)
{
lockdep_assert(lockdep_is_held_type(&vm->svm.gpusvm.notifier_lock, 0) ||
diff --git a/drivers/gpu/drm/xe/xe_userptr.h b/drivers/gpu/drm/xe/xe_userptr.h
index 179f2aca26a3..52d9734ccecc 100644
--- a/drivers/gpu/drm/xe/xe_userptr.h
+++ b/drivers/gpu/drm/xe/xe_userptr.h
@@ -151,6 +151,12 @@ struct xe_userptr {
};
#if IS_ENABLED(CONFIG_DRM_GPUSVM)
+
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+void xe_userptr_dma_map_account(struct drm_gpusvm *gpusvm,
+ const struct drm_pagemap_addr *addr, int sign);
+#endif
+
void xe_userptr_remove(struct xe_userptr_vma *uvma);
int xe_userptr_setup(struct xe_userptr_vma *uvma, unsigned long start,
unsigned long range);
@@ -161,6 +167,7 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm);
int xe_vm_userptr_check_repin(struct xe_vm *vm);
int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma);
int xe_vma_userptr_check_repin(struct xe_userptr_vma *uvma);
+const struct drm_gpusvm_ops *xe_userptr_gpusvm_ops_get(void);
#else
static inline void xe_userptr_remove(struct xe_userptr_vma *uvma) {}
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 14/36] drm/xe: Track BOs backed at a sub-optimal page order
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
` (12 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 13/36] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:53 ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 15/36] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
` (24 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Add per-device tracking of BOs whose backing TT pages were allocated
below the pool's beneficial order, as reported by the
TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED tt page flag (read via
ttm_tt_is_beneficial_order_failed()). These BOs are future candidates for
a defragmentation pass that reallocates their pages at the beneficial
order.
Add a mem.defrag sub-struct (lock, list) to struct
xe_device and a defrag_link to struct xe_bo, initialised at BO create
and device init. Membership is updated from xe_bo_move() via
xe_bo_defrag_update(): a BO is added when it is a populated, needed,
non-pinned ttm_bo_type_device object flagged
TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED, and removed otherwise. BOs are also
removed on pin, on purge, moved to dontneed, and at destroy.
Only ttm_bo_type_device BOs are tracked.
Defragmentation is disabled on VF platforms requiring CCS save/restore
(IS_VF_CCS_NEEDED, a static platform check that, unlike IS_VF_CCS_READY,
does not change during probe), where reallocating BO backing would
interfere with CCS metadata migration (currently broken for VF
migration);
xe_bo_defrag_supported() gates such BOs out of the tracking list.
v4:
- Drop defrag count in favor of only defrag sets reclaim bits
- Call xe_bo_defrag_update on CPU fault (Niranjana)
- Add comment about dma-resv to __xe_bo_defrag_remove (Niranjana)
- Hook pin/unpin tracking into xe_bo_(un)pin_account() so display fb
pins are covered (Sashiko)
- Leave list membership untouched on a failed move (Sashiko)
- Only update on CPU fault when the fault populated the tt, and skip the
lock for already-linked BOs (Sashiko)
- Gate on static IS_VF_CCS_NEEDED rather than IS_VF_CCS_READY
v5:
- Drop mention of count in commit message (Sashiko)
- Try not to contend on defrag list lock on CPU faults (Sashiko)
- Make sure FB pin works with defrag (Sashiko)
- Only update defrag list on successful move (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 142 ++++++++++++++++++++++++++-
drivers/gpu/drm/xe/xe_bo.h | 1 +
drivers/gpu/drm/xe/xe_bo_types.h | 6 ++
drivers/gpu/drm/xe/xe_device.c | 2 +
drivers/gpu/drm/xe/xe_device_types.h | 14 +++
drivers/gpu/drm/xe/xe_sriov_vf_ccs.c | 17 +---
drivers/gpu/drm/xe/xe_sriov_vf_ccs.h | 23 +++++
7 files changed, 188 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index ff5610ba4b74..98c0b32e9543 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -585,6 +585,9 @@ static void xe_bo_account_unpin(struct xe_bo *bo)
xe_ttm_tt_account_add(xe, bo->ttm.ttm);
}
+static void xe_bo_defrag_update(struct xe_bo *bo);
+static void xe_bo_defrag_remove(struct xe_bo *bo);
+
/**
* xe_bo_pin_account() - Pin a bo and account its pages for the shrinker
* @bo: The buffer object to pin.
@@ -598,6 +601,7 @@ void xe_bo_pin_account(struct xe_bo *bo)
{
ttm_bo_pin(&bo->ttm);
xe_bo_account_pin(bo);
+ xe_bo_defrag_remove(bo);
}
/**
@@ -612,6 +616,7 @@ void xe_bo_unpin_account(struct xe_bo *bo)
{
xe_bo_account_unpin(bo);
ttm_bo_unpin(&bo->ttm);
+ xe_bo_defrag_update(bo);
}
static void update_global_total_pages(struct ttm_device *ttm_dev,
@@ -1112,6 +1117,7 @@ void xe_bo_set_purgeable_state(struct xe_bo *bo,
bo->purgeable.state = new_state;
xe_bo_set_purgeable_shrinker(bo, new_state);
+ xe_bo_defrag_update(bo);
}
/**
@@ -1161,6 +1167,115 @@ int xe_ttm_bo_purge(struct ttm_buffer_object *ttm_bo, struct ttm_operation_ctx *
return 0;
}
+/**
+ * xe_bo_defrag_init_early() - Initialize the device defrag BO tracking
+ * @xe: The xe device
+ *
+ * Initialize the list and lock used to track BOs whose backing TT
+ * pages were allocated at a sub-optimal order.
+ */
+void xe_bo_defrag_init_early(struct xe_device *xe)
+{
+ spin_lock_init(&xe->mem.defrag.lock);
+ INIT_LIST_HEAD(&xe->mem.defrag.list);
+}
+
+/*
+ * xe_bo_defrag_supported() - Whether background defragmentation is usable
+ * @xe: xe device instance
+ *
+ * Defragmentation forces TTM moves that reallocate a BO's backing. On a VF
+ * platform that requires CCS save/restore this interacts badly with CCS
+ * metadata migration (which is currently broken for VF migration), so disable
+ * it there: gate BOs out of the defrag list and skip the up-front reclaim
+ * backoff that assumes a later in-place upgrade. This is a static platform
+ * check so the answer can't change during probe, after BOs have been
+ * allocated or tracked.
+ */
+static bool xe_bo_defrag_supported(struct xe_device *xe)
+{
+ return !IS_VF_CCS_NEEDED(xe);
+}
+
+static bool xe_bo_needs_defrag(struct xe_bo *bo)
+{
+ struct ttm_buffer_object *ttm_bo = &bo->ttm;
+ struct ttm_tt *tt = ttm_bo->ttm;
+
+ xe_bo_assert_held(bo);
+
+ return xe_bo_defrag_supported(xe_bo_device(bo)) &&
+ ttm_bo->type == ttm_bo_type_device && tt &&
+ !xe_bo_madv_is_dontneed(bo) &&
+ ttm_tt_is_populated(tt) &&
+ ttm_tt_is_beneficial_order_failed(tt) &&
+ ttm_bo->resource && ttm_bo->resource->mem_type == XE_PL_TT &&
+ !xe_bo_is_pinned(bo);
+}
+
+static void xe_bo_defrag_add(struct xe_bo *bo)
+{
+ struct xe_device *xe = xe_bo_device(bo);
+
+ xe_bo_assert_held(bo);
+ xe_assert(xe, xe_bo_needs_defrag(bo));
+
+ /*
+ * Under the dma-resv lock only the dying-BO path in the worker can
+ * unlink @bo without it, so an already-linked BO needs no locking.
+ */
+ if (!list_empty(&bo->defrag_link))
+ return;
+
+ scoped_guard(spinlock, &xe->mem.defrag.lock) {
+ if (list_empty(&bo->defrag_link))
+ list_add_tail(&bo->defrag_link, &xe->mem.defrag.list);
+ }
+}
+
+static void __xe_bo_defrag_remove(struct xe_bo *bo)
+{
+ struct xe_device *xe = xe_bo_device(bo);
+
+ /*
+ * dma-resv optional version, should only be directly when BO being
+ * destroyed
+ */
+
+ guard(spinlock)(&xe->mem.defrag.lock);
+ if (!list_empty(&bo->defrag_link))
+ list_del_init(&bo->defrag_link);
+}
+
+static void xe_bo_defrag_remove(struct xe_bo *bo)
+{
+ xe_bo_assert_held(bo);
+
+ if (list_empty(&bo->defrag_link))
+ return;
+
+ __xe_bo_defrag_remove(bo);
+}
+
+/**
+ * xe_bo_defrag_update() - Update defrag list membership for a BO
+ * @bo: The buffer object
+ *
+ * Add @bo to the device defrag list when it is a ttm_bo_type_device BO resident
+ * in XE_PL_TT with a populated TT whose pages were allocated at a sub-optimal
+ * order (ttm_tt_is_beneficial_order_failed()) and it isn't pinned. Otherwise
+ * ensure it is removed from the list.
+ */
+static void xe_bo_defrag_update(struct xe_bo *bo)
+{
+ xe_bo_assert_held(bo);
+
+ if (xe_bo_needs_defrag(bo))
+ xe_bo_defrag_add(bo);
+ else
+ xe_bo_defrag_remove(bo);
+}
+
static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
struct ttm_operation_ctx *ctx,
struct ttm_resource *new_mem,
@@ -1413,6 +1528,14 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
if (!ret && ttm_bo->resource && ttm_bo->resource->mem_type == XE_PL_TT)
bo->lru_stamp = jiffies;
+ /*
+ * On failure TTM restores the BO's previous backing (for a defrag move
+ * only after we return, while bo->ttm is still the new tt), so leave
+ * the defrag list membership untouched.
+ */
+ if (!ret)
+ xe_bo_defrag_update(bo);
+
return ret;
}
@@ -1529,6 +1652,15 @@ static long xe_bo_shrink_purge(struct ttm_operation_ctx *ctx,
if (lret > 0) {
xe_ttm_tt_account_subtract(xe, bo->ttm);
update_global_total_pages(bo->bdev, -(long)tt->num_pages);
+
+ /*
+ * The pages are gone, so a tracked BO no longer needs defrag.
+ * This shrinker purge path frees pages without going through
+ * xe_bo_move(), so drop any stale defrag list entry here. Ghost
+ * bos are never tracked, so guard for real xe bos.
+ */
+ if (xe_bo_is_xe_bo(bo))
+ xe_bo_defrag_remove(ttm_to_xe_bo(bo));
}
return lret;
@@ -2171,6 +2303,8 @@ static void xe_ttm_bo_destroy(struct ttm_buffer_object *ttm_bo)
list_del(&bo->vram_userfault_link);
mutex_unlock(&xe->mem_access.vram_userfault.lock);
+ __xe_bo_defrag_remove(bo);
+
kfree(bo);
}
@@ -2245,9 +2379,14 @@ static int xe_bo_fault_migrate(struct xe_bo *bo, struct ttm_operation_ctx *ctx,
int err = 0;
if (ttm_manager_type(tbo->bdev, tbo->resource->mem_type)->use_tt) {
+ bool populated = tbo->ttm && ttm_tt_is_populated(tbo->ttm);
+
err = xe_bo_wait_usage_kernel(bo, ctx);
- if (!err)
+ if (!err) {
err = ttm_bo_populate(&bo->ttm, ctx);
+ if (!err && !populated)
+ xe_bo_defrag_update(bo);
+ }
} else if (should_migrate_to_smem(bo)) {
xe_assert(xe_bo_device(bo), bo->flags & XE_BO_FLAG_SYSTEM);
err = xe_bo_migrate(bo, XE_PL_TT, ctx, exec);
@@ -2689,6 +2828,7 @@ struct xe_bo *xe_bo_init_locked(struct xe_device *xe, struct xe_bo *bo,
bo->ttm.base.funcs = &xe_gem_object_funcs;
bo->ttm.priority = XE_BO_PRIORITY_NORMAL;
INIT_LIST_HEAD(&bo->pinned_link);
+ INIT_LIST_HEAD(&bo->defrag_link);
#ifdef CONFIG_PROC_FS
INIT_LIST_HEAD(&bo->client_link);
#endif
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 6a1ae07d2904..4ec3a2dbaf68 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -231,6 +231,7 @@ void xe_bo_unpin_external(struct xe_bo *bo);
void xe_bo_unpin(struct xe_bo *bo);
void xe_bo_pin_account(struct xe_bo *bo);
void xe_bo_unpin_account(struct xe_bo *bo);
+void xe_bo_defrag_init_early(struct xe_device *xe);
int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict,
struct drm_exec *exec);
diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h
index beae25d3ad4b..dc5b12316bf0 100644
--- a/drivers/gpu/drm/xe/xe_bo_types.h
+++ b/drivers/gpu/drm/xe/xe_bo_types.h
@@ -78,6 +78,12 @@ struct xe_bo {
struct ttm_bo_kmap_obj kmap;
/** @pinned_link: link to present / evicted list of pinned BO */
struct list_head pinned_link;
+ /**
+ * @defrag_link: link into @xe_device.mem.defrag.list for BOs whose
+ * backing TT pages were allocated at a sub-optimal order. Protected by
+ * @xe_device.mem.defrag.lock.
+ */
+ struct list_head defrag_link;
#ifdef CONFIG_PROC_FS
/**
* @client: @xe_drm_client which created the bo
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 781324ef950d..67d648833030 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -549,6 +549,8 @@ int xe_device_init_early(struct xe_device *xe)
if (err)
return err;
+ xe_bo_defrag_init_early(xe);
+
xe->preempt_fence_wq = alloc_ordered_workqueue("xe-preempt-fence-wq",
WQ_MEM_RECLAIM);
xe->rebind_wq = alloc_workqueue("xe-rebind-wq", WQ_UNBOUND, 0);
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index f00fc544d21c..0d09cb5bd2d5 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -324,6 +324,20 @@ struct xe_device {
*/
atomic_long_t dma_mapped_pages_svm[NR_PAGE_ORDERS];
#endif
+ /**
+ * @mem.defrag: Tracking of BOs whose backing TT pages were
+ * allocated at a sub-optimal (smaller than beneficial) order.
+ *
+ * Such BOs are candidates for a future defragmentation pass that
+ * tries to reallocate their pages at the device's beneficial
+ * order. Only ttm_bo_type_device BOs are tracked.
+ */
+ struct {
+ /** @mem.defrag.lock: Protects @mem.defrag.list. */
+ spinlock_t lock;
+ /** @mem.defrag.list: List of struct xe_bo defrag_link. */
+ struct list_head list;
+ } defrag;
} mem;
/** @sriov: device level virtualization data */
diff --git a/drivers/gpu/drm/xe/xe_sriov_vf_ccs.c b/drivers/gpu/drm/xe/xe_sriov_vf_ccs.c
index a54138461f44..40ede31107dc 100644
--- a/drivers/gpu/drm/xe/xe_sriov_vf_ccs.c
+++ b/drivers/gpu/drm/xe/xe_sriov_vf_ccs.c
@@ -272,21 +272,6 @@ int xe_sriov_vf_ccs_register_context(struct xe_device *xe)
return err;
}
-/*
- * Whether GuC requires CCS copy BBs for VF migration.
- * @xe: the &xe_device instance.
- *
- * Only selected platforms require VF KMD to maintain CCS copy BBs and linked LRCAs.
- *
- * Return: true if VF driver must participate in the CCS migration, false otherwise.
- */
-static bool vf_migration_ccs_bb_needed(struct xe_device *xe)
-{
- xe_assert(xe, IS_SRIOV_VF(xe));
-
- return !IS_DGFX(xe) && xe_device_has_flat_ccs(xe);
-}
-
/*
* Check for disable migration due to no CCS BBs support in GuC FW.
* @xe: the &xe_device instance.
@@ -345,7 +330,7 @@ int xe_sriov_vf_ccs_init(struct xe_device *xe)
xe_assert(xe, IS_SRIOV_VF(xe));
if (!xe_sriov_vf_migration_supported(xe) ||
- !vf_migration_ccs_bb_needed(xe) ||
+ !xe_sriov_vf_ccs_needed(xe) ||
!vf_migration_ccs_bb_support_check(xe))
return 0;
diff --git a/drivers/gpu/drm/xe/xe_sriov_vf_ccs.h b/drivers/gpu/drm/xe/xe_sriov_vf_ccs.h
index e1034d852104..572cd2c42702 100644
--- a/drivers/gpu/drm/xe/xe_sriov_vf_ccs.h
+++ b/drivers/gpu/drm/xe/xe_sriov_vf_ccs.h
@@ -34,4 +34,27 @@ static inline bool xe_sriov_vf_ccs_ready(struct xe_device *xe)
IS_SRIOV_VF(xe__) && xe_sriov_vf_ccs_ready(xe__); \
})
+/**
+ * xe_sriov_vf_ccs_needed() - Whether GuC requires CCS copy BBs for VF migration
+ * @xe: the &xe_device instance.
+ *
+ * Only selected platforms require VF KMD to maintain CCS copy BBs and linked
+ * LRCAs. Unlike xe_sriov_vf_ccs_ready(), this is a static platform property,
+ * valid from probe onwards and independent of whether CCS save/restore was
+ * actually set up.
+ *
+ * Return: true if VF driver must participate in the CCS migration, false
+ * otherwise.
+ */
+static inline bool xe_sriov_vf_ccs_needed(struct xe_device *xe)
+{
+ xe_assert(xe, IS_SRIOV_VF(xe));
+ return !IS_DGFX(xe) && xe->info.has_flat_ccs;
+}
+
+#define IS_VF_CCS_NEEDED(xe) ({ \
+ struct xe_device *xe__ = (xe); \
+ IS_SRIOV_VF(xe__) && xe_sriov_vf_ccs_needed(xe__); \
+ })
+
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 15/36] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies
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
` (13 preceding siblings ...)
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:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
` (23 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Add xe_migrate_copy_defrag(), a copy helper for the upcoming page
defragmentation path where a single BO has its backing reallocated at a
more beneficial page order and its contents must be relocated from the
old pages to the new ones entirely on the GPU.
The contents are relocated in up to two passes:
- Data pass (always): copy the data pages verbatim. The pages are
mapped without the compression PAT, so the (possibly compressed)
bytes are copied as-is rather than being decompressed and
recompressed, and no CCS aux copy is appended.
- CCS pass (need_ccs): copy the CCS aux (compression) state. Both the
old and new data pages are mapped with the compression PAT so the
copy engine accesses the aux state indirectly, issuing one
indirect -> indirect XY_CTRL_SURF_COPY_BLT; the data blit is skipped.
The two passes are issued separately because they require opposite
compression PAT settings on the data page mappings (cleared for the
verbatim data copy, set for the indirect CCS access), which a single
mapping cannot satisfy. Both passes run in order on the same migrate
queue and are captured by the returned fence.
The source pages are passed explicitly via an sg_table argument (the
old, still populated backing) since they no longer match the BO's
current backing. The boolean arguments to __xe_migrate_copy() are replaced
by a single enum xe_migrate_copy_mode, since the copy variants are
mutually exclusive.
v4:
- s/struct xe_migrate_copy_flags/enum xe_migrate_copy_mode (Niranjana)
v5:
- non-interruptible comment (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/xe/xe_migrate.c | 135 ++++++++++++++++++++++++++++----
drivers/gpu/drm/xe/xe_migrate.h | 8 ++
2 files changed, 129 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 23575f9dc651..71192fbd722d 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -1292,16 +1292,50 @@ static bool is_devmem(struct xe_bo *bo, struct ttm_resource *res)
return true;
}
+/**
+ * enum xe_migrate_copy_mode - Mode for __xe_migrate_copy()
+ * @XE_MIGRATE_COPY_NORMAL: Regular copy of data (and CCS aux state if needed).
+ * @XE_MIGRATE_COPY_CCS_ONLY: Only copy the CCS aux state, aliasing the
+ * destination data mapping to the source (used when the data pages are shared
+ * between src/dst).
+ * @XE_MIGRATE_COPY_VRAM_RESOLVE: Decompression (VRAM -> system) resolve;
+ * always uses the compression PAT index for the data copy.
+ * @XE_MIGRATE_COPY_DEFRAG_DATA: Defrag move pass that copies the data pages
+ * between two distinct page sets (old @src_sg pages -> new pages) without
+ * touching the CCS aux state. The data pages are mapped without the
+ * compression PAT so the (possibly compressed) bytes are copied verbatim
+ * rather than being decompressed and recompressed, and no CCS aux copy is
+ * appended; the aux state is migrated separately by the
+ * @XE_MIGRATE_COPY_DEFRAG_CCS pass.
+ * @XE_MIGRATE_COPY_DEFRAG_CCS: Defrag move pass that migrates only the CCS aux
+ * state between two distinct page sets (old @src_sg pages -> new pages). The
+ * data blit is skipped (the data was copied by the
+ * @XE_MIGRATE_COPY_DEFRAG_DATA pass) and both the source and destination data
+ * pages are mapped with the compression PAT so the aux state is copied
+ * indirect -> indirect. The two defrag passes need opposite compression PAT
+ * settings, which is why they cannot be combined.
+ */
+enum xe_migrate_copy_mode {
+ XE_MIGRATE_COPY_NORMAL,
+ XE_MIGRATE_COPY_CCS_ONLY,
+ XE_MIGRATE_COPY_VRAM_RESOLVE,
+ XE_MIGRATE_COPY_DEFRAG_DATA,
+ XE_MIGRATE_COPY_DEFRAG_CCS,
+};
static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
struct xe_bo *src_bo,
struct xe_bo *dst_bo,
struct ttm_resource *src,
struct ttm_resource *dst,
- bool copy_only_ccs,
- bool is_vram_resolve,
+ struct sg_table *src_sg,
+ enum xe_migrate_copy_mode mode,
bool intr)
{
+ bool copy_only_ccs = mode == XE_MIGRATE_COPY_CCS_ONLY;
+ bool is_vram_resolve = mode == XE_MIGRATE_COPY_VRAM_RESOLVE;
+ bool defrag_copy = mode == XE_MIGRATE_COPY_DEFRAG_DATA;
+ bool defrag_ccs = mode == XE_MIGRATE_COPY_DEFRAG_CCS;
struct xe_gt *gt = m->tile->primary_gt;
struct xe_device *xe = gt_to_xe(gt);
struct dma_fence *fence = NULL;
@@ -1317,10 +1351,13 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
bool src_is_vram = is_devmem(src_bo, src);
bool dst_is_vram = is_devmem(dst_bo, dst);
bool type_device = src_bo->ttm.type == ttm_bo_type_device;
- bool needs_ccs_emit = type_device && xe_migrate_needs_ccs_emit(xe);
+ bool needs_ccs_emit = type_device && xe_migrate_needs_ccs_emit(xe) &&
+ !defrag_copy;
bool copy_ccs = xe_device_has_flat_ccs(xe) &&
- xe_bo_needs_ccs_pages(src_bo) && xe_bo_needs_ccs_pages(dst_bo);
- bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram);
+ xe_bo_needs_ccs_pages(src_bo) && xe_bo_needs_ccs_pages(dst_bo) &&
+ !defrag_copy;
+ bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram) &&
+ !defrag_ccs && !defrag_copy;
/*
* For decompression operation, always use the compression PAT index.
@@ -1331,6 +1368,12 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
xe_device_has_flat_ccs(xe) &&
GRAPHICS_VER(xe) >= 20 && src_is_vram && !dst_is_vram);
+ /*
+ * The defrag CCS pass migrates the aux state from the old pages
+ * (@src_sg) to the new pages with both sides accessed indirectly, so
+ * keep both src_is_pltt and dst_is_pltt set (no direct staging side).
+ */
+
/* Copying CCS between two different BOs is not supported yet. */
if (XE_WARN_ON(copy_ccs && src_bo != dst_bo))
return ERR_PTR(-EINVAL);
@@ -1339,7 +1382,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
return ERR_PTR(-EINVAL);
if (!src_is_vram && src->mem_type != XE_PL_STOLEN)
- xe_res_first_sg(xe_bo_sg(src_bo), 0, size, &src_it);
+ xe_res_first_sg(src_sg ? src_sg : xe_bo_sg(src_bo), 0, size, &src_it);
else
xe_res_first(src, 0, size, &src_it);
if (!dst_is_vram && dst->mem_type != XE_PL_STOLEN)
@@ -1348,7 +1391,8 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
xe_res_first(dst, 0, size, &dst_it);
if (copy_system_ccs)
- xe_res_first_sg(xe_bo_sg(src_bo), xe_bo_ccs_pages_start(src_bo),
+ xe_res_first_sg(src_sg ? src_sg : xe_bo_sg(src_bo),
+ xe_bo_ccs_pages_start(src_bo),
PAGE_ALIGN(xe_device_ccs_bytes(xe, size)),
&ccs_it);
@@ -1399,7 +1443,8 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
}
/* Add copy commands size here */
- batch_size += ((copy_only_ccs) ? 0 : emit_copy_cmd_len(xe)) +
+ batch_size += ((copy_only_ccs || defrag_ccs) ? 0 :
+ emit_copy_cmd_len(xe)) +
((needs_ccs_emit ? EMIT_COPY_CCS_DW : 0));
bb = __xe_bb_new(gt, batch_size, usm, !fence && intr);
@@ -1411,13 +1456,15 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
if (src_is_vram && xe_migrate_allow_identity(src_L0, &src_it))
xe_res_next(&src_it, src_L0);
else
- emit_pte(m, bb, src_L0_pt, src_is_vram, copy_system_ccs || use_comp_pat,
+ emit_pte(m, bb, src_L0_pt, src_is_vram,
+ copy_system_ccs || use_comp_pat || defrag_ccs,
&src_it, src_L0, src);
if (dst_is_vram && xe_migrate_allow_identity(src_L0, &dst_it))
xe_res_next(&dst_it, src_L0);
else if (!copy_only_ccs)
- emit_pte(m, bb, dst_L0_pt, dst_is_vram, copy_system_ccs,
+ emit_pte(m, bb, dst_L0_pt, dst_is_vram,
+ copy_system_ccs || defrag_ccs,
&dst_it, src_L0, dst);
if (copy_system_ccs)
@@ -1426,7 +1473,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
bb->cs[bb->len++] = MI_BATCH_BUFFER_END;
update_idx = bb->len;
- if (!copy_only_ccs)
+ if (!copy_only_ccs && !defrag_ccs)
emit_copy(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, XE_PAGE_SIZE);
if (needs_ccs_emit)
@@ -1513,7 +1560,66 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
bool copy_only_ccs,
bool intr)
{
- return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, copy_only_ccs, false, intr);
+ return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, NULL,
+ copy_only_ccs ? XE_MIGRATE_COPY_CCS_ONLY :
+ XE_MIGRATE_COPY_NORMAL, intr);
+}
+
+/**
+ * xe_migrate_copy_defrag() - Migrate a BO's backing to a reallocated page set.
+ * @m: The migration context.
+ * @bo: The buffer object being defragmented. Both @src and @dst belong to @bo.
+ * @src: The source TTM resource (the old backing).
+ * @dst: The dst TTM resource (the freshly reallocated backing).
+ * @src_sg: Scatter-gather table of the source (old) backing pages.
+ * @need_ccs: Whether the BO has CCS aux state that must be migrated too.
+ *
+ * Used by the defrag path where a single BO has its backing reallocated at a
+ * more beneficial page order. The contents are relocated from the old pages
+ * (@src_sg) to the new pages (the BO's current backing) entirely on the GPU,
+ * in up to two passes:
+ *
+ * - Data pass (always): copy the data pages verbatim. The pages are mapped
+ * without the compression PAT, so the (possibly compressed) bytes are copied
+ * as-is rather than being decompressed and recompressed, and no CCS aux copy
+ * is appended.
+ *
+ * - CCS pass (@need_ccs): copy the CCS aux (compression) state. Both the old
+ * and new data pages are mapped with the compression PAT so the copy engine
+ * accesses the aux state indirectly, issuing one indirect -> indirect
+ * XY_CTRL_SURF_COPY_BLT; the data blit is skipped.
+ *
+ * The two passes are issued separately because they require opposite
+ * compression PAT settings on the data page mappings (cleared for the verbatim
+ * data copy, set for the indirect CCS access), which a single mapping cannot
+ * satisfy. Both passes run in order on the same migrate queue.
+ *
+ * Always run non-interruptible as defrag are issued from a work queue.
+ *
+ * Return: Pointer to a dma_fence representing the last copy batch, or an error
+ * pointer on failure.
+ */
+struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m,
+ struct xe_bo *bo,
+ struct ttm_resource *src,
+ struct ttm_resource *dst,
+ struct sg_table *src_sg,
+ bool need_ccs)
+{
+ struct dma_fence *fence2, *fence =
+ __xe_migrate_copy(m, bo, bo, src, dst, src_sg,
+ XE_MIGRATE_COPY_DEFRAG_DATA, false);
+
+ if (IS_ERR(fence) || !need_ccs)
+ return fence;
+
+ fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_sg,
+ XE_MIGRATE_COPY_DEFRAG_CCS, false);
+ if (IS_ERR(fence2))
+ dma_fence_wait(fence, false);
+ dma_fence_put(fence);
+
+ return fence2;
}
/**
@@ -1522,7 +1628,7 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
* @bo: The buffer object to resolve
* @res: The reservation object
*
- * Wrapper around __xe_migrate_copy() with is_vram_resolve set to true
+ * Wrapper around __xe_migrate_copy() with XE_MIGRATE_COPY_VRAM_RESOLVE
* to trigger decompression if needed.
*
* Return: A dma_fence that signals on completion, or an ERR_PTR on failure.
@@ -1531,7 +1637,8 @@ struct dma_fence *xe_migrate_resolve(struct xe_migrate *m,
struct xe_bo *bo,
struct ttm_resource *res)
{
- return __xe_migrate_copy(m, bo, bo, res, res, false, true, true);
+ return __xe_migrate_copy(m, bo, bo, res, res, NULL,
+ XE_MIGRATE_COPY_VRAM_RESOLVE, true);
}
/**
diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h
index 0bf94f5b388d..70451392e0a7 100644
--- a/drivers/gpu/drm/xe/xe_migrate.h
+++ b/drivers/gpu/drm/xe/xe_migrate.h
@@ -11,6 +11,7 @@
struct dma_fence;
struct drm_pagemap_addr;
struct iosys_map;
+struct sg_table;
struct ttm_resource;
struct xe_bo;
@@ -59,6 +60,13 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
bool copy_only_ccs,
bool intr);
+struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m,
+ struct xe_bo *bo,
+ struct ttm_resource *src,
+ struct ttm_resource *dst,
+ struct sg_table *src_sg,
+ bool need_ccs);
+
struct dma_fence *xe_migrate_resolve(struct xe_migrate *m,
struct xe_bo *bo,
struct ttm_resource *res);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move()
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
` (14 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:55 ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 17/36] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
` (22 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Teach xe_bo_move() to service a defrag move, where TTM reallocates a
BO's backing at the device's beneficial order and hands the old, still
populated tt to the move via the BO's defrag_old_tt.
A defrag move always has existing contents to copy, so force
move_lacks_source false and fall through the XE_PL_TT -> XE_PL_TT no-op
shortcut so the copy path runs. The relocation is performed entirely on
the GPU via xe_migrate_copy_defrag(), reading the old pages from the
stashed tt's sg table and writing the freshly reallocated backing.
Both copy passes run in order on the same migrate queue and are captured
by the returned fence, so the teardown is pipelined via
ttm_bo_move_accel_cleanup(): the old tt is handed to a ghost object and
only unpopulated and freed once the fence signals, so the move need not
block.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 98c0b32e9543..4c735ec8754e 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1291,6 +1291,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
bool move_lacks_source;
bool tt_has_data;
bool needs_clear;
+ bool has_defrag_old_tt = !!ttm_bo->defrag_old_tt;
bool handle_system_ccs = (!IS_DGFX(xe) && xe_bo_needs_ccs_pages(bo) &&
ttm && ttm_tt_is_populated(ttm)) ? true : false;
int ret = 0;
@@ -1331,6 +1332,13 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
move_lacks_source = !old_mem || (handle_system_ccs ? (!bo->ccs_cleared) :
(!mem_type_is_vram(old_mem_type) && !tt_has_data));
+ /*
+ * A defrag move always copies the existing contents from the stashed
+ * old tt into the freshly (re)allocated backing.
+ */
+ if (has_defrag_old_tt)
+ move_lacks_source = false;
+
needs_clear = (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) ||
(!ttm && ttm_bo->type == ttm_bo_type_device);
@@ -1374,9 +1382,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
/*
* Failed multi-hop where the old_mem is still marked as
* TTM_PL_FLAG_TEMPORARY, should just be a dummy move.
+ *
+ * For a defrag move the old and new tt differ, so fallthrough to the
+ * copy path instead of treating it as a no-op.
*/
if (old_mem_type == XE_PL_TT &&
- new_mem->mem_type == XE_PL_TT) {
+ new_mem->mem_type == XE_PL_TT && !has_defrag_old_tt) {
ttm_bo_move_null(ttm_bo, new_mem);
goto out;
}
@@ -1463,6 +1474,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
fence = xe_migrate_clear(migrate, bo, new_mem, flags,
ctx->interruptible);
+ } else if (has_defrag_old_tt) {
+ struct xe_ttm_tt *old_xe_tt =
+ container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm);
+
+ fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem,
+ old_xe_tt->sg, handle_system_ccs);
} else {
fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem,
handle_system_ccs, ctx->interruptible);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 17/36] drm/xe: Skip self-copies for borrowed pages on defrag moves
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
` (15 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:52 ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 18/36] drm/xe: Add a page defragmentation worker Matthew Brost
` (21 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
A defrag move may harvest already beneficial-order chunks from the old
tt, so the freshly reallocated backing borrows (references) some of the
same physical pages. For those pages the source and destination GPU
mappings alias the same memory, making the data blit a pointless
self-copy.
Pass the source (old) tt into __xe_migrate_copy() instead of just its sg
table, so the data pass can compare the src and dst tt page arrays at the
matching offset and only blit runs of pages that actually differ. A new
emit_copy_chunks() helper walks each L0 chunk, skips borrowed-page runs,
and coalesces contiguous to-copy pages into a single emit_copy(). It runs
twice per chunk: once with a NULL batch buffer to count the blits for
batch sizing, then again to emit them.
When an entire L0 chunk turns out to be borrowed, skip it outright: no
batch buffer is allocated and no GPU commands are issued, the cursors are
just advanced past the chunk. If every chunk of the move is borrowed the
copy is a complete no-op, so hand back a signaled stub fence.
The comparison is a cheap per-page pointer test (src page != dst page)
that coalesces contiguous to-copy pages into a single blit. PTEs are
still emitted for partially borrowed chunks, since that setup is cheap and
only the data copies are worth skipping. Only the defrag data pass is
affected; the separate CCS pass still migrates all aux state.
Since the Xe tt sg lives in the xe_ttm_tt subclass rather than the base
ttm_tt, add an xe_tt_sg() helper to fetch it from a struct ttm_tt.
v3:
- Fix start_page page-shift and blit pitch for src-natural to
dst-packed copies (Sashiko)
v4:
- Drop L0 naming (Niranjana)
- Assert src_tt/dst_tt (Niranjana)
v5:
- Assert a copy always occurs (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 22 ++++-
drivers/gpu/drm/xe/xe_bo.h | 2 +
drivers/gpu/drm/xe/xe_migrate.c | 147 +++++++++++++++++++++++++++-----
drivers/gpu/drm/xe/xe_migrate.h | 3 +-
4 files changed, 149 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 4c735ec8754e..85fb888d5db4 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -496,6 +496,22 @@ struct sg_table *xe_bo_sg(struct xe_bo *bo)
return xe_tt->sg;
}
+/**
+ * xe_tt_sg() - Return the DMA scatter-gather table backing a ttm_tt.
+ * @tt: The ttm_tt to query.
+ *
+ * Like xe_bo_sg(), but takes the ttm_tt directly. Used by the defrag copy
+ * path which needs the old (source) tt's sg table without a backing xe_bo.
+ *
+ * Return: The sg table, or NULL if the tt is not currently mapped.
+ */
+struct sg_table *xe_tt_sg(struct ttm_tt *tt)
+{
+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
+
+ return xe_tt->sg;
+}
+
/*
* Account ttm pages against the device shrinker's shrinkable and
* purgeable counts.
@@ -1475,11 +1491,9 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
fence = xe_migrate_clear(migrate, bo, new_mem, flags,
ctx->interruptible);
} else if (has_defrag_old_tt) {
- struct xe_ttm_tt *old_xe_tt =
- container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm);
-
fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem,
- old_xe_tt->sg, handle_system_ccs);
+ ttm_bo->defrag_old_tt,
+ handle_system_ccs);
} else {
fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem,
handle_system_ccs, ctx->interruptible);
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 4ec3a2dbaf68..f6b8b71228c6 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -114,6 +114,7 @@ enum xe_madv_purgeable_state {
struct drm_printer;
struct sg_table;
+struct ttm_tt;
struct xe_bo *xe_bo_alloc(void);
void xe_bo_free(struct xe_bo *bo);
@@ -565,6 +566,7 @@ void xe_bo_dev_init(struct xe_bo_dev *bo_device);
void xe_bo_dev_fini(struct xe_bo_dev *bo_device);
struct sg_table *xe_bo_sg(struct xe_bo *bo);
+struct sg_table *xe_tt_sg(struct ttm_tt *tt);
/**
* xe_bo_sg_is_contiguous() - Check if a BO's DMA address space is contiguous.
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 71192fbd722d..5b40405aaba9 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -1228,6 +1228,63 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb,
emit_xy_fast_copy(gt, bb, src_ofs, dst_ofs, size, pitch);
}
+/*
+ * emit_copy_chunks() - Emit the data blits for one defrag chunk, skipping
+ * borrowed pages.
+ * @gt: The GT.
+ * @bb: The batch buffer to emit into, or NULL to only count the blits needed.
+ * @src_ofs: GPU offset of the source pages mapped for this chunk.
+ * @dst_ofs: GPU offset of the destination pages mapped for this chunk.
+ * @src_bytes: Byte size of the 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 chunk within the tt page arrays.
+ *
+ * A defragmentation move may harvest already beneficial-order chunks from the
+ * old tt, so the new tt references (borrows) some of the same physical pages.
+ * For those pages the source and destination GPU mappings alias the same
+ * memory and the data blit is a pointless self-copy. Walk the chunk and
+ * only blit runs of pages that actually differ (src page != dst page),
+ * coalescing contiguous to-copy pages into a single blit.
+ *
+ * Return: The number of blits emitted (or that would be emitted when @bb is
+ * NULL).
+ */
+static u32 emit_copy_chunks(struct xe_gt *gt, struct xe_bb *bb,
+ u64 src_ofs, u64 dst_ofs, u32 src_bytes,
+ struct ttm_tt *src_tt, struct ttm_tt *dst_tt,
+ pgoff_t start_page)
+{
+ u32 npages = src_bytes >> PAGE_SHIFT;
+ u32 i = 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 that actually need copying. */
+ while (i + run < npages &&
+ src_tt->pages[start_page + i + run] !=
+ dst_tt->pages[start_page + i + run])
+ run++;
+
+ if (bb)
+ emit_copy(gt, bb, src_ofs + (u64)i * PAGE_SIZE,
+ dst_ofs + (u64)i * PAGE_SIZE,
+ run * PAGE_SIZE, XE_PAGE_SIZE);
+ nblits++;
+ i += run;
+ }
+
+ return nblits;
+}
+
static u64 xe_migrate_batch_base(struct xe_migrate *m, bool usm)
{
return usm ? m->usm_batch_base_ofs : m->batch_base_ofs;
@@ -1301,14 +1358,15 @@ static bool is_devmem(struct xe_bo *bo, struct ttm_resource *res)
* @XE_MIGRATE_COPY_VRAM_RESOLVE: Decompression (VRAM -> system) resolve;
* always uses the compression PAT index for the data copy.
* @XE_MIGRATE_COPY_DEFRAG_DATA: Defrag move pass that copies the data pages
- * between two distinct page sets (old @src_sg pages -> new pages) without
- * touching the CCS aux state. The data pages are mapped without the
- * compression PAT so the (possibly compressed) bytes are copied verbatim
- * rather than being decompressed and recompressed, and no CCS aux copy is
- * appended; the aux state is migrated separately by the
- * @XE_MIGRATE_COPY_DEFRAG_CCS pass.
+ * between two distinct page sets (old @src_tt pages -> new pages) without
+ * touching the CCS aux state. Pages the new tt borrowed from @src_tt
+ * (harvested already beneficial-order chunks) alias the same memory on both
+ * sides and are skipped. The data pages are mapped without the compression PAT
+ * so the (possibly compressed) bytes are copied verbatim rather than being
+ * decompressed and recompressed, and no CCS aux copy is appended; the aux
+ * state is migrated separately by the @XE_MIGRATE_COPY_DEFRAG_CCS pass.
* @XE_MIGRATE_COPY_DEFRAG_CCS: Defrag move pass that migrates only the CCS aux
- * state between two distinct page sets (old @src_sg pages -> new pages). The
+ * state between two distinct page sets (old @src_tt pages -> new pages). The
* data blit is skipped (the data was copied by the
* @XE_MIGRATE_COPY_DEFRAG_DATA pass) and both the source and destination data
* pages are mapped with the compression PAT so the aux state is copied
@@ -1328,7 +1386,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
struct xe_bo *dst_bo,
struct ttm_resource *src,
struct ttm_resource *dst,
- struct sg_table *src_sg,
+ struct ttm_tt *src_tt,
enum xe_migrate_copy_mode mode,
bool intr)
{
@@ -1358,6 +1416,14 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
!defrag_copy;
bool copy_system_ccs = copy_ccs && (!src_is_vram || !dst_is_vram) &&
!defrag_ccs && !defrag_copy;
+ /*
+ * On the defrag data pass the new (destination) tt may have borrowed
+ * already beneficial-order pages from the old (source) tt, so skip the
+ * self-copy for any page they share. Compare the tt page arrays at the
+ * matching offset.
+ */
+ struct ttm_tt *dst_tt = dst_bo->ttm.ttm;
+ bool skip_borrowed = defrag_copy;
/*
* For decompression operation, always use the compression PAT index.
@@ -1370,10 +1436,13 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
/*
* The defrag CCS pass migrates the aux state from the old pages
- * (@src_sg) to the new pages with both sides accessed indirectly, so
+ * (@src_tt) to the new pages with both sides accessed indirectly, so
* keep both src_is_pltt and dst_is_pltt set (no direct staging side).
*/
+ /* Defrag passes compare the old (@src_tt) and new tt page arrays. */
+ xe_assert(xe, !(defrag_copy || defrag_ccs) || (src_tt && dst_tt));
+
/* Copying CCS between two different BOs is not supported yet. */
if (XE_WARN_ON(copy_ccs && src_bo != dst_bo))
return ERR_PTR(-EINVAL);
@@ -1382,7 +1451,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
return ERR_PTR(-EINVAL);
if (!src_is_vram && src->mem_type != XE_PL_STOLEN)
- xe_res_first_sg(src_sg ? src_sg : xe_bo_sg(src_bo), 0, size, &src_it);
+ xe_res_first_sg(src_tt ? xe_tt_sg(src_tt) : xe_bo_sg(src_bo), 0, size, &src_it);
else
xe_res_first(src, 0, size, &src_it);
if (!dst_is_vram && dst->mem_type != XE_PL_STOLEN)
@@ -1391,7 +1460,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
xe_res_first(dst, 0, size, &dst_it);
if (copy_system_ccs)
- xe_res_first_sg(src_sg ? src_sg : xe_bo_sg(src_bo),
+ xe_res_first_sg(src_tt ? xe_tt_sg(src_tt) : xe_bo_sg(src_bo),
xe_bo_ccs_pages_start(src_bo),
PAGE_ALIGN(xe_device_ccs_bytes(xe, size)),
&ccs_it);
@@ -1405,6 +1474,8 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
u64 ccs_ofs, ccs_size;
u32 ccs_pt;
u32 pte_flags;
+ pgoff_t start_page = (xe_bo_size(src_bo) - size) >> PAGE_SHIFT;
+ u32 ndata_blits = 1;
bool usm = xe->info.has_usm;
u32 avail_pts = max_mem_transfer_per_pass(xe) / LEVEL0_PAGE_TABLE_ENCODE_SIZE;
@@ -1442,9 +1513,30 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
xe_assert(xe, IS_ALIGNED(ccs_it.start, PAGE_SIZE));
}
- /* Add copy commands size here */
+ /*
+ * Add copy commands size here. On the defrag data pass the blit
+ * is split into one command per run of non-borrowed pages, so
+ * size for the number of runs actually needed.
+ */
+ if (skip_borrowed)
+ ndata_blits = emit_copy_chunks(gt, NULL, 0, 0, src_L0,
+ src_tt, dst_tt, start_page);
+
+ /*
+ * If every page in this chunk was borrowed there is nothing to
+ * copy: don't build a batch or issue any GPU commands, just
+ * advance the cursors past the chunk. The non-vram tt cursors
+ * would otherwise be advanced by emit_pte().
+ */
+ if (skip_borrowed && !ndata_blits) {
+ xe_res_next(&src_it, src_L0);
+ xe_res_next(&dst_it, src_L0);
+ size -= src_L0;
+ continue;
+ }
+
batch_size += ((copy_only_ccs || defrag_ccs) ? 0 :
- emit_copy_cmd_len(xe)) +
+ ndata_blits * emit_copy_cmd_len(xe)) +
((needs_ccs_emit ? EMIT_COPY_CCS_DW : 0));
bb = __xe_bb_new(gt, batch_size, usm, !fence && intr);
@@ -1473,7 +1565,10 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
bb->cs[bb->len++] = MI_BATCH_BUFFER_END;
update_idx = bb->len;
- if (!copy_only_ccs && !defrag_ccs)
+ if (skip_borrowed)
+ emit_copy_chunks(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0,
+ src_tt, dst_tt, start_page);
+ else if (!copy_only_ccs && !defrag_ccs)
emit_copy(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, XE_PAGE_SIZE);
if (needs_ccs_emit)
@@ -1529,6 +1624,15 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
return ERR_PTR(err);
}
+ /*
+ * A defrag move always (re)allocates at least one chunk (TTM fails a
+ * zero-progress defrag move), so at least one page differs and a job
+ * carrying the resv dependencies is always emitted. A signaled stub
+ * here would let the old tt be torn down under in-flight GPU work.
+ */
+ if (XE_WARN_ON(!fence))
+ return ERR_PTR(-EINVAL);
+
return fence;
}
@@ -1571,18 +1675,21 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
* @bo: The buffer object being defragmented. Both @src and @dst belong to @bo.
* @src: The source TTM resource (the old backing).
* @dst: The dst TTM resource (the freshly reallocated backing).
- * @src_sg: Scatter-gather table of the source (old) backing pages.
+ * @src_tt: The source (old) backing tt, providing both the scatter-gather
+ * table and page pointers of the old pages.
* @need_ccs: Whether the BO has CCS aux state that must be migrated too.
*
* Used by the defrag path where a single BO has its backing reallocated at a
* more beneficial page order. The contents are relocated from the old pages
- * (@src_sg) to the new pages (the BO's current backing) entirely on the GPU,
+ * (@src_tt) to the new pages (the BO's current backing) entirely on the GPU,
* in up to two passes:
*
* - Data pass (always): copy the data pages verbatim. The pages are mapped
* without the compression PAT, so the (possibly compressed) bytes are copied
* as-is rather than being decompressed and recompressed, and no CCS aux copy
- * is appended.
+ * is appended. Pages the new backing borrowed from @src_tt (harvested
+ * already beneficial-order chunks) alias the same memory on both sides and
+ * are skipped.
*
* - CCS pass (@need_ccs): copy the CCS aux (compression) state. Both the old
* and new data pages are mapped with the compression PAT so the copy engine
@@ -1603,17 +1710,17 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m,
struct xe_bo *bo,
struct ttm_resource *src,
struct ttm_resource *dst,
- struct sg_table *src_sg,
+ struct ttm_tt *src_tt,
bool need_ccs)
{
struct dma_fence *fence2, *fence =
- __xe_migrate_copy(m, bo, bo, src, dst, src_sg,
+ __xe_migrate_copy(m, bo, bo, src, dst, src_tt,
XE_MIGRATE_COPY_DEFRAG_DATA, false);
if (IS_ERR(fence) || !need_ccs)
return fence;
- fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_sg,
+ fence2 = __xe_migrate_copy(m, bo, bo, src, dst, src_tt,
XE_MIGRATE_COPY_DEFRAG_CCS, false);
if (IS_ERR(fence2))
dma_fence_wait(fence, false);
diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h
index 70451392e0a7..c410652641f5 100644
--- a/drivers/gpu/drm/xe/xe_migrate.h
+++ b/drivers/gpu/drm/xe/xe_migrate.h
@@ -13,6 +13,7 @@ struct drm_pagemap_addr;
struct iosys_map;
struct sg_table;
struct ttm_resource;
+struct ttm_tt;
struct xe_bo;
struct xe_gt;
@@ -64,7 +65,7 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m,
struct xe_bo *bo,
struct ttm_resource *src,
struct ttm_resource *dst,
- struct sg_table *src_sg,
+ struct ttm_tt *src_tt,
bool need_ccs);
struct dma_fence *xe_migrate_resolve(struct xe_migrate *m,
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 18/36] drm/xe: Add a page defragmentation worker
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
` (16 preceding siblings ...)
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:33 ` Matthew Brost
2026-12-03 0:12 ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 19/36] drm/xe: Add defrag GT stats Matthew Brost
` (20 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
BOs whose backing TT pages were allocated below the device's beneficial
order (tracked via the TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED tt page flag)
are added to a per-device defrag list. Add a delayed worker that
periodically walks this list and attempts to re-back each BO with
beneficial-order pages, improving TLB efficiency for long-lived objects
that were initially allocated under memory pressure.
The worker is kicked when the list first transitions to non-empty and
reschedules itself while work remains. On a failed pass it backs off
exponentially (XE_BO_DEFRAG_INTERVAL_MS up to
XE_BO_DEFRAG_INTERVAL_MAX_MS) and retries the whole list later; the
interval is reset to the default on the next fresh enqueue. The worker
stops scheduling once the list drains.
A defrag move synchronously reallocates and re-copies a BO's backing
store, which is not free. To avoid stalling concurrent active work when
many BOs (or one very large BO) become eligible at once (e.g. after a
burst of memory pressure, which would otherwise manifest as a large FPS
drop while the worker churns through the whole list), cap the number of
newly (re)allocated bytes processed per run to XE_BO_DEFRAG_SIZE_LIMIT
and reschedule. Only the pages a move actually reallocates are charged -
pages harvested (borrowed) from the old backing are free and do not count
- so the budget tracks real defrag work and an object larger than the
budget is upgraded in budget-sized slices across runs. This spreads the
defrag effort over time, keeping it in the background and yielding to
userspace progress.
Defragmenting a BO forces a TTM move (ctx.defrag) that reallocates the
backing at the beneficial order and relocates the contents on the GPU
(see xe_bo_move()). The per-BO move is bounded by the run's remaining
byte budget via ctx.defrag_bytes_remaining; the pool allocator reports
how much it spent so the worker can charge it accurately. When
beneficial-order pages cannot be obtained the new allocation is
discharged during populate and the BO keeps its original backing, staying
on the list for a later retry.
v4:
- Only enter reclaim from defrag worker
- Disable worker with early cleanup handler too (Sashiko)
v5:
- Fix suspend / resume by pausing defrag worker (Sashiko)
- Clear TTM_PL_FLAG_TEMPORARY after defrag (Sashiko)
- Use xe_pm_runtime_get_if_active in defrag worker (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 387 ++++++++++++++++++++++++++-
drivers/gpu/drm/xe/xe_bo.h | 6 +-
drivers/gpu/drm/xe/xe_device.c | 22 +-
drivers/gpu/drm/xe/xe_device_types.h | 17 ++
drivers/gpu/drm/xe/xe_pm.c | 12 +
5 files changed, 435 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 85fb888d5db4..5944077ba997 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -34,6 +34,7 @@
#include "xe_pat.h"
#include "xe_pm.h"
#include "xe_preempt_fence.h"
+#include "xe_printk.h"
#include "xe_pxp.h"
#include "xe_res_cursor.h"
#include "xe_shrinker.h"
@@ -45,6 +46,35 @@
#include "xe_vram_types.h"
#include "xe_wedge.h"
+/*
+ * Maximum number of bytes of newly (re)allocated backing the defrag worker will
+ * produce in a single run before yielding and rescheduling itself.
+ *
+ * A defrag move synchronously reallocates and re-copies a BO's backing store,
+ * which is not free. If a large number of BOs (or one very large BO) become
+ * eligible at once (e.g. after a burst of memory pressure), processing them all
+ * in one worker run would hold things up for a long, unbounded stretch and can
+ * visibly starve concurrent active work (e.g. a large FPS drop). Instead, cap
+ * the bytes actually upgraded per run and requeue, spreading the defrag effort
+ * out over time so it stays in the background and yields to userspace progress.
+ * Only pages a move truly reallocates are charged; pages harvested from the old
+ * backing are free, so an object larger than the budget is upgraded in
+ * budget-sized slices across runs.
+ */
+#define XE_BO_DEFRAG_SIZE_LIMIT SZ_32M
+
+/* Default delay before (re)running the defrag worker, in milliseconds. */
+#define XE_BO_DEFRAG_INTERVAL_MS 25
+
+/*
+ * Upper bound for the (exponentially backed off) defrag worker interval, in
+ * milliseconds, so repeated failures don't push the retry arbitrarily far out.
+ */
+#define XE_BO_DEFRAG_INTERVAL_MAX_MS 15000 /* 15 seconds */
+
+static void xe_bo_defrag_worker(struct work_struct *w);
+static void xe_place_from_ttm_type(u32 mem_type, struct ttm_place *place);
+
const char *const xe_mem_type_to_name[TTM_NUM_MEM_TYPES] = {
[XE_PL_SYSTEM] = "system",
[XE_PL_TT] = "gtt",
@@ -727,9 +757,12 @@ static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object *ttm_bo,
return tt;
}
+static bool xe_bo_defrag_supported(struct xe_device *xe);
+
static int xe_ttm_tt_populate(struct ttm_device *ttm_dev, struct ttm_tt *tt,
struct ttm_operation_ctx *ctx)
{
+ struct xe_device *xe = ttm_to_xe_device(ttm_dev);
struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
int err;
@@ -741,6 +774,10 @@ static int xe_ttm_tt_populate(struct ttm_device *ttm_dev, struct ttm_tt *tt,
!(tt->page_flags & TTM_TT_FLAG_EXTERNAL_MAPPABLE))
return 0;
+ /* Only defrag will enter reclaim at higher orders */
+ ctx->beneficial_reclaim_backoff = !ctx->defrag &&
+ xe_bo_defrag_supported(xe);
+
if (ttm_tt_is_backed_up(tt) && !xe_tt->purgeable) {
err = ttm_tt_restore(ttm_dev, tt, ctx);
} else {
@@ -1183,17 +1220,140 @@ int xe_ttm_bo_purge(struct ttm_buffer_object *ttm_bo, struct ttm_operation_ctx *
return 0;
}
+static void xe_bo_defrag_fini_early(void *arg)
+{
+ struct xe_device *xe = arg;
+
+ disable_delayed_work_sync(&xe->mem.defrag.worker);
+}
+
+static void xe_bo_defrag_fini(void *arg)
+{
+ struct xe_device *xe = arg;
+
+ disable_delayed_work_sync(&xe->mem.defrag.worker);
+}
+
/**
* xe_bo_defrag_init_early() - Initialize the device defrag BO tracking
* @xe: The xe device
*
- * Initialize the list and lock used to track BOs whose backing TT
- * pages were allocated at a sub-optimal order.
+ * Initialize the list, lock and delayed worker used to track and
+ * defragment BOs whose backing TT pages were allocated at a sub-optimal order.
+ *
+ * Return: 0 on success, negative error code on failure.
*/
-void xe_bo_defrag_init_early(struct xe_device *xe)
+int xe_bo_defrag_init_early(struct xe_device *xe)
{
spin_lock_init(&xe->mem.defrag.lock);
INIT_LIST_HEAD(&xe->mem.defrag.list);
+ xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ INIT_DELAYED_WORK(&xe->mem.defrag.worker, xe_bo_defrag_worker);
+
+ return devm_add_action_or_reset(xe->drm.dev, xe_bo_defrag_fini_early, xe);
+}
+
+/**
+ * xe_bo_defrag_init() - Register defrag worker teardown
+ * @xe: The xe device
+ *
+ * Register the devm action that disables and drains the defrag worker on
+ * device teardown. This must be called after xe_migrate_init() so that, with
+ * devm's reverse-order cleanup, the worker is stopped before the migrate
+ * contexts it relies on (via xe_bo_defrag_one() -> ttm_bo_validate() ->
+ * xe_bo_move() -> xe_migrate_copy_defrag()) are torn down.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int xe_bo_defrag_init(struct xe_device *xe)
+{
+ return devm_add_action_or_reset(xe->drm.dev, xe_bo_defrag_fini, xe);
+}
+
+/*
+ * Queue the defrag worker at the current interval. Called under
+ * @mem.defrag.lock so it cannot race xe_bo_defrag_suspend() setting
+ * @mem.defrag.suspended and cancelling the worker. A @kick (list became
+ * non-empty or the device resumed) uses mod_delayed_work() so that it pulls in
+ * a pending, backed-off timer rather than leaving it in place.
+ */
+static void xe_bo_defrag_schedule_locked(struct xe_device *xe, bool kick)
+{
+ unsigned long delay;
+
+ lockdep_assert_held(&xe->mem.defrag.lock);
+
+ if (xe->mem.defrag.suspended)
+ return;
+
+ delay = msecs_to_jiffies(xe->mem.defrag.interval_ms);
+ if (kick)
+ mod_delayed_work(system_percpu_wq, &xe->mem.defrag.worker,
+ delay);
+ else
+ queue_delayed_work(system_percpu_wq, &xe->mem.defrag.worker,
+ delay);
+}
+
+static void xe_bo_defrag_kick_locked(struct xe_device *xe)
+{
+ lockdep_assert_held(&xe->mem.defrag.lock);
+
+ if (list_empty(&xe->mem.defrag.list))
+ return;
+
+ xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ xe_bo_defrag_schedule_locked(xe, true);
+}
+
+/**
+ * xe_bo_defrag_suspend() - Stop the defragmentation worker for suspend / FLR
+ * @xe: xe device instance
+ *
+ * Block the defrag worker from being queued and wait for any running instance
+ * to finish, so no defrag move (and its GPU copy) can run while the device is
+ * being suspended or reset. Idempotent; undone by xe_bo_defrag_resume().
+ */
+void xe_bo_defrag_suspend(struct xe_device *xe)
+{
+ scoped_guard(spinlock, &xe->mem.defrag.lock)
+ xe->mem.defrag.suspended = true;
+
+ cancel_delayed_work_sync(&xe->mem.defrag.worker);
+}
+
+/**
+ * xe_bo_defrag_resume() - Re-enable the defragmentation worker
+ * @xe: xe device instance
+ *
+ * Undo xe_bo_defrag_suspend() after system resume or FLR (or an aborted
+ * suspend) and re-arm the worker if BOs are still pending. Idempotent.
+ */
+void xe_bo_defrag_resume(struct xe_device *xe)
+{
+ guard(spinlock)(&xe->mem.defrag.lock);
+
+ xe->mem.defrag.suspended = false;
+ xe_bo_defrag_kick_locked(xe);
+}
+
+/**
+ * xe_bo_defrag_kick() - Re-arm the defragmentation worker
+ * @xe: xe device instance
+ *
+ * The defrag worker bails without rescheduling when it cannot take a runtime
+ * PM reference (the device is runtime suspended/suspending). Call this when the
+ * device becomes runtime active again (runtime resume, or a failed runtime
+ * suspend) so the worker is re-armed if BOs are still pending, rather than
+ * polling a wakeup timer while suspended. A no-op if the tracking list is empty
+ * (the next xe_bo_defrag_add() will kick the worker) or while
+ * xe_bo_defrag_suspend() is in effect.
+ */
+void xe_bo_defrag_kick(struct xe_device *xe)
+{
+ guard(spinlock)(&xe->mem.defrag.lock);
+
+ xe_bo_defrag_kick_locked(xe);
}
/*
@@ -1243,9 +1403,14 @@ static void xe_bo_defrag_add(struct xe_bo *bo)
if (!list_empty(&bo->defrag_link))
return;
- scoped_guard(spinlock, &xe->mem.defrag.lock) {
- if (list_empty(&bo->defrag_link))
- list_add_tail(&bo->defrag_link, &xe->mem.defrag.list);
+ guard(spinlock)(&xe->mem.defrag.lock);
+ if (list_empty(&bo->defrag_link)) {
+ /* Kick the worker when the list transitions to non-empty. */
+ bool kick = list_empty(&xe->mem.defrag.list);
+
+ list_add_tail(&bo->defrag_link, &xe->mem.defrag.list);
+ if (kick)
+ xe_bo_defrag_kick_locked(xe);
}
}
@@ -1292,6 +1457,216 @@ static void xe_bo_defrag_update(struct xe_bo *bo)
xe_bo_defrag_remove(bo);
}
+/*
+ * Attempt to defragment a single BO by forcing a move that reallocates its
+ * backing at the device's beneficial order. @budget bounds how many bytes of
+ * new pages the move may (re)allocate; the remainder of the object is completed
+ * by harvesting the old backing, and the BO stays flagged for a later pass. On
+ * return *@consumed holds the bytes actually (re)allocated (0 on failure or
+ * when nothing needed reallocating). *@needs_more is set to true when the move
+ * succeeded but the BO still has sub-beneficial backing (partial upgrade) and
+ * should be revisited; it is computed under the BO lock so the caller does not
+ * need to re-inspect bo->ttm.ttm after the lock is dropped. Returns 0 if the BO
+ * no longer needs to be tracked (either defragmented or no longer eligible), or
+ * a negative error code if the attempt should be retried later.
+ */
+static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
+ u64 budget, u64 *consumed, bool *needs_more)
+{
+ struct ttm_operation_ctx ctx = {
+ .gfp_retry_mayfail = true,
+ .defrag = true,
+ .defrag_bytes_remaining = budget,
+ };
+ struct ttm_buffer_object *ttm_bo = &bo->ttm;
+ struct ttm_placement placement;
+ struct ttm_place place;
+ int ret = 0;
+
+ *consumed = 0;
+ *needs_more = false;
+
+ xe_bo_lock(bo, false);
+
+ /* Re-check eligibility under the BO lock. */
+ if (!xe_bo_needs_defrag(bo)) {
+ xe_bo_defrag_remove(bo);
+ goto unlock;
+ }
+
+ xe_place_from_ttm_type(ttm_bo->resource->mem_type, &place);
+ place.flags |= TTM_PL_FLAG_TEMPORARY;
+ placement.num_placement = 1;
+ placement.placement = &place;
+
+ /*
+ * On success the move reallocates the backing at beneficial order and
+ * drops the BO from the defrag list. On failure the BO keeps its
+ * original backing and stays on the list for a later retry.
+ */
+ ret = ttm_bo_validate(ttm_bo, &placement, &ctx);
+
+ /*
+ * TTM_PL_FLAG_TEMPORARY only lets the new XE_PL_TT resource bypass the
+ * sys manager's size check while the old and new resources are
+ * transiently both charged. ttm_resource_init() copied it into the new
+ * resource's placement, where it would make ttm_resource_compatible()
+ * reject the resource on the next validate and force a needless move.
+ */
+ if (!ret)
+ ttm_bo->resource->placement &= ~TTM_PL_FLAG_TEMPORARY;
+
+ /*
+ * The pool allocator decremented defrag_bytes_remaining as it
+ * (re)allocated pages, so the unused budget tells us how much was spent.
+ * Only meaningful when the move succeeded, in which case TTM has
+ * (re)allocated at least one chunk.
+ */
+ if (!ret) {
+ s64 spent = (s64)budget - ctx.defrag_bytes_remaining;
+
+ *consumed = spent > 0 ? spent : 0;
+ }
+
+ xe_dbg(xe, "Defrag attempt on BO size=%zu: ret=%pe consumed=%llu\n",
+ xe_bo_size(bo), ERR_PTR(ret), *consumed);
+
+ if (!ret && ttm_tt_is_beneficial_order_failed(bo->ttm.ttm))
+ *needs_more = true;
+
+unlock:
+ xe_bo_unlock(bo);
+ return ret;
+}
+
+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)) {
+ /*
+ * The device is (runtime) suspending/suspended. Do not spin a
+ * wakeup timer here: the worker is re-armed via
+ * xe_bo_defrag_kick() once the device is runtime active again
+ * (runtime resume or a failed runtime suspend), so tracked BOs
+ * are picked up without polling while suspended.
+ */
+ drm_dev_exit(idx);
+ return;
+ }
+
+ /*
+ * Process at most XE_BO_DEFRAG_SIZE_LIMIT bytes of newly (re)allocated
+ * backing per run rather than draining the whole list in one go. Only
+ * the pages a move actually reallocates are charged - pages harvested
+ * (borrowed) from the old backing are free and do not count - so the
+ * budget tracks real defrag work. A single object larger than the
+ * budget is upgraded in slices across successive runs. Each defrag is
+ * synchronous and relatively expensive, so bounding the work per run
+ * keeps the worker from monopolising resources and lets concurrent
+ * active work make progress; any remaining work is handled by a
+ * follow-up run scheduled below.
+ */
+ while (defrag_bytes < XE_BO_DEFRAG_SIZE_LIMIT) {
+ struct xe_bo *first, *bo;
+ u64 consumed = 0;
+ bool needs_more = false;
+ int ret;
+
+ scoped_guard(spinlock, &xe->mem.defrag.lock) {
+ bool again;
+
+ /* Progress, reset interval */
+ if (defrag_bytes)
+ xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+
+ do {
+ first = list_first_entry_or_null(&xe->mem.defrag.list,
+ struct xe_bo,
+ defrag_link);
+ bo = first ? xe_bo_get_unless_zero(first) : NULL;
+ again = first && !bo;
+ if (again)
+ list_del_init(&first->defrag_link);
+ } while (again);
+ }
+
+ if (!bo)
+ break;
+
+ /*
+ * 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) {
+ scoped_guard(spinlock, &xe->mem.defrag.lock) {
+ if (ret)
+ /*
+ * Abort the pass and retry the whole
+ * list later, backing off exponentially
+ * on every failure.
+ */
+ xe->mem.defrag.interval_ms =
+ min(xe->mem.defrag.interval_ms * 2,
+ (unsigned int)XE_BO_DEFRAG_INTERVAL_MAX_MS);
+ else
+ /* Progress, reset interval */
+ xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ }
+
+ xe_bo_put(bo);
+ requeue = true;
+ break;
+ }
+
+ xe_bo_put(bo);
+ }
+
+ /*
+ * Decide whether to reschedule:
+ *
+ * - The loop hit its per-run limit (defrag_bytes >=
+ * XE_BO_DEFRAG_SIZE_LIMIT): we stopped early to spread the work out,
+ * so requeue at the default interval (reset here since this run made
+ * progress) whenever the list still has entries.
+ *
+ * - The loop aborted on a failed defrag (requeue): retry later at the
+ * backed-off interval computed above.
+ *
+ * - The loop drained the list (broke on the empty list): nothing left to
+ * do, so stop scheduling. A fresh enqueue will kick the worker again.
+ */
+ if (defrag_bytes >= XE_BO_DEFRAG_SIZE_LIMIT) {
+ guard(spinlock)(&xe->mem.defrag.lock);
+
+ xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ if (!list_empty(&xe->mem.defrag.list))
+ xe_bo_defrag_schedule_locked(xe, false);
+ } else if (requeue) {
+ guard(spinlock)(&xe->mem.defrag.lock);
+
+ xe_bo_defrag_schedule_locked(xe, false);
+ }
+
+ xe_pm_runtime_put(xe);
+ drm_dev_exit(idx);
+}
+
static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
struct ttm_operation_ctx *ctx,
struct ttm_resource *new_mem,
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index f6b8b71228c6..ff99bed7089b 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -232,7 +232,11 @@ void xe_bo_unpin_external(struct xe_bo *bo);
void xe_bo_unpin(struct xe_bo *bo);
void xe_bo_pin_account(struct xe_bo *bo);
void xe_bo_unpin_account(struct xe_bo *bo);
-void xe_bo_defrag_init_early(struct xe_device *xe);
+int xe_bo_defrag_init_early(struct xe_device *xe);
+int xe_bo_defrag_init(struct xe_device *xe);
+void xe_bo_defrag_suspend(struct xe_device *xe);
+void xe_bo_defrag_resume(struct xe_device *xe);
+void xe_bo_defrag_kick(struct xe_device *xe);
int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict,
struct drm_exec *exec);
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 67d648833030..637f9e71e78b 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -549,7 +549,9 @@ int xe_device_init_early(struct xe_device *xe)
if (err)
return err;
- xe_bo_defrag_init_early(xe);
+ err = xe_bo_defrag_init_early(xe);
+ if (err)
+ return err;
xe->preempt_fence_wq = alloc_ordered_workqueue("xe-preempt-fence-wq",
WQ_MEM_RECLAIM);
@@ -1062,6 +1064,15 @@ int xe_device_probe(struct xe_device *xe)
if (err)
return err;
+ /*
+ * Register the defrag worker teardown now that the migrate contexts it
+ * depends on are initialized, so devm's reverse-order cleanup stops the
+ * worker before those contexts are torn down.
+ */
+ err = xe_bo_defrag_init(xe);
+ if (err)
+ return err;
+
err = xe_pagefault_init(xe);
if (err)
return err;
@@ -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);
if (err)
- return err;
+ goto err_defrag;
xe_late_bind_pm_suspend(&xe->late_bind);
@@ -1489,6 +1503,8 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr)
err_display:
xe_display_pm_resume(xe);
xe_pxp_pm_resume(xe->pxp);
+err_defrag:
+ xe_bo_defrag_resume(xe);
return err;
}
@@ -1582,5 +1598,7 @@ int xe_device_resume(struct xe_device *xe, bool flr)
xe_late_bind_pm_resume(&xe->late_bind);
+ xe_bo_defrag_resume(xe);
+
return 0;
}
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index 0d09cb5bd2d5..f64f19c85c71 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -337,6 +337,23 @@ struct xe_device {
spinlock_t lock;
/** @mem.defrag.list: List of struct xe_bo defrag_link. */
struct list_head list;
+ /**
+ * @mem.defrag.worker: Delayed worker that walks
+ * @mem.defrag.list trying to reallocate BO backing
+ * store at the device's beneficial order.
+ */
+ struct delayed_work worker;
+ /**
+ * @mem.defrag.interval_ms: Reschedule interval for
+ * @mem.defrag.worker, in milliseconds.
+ */
+ unsigned int interval_ms;
+ /**
+ * @mem.defrag.suspended: The device is suspending,
+ * suspended or undergoing FLR; @mem.defrag.worker must
+ * not be queued. Protected by @mem.defrag.lock.
+ */
+ bool suspended;
} defrag;
} mem;
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index f73f68bd449b..a0c2ec7aa468 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -387,6 +387,8 @@ static int xe_pm_notifier_callback(struct notifier_block *nb,
struct xe_validation_ctx ctx;
reinit_completion(&xe->pm_block);
+ /* Don't defrag BOs we are about to evict or tear down under. */
+ xe_bo_defrag_suspend(xe);
if (!xe_pm_needs_bo_evict(xe, action == PM_HIBERNATION_PREPARE))
break;
@@ -414,6 +416,8 @@ static int xe_pm_notifier_callback(struct notifier_block *nb,
case PM_POST_SUSPEND:
complete_all(&xe->pm_block);
xe_pm_wake_rebind_workers(xe);
+ /* Also covers a suspend aborted after PM_*_PREPARE. */
+ xe_bo_defrag_resume(xe);
if (!xe_pm_needs_bo_evict(xe, action == PM_POST_HIBERNATION))
break;
@@ -606,6 +610,12 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
xe_display_pm_runtime_resume(xe);
xe_pxp_pm_resume(xe->pxp);
out:
+ /*
+ * The runtime PM core puts the device back to active without calling
+ * xe_pm_runtime_resume(), so re-arm a defrag worker that bailed while
+ * we were suspending.
+ */
+ xe_bo_defrag_kick(xe);
xe_rpm_lockmap_release(xe);
xe_pm_write_callback_task(xe, NULL);
return err;
@@ -689,6 +699,8 @@ int xe_pm_runtime_resume(struct xe_device *xe)
if (xe->d3cold.allowed)
xe_late_bind_pm_resume(&xe->late_bind);
+ xe_bo_defrag_kick(xe);
+
out:
xe_rpm_lockmap_release(xe);
xe_pm_write_callback_task(xe, NULL);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 19/36] drm/xe: Add defrag GT stats
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
` (17 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 18/36] drm/xe: Add a page defragmentation worker Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 20/36] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
` (19 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Add observability for the page defragmentation worker.
Introduce four primary-GT statistics counters: defrag_added_count
(BOs queued onto the defrag list after being backed at a sub-optimal
page order), defrag_success_count (BOs fully re-backed at the beneficial
order), defrag_partial_success_count (BOs only partially re-backed at the
beneficial order) defrag_failed_count (attempts that failed and left the
BO on its original backing) and defrag_mb_moved. The
ineligible/already-removed fast path is intentionally not counted as
either success or failure.
v5:
- Mention counter only valid on root GT in kernel doc (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 18 +++++++++++++++++-
drivers/gpu/drm/xe/xe_gt_stats.c | 5 +++++
drivers/gpu/drm/xe/xe_gt_stats_types.h | 21 +++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 5944077ba997..b3f1a40c4425 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -28,6 +28,7 @@
#include "xe_dma_buf.h"
#include "xe_drm_client.h"
#include "xe_ggtt.h"
+#include "xe_gt_stats.h"
#include "xe_map.h"
#include "xe_migrate.h"
#include "xe_mmio_gem.h"
@@ -1409,6 +1410,8 @@ static void xe_bo_defrag_add(struct xe_bo *bo)
bool kick = list_empty(&xe->mem.defrag.list);
list_add_tail(&bo->defrag_link, &xe->mem.defrag.list);
+ xe_gt_stats_incr(xe_root_mmio_gt(xe),
+ XE_GT_STATS_ID_DEFRAG_ADDED_COUNT, 1);
if (kick)
xe_bo_defrag_kick_locked(xe);
}
@@ -1531,8 +1534,21 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
xe_dbg(xe, "Defrag attempt on BO size=%zu: ret=%pe consumed=%llu\n",
xe_bo_size(bo), ERR_PTR(ret), *consumed);
- if (!ret && ttm_tt_is_beneficial_order_failed(bo->ttm.ttm))
+ if (!ret && ttm_tt_is_beneficial_order_failed(bo->ttm.ttm)) {
*needs_more = true;
+ xe_gt_stats_incr(xe_root_mmio_gt(xe),
+ XE_GT_STATS_ID_DEFRAG_PARTIAL_SUCCESS_COUNT,
+ 1);
+ } else {
+ xe_gt_stats_incr(xe_root_mmio_gt(xe),
+ ret ? XE_GT_STATS_ID_DEFRAG_FAILED_COUNT :
+ XE_GT_STATS_ID_DEFRAG_SUCCESS_COUNT, 1);
+ }
+
+ if (!ret)
+ xe_gt_stats_incr(xe_root_mmio_gt(xe),
+ XE_GT_STATS_ID_DEFRAG_MB_MOVED,
+ *consumed >> 20);
unlock:
xe_bo_unlock(bo);
diff --git a/drivers/gpu/drm/xe/xe_gt_stats.c b/drivers/gpu/drm/xe/xe_gt_stats.c
index 2a40924660ee..5ab0a9fa09dc 100644
--- a/drivers/gpu/drm/xe/xe_gt_stats.c
+++ b/drivers/gpu/drm/xe/xe_gt_stats.c
@@ -161,6 +161,11 @@ static const char *const stat_description[__XE_GT_STATS_NUM_IDS] = {
DEF_STAT_STR(PRL_2M_ENTRY_COUNT, "prl_2m_entry_count"),
DEF_STAT_STR(PRL_ISSUED_COUNT, "prl_issued_count"),
DEF_STAT_STR(PRL_ABORTED_COUNT, "prl_aborted_count"),
+ DEF_STAT_STR(DEFRAG_ADDED_COUNT, "defrag_added_count"),
+ DEF_STAT_STR(DEFRAG_SUCCESS_COUNT, "defrag_success_count"),
+ DEF_STAT_STR(DEFRAG_PARTIAL_SUCCESS_COUNT, "defrag_partial_success_count"),
+ DEF_STAT_STR(DEFRAG_FAILED_COUNT, "defrag_failed_count"),
+ DEF_STAT_STR(DEFRAG_MB_MOVED, "defrag_mb_moved"),
};
/**
diff --git a/drivers/gpu/drm/xe/xe_gt_stats_types.h b/drivers/gpu/drm/xe/xe_gt_stats_types.h
index 24abeb9f2137..41b32c502c3f 100644
--- a/drivers/gpu/drm/xe/xe_gt_stats_types.h
+++ b/drivers/gpu/drm/xe/xe_gt_stats_types.h
@@ -137,6 +137,22 @@
* @XE_GT_STATS_ID_PRL_ABORTED_COUNT: Times the page reclaim process was
* aborted.
*
+ * @XE_GT_STATS_ID_DEFRAG_ADDED_COUNT: Times a buffer object was added to the
+ * page defragmentation list after being backed at a sub-optimal page order.
+ * Only valid on root GT.
+ * @XE_GT_STATS_ID_DEFRAG_SUCCESS_COUNT: Times the defrag worker successfully
+ * re-backed a buffer object at the beneficial page order. Only valid on root
+ * GT.
+ * @XE_GT_STATS_ID_DEFRAG_PARTIAL_SUCCESS_COUNT: Times the defrag worker
+ * partially re-backed a buffer object at the beneficial page order. Only
+ * valid on root GT.
+ * @XE_GT_STATS_ID_DEFRAG_FAILED_COUNT: Times the defrag worker failed to
+ * re-back a buffer object at the beneficial page order. Only valid on root
+ * GT.
+ * @XE_GT_STATS_ID_DEFRAG_MB_MOVED: Data (MiB) actually (re)allocated while
+ * re-backing buffer objects at the beneficial page order. Chunks borrowed
+ * from the old backing for free are not counted. Only valid on root GT.
+ *
* @__XE_GT_STATS_NUM_IDS: Number of valid IDs; not a real counter.
*
* See Documentation/gpu/xe/xe_gt_stats.rst.
@@ -203,6 +219,11 @@ enum xe_gt_stats_id {
XE_GT_STATS_ID_PRL_2M_ENTRY_COUNT,
XE_GT_STATS_ID_PRL_ISSUED_COUNT,
XE_GT_STATS_ID_PRL_ABORTED_COUNT,
+ XE_GT_STATS_ID_DEFRAG_ADDED_COUNT,
+ XE_GT_STATS_ID_DEFRAG_SUCCESS_COUNT,
+ XE_GT_STATS_ID_DEFRAG_PARTIAL_SUCCESS_COUNT,
+ XE_GT_STATS_ID_DEFRAG_FAILED_COUNT,
+ XE_GT_STATS_ID_DEFRAG_MB_MOVED,
/* must be the last entry */
__XE_GT_STATS_NUM_IDS,
};
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 20/36] drm/xe: Add Kconfig.profile options for BO defrag configuration
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
` (18 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 19/36] drm/xe: Add defrag GT stats Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
` (18 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Add Kconfig.profile options to make XE_BO_DEFRAG_* defines configurable:
- DRM_XE_BO_DEFRAG_SIZE_LIMIT: Maximum number of bytes to defrag per
work run
- DRM_XE_BO_DEFRAG_INTERVAL_MS: Default delay before defrag worker runs
- DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS: Upper bound for defrag worker
interval
Update xe_bo.c to use these Kconfig options as defaults via #ifdef
guards, maintaining backward compatibility with hardcoded values when
not configured.
Additionally, disable defrag completely when XE_BO_DEFRAG_SIZE_LIMIT is
set less than 2M by returning early from xe_bo_defrag_update() (and
xe_bo_defrag_remove()) so BOs are never added to the defrag list or the
worker kicked; xe_bo_defrag_add() and xe_bo_defrag_schedule() assert the
limit is at least 2M. A limit of 2M or more must be 2M aligned, which
is enforced with a BUILD_BUG_ON.
v4:
- Drop DRM_XE_BO_DEFRAG_RECLAIM_BACKOFF_THRESHOLD
- Add BUILD_BUG_ON for a bad Kconfig (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/Kconfig.profile | 31 ++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_bo.c | 30 ++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/Kconfig.profile b/drivers/gpu/drm/xe/Kconfig.profile
index dd3985e502b8..32bc358e6968 100644
--- a/drivers/gpu/drm/xe/Kconfig.profile
+++ b/drivers/gpu/drm/xe/Kconfig.profile
@@ -101,3 +101,34 @@ config DRM_XE_SHRINKER_MIN_AGE_MS
set kept younger than this is never backed up and can cause OOM.
Only set if that risk is preferred over thrashing a hot working
set. 0 disables.
+
+config DRM_XE_BO_DEFRAG_SIZE_LIMIT
+ int "Maximum bytes to defrag per work run"
+ default 33554432
+ range 0 1073741824
+ help
+ Maximum number of bytes the defrag worker will process in a single run
+ before yielding and rescheduling itself. Set to less than large page
+ size (2M) to disable defrag, otherwise it must be 2M aligned. A
+ defrag move synchronously reallocates and re-copies a BO's backing
+ store, which is not free. If a large
+ number of BOs become eligible at once, processing them all in one
+ worker run would hold things up for a long, unbounded stretch.
+ Instead, cap the work done per run and requeue, spreading the defrag
+ effort out over time.
+
+config DRM_XE_BO_DEFRAG_INTERVAL_MS
+ int "Default delay before defrag worker run (ms)"
+ default 25
+ range 1 1000
+ help
+ Default delay before (re)running the defrag worker, in milliseconds.
+
+config DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS
+ int "Upper bound for defrag worker interval (ms)"
+ default 15000
+ range 100 1000000
+ help
+ Upper bound for the (exponentially backed off) defrag worker interval,
+ in milliseconds, so repeated failures don't push the retry arbitrarily
+ far out. 15000 ms = 15 seconds.
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index b3f1a40c4425..af9bdb7f05ef 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -61,17 +61,31 @@
* Only pages a move truly reallocates are charged; pages harvested from the old
* backing are free, so an object larger than the budget is upgraded in
* budget-sized slices across runs.
+ *
+ * Set to 0 to disable defrag completely, otherwise must be 2M aligned.
*/
+#ifdef CONFIG_DRM_XE_BO_DEFRAG_SIZE_LIMIT
+#define XE_BO_DEFRAG_SIZE_LIMIT CONFIG_DRM_XE_BO_DEFRAG_SIZE_LIMIT
+#else
#define XE_BO_DEFRAG_SIZE_LIMIT SZ_32M
+#endif
/* Default delay before (re)running the defrag worker, in milliseconds. */
+#ifdef CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MS
+#define XE_BO_DEFRAG_INTERVAL_MS CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MS
+#else
#define XE_BO_DEFRAG_INTERVAL_MS 25
+#endif
/*
* Upper bound for the (exponentially backed off) defrag worker interval, in
* milliseconds, so repeated failures don't push the retry arbitrarily far out.
*/
+#ifdef CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS
+#define XE_BO_DEFRAG_INTERVAL_MAX_MS CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS
+#else
#define XE_BO_DEFRAG_INTERVAL_MAX_MS 15000 /* 15 seconds */
+#endif
static void xe_bo_defrag_worker(struct work_struct *w);
static void xe_place_from_ttm_type(u32 mem_type, struct ttm_place *place);
@@ -1246,6 +1260,10 @@ static void xe_bo_defrag_fini(void *arg)
*/
int xe_bo_defrag_init_early(struct xe_device *xe)
{
+ BUILD_BUG_ON(XE_BO_DEFRAG_INTERVAL_MS > XE_BO_DEFRAG_INTERVAL_MAX_MS);
+ BUILD_BUG_ON(XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M &&
+ !IS_ALIGNED(XE_BO_DEFRAG_SIZE_LIMIT, SZ_2M));
+
spin_lock_init(&xe->mem.defrag.lock);
INIT_LIST_HEAD(&xe->mem.defrag.list);
xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
@@ -1283,6 +1301,7 @@ static void xe_bo_defrag_schedule_locked(struct xe_device *xe, bool kick)
unsigned long delay;
lockdep_assert_held(&xe->mem.defrag.lock);
+ xe_assert(xe, XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M);
if (xe->mem.defrag.suspended)
return;
@@ -1361,6 +1380,8 @@ void xe_bo_defrag_kick(struct xe_device *xe)
* xe_bo_defrag_supported() - Whether background defragmentation is usable
* @xe: xe device instance
*
+ * Defragmentation is not supported if XE_BO_DEFRAG_SIZE_LIMIT is less than 2M.
+ *
* Defragmentation forces TTM moves that reallocate a BO's backing. On a VF
* platform that requires CCS save/restore this interacts badly with CCS
* metadata migration (which is currently broken for VF migration), so disable
@@ -1371,7 +1392,7 @@ void xe_bo_defrag_kick(struct xe_device *xe)
*/
static bool xe_bo_defrag_supported(struct xe_device *xe)
{
- return !IS_VF_CCS_NEEDED(xe);
+ return XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M && !IS_VF_CCS_NEEDED(xe);
}
static bool xe_bo_needs_defrag(struct xe_bo *bo)
@@ -1396,6 +1417,7 @@ static void xe_bo_defrag_add(struct xe_bo *bo)
xe_bo_assert_held(bo);
xe_assert(xe, xe_bo_needs_defrag(bo));
+ xe_assert(xe, XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M);
/*
* Under the dma-resv lock only the dying-BO path in the worker can
@@ -1435,6 +1457,9 @@ static void xe_bo_defrag_remove(struct xe_bo *bo)
{
xe_bo_assert_held(bo);
+ if (!xe_bo_defrag_supported(xe_bo_device(bo)))
+ return;
+
if (list_empty(&bo->defrag_link))
return;
@@ -1454,6 +1479,9 @@ static void xe_bo_defrag_update(struct xe_bo *bo)
{
xe_bo_assert_held(bo);
+ if (!xe_bo_defrag_supported(xe_bo_device(bo)))
+ return;
+
if (xe_bo_needs_defrag(bo))
xe_bo_defrag_add(bo);
else
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation
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
` (19 preceding siblings ...)
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 ` 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
` (17 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Convert xe_bo_defrag_one() to a three-phase scheme that moves the
expensive beneficial-order allocations out of the BO dma-resv lock:
1. Under the lock, re-check eligibility, capture the tt cpu-caching and
read the exact sub-optimal page count (ttm_tt_suboptimal_pages()),
bounded by the run budget.
2. Drop the lock and preallocate that many beneficial-order chunks via
ttm_pool_prealloc_fill(); reclaim/compaction stalls and the cpu
cache mode change both happen here, outside the lock.
3. Re-take the lock, re-check, and validate consuming the prealloc bag.
Any shortfall harvests the old backing instead of reclaiming, so the
move never stalls under the lock; the BO re-queues for a later pass.
With both allocation and caching hoisted out, the BO-lock held time
drops to copy-bound (median ~0.27ms, p95 ~2ms); the remaining tail is
lock-wait behind active rendering, as intended.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 55 +++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index af9bdb7f05ef..f3ce4e7ed98d 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1510,16 +1510,65 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
.defrag_bytes_remaining = budget,
};
struct ttm_buffer_object *ttm_bo = &bo->ttm;
+ struct ttm_pool *pool = &ttm_bo->bdev->pool;
+ struct ttm_pool_prealloc pp = {};
struct ttm_placement placement;
struct ttm_place place;
+ enum ttm_caching tt_caching;
+ unsigned int order, want = 0;
int ret = 0;
*consumed = 0;
*needs_more = false;
+ /*
+ * Phase 1: under the BO lock, re-check eligibility and estimate how
+ * many beneficial-order chunks the move will (re)allocate, bounded by
+ * the run's byte budget. Then drop the lock so the high-order, possibly
+ * reclaim/compaction stalling allocations happen unlocked.
+ */
+ xe_bo_lock(bo, false);
+ if (!xe_bo_needs_defrag(bo)) {
+ xe_bo_defrag_remove(bo);
+ xe_bo_unlock(bo);
+ goto out;
+ }
+ tt_caching = bo->ttm.ttm->caching;
+ order = ttm_pool_prealloc_order(pool);
+ if (order && ttm_bo->ttm) {
+ u32 suboptimal = ttm_tt_suboptimal_pages(ttm_bo->ttm);
+ u64 cap = min_t(u64, budget, xe_bo_size(bo)) >> PAGE_SHIFT;
+
+ /* Prealloc only the beneficial-order chunks the move replaces. */
+ want = DIV_ROUND_UP_ULL(min_t(u64, suboptimal, cap), 1UL << order);
+ }
+
+ /*
+ * Nothing the move could upgrade: TTM would fail a defrag move that
+ * allocates no chunk, so drop the BO rather than retry it forever. It
+ * is re-added if a later populate backs it sub-optimally again.
+ */
+ if (!want) {
+ xe_bo_defrag_remove(bo);
+ xe_bo_unlock(bo);
+ goto out;
+ }
+ xe_bo_unlock(bo);
+
+ /* Phase 2: preallocate outside the lock; */
+ ret = ttm_pool_prealloc_fill(pool, tt_caching, &pp, want);
+ if (ret || !pp.count) {
+ ret = ret ?: -ENOMEM;
+ xe_gt_stats_incr(xe_root_mmio_gt(xe),
+ XE_GT_STATS_ID_DEFRAG_FAILED_COUNT, 1);
+ goto out_err;
+ }
+
+ /*
+ * Phase 3: re-take the lock, re-check, and validate using the prealloc.
+ */
xe_bo_lock(bo, false);
- /* Re-check eligibility under the BO lock. */
if (!xe_bo_needs_defrag(bo)) {
xe_bo_defrag_remove(bo);
goto unlock;
@@ -1529,6 +1578,7 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
place.flags |= TTM_PL_FLAG_TEMPORARY;
placement.num_placement = 1;
placement.placement = &place;
+ ctx.prealloc = &pp;
/*
* On success the move reallocates the backing at beneficial order and
@@ -1580,6 +1630,9 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
unlock:
xe_bo_unlock(bo);
+out_err:
+ ttm_pool_prealloc_fini(pool, &pp);
+out:
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 22/36] drm/xe: Add defrag profiling tracepoints
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
` (20 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 23/36] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
` (16 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Add two tracepoints to profile the page defragmentation worker:
- xe_bo_defrag_worker: emitted on worker entry and exit with the
bytes processed in the run.
- xe_bo_defrag_one: emitted per BO with the run budget, the prealloc
fill ratio (got/want) and the lock-held, lock-wait and prealloc
durations, plus the bytes consumed and the result.
These break down the cost of a defrag attempt into its locked vs
unlocked phases, making it possible to confirm that the expensive
beneficial-order allocation and cpu cache mode change happen outside
the BO dma-resv lock and that the residual lock-held time is copy-bound
(with the tail dominated by lock-wait behind active rendering).
v4:
- Drop count from trace point
- Add phase 1 to lockwait_us (Niranjana)
v5:
- Reword commit (Sashiko)
- Use pp.count rather than used (Sashiko)
- Record prealloc_ns regardless of failure (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 18 +++++++++-
drivers/gpu/drm/xe/xe_trace_bo.h | 56 ++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index f3ce4e7ed98d..bf8078635932 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1515,7 +1515,9 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
struct ttm_placement placement;
struct ttm_place place;
enum ttm_caching tt_caching;
- unsigned int order, want = 0;
+ unsigned int order, want = 0, got = 0;
+ u64 lock_ns = 0, prealloc_ns = 0, lockwait_ns = 0;
+ ktime_t t0;
int ret = 0;
*consumed = 0;
@@ -1527,7 +1529,9 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
* the run's byte budget. Then drop the lock so the high-order, possibly
* reclaim/compaction stalling allocations happen unlocked.
*/
+ t0 = ktime_get();
xe_bo_lock(bo, false);
+ lockwait_ns = ktime_to_ns(ktime_sub(ktime_get(), t0));
if (!xe_bo_needs_defrag(bo)) {
xe_bo_defrag_remove(bo);
xe_bo_unlock(bo);
@@ -1556,7 +1560,10 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
xe_bo_unlock(bo);
/* Phase 2: preallocate outside the lock; */
+ t0 = ktime_get();
ret = ttm_pool_prealloc_fill(pool, tt_caching, &pp, want);
+ prealloc_ns = ktime_to_ns(ktime_sub(ktime_get(), t0));
+ got = pp.count;
if (ret || !pp.count) {
ret = ret ?: -ENOMEM;
xe_gt_stats_incr(xe_root_mmio_gt(xe),
@@ -1567,7 +1574,10 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
/*
* Phase 3: re-take the lock, re-check, and validate using the prealloc.
*/
+ t0 = ktime_get();
xe_bo_lock(bo, false);
+ lockwait_ns += ktime_to_ns(ktime_sub(ktime_get(), t0));
+ t0 = ktime_get();
if (!xe_bo_needs_defrag(bo)) {
xe_bo_defrag_remove(bo);
@@ -1630,9 +1640,12 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
unlock:
xe_bo_unlock(bo);
+ lock_ns = ktime_to_ns(ktime_sub(ktime_get(), t0));
out_err:
ttm_pool_prealloc_fini(pool, &pp);
out:
+ trace_xe_bo_defrag_one(bo, budget, want, got, lock_ns, prealloc_ns,
+ lockwait_ns, *consumed, ret);
return ret;
}
@@ -1660,6 +1673,8 @@ static void xe_bo_defrag_worker(struct work_struct *w)
return;
}
+ trace_xe_bo_defrag_worker(xe, 0, true);
+
/*
* Process at most XE_BO_DEFRAG_SIZE_LIMIT bytes of newly (re)allocated
* backing per run rather than draining the whole list in one go. Only
@@ -1762,6 +1777,7 @@ static void xe_bo_defrag_worker(struct work_struct *w)
xe_pm_runtime_put(xe);
drm_dev_exit(idx);
+ trace_xe_bo_defrag_worker(xe, defrag_bytes, false);
}
static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
diff --git a/drivers/gpu/drm/xe/xe_trace_bo.h b/drivers/gpu/drm/xe/xe_trace_bo.h
index 36fc7eb65882..e21aa96d9d6f 100644
--- a/drivers/gpu/drm/xe/xe_trace_bo.h
+++ b/drivers/gpu/drm/xe/xe_trace_bo.h
@@ -90,6 +90,62 @@ TRACE_EVENT(xe_bo_move,
__get_str(new_placement_name), __get_str(device_id))
);
+TRACE_EVENT(xe_bo_defrag_worker,
+ TP_PROTO(struct xe_device *xe, u64 defrag_bytes, bool enter),
+ TP_ARGS(xe, defrag_bytes, enter),
+ TP_STRUCT__entry(
+ __string(dev, dev_name(xe->drm.dev))
+ __field(u64, defrag_bytes)
+ __field(bool, enter)
+ ),
+ TP_fast_assign(
+ __assign_str(dev);
+ __entry->defrag_bytes = defrag_bytes;
+ __entry->enter = enter;
+ ),
+ TP_printk("dev=%s %s defrag_bytes=%llu",
+ __get_str(dev), __entry->enter ? "enter" : "exit",
+ __entry->defrag_bytes)
+);
+
+TRACE_EVENT(xe_bo_defrag_one,
+ TP_PROTO(struct xe_bo *bo, u64 budget, unsigned int prealloc_want,
+ unsigned int prealloc_got, u64 lock_ns, u64 prealloc_ns,
+ u64 lockwait_ns, u64 consumed, int ret),
+ TP_ARGS(bo, budget, prealloc_want, prealloc_got, lock_ns,
+ prealloc_ns, lockwait_ns, consumed, ret),
+ TP_STRUCT__entry(
+ __string(dev, __dev_name_bo(bo))
+ __field(size_t, size)
+ __field(u64, budget)
+ __field(unsigned int, prealloc_want)
+ __field(unsigned int, prealloc_got)
+ __field(u64, lock_us)
+ __field(u64, prealloc_us)
+ __field(u64, lockwait_us)
+ __field(u64, consumed)
+ __field(int, ret)
+ ),
+ TP_fast_assign(
+ __assign_str(dev);
+ __entry->size = xe_bo_size(bo);
+ __entry->budget = budget;
+ __entry->prealloc_want = prealloc_want;
+ __entry->prealloc_got = prealloc_got;
+ __entry->lock_us = div_u64(lock_ns, 1000);
+ __entry->prealloc_us = div_u64(prealloc_ns, 1000);
+ __entry->lockwait_us = div_u64(lockwait_ns, 1000);
+ __entry->consumed = consumed;
+ __entry->ret = ret;
+ ),
+ TP_printk("dev=%s size=%zu budget=%llu prealloc=%u/%u lock_us=%llu lockwait_us=%llu prealloc_us=%llu consumed=%llu ret=%d",
+ __get_str(dev), __entry->size, __entry->budget,
+ __entry->prealloc_got, __entry->prealloc_want,
+ __entry->lock_us, __entry->lockwait_us,
+ __entry->prealloc_us, __entry->consumed,
+ __entry->ret)
+);
+
DECLARE_EVENT_CLASS(xe_vma,
TP_PROTO(struct xe_vma *vma),
TP_ARGS(vma),
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 23/36] drm/xe: Preallocate system BO backing outside the dma-resv lock
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
` (21 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 22/36] drm/xe: Add defrag profiling tracepoints Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 24/36] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
` (15 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
xe_gem_create_ioctl() populates a buffer object's backing store inside
xe_validation_guard(), i.e. under the dma-resv lock. For a system-memory
buffer that means the whole page allocation - potentially stalling in
reclaim or compaction - happens in the critical section, holding the
reservation and blocking anything that contends on it.
Use the TTM full-preallocation mechanism to move that work out of the
lock. For a system-only, non-deferred user BO, allocate the entire tt
backing up front, before entering the validation guard, and hand the bag
down to the populate so it merely installs the pages:
- Thread an optional struct ttm_pool_prealloc through xe_bo_create_user()
-> __xe_bo_create_locked() -> xe_bo_init_locked(), which stashes it in
ttm_operation_ctx::prealloc. All other callers pass NULL.
- In xe_gem_create_ioctl(), for XE_BO_FLAG_SYSTEM BOs that are not VRAM,
stolen or deferred-backing, call ttm_pool_prealloc_fill_full() before
the guard and ttm_pool_prealloc_fini() after it. The bag size covers
both the data pages and the appended CCS backup pages, matching the tt
layout in xe_ttm_tt_create(), and the caching mirrors the same path.
The fill is best-effort: on a short fill (or if it is skipped) the pool
allocates the remainder in-line as before, so this is purely an
optimisation with no behavioural change to the created BO. fini() only
releases the unconsumed tail, so it is safe on every success, error and
OOM-retry path (consumed pages are owned by the tt).
The fill requests reclaim backoff for higher-order chunks
(@beneficial_reclaim_backoff) when defragmentation is supported: Xe runs
a background defragmenter that upgrades suboptimal pages to beneficial
order in place, so there is no need to stall this user context
reclaiming/compacting for contiguity. When defrag is disabled (VF CCS)
there is no later upgrade, so reclaim backoff is left off and
beneficial-order pages are taken up front.
To size the preallocation before the xe_bo exists, factor the CCS-pages
decision in xe_bo_needs_ccs_pages() into a parameterised helper,
__xe_bo_needs_ccs_pages(), and query it directly from the ioctl.
v4:
- Use helper function in xe_gem_create_ioctl (Niranjana)
v5:
- Fix build for certain Kconfig (Sashiko)
- Rework math to avoid overflow (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/tests/xe_bo.c | 12 +-
drivers/gpu/drm/xe/tests/xe_dma_buf.c | 4 +-
drivers/gpu/drm/xe/tests/xe_migrate.c | 9 +-
drivers/gpu/drm/xe/xe_bo.c | 151 +++++++++++++++++++++-----
drivers/gpu/drm/xe/xe_bo.h | 6 +-
drivers/gpu/drm/xe/xe_dma_buf.c | 3 +-
6 files changed, 146 insertions(+), 39 deletions(-)
diff --git a/drivers/gpu/drm/xe/tests/xe_bo.c b/drivers/gpu/drm/xe/tests/xe_bo.c
index 22a2e8f8143a..68a7d5eb74bb 100644
--- a/drivers/gpu/drm/xe/tests/xe_bo.c
+++ b/drivers/gpu/drm/xe/tests/xe_bo.c
@@ -89,7 +89,7 @@ static void run_only_leaf(struct kunit *test,
bo = xe_bo_create_user(xe, NULL, li->alloc_size,
DRM_XE_GEM_CPU_CACHING_WC,
- XE_BO_FLAG_VRAM0, NULL);
+ XE_BO_FLAG_VRAM0, NULL, NULL);
if (IS_ERR(bo)) {
page_size_alloc_restore(xe, &saved);
if (PTR_ERR(bo) == -ENOSPC) {
@@ -183,7 +183,7 @@ static void xe_bo_page_size_alloc_mixed_bos(struct kunit *test)
*/
bo = xe_bo_create_user(xe, NULL, SZ_1G,
DRM_XE_GEM_CPU_CACHING_WC,
- XE_BO_FLAG_VRAM0, NULL);
+ XE_BO_FLAG_VRAM0, NULL, NULL);
if (IS_ERR(bo)) {
int err = PTR_ERR(bo);
@@ -366,7 +366,7 @@ static void ccs_test_run_tile(struct xe_device *xe, struct xe_tile *tile,
kunit_info(test, "Testing system memory\n");
bo = xe_bo_create_user(xe, NULL, SZ_1M, DRM_XE_GEM_CPU_CACHING_WC,
- bo_flags, exec);
+ bo_flags, NULL, exec);
if (IS_ERR(bo)) {
KUNIT_FAIL(test, "Failed to create bo.\n");
return;
@@ -445,7 +445,7 @@ static int evict_test_run_tile(struct xe_device *xe, struct xe_tile *tile, struc
xe_vm_lock(vm, false);
bo = xe_bo_create_user(xe, vm, 0x10000,
DRM_XE_GEM_CPU_CACHING_WC,
- bo_flags, exec);
+ bo_flags, NULL, exec);
xe_vm_unlock(vm);
if (IS_ERR(bo)) {
KUNIT_FAIL(test, "bo create err=%pe\n", bo);
@@ -454,7 +454,7 @@ static int evict_test_run_tile(struct xe_device *xe, struct xe_tile *tile, struc
external = xe_bo_create_user(xe, NULL, 0x10000,
DRM_XE_GEM_CPU_CACHING_WC,
- bo_flags, NULL);
+ bo_flags, NULL, NULL);
if (IS_ERR(external)) {
KUNIT_FAIL(test, "external bo create err=%pe\n", external);
goto cleanup_bo;
@@ -719,7 +719,7 @@ static int shrink_test_run_device(struct xe_device *xe)
/* We can create bos using WC caching here. But it is slower. */
bo = xe_bo_create_user(xe, NULL, XE_BO_SHRINK_SIZE,
DRM_XE_GEM_CPU_CACHING_WB,
- XE_BO_FLAG_SYSTEM, NULL);
+ XE_BO_FLAG_SYSTEM, NULL, NULL);
if (IS_ERR(bo)) {
if (bo != ERR_PTR(-ENOMEM) && bo != ERR_PTR(-ENOSPC) &&
bo != ERR_PTR(-EINTR) && bo != ERR_PTR(-ERESTARTSYS))
diff --git a/drivers/gpu/drm/xe/tests/xe_dma_buf.c b/drivers/gpu/drm/xe/tests/xe_dma_buf.c
index 792376e965f1..dae03a4f6af1 100644
--- a/drivers/gpu/drm/xe/tests/xe_dma_buf.c
+++ b/drivers/gpu/drm/xe/tests/xe_dma_buf.c
@@ -127,7 +127,7 @@ static void xe_test_dmabuf_import_same_driver(struct xe_device *xe)
kunit_info(test, "running %s\n", __func__);
bo = xe_bo_create_user(xe, NULL, size, DRM_XE_GEM_CPU_CACHING_WC,
- params->mem_mask, NULL);
+ params->mem_mask, NULL, NULL);
if (IS_ERR(bo)) {
KUNIT_FAIL(test, "xe_bo_create() failed with err=%ld\n",
PTR_ERR(bo));
@@ -215,7 +215,7 @@ static void xe_test_dmabuf_move_notify_no_resource(struct xe_device *xe)
kunit_info(test, "running %s\n", __func__);
bo = xe_bo_create_user(xe, NULL, PAGE_SIZE, DRM_XE_GEM_CPU_CACHING_WC,
- params->mem_mask, NULL);
+ params->mem_mask, NULL, NULL);
if (IS_ERR(bo)) {
KUNIT_FAIL(test, "xe_bo_create() failed with err=%ld\n",
PTR_ERR(bo));
diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
index 7feb704b0984..eba991e28af0 100644
--- a/drivers/gpu/drm/xe/tests/xe_migrate.c
+++ b/drivers/gpu/drm/xe/tests/xe_migrate.c
@@ -649,7 +649,7 @@ static void validate_ccs_test_run_tile(struct xe_device *xe, struct xe_tile *til
DRM_XE_GEM_CPU_CACHING_WC,
XE_BO_FLAG_SYSTEM |
XE_BO_FLAG_NEEDS_CPU_ACCESS |
- XE_BO_FLAG_PINNED, NULL);
+ XE_BO_FLAG_PINNED, NULL, NULL);
if (IS_ERR(sys_bo)) {
KUNIT_FAIL(test, "xe_bo_create() failed with err=%ld\n",
@@ -675,7 +675,7 @@ static void validate_ccs_test_run_tile(struct xe_device *xe, struct xe_tile *til
ccs_bo = xe_bo_create_user(xe, NULL, SZ_4M,
DRM_XE_GEM_CPU_CACHING_WC,
bo_flags | XE_BO_FLAG_NEEDS_CPU_ACCESS |
- XE_BO_FLAG_PINNED, NULL);
+ XE_BO_FLAG_PINNED, NULL, NULL);
if (IS_ERR(ccs_bo)) {
KUNIT_FAIL(test, "xe_bo_create() failed with err=%ld\n",
@@ -700,7 +700,7 @@ static void validate_ccs_test_run_tile(struct xe_device *xe, struct xe_tile *til
vram_bo = xe_bo_create_user(xe, NULL, SZ_4M,
DRM_XE_GEM_CPU_CACHING_WC,
bo_flags | XE_BO_FLAG_NEEDS_CPU_ACCESS |
- XE_BO_FLAG_PINNED, NULL);
+ XE_BO_FLAG_PINNED, NULL, NULL);
if (IS_ERR(vram_bo)) {
KUNIT_FAIL(test, "xe_bo_create() failed with err=%ld\n",
PTR_ERR(vram_bo));
@@ -979,7 +979,8 @@ static void access_memory_test_run_tile(struct xe_device *xe,
bo = xe_bo_create_user(xe, NULL, ACCESS_MEM_BO_SIZE,
DRM_XE_GEM_CPU_CACHING_WC,
- bo_flags | XE_BO_FLAG_NEEDS_CPU_ACCESS, NULL);
+ bo_flags | XE_BO_FLAG_NEEDS_CPU_ACCESS, NULL,
+ NULL);
if (IS_ERR(bo)) {
KUNIT_FAIL(test, "Failed to create bo: %pe\n", bo);
goto free_buf;
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index bf8078635932..7b9017e9c758 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -2321,7 +2321,7 @@ int xe_bo_notifier_prepare_pinned(struct xe_bo *bo)
backup = xe_bo_init_locked(xe, NULL, NULL, bo->ttm.base.resv, NULL, xe_bo_size(bo),
DRM_XE_GEM_CPU_CACHING_WB, ttm_bo_type_kernel,
XE_BO_FLAG_SYSTEM | XE_BO_FLAG_NEEDS_CPU_ACCESS |
- XE_BO_FLAG_PINNED, NULL, &exec);
+ XE_BO_FLAG_PINNED, NULL, NULL, &exec);
if (IS_ERR(backup)) {
drm_exec_retry_on_contention(&exec);
ret = PTR_ERR(backup);
@@ -2463,7 +2463,7 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
xe_bo_size(bo),
DRM_XE_GEM_CPU_CACHING_WB, ttm_bo_type_kernel,
XE_BO_FLAG_SYSTEM | XE_BO_FLAG_NEEDS_CPU_ACCESS |
- XE_BO_FLAG_PINNED, NULL, &exec);
+ XE_BO_FLAG_PINNED, NULL, NULL, &exec);
if (IS_ERR(backup)) {
drm_exec_retry_on_contention(&exec);
ret = PTR_ERR(backup);
@@ -3266,6 +3266,8 @@ void xe_bo_free(struct xe_bo *bo)
* @flags: XE_BO_FLAG_ flags.
* @dma_buf: The dma-buf to reference for the BO lifetime (imported BOs),
* or NULL.
+ * @prealloc: Optional pages preallocated outside the dma-resv lock to back the
+ * bo (see ttm_operation_ctx::prealloc), or NULL.
* @exec: The drm_exec transaction to use for exhaustive eviction.
*
* Initialize or create an xe buffer object. On failure, any allocated buffer
@@ -3278,12 +3280,14 @@ struct xe_bo *xe_bo_init_locked(struct xe_device *xe, struct xe_bo *bo,
struct ttm_lru_bulk_move *bulk, size_t size,
u16 cpu_caching, enum ttm_bo_type type,
u32 flags, struct dma_buf *dma_buf,
+ struct ttm_pool_prealloc *prealloc,
struct drm_exec *exec)
{
struct ttm_operation_ctx ctx = {
.interruptible = true,
.no_wait_gpu = false,
.gfp_retry_mayfail = true,
+ .prealloc = prealloc,
};
struct ttm_placement *placement;
uint32_t alignment;
@@ -3479,7 +3483,8 @@ __xe_bo_create_locked(struct xe_device *xe,
struct xe_tile *tile, struct xe_vm *vm,
size_t size, u64 start, u64 end,
u16 cpu_caching, enum ttm_bo_type type, u32 flags,
- u64 alignment, struct drm_exec *exec)
+ u64 alignment, struct ttm_pool_prealloc *prealloc,
+ struct drm_exec *exec)
{
struct xe_bo *bo = NULL;
int err;
@@ -3504,7 +3509,7 @@ __xe_bo_create_locked(struct xe_device *xe,
vm && !xe_vm_in_fault_mode(vm) &&
flags & XE_BO_FLAG_USER ?
&vm->lru_bulk_move : NULL, size,
- cpu_caching, type, flags, NULL, exec);
+ cpu_caching, type, flags, NULL, prealloc, exec);
if (IS_ERR(bo))
return bo;
@@ -3579,7 +3584,7 @@ struct xe_bo *xe_bo_create_locked(struct xe_device *xe, struct xe_tile *tile,
struct drm_exec *exec)
{
return __xe_bo_create_locked(xe, tile, vm, size, 0, ~0ULL, 0, type,
- flags, 0, exec);
+ flags, 0, NULL, exec);
}
static struct xe_bo *xe_bo_create_novm(struct xe_device *xe, struct xe_tile *tile,
@@ -3595,7 +3600,7 @@ static struct xe_bo *xe_bo_create_novm(struct xe_device *xe, struct xe_tile *til
xe_validation_guard(&ctx, &xe->val, &exec, (struct xe_val_flags) {.interruptible = intr},
ret) {
bo = __xe_bo_create_locked(xe, tile, NULL, size, 0, ~0ULL,
- cpu_caching, type, flags, alignment, &exec);
+ cpu_caching, type, flags, alignment, NULL, &exec);
drm_exec_retry_on_contention(&exec);
if (IS_ERR(bo)) {
ret = PTR_ERR(bo);
@@ -3754,6 +3759,9 @@ static void xe_bo_debug_mixed_mode_cur_index_advance(struct xe_device *xe,
* @size: The storage size to use for the bo.
* @cpu_caching: The caching mode to be used for system backing store.
* @flags: XE_BO_FLAG_ flags.
+ * @prealloc: Optional pages preallocated outside the dma-resv lock to back the
+ * bo (see ttm_operation_ctx::prealloc), or NULL. Only consumed on the locked
+ * (@vm or @exec) path.
* @exec: The drm_exec transaction to use for exhaustive eviction, or NULL
* if such a transaction should be initiated by the call.
*
@@ -3764,7 +3772,8 @@ static void xe_bo_debug_mixed_mode_cur_index_advance(struct xe_device *xe,
struct xe_bo *xe_bo_create_user(struct xe_device *xe,
struct xe_vm *vm, size_t size,
u16 cpu_caching,
- u32 flags, struct drm_exec *exec)
+ u32 flags, struct ttm_pool_prealloc *prealloc,
+ struct drm_exec *exec)
{
struct xe_bo *bo;
int err = 0;
@@ -3781,7 +3790,7 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe,
xe_assert(xe, exec);
bo = __xe_bo_create_locked(xe, NULL, vm, size, 0, ~0ULL,
cpu_caching, ttm_bo_type_device,
- flags, 0, exec);
+ flags, 0, prealloc, exec);
if (!IS_ERR(bo))
xe_bo_unlock_vm_held(bo);
} else {
@@ -3820,7 +3829,7 @@ struct xe_bo *xe_bo_create_pin_range_novm(struct xe_device *xe, struct xe_tile *
xe_validation_guard(&ctx, &xe->val, &exec, (struct xe_val_flags) {}, err) {
bo = __xe_bo_create_locked(xe, tile, NULL, size, start, end,
- 0, type, flags, 0, &exec);
+ 0, type, flags, 0, NULL, &exec);
if (IS_ERR(bo)) {
drm_exec_retry_on_contention(&exec);
err = PTR_ERR(bo);
@@ -3859,7 +3868,7 @@ static struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
bo = __xe_bo_create_locked(xe, tile, vm, size, start, end, 0, type,
flags | XE_BO_FLAG_NEEDS_CPU_ACCESS | XE_BO_FLAG_PINNED,
- alignment, exec);
+ alignment, NULL, exec);
if (IS_ERR(bo))
return bo;
@@ -4456,6 +4465,80 @@ static int gem_create_user_extensions(struct xe_device *xe, struct xe_bo *bo,
return 0;
}
+static bool __xe_bo_needs_ccs_pages(struct xe_device *xe,
+ enum ttm_bo_type type, u32 flags,
+ u16 cpu_caching);
+
+/*
+ * For system-only BOs, preallocate the whole backing outside the dma-resv lock
+ * so the populate under the validation guard does not stall in
+ * reclaim/compaction. The caching mirrors the system-BO path in
+ * xe_ttm_tt_create(); the pool falls back to in-line allocation for any
+ * shortfall, so a failed fill is harmless.
+ *
+ * Return: true if @prealloc was filled (possibly partially) and must be
+ * released with ttm_pool_prealloc_fini(), false if preallocation was skipped.
+ */
+static bool xe_gem_create_prealloc(struct xe_device *xe,
+ const struct drm_xe_gem_create *args,
+ u32 bo_flags,
+ struct ttm_pool_prealloc *prealloc)
+{
+ struct ttm_resource_manager *tt_man =
+ ttm_manager_type(&xe->ttm, XE_PL_TT);
+ enum ttm_caching caching = ttm_cached;
+ u64 num_pages = args->size >> PAGE_SHIFT;
+ u64 used, shift_size, avail;
+
+ if (!(bo_flags & XE_BO_FLAG_SYSTEM) ||
+ (bo_flags & (XE_BO_FLAG_DEFER_BACKING | XE_BO_FLAG_VRAM_MASK |
+ XE_BO_FLAG_STOLEN)))
+ return false;
+
+ if (!tt_man)
+ return false;
+
+ if (!IS_DGFX(xe) && args->cpu_caching == DRM_XE_GEM_CPU_CACHING_WC)
+ caching = ttm_write_combined;
+
+ /*
+ * Cover the CCS backup pages appended to the tt (see
+ * xe_ttm_tt_create()) so the whole tt is preallocated.
+ */
+ if (__xe_bo_needs_ccs_pages(xe, ttm_bo_type_device, bo_flags,
+ args->cpu_caching))
+ num_pages += DIV_ROUND_UP(xe_device_ccs_bytes(xe, args->size),
+ PAGE_SIZE);
+
+ /*
+ * Only prealloc when the backing fits the currently-available TT space
+ * (manager size minus current usage). This skips the up-front
+ * reclaim/compaction both for over-large, user-controlled sizes and
+ * when TT is already near full; the populate under the validation
+ * guard handles those cases. Compare in pages: a user-controlled size
+ * plus the CCS pages can overflow a byte count, and the fill takes an
+ * unsigned int page count.
+ */
+ used = ttm_resource_manager_usage(tt_man);
+ shift_size = tt_man->size << PAGE_SHIFT;
+ avail = shift_size > used ? shift_size - used : 0;
+ if (num_pages > (avail >> PAGE_SHIFT) || num_pages > UINT_MAX)
+ return false;
+
+ /*
+ * Back off aggressive reclaim/compaction for higher-order chunks here:
+ * Xe runs a background defragmenter that upgrades suboptimal pages to
+ * beneficial order in place later, so there is no need to stall this
+ * user context reclaiming for contiguity. When defrag is disabled there
+ * is no such later upgrade, so do not back off reclaim here: take
+ * beneficial-order pages up front.
+ */
+ ttm_pool_prealloc_fill_full(&xe->ttm.pool, caching, prealloc,
+ num_pages, xe_bo_defrag_supported(xe));
+
+ return true;
+}
+
int xe_gem_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file)
{
@@ -4466,6 +4549,8 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
struct drm_exec exec;
struct xe_vm *vm = NULL;
struct xe_bo *bo;
+ struct ttm_pool_prealloc prealloc = {};
+ bool have_prealloc;
unsigned int bo_flags;
u32 handle;
int err;
@@ -4548,6 +4633,8 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
return -ENOENT;
}
+ have_prealloc = xe_gem_create_prealloc(xe, args, bo_flags, &prealloc);
+
err = 0;
xe_validation_guard(&ctx, &xe->val, &exec, (struct xe_val_flags) {.interruptible = true},
err) {
@@ -4558,7 +4645,8 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
break;
}
bo = xe_bo_create_user(xe, vm, args->size, args->cpu_caching,
- bo_flags, &exec);
+ bo_flags, have_prealloc ? &prealloc : NULL,
+ &exec);
drm_exec_retry_on_contention(&exec);
if (IS_ERR(bo)) {
err = PTR_ERR(bo);
@@ -4566,6 +4654,8 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
break;
}
}
+ if (have_prealloc)
+ ttm_pool_prealloc_fini(&xe->ttm.pool, &prealloc);
if (err)
goto out_vm;
@@ -4883,21 +4973,19 @@ int xe_bo_evict(struct xe_bo *bo, struct drm_exec *exec)
return 0;
}
-/**
- * xe_bo_needs_ccs_pages - Whether a bo needs to back up CCS pages when
- * placed in system memory.
- * @bo: The xe_bo
- *
- * Return: true if extra pages need to be allocated, false otherwise.
+/*
+ * Whether a bo with the given attributes needs to back up CCS pages when placed
+ * in system memory. Split out so callers can query before the xe_bo exists (see
+ * xe_gem_create_ioctl() preallocation).
*/
-bool xe_bo_needs_ccs_pages(struct xe_bo *bo)
+static bool __xe_bo_needs_ccs_pages(struct xe_device *xe,
+ enum ttm_bo_type type, u32 flags,
+ u16 cpu_caching)
{
- struct xe_device *xe = xe_bo_device(bo);
-
if (GRAPHICS_VER(xe) >= 20 && IS_DGFX(xe))
return false;
- if (!xe_device_has_flat_ccs(xe) || bo->ttm.type != ttm_bo_type_device)
+ if (!xe_device_has_flat_ccs(xe) || type != ttm_bo_type_device)
return false;
/* On discrete GPUs, if the GPU can access this buffer from
@@ -4905,24 +4993,37 @@ bool xe_bo_needs_ccs_pages(struct xe_bo *bo)
* can't be used since there's no CCS storage associated with
* non-VRAM addresses.
*/
- if (IS_DGFX(xe) && (bo->flags & XE_BO_FLAG_SYSTEM))
+ if (IS_DGFX(xe) && (flags & XE_BO_FLAG_SYSTEM))
return false;
/* Check if userspace explicitly requested no compression */
- if (bo->flags & XE_BO_FLAG_NO_COMPRESSION)
+ if (flags & XE_BO_FLAG_NO_COMPRESSION)
return false;
/*
* For WB (Write-Back) CPU caching mode, check if the device
* supports WB compression with coherency.
*/
- if (bo->cpu_caching == DRM_XE_GEM_CPU_CACHING_WB &&
+ if (cpu_caching == DRM_XE_GEM_CPU_CACHING_WB &&
xe->pat.idx[XE_CACHE_WB_COMPRESSION] == XE_PAT_INVALID_IDX)
return false;
return true;
}
+/**
+ * xe_bo_needs_ccs_pages - Whether a bo needs to back up CCS pages when
+ * placed in system memory.
+ * @bo: The xe_bo
+ *
+ * Return: true if extra pages need to be allocated, false otherwise.
+ */
+bool xe_bo_needs_ccs_pages(struct xe_bo *bo)
+{
+ return __xe_bo_needs_ccs_pages(xe_bo_device(bo), bo->ttm.type,
+ bo->flags, bo->cpu_caching);
+}
+
/**
* __xe_bo_release_dummy() - Dummy kref release function
* @kref: The embedded struct kref.
@@ -5029,7 +5130,7 @@ int xe_bo_dumb_create(struct drm_file *file_priv,
DRM_XE_GEM_CPU_CACHING_WC,
XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
XE_BO_FLAG_FORCE_WC |
- XE_BO_FLAG_NEEDS_CPU_ACCESS, NULL);
+ XE_BO_FLAG_NEEDS_CPU_ACCESS, NULL, NULL);
if (IS_ERR(bo))
return PTR_ERR(bo);
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index ff99bed7089b..48298a372e70 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -115,6 +115,7 @@ enum xe_madv_purgeable_state {
struct drm_printer;
struct sg_table;
struct ttm_tt;
+struct ttm_pool_prealloc;
struct xe_bo *xe_bo_alloc(void);
void xe_bo_free(struct xe_bo *bo);
@@ -124,13 +125,16 @@ struct xe_bo *xe_bo_init_locked(struct xe_device *xe, struct xe_bo *bo,
struct ttm_lru_bulk_move *bulk, size_t size,
u16 cpu_caching, enum ttm_bo_type type,
u32 flags, struct dma_buf *dma_buf,
+ struct ttm_pool_prealloc *prealloc,
struct drm_exec *exec);
struct xe_bo *xe_bo_create_locked(struct xe_device *xe, struct xe_tile *tile,
struct xe_vm *vm, size_t size,
enum ttm_bo_type type, u32 flags,
struct drm_exec *exec);
struct xe_bo *xe_bo_create_user(struct xe_device *xe, struct xe_vm *vm, size_t size,
- u16 cpu_caching, u32 flags, struct drm_exec *exec);
+ u16 cpu_caching, u32 flags,
+ struct ttm_pool_prealloc *prealloc,
+ struct drm_exec *exec);
struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
struct xe_vm *vm, size_t size,
enum ttm_bo_type type, u32 flags,
diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
index 90c9b90de552..f860221c7e53 100644
--- a/drivers/gpu/drm/xe/xe_dma_buf.c
+++ b/drivers/gpu/drm/xe/xe_dma_buf.c
@@ -345,7 +345,8 @@ xe_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)
bo = xe_bo_init_locked(xe, NULL, NULL, resv, NULL, dma_buf->size,
0, /* Will require 1way or 2way for vm_bind */
- ttm_bo_type_sg, XE_BO_FLAG_SYSTEM, dma_buf, &exec);
+ ttm_bo_type_sg, XE_BO_FLAG_SYSTEM, dma_buf,
+ NULL, &exec);
drm_exec_retry_on_contention(&exec);
if (IS_ERR(bo)) {
ret = PTR_ERR(bo);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 24/36] drm/xe: Add tracepoint for xe_gem_create_ioctl
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
` (22 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 25/36] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
` (14 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Add a xe_gem_create_ioctl tracepoint to help profile GEM creation, in
particular the cost of populating a BO while holding the dma-resv lock
versus the total IOCTL cost. This is useful for evaluating the
out-of-lock preallocation path, which aims to shrink the time spent
under the lock.
The tracepoint records the BO size, the requested placement mask, the
CPU caching mode, the VM asid (0 when no VM is bound), the total time
spent in the IOCTL, and the time spent under the dma-resv lock (the
xe_validation_guard region where the lock is held).
The asid is captured at VM lookup time rather than at trace emission,
since the VM reference is dropped before the tracepoint fires.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 17 +++++++++++++++++
drivers/gpu/drm/xe/xe_trace_bo.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 7b9017e9c758..41092e2810b4 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -4553,6 +4553,10 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
bool have_prealloc;
unsigned int bo_flags;
u32 handle;
+ ktime_t ioctl_start = ktime_get();
+ ktime_t lock_start = ktime_set(0, 0);
+ u64 lock_ns = 0;
+ u32 asid = 0;
int err;
if (XE_IOCTL_DBG(xe, args->pad[0] || args->pad[1] || args->pad[2]) ||
@@ -4631,6 +4635,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
vm = xe_vm_lookup(xef, args->vm_id);
if (XE_IOCTL_DBG(xe, !vm))
return -ENOENT;
+ asid = vm->usm.asid;
}
have_prealloc = xe_gem_create_prealloc(xe, args, bo_flags, &prealloc);
@@ -4644,6 +4649,10 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
if (err)
break;
}
+
+ if (lock_start == ktime_set(0, 0))
+ lock_start = ktime_get();
+
bo = xe_bo_create_user(xe, vm, args->size, args->cpu_caching,
bo_flags, have_prealloc ? &prealloc : NULL,
&exec);
@@ -4654,6 +4663,8 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
break;
}
}
+ if (lock_start != ktime_set(0, 0))
+ lock_ns = ktime_to_ns(ktime_sub(ktime_get(), lock_start));
if (have_prealloc)
ttm_pool_prealloc_fini(&xe->ttm.pool, &prealloc);
if (err)
@@ -4686,6 +4697,12 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
if (vm)
xe_vm_put(vm);
+ trace_xe_gem_create_ioctl(xe, args->size, args->placement,
+ args->cpu_caching, asid,
+ div_u64(ktime_to_ns(ktime_sub(ktime_get(),
+ ioctl_start)), 1000),
+ div_u64(lock_ns, 1000));
+
return err;
}
diff --git a/drivers/gpu/drm/xe/xe_trace_bo.h b/drivers/gpu/drm/xe/xe_trace_bo.h
index e21aa96d9d6f..1ebfd3026e5a 100644
--- a/drivers/gpu/drm/xe/xe_trace_bo.h
+++ b/drivers/gpu/drm/xe/xe_trace_bo.h
@@ -146,6 +146,37 @@ TRACE_EVENT(xe_bo_defrag_one,
__entry->ret)
);
+TRACE_EVENT(xe_gem_create_ioctl,
+ TP_PROTO(struct xe_device *xe, u64 size, u32 placement,
+ u16 caching, u32 asid, u64 ioctl_us, u64 lock_us),
+ TP_ARGS(xe, size, placement, caching, asid, ioctl_us, lock_us),
+
+ TP_STRUCT__entry(
+ __string(dev, dev_name(xe->drm.dev))
+ __field(u64, size)
+ __field(u32, placement)
+ __field(u16, caching)
+ __field(u32, asid)
+ __field(u64, ioctl_us)
+ __field(u64, lock_us)
+ ),
+
+ TP_fast_assign(
+ __assign_str(dev);
+ __entry->size = size;
+ __entry->placement = placement;
+ __entry->caching = caching;
+ __entry->asid = asid;
+ __entry->ioctl_us = ioctl_us;
+ __entry->lock_us = lock_us;
+ ),
+
+ TP_printk("dev=%s, size=%llu, placement=0x%x, caching=%u, asid=%u, ioctl_us=%llu, lock_us=%llu",
+ __get_str(dev), __entry->size, __entry->placement,
+ __entry->caching, __entry->asid, __entry->ioctl_us,
+ __entry->lock_us)
+);
+
DECLARE_EVENT_CLASS(xe_vma,
TP_PROTO(struct xe_vma *vma),
TP_ARGS(vma),
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 25/36] drm/xe: Add IOVA-based xe_res_cursor variant
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
` (23 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 26/36] drm/xe: Don't DMA map tt pages after device unplug Matthew Brost
` (13 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Introduce xe_res_first_iova() to walk a buffer that was DMA mapped using
the IOVA-based DMA API (dma_iova_try_alloc() and friends). Such a mapping
is described by a struct dma_iova_state and is a single contiguous IOVA
range, so the cursor walks it as one segment.
Add an is_iova flag to struct xe_res_cursor to distinguish this case.
When set, xe_res_dma() returns the IOVA backing the current position
(state->addr + cursor offset), xe_res_next() advances within the single
contiguous segment, and xe_res_is_vram() returns false since IOVA
mappings never point to same-device VRAM.
The flag is explicitly cleared in the existing xe_res_first(),
xe_res_first_sg() and xe_res_first_dma() initializers so stale stack
values cannot leak into the new path.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/xe/xe_res_cursor.h | 52 +++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_res_cursor.h b/drivers/gpu/drm/xe/xe_res_cursor.h
index c3a037e5f34e..b3ff92b4d837 100644
--- a/drivers/gpu/drm/xe/xe_res_cursor.h
+++ b/drivers/gpu/drm/xe/xe_res_cursor.h
@@ -24,6 +24,7 @@
#ifndef _XE_RES_CURSOR_H_
#define _XE_RES_CURSOR_H_
+#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <drm/drm_pagemap.h>
@@ -67,6 +68,12 @@ struct xe_res_cursor {
u64 dma_start;
/** @dma_seg_size: Size of the current DMA segment. */
u64 dma_seg_size;
+ /**
+ * @is_iova: Whether the cursor walks a single contiguous IOVA
+ * mapping described by a struct dma_iova_state. When true, the
+ * DMA address is @dma_start + @start and never points to VRAM.
+ */
+ bool is_iova;
};
static struct gpu_buddy *xe_res_get_buddy(struct ttm_resource *res)
@@ -93,6 +100,7 @@ static inline void xe_res_first(struct ttm_resource *res,
{
cur->sgl = NULL;
cur->dma_addr = NULL;
+ cur->is_iova = false;
if (!res)
goto fallback;
@@ -224,6 +232,7 @@ static inline void xe_res_first_sg(const struct sg_table *sg,
cur->dma_addr = NULL;
cur->sgl = sg->sgl;
cur->mem_type = XE_PL_TT;
+ cur->is_iova = false;
__xe_res_sg_next(cur);
}
@@ -256,6 +265,40 @@ static inline void xe_res_first_dma(const struct drm_pagemap_addr *dma_addr,
__xe_res_dma_next(cur);
cur->sgl = NULL;
cur->mem_type = XE_PL_TT;
+ cur->is_iova = false;
+}
+
+/**
+ * xe_res_first_iova() - initialize a xe_res_cursor with a dma_iova_state
+ *
+ * @state: struct dma_iova_state describing a single contiguous IOVA mapping
+ * @start: Start of the range
+ * @size: Size of the range
+ * @cur: cursor object to initialize
+ *
+ * Start walking over the range of an allocation that was DMA mapped using the
+ * IOVA-based DMA API (see dma_iova_try_alloc()). Such a mapping is a single
+ * contiguous IOVA range, so the cursor walks it as one segment. Subsequent
+ * calls to xe_res_next() advance within that range and xe_res_dma() returns
+ * the IOVA backing the current position. xe_res_is_vram() always returns false
+ * for such a cursor.
+ */
+static inline void xe_res_first_iova(struct dma_iova_state *state,
+ u64 start, u64 size,
+ struct xe_res_cursor *cur)
+{
+ XE_WARN_ON(!state);
+ XE_WARN_ON(start + size > dma_iova_size(state));
+
+ cur->node = NULL;
+ cur->start = start;
+ cur->remaining = size;
+ cur->size = size;
+ cur->dma_addr = NULL;
+ cur->sgl = NULL;
+ cur->dma_start = state->addr;
+ cur->mem_type = XE_PL_TT;
+ cur->is_iova = true;
}
/**
@@ -284,6 +327,10 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size)
return;
}
+ /* IOVA cursors are a single segment, fully consumed by the above. */
+ if (XE_WARN_ON(cur->is_iova))
+ return;
+
if (cur->dma_addr) {
cur->start += size;
__xe_res_dma_next(cur);
@@ -335,7 +382,7 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size)
*/
static inline u64 xe_res_dma(const struct xe_res_cursor *cur)
{
- if (cur->dma_addr)
+ if (cur->is_iova || cur->dma_addr)
return cur->dma_start + cur->start;
else if (cur->sgl)
return sg_dma_address(cur->sgl) + cur->start;
@@ -352,6 +399,9 @@ static inline u64 xe_res_dma(const struct xe_res_cursor *cur)
*/
static inline bool xe_res_is_vram(const struct xe_res_cursor *cur)
{
+ if (cur->is_iova)
+ return false;
+
if (cur->dma_addr)
return cur->dma_addr->proto == XE_INTERCONNECT_VRAM;
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 26/36] drm/xe: Don't DMA map tt pages after device unplug
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
` (24 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:52 ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 27/36] drm/xe/display: Flush cleanup work on unregister Matthew Brost
` (12 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel; +Cc: Thomas Hellström, Matthew Auld, stable
xe_bo_pci_dev_remove_all() drops all DMA mappings on device removal:
non-exported bos are purged and exported dma-bufs are moved out to
system. However, nothing prevents an exported dma-buf from being moved
back to TT afterwards, e.g. via DMA_BUF_IOCTL_SYNC ->
xe_dma_buf_begin_cpu_access() -> xe_bo_migrate(bo, XE_PL_TT), which
re-establishes a DMA mapping for a device that is going away. Once the
pci device has been removed from its IOMMU group, unmapping that tt on
dma-buf release dereferences a NULL iommu group.
Refuse to DMA map tt pages once the device is unplugged. drm_dev_unplug()
completes before xe_bo_pci_dev_remove_all() evicts bos under their dma-resv
lock and the map runs under the same lock, so a mapping created before
the unplug is evicted, and any later map attempt sees the unplugged
device. begin_cpu_access() already ignores migration failures, leaving
CPU access in the system placement.
Fixes: 3cbb651117ff ("drm/xe/bo: Add a bo remove callback")
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: stable@vger.kernel.org # v6.16+
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 41092e2810b4..8ff92b2c9176 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -499,6 +499,16 @@ static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
if (xe_tt->sg)
return 0;
+ /*
+ * Once the device is unplugged, xe_bo_pci_dev_remove_all() has dropped
+ * (or is about to drop, under each bo's lock) all DMA mappings. Don't
+ * create new ones, e.g. when an exported dma-buf moved out to system
+ * is migrated back to TT by begin_cpu_access(): such a mapping would
+ * outlive the device's IOMMU group and crash on unmap.
+ */
+ if (drm_dev_is_unplugged(&xe->drm))
+ return -ENODEV;
+
ret = sg_alloc_table_from_pages_segment(&xe_tt->sgt, tt->pages,
num_pages, 0,
(u64)num_pages << PAGE_SHIFT,
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 27/36] drm/xe/display: Flush cleanup work on unregister
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
` (25 preceding siblings ...)
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:33 ` Matthew Brost
2026-12-02 23:58 ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 28/36] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned() Matthew Brost
` (11 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Thomas Hellström, Matthew Auld, Jani Nikula, stable
xe_device_remove() calls xe_display_unregister() and then
xe_bo_pci_dev_remove_all(), which drops all DMA mappings by evicting
every bo. Framebuffers pinned for scanout via ttm_bo_pin() are on the
unevictable list and are not on the xe pinned lists, so they rely on
drm_atomic_helper_shutdown() in intel_display_driver_unregister() to be
unpinned first.
However, the shutdown commit unpins the old plane state from the
asynchronous cleanup work (intel_atomic_cleanup_work()), which is not
flushed until intel_display_driver_remove() runs from a devm action,
after xe_device_remove(). A scanout bo can therefore still be pinned
when xe_bo_pci_dev_remove_all() runs and keep its DMA mapping past
device removal. Unmapping it on final release, after the pci device has
left its IOMMU group, dereferences a NULL iommu group.
Flush the cleanup work in xe_display_unregister() so all framebuffers are
unpinned before the bos are evicted.
Fixes: 3cbb651117ff ("drm/xe/bo: Add a bo remove callback")
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: stable@vger.kernel.org # v6.16+
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/display/xe_display.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c
index b1a6008bf15c..68d29d78dc8b 100644
--- a/drivers/gpu/drm/xe/display/xe_display.c
+++ b/drivers/gpu/drm/xe/display/xe_display.c
@@ -155,6 +155,14 @@ void xe_display_unregister(struct xe_device *xe)
intel_display_driver_runtime_pm_disable(display);
intel_display_driver_unregister(display);
+
+ /*
+ * The shutdown commit unpins the framebuffers from the asynchronous
+ * cleanup work. Flush it so they are unpinned, and thus visible to
+ * the eviction in xe_bo_pci_dev_remove_all(), before the device
+ * is removed.
+ */
+ intel_display_flush_cleanup_work(display);
}
void xe_display_shutdown(struct xe_device *xe)
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 28/36] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned()
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
` (26 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 27/36] drm/xe/display: Flush cleanup work on unregister Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
` (10 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel; +Cc: Thomas Hellström, Matthew Auld, stable
xe_bo_apply_to_pinned() drops xe->pinned.lock before invoking the
callback with only a bo reference held. Unlike the other pinned
callbacks, xe_bo_dma_unmap_pinned() does not take the bo's dma-resv lock,
so on device removal it can race with an importer unpinning an exported
bo (xe_bo_unpin_external()) followed by an eviction that unmaps the same
tt, resulting in a double DMA unmap and sg table free. The imported-bo
branch also calls dma_buf_unmap_sgt(), which asserts that the dma-resv
lock is held.
Take the bo lock around the unmap.
Fixes: 3cbb651117ff ("drm/xe/bo: Add a bo remove callback")
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: stable@vger.kernel.org # v6.16+
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 8ff92b2c9176..878a1b0e7dac 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -2585,8 +2585,15 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
int xe_bo_dma_unmap_pinned(struct xe_bo *bo)
{
struct ttm_buffer_object *ttm_bo = &bo->ttm;
- struct ttm_tt *tt = ttm_bo->ttm;
+ struct ttm_tt *tt;
+ /*
+ * The caller only holds a reference: without the lock, a concurrent
+ * unpin followed by eviction or destruction may unmap, or free, the
+ * same tt.
+ */
+ xe_bo_lock(bo, false);
+ tt = ttm_bo->ttm;
if (tt) {
struct xe_ttm_tt *xe_tt = container_of(tt, typeof(*xe_tt), ttm);
@@ -2601,6 +2608,7 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo)
&xe_tt->ttm);
}
}
+ xe_bo_unlock(bo);
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs
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
` (27 preceding siblings ...)
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 ` 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
` (9 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Add support for mapping a ttm_tt's pages using the IOVA-based DMA API
(dma_iova_try_alloc()/link()/sync()/unlink()/free()) as an alternative
to the scatter-gather list. An IOVA mapping is a single contiguous DMA
range, which is cheaper to walk and program than an sg list.
Whether the IOVA API can be used depends on the IOMMU mode, so
eligibility is decided once per tt at xe_ttm_tt_create() time and
recorded in struct xe_ttm_tt::iova_eligible. To keep the scope limited,
only device BOs that are neither GGTT-mapped nor pinned
(XE_BO_FLAG_PINNED) are eligible: dma-buf imports manage their own
mapping, GGTT BOs are mostly pinned kernel BOs, and pinned BOs are not
evicted by xe_bo_pci_dev_remove_all(), so their IOVA state could
outlive the device's IOMMU group on hot-unplug.
The IOVA reservation is taken when the tt is DMA mapped and released
when it is unmapped, so it never outlives the device. xe_tt_map() calls
xe_tt_iova_reserve(), which allocates the range with
dma_iova_try_alloc() and sets xe_ttm_tt::use_iova, then
xe_tt_map_iova() links the tt pages (one folio at a time) and syncs the
IOTLB. xe_tt_unmap_iova() destroys both the mapping and the reservation.
If dma_iova_try_alloc() fails, the tt transparently falls back to the sg
list, which remains the default. xe_tt_map()/xe_tt_unmap() dispatch
between the IOVA and sg backends, and xe_bo_dma_unmap_pinned() learns
about the IOVA case.
Consumers that walked the sg list via xe_res_first_sg(xe_bo_sg()),
including xe_ggtt_map_bo(), now go through the new xe_res_first_tt()
helper, which initializes either an IOVA cursor (xe_res_first_iova()) or
an sg cursor depending on the tt's mapping mode.
v4:
- Shuffle around dma_iova_try_iova/link/sync/unlink/free to be unplug
safe (Auld)
v5:
- Reword commit message (Sashiko)
- Rebase on 3 unrelated fixes flagged by Sashiko
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/tests/xe_migrate.c | 6 +-
drivers/gpu/drm/xe/xe_bo.c | 343 ++++++++++++++++++++++++--
drivers/gpu/drm/xe/xe_bo.h | 18 +-
drivers/gpu/drm/xe/xe_ggtt.c | 2 +-
drivers/gpu/drm/xe/xe_migrate.c | 14 +-
drivers/gpu/drm/xe/xe_pt.c | 2 +-
6 files changed, 333 insertions(+), 52 deletions(-)
diff --git a/drivers/gpu/drm/xe/tests/xe_migrate.c b/drivers/gpu/drm/xe/tests/xe_migrate.c
index eba991e28af0..045629c6d6da 100644
--- a/drivers/gpu/drm/xe/tests/xe_migrate.c
+++ b/drivers/gpu/drm/xe/tests/xe_migrate.c
@@ -255,7 +255,7 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test,
if (xe_bo_is_vram(pt))
xe_res_first(pt->ttm.resource, 0, xe_bo_size(pt), &src_it);
else
- xe_res_first_sg(xe_bo_sg(pt), 0, xe_bo_size(pt), &src_it);
+ xe_res_first_tt(pt->ttm.ttm, 0, xe_bo_size(pt), &src_it);
emit_pte(m, bb, NUM_KERNEL_PDE - 1, xe_bo_is_vram(pt), false,
&src_it, XE_PAGE_SIZE, pt->ttm.resource);
@@ -387,12 +387,12 @@ static struct dma_fence *blt_copy(struct xe_tile *tile,
bool dst_is_vram = mem_type_is_vram(dst->mem_type);
if (!src_is_vram)
- xe_res_first_sg(xe_bo_sg(src_bo), 0, size, &src_it);
+ xe_res_first_tt(src_bo->ttm.ttm, 0, size, &src_it);
else
xe_res_first(src, 0, size, &src_it);
if (!dst_is_vram)
- xe_res_first_sg(xe_bo_sg(dst_bo), 0, size, &dst_it);
+ xe_res_first_tt(dst_bo->ttm.ttm, 0, size, &dst_it);
else
xe_res_first(dst, 0, size, &dst_it);
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 878a1b0e7dac..e2a725c790d8 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -6,6 +6,8 @@
#include "xe_bo.h"
#include <linux/dma-buf.h>
+#include <linux/dma-mapping.h>
+#include <linux/iommu-dma.h>
#include <linux/nodemask.h>
#include <linux/nospec.h>
@@ -17,6 +19,7 @@
#include <drm/ttm/ttm_backup.h>
#include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_placement.h>
+#include <drm/ttm/ttm_pool.h>
#include <drm/ttm/ttm_tt.h>
#include <uapi/drm/xe_drm.h>
@@ -439,6 +442,40 @@ struct xe_ttm_tt {
struct ttm_tt ttm;
struct sg_table sgt;
struct sg_table *sg;
+ /**
+ * @iova: IOVA state describing the single contiguous IOVA mapping of
+ * the tt pages. Only valid when @use_iova is true.
+ */
+ struct dma_iova_state iova;
+ /**
+ * @iova_eligible: Whether this tt may use the IOVA-based DMA API
+ * instead of a scatter-gather list. A policy decision taken once at tt
+ * creation time and stable for the lifetime of the tt.
+ */
+ bool iova_eligible;
+ /**
+ * @use_iova: Whether this tt currently holds an IOVA reservation and
+ * is therefore DMA mapped using the IOVA-based DMA API instead of a
+ * scatter-gather list. The reservation is taken when the tt is DMA
+ * mapped and released when it is unmapped, so that it never outlives
+ * the device's IOMMU domain (see xe_bo_pci_dev_remove_all()).
+ */
+ bool use_iova;
+ /**
+ * @iova_linked: Whether the tt pages are currently linked into the
+ * IOVA mapping. Only meaningful when @use_iova is true.
+ */
+ bool iova_linked;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+ /**
+ * @iova_dma_pages: Per-order count of DMA-mapped pages this tt
+ * accounted into xe->mem.dma_mapped_pages[] for its IOVA mapping,
+ * recorded at link time so the unlink can apply an exactly matching
+ * decrement without re-walking tt->pages (which TTM may mutate, e.g.
+ * during defrag). Counter ownership stays isolated in xe_bo.c.
+ */
+ unsigned long iova_dma_pages[NR_PAGE_ORDERS];
+#endif
/** @purgeable: Whether the content of the pages of @ttm is purgeable. */
bool purgeable;
};
@@ -487,6 +524,52 @@ static void xe_tt_account_dma_pages(struct xe_device *xe,
}
#endif
+/*
+ * xe_tt_account_iova_add - account one freshly linked IOVA folio
+ * @xe: the xe device
+ * @xe_tt: the xe_ttm_tt being mapped
+ * @order: page order of the linked folio
+ *
+ * Add the folio's 2^order pages to xe->mem.dma_mapped_pages[order] and record
+ * the same amount in @xe_tt so xe_tt_unaccount_iova() can later subtract an
+ * exactly matching count without re-walking tt->pages.
+ */
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static void xe_tt_account_iova_add(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt, unsigned int order)
+{
+ unsigned long chunk = 1UL << order;
+
+ xe_tt->iova_dma_pages[order] += chunk;
+ atomic_long_add(chunk, &xe->mem.dma_mapped_pages[order]);
+}
+
+static void xe_tt_unaccount_iova(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt)
+{
+ unsigned int order;
+
+ for (order = 0; order < NR_PAGE_ORDERS; order++) {
+ unsigned long pages = xe_tt->iova_dma_pages[order];
+
+ if (pages) {
+ atomic_long_sub(pages, &xe->mem.dma_mapped_pages[order]);
+ xe_tt->iova_dma_pages[order] = 0;
+ }
+ }
+}
+#else
+static void xe_tt_account_iova_add(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt, unsigned int order)
+{
+}
+
+static void xe_tt_unaccount_iova(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt)
+{
+}
+#endif
+
static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
{
struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
@@ -499,16 +582,6 @@ static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
if (xe_tt->sg)
return 0;
- /*
- * Once the device is unplugged, xe_bo_pci_dev_remove_all() has dropped
- * (or is about to drop, under each bo's lock) all DMA mappings. Don't
- * create new ones, e.g. when an exported dma-buf moved out to system
- * is migrated back to TT by begin_cpu_access(): such a mapping would
- * outlive the device's IOMMU group and crash on unmap.
- */
- if (drm_dev_is_unplugged(&xe->drm))
- return -ENODEV;
-
ret = sg_alloc_table_from_pages_segment(&xe_tt->sgt, tt->pages,
num_pages, 0,
(u64)num_pages << PAGE_SHIFT,
@@ -543,28 +616,207 @@ static void xe_tt_unmap_sg(struct xe_device *xe, struct ttm_tt *tt)
}
}
-struct sg_table *xe_bo_sg(struct xe_bo *bo)
+/*
+ * xe_tt_iova_reserve - Reserve the IOVA range backing a tt's DMA mapping.
+ *
+ * The reservation is taken when the tt is DMA mapped rather than when it is
+ * created, so that it is always released by xe_tt_unmap_iova() while the
+ * device's IOMMU domain is still alive. A tt whose reservation outlived
+ * pci device removal would hit a NULL iommu group in dma_iova_free().
+ *
+ * Return: true if @xe_tt holds a reservation on return, false if the caller
+ * should fall back to the scatter-gather path.
+ */
+static bool xe_tt_iova_reserve(struct xe_device *xe, struct ttm_tt *tt)
{
- 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;
+ if (xe_tt->use_iova)
+ return true;
+
+ if (!xe_tt->iova_eligible)
+ return false;
+
+ if (!dma_iova_try_alloc(xe->drm.dev, &xe_tt->iova, 0,
+ (size_t)tt->num_pages << PAGE_SHIFT))
+ return false;
+
+ xe_tt->use_iova = true;
+ return true;
+}
+
+/*
+ * xe_tt_map_iova - DMA map a tt using the IOVA-based DMA API.
+ *
+ * Link all of the tt's pages into the IOVA range reserved by
+ * xe_tt_iova_reserve(), one folio at a time, and sync the IOTLB once at the
+ * end.
+ */
+static int xe_tt_map_iova(struct xe_device *xe, struct ttm_tt *tt)
+{
+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
+ struct device *dev = xe->drm.dev;
+ unsigned long num_pages = tt->num_pages;
+ unsigned long i = 0;
+ size_t mapped = 0;
+ int ret;
+
+ if (xe_tt->iova_linked)
+ return 0;
+
+ while (i < num_pages) {
+ struct page *page = tt->pages[i];
+ unsigned int order = ttm_pool_page_order_nodma(page);
+ size_t len = PAGE_SIZE << order;
+
+ ret = dma_iova_link(dev, &xe_tt->iova, page_to_phys(page),
+ mapped, len, DMA_BIDIRECTIONAL,
+ DMA_ATTR_SKIP_CPU_SYNC);
+ if (ret)
+ goto err_unlink;
+
+ xe_tt_account_iova_add(xe, xe_tt, order);
+ mapped += len;
+ i += 1UL << order;
+ }
+
+ ret = dma_iova_sync(dev, &xe_tt->iova, 0, mapped);
+ if (ret)
+ goto err_unlink;
+
+ xe_tt->iova_linked = true;
+ return 0;
+
+err_unlink:
+ if (mapped) {
+ dma_iova_unlink(dev, &xe_tt->iova, 0, mapped,
+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
+ xe_tt_unaccount_iova(xe, xe_tt);
+ }
+ /*
+ * Drop the reservation as well: a failed map leaves no DMA mapping
+ * behind, and the reservation must not outlive the device's IOMMU
+ * domain on a teardown path that never calls xe_tt_unmap().
+ */
+ dma_iova_free(dev, &xe_tt->iova);
+ xe_tt->use_iova = false;
+ return ret;
+}
+
+/*
+ * xe_tt_unmap_iova - Unlink a tt's pages and release its IOVA reservation.
+ *
+ * Both the mapping and the reservation are torn down here so that no IOMMU
+ * state survives beyond the tt's DMA mapping. The eviction performed by
+ * xe_bo_pci_dev_remove_all() therefore drains every reservation while the
+ * device is still bound to its IOMMU domain.
+ */
+static void xe_tt_unmap_iova(struct xe_device *xe, struct ttm_tt *tt)
+{
+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
+
+ if (!xe_tt->use_iova)
+ return;
+
+ if (xe_tt->iova_linked) {
+ /*
+ * Unmap with attrs 0 (matching the sg unmap path) so that the
+ * CPU copy-back sync is performed for non-coherent or bounced
+ * (SWIOTLB) mappings, even though the link was done with
+ * DMA_ATTR_SKIP_CPU_SYNC.
+ */
+ dma_iova_destroy(xe->drm.dev, &xe_tt->iova,
+ dma_iova_size(&xe_tt->iova),
+ DMA_BIDIRECTIONAL, 0);
+ xe_tt_unaccount_iova(xe, xe_tt);
+ xe_tt->iova_linked = false;
+ } else {
+ dma_iova_free(xe->drm.dev, &xe_tt->iova);
+ }
+
+ xe_tt->use_iova = false;
+}
+
+/*
+ * xe_tt_map - DMA map a tt, using IOVA when available and sg otherwise.
+ */
+static int xe_tt_map(struct xe_device *xe, struct ttm_tt *tt)
+{
+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
+
+ /*
+ * Once the device is unplugged, xe_bo_pci_dev_remove_all() has dropped
+ * (or is about to drop, under each bo's lock) all DMA mappings. Don't
+ * create new ones, e.g. when an exported dma-buf moved out to system
+ * is migrated back to TT by begin_cpu_access(): such a mapping would
+ * outlive the device's IOMMU group and crash on unmap.
+ */
+ if (drm_dev_is_unplugged(&xe->drm))
+ return -ENODEV;
+
+ /*
+ * An already sg-mapped tt keeps its sg mapping: taking an IOVA
+ * reservation here would establish a second, redundant mapping.
+ */
+ if (!xe_tt->sg && xe_tt_iova_reserve(xe, tt))
+ return xe_tt_map_iova(xe, tt);
+
+ return xe_tt_map_sg(xe, tt);
+}
+
+/*
+ * xe_tt_unmap - Undo xe_tt_map().
+ */
+static void xe_tt_unmap(struct xe_device *xe, struct ttm_tt *tt)
+{
+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
+
+ if (xe_tt->use_iova)
+ xe_tt_unmap_iova(xe, tt);
+ else
+ xe_tt_unmap_sg(xe, tt);
}
/**
- * xe_tt_sg() - Return the DMA scatter-gather table backing a ttm_tt.
- * @tt: The ttm_tt to query.
+ * xe_res_first_tt() - Initialize a resource cursor over a ttm_tt's DMA mapping.
+ * @tt: The ttm_tt to walk.
+ * @start: Start of the range, in bytes.
+ * @size: Size of the range, in bytes.
+ * @cur: The cursor to initialize.
*
- * Like xe_bo_sg(), but takes the ttm_tt directly. Used by the defrag copy
- * path which needs the old (source) tt's sg table without a backing xe_bo.
+ * Initialize @cur to walk the DMA addresses backing @tt, transparently
+ * handling both the IOVA-based mapping (single contiguous range) and the
+ * scatter-gather list fallback.
+ */
+void xe_res_first_tt(struct ttm_tt *tt, u64 start, u64 size,
+ struct xe_res_cursor *cur)
+{
+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
+
+ if (xe_tt->use_iova)
+ xe_res_first_iova(&xe_tt->iova, start, size, cur);
+ else
+ xe_res_first_sg(xe_tt->sg, start, size, cur);
+}
+
+/**
+ * xe_bo_sg_is_contiguous() - Check if a BO's DMA address space is contiguous.
+ * @bo: the BO to check (must have a valid tt mapping, i.e. !xe_bo_is_vram())
+ * @len: required contiguous length in bytes
*
- * Return: The sg table, or NULL if the tt is not currently mapped.
+ * Returns true if the first @len bytes of the BO are mapped to a contiguous
+ * DMA address range. An IOVA-mapped tt is a single contiguous range by
+ * construction, so only the sg fallback has to be walked.
*/
-struct sg_table *xe_tt_sg(struct ttm_tt *tt)
+bool xe_bo_sg_is_contiguous(struct xe_bo *bo, size_t len)
{
+ 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;
+ if (xe_tt->use_iova)
+ return xe_tt->iova_linked && xe_bo_size(bo) >= len;
+
+ return drm_prime_get_contiguous_size(xe_tt->sg) >= len;
}
/*
@@ -779,6 +1031,30 @@ static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object *ttm_bo,
}
}
+ /*
+ * Eligible BOs are DMA mapped using the IOVA-based DMA API, which
+ * yields a single contiguous IOVA range instead of a scatter-gather
+ * list. Only evictable device BOs that are not GGTT-mapped qualify:
+ * dma-buf imports manage their own mapping and GGTT bindings are
+ * programmed directly from the sg list.
+ *
+ * Pinned BOs are excluded because they are invisible to the eviction
+ * done by xe_bo_pci_dev_remove_all(): a BO pinned in XE_PL_TT (e.g. a
+ * page table on integrated) keeps its mapping until the BO is
+ * destroyed, which may happen long after the pci device was removed
+ * (an open drm file outliving a hot-unplug). Releasing IOVA state at
+ * that point would dereference a NULL iommu group.
+ *
+ * The IOVA range itself is reserved when the tt is DMA mapped and
+ * released when it is unmapped, so it never outlives the device;
+ * dma_iova_try_alloc() may still fail there, in which case we
+ * transparently fall back to the sg list.
+ */
+ xe_tt->iova_eligible = ttm_bo->type != ttm_bo_type_sg &&
+ !(bo->flags & (XE_BO_FLAG_GGTT | XE_BO_FLAG_GGTT_ALL |
+ XE_BO_FLAG_PINNED)) &&
+ use_dma_iommu(xe->drm.dev);
+
return tt;
}
@@ -827,7 +1103,7 @@ static void xe_ttm_tt_unpopulate(struct ttm_device *ttm_dev, struct ttm_tt *tt)
!(tt->page_flags & TTM_TT_FLAG_EXTERNAL_MAPPABLE))
return;
- xe_tt_unmap_sg(xe, tt);
+ xe_tt_unmap(xe, tt);
ttm_pool_free(&ttm_dev->pool, tt);
xe_ttm_tt_account_subtract(xe, tt);
@@ -836,6 +1112,19 @@ static void xe_ttm_tt_unpopulate(struct ttm_device *ttm_dev, struct ttm_tt *tt)
static void xe_ttm_tt_destroy(struct ttm_device *ttm_dev, struct ttm_tt *tt)
{
+ struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
+ struct xe_device *xe = ttm_to_xe_device(ttm_dev);
+
+ /*
+ * No IOVA state may survive until here: a tt can be destroyed long
+ * after the pci device was removed (e.g. an open drm file outliving a
+ * hot-unplug), at which point the device has no IOMMU domain left and
+ * any dma_iova_*() call would dereference a NULL iommu group. The
+ * reservation is instead released by xe_tt_unmap_iova().
+ */
+ xe_assert(xe, !xe_tt->use_iova);
+ xe_assert(xe, !xe_tt->iova_linked);
+
ttm_tt_fini(tt);
kfree(tt);
}
@@ -1827,7 +2116,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
/* Bo creation path, moving to system or TT. */
if ((!old_mem && ttm) && !handle_system_ccs) {
if (new_mem->mem_type == XE_PL_TT)
- ret = xe_tt_map_sg(xe, ttm);
+ ret = xe_tt_map(xe, ttm);
if (!ret)
ttm_bo_move_null(ttm_bo, new_mem);
goto out;
@@ -1857,7 +2146,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
(!ttm && ttm_bo->type == ttm_bo_type_device);
if (new_mem->mem_type == XE_PL_TT) {
- ret = xe_tt_map_sg(xe, ttm);
+ ret = xe_tt_map(xe, ttm);
if (ret)
goto out;
}
@@ -2047,7 +2336,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
if (IS_VF_CCS_READY(xe))
xe_sriov_vf_ccs_detach_bo(bo);
- xe_tt_unmap_sg(xe, ttm_bo->ttm);
+ xe_tt_unmap(xe, ttm_bo->ttm);
}
/*
@@ -2168,7 +2457,7 @@ static long xe_bo_shrink_purge(struct ttm_operation_ctx *ctx,
if (lret)
return lret;
- xe_tt_unmap_sg(xe, bo->ttm);
+ xe_tt_unmap(xe, bo->ttm);
ttm_bo_move_null(bo, new_resource);
}
@@ -2603,6 +2892,8 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo)
DMA_BIDIRECTIONAL);
ttm_bo->sg = NULL;
xe_tt->sg = NULL;
+ } else if (xe_tt->use_iova) {
+ xe_tt_unmap_iova(ttm_to_xe_device(ttm_bo->bdev), tt);
} else if (xe_tt->sg) {
xe_tt_unmap_sg(ttm_to_xe_device(ttm_bo->bdev),
&xe_tt->ttm);
@@ -4327,7 +4618,7 @@ dma_addr_t __xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size)
if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) {
xe_assert(xe, bo->ttm.ttm);
- xe_res_first_sg(xe_bo_sg(bo), page << PAGE_SHIFT,
+ xe_res_first_tt(bo->ttm.ttm, page << PAGE_SHIFT,
page_size, &cur);
return xe_res_dma(&cur) + offset;
} else {
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 48298a372e70..871d1aa1425c 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -573,21 +573,11 @@ void xe_bo_dev_init(struct xe_bo_dev *bo_device);
void xe_bo_dev_fini(struct xe_bo_dev *bo_device);
-struct sg_table *xe_bo_sg(struct xe_bo *bo);
-struct sg_table *xe_tt_sg(struct ttm_tt *tt);
+struct xe_res_cursor;
+void xe_res_first_tt(struct ttm_tt *tt, u64 start, u64 size,
+ struct xe_res_cursor *cur);
-/**
- * xe_bo_sg_is_contiguous() - Check if a BO's DMA address space is contiguous.
- * @bo: the BO to check (must have a valid sg table, i.e. !xe_bo_is_vram())
- * @len: required contiguous length in bytes
- *
- * Returns true if the first @len bytes of the BO are mapped to a contiguous
- * DMA address range.
- */
-static inline bool xe_bo_sg_is_contiguous(struct xe_bo *bo, size_t len)
-{
- return drm_prime_get_contiguous_size(xe_bo_sg(bo)) >= len;
-}
+bool xe_bo_sg_is_contiguous(struct xe_bo *bo, size_t len);
/*
* xe_sg_segment_size() - Provides upper limit for sg segment size.
diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index 86fc3d186fc8..53fcd26d3f8b 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -919,7 +919,7 @@ static void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node,
if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) {
xe_assert(xe_bo_device(bo), bo->ttm.ttm);
- for (xe_res_first_sg(xe_bo_sg(bo), 0, xe_bo_size(bo), &cur);
+ for (xe_res_first_tt(bo->ttm.ttm, 0, xe_bo_size(bo), &cur);
cur.remaining; xe_res_next(&cur, XE_PAGE_SIZE))
ggtt->pt_ops->ggtt_set_pte(ggtt, end - cur.remaining,
pte | xe_res_dma(&cur));
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 5b40405aaba9..03f14e4ed9fa 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -1451,16 +1451,16 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
return ERR_PTR(-EINVAL);
if (!src_is_vram && src->mem_type != XE_PL_STOLEN)
- xe_res_first_sg(src_tt ? xe_tt_sg(src_tt) : xe_bo_sg(src_bo), 0, size, &src_it);
+ xe_res_first_tt(src_tt ? src_tt : src_bo->ttm.ttm, 0, size, &src_it);
else
xe_res_first(src, 0, size, &src_it);
if (!dst_is_vram && dst->mem_type != XE_PL_STOLEN)
- xe_res_first_sg(xe_bo_sg(dst_bo), 0, size, &dst_it);
+ xe_res_first_tt(dst_bo->ttm.ttm, 0, size, &dst_it);
else
xe_res_first(dst, 0, size, &dst_it);
if (copy_system_ccs)
- xe_res_first_sg(src_tt ? xe_tt_sg(src_tt) : xe_bo_sg(src_bo),
+ xe_res_first_tt(src_tt ? src_tt : src_bo->ttm.ttm,
xe_bo_ccs_pages_start(src_bo),
PAGE_ALIGN(xe_device_ccs_bytes(xe, size)),
&ccs_it);
@@ -1830,9 +1830,9 @@ int xe_migrate_ccs_rw_copy(struct xe_tile *tile, struct xe_exec_queue *q,
ctx = &xe->sriov.vf.ccs.contexts[read_write];
- xe_res_first_sg(xe_bo_sg(src_bo), 0, size, &src_it);
+ xe_res_first_tt(src_bo->ttm.ttm, 0, size, &src_it);
- xe_res_first_sg(xe_bo_sg(src_bo), xe_bo_ccs_pages_start(src_bo),
+ xe_res_first_tt(src_bo->ttm.ttm, xe_bo_ccs_pages_start(src_bo),
PAGE_ALIGN(xe_device_ccs_bytes(xe, size)),
&ccs_it);
@@ -2039,7 +2039,7 @@ struct dma_fence *xe_migrate_vram_copy_chunk(struct xe_bo *vram_bo, u64 vram_off
xe_assert(xe, !range_overflows(sysmem_offset, size, (u64)sysmem_bo->ttm.base.size));
xe_res_first(vram, vram_offset, size, &vram_it);
- xe_res_first_sg(xe_bo_sg(sysmem_bo), sysmem_offset, size, &sysmem_it);
+ xe_res_first_tt(sysmem_bo->ttm.ttm, sysmem_offset, size, &sysmem_it);
while (size) {
u32 pte_flags = PTE_UPDATE_FLAG_IS_VRAM;
@@ -2250,7 +2250,7 @@ struct dma_fence *xe_migrate_clear(struct xe_migrate *m,
clear_only_system_ccs = true;
if (!clear_vram && dst->mem_type != XE_PL_STOLEN)
- xe_res_first_sg(xe_bo_sg(bo), 0, xe_bo_size(bo), &src_it);
+ xe_res_first_tt(bo->ttm.ttm, 0, xe_bo_size(bo), &src_it);
else
xe_res_first(src, 0, xe_bo_size(bo), &src_it);
diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
index 0e0bf428df0f..42b3fb544861 100644
--- a/drivers/gpu/drm/xe/xe_pt.c
+++ b/drivers/gpu/drm/xe/xe_pt.c
@@ -887,7 +887,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
xe_vma_size(vma), &curs);
else
- xe_res_first_sg(xe_bo_sg(bo), xe_vma_bo_offset(vma),
+ xe_res_first_tt(bo->ttm.ttm, xe_vma_bo_offset(vma),
xe_vma_size(vma), &curs);
} else if (!range) {
curs.size = xe_vma_size(vma);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 30/36] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize
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
` (28 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 31/36] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
` (8 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
A future patch performs the destination DMA mapping of a defrag move in
two stages when the BO is IOVA mapped: a temporary contiguous mapping of
just that changed pages used for the GPU copy, followed by a post-copy
finalize step that tears that mapping down and links the new backing
into the (transferred) IOVA reservation. The finalize step must run only
after the GPU copy it depends on has completed, so it is dispatched as
an xe_dep_job.
Add a per-device xe_dep_scheduler dedicated to these finalize jobs,
created in xe_bo_defrag_init() (after the migrate contexts are up) and
torn down in xe_bo_defrag_fini(). No users yet; the job itself is added
in a later patch.
v4:
-Gate dep scheduler creation on use_dma_iommu (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 19 +++++++++++++++++++
drivers/gpu/drm/xe/xe_device_types.h | 10 ++++++++++
2 files changed, 29 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index e2a725c790d8..55253071950c 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -28,6 +28,7 @@
#include <trace/events/gpu_mem.h>
#include "xe_device.h"
+#include "xe_dep_scheduler.h"
#include "xe_dma_buf.h"
#include "xe_drm_client.h"
#include "xe_ggtt.h"
@@ -1546,6 +1547,10 @@ static void xe_bo_defrag_fini(void *arg)
struct xe_device *xe = arg;
disable_delayed_work_sync(&xe->mem.defrag.worker);
+ if (xe->mem.defrag.iova_sched) {
+ xe_dep_scheduler_fini(xe->mem.defrag.iova_sched);
+ xe->mem.defrag.iova_sched = NULL;
+ }
}
/**
@@ -1585,6 +1590,20 @@ int xe_bo_defrag_init_early(struct xe_device *xe)
*/
int xe_bo_defrag_init(struct xe_device *xe)
{
+
+ if (use_dma_iommu(xe->drm.dev)) {
+ struct xe_dep_scheduler *iova_sched;
+
+#define XE_BO_MAX_IOVA_DEFRAG_JOBS 16 /* Picking a reasonable value */
+ iova_sched = xe_dep_scheduler_create(xe, NULL, "xe_iova_defrag",
+ XE_BO_MAX_IOVA_DEFRAG_JOBS);
+#undef XE_BO_MAX_IOVA_DEFRAG_JOBS
+ if (IS_ERR(iova_sched))
+ return PTR_ERR(iova_sched);
+
+ xe->mem.defrag.iova_sched = iova_sched;
+ }
+
return devm_add_action_or_reset(xe->drm.dev, xe_bo_defrag_fini, xe);
}
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index f64f19c85c71..423a868d4605 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -42,6 +42,7 @@
struct drm_pagemap_shrinker;
struct intel_display;
+struct xe_dep_scheduler;
struct intel_dg_nvm_dev;
struct xe_cpu_bind;
struct xe_ggtt;
@@ -354,6 +355,15 @@ struct xe_device {
* not be queued. Protected by @mem.defrag.lock.
*/
bool suspended;
+ /**
+ * @mem.defrag.iova_sched: Dependency scheduler used to
+ * run the post-copy IOVA finalize job for defrag moves
+ * of IOVA-mapped BOs. The job tears down the temporary
+ * copy-step IOVA mapping and links the new backing into
+ * the (transferred) reservation once the GPU copy that
+ * its dependencies gate has completed.
+ */
+ struct xe_dep_scheduler *iova_sched;
} defrag;
} mem;
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 31/36] drm/xe: Add packed copy-step IOVA mapping for defrag
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
` (29 preceding siblings ...)
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 ` 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
` (7 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström,
Niranjana Vishwanathapura
Add machinery to map only changed pages during defrag when the
destination TT is IOVA-mapped. Only the non-borrowed (freshly
allocated) pages need copying; borrowed pages are aliases from
the old TT.
Add xe_tt_iova_copy_init() to diff new vs old TT folios and
record changed-page runs. Add xe_tt_map_iova_copy() to link
those changed pages packed contiguously at the front of the
new TT's IOVA reservation, synced and ready for GPU blits.
No users yet; wired up in later patches.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 371 +++++++++++++++++++++++++++++++++++++
1 file changed, 371 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 55253071950c..9f216a7d115e 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -559,6 +559,31 @@ static void xe_tt_unaccount_iova(struct xe_device *xe,
}
}
}
+
+/*
+ * xe_tt_account_iova_pages - account a tt's pages from a full folio walk
+ * @xe: the xe device
+ * @xe_tt: the xe_ttm_tt to account (its @iova_dma_pages must start zeroed)
+ *
+ * Walk @xe_tt's pages one folio at a time (the same head-page order walk used
+ * by xe_tt_map_iova()) and account each into xe->mem.dma_mapped_pages[] and
+ * @xe_tt->iova_dma_pages[]. Used to (re)derive accounting that exactly matches
+ * the pages a tt is actually mapped with.
+ */
+__maybe_unused
+static void xe_tt_account_iova_pages(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt)
+{
+ struct ttm_tt *tt = &xe_tt->ttm;
+ unsigned long i = 0;
+
+ while (i < tt->num_pages) {
+ unsigned int order = ttm_pool_page_order_nodma(tt->pages[i]);
+
+ xe_tt_account_iova_add(xe, xe_tt, order);
+ i += 1UL << order;
+ }
+}
#else
static void xe_tt_account_iova_add(struct xe_device *xe,
struct xe_ttm_tt *xe_tt, unsigned int order)
@@ -569,6 +594,12 @@ static void xe_tt_unaccount_iova(struct xe_device *xe,
struct xe_ttm_tt *xe_tt)
{
}
+
+__maybe_unused
+static void xe_tt_account_iova_pages(struct xe_device *xe,
+ struct xe_ttm_tt *xe_tt)
+{
+}
#endif
static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
@@ -820,6 +851,346 @@ bool xe_bo_sg_is_contiguous(struct xe_bo *bo, size_t len)
return drm_prime_get_contiguous_size(xe_tt->sg) >= len;
}
+/**
+ * struct xe_tt_iova_run - A contiguous run of changed pages in a defrag move
+ * @start: First page offset (natural ttm_tt index) of the run.
+ * @count: Number of pages in the run.
+ *
+ * Runs are folio aligned: defrag borrows whole beneficial-order chunks, so a
+ * folio is either entirely borrowed (unchanged) or entirely freshly allocated
+ * (changed), never split across the boundary.
+ */
+struct xe_tt_iova_run {
+ pgoff_t start;
+ pgoff_t count;
+};
+
+/**
+ * struct xe_tt_iova_link - A snapshot folio link descriptor for defrag relink
+ * @phys: Physical address of the folio's head page.
+ * @offset: Natural byte offset into the reservation to link the folio at.
+ * @len: Byte length of the folio (PAGE_SIZE << order).
+ *
+ * Captured at copy-init time while the destination tt's page array is valid and
+ * stable under the BO lock. The post-copy finalize job runs asynchronously,
+ * after TTM may have mutated (or torn down) the destination tt page array, so
+ * it relinks purely from these snapshots and never dereferences that array.
+ */
+struct xe_tt_iova_link {
+ phys_addr_t phys;
+ size_t offset;
+ size_t len;
+};
+
+/**
+ * struct xe_tt_iova_copy - Changed-page subset of an IOVA defrag move
+ * @runs: Array of changed-page runs, in ascending natural tt offset.
+ * @nr_runs: Number of entries in @runs.
+ * @links: Per-folio link snapshots covering the changed runs, in ascending
+ * natural offset. Drives the asynchronous finalize relink so it never
+ * touches the destination tt's (possibly mutated) page array.
+ * @nr_links: Number of entries in @links.
+ * @nr_changed: Total number of changed pages (sum of the run counts). This is
+ * also the size, in pages, of the packed copy-step IOVA mapping
+ * produced by xe_tt_map_iova_copy().
+ */
+struct xe_tt_iova_copy {
+ struct xe_tt_iova_run *runs;
+ unsigned int nr_runs;
+ struct xe_tt_iova_link *links;
+ unsigned int nr_links;
+ pgoff_t nr_changed;
+};
+
+/*
+ * xe_tt_iova_walk_changed - Walk a defrag move's changed-page runs.
+ *
+ * Iterate @new_tt one folio at a time (folio order read from TTM via
+ * ttm_pool_page_order_nodma()) and compare each folio's head page against
+ * @old_tt at the same natural offset. Pages the new backing borrowed from the
+ * old tt alias the same struct page and are unchanged; freshly allocated pages
+ * differ. Coalesce contiguous changed folios into runs and, for each run,
+ * invoke @fn. Returns the total number of changed pages.
+ */
+__maybe_unused
+static pgoff_t xe_tt_iova_walk_changed(struct ttm_tt *new_tt,
+ struct ttm_tt *old_tt,
+ void (*fn)(pgoff_t start, pgoff_t count,
+ void *arg),
+ void *arg)
+{
+ pgoff_t i = 0, n = new_tt->num_pages;
+ pgoff_t run_start = 0, nr_changed = 0;
+ bool in_run = false;
+
+ while (i < n) {
+ unsigned int order = ttm_pool_page_order_nodma(new_tt->pages[i]);
+ pgoff_t nr = 1UL << order;
+ bool changed = new_tt->pages[i] != old_tt->pages[i];
+
+ if (changed) {
+ if (!in_run) {
+ run_start = i;
+ in_run = true;
+ }
+ nr_changed += nr;
+ } else if (in_run) {
+ if (fn)
+ fn(run_start, i - run_start, arg);
+ in_run = false;
+ }
+
+ i += nr;
+ }
+
+ if (in_run && fn)
+ fn(run_start, n - run_start, arg);
+
+ return nr_changed;
+}
+
+struct xe_tt_iova_run_collect {
+ struct ttm_tt *new_tt;
+ struct xe_tt_iova_run *runs;
+ unsigned int nr_runs;
+ unsigned int runs_cap;
+ struct xe_tt_iova_link *links;
+ unsigned int nr_links;
+ unsigned int links_cap;
+ int err;
+};
+
+/* Geometrically grow @arr (element size @elem) to hold at least @need slots. */
+__maybe_unused
+static int xe_tt_iova_grow(void **arr, unsigned int *cap, unsigned int need,
+ size_t elem)
+{
+ unsigned int new_cap;
+ void *p;
+
+ if (need <= *cap)
+ return 0;
+
+ new_cap = *cap ? *cap * 2 : 64;
+ if (new_cap < need)
+ new_cap = need;
+
+ p = krealloc_array(*arr, new_cap, elem, GFP_KERNEL);
+ if (!p)
+ return -ENOMEM;
+
+ *arr = p;
+ *cap = new_cap;
+ return 0;
+}
+
+__maybe_unused
+static void xe_tt_iova_store_run(pgoff_t start, pgoff_t count, void *arg)
+{
+ struct xe_tt_iova_run_collect *c = arg;
+ pgoff_t i = start, end = start + count;
+
+ if (c->err)
+ return;
+
+ if (xe_tt_iova_grow((void **)&c->runs, &c->runs_cap, c->nr_runs + 1,
+ sizeof(*c->runs))) {
+ c->err = -ENOMEM;
+ return;
+ }
+ c->runs[c->nr_runs].start = start;
+ c->runs[c->nr_runs].count = count;
+ c->nr_runs++;
+
+ while (i < end) {
+ struct page *page = c->new_tt->pages[i];
+ unsigned int order = ttm_pool_page_order_nodma(page);
+
+ if (xe_tt_iova_grow((void **)&c->links, &c->links_cap,
+ c->nr_links + 1, sizeof(*c->links))) {
+ c->err = -ENOMEM;
+ return;
+ }
+ c->links[c->nr_links].phys = page_to_phys(page);
+ c->links[c->nr_links].offset = (size_t)i << PAGE_SHIFT;
+ c->links[c->nr_links].len = PAGE_SIZE << order;
+ c->nr_links++;
+
+ i += 1UL << order;
+ }
+}
+
+/**
+ * xe_tt_iova_copy_init() - Compute the changed-page subset of a defrag move
+ * @new_tt: The freshly (re)allocated destination tt.
+ * @old_tt: The stashed source tt (bo->defrag_old_tt).
+ * @copy: Output description of the changed pages.
+ *
+ * Diff @new_tt against @old_tt and record the runs of changed (non-borrowed)
+ * pages into @copy, along with a per-folio snapshot of their physical
+ * addresses, natural offsets and lengths. The result drives both the packed
+ * copy-step IOVA mapping (xe_tt_map_iova_copy()) and the post-copy finalize
+ * that relinks the new backing into the IOVA reservation. The finalize runs
+ * asynchronously, after TTM may have mutated @new_tt->pages, so it consumes the
+ * snapshot rather than re-reading the page array. @new_tt and @old_tt must
+ * describe the same BO (equal num_pages) and both be populated.
+ *
+ * The caller owns @copy and must release it with xe_tt_iova_copy_fini().
+ *
+ * Return: 0 on success, -ENOMEM on allocation failure.
+ */
+__maybe_unused
+static int xe_tt_iova_copy_init(struct ttm_tt *new_tt, struct ttm_tt *old_tt,
+ struct xe_tt_iova_copy *copy)
+{
+ struct xe_tt_iova_run_collect c = { .new_tt = new_tt };
+
+ memset(copy, 0, sizeof(*copy));
+
+ /*
+ * Single pass: collect the changed runs and per-folio link snapshots
+ * directly, growing the arrays on demand. Changed runs are few (the
+ * borrowed majority is skipped), so the geometric reallocs are rare and
+ * this avoids a second full O(num_pages) walk just to size the arrays.
+ */
+ copy->nr_changed = xe_tt_iova_walk_changed(new_tt, old_tt,
+ xe_tt_iova_store_run, &c);
+ if (c.err) {
+ kfree(c.runs);
+ kfree(c.links);
+ return c.err;
+ }
+ if (!c.nr_runs)
+ return 0;
+
+ copy->runs = c.runs;
+ copy->nr_runs = c.nr_runs;
+ copy->links = c.links;
+ copy->nr_links = c.nr_links;
+
+ return 0;
+}
+
+/**
+ * xe_tt_iova_copy_fini() - Release a struct xe_tt_iova_copy
+ * @copy: The copy description to release.
+ */
+__maybe_unused
+static void xe_tt_iova_copy_fini(struct xe_tt_iova_copy *copy)
+{
+ kfree(copy->runs);
+ kfree(copy->links);
+ copy->runs = NULL;
+ copy->links = NULL;
+ copy->nr_runs = 0;
+ copy->nr_links = 0;
+ copy->nr_changed = 0;
+}
+
+/**
+ * xe_tt_map_iova_copy() - DMA map the changed-page subset for a defrag copy
+ * @xe: The xe device.
+ * @new_tt: The destination tt (must be IOVA eligible and not yet reserved).
+ * @copy: The changed-page description from xe_tt_iova_copy_init().
+ *
+ * Reserve an IOVA range for @new_tt and link only its changed pages into it,
+ * packed contiguously at the front of the range ([0, @copy->nr_changed)
+ * pages). This provides a compact, contiguous destination for the GPU defrag
+ * copy without mapping the (majority) borrowed pages, and lets the whole
+ * temporary mapping later be torn down with a single dma_iova_destroy().
+ *
+ * The reservation's remaining tail is left unlinked. This does not establish
+ * the tt's final mapping (@iova_linked stays false); the post-copy finalize is
+ * responsible for that.
+ *
+ * Return: 0 on success, negative error code on failure (any partial linkage is
+ * unwound).
+ */
+__maybe_unused
+static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt,
+ const struct xe_tt_iova_copy *copy)
+{
+ struct xe_ttm_tt *xe_tt = container_of(new_tt, struct xe_ttm_tt, ttm);
+ struct device *dev = xe->drm.dev;
+ size_t mapped = 0;
+ unsigned int r;
+ int ret;
+
+ xe_assert(xe, xe_tt->iova_eligible);
+ xe_assert(xe, !xe_tt->use_iova);
+ xe_assert(xe, !xe_tt->iova_linked);
+
+ if (!xe_tt_iova_reserve(xe, new_tt))
+ return -ENOMEM;
+
+ for (r = 0; r < copy->nr_runs; r++) {
+ pgoff_t i = copy->runs[r].start;
+ pgoff_t end = i + copy->runs[r].count;
+
+ while (i < end) {
+ struct page *page = new_tt->pages[i];
+ unsigned int order = ttm_pool_page_order_nodma(page);
+ size_t len = PAGE_SIZE << order;
+
+ ret = dma_iova_link(dev, &xe_tt->iova,
+ page_to_phys(page), mapped, len,
+ DMA_BIDIRECTIONAL,
+ DMA_ATTR_SKIP_CPU_SYNC);
+ if (ret)
+ goto err_unlink;
+
+ mapped += len;
+ i += 1UL << order;
+ }
+ }
+
+ ret = dma_iova_sync(dev, &xe_tt->iova, 0, mapped);
+ if (ret)
+ goto err_unlink;
+
+ return 0;
+
+err_unlink:
+ if (mapped)
+ dma_iova_unlink(dev, &xe_tt->iova, 0, mapped,
+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
+ dma_iova_free(dev, &xe_tt->iova);
+ xe_tt->use_iova = false;
+ return ret;
+}
+
+/*
+ * xe_tt_iova_transfer - Transfer a full IOVA reservation old_tt -> new_tt.
+ *
+ * Move the (fully linked) IOVA reservation from the old tt to the new tt,
+ * leaving the old tt without a reservation so its destroy path does not double
+ * free. The new tt keeps its existing reservation snapshotted in the finalize
+ * job for teardown. Called at the defrag finalize job's point of no failure.
+ *
+ * Also rebalance the per-order DMA-page accounting: drop the old tt's
+ * accounting and account the pages the new tt actually ends up mapped with.
+ * The finalize relink leaves the new tt's mapping equal to new_tt->pages
+ * (borrowed pages alias the old tt; changed runs use the new pages, which may
+ * have a different order distribution), so deriving the accounting from a full
+ * folio walk of the new tt keeps xe->mem.dma_mapped_pages[] exact while the new
+ * mapping lives, rather than carrying the old tt's stale distribution.
+ */
+__maybe_unused
+static void xe_tt_iova_transfer(struct xe_device *xe,
+ struct xe_ttm_tt *new_tt,
+ struct xe_ttm_tt *old_tt)
+{
+ new_tt->iova = old_tt->iova;
+ new_tt->use_iova = true;
+ new_tt->iova_linked = true;
+
+ xe_tt_unaccount_iova(xe, old_tt);
+ xe_tt_account_iova_pages(xe, new_tt);
+
+ old_tt->iova_linked = false;
+ old_tt->use_iova = false;
+}
+
/*
* Account ttm pages against the device shrinker's shrinkable and
* purgeable counts.
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 32/36] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies
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
` (30 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 33/36] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
` (6 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
A defrag move with IOVA enabled only DMA-maps the changed (non-borrowed)
pages of the new tt, packed contiguously into the front of its IOVA
reservation (xe_tt_map_iova_copy()). The GPU copy therefore has an
asymmetric geometry: the source is read from the old tt at its natural
page offsets (via the old tt's full IOVA), while the destination only
exposes the changed pages, packed.
Teach __xe_migrate_copy() about this packed-destination mode:
- Add a @dst_packed_pages argument. When non-zero the destination tt
cursor walks just that many packed pages and the source (not the
destination) drives the chunk size, so the smaller packed prefix never
clamps the source walk.
- Size the destination PTE update for each chunk from the changed-page
count (xe_migrate_count_changed_pages()) rather than the full chunk.
Leading borrowed pages of each chunk are skipped up front
(xe_migrate_leading_borrowed_pages()) so every emitted chunk starts
on a changed page and has a non-empty packed destination.
- 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, and with a
@ccs flag so the same runs can be emitted as indirect -> indirect CCS
aux copies.
Expose this via xe_migrate_copy_defrag_iova(). When the BO has flat-CCS
state a second pass migrates the aux state of the changed runs through
their (packed) data mappings with the compression PAT set. The aux
state follows the physical page, and borrowed pages share the same
physical page on both sides, so they are skipped in both passes.
xe_migrate_copy_defrag() becomes a wrapper passing a zero packed page
count, i.e. a fully mapped destination, and remains the path for the
non-IOVA fallback.
No users yet; xe_bo_move() is wired to this path in a later patch.
v4:
- Remove some now dead code (Niranjana)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_migrate.c | 251 ++++++++++++++++++++++++++++----
drivers/gpu/drm/xe/xe_migrate.h | 8 +
2 files changed, 230 insertions(+), 29 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 03f14e4ed9fa..c894cd1f1305 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -1228,6 +1228,64 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb,
emit_xy_fast_copy(gt, bb, src_ofs, dst_ofs, size, pitch);
}
+/*
+ * xe_migrate_count_changed_pages() - Count non-borrowed pages in a defrag chunk.
+ * @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.
+ * @npages: Number of pages in the L0 chunk.
+ *
+ * A defragmentation move may harvest already beneficial-order chunks from the
+ * old tt, so the new tt references (borrows) some of the same physical pages.
+ * Count the pages that actually differ (src page != dst page) within the chunk.
+ *
+ * Return: The number of non-borrowed (changed) pages.
+ */
+static u32 xe_migrate_count_changed_pages(struct ttm_tt *src_tt,
+ struct ttm_tt *dst_tt,
+ pgoff_t start_page, u32 npages)
+{
+ u32 i, nchg = 0;
+
+ for (i = 0; i < npages; i++)
+ if (src_tt->pages[start_page + i] !=
+ dst_tt->pages[start_page + i])
+ nchg++;
+
+ return nchg;
+}
+
+/*
+ * xe_migrate_leading_borrowed_pages() - Count the run of borrowed pages at the
+ * head of the remaining copy.
+ * @src_tt: Source (old) tt providing the page pointers.
+ * @dst_tt: Destination (new) tt providing the page pointers.
+ * @start_page: Page offset of the next page to copy within the tt page arrays.
+ * @max_pages: Pages left to copy.
+ *
+ * A defragmentation move borrows the already beneficial-order chunks from the
+ * old tt, so the new tt references (borrows) the same physical pages for the
+ * unchanged majority of a large object. Those pages alias on both the source
+ * and destination GPU mappings and need no copy. Count how many consecutive
+ * pages starting at @start_page are borrowed so the caller can advance past the
+ * whole run at once instead of rediscovering it one L0 chunk at a time.
+ *
+ * Return: The number of leading borrowed (src page == dst page) pages, capped
+ * at @max_pages.
+ */
+static u32 xe_migrate_leading_borrowed_pages(struct ttm_tt *src_tt,
+ struct ttm_tt *dst_tt,
+ pgoff_t start_page, u32 max_pages)
+{
+ u32 n = 0;
+
+ while (n < max_pages &&
+ src_tt->pages[start_page + n] == dst_tt->pages[start_page + n])
+ n++;
+
+ return n;
+}
+
/*
* emit_copy_chunks() - Emit the data blits for one defrag chunk, skipping
* borrowed pages.
@@ -1239,6 +1297,11 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb,
* @src_tt: Source (old) tt providing the page pointers.
* @dst_tt: Destination (new) tt providing the page pointers.
* @start_page: Page offset of this chunk within the tt page arrays.
+ * @pack_dst: If true the destination only maps the changed pages packed
+ * contiguously, so the destination offset advances by changed-page
+ * runs instead of tracking the source page index.
+ * @ccs: If true emit indirect -> indirect CCS aux copies instead of data
+ * blits. Requires @pack_dst.
*
* A defragmentation move may harvest already beneficial-order chunks from the
* old tt, so the new tt references (borrows) some of the same physical pages.
@@ -1247,16 +1310,27 @@ static void emit_copy(struct xe_gt *gt, struct xe_bb *bb,
* only blit runs of pages that actually differ (src page != dst page),
* coalescing contiguous to-copy pages into a single blit.
*
- * Return: The number of blits emitted (or that would be emitted when @bb is
+ * When @pack_dst is set the source pages are read from their natural offsets
+ * (@src_ofs + page index) while the destination pages were packed into a
+ * contiguous prefix, so the destination offset is a running counter that only
+ * advances for emitted (changed) runs.
+ *
+ * When @ccs is set the same runs are used 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 as well.
+ *
+ * Return: The number of copies emitted (or that would be emitted when @bb is
* NULL).
*/
static u32 emit_copy_chunks(struct xe_gt *gt, struct xe_bb *bb,
u64 src_ofs, u64 dst_ofs, u32 src_bytes,
struct ttm_tt *src_tt, struct ttm_tt *dst_tt,
- pgoff_t start_page)
+ pgoff_t start_page, bool pack_dst, bool ccs)
{
u32 npages = src_bytes >> PAGE_SHIFT;
- u32 i = 0, nblits = 0;
+ u32 i = 0, pack = 0, nblits = 0;
while (i < npages) {
u32 run = 0;
@@ -1274,11 +1348,18 @@ static u32 emit_copy_chunks(struct xe_gt *gt, struct xe_bb *bb,
dst_tt->pages[start_page + i + run])
run++;
- if (bb)
+ if (bb && ccs)
+ emit_copy_ccs(gt, bb,
+ dst_ofs + (u64)pack * PAGE_SIZE, true,
+ src_ofs + (u64)i * PAGE_SIZE, true,
+ run * PAGE_SIZE);
+ else 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;
}
@@ -1387,6 +1468,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
struct ttm_resource *src,
struct ttm_resource *dst,
struct ttm_tt *src_tt,
+ pgoff_t dst_packed_pages,
enum xe_migrate_copy_mode mode,
bool intr)
{
@@ -1424,6 +1506,23 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
*/
struct ttm_tt *dst_tt = dst_bo->ttm.ttm;
bool skip_borrowed = defrag_copy;
+ /*
+ * Defrag-IOVA copy: the destination tt only maps the changed
+ * (non-borrowed) pages, packed contiguously into the first
+ * @dst_packed_pages pages of its IOVA. The source is read from the old
+ * tt at natural offsets and each changed run is blitted into the packed
+ * destination prefix.
+ */
+ bool pack_dst = dst_packed_pages != 0;
+ /*
+ * Packed defrag CCS pass: migrate the flat-CCS aux state of the changed
+ * pages only, from the source at its natural offset to the destination
+ * packed prefix. Borrowed pages share the physical page (and thus its
+ * aux) on both sides, so they are skipped exactly like the data pass.
+ */
+ bool ccs_pack = defrag_ccs && pack_dst;
+ /* Per-run, borrowed-skipping defrag emission (data or packed CCS). */
+ bool defrag_runs = skip_borrowed || ccs_pack;
/*
* For decompression operation, always use the compression PAT index.
@@ -1455,7 +1554,9 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
else
xe_res_first(src, 0, size, &src_it);
if (!dst_is_vram && dst->mem_type != XE_PL_STOLEN)
- xe_res_first_tt(dst_bo->ttm.ttm, 0, size, &dst_it);
+ xe_res_first_tt(dst_bo->ttm.ttm, 0,
+ pack_dst ? (u64)dst_packed_pages << PAGE_SHIFT :
+ size, &dst_it);
else
xe_res_first(dst, 0, size, &dst_it);
@@ -1476,29 +1577,84 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
u32 pte_flags;
pgoff_t start_page = (xe_bo_size(src_bo) - size) >> PAGE_SHIFT;
u32 ndata_blits = 1;
+ u32 nchg = 0;
+ u64 dst_size;
bool usm = xe->info.has_usm;
u32 avail_pts = max_mem_transfer_per_pass(xe) / LEVEL0_PAGE_TABLE_ENCODE_SIZE;
+ /*
+ * Defrag fast-forward: the new (destination) tt borrows the
+ * unchanged beneficial-order chunks from the old tt, so for a
+ * large object the bulk of the copy is borrowed pages that alias
+ * the same memory on both sides. Skip the entire leading
+ * borrowed run in a single cursor stride rather than discovering
+ * it one (8 MB) L0 chunk at a time - each such pass would
+ * otherwise pay xe_migrate_res_sizes() + pte_update_size() + a
+ * full chunk walk only to copy nothing. The non-vram tt cursors
+ * are normally advanced by emit_pte(); replicate that with
+ * xe_res_next(). In pack_dst mode the destination only maps the
+ * changed pages, so its cursor must not advance for borrowed
+ * pages.
+ */
+ if (defrag_runs) {
+ u32 brun = xe_migrate_leading_borrowed_pages(src_tt,
+ dst_tt,
+ start_page,
+ size >> PAGE_SHIFT);
+
+ if (brun) {
+ u64 brun_bytes = (u64)brun << PAGE_SHIFT;
+
+ xe_res_next(&src_it, brun_bytes);
+ if (!pack_dst)
+ xe_res_next(&dst_it, brun_bytes);
+ size -= brun_bytes;
+ continue;
+ }
+ }
+
src_L0 = xe_migrate_res_sizes(m, &src_it);
dst_L0 = xe_migrate_res_sizes(m, &dst_it);
drm_dbg(&xe->drm, "Pass %u, sizes: %llu & %llu\n",
pass++, src_L0, dst_L0);
- src_L0 = min(src_L0, dst_L0);
+ /*
+ * In pack_dst mode the destination is the (smaller) packed
+ * prefix, so it must not clamp the source chunk size; the
+ * source drives the walk and the destination is sized
+ * independently from the changed-page count below.
+ */
+ if (!pack_dst)
+ src_L0 = min(src_L0, dst_L0);
pte_flags = src_is_vram ? PTE_UPDATE_FLAG_IS_VRAM : 0;
pte_flags |= use_comp_pat ? PTE_UPDATE_FLAG_IS_COMP_PTE : 0;
batch_size += pte_update_size(m, pte_flags, src, &src_it, &src_L0,
&src_L0_ofs, &src_L0_pt, 0, 0,
avail_pts);
+ /*
+ * The source chunk size may have been clamped above, so derive
+ * the packed destination size from the changed-page count of
+ * the final chunk.
+ */
+ if (pack_dst) {
+ nchg = xe_migrate_count_changed_pages(src_tt, dst_tt,
+ start_page,
+ src_L0 >> PAGE_SHIFT);
+ /* Leading borrowed pages were skipped above. */
+ xe_assert(xe, nchg);
+ dst_size = (u64)nchg << PAGE_SHIFT;
+ } else {
+ dst_size = src_L0;
+ }
if (copy_only_ccs) {
dst_L0_ofs = src_L0_ofs;
} else {
pte_flags = dst_is_vram ? PTE_UPDATE_FLAG_IS_VRAM : 0;
batch_size += pte_update_size(m, pte_flags, dst,
- &dst_it, &src_L0,
+ &dst_it, &dst_size,
&dst_L0_ofs, &dst_L0_pt,
0, avail_pts, avail_pts);
}
@@ -1518,26 +1674,18 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
* is split into one command per run of non-borrowed pages, so
* size for the number of runs actually needed.
*/
- if (skip_borrowed)
+ if (defrag_runs) {
ndata_blits = emit_copy_chunks(gt, NULL, 0, 0, src_L0,
- src_tt, dst_tt, start_page);
-
- /*
- * If every page in this chunk was borrowed there is nothing to
- * copy: don't build a batch or issue any GPU commands, just
- * advance the cursors past the chunk. The non-vram tt cursors
- * would otherwise be advanced by emit_pte().
- */
- if (skip_borrowed && !ndata_blits) {
- xe_res_next(&src_it, src_L0);
- xe_res_next(&dst_it, src_L0);
- size -= src_L0;
- continue;
+ src_tt, dst_tt, start_page,
+ pack_dst, false);
+ /* Leading borrowed pages were skipped above. */
+ xe_assert(xe, ndata_blits);
}
batch_size += ((copy_only_ccs || defrag_ccs) ? 0 :
ndata_blits * emit_copy_cmd_len(xe)) +
- ((needs_ccs_emit ? EMIT_COPY_CCS_DW : 0));
+ (ccs_pack ? ndata_blits * EMIT_COPY_CCS_DW :
+ (needs_ccs_emit ? EMIT_COPY_CCS_DW : 0));
bb = __xe_bb_new(gt, batch_size, usm, !fence && intr);
if (IS_ERR(bb)) {
@@ -1557,7 +1705,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
else if (!copy_only_ccs)
emit_pte(m, bb, dst_L0_pt, dst_is_vram,
copy_system_ccs || defrag_ccs,
- &dst_it, src_L0, dst);
+ &dst_it, dst_size, dst);
if (copy_system_ccs)
emit_pte(m, bb, ccs_pt, false, false, &ccs_it, ccs_size, src);
@@ -1567,16 +1715,23 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
if (skip_borrowed)
emit_copy_chunks(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0,
- src_tt, dst_tt, start_page);
+ src_tt, dst_tt, start_page, pack_dst,
+ false);
else if (!copy_only_ccs && !defrag_ccs)
emit_copy(gt, bb, src_L0_ofs, dst_L0_ofs, src_L0, XE_PAGE_SIZE);
- if (needs_ccs_emit)
+ if (ccs_pack) {
+ if (emit_copy_chunks(gt, bb, src_L0_ofs, dst_L0_ofs,
+ src_L0, src_tt, dst_tt,
+ start_page, true, true))
+ flush_flags = MI_FLUSH_DW_CCS;
+ } else if (needs_ccs_emit) {
flush_flags = xe_migrate_ccs_copy(m, bb, src_L0_ofs,
IS_DGFX(xe) ? src_is_vram : src_is_pltt,
dst_L0_ofs,
IS_DGFX(xe) ? dst_is_vram : dst_is_pltt,
src_L0, ccs_ofs, copy_ccs);
+ }
job = xe_bb_create_migration_job(m->q, bb,
xe_migrate_batch_base(m, usm),
@@ -1664,7 +1819,7 @@ struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
bool copy_only_ccs,
bool intr)
{
- return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, NULL,
+ return __xe_migrate_copy(m, src_bo, dst_bo, src, dst, NULL, 0,
copy_only_ccs ? XE_MIGRATE_COPY_CCS_ONLY :
XE_MIGRATE_COPY_NORMAL, intr);
}
@@ -1712,15 +1867,53 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m,
struct ttm_resource *dst,
struct ttm_tt *src_tt,
bool need_ccs)
+{
+ return xe_migrate_copy_defrag_iova(m, bo, src, dst, src_tt, 0,
+ need_ccs);
+}
+
+/**
+ * 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(), or 0 if the destination is fully
+ * mapped (see xe_migrate_copy_defrag()).
+ * @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,
+ __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);
@@ -1744,7 +1937,7 @@ struct dma_fence *xe_migrate_resolve(struct xe_migrate *m,
struct xe_bo *bo,
struct ttm_resource *res)
{
- return __xe_migrate_copy(m, bo, bo, res, res, NULL,
+ return __xe_migrate_copy(m, bo, bo, res, res, NULL, 0,
XE_MIGRATE_COPY_VRAM_RESOLVE, true);
}
diff --git a/drivers/gpu/drm/xe/xe_migrate.h b/drivers/gpu/drm/xe/xe_migrate.h
index c410652641f5..3a9e9276e699 100644
--- a/drivers/gpu/drm/xe/xe_migrate.h
+++ b/drivers/gpu/drm/xe/xe_migrate.h
@@ -68,6 +68,14 @@ struct dma_fence *xe_migrate_copy_defrag(struct xe_migrate *m,
struct ttm_tt *src_tt,
bool need_ccs);
+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 *xe_migrate_resolve(struct xe_migrate *m,
struct xe_bo *bo,
struct ttm_resource *res);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 33/36] drm/xe: Finalize defrag-IOVA moves with post-copy job
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
` (31 preceding siblings ...)
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 ` 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
` (5 subsequent siblings)
38 siblings, 1 reply; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, linux-kernel, Thomas Hellström
Wire up end-to-end defrag for IOVA-mapped BOs. A defrag move
is eligible whenever the destination TT is IOVA mapped. The
packed-copy step moves only changed pages; the IOVA reservation
is transferred to the new backing so device-visible addresses
are preserved, avoiding GPU rebind overhead.
Add xe_bo_defrag_use_iova() to select the IOVA defrag path.
Add xe_bo_defrag_iova_copy() to drive the move: diff new vs
stashed old TT, link changed pages packed, blit them, then
queue a post-copy finalize job.
The finalize job tears down the temporary packed mapping,
transfers the full old TT reservation to the new one, and
relinks the copied pages at natural offsets.
Borrowed pages skip the copy and simply adopt the old
reservation.
Since reservation transfer preserves device-visible addresses,
xe_bo_trigger_rebind() skips drm_gpuvm_bo_evict() marking for
dma-fence mode VMs; GPU PTEs stay valid, and exec already waits
on the kernel fences of all external BOs.
Preempt-fence mode VMs are still marked evicted. For an external
BO the move's kernel fence lands in the BO's own dma-resv, and
only the rebind chains it into the VM's dma-resv, which is what
the preempt rebind worker and xe_vm_add_compute_exec_queue()
wait on. Defrag targets 3D (dma-fence mode) workloads, so the
needless rebind of compute VMs is accepted rather than teaching
the preempt paths to wait on external BO kernel fences.
v5:
- Assert of move always happens (Sashiko)
- All call drm_gpuvm_bo_evict a preempt VMs (Sashiko)
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 340 +++++++++++++++++++++++++++++++++++--
1 file changed, 326 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 9f216a7d115e..65ab974c56ac 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -16,6 +16,7 @@
#include <drm/drm_gem_ttm_helper.h>
#include <drm/drm_managed.h>
#include <drm/drm_print.h>
+#include <drm/gpu_scheduler.h>
#include <drm/ttm/ttm_backup.h>
#include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_placement.h>
@@ -28,6 +29,7 @@
#include <trace/events/gpu_mem.h>
#include "xe_device.h"
+#include "xe_dep_job_types.h"
#include "xe_dep_scheduler.h"
#include "xe_dma_buf.h"
#include "xe_drm_client.h"
@@ -570,7 +572,6 @@ static void xe_tt_unaccount_iova(struct xe_device *xe,
* @xe_tt->iova_dma_pages[]. Used to (re)derive accounting that exactly matches
* the pages a tt is actually mapped with.
*/
-__maybe_unused
static void xe_tt_account_iova_pages(struct xe_device *xe,
struct xe_ttm_tt *xe_tt)
{
@@ -595,7 +596,6 @@ static void xe_tt_unaccount_iova(struct xe_device *xe,
{
}
-__maybe_unused
static void xe_tt_account_iova_pages(struct xe_device *xe,
struct xe_ttm_tt *xe_tt)
{
@@ -912,7 +912,6 @@ struct xe_tt_iova_copy {
* differ. Coalesce contiguous changed folios into runs and, for each run,
* invoke @fn. Returns the total number of changed pages.
*/
-__maybe_unused
static pgoff_t xe_tt_iova_walk_changed(struct ttm_tt *new_tt,
struct ttm_tt *old_tt,
void (*fn)(pgoff_t start, pgoff_t count,
@@ -961,7 +960,6 @@ struct xe_tt_iova_run_collect {
};
/* Geometrically grow @arr (element size @elem) to hold at least @need slots. */
-__maybe_unused
static int xe_tt_iova_grow(void **arr, unsigned int *cap, unsigned int need,
size_t elem)
{
@@ -984,7 +982,6 @@ static int xe_tt_iova_grow(void **arr, unsigned int *cap, unsigned int need,
return 0;
}
-__maybe_unused
static void xe_tt_iova_store_run(pgoff_t start, pgoff_t count, void *arg)
{
struct xe_tt_iova_run_collect *c = arg;
@@ -1039,7 +1036,6 @@ static void xe_tt_iova_store_run(pgoff_t start, pgoff_t count, void *arg)
*
* Return: 0 on success, -ENOMEM on allocation failure.
*/
-__maybe_unused
static int xe_tt_iova_copy_init(struct ttm_tt *new_tt, struct ttm_tt *old_tt,
struct xe_tt_iova_copy *copy)
{
@@ -1075,7 +1071,6 @@ static int xe_tt_iova_copy_init(struct ttm_tt *new_tt, struct ttm_tt *old_tt,
* xe_tt_iova_copy_fini() - Release a struct xe_tt_iova_copy
* @copy: The copy description to release.
*/
-__maybe_unused
static void xe_tt_iova_copy_fini(struct xe_tt_iova_copy *copy)
{
kfree(copy->runs);
@@ -1106,7 +1101,6 @@ static void xe_tt_iova_copy_fini(struct xe_tt_iova_copy *copy)
* Return: 0 on success, negative error code on failure (any partial linkage is
* unwound).
*/
-__maybe_unused
static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt,
const struct xe_tt_iova_copy *copy)
{
@@ -1159,6 +1153,130 @@ static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt,
return ret;
}
+/**
+ * struct xe_iova_defrag_job - Post-copy finalize job for an IOVA defrag move.
+ *
+ * After the GPU defrag copy into the packed copy-step mapping completes, this
+ * dependency job runs the CPU-side IOMMU fixups at the point of no failure:
+ * tear down the temporary packed mapping, then per changed run unlink the old
+ * pages and link the new pages into the (transferred) reservation at their
+ * natural offset.
+ */
+struct xe_iova_defrag_job {
+ /** @dep: base generic dependency Xe job. */
+ struct xe_dep_job dep;
+ /** @xe: The xe device. */
+ struct xe_device *xe;
+ /** @new_tt: The destination tt being finalized (owns the reservation). */
+ struct ttm_tt *new_tt;
+ /**
+ * @copy_iova: Snapshot of the new tt's temporary IOVA reservation that
+ * held the packed copy-step mapping. Destroyed by the job (the new tt
+ * itself adopts the old tt's reservation at job creation).
+ */
+ struct dma_iova_state copy_iova;
+ /** @copy_bytes: Byte length of the packed copy-step mapping. */
+ size_t copy_bytes;
+ /** @copy: Changed-page description; the job owns and frees @copy.runs. */
+ struct xe_tt_iova_copy copy;
+};
+
+static struct dma_fence *xe_iova_defrag_job_run(struct xe_dep_job *dep_job)
+{
+ struct xe_iova_defrag_job *job =
+ container_of(dep_job, typeof(*job), dep);
+ struct xe_device *xe = job->xe;
+ struct device *dev = xe->drm.dev;
+ struct xe_ttm_tt *xe_tt =
+ container_of(job->new_tt, struct xe_ttm_tt, ttm);
+ unsigned int r, l;
+
+ /*
+ * Tear down the temporary packed copy-step mapping and free its
+ * reservation. The new tt has already adopted the old tt's full
+ * reservation (transferred at job creation), so this only touches the
+ * snapshot taken before the transfer.
+ *
+ * This mapping was the GPU blit's write destination, so tear it down
+ * with attrs 0 (not DMA_ATTR_SKIP_CPU_SYNC): for non-coherent or
+ * bounced (SWIOTLB) mappings the device->CPU copy-back / cache sync of
+ * the freshly copied data happens during unlink, exactly as
+ * xe_tt_unmap_iova() does. Skipping it would silently drop the
+ * defragmented data on those configs.
+ */
+ dma_iova_destroy(dev, &job->copy_iova, job->copy_bytes,
+ DMA_BIDIRECTIONAL, 0);
+
+ /*
+ * For each changed run, unlink the old pages (still linked from the
+ * adopted reservation).
+ */
+ for (r = 0; r < job->copy.nr_runs; r++) {
+ size_t off = (size_t)job->copy.runs[r].start << PAGE_SHIFT;
+ size_t len = (size_t)job->copy.runs[r].count << PAGE_SHIFT;
+
+ dma_iova_unlink(dev, &xe_tt->iova, off, len,
+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
+ }
+
+ /*
+ * Relink the freshly copied new pages from the snapshot captured at job
+ * creation. The destination tt's page array may have been mutated (or
+ * torn down) by TTM since then, so it is never dereferenced here.
+ * Borrowed pages are shared with the old tt and stay correctly linked
+ * for free, so the snapshot only covers the changed runs.
+ */
+ for (l = 0; l < job->copy.nr_links; l++) {
+ int ret = dma_iova_link(dev, &xe_tt->iova,
+ job->copy.links[l].phys,
+ job->copy.links[l].offset,
+ job->copy.links[l].len,
+ DMA_BIDIRECTIONAL,
+ DMA_ATTR_SKIP_CPU_SYNC);
+ /*
+ * Point of no failure: the data is already copied and the
+ * reservation ownership has been transferred. A relink failure
+ * leaves a hole in the mapping; there is no safe recovery, so
+ * just warn.
+ */
+ drm_WARN_ON(&xe->drm, ret);
+ }
+
+ /* Sync the relinked changed runs into the device's view. */
+ for (r = 0; r < job->copy.nr_runs; r++) {
+ size_t off = (size_t)job->copy.runs[r].start << PAGE_SHIFT;
+ size_t len = (size_t)job->copy.runs[r].count << PAGE_SHIFT;
+
+ /*
+ * Point of no failure (as with the relink above): warn on a
+ * sync error so a stale IOMMU cache does not fail silently.
+ */
+ drm_WARN_ON(&xe->drm, dma_iova_sync(dev, &xe_tt->iova, off, len));
+ }
+
+ /*
+ * All work is synchronous CPU-side IOMMU fixup, so there is no hardware
+ * fence to wait on; returning NULL makes the scheduler signal the job's
+ * finished fence immediately.
+ */
+ return NULL;
+}
+
+static void xe_iova_defrag_job_free(struct xe_dep_job *dep_job)
+{
+ struct xe_iova_defrag_job *job =
+ container_of(dep_job, typeof(*job), dep);
+
+ xe_tt_iova_copy_fini(&job->copy);
+ drm_sched_job_cleanup(&job->dep.drm);
+ kfree(job);
+}
+
+static const struct xe_dep_job_ops xe_iova_defrag_job_ops = {
+ .run_job = xe_iova_defrag_job_run,
+ .free_job = xe_iova_defrag_job_free,
+};
+
/*
* xe_tt_iova_transfer - Transfer a full IOVA reservation old_tt -> new_tt.
*
@@ -1175,7 +1293,6 @@ static int xe_tt_map_iova_copy(struct xe_device *xe, struct ttm_tt *new_tt,
* folio walk of the new tt keeps xe->mem.dma_mapped_pages[] exact while the new
* mapping lives, rather than carrying the old tt's stale distribution.
*/
-__maybe_unused
static void xe_tt_iova_transfer(struct xe_device *xe,
struct xe_ttm_tt *new_tt,
struct xe_ttm_tt *old_tt)
@@ -1191,6 +1308,157 @@ static void xe_tt_iova_transfer(struct xe_device *xe,
old_tt->use_iova = false;
}
+/*
+ * xe_bo_defrag_iova_copy - Run an IOVA defrag move with a packed copy mapping.
+ *
+ * Only the changed (non-borrowed) pages of @new_tt are DMA mapped, packed
+ * contiguously into the front of its reservation, the GPU copy blits them from
+ * the old tt at natural offsets, and a post-copy finalize job adopts the old
+ * tt's full reservation and relinks the changed runs. Returns the finalize
+ * job's finished fence (the fence the move waits on), or an ERR_PTR on failure
+ * with all partial state unwound.
+ */
+static struct dma_fence *
+xe_bo_defrag_iova_copy(struct xe_device *xe, struct xe_migrate *migrate,
+ struct xe_bo *bo, struct ttm_resource *old_mem,
+ struct ttm_resource *new_mem, struct ttm_tt *old_tt,
+ bool handle_system_ccs)
+{
+ struct ttm_tt *new_tt = bo->ttm.ttm;
+ struct xe_ttm_tt *new_xe_tt = container_of(new_tt, struct xe_ttm_tt, ttm);
+ struct xe_ttm_tt *old_xe_tt = container_of(old_tt, struct xe_ttm_tt, ttm);
+ struct drm_sched_entity *entity =
+ xe_dep_scheduler_entity(xe->mem.defrag.iova_sched);
+ struct xe_iova_defrag_job *job;
+ struct dma_fence *copy_fence;
+ struct dma_fence *fence;
+ struct xe_tt_iova_copy copy;
+ int err;
+
+ xe_assert(xe, new_xe_tt->iova_eligible && !new_xe_tt->use_iova);
+ xe_assert(xe, old_xe_tt->use_iova && old_xe_tt->iova_linked);
+
+ err = xe_tt_iova_copy_init(new_tt, old_tt, ©);
+ if (err)
+ return ERR_PTR(err);
+
+ /*
+ * TTM fails a defrag move that (re)allocates no chunk, so at least one
+ * page always differs from the old tt.
+ */
+ if (XE_WARN_ON(!copy.nr_changed)) {
+ err = -EINVAL;
+ goto err_copy;
+ }
+
+ err = xe_tt_map_iova_copy(xe, new_tt, ©);
+ if (err)
+ goto err_copy;
+
+ copy_fence = xe_migrate_copy_defrag_iova(migrate, bo, old_mem, new_mem,
+ old_tt, copy.nr_changed,
+ handle_system_ccs);
+ if (IS_ERR(copy_fence)) {
+ err = PTR_ERR(copy_fence);
+ goto err_unmap;
+ }
+
+ job = kzalloc(sizeof(*job), GFP_KERNEL);
+ if (!job) {
+ err = -ENOMEM;
+ goto err_fence;
+ }
+
+ job->dep.ops = &xe_iova_defrag_job_ops;
+ job->xe = xe;
+ job->new_tt = new_tt;
+ job->copy_iova = new_xe_tt->iova;
+ job->copy_bytes = (size_t)copy.nr_changed << PAGE_SHIFT;
+ job->copy = copy;
+
+ err = drm_sched_job_init(&job->dep.drm, entity, 1, NULL, 0);
+ if (err)
+ goto err_job;
+
+ err = drm_sched_job_add_dependency(&job->dep.drm,
+ dma_fence_get(copy_fence));
+ if (err)
+ goto err_job_init;
+
+ /*
+ * Point of no failure: transfer the old tt's full reservation to the
+ * new tt. The finalize job (already armed below) destroys the packed
+ * copy mapping snapshot and relinks the changed runs.
+ */
+ xe_tt_iova_transfer(xe, new_xe_tt, old_xe_tt);
+ memset(©, 0, sizeof(copy)); /* ownership moved to the job */
+
+ drm_sched_job_arm(&job->dep.drm);
+ fence = dma_fence_get(&job->dep.drm.s_fence->finished);
+ drm_sched_entity_push_job(&job->dep.drm);
+
+ dma_fence_put(copy_fence);
+
+ return fence;
+
+err_job_init:
+ drm_sched_job_cleanup(&job->dep.drm);
+err_job:
+ kfree(job);
+err_fence:
+ /*
+ * The GPU copy into the packed destination mapping was already
+ * submitted; it must finish before we tear that mapping down below,
+ * otherwise the blit would fault or scribble on unmapped IOVA. (Reached
+ * only with a valid, submitted copy_fence; the IS_ERR(copy_fence) case
+ * jumps straight to err_unmap with no GPU work in flight.)
+ */
+ dma_fence_wait(copy_fence, false);
+ dma_fence_put(copy_fence);
+err_unmap:
+ dma_iova_unlink(xe->drm.dev, &new_xe_tt->iova, 0,
+ (size_t)copy.nr_changed << PAGE_SHIFT,
+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC);
+ dma_iova_free(xe->drm.dev, &new_xe_tt->iova);
+ new_xe_tt->use_iova = false;
+err_copy:
+ xe_tt_iova_copy_fini(©);
+ return ERR_PTR(err);
+}
+
+/*
+ * xe_bo_defrag_use_iova - Whether a defrag move should use the packed IOVA path.
+ *
+ * Eligible when the move is a defrag (stashed old tt) and the destination tt is
+ * IOVA mapped. The IOVA reservation is transferred to the new backing, so the
+ * device-visible addresses are preserved and no GPU rebind is needed (see
+ * xe_bo_trigger_rebind()); this makes the path worthwhile regardless of BO
+ * size. A flat-CCS aux pass, if needed, is migrated packed alongside the data
+ * (changed pages only), so it does not disqualify the path. Otherwise the
+ * full-mapping defrag path is used.
+ */
+static bool xe_bo_defrag_use_iova(struct ttm_buffer_object *ttm_bo)
+{
+ struct xe_ttm_tt *xe_tt, *old_xe_tt;
+
+ if (!ttm_bo->defrag_old_tt || !ttm_bo->ttm)
+ return false;
+
+ xe_tt = container_of(ttm_bo->ttm, struct xe_ttm_tt, ttm);
+ old_xe_tt = container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm);
+
+ /*
+ * The old tt must hold a live IOVA mapping (the packed copy reads its
+ * IOVA and the finalize job transfers its reservation to the new tt),
+ * and the new tt must be eligible to take the temporary copy-step
+ * reservation. Eligibility is a deterministic per-device decision taken
+ * at tt creation, so for a given BO the old and new tt always agree;
+ * the explicit old-tt check guards against ever routing a sg-fallback
+ * old tt into xe_tt_iova_transfer() (which would copy an invalid iova).
+ */
+ return xe_tt->iova_eligible && old_xe_tt->use_iova;
+}
+
/*
* Account ttm pages against the device shrinker's shrinkable and
* purgeable counts.
@@ -1577,6 +1845,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
struct drm_gem_object *obj = &bo->ttm.base;
struct drm_gpuvm_bo *vm_bo;
bool idle = false;
+ bool defrag_iova;
int ret = 0;
dma_resv_assert_held(bo->ttm.base.resv);
@@ -1589,18 +1858,48 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
dma_resv_iter_end(&cursor);
}
+ /*
+ * A defrag move that reallocates IOVA-mapped backing preserves the
+ * device-visible addresses: the IOVA reservation is transferred from
+ * the old to the new tt, so the existing GPU PTEs stay valid and the
+ * BO must not be marked evicted (the rebind paths in xe_exec_ioctl()
+ * and preempt_rebind_work_func() would otherwise needlessly rebind).
+ * Preempt fences still need to be triggered, and fault-mode / L2
+ * flush-optimized configs still need a TLB invalidation below, so only
+ * the eviction marking is skipped (except on L2 flush-optimized HW,
+ * where that invalidation zaps the PTEs of a dma-resv VM).
+ *
+ * Preempt-fence mode VMs are still marked evicted: for an external BO
+ * the move's kernel fence lands in the BO's own dma-resv, which only
+ * the rebind (chaining it into the VM's dma-resv) makes
+ * preempt_rebind_work_func() and xe_vm_add_compute_exec_queue() wait
+ * for. Defrag targets 3D (dma-fence mode) workloads, whose exec waits
+ * on the kernel fences of all external BOs, so the needless rebind of
+ * compute VMs is accepted rather than teaching the preempt paths to
+ * wait as well.
+ */
+ defrag_iova = xe_bo_defrag_use_iova(&bo->ttm);
+
drm_gem_for_each_gpuvm_bo(vm_bo, obj) {
struct xe_vm *vm = gpuvm_to_vm(vm_bo->vm);
struct drm_gpuva *gpuva;
if (!xe_vm_in_fault_mode(vm)) {
- drm_gpuvm_bo_evict(vm_bo, true);
+ if (!defrag_iova || xe_vm_in_preempt_fence_mode(vm))
+ drm_gpuvm_bo_evict(vm_bo, true);
/*
* L2 cache may not be flushed, so ensure that is done in
* xe_vm_invalidate_vma() below
*/
if (!xe_device_is_l2_flush_optimized(xe))
continue;
+
+ /*
+ * The invalidation below zaps the PTEs, so a defrag-IOVA
+ * BO must be rebound after all.
+ */
+ if (defrag_iova && !xe_vm_in_preempt_fence_mode(vm))
+ drm_gpuvm_bo_evict(vm_bo, true);
}
if (!idle) {
@@ -2487,6 +2786,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
bool has_defrag_old_tt = !!ttm_bo->defrag_old_tt;
bool handle_system_ccs = (!IS_DGFX(xe) && xe_bo_needs_ccs_pages(bo) &&
ttm && ttm_tt_is_populated(ttm)) ? true : false;
+ bool defrag_iova = xe_bo_defrag_use_iova(ttm_bo);
int ret = 0;
/*
@@ -2535,7 +2835,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
needs_clear = (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) ||
(!ttm && ttm_bo->type == ttm_bo_type_device);
- if (new_mem->mem_type == XE_PL_TT) {
+ /*
+ * For a defrag move using the packed IOVA path the destination tt is
+ * not fully mapped here; only the changed pages are mapped (packed) for
+ * the copy, and the finalize job establishes the full mapping.
+ */
+ if (new_mem->mem_type == XE_PL_TT && !defrag_iova) {
ret = xe_tt_map(xe, ttm);
if (ret)
goto out;
@@ -2668,9 +2973,16 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
fence = xe_migrate_clear(migrate, bo, new_mem, flags,
ctx->interruptible);
} else if (has_defrag_old_tt) {
- fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem,
- ttm_bo->defrag_old_tt,
- handle_system_ccs);
+ if (defrag_iova)
+ fence = xe_bo_defrag_iova_copy(xe, migrate, bo, old_mem,
+ new_mem,
+ ttm_bo->defrag_old_tt,
+ handle_system_ccs);
+ else
+ fence = xe_migrate_copy_defrag(migrate, bo, old_mem,
+ new_mem,
+ ttm_bo->defrag_old_tt,
+ handle_system_ccs);
} else {
fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem,
handle_system_ccs, ctx->interruptible);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 34/36] drm/xe: Grow the USM batch pool to 2M and map it via a single PDE
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
` (32 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 33/36] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
@ 2026-12-02 23:33 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 35/36] drm/xe: Add bo_defrag debugfs entry Matthew Brost
` (4 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel; +Cc: Natalie Vock, Arun Pravin
The defrag copy path submits its migration batches from the USM batch
pool. When the pool is small, xe_bb_new() backs up in the suballocator
waiting for prior migrate batches to retire, and that stall happens while
the BO reservation lock is held during the move. Traces of a 32MB defrag
move showed the entire ~37ms lock hold sitting inside xe_migrate_copy_*()
at xe_bb_new(), i.e. pool backpressure rather than actual copy time.
Grow the USM batch pool from 512K (integrated) / 1M (DGFX) to a uniform
2M to give the migrate engine enough in-flight batch space to avoid this
backpressure.
On integrated (non-DGFX) the pool is mapped into the migrate VM through
the shared level-0 pagetable alongside the 1M kernel batch pool. A full
2M needs 512 PTEs and no longer fits in that shared table's 2M window.
Instead, map the USM pool through a dedicated level-0 pagetable (reusing
an otherwise unused pt_bo page, as the vram identity map pages are only
consumed on DGFX) and point a single reserved 2M PDE at it, mirroring the
large_page_copy reservation. DGFX is unaffected as it reaches the pool
through the vram identity map.
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_gt.c | 4 +---
drivers/gpu/drm/xe/xe_migrate.c | 34 ++++++++++++++++++++++++++-------
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
index 7eacbe950ccd..7fb89bb5df75 100644
--- a/drivers/gpu/drm/xe/xe_gt.c
+++ b/drivers/gpu/drm/xe/xe_gt.c
@@ -660,10 +660,8 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)
* USM has its only SA pool to non-block behind user operations
*/
if (gt_to_xe(gt)->info.has_usm) {
- struct xe_device *xe = gt_to_xe(gt);
-
gt->usm.bb_pool = xe_sa_bo_manager_init(gt_to_tile(gt),
- IS_DGFX(xe) ? SZ_1M : SZ_512K, 16);
+ SZ_2M, 16);
if (IS_ERR(gt->usm.bb_pool))
return PTR_ERR(gt->usm.bb_pool);
}
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index c894cd1f1305..5844d085d418 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -505,22 +505,42 @@ static void xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
level++;
}
if (xe->info.has_usm) {
+ u64 usm_pt_ofs;
+ u32 usm_pde_slot, usm_pte;
+
xe_tile_assert(tile, xe_bo_size(batch) == SZ_1M);
batch = tile->primary_gt->usm.bb_pool->bo;
- m->usm_batch_base_ofs = m->batch_base_ofs + SZ_1M;
- xe_tile_assert(tile, xe_bo_size(batch) == SZ_512K);
+ xe_tile_assert(tile, xe_bo_size(batch) == SZ_2M);
- for (i = 0; i < xe_bo_size(batch);
+ /*
+ * The usm batch pool is a full 2M and no longer fits in
+ * the shared level-0 pagetable alongside the kernel
+ * batch pool. Map it through a dedicated level-0
+ * pagetable (reusing an otherwise unused pt_bo page, as
+ * the vram identity map pages are only consumed on
+ * DGFX) and point a single reserved 2M PDE at it,
+ * mirroring the large_page_copy reservation below.
+ */
+ usm_pt_ofs = xe_bo_size(bo) - 2 * XE_PAGE_SIZE;
+ for (i = 0, usm_pte = 0; i < xe_bo_size(batch);
i += vm->flags & XE_VM_FLAG_64K ? XE_64K_PAGE_SIZE :
- XE_PAGE_SIZE) {
+ XE_PAGE_SIZE, usm_pte++) {
entry = vm->pt_ops->pte_encode_bo(batch, i,
pat_index, 0);
- xe_map_wr(xe, &bo->vmap, map_ofs + level * 8, u64,
- entry);
- level++;
+ xe_map_wr(xe, &bo->vmap,
+ usm_pt_ofs + usm_pte * 8, u64, entry);
}
+
+ usm_pde_slot = NUM_PT_SLOTS - 1;
+ xe_tile_assert(tile,
+ usm_pde_slot > map_ofs / XE_PAGE_SIZE);
+ entry = vm->pt_ops->pde_encode_bo(bo, usm_pt_ofs);
+ xe_map_wr(xe, &bo->vmap, map_ofs + XE_PAGE_SIZE +
+ usm_pde_slot * 8, u64, entry);
+ m->usm_batch_base_ofs = (u64)usm_pde_slot <<
+ xe_pt_shift(1);
}
} else {
u64 batch_addr = xe_bo_addr(batch, 0, XE_PAGE_SIZE);
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 35/36] drm/xe: Add bo_defrag debugfs entry
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
` (33 preceding siblings ...)
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 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 36/36] drm/xe: Make BO defrag tunables configurable via sysfs Matthew Brost
` (3 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Matthew Auld, Thomas Hellström,
Natalie Vock, Arun Pravin
Add a bo_defrag debugfs file to inspect the state of the BO
defragmentation worker. It reports whether defrag is supported, the
beneficial page order, the per-run size limit, the current (possibly
backed-off) worker interval along with its default and maximum, whether
the worker is pending (and when it will next run), running or idle, and
the number of BOs on the defrag list.
Each BO on the defrag list is then printed with its size, the number of
bytes still backed below the beneficial order (the bytes a defrag move
would reallocate) and whether it still needs defrag, followed by totals.
A reference to each listed BO is taken under the defrag list lock and
the BO is then locked to sample its backing, as the tt can be torn down
while the BO is still on the list. The per-BO output is therefore a
best-effort snapshot.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 97 +++++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_bo.h | 1 +
drivers/gpu/drm/xe/xe_debugfs.c | 9 +++
3 files changed, 107 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 65ab974c56ac..85552da80bf5 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -2476,6 +2476,103 @@ static void xe_bo_defrag_update(struct xe_bo *bo)
xe_bo_defrag_remove(bo);
}
+/**
+ * xe_bo_defrag_print() - Print the BO defragmentation state
+ * @xe: xe device instance
+ * @p: The drm_printer to print to
+ *
+ * Print the defrag worker configuration and state, followed by each BO on the
+ * defrag list with its size and the bytes still backed below the beneficial
+ * order (i.e. the bytes a defrag move would reallocate). A reference to each
+ * listed BO is taken under the list lock and the BO is then locked to sample
+ * its backing, so the per-BO output is a best-effort snapshot.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p)
+{
+ struct delayed_work *dwork = &xe->mem.defrag.worker;
+ u64 total_size = 0, total_subopt = 0;
+ unsigned int count = 0, nr = 0, i;
+ unsigned int interval_ms;
+ struct xe_bo **bos, *bo;
+ int err = 0;
+
+ drm_printf(p, "supported: %s\n",
+ str_yes_no(xe_bo_defrag_supported(xe)));
+ if (!xe_bo_defrag_supported(xe))
+ return 0;
+
+ scoped_guard(spinlock, &xe->mem.defrag.lock) {
+ interval_ms = xe->mem.defrag.interval_ms;
+ list_for_each_entry(bo, &xe->mem.defrag.list, defrag_link)
+ count++;
+ }
+
+ drm_printf(p, "beneficial_order: %u\n",
+ ttm_pool_prealloc_order(&xe->ttm.pool));
+ drm_printf(p, "size_limit: %llu\n", (u64)XE_BO_DEFRAG_SIZE_LIMIT);
+ drm_printf(p, "interval_ms: %u (default %u, max %u)\n", interval_ms,
+ XE_BO_DEFRAG_INTERVAL_MS, XE_BO_DEFRAG_INTERVAL_MAX_MS);
+ if (delayed_work_pending(dwork)) {
+ long delay = (long)(READ_ONCE(dwork->timer.expires) - jiffies);
+
+ drm_printf(p, "worker: pending, next run in %u ms\n",
+ jiffies_to_msecs(max(delay, 0L)));
+ } else {
+ drm_printf(p, "worker: %s\n",
+ work_busy(&dwork->work) ? "running" : "idle");
+ }
+ drm_printf(p, "list_count: %u\n", count);
+ if (!count)
+ return 0;
+
+ bos = kvmalloc_array(count, sizeof(*bos), GFP_KERNEL);
+ if (!bos)
+ return -ENOMEM;
+
+ /* The list may have changed while unlocked; snapshot at most @count. */
+ scoped_guard(spinlock, &xe->mem.defrag.lock) {
+ list_for_each_entry(bo, &xe->mem.defrag.list, defrag_link) {
+ if (nr == count)
+ break;
+ bos[nr] = xe_bo_get_unless_zero(bo);
+ if (bos[nr])
+ nr++;
+ }
+ }
+
+ for (i = 0; i < nr; i++) {
+ u64 size, subopt = 0;
+ bool needs;
+
+ bo = bos[i];
+ if (!err)
+ err = xe_bo_lock(bo, true);
+ if (!err) {
+ size = xe_bo_size(bo);
+ if (bo->ttm.ttm)
+ subopt = (u64)ttm_tt_suboptimal_pages(bo->ttm.ttm) <<
+ PAGE_SHIFT;
+ needs = xe_bo_needs_defrag(bo);
+ xe_bo_unlock(bo);
+
+ drm_printf(p, " bo[%u] %p: size=%llu suboptimal=%llu needs_defrag=%s\n",
+ i, bo, size, subopt, str_yes_no(needs));
+ total_size += size;
+ total_subopt += subopt;
+ }
+ xe_bo_put(bo);
+ }
+ kvfree(bos);
+
+ if (!err)
+ drm_printf(p, "total: bos=%u size=%llu suboptimal=%llu\n",
+ nr, total_size, total_subopt);
+
+ return err;
+}
+
/*
* Attempt to defragment a single BO by forcing a move that reallocates its
* backing at the device's beneficial order. @budget bounds how many bytes of
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 871d1aa1425c..28325341b4d1 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -241,6 +241,7 @@ int xe_bo_defrag_init(struct xe_device *xe);
void xe_bo_defrag_suspend(struct xe_device *xe);
void xe_bo_defrag_resume(struct xe_device *xe);
void xe_bo_defrag_kick(struct xe_device *xe);
+int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p);
int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict,
struct drm_exec *exec);
diff --git a/drivers/gpu/drm/xe/xe_debugfs.c b/drivers/gpu/drm/xe/xe_debugfs.c
index be533435097f..b070835b8d24 100644
--- a/drivers/gpu/drm/xe/xe_debugfs.c
+++ b/drivers/gpu/drm/xe/xe_debugfs.c
@@ -372,11 +372,20 @@ static int dma_mapped_pages_show(struct seq_file *m, void *data)
}
DEFINE_SHOW_ATTRIBUTE(dma_mapped_pages);
+static int bo_defrag(struct seq_file *m, void *data)
+{
+ struct xe_device *xe = node_to_xe(m->private);
+ struct drm_printer p = drm_seq_file_printer(m);
+
+ return xe_bo_defrag_print(xe, &p);
+}
+
static const struct drm_info_list debugfs_list[] = {
{"info", info, 0},
{ .name = "sriov_info", .show = sriov_info, },
{ .name = "workarounds", .show = workaround_info, },
{ .name = "pagefault_info", .show = pagefault_info, },
+ { .name = "bo_defrag", .show = bo_defrag, },
};
static const struct drm_info_list pcode_info_debugfs[] = {
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v5 36/36] drm/xe: Make BO defrag tunables configurable via sysfs
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
` (34 preceding siblings ...)
2026-12-02 23:33 ` [PATCH v5 35/36] drm/xe: Add bo_defrag debugfs entry Matthew Brost
@ 2026-12-02 23:33 ` 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
` (2 subsequent siblings)
38 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-02 23:33 UTC (permalink / raw)
To: intel-xe, dri-devel
Cc: Carlos Santa, Ryan Neph, Matthew Auld, Thomas Hellström,
Natalie Vock, Arun Pravin
The BO defrag per-run size limit, default worker interval and maximum
backed off worker interval are currently fixed at build time via
Kconfig. Tuning them requires a rebuild, which makes experimenting with
defrag behaviour on a running system painful.
Add defrag_size_limit, defrag_interval_ms and defrag_interval_max_ms
device sysfs attributes, defaulting to the Kconfig values. Writes are
validated against the Kconfig ranges, the size limit must be 2M aligned,
and the default interval may not exceed the maximum interval. Lowering
the size limit below 2M (disabling defrag) remains a build time only
decision, so the attributes are only exposed when defrag is supported.
Report the runtime values in the bo_defrag debugfs entry.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/Kconfig.profile | 9 +-
drivers/gpu/drm/xe/xe_bo.c | 131 +++++++++++++++++++++++----
drivers/gpu/drm/xe/xe_bo.h | 5 +
drivers/gpu/drm/xe/xe_device_sysfs.c | 122 +++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_device_types.h | 24 ++++-
5 files changed, 269 insertions(+), 22 deletions(-)
diff --git a/drivers/gpu/drm/xe/Kconfig.profile b/drivers/gpu/drm/xe/Kconfig.profile
index 32bc358e6968..ea46e34e3957 100644
--- a/drivers/gpu/drm/xe/Kconfig.profile
+++ b/drivers/gpu/drm/xe/Kconfig.profile
@@ -115,7 +115,9 @@ config DRM_XE_BO_DEFRAG_SIZE_LIMIT
number of BOs become eligible at once, processing them all in one
worker run would hold things up for a long, unbounded stretch.
Instead, cap the work done per run and requeue, spreading the defrag
- effort out over time.
+ effort out over time. This is the default; when defrag is enabled it
+ can be changed at runtime (2M to 1G) via the defrag_size_limit
+ device sysfs attribute.
config DRM_XE_BO_DEFRAG_INTERVAL_MS
int "Default delay before defrag worker run (ms)"
@@ -123,6 +125,8 @@ config DRM_XE_BO_DEFRAG_INTERVAL_MS
range 1 1000
help
Default delay before (re)running the defrag worker, in milliseconds.
+ Can be changed at runtime via the defrag_interval_ms device sysfs
+ attribute.
config DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS
int "Upper bound for defrag worker interval (ms)"
@@ -131,4 +135,5 @@ config DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS
help
Upper bound for the (exponentially backed off) defrag worker interval,
in milliseconds, so repeated failures don't push the retry arbitrarily
- far out. 15000 ms = 15 seconds.
+ far out. 15000 ms = 15 seconds. Can be changed at runtime via the
+ defrag_interval_max_ms device sysfs attribute.
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 85552da80bf5..321e74e03e3c 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -93,6 +93,12 @@
#define XE_BO_DEFRAG_INTERVAL_MAX_MS 15000 /* 15 seconds */
#endif
+/* Bounds for the values tunable at runtime via sysfs. */
+#define XE_BO_DEFRAG_SIZE_LIMIT_MAX SZ_1G
+#define XE_BO_DEFRAG_INTERVAL_MS_MAX 1000
+#define XE_BO_DEFRAG_INTERVAL_MAX_MS_MIN 100
+#define XE_BO_DEFRAG_INTERVAL_MAX_MS_MAX 1000000
+
static void xe_bo_defrag_worker(struct work_struct *w);
static void xe_place_from_ttm_type(u32 mem_type, struct ttm_place *place);
@@ -1698,8 +1704,6 @@ static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object *ttm_bo,
return tt;
}
-static bool xe_bo_defrag_supported(struct xe_device *xe);
-
static int xe_ttm_tt_populate(struct ttm_device *ttm_dev, struct ttm_tt *tt,
struct ttm_operation_ctx *ctx)
{
@@ -2240,6 +2244,9 @@ int xe_bo_defrag_init_early(struct xe_device *xe)
spin_lock_init(&xe->mem.defrag.lock);
INIT_LIST_HEAD(&xe->mem.defrag.list);
+ xe->mem.defrag.size_limit = XE_BO_DEFRAG_SIZE_LIMIT;
+ xe->mem.defrag.interval_default_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ xe->mem.defrag.interval_max_ms = XE_BO_DEFRAG_INTERVAL_MAX_MS;
xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
INIT_DELAYED_WORK(&xe->mem.defrag.worker, xe_bo_defrag_worker);
@@ -2310,7 +2317,7 @@ static void xe_bo_defrag_kick_locked(struct xe_device *xe)
if (list_empty(&xe->mem.defrag.list))
return;
- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ xe->mem.defrag.interval_ms = xe->mem.defrag.interval_default_ms;
xe_bo_defrag_schedule_locked(xe, true);
}
@@ -2364,11 +2371,14 @@ void xe_bo_defrag_kick(struct xe_device *xe)
xe_bo_defrag_kick_locked(xe);
}
-/*
+/**
* xe_bo_defrag_supported() - Whether background defragmentation is usable
* @xe: xe device instance
*
- * Defragmentation is not supported if XE_BO_DEFRAG_SIZE_LIMIT is less than 2M.
+ * Defragmentation is not supported if the default size limit
+ * (CONFIG_DRM_XE_BO_DEFRAG_SIZE_LIMIT) is less than 2M. The runtime size limit
+ * can't be lowered below 2M, so it can't change whether defragmentation is
+ * supported.
*
* Defragmentation forces TTM moves that reallocate a BO's backing. On a VF
* platform that requires CCS save/restore this interacts badly with CCS
@@ -2377,12 +2387,91 @@ void xe_bo_defrag_kick(struct xe_device *xe)
* backoff that assumes a later in-place upgrade. This is a static platform
* check so the answer can't change during probe, after BOs have been
* allocated or tracked.
+ *
+ * Return: true if background defragmentation is supported, false otherwise.
*/
-static bool xe_bo_defrag_supported(struct xe_device *xe)
+bool xe_bo_defrag_supported(struct xe_device *xe)
{
return XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M && !IS_VF_CCS_NEEDED(xe);
}
+/**
+ * xe_bo_defrag_set_size_limit() - Set the defrag worker per-run byte budget
+ * @xe: xe device instance
+ * @size_limit: New maximum number of bytes to defrag per worker run
+ *
+ * Takes effect from the next worker run.
+ *
+ * Return: 0 on success, -EINVAL if @size_limit is out of range or not 2M
+ * aligned.
+ */
+int xe_bo_defrag_set_size_limit(struct xe_device *xe, u64 size_limit)
+{
+ if (size_limit < SZ_2M || size_limit > XE_BO_DEFRAG_SIZE_LIMIT_MAX ||
+ !IS_ALIGNED(size_limit, SZ_2M))
+ return -EINVAL;
+
+ WRITE_ONCE(xe->mem.defrag.size_limit, size_limit);
+
+ return 0;
+}
+
+/**
+ * xe_bo_defrag_set_interval_ms() - Set the default defrag worker interval
+ * @xe: xe device instance
+ * @interval_ms: New default delay before (re)running the defrag worker
+ *
+ * The new value is used the next time the worker interval is reset, i.e. on
+ * forward progress or when the defrag list transitions to non-empty.
+ *
+ * Return: 0 on success, -EINVAL if @interval_ms is out of range or exceeds
+ * the maximum interval.
+ */
+int xe_bo_defrag_set_interval_ms(struct xe_device *xe, unsigned int interval_ms)
+{
+ if (!interval_ms || interval_ms > XE_BO_DEFRAG_INTERVAL_MS_MAX)
+ return -EINVAL;
+
+ guard(spinlock)(&xe->mem.defrag.lock);
+
+ if (interval_ms > xe->mem.defrag.interval_max_ms)
+ return -EINVAL;
+
+ WRITE_ONCE(xe->mem.defrag.interval_default_ms, interval_ms);
+
+ return 0;
+}
+
+/**
+ * xe_bo_defrag_set_interval_max_ms() - Set the maximum defrag worker interval
+ * @xe: xe device instance
+ * @interval_max_ms: New upper bound for the backed off worker interval
+ *
+ * The current interval is clamped to the new maximum, taking effect the next
+ * time the worker is scheduled.
+ *
+ * Return: 0 on success, -EINVAL if @interval_max_ms is out of range or is
+ * less than the default interval.
+ */
+int xe_bo_defrag_set_interval_max_ms(struct xe_device *xe,
+ unsigned int interval_max_ms)
+{
+ if (interval_max_ms < XE_BO_DEFRAG_INTERVAL_MAX_MS_MIN ||
+ interval_max_ms > XE_BO_DEFRAG_INTERVAL_MAX_MS_MAX)
+ return -EINVAL;
+
+ guard(spinlock)(&xe->mem.defrag.lock);
+
+ if (interval_max_ms < xe->mem.defrag.interval_default_ms)
+ return -EINVAL;
+
+ WRITE_ONCE(xe->mem.defrag.interval_max_ms, interval_max_ms);
+ xe->mem.defrag.interval_ms = min(xe->mem.defrag.interval_ms,
+ interval_max_ms);
+
+ return 0;
+}
+
static bool xe_bo_needs_defrag(struct xe_bo *bo)
{
struct ttm_buffer_object *ttm_bo = &bo->ttm;
@@ -2494,7 +2583,7 @@ int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p)
struct delayed_work *dwork = &xe->mem.defrag.worker;
u64 total_size = 0, total_subopt = 0;
unsigned int count = 0, nr = 0, i;
- unsigned int interval_ms;
+ unsigned int interval_ms, interval_default_ms, interval_max_ms;
struct xe_bo **bos, *bo;
int err = 0;
@@ -2505,15 +2594,18 @@ int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p)
scoped_guard(spinlock, &xe->mem.defrag.lock) {
interval_ms = xe->mem.defrag.interval_ms;
+ interval_default_ms = xe->mem.defrag.interval_default_ms;
+ interval_max_ms = xe->mem.defrag.interval_max_ms;
list_for_each_entry(bo, &xe->mem.defrag.list, defrag_link)
count++;
}
drm_printf(p, "beneficial_order: %u\n",
ttm_pool_prealloc_order(&xe->ttm.pool));
- drm_printf(p, "size_limit: %llu\n", (u64)XE_BO_DEFRAG_SIZE_LIMIT);
+ drm_printf(p, "size_limit: %llu\n",
+ READ_ONCE(xe->mem.defrag.size_limit));
drm_printf(p, "interval_ms: %u (default %u, max %u)\n", interval_ms,
- XE_BO_DEFRAG_INTERVAL_MS, XE_BO_DEFRAG_INTERVAL_MAX_MS);
+ interval_default_ms, interval_max_ms);
if (delayed_work_pending(dwork)) {
long delay = (long)(READ_ONCE(dwork->timer.expires) - jiffies);
@@ -2739,6 +2831,7 @@ 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 size_limit = READ_ONCE(xe->mem.defrag.size_limit);
u64 defrag_bytes = 0;
bool requeue = false;
int idx;
@@ -2761,7 +2854,7 @@ static void xe_bo_defrag_worker(struct work_struct *w)
trace_xe_bo_defrag_worker(xe, 0, true);
/*
- * Process at most XE_BO_DEFRAG_SIZE_LIMIT bytes of newly (re)allocated
+ * Process at most @mem.defrag.size_limit bytes of newly (re)allocated
* backing per run rather than draining the whole list in one go. Only
* the pages a move actually reallocates are charged - pages harvested
* (borrowed) from the old backing are free and do not count - so the
@@ -2772,7 +2865,7 @@ static void xe_bo_defrag_worker(struct work_struct *w)
* active work make progress; any remaining work is handled by a
* follow-up run scheduled below.
*/
- while (defrag_bytes < XE_BO_DEFRAG_SIZE_LIMIT) {
+ while (defrag_bytes < size_limit) {
struct xe_bo *first, *bo;
u64 consumed = 0;
bool needs_more = false;
@@ -2783,7 +2876,8 @@ static void xe_bo_defrag_worker(struct work_struct *w)
/* Progress, reset interval */
if (defrag_bytes)
- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ xe->mem.defrag.interval_ms =
+ xe->mem.defrag.interval_default_ms;
do {
first = list_first_entry_or_null(&xe->mem.defrag.list,
@@ -2806,7 +2900,7 @@ static void xe_bo_defrag_worker(struct work_struct *w)
* 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,
+ ret = xe_bo_defrag_one(xe, bo, size_limit - defrag_bytes,
&consumed, &needs_more);
defrag_bytes += consumed;
@@ -2820,10 +2914,11 @@ static void xe_bo_defrag_worker(struct work_struct *w)
*/
xe->mem.defrag.interval_ms =
min(xe->mem.defrag.interval_ms * 2,
- (unsigned int)XE_BO_DEFRAG_INTERVAL_MAX_MS);
+ xe->mem.defrag.interval_max_ms);
else
/* Progress, reset interval */
- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ xe->mem.defrag.interval_ms =
+ xe->mem.defrag.interval_default_ms;
}
xe_bo_put(bo);
@@ -2838,7 +2933,7 @@ static void xe_bo_defrag_worker(struct work_struct *w)
* Decide whether to reschedule:
*
* - The loop hit its per-run limit (defrag_bytes >=
- * XE_BO_DEFRAG_SIZE_LIMIT): we stopped early to spread the work out,
+ * size_limit): we stopped early to spread the work out,
* so requeue at the default interval (reset here since this run made
* progress) whenever the list still has entries.
*
@@ -2848,10 +2943,10 @@ static void xe_bo_defrag_worker(struct work_struct *w)
* - The loop drained the list (broke on the empty list): nothing left to
* do, so stop scheduling. A fresh enqueue will kick the worker again.
*/
- if (defrag_bytes >= XE_BO_DEFRAG_SIZE_LIMIT) {
+ if (defrag_bytes >= size_limit) {
guard(spinlock)(&xe->mem.defrag.lock);
- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS;
+ xe->mem.defrag.interval_ms = xe->mem.defrag.interval_default_ms;
if (!list_empty(&xe->mem.defrag.list))
xe_bo_defrag_schedule_locked(xe, false);
} else if (requeue) {
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 28325341b4d1..281a863c1702 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -241,6 +241,11 @@ int xe_bo_defrag_init(struct xe_device *xe);
void xe_bo_defrag_suspend(struct xe_device *xe);
void xe_bo_defrag_resume(struct xe_device *xe);
void xe_bo_defrag_kick(struct xe_device *xe);
+bool xe_bo_defrag_supported(struct xe_device *xe);
+int xe_bo_defrag_set_size_limit(struct xe_device *xe, u64 size_limit);
+int xe_bo_defrag_set_interval_ms(struct xe_device *xe, unsigned int interval_ms);
+int xe_bo_defrag_set_interval_max_ms(struct xe_device *xe,
+ unsigned int interval_max_ms);
int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p);
int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict,
struct drm_exec *exec);
diff --git a/drivers/gpu/drm/xe/xe_device_sysfs.c b/drivers/gpu/drm/xe/xe_device_sysfs.c
index 9b734aeefd33..c94592576408 100644
--- a/drivers/gpu/drm/xe/xe_device_sysfs.c
+++ b/drivers/gpu/drm/xe/xe_device_sysfs.c
@@ -11,6 +11,7 @@
#include <linux/sysfs.h>
#include "regs/xe_regs.h"
+#include "xe_bo.h"
#include "xe_device.h"
#include "xe_device_sysfs.h"
#include "xe_mmio.h"
@@ -56,6 +57,24 @@
* back it up. BOs evicted to system memory are never protected. Defaults to
* CONFIG_DRM_XE_SHRINKER_MIN_AGE_MS, 0 disables. This applies at every
* reclaim priority, so a non-zero value can lead to OOM.
+ *
+ * defrag_size_limit - Report/change the maximum number of bytes the BO
+ * defragmentation worker reallocates per run. Valid values are 2M aligned,
+ * 2M to 1G.
+ * Defaults to CONFIG_DRM_XE_BO_DEFRAG_SIZE_LIMIT. Exposed only if BO
+ * defragmentation is supported.
+ *
+ * defrag_interval_ms - Report/change the default delay, in milliseconds,
+ * before (re)running the BO defragmentation worker. Valid values are 1 to
+ * 1000 and must not exceed defrag_interval_max_ms. Defaults to
+ * CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MS. Exposed only if BO defragmentation is
+ * supported.
+ *
+ * defrag_interval_max_ms - Report/change the upper bound, in milliseconds, of
+ * the exponentially backed off BO defragmentation worker interval. Valid
+ * values are 100 to 1000000 and must not be less than defrag_interval_ms.
+ * Defaults to CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS. Exposed only if BO
+ * defragmentation is supported.
*/
static ssize_t
@@ -428,6 +447,103 @@ static const struct attribute_group userptr_attr_group = {
.attrs = userptr_attrs,
};
+static ssize_t
+defrag_size_limit_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev));
+
+ return sysfs_emit(buf, "%llu\n", READ_ONCE(xe->mem.defrag.size_limit));
+}
+
+static ssize_t
+defrag_size_limit_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev));
+ u64 size_limit;
+ int ret;
+
+ ret = kstrtou64(buf, 0, &size_limit);
+ if (ret)
+ return ret;
+
+ ret = xe_bo_defrag_set_size_limit(xe, size_limit);
+
+ return ret ?: count;
+}
+
+static DEVICE_ATTR_RW(defrag_size_limit);
+
+static ssize_t
+defrag_interval_ms_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev));
+
+ return sysfs_emit(buf, "%u\n",
+ READ_ONCE(xe->mem.defrag.interval_default_ms));
+}
+
+static ssize_t
+defrag_interval_ms_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev));
+ unsigned int interval_ms;
+ int ret;
+
+ ret = kstrtouint(buf, 0, &interval_ms);
+ if (ret)
+ return ret;
+
+ ret = xe_bo_defrag_set_interval_ms(xe, interval_ms);
+
+ return ret ?: count;
+}
+
+static DEVICE_ATTR_RW(defrag_interval_ms);
+
+static ssize_t
+defrag_interval_max_ms_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev));
+
+ return sysfs_emit(buf, "%u\n",
+ READ_ONCE(xe->mem.defrag.interval_max_ms));
+}
+
+static ssize_t
+defrag_interval_max_ms_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev));
+ unsigned int interval_max_ms;
+ int ret;
+
+ ret = kstrtouint(buf, 0, &interval_max_ms);
+ if (ret)
+ return ret;
+
+ ret = xe_bo_defrag_set_interval_max_ms(xe, interval_max_ms);
+
+ return ret ?: count;
+}
+
+static DEVICE_ATTR_RW(defrag_interval_max_ms);
+
+static struct attribute *defrag_attrs[] = {
+ &dev_attr_defrag_size_limit.attr,
+ &dev_attr_defrag_interval_ms.attr,
+ &dev_attr_defrag_interval_max_ms.attr,
+ NULL
+};
+
+static const struct attribute_group defrag_attr_group = {
+ .attrs = defrag_attrs,
+};
+
int xe_device_sysfs_init(struct xe_device *xe)
{
struct device *dev = xe->drm.dev;
@@ -441,6 +557,12 @@ int xe_device_sysfs_init(struct xe_device *xe)
if (ret)
return ret;
+ if (xe_bo_defrag_supported(xe)) {
+ ret = devm_device_add_group(dev, &defrag_attr_group);
+ if (ret)
+ return ret;
+ }
+
if (xe->d3cold.capable) {
ret = devm_device_add_group(dev, &vram_attr_group);
if (ret)
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index 423a868d4605..051e29a6f00c 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -345,10 +345,30 @@ struct xe_device {
*/
struct delayed_work worker;
/**
- * @mem.defrag.interval_ms: Reschedule interval for
- * @mem.defrag.worker, in milliseconds.
+ * @mem.defrag.interval_ms: Current (possibly backed off)
+ * reschedule interval for @mem.defrag.worker, in
+ * milliseconds. Protected by @mem.defrag.lock.
*/
unsigned int interval_ms;
+ /**
+ * @mem.defrag.interval_default_ms: Interval that
+ * @mem.defrag.interval_ms is reset to on forward progress,
+ * in milliseconds. Tunable via sysfs. Written under
+ * @mem.defrag.lock.
+ */
+ unsigned int interval_default_ms;
+ /**
+ * @mem.defrag.interval_max_ms: Upper bound for the
+ * backed off @mem.defrag.interval_ms, in milliseconds.
+ * Tunable via sysfs. Written under @mem.defrag.lock.
+ */
+ unsigned int interval_max_ms;
+ /**
+ * @mem.defrag.size_limit: Maximum number of newly
+ * (re)allocated bytes the worker defrags per run.
+ * Tunable via sysfs.
+ */
+ u64 size_limit;
/**
* @mem.defrag.suspended: The device is suspending,
* suspended or undergoing FLR; @mem.defrag.worker must
--
2.34.1
^ permalink raw reply related [flat|nested] 59+ messages in thread
* Re: [PATCH v5 26/36] drm/xe: Don't DMA map tt pages after device unplug
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
0 siblings, 0 replies; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:52 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/xe: broken VRAM dma-buf eviction on unplug in
xe_tt_map_sg()
--
commit 6ee99dc07c1b583a7ad70334282ca88f6e39b4b1
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe: Don't DMA map tt pages after device unplug
This commit rejects DMA-mapping ttm_tt pages in xe_tt_map_sg() with
-ENODEV once the DRM device has been marked unplugged.
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 41092e2810b42..8ff92b2c91761 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -499,6 +499,16 @@ static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
> if (xe_tt->sg)
> return 0;
>
> + /*
> + * Once the device is unplugged, xe_bo_pci_dev_remove_all() has dropped
> + * (or is about to drop, under each bo's lock) all DMA mappings. Don't
> + * create new ones, e.g. when an exported dma-buf moved out to system
> + * is migrated back to TT by begin_cpu_access(): such a mapping would
> + * outlive the device's IOMMU group and crash on unmap.
> + */
> + if (drm_dev_is_unplugged(&xe->drm))
> + return -ENODEV;
[Severity: High]
Does this break evicting exported dma-buf BOs from VRAM during device
removal?
In xe_device_remove(), drm_dev_unplug() runs before
xe_bo_pci_dev_remove_all():
drivers/gpu/drm/xe/xe_device.c:xe_device_remove() {
...
drm_dev_unplug(&xe->drm);
xe_bo_pci_dev_remove_all(xe);
...
}
When xe_bo_pci_dev_remove_all() evicts an exported dma-buf BO from
XE_PL_VRAM0 or XE_PL_VRAM1, xe_evict_flags() selects tt_placement so the
BO moves to XE_PL_TT before XE_PL_SYSTEM. That VRAM-to-TT move allocates
a new ttm_tt and calls xe_bo_move() -> xe_tt_map_sg(), which now fails
with -ENODEV because drm_dev_is_unplugged() is already true. As a result,
ttm_resource_manager_evict_all() aborts with a warning, the exported
dma-buf BO is left in VRAM, and xe_ttm_vram_mgr_fini() returns early
without running gpu_buddy_fini() or ttm_resource_manager_cleanup().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=26
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 17/36] drm/xe: Skip self-copies for borrowed pages on defrag moves
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
0 siblings, 1 reply; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:52 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/xe: WARN_ON and -EINVAL in __xe_migrate_copy() on
extra_pages-only defrag
- [Low] drm/xe: commit message claims stub fence on no-op copy in
__xe_migrate_copy()
--
commit ce7de21d385e57fce79126c867241da7e3be2512
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe: Skip self-copies for borrowed pages on defrag moves
This commit skips GPU data blits on the defragmentation data pass for
pages that the new ttm_tt borrowed directly from the old ttm_tt.
> When an entire L0 chunk turns out to be borrowed, skip it outright: no
> batch buffer is allocated and no GPU commands are issued, the cursors are
> just advanced past the chunk. If every chunk of the move is borrowed the
> copy is a complete no-op, so hand back a signaled stub fence.
[Severity: Low]
This isn't a bug, but the commit message still says a signaled stub fence
is returned when every chunk is borrowed, whereas v5 changed
__xe_migrate_copy() to warn on !fence and return ERR_PTR(-EINVAL).
> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index 71192fbd722d6..5b40405aaba90 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c
[ ... ]
> @@ -1442,9 +1513,30 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
> xe_assert(xe, IS_ALIGNED(ccs_it.start, PAGE_SIZE));
> }
>
> - /* Add copy commands size here */
> + /*
> + * Add copy commands size here. On the defrag data pass the blit
> + * is split into one command per run of non-borrowed pages, so
> + * size for the number of runs actually needed.
> + */
> + if (skip_borrowed)
> + ndata_blits = emit_copy_chunks(gt, NULL, 0, 0, src_L0,
> + src_tt, dst_tt, start_page);
> +
> + /*
> + * If every page in this chunk was borrowed there is nothing to
> + * copy: don't build a batch or issue any GPU commands, just
> + * advance the cursors past the chunk. The non-vram tt cursors
> + * would otherwise be advanced by emit_pte().
> + */
> + if (skip_borrowed && !ndata_blits) {
> + xe_res_next(&src_it, src_L0);
> + xe_res_next(&dst_it, src_L0);
> + size -= src_L0;
> + continue;
> + }
[ ... ]
> @@ -1529,6 +1624,15 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
> return ERR_PTR(err);
> }
>
> + /*
> + * A defrag move always (re)allocates at least one chunk (TTM fails a
> + * zero-progress defrag move), so at least one page differs and a job
> + * carrying the resv dependencies is always emitted. A signaled stub
> + * here would let the old tt be torn down under in-flight GPU work.
> + */
> + if (XE_WARN_ON(!fence))
> + return ERR_PTR(-EINVAL);
> +
> return fence;
> }
[Severity: Medium]
Can __xe_migrate_copy() hit XE_WARN_ON(!fence) and fail the move with
-EINVAL when a defrag pass only reallocates pages in the trailing CCS
extra_pages region?
When xe_bo_needs_ccs_pages(bo) is true, xe_ttm_tt_create() appends
extra_pages beyond xe_bo_size(bo) >> PAGE_SHIFT to tt->num_pages, and the
TTM pool allocator defragments across the full [0, tt->num_pages) array.
If all data chunks in [0, xe_bo_size(bo)) are already at beneficial order
(either initially or after earlier budget-limited defrag passes) and only
a beneficial-order chunk in the trailing extra_pages region is upgraded,
TTM's defrag allocation succeeds while borrowing every data page.
Because __xe_migrate_copy() only iterates over size = xe_bo_size(src_bo),
emit_copy_chunks() returns 0 for every pass and the loop finishes with
fence == NULL, triggering the warning and leaving the BO on the defrag
list to fail again on subsequent passes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=17
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 14/36] drm/xe: Track BOs backed at a sub-optimal page order
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
0 siblings, 1 reply; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:53 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe: no-op xe_bo_defrag_update() on CPU fault in
xe_bo_fault_migrate()
--
commit 22495e3a9f5a9f486e4a553586605bb281ab160e
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe: Track BOs backed at a sub-optimal page order
This commit adds per-device tracking for buffer objects whose backing TT
pages were allocated below the pool's beneficial order so they can be
candidates for future defragmentation.
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index ff5610ba4b740..98c0b32e95439 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
[ ... ]
> +static bool xe_bo_needs_defrag(struct xe_bo *bo)
> +{
> + struct ttm_buffer_object *ttm_bo = &bo->ttm;
> + struct ttm_tt *tt = ttm_bo->ttm;
> +
> + xe_bo_assert_held(bo);
> +
> + return xe_bo_defrag_supported(xe_bo_device(bo)) &&
> + ttm_bo->type == ttm_bo_type_device && tt &&
> + !xe_bo_madv_is_dontneed(bo) &&
> + ttm_tt_is_populated(tt) &&
> + ttm_tt_is_beneficial_order_failed(tt) &&
> + ttm_bo->resource && ttm_bo->resource->mem_type == XE_PL_TT &&
> + !xe_bo_is_pinned(bo);
> +}
[ ... ]
> @@ -2245,9 +2379,14 @@ static int xe_bo_fault_migrate(struct xe_bo *bo, struct ttm_operation_ctx *ctx,
> int err = 0;
>
> if (ttm_manager_type(tbo->bdev, tbo->resource->mem_type)->use_tt) {
> + bool populated = tbo->ttm && ttm_tt_is_populated(tbo->ttm);
> +
> err = xe_bo_wait_usage_kernel(bo, ctx);
> - if (!err)
> + if (!err) {
> err = ttm_bo_populate(&bo->ttm, ctx);
> + if (!err && !populated)
> + xe_bo_defrag_update(bo);
> + }
> } else if (should_migrate_to_smem(bo)) {
[Severity: Medium]
Can xe_bo_defrag_update(bo) ever add a BO to xe->mem.defrag.list from
xe_bo_fault_migrate()?
Any BO resident in XE_PL_TT is already populated before xe_bo_move() runs,
and all shrink, swapout and deferred-backing paths leave unpopulated BOs
in XE_PL_SYSTEM. When !populated is true here, tbo->resource->mem_type is
always XE_PL_SYSTEM, and ttm_bo_populate() populates tbo->ttm in place
without changing the resource's mem_type. Because xe_bo_needs_defrag()
requires ttm_bo->resource->mem_type == XE_PL_TT, BOs populated on a CPU
page fault at a sub-optimal order will never be added to the defrag list.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=14
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move()
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
0 siblings, 1 reply; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:55 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/xe: loss of FlatCCS extra TT pages on DGFX defrag in
xe_bo_move()
--
commit fb1ace888ac8c6157078a250c431da6e90c2457a
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe: Handle defrag moves in xe_bo_move()
This commit updates xe_bo_move() to handle defragmentation moves by
copying data from the BO's stashed defrag_old_tt to the newly allocated
backing via xe_migrate_copy_defrag().
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 98c0b32e95439..4c735ec8754ea 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -1291,6 +1291,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
> bool move_lacks_source;
> bool tt_has_data;
> bool needs_clear;
> + bool has_defrag_old_tt = !!ttm_bo->defrag_old_tt;
> bool handle_system_ccs = (!IS_DGFX(xe) && xe_bo_needs_ccs_pages(bo) &&
> ttm && ttm_tt_is_populated(ttm)) ? true : false;
> int ret = 0;
[ ... ]
> @@ -1463,6 +1474,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
>
> fence = xe_migrate_clear(migrate, bo, new_mem, flags,
> ctx->interruptible);
> + } else if (has_defrag_old_tt) {
> + struct xe_ttm_tt *old_xe_tt =
> + container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm);
> +
> + fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem,
> + old_xe_tt->sg, handle_system_ccs);
> } else {
> fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem,
> handle_system_ccs, ctx->interruptible);
[Severity: High]
Does this lose the saved FlatCCS pages when defragmenting an evicted
VRAM BO on DG2?
On discrete GPUs with FlatCCS and GRAPHICS_VER(xe) < 20 (DG2), a
compressible VRAM-only BO evicted to XE_PL_TT stores its saved FlatCCS
state in extra TT pages starting at xe_bo_ccs_pages_start(bo), and
xe_bo_needs_defrag() admits that evicted BO for defragmentation when
ttm_tt_is_beneficial_order_failed(tt) is set. During the defrag move,
handle_system_ccs is false because IS_DGFX(xe) is true, and
xe_migrate_copy_defrag() only copies [0, xe_bo_size(bo)), leaving any
newly reallocated 2 MB chunk overlapping the trailing extra CCS pages in
bo->ttm uninitialized. When the BO is later validated back to VRAM,
corrupted FlatCCS metadata is restored.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=16
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation
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
0 siblings, 0 replies; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:56 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/xe: FlatCCS extra_pages size mismatch in
xe_bo_defrag_one()
- [Medium] drm/xe: TTM WC/UC page pool bypass in xe_bo_defrag_one()
preallocation
--
commit 27539e0916948f7e33871d52a57501de9005f821
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe: Defrag using out-of-lock page preallocation
This commit converts xe_bo_defrag_one() to preallocate beneficial-order
pages via ttm_pool_prealloc_fill() outside the BO dma-resv lock before
validating the BO with the preallocated page bag.
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index af9bdb7f05ef4..f3ce4e7ed98d1 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -1510,16 +1510,65 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
> .defrag_bytes_remaining = budget,
> };
> struct ttm_buffer_object *ttm_bo = &bo->ttm;
> + struct ttm_pool *pool = &ttm_bo->bdev->pool;
> + struct ttm_pool_prealloc pp = {};
> struct ttm_placement placement;
> struct ttm_place place;
> + enum ttm_caching tt_caching;
> + unsigned int order, want = 0;
> int ret = 0;
>
> *consumed = 0;
> *needs_more = false;
>
> + /*
> + * Phase 1: under the BO lock, re-check eligibility and estimate how
> + * many beneficial-order chunks the move will (re)allocate, bounded by
> + * the run's byte budget. Then drop the lock so the high-order, possibly
> + * reclaim/compaction stalling allocations happen unlocked.
> + */
> + xe_bo_lock(bo, false);
> + if (!xe_bo_needs_defrag(bo)) {
> + xe_bo_defrag_remove(bo);
> + xe_bo_unlock(bo);
> + goto out;
> + }
> + tt_caching = bo->ttm.ttm->caching;
> + order = ttm_pool_prealloc_order(pool);
> + if (order && ttm_bo->ttm) {
> + u32 suboptimal = ttm_tt_suboptimal_pages(ttm_bo->ttm);
> + u64 cap = min_t(u64, budget, xe_bo_size(bo)) >> PAGE_SHIFT;
> +
> + /* Prealloc only the beneficial-order chunks the move replaces. */
> + want = DIV_ROUND_UP_ULL(min_t(u64, suboptimal, cap), 1UL << order);
> + }
[Severity: Medium]
Can capping want by xe_bo_size(bo) while reading suboptimal from
ttm_tt_suboptimal_pages() trigger XE_WARN_ON(!fence) in
__xe_migrate_copy() on integrated GPUs with FlatCCS?
For compressible system-memory BOs, xe_ttm_tt_create() appends FlatCCS
extra_pages beyond xe_bo_size(bo), and ttm_pool accounts sub-optimal
chunks across the full tt->num_pages range. On a 1 GiB compressible BO
(512 order-9 data chunks plus one order-9 extra_pages chunk), cap limits
want to 512 even with a 1 GiB budget, so the first pass upgrades the 512
data chunks and harvests the extra_pages chunk as sub-optimal.
On the next pass (or whenever all data chunks are already at order 9 and
only the trailing extra_pages chunk is sub-optimal), want is 1.
ttm_bo_validate() borrows all data pages and reallocates only the
extra_pages chunk, but __xe_migrate_copy() only iterates over
xe_bo_size(src_bo), finds no non-borrowed pages to copy, hits
XE_WARN_ON(!fence), and fails with -EINVAL while leaving the BO on the
defrag list to repeat on later runs.
> +
> + /*
> + * Nothing the move could upgrade: TTM would fail a defrag move that
> + * allocates no chunk, so drop the BO rather than retry it forever. It
> + * is re-added if a later populate backs it sub-optimally again.
> + */
> + if (!want) {
> + xe_bo_defrag_remove(bo);
> + xe_bo_unlock(bo);
> + goto out;
> + }
> + xe_bo_unlock(bo);
> +
> + /* Phase 2: preallocate outside the lock; */
> + ret = ttm_pool_prealloc_fill(pool, tt_caching, &pp, want);
> + if (ret || !pp.count) {
> + ret = ret ?: -ENOMEM;
> + xe_gt_stats_incr(xe_root_mmio_gt(xe),
> + XE_GT_STATS_ID_DEFRAG_FAILED_COUNT, 1);
> + goto out_err;
> + }
[Severity: Medium]
Does switching to ttm_pool_prealloc_fill() and ttm_pool_prealloc_fini()
bypass the TTM WC/UC page pools during defragmentation?
Before this change, in-line allocation via ttm_pool_iter_acquire_page()
checked ttm_pool_select_type() and ttm_pool_type_take() first to reuse
already cache-converted order-9 pages from the TTM pool. Unlike
ttm_pool_prealloc_fill_full(), ttm_pool_prealloc_fill() never consults
the TTM pool: it unconditionally calls ttm_pool_alloc_page() for fresh
write-back pages from the buddy allocator and converts their PAT caching
via ttm_pool_prealloc_apply_caching(). Similarly,
ttm_pool_prealloc_fini() frees unconsumed chunks via
ttm_pool_free_page() (converting each chunk back to write-back) instead
of returning WC/UC chunks to the TTM pool.
For WC and UC system-memory BOs on x86, this forces order-9 buddy
allocations, direct reclaim/compaction, and cross-CPU PAT/TLB shootdown
IPIs (or -ENOMEM defrag failures) even when pre-converted order-9 pages
are sitting idle in the TTM pool.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=21
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 10/36] drm/ttm: Preallocate beneficial-order defrag pages outside the lock
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
0 siblings, 1 reply; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:57 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/ttm: stale beneficial-order failure flag on resumed restore
in ttm_pool_restore_and_alloc()
--
commit 5e2ee65385b61ac88536ccf836b08b653cbf5979
Author: Matthew Brost <matthew.brost@intel.com>
drm/ttm: Preallocate beneficial-order defrag pages outside the lock
This commit adds out-of-lock preallocation of beneficial-order pages for
TTM defragmentation moves and records the number of sub-optimal pages on
each ttm_tt at populate time.
> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index 79538d776dde3..fa76f880d5632 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
[ ... ]
> @@ -1384,7 +1628,7 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
>
> tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
> - ttm_pool_alloc_state_init(tt, &alloc);
> + ttm_pool_alloc_state_init(pool, tt, &alloc);
> if (ctx->gfp_retry_mayfail)
> gfp |= __GFP_RETRY_MAYFAIL;
>
> @@ -1414,11 +1658,16 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> kfree(tt->restore);
> tt->restore = NULL;
>
> + tt->nr_suboptimal_pages = alloc.nr_suboptimal_pages;
> return 0;
> }
> }
>
> - return __ttm_pool_alloc(pool, tt, ctx, &alloc, restore);
> + ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, restore);
> + if (!ret)
> + tt->nr_suboptimal_pages = alloc.nr_suboptimal_pages;
> +
> + return ret;
> }
[Severity: Low]
Can a resumed restore finish with TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED set
on tt->page_flags while tt->nr_suboptimal_pages is 0?
During a restore, ttm_pool_iter_lower_order() sets
TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED directly on tt->page_flags before the
lower-order fallback chunk is allocated, restored, and committed to
restore->snapshot_alloc. If ttm_pool_restore_commit() is then interrupted
at restore->restored_pages == 0, it frees the uncommitted fallback page
without advancing restore->snapshot_alloc:
drivers/gpu/drm/ttm/ttm_pool.c:ttm_pool_restore_commit() {
...
if (ret) {
if (!restore->restored_pages) {
dma_addr_t *dma_addr = alloc->dma_addr ? &restore->first_dma : NULL;
ttm_pool_unmap_and_free(restore->pool, restore->alloced_page,
dma_addr, restore->page_caching);
restore->restored_pages = nr;
}
return ret;
}
...
}
When ttm_pool_restore_and_alloc() is called again to resume, it reloads
restore->snapshot_alloc without clearing
TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED. If the resumed pass then succeeds at
the beneficial order, the restore completes with
TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED still set and tt->nr_suboptimal_pages
== 0, causing drivers to repeatedly queue an already optimal BO for
defragmentation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=10
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 27/36] drm/xe/display: Flush cleanup work on unregister
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
0 siblings, 0 replies; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:58 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe/display: incomplete cleanup flush in
xe_display_unregister()
--
commit 6c15425fef0fac1bcda715813c673a4c85d77163
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe/display: Flush cleanup work on unregister
This commit flushes display atomic cleanup work in xe_display_unregister()
so that scanout framebuffers are unpinned before xe_bo_pci_dev_remove_all()
evicts all buffer objects on device removal.
> diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c
> index b1a6008bf15c6..68d29d78dc8b2 100644
> --- a/drivers/gpu/drm/xe/display/xe_display.c
> +++ b/drivers/gpu/drm/xe/display/xe_display.c
> @@ -155,6 +155,14 @@ void xe_display_unregister(struct xe_device *xe)
>
> intel_display_driver_runtime_pm_disable(display);
> intel_display_driver_unregister(display);
> +
> + /*
> + * The shutdown commit unpins the framebuffers from the asynchronous
> + * cleanup work. Flush it so they are unpinned, and thus visible to
> + * the eviction in xe_bo_pci_dev_remove_all(), before the device
> + * is removed.
> + */
> + intel_display_flush_cleanup_work(display);
> }
[Severity: Medium]
Can intel_display_flush_cleanup_work() return while an earlier commit on
the same CRTC is still unpinning its old scanout framebuffer?
intel_display_flush_cleanup_work() only waits on the first (newest) entry
of crtc->base.commit_list:
drivers/gpu/drm/i915/display/intel_display.c:intel_display_flush_cleanup_work() {
...
spin_lock(&crtc->base.commit_lock);
commit = list_first_entry_or_null(&crtc->base.commit_list,
struct drm_crtc_commit, commit_entry);
if (commit)
drm_crtc_commit_get(commit);
spin_unlock(&crtc->base.commit_lock);
if (commit) {
wait_for_completion(&commit->cleanup_done);
drm_crtc_commit_put(commit);
}
...
}
When drm_atomic_helper_shutdown() submits the shutdown commit (commit 2),
stall_checks() only waits for cleanup_done of the second previous commit
(i == 1), and drm_atomic_helper_wait_for_dependencies() only waits for
hw_done and flip_done of the immediately preceding commit (commit 1, e.g.
from drm_client_dev_unregister() tearing down fbdev or a prior flip).
drm_atomic_helper_swap_state() prepends commit 2 to the head of
crtc->commit_list ahead of commit 1.
Because display->wq.cleanup is allocated with WQ_HIGHPRI | WQ_PERCPU and
max_active = 0 (unordered), commit 1 and commit 2 can run
intel_atomic_cleanup_work() concurrently:
kworker (commit 1) CPU0 (unregister / commit 2)
------------------ ----------------------------
intel_atomic_cleanup_work()
intel_atomic_cleanup_planes()
__xe_unpin_fb_vma()
...
drm_atomic_helper_shutdown()
...
queue_work(wq.cleanup,
&commit2->cleanup_work)
[commit 2 cleanup_work runs and
signals commit2->cleanup_done]
intel_display_flush_cleanup_work()
wait_for_completion(
&commit2->cleanup_done)
xe_bo_pci_dev_remove_all()
<-- commit 1's old fb BO is still
pinned and missed by eviction
If commit 2 finishes cleanup_done first while commit 1 is still in
intel_atomic_cleanup_work(), intel_display_flush_cleanup_work() returns
before commit 1 unpins its old scanout BO. That BO stays pinned past
xe_bo_pci_dev_remove_all() and hits the NULL IOMMU group dereference on
final release after PCI device removal.
Flushing display->wq.cleanup (or waiting for cleanup_done across all
commits on crtc->base.commit_list) would ensure all in-flight plane
cleanups have finished.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=27
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
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
0 siblings, 1 reply; 59+ messages in thread
From: sashiko-bot @ 2026-12-02 23:59 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/ttm: repeated empty-pool list_lru locking in
ttm_pool_prealloc_fill_full()
--
commit a9c3c46ffa013c41ec426391623e966b58881b75
Author: Matthew Brost <matthew.brost@intel.com>
drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
This commit adds ttm_pool_prealloc_fill_full() to preallocate the entire
backing of a system-memory ttm_tt at mixed orders outside the dma-resv
lock.
> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index fa76f880d5632..7b1736324f7e5 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
[ ... ]
> +static struct page *ttm_pool_take_page(struct ttm_pool *pool,
> + enum ttm_caching caching,
> + unsigned int *order, gfp_t gfp,
> + bool *need_caching,
> + bool beneficial_reclaim_backoff)
> +{
> + unsigned int beneficial = ttm_pool_beneficial_order(pool);
> + struct ttm_pool_type *pt;
> + struct page *p;
> +
> + *need_caching = false;
> +
> + if (IS_ENABLED(CONFIG_FAULT_INJECTION) && beneficial &&
> + *order >= beneficial &&
> + should_fail(&beneficial_order_fault_inject, 1)) {
> + *order = beneficial;
> + return NULL;
> + }
> +
> + pt = ttm_pool_select_type(pool, caching, *order);
> + if (pt) {
> + p = ttm_pool_type_take(pt, ttm_pool_nid(pool));
> + if (p)
> + return p; /* pool page already carries @caching */
> + }
> +
> + p = ttm_pool_alloc_page(pool, gfp, *order, beneficial_reclaim_backoff);
> + if (!p)
> + return NULL;
> +
> + /* Fresh system page is write-back; caller applies @caching in bulk. */
> + *need_caching = true;
> + return p;
> +}
[ ... ]
> +int ttm_pool_prealloc_fill_full(struct ttm_pool *pool,
> + enum ttm_caching tt_caching,
> + struct ttm_pool_prealloc *pp,
> + unsigned int num_pages,
> + bool beneficial_reclaim_backoff)
> +{
[ ... ]
> + while (remaining) {
> + unsigned int order = min_t(unsigned int, highest,
> + __fls(remaining));
> + bool need_caching;
> + struct page *p;
> +
> + for (;;) {
> + p = ttm_pool_take_page(pool, tt_caching, &order, gfp,
> + &need_caching,
> + beneficial_reclaim_backoff);
> + if (p)
> + break;
> + if (!order)
> + goto apply_caching; /* short fill */
> + /*
> + * Genuine failure: retry one order down. A fault
> + * injection lowered @order to the beneficial order
> + * above, so this drops it below - landing on a
> + * sub-optimal (defrag-worthy) chunk.
> + */
> + order--;
> + }
[Severity: Medium]
Should ttm_pool_prealloc_fill_full() stop probing the pool at the current
order once ttm_pool_type_take() returns NULL, the way
ttm_pool_iter_acquire_page() does with it->allow_pools?
In the in-line allocator, once ttm_pool_type_take() misses at a given
order, it->allow_pools is cleared until the allocator drops to a lower
order. Here, ttm_pool_take_page() calls ttm_pool_type_take() on every
iteration of the while (remaining) loop.
On x86, ttm_write_combined and ttm_uncached use the global pool types, and
ttm_pool_type_take() -> list_lru_walk_node() unconditionally acquires and
releases the list_lru spinlock even when the list is empty. When the
global WC or UC pool is empty and allocation falls back to order 0 (for
instance when beneficial_reclaim_backoff skips reclaim at higher orders),
preallocating a buffer object acquires and releases the global order-0
list_lru spinlock once per 4K page instead of once per order, contending
across concurrent unlocked preallocations.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=11
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs
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
0 siblings, 0 replies; 59+ messages in thread
From: sashiko-bot @ 2026-12-03 0:06 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/xe: xe_tt_map() returns -ENODEV during unplug VRAM eviction
- [High] drm/xe: IOVA mapping can escape xe_bo_pci_dev_remove_all() on
unplug
--
commit a2fdff5ea39545a2086c69c17159fb3fb9d84d16
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe: Use IOVA-based DMA mapping for eligible tt BOs
This commit adds support for DMA-mapping eligible ttm_tt objects with the
IOVA-based DMA API as a contiguous alternative to scatter-gather lists, and
switches TT resource cursor users to xe_res_first_tt().
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 878a1b0e7dac3..e2a725c790d8b 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
[ ... ]
> @@ -543,28 +616,207 @@ static void xe_tt_unmap_sg(struct xe_device *xe, struct ttm_tt *tt)
[ ... ]
> +/*
> + * xe_tt_map - DMA map a tt, using IOVA when available and sg otherwise.
> + */
> +static int xe_tt_map(struct xe_device *xe, struct ttm_tt *tt)
> +{
> + struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
> +
> + /*
> + * Once the device is unplugged, xe_bo_pci_dev_remove_all() has dropped
> + * (or is about to drop, under each bo's lock) all DMA mappings. Don't
> + * create new ones, e.g. when an exported dma-buf moved out to system
> + * is migrated back to TT by begin_cpu_access(): such a mapping would
> + * outlive the device's IOMMU group and crash on unmap.
> + */
> + if (drm_dev_is_unplugged(&xe->drm))
> + return -ENODEV;
[Severity: High]
Does rejecting xe_tt_map() when drm_dev_is_unplugged() is true break VRAM
eviction of exported dma-buf BOs during device removal?
In xe_device_remove(), drm_dev_unplug() runs before
xe_bo_pci_dev_remove_all(). When xe_bo_pci_dev_remove_all() evicts an
exported dma-buf BO (tbo->base.dma_buf != NULL) from VRAM, xe_evict_flags()
skips purge_placement and routes the BO to XE_PL_TT so its contents can be
copied to system memory. That hop calls xe_bo_move() -> xe_tt_map(), which
now fails with -ENODEV, aborting ttm_resource_manager_evict_all(),
triggering drm_WARN_ON() in xe_bo_pci_dev_remove_all(), and leaving the BO
and any remaining BOs on that VRAM manager's LRU unevicted.
[ ... ]
> @@ -2603,6 +2892,8 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo)
> DMA_BIDIRECTIONAL);
> ttm_bo->sg = NULL;
> xe_tt->sg = NULL;
> + } else if (xe_tt->use_iova) {
> + xe_tt_unmap_iova(ttm_to_xe_device(ttm_bo->bdev), tt);
> } else if (xe_tt->sg) {
> xe_tt_unmap_sg(ttm_to_xe_device(ttm_bo->bdev),
> &xe_tt->ttm);
[Severity: High]
Can an IOVA-mapped user BO in XE_PL_TT escape xe_bo_pci_dev_remove_all()
if it is unpinned concurrently with device removal?
An exported user BO created without a VM has neither XE_BO_FLAG_GGTT nor
XE_BO_FLAG_PINNED, so xe_tt->iova_eligible is true. If a dma-buf importer
pins and later unpins that BO while xe_bo_pci_dev_remove_all() is running:
CPU0 CPU1
xe_bo_pci_dev_remove_all()
ttm_resource_manager_evict_all(TT)
(skips pinned BO on unevictable)
xe_dma_buf_unpin()
xe_bo_unpin_external()
xe_bo_account_unpin()
list_del_init(&bo->pinned_link)
ttm_bo_unpin()
(moves BO back to TT LRU)
xe_bo_pci_dev_remove_pinned()
(misses BO, no longer on
pinned.late.external)
The same miss happens without a race if the user BO was already pinned for
display scanout via __xe_pin_fb_vma() before xe_dma_buf_pin() ->
xe_bo_pin_external() ran, because first_pin is false and bo->pinned_link is
never added to xe->pinned.late.external.
In either case, xe_tt->use_iova survives PCI device removal, and when the
BO is later destroyed after the device's IOMMU domain has been torn down,
xe_ttm_tt_unpopulate() -> xe_tt_unmap_iova() -> dma_iova_destroy() hits a
NULL pointer dereference (and trips the xe_assert() in
xe_ttm_tt_destroy()).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=29
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 10/36] drm/ttm: Preallocate beneficial-order defrag pages outside the lock
2026-12-02 23:57 ` sashiko-bot
@ 2026-12-03 0:08 ` Matthew Brost
0 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-03 0:08 UTC (permalink / raw)
To: sashiko-reviews; +Cc: intel-xe, dri-devel
On Wed, Dec 02, 2026 at 11:57:53PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] drm/ttm: stale beneficial-order failure flag on resumed restore
> in ttm_pool_restore_and_alloc()
This one looks valid, easy fix. Will adjust in v6.
Matt
> --
>
> commit 5e2ee65385b61ac88536ccf836b08b653cbf5979
> Author: Matthew Brost <matthew.brost@intel.com>
>
> drm/ttm: Preallocate beneficial-order defrag pages outside the lock
>
> This commit adds out-of-lock preallocation of beneficial-order pages for
> TTM defragmentation moves and records the number of sub-optimal pages on
> each ttm_tt at populate time.
>
> > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> > index 79538d776dde3..fa76f880d5632 100644
> > --- a/drivers/gpu/drm/ttm/ttm_pool.c
> > +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> [ ... ]
> > @@ -1384,7 +1628,7 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> > gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
> >
> > tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
> > - ttm_pool_alloc_state_init(tt, &alloc);
> > + ttm_pool_alloc_state_init(pool, tt, &alloc);
> > if (ctx->gfp_retry_mayfail)
> > gfp |= __GFP_RETRY_MAYFAIL;
> >
> > @@ -1414,11 +1658,16 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> > kfree(tt->restore);
> > tt->restore = NULL;
> >
> > + tt->nr_suboptimal_pages = alloc.nr_suboptimal_pages;
> > return 0;
> > }
> > }
> >
> > - return __ttm_pool_alloc(pool, tt, ctx, &alloc, restore);
> > + ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, restore);
> > + if (!ret)
> > + tt->nr_suboptimal_pages = alloc.nr_suboptimal_pages;
> > +
> > + return ret;
> > }
>
> [Severity: Low]
> Can a resumed restore finish with TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED set
> on tt->page_flags while tt->nr_suboptimal_pages is 0?
>
> During a restore, ttm_pool_iter_lower_order() sets
> TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED directly on tt->page_flags before the
> lower-order fallback chunk is allocated, restored, and committed to
> restore->snapshot_alloc. If ttm_pool_restore_commit() is then interrupted
> at restore->restored_pages == 0, it frees the uncommitted fallback page
> without advancing restore->snapshot_alloc:
>
> drivers/gpu/drm/ttm/ttm_pool.c:ttm_pool_restore_commit() {
> ...
> if (ret) {
> if (!restore->restored_pages) {
> dma_addr_t *dma_addr = alloc->dma_addr ? &restore->first_dma : NULL;
>
> ttm_pool_unmap_and_free(restore->pool, restore->alloced_page,
> dma_addr, restore->page_caching);
> restore->restored_pages = nr;
> }
> return ret;
> }
> ...
> }
>
> When ttm_pool_restore_and_alloc() is called again to resume, it reloads
> restore->snapshot_alloc without clearing
> TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED. If the resumed pass then succeeds at
> the beneficial order, the restore completes with
> TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED still set and tt->nr_suboptimal_pages
> == 0, causing drivers to repeatedly queue an already optimal BO for
> defragmentation.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=10
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 18/36] drm/xe: Add a page defragmentation worker
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
0 siblings, 1 reply; 59+ messages in thread
From: sashiko-bot @ 2026-12-03 0:12 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
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()
- [High] drm/xe: sliced defrag of FlatCCS BOs hits WARN_ON in
__xe_migrate_copy()
- [Medium] drm/xe: stop defrag worker in xe_device_shutdown() before GT
reset and FLR
--
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
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
2026-12-02 23:59 ` sashiko-bot
@ 2026-12-03 0:16 ` Matthew Brost
0 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-03 0:16 UTC (permalink / raw)
To: sashiko-reviews; +Cc: intel-xe, dri-devel
On Wed, Dec 02, 2026 at 11:59:42PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] drm/ttm: repeated empty-pool list_lru locking in
> ttm_pool_prealloc_fill_full()
IMO micro-optimization but it exists in the main alloc path so might as
well add it here as it simple enough to code up.
Matt
> --
>
> commit a9c3c46ffa013c41ec426391623e966b58881b75
> Author: Matthew Brost <matthew.brost@intel.com>
>
> drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
>
> This commit adds ttm_pool_prealloc_fill_full() to preallocate the entire
> backing of a system-memory ttm_tt at mixed orders outside the dma-resv
> lock.
>
> > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> > index fa76f880d5632..7b1736324f7e5 100644
> > --- a/drivers/gpu/drm/ttm/ttm_pool.c
> > +++ b/drivers/gpu/drm/ttm/ttm_pool.c
>
> [ ... ]
>
> > +static struct page *ttm_pool_take_page(struct ttm_pool *pool,
> > + enum ttm_caching caching,
> > + unsigned int *order, gfp_t gfp,
> > + bool *need_caching,
> > + bool beneficial_reclaim_backoff)
> > +{
> > + unsigned int beneficial = ttm_pool_beneficial_order(pool);
> > + struct ttm_pool_type *pt;
> > + struct page *p;
> > +
> > + *need_caching = false;
> > +
> > + if (IS_ENABLED(CONFIG_FAULT_INJECTION) && beneficial &&
> > + *order >= beneficial &&
> > + should_fail(&beneficial_order_fault_inject, 1)) {
> > + *order = beneficial;
> > + return NULL;
> > + }
> > +
> > + pt = ttm_pool_select_type(pool, caching, *order);
> > + if (pt) {
> > + p = ttm_pool_type_take(pt, ttm_pool_nid(pool));
> > + if (p)
> > + return p; /* pool page already carries @caching */
> > + }
> > +
> > + p = ttm_pool_alloc_page(pool, gfp, *order, beneficial_reclaim_backoff);
> > + if (!p)
> > + return NULL;
> > +
> > + /* Fresh system page is write-back; caller applies @caching in bulk. */
> > + *need_caching = true;
> > + return p;
> > +}
>
> [ ... ]
>
> > +int ttm_pool_prealloc_fill_full(struct ttm_pool *pool,
> > + enum ttm_caching tt_caching,
> > + struct ttm_pool_prealloc *pp,
> > + unsigned int num_pages,
> > + bool beneficial_reclaim_backoff)
> > +{
>
> [ ... ]
>
> > + while (remaining) {
> > + unsigned int order = min_t(unsigned int, highest,
> > + __fls(remaining));
> > + bool need_caching;
> > + struct page *p;
> > +
> > + for (;;) {
> > + p = ttm_pool_take_page(pool, tt_caching, &order, gfp,
> > + &need_caching,
> > + beneficial_reclaim_backoff);
> > + if (p)
> > + break;
> > + if (!order)
> > + goto apply_caching; /* short fill */
> > + /*
> > + * Genuine failure: retry one order down. A fault
> > + * injection lowered @order to the beneficial order
> > + * above, so this drops it below - landing on a
> > + * sub-optimal (defrag-worthy) chunk.
> > + */
> > + order--;
> > + }
>
> [Severity: Medium]
> Should ttm_pool_prealloc_fill_full() stop probing the pool at the current
> order once ttm_pool_type_take() returns NULL, the way
> ttm_pool_iter_acquire_page() does with it->allow_pools?
>
> In the in-line allocator, once ttm_pool_type_take() misses at a given
> order, it->allow_pools is cleared until the allocator drops to a lower
> order. Here, ttm_pool_take_page() calls ttm_pool_type_take() on every
> iteration of the while (remaining) loop.
>
> On x86, ttm_write_combined and ttm_uncached use the global pool types, and
> ttm_pool_type_take() -> list_lru_walk_node() unconditionally acquires and
> releases the list_lru spinlock even when the list is empty. When the
> global WC or UC pool is empty and allocation falls back to order 0 (for
> instance when beneficial_reclaim_backoff skips reclaim at higher orders),
> preallocating a buffer object acquires and releases the global order-0
> list_lru spinlock once per 4K page instead of once per order, contending
> across concurrent unlocked preallocations.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=11
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 33/36] drm/xe: Finalize defrag-IOVA moves with post-copy job
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
0 siblings, 0 replies; 59+ messages in thread
From: sashiko-bot @ 2026-12-03 0:18 UTC (permalink / raw)
To: Matthew Brost, intel-xe, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe: page range mismatch in xe_bo_defrag_iova_copy() with
CCS extra_pages
--
commit d43bc6ca2ee8e9ea06f7417aee36a16ea7bf5ca3
Author: Matthew Brost <matthew.brost@intel.com>
drm/xe: Finalize defrag-IOVA moves with post-copy job
This commit wires up IOVA defragmentation moves using a packed temporary
copy mapping and a post-copy dependency job to transfer the IOVA
reservation and relink changed pages.
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 9f216a7d115ea..65ab974c56acc 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
[ ... ]
> @@ -1191,6 +1308,157 @@ static void xe_tt_iova_transfer(struct xe_device *xe,
> old_tt->use_iova = false;
> }
>
> +/*
> + * xe_bo_defrag_iova_copy - Run an IOVA defrag move with a packed copy mapping.
> + *
> + * Only the changed (non-borrowed) pages of @new_tt are DMA mapped, packed
> + * contiguously into the front of its reservation, the GPU copy blits them from
> + * the old tt at natural offsets, and a post-copy finalize job adopts the old
> + * tt's full reservation and relinks the changed runs. Returns the finalize
> + * job's finished fence (the fence the move waits on), or an ERR_PTR on failure
> + * with all partial state unwound.
> + */
> +static struct dma_fence *
> +xe_bo_defrag_iova_copy(struct xe_device *xe, struct xe_migrate *migrate,
> + struct xe_bo *bo, struct ttm_resource *old_mem,
> + struct ttm_resource *new_mem, struct ttm_tt *old_tt,
> + bool handle_system_ccs)
> +{
> + struct ttm_tt *new_tt = bo->ttm.ttm;
> + struct xe_ttm_tt *new_xe_tt = container_of(new_tt, struct xe_ttm_tt, ttm);
> + struct xe_ttm_tt *old_xe_tt = container_of(old_tt, struct xe_ttm_tt, ttm);
> + struct drm_sched_entity *entity =
> + xe_dep_scheduler_entity(xe->mem.defrag.iova_sched);
> + struct xe_iova_defrag_job *job;
> + struct dma_fence *copy_fence;
> + struct dma_fence *fence;
> + struct xe_tt_iova_copy copy;
> + int err;
> +
> + xe_assert(xe, new_xe_tt->iova_eligible && !new_xe_tt->use_iova);
> + xe_assert(xe, old_xe_tt->use_iova && old_xe_tt->iova_linked);
> +
> + err = xe_tt_iova_copy_init(new_tt, old_tt, ©);
> + if (err)
> + return ERR_PTR(err);
> +
> + /*
> + * TTM fails a defrag move that (re)allocates no chunk, so at least one
> + * page always differs from the old tt.
> + */
> + if (XE_WARN_ON(!copy.nr_changed)) {
> + err = -EINVAL;
> + goto err_copy;
> + }
> +
> + err = xe_tt_map_iova_copy(xe, new_tt, ©);
> + if (err)
> + goto err_copy;
> +
> + copy_fence = xe_migrate_copy_defrag_iova(migrate, bo, old_mem, new_mem,
> + old_tt, copy.nr_changed,
> + handle_system_ccs);
[Severity: Medium]
Can xe_bo_defrag_iova_copy() hit XE_WARN_ON(!fence) in __xe_migrate_copy()
when a defrag slice only upgrades Flat-CCS extra_pages?
On integrated platforms with Flat-CCS, xe_ttm_tt_create() appends CCS
extra_pages to tt->num_pages, and ttm_pool_alloc() upgrades and tracks
TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED across the full tt->num_pages array.
When a defrag pass borrows all data pages in [0, xe_bo_size(bo)) from
old_tt and only reallocates a chunk in those trailing extra_pages (for
example, on the final defrag slice of a >= 1 GB compressible BO where
extra_pages >= 512), xe_tt_iova_copy_init() walks new_tt->num_pages and
sets copy.nr_changed > 0.
However, xe_migrate_copy_defrag_iova() -> __xe_migrate_copy() only
iterates over size = xe_bo_size(src_bo). Because all pages in that range
were borrowed, xe_migrate_leading_borrowed_pages() skips the entire
buffer without emitting a job, hitting XE_WARN_ON(!fence) and returning
-EINVAL. TTM then restores old_tt with
TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED still set, leaving the BO at the head
of xe->mem.defrag.list to warn and abort the defrag worker on every retry.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=33
^ permalink raw reply [flat|nested] 59+ messages in thread
* ✗ CI.checkpatch: warning for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2)
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
` (35 preceding siblings ...)
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 ` Patchwork
2026-12-03 0:23 ` ✓ CI.KUnit: success " Patchwork
2026-12-03 0:56 ` ✓ Xe.CI.BAT: " Patchwork
38 siblings, 0 replies; 59+ messages in thread
From: Patchwork @ 2026-12-03 0:21 UTC (permalink / raw)
To: Matthew Brost; +Cc: intel-xe
== Series Details ==
Series: drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2)
URL : https://patchwork.freedesktop.org/series/180217/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt
Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master
3009867cd31863246e4afc138520a7a8bd37bb11
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit f8632602d26620e69de8c3bfe90f515e03ff8ad9
Author: Matthew Brost <matthew.brost@intel.com>
Date: Wed Dec 2 15:33:23 2026 -0800
drm/xe: Make BO defrag tunables configurable via sysfs
The BO defrag per-run size limit, default worker interval and maximum
backed off worker interval are currently fixed at build time via
Kconfig. Tuning them requires a rebuild, which makes experimenting with
defrag behaviour on a running system painful.
Add defrag_size_limit, defrag_interval_ms and defrag_interval_max_ms
device sysfs attributes, defaulting to the Kconfig values. Writes are
validated against the Kconfig ranges, the size limit must be 2M aligned,
and the default interval may not exceed the maximum interval. Lowering
the size limit below 2M (disabling defrag) remains a build time only
decision, so the attributes are only exposed when defrag is supported.
Report the runtime values in the bo_defrag debugfs entry.
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
+ /mt/dim checkpatch acd75be5933b65fbec28b648d318128a8b26593a drm-intel
bf021fa06f05 drm/ttm/pool: Allow backing off reclaim at the beneficial order
835035329f90 drm/ttm/pool: Add ttm_pool_page_order_nodma() helper
3c3fa8183164 drm/ttm: Record sub-optimal page order allocations in ttm_tt
2646f4f3b75b drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc()
9dba1b1b1468 drm/ttm: Support defragmentation moves
0eef0241cc96 drm/ttm: Add fault injection for beneficial-order allocation failures
c3ce9784df44 drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore
fd4bd4d4e0bb drm/ttm: Harvest beneficial-order pages on defragmentation moves
-:327: WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment
#327: FILE: drivers/gpu/drm/ttm/ttm_pool.c:1001:
+ * fall through to a fresh allocation, or a negative errno.
total: 0 errors, 1 warnings, 0 checks, 488 lines checked
96e3ad60a1dd drm/ttm: Bound page (re)allocation per defragmentation move
54e902d8915f drm/ttm: Preallocate beneficial-order defrag pages outside the lock
-:39: WARNING:COMMIT_LOG_LONG_LINE: Prefer a maximum 75 chars per line (possible unwrapped commit description?)
#39:
- skip p->count check in ttm_pool_iter_defrag_exhausted (Sashiko, Niranjana)
-:400: WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment
#400: FILE: drivers/gpu/drm/ttm/ttm_pool.c:1340:
+ * reclaim/compaction). Falls through once the bag is empty.
total: 0 errors, 2 warnings, 0 checks, 502 lines checked
7939166cf8b7 drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
-:319: WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment
#319: FILE: drivers/gpu/drm/ttm/ttm_pool.c:1519:
+ * taking its order from the page. Falls through to in-line allocation
total: 0 errors, 1 warnings, 0 checks, 351 lines checked
5472a612602e drm/gpusvm: Add a DMA-mapping accounting callback
3d93331eb919 drm/xe: Add debugfs stats for DMA-mapped pages per order
75be7d7af563 drm/xe: Track BOs backed at a sub-optimal page order
739326a545d7 drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies
-:67: CHECK:LINE_SPACING: Please use a blank line after function/struct/union/enum declarations
#67: FILE: drivers/gpu/drm/xe/xe_migrate.c:1295:
}
+/**
total: 0 errors, 0 warnings, 1 checks, 235 lines checked
c18d5a8fc847 drm/xe: Handle defrag moves in xe_bo_move()
-:71: WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment
#71: FILE: drivers/gpu/drm/xe/xe_bo.c:1386:
+ * For a defrag move the old and new tt differ, so fallthrough to the
total: 0 errors, 1 warnings, 0 checks, 45 lines checked
8120f9e63690 drm/xe: Skip self-copies for borrowed pages on defrag moves
6c3b35aacb96 drm/xe: Add a page defragmentation worker
a305f4d9c782 drm/xe: Add defrag GT stats
002d6bc34781 drm/xe: Add Kconfig.profile options for BO defrag configuration
-:127: WARNING:CONSTANT_COMPARISON: Comparisons should place the constant on the right side of the test
#127: FILE: drivers/gpu/drm/xe/xe_bo.c:1264:
+ BUILD_BUG_ON(XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M &&
-:155: WARNING:CONSTANT_COMPARISON: Comparisons should place the constant on the right side of the test
#155: FILE: drivers/gpu/drm/xe/xe_bo.c:1395:
+ return XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M && !IS_VF_CCS_NEEDED(xe);
total: 0 errors, 2 warnings, 0 checks, 123 lines checked
96e40a7b97d2 drm/xe: Defrag using out-of-lock page preallocation
c078d2ab72bb drm/xe: Add defrag profiling tracepoints
-:134: CHECK:OPEN_ENDED_LINE: Lines should not end with a '('
#134: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:96:
+ TP_STRUCT__entry(
-:139: CHECK:OPEN_ENDED_LINE: Lines should not end with a '('
#139: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:101:
+ TP_fast_assign(
-:155: CHECK:OPEN_ENDED_LINE: Lines should not end with a '('
#155: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:117:
+ TP_STRUCT__entry(
-:167: CHECK:OPEN_ENDED_LINE: Lines should not end with a '('
#167: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:129:
+ TP_fast_assign(
total: 0 errors, 0 warnings, 4 checks, 128 lines checked
bc5677002621 drm/xe: Preallocate system BO backing outside the dma-resv lock
d88b9d69d0d6 drm/xe: Add tracepoint for xe_gem_create_ioctl
-:89: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#89: FILE: drivers/gpu/drm/xe/xe_bo.c:4703:
+ div_u64(ktime_to_ns(ktime_sub(ktime_get(),
+ ioctl_start)), 1000),
-:108: CHECK:OPEN_ENDED_LINE: Lines should not end with a '('
#108: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:154:
+ TP_STRUCT__entry(
-:118: CHECK:OPEN_ENDED_LINE: Lines should not end with a '('
#118: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:164:
+ TP_fast_assign(
total: 0 errors, 0 warnings, 3 checks, 84 lines checked
4bdc9fe97ae6 drm/xe: Add IOVA-based xe_res_cursor variant
afd3c507f0d9 drm/xe: Don't DMA map tt pages after device unplug
e26ad7831730 drm/xe/display: Flush cleanup work on unregister
9c89cf5ebbee drm/xe: Lock the bo in xe_bo_dma_unmap_pinned()
33c6fa734308 drm/xe: Use IOVA-based DMA mapping for eligible tt BOs
792913663170 drm/xe: Add per-device dependency scheduler for IOVA defrag finalize
-:69: CHECK:BRACES: Blank lines aren't necessary after an open brace '{'
#69: FILE: drivers/gpu/drm/xe/xe_bo.c:1593:
{
+
total: 0 errors, 0 warnings, 1 checks, 59 lines checked
10644f24ec33 drm/xe: Add packed copy-step IOVA mapping for defrag
473c252c7bce drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies
17fca5cca8f6 drm/xe: Finalize defrag-IOVA moves with post-copy job
e8b0b054dffb drm/xe: Grow the USM batch pool to 2M and map it via a single PDE
aafdd9b66ddb drm/xe: Add bo_defrag debugfs entry
f8632602d266 drm/xe: Make BO defrag tunables configurable via sysfs
^ permalink raw reply [flat|nested] 59+ messages in thread
* ✓ CI.KUnit: success for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2)
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
` (36 preceding siblings ...)
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 ` Patchwork
2026-12-03 0:56 ` ✓ Xe.CI.BAT: " Patchwork
38 siblings, 0 replies; 59+ messages in thread
From: Patchwork @ 2026-12-03 0:23 UTC (permalink / raw)
To: Matthew Brost; +Cc: intel-xe
== Series Details ==
Series: drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2)
URL : https://patchwork.freedesktop.org/series/180217/
State : success
== Summary ==
+ trap cleanup EXIT
+ kunitconfigs=('/kernel/drivers/gpu/tests/.kunitconfig' '/kernel/drivers/gpu/drm/xe/.kunitconfig' '/kernel/drivers/gpu/drm/tests/.kunitconfig' '/kernel/drivers/gpu/drm/ttm/tests/.kunitconfig' '/kernel/drivers/dma-buf/.kunitconfig')
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/tests/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/tests/.kunitconfig
[00:21:42] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[00:21:47] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
[00:22:08] Starting KUnit Kernel (1/1)...
[00:22:08] ============================================================
Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[00:22:08] ================= gpu_buddy (15 subtests) ==================
[00:22:08] [PASSED] gpu_test_buddy_alloc_limit
[00:22:08] [PASSED] gpu_test_buddy_alloc_optimistic
[00:22:08] [PASSED] gpu_test_buddy_alloc_pessimistic
[00:22:08] [PASSED] gpu_test_buddy_alloc_pathological
[00:22:08] [PASSED] gpu_test_buddy_alloc_contiguous
[00:22:08] [PASSED] gpu_test_buddy_alloc_clear
[00:22:08] [PASSED] gpu_test_buddy_alloc_range
[00:22:08] [PASSED] gpu_test_buddy_alloc_range_bias
[00:22:08] [PASSED] gpu_test_buddy_alloc_range_clear_guard
[00:22:09] [PASSED] gpu_test_buddy_fragmentation_performance
[00:22:10] [PASSED] gpu_test_buddy_dirty_tracker_performance
[00:22:10] [PASSED] gpu_test_buddy_alloc_exceeds_max_order
[00:22:10] [PASSED] gpu_test_buddy_offset_aligned_allocation
[00:22:10] [PASSED] gpu_test_buddy_subtree_offset_alignment_stress
[00:22:10] [PASSED] gpu_test_buddy_addr_to_block
[00:22:10] ==================== [PASSED] gpu_buddy ====================
[00:22:10] ============================================================
[00:22:10] Testing complete. Ran 15 tests: passed: 15
[00:22:10] Elapsed time: 28.354s total, 5.210s configuring, 21.126s building, 1.988s running
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/drm/xe/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig
[00:22:10] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[00:22:13] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
[00:22:52] Starting KUnit Kernel (1/1)...
[00:22:52] ============================================================
Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[00:22:52] ================= xe_ggtt_iov (9 subtests) =================
[00:22:52] [PASSED] init_shared_pf
[00:22:52] [PASSED] init_partial_overlap
[00:22:52] [PASSED] alloc_usable_pool_low
[00:22:52] [PASSED] alloc_shareable_pool_high
[00:22:52] [PASSED] alloc_partial_overlap
[00:22:52] [PASSED] alloc_partial_overlap_usable_full
[00:22:52] [PASSED] alloc_partial_overlap_shareable_full
[00:22:52] [PASSED] alloc_shareable_pool_unavailable
[00:22:52] [PASSED] alloc_shareable_pool_oversized
[00:22:52] =================== [PASSED] xe_ggtt_iov ===================
[00:22:52] =================== xe_ggtt (3 subtests) ===================
[00:22:52] [PASSED] init_native
[00:22:52] [PASSED] alloc_usable_pool_native
[00:22:52] [PASSED] alloc_usable_pool_oversized
[00:22:52] ===================== [PASSED] xe_ggtt =====================
[00:22:52] ================== guc_buf (11 subtests) ===================
[00:22:52] [PASSED] test_smallest
[00:22:52] [PASSED] test_largest
[00:22:52] [PASSED] test_granular
[00:22:52] [PASSED] test_unique
[00:22:52] [PASSED] test_overlap
[00:22:52] [PASSED] test_reusable
[00:22:52] [PASSED] test_too_big
[00:22:52] [PASSED] test_flush
[00:22:52] [PASSED] test_lookup
[00:22:52] [PASSED] test_data
[00:22:52] [PASSED] test_class
[00:22:52] ===================== [PASSED] guc_buf =====================
[00:22:52] =================== guc_dbm (7 subtests) ===================
[00:22:52] [PASSED] test_empty
[00:22:52] [PASSED] test_default
[00:22:52] ======================== test_size ========================
[00:22:52] [PASSED] 4
[00:22:52] [PASSED] 8
[00:22:52] [PASSED] 32
[00:22:52] [PASSED] 256
[00:22:52] ==================== [PASSED] test_size ====================
[00:22:52] ======================= test_reuse ========================
[00:22:52] [PASSED] 4
[00:22:52] [PASSED] 8
[00:22:52] [PASSED] 32
[00:22:52] [PASSED] 256
[00:22:52] =================== [PASSED] test_reuse ====================
[00:22:52] =================== test_range_overlap ====================
[00:22:52] [PASSED] 4
[00:22:52] [PASSED] 8
[00:22:52] [PASSED] 32
[00:22:52] [PASSED] 256
[00:22:52] =============== [PASSED] test_range_overlap ================
[00:22:52] =================== test_range_compact ====================
[00:22:52] [PASSED] 4
[00:22:52] [PASSED] 8
[00:22:52] [PASSED] 32
[00:22:52] [PASSED] 256
[00:22:52] =============== [PASSED] test_range_compact ================
[00:22:52] ==================== test_range_spare =====================
[00:22:52] [PASSED] 4
[00:22:52] [PASSED] 8
[00:22:52] [PASSED] 32
[00:22:52] [PASSED] 256
[00:22:52] ================ [PASSED] test_range_spare =================
[00:22:52] ===================== [PASSED] guc_dbm =====================
[00:22:52] ================== guc_idm (22 subtests) ===================
[00:22:52] [PASSED] bad_init
[00:22:52] [PASSED] no_init
[00:22:52] [PASSED] init_fini
[00:22:52] [PASSED] check_init_small
[00:22:52] [PASSED] check_init_shared
[00:22:52] [PASSED] check_used
[00:22:52] [PASSED] check_quota
[00:22:52] [PASSED] check_all
[00:22:52] [PASSED] check_limits
[00:22:52] [PASSED] check_overlap
[00:22:52] [PASSED] check_overlap_alloc
[00:22:52] [PASSED] check_overlap_release
[00:22:52] [PASSED] check_overlap_partial_init
[00:22:52] [PASSED] check_overlap_partial_shared_range_blocking
[00:22:52] [PASSED] check_used_usable
[00:22:52] [PASSED] check_used_shareable
[00:22:52] [PASSED] check_used_mixed
[00:22:52] [PASSED] check_release_usable_range
[00:22:52] [PASSED] check_release_shareable_range
[00:22:52] [PASSED] check_split_boundaries
[00:22:52] [PASSED] check_shareable_spare
[00:22:52] [PASSED] check_shareable_spare_fragmented_tail
[00:22:52] ===================== [PASSED] guc_idm =====================
[00:22:52] ============== guc_klv_helpers (13 subtests) ===============
[00:22:52] [PASSED] test_count
[00:22:52] [PASSED] test_encode_u32
[00:22:52] [PASSED] test_encode_u64
[00:22:52] [PASSED] test_encode_string
[00:22:52] [PASSED] test_encode_object_raw
[00:22:52] [PASSED] test_encode_object_klv
[00:22:52] [PASSED] test_encode_object_nested
[00:22:52] [PASSED] test_encode_object_basic
[00:22:52] ===================== test_decode_u16 =====================
[00:22:52] [PASSED] empty
[00:22:52] [PASSED] valid
[00:22:52] [PASSED] max
[00:22:52] [PASSED] big
[00:22:52] [PASSED] long
[00:22:52] ================= [PASSED] test_decode_u16 =================
[00:22:52] ===================== test_decode_u32 =====================
[00:22:52] [PASSED] empty
[00:22:52] [PASSED] valid
[00:22:52] [PASSED] max
[00:22:52] [PASSED] long
[00:22:52] ================= [PASSED] test_decode_u32 =================
[00:22:52] ===================== test_decode_u64 =====================
[00:22:52] [PASSED] empty
[00:22:52] [PASSED] short
[00:22:52] [PASSED] valid
[00:22:52] [PASSED] max
[00:22:52] [PASSED] long
[00:22:52] ================= [PASSED] test_decode_u64 =================
[00:22:52] ===================== test_decode_str =====================
[00:22:52] [PASSED] empty
[00:22:52] [PASSED] one
[00:22:52] [PASSED] one_trash
[00:22:52] [PASSED] two
[00:22:52] [PASSED] two_trash
[00:22:52] [PASSED] three
[00:22:52] [PASSED] dword
[00:22:52] [PASSED] four
[00:22:52] [PASSED] five
[00:22:52] [PASSED] six
[00:22:52] [PASSED] seven
[00:22:52] [PASSED] qword
[00:22:52] ================= [PASSED] test_decode_str =================
[00:22:52] [PASSED] test_print
[00:22:52] ================= [PASSED] guc_klv_helpers =================
[00:22:52] =================== xe_log (6 subtests) ====================
[00:22:52] [PASSED] demo_cper
[00:22:52] [PASSED] demo_dmesg
[00:22:52] [PASSED] test_cper_null_xe
[00:22:52] ======================= test_dmesg ========================
[00:22:52] [PASSED] test_fatal
[00:22:52] [PASSED] test_fatal_tile
[00:22:52] [PASSED] test_fatal_gt
[00:22:52] [PASSED] test_fatal_comp
[00:22:52] [PASSED] test_fatal_comp_tile
[00:22:52] [PASSED] test_fatal_comp_gt
[00:22:52] [PASSED] test_fatal_all
[00:22:52] [PASSED] test_recoverable
[00:22:52] [PASSED] test_recoverable_tile
[00:22:52] [PASSED] test_recoverable_gt
[00:22:52] [PASSED] test_recoverable_comp
[00:22:52] [PASSED] test_recoverable_comp_tile
[00:22:52] [PASSED] test_recoverable_comp_gt
[00:22:52] [PASSED] test_recoverable_all
[00:22:52] [PASSED] test_info
[00:22:52] [PASSED] test_info_tile
[00:22:52] [PASSED] test_info_gt
[00:22:52] [PASSED] test_info_err
[00:22:52] [PASSED] test_info_comp
[00:22:52] [PASSED] test_info_comp_tile
[00:22:52] [PASSED] test_info_comp_gt
[00:22:52] [PASSED] test_info_all
[00:22:52] [PASSED] test_hw_fatal
[00:22:52] [PASSED] test_hw_recoverable
[00:22:52] [PASSED] test_hw_corrected
[00:22:52] [PASSED] test_hw_informational
[00:22:52] =================== [PASSED] test_dmesg ====================
[00:22:52] ====================== test_sw_cper =======================
[00:22:52] [PASSED] sw-fatal-errno
[00:22:52] [PASSED] sw-recoverable-errno
[00:22:52] [PASSED] sw-corrected
[00:22:52] [PASSED] sw-informational
[00:22:52] [PASSED] sw-with-error-class
[00:22:52] ================== [PASSED] test_sw_cper ===================
[00:22:52] ====================== test_invalid =======================
[00:22:52] [SKIPPED] no-component no-location no-warn (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] reserved location (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] unknown location (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] nonzero-device-id location (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] invalid-tile-id location (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] invalid-gt-id location (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] unknown component class (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] unknown system component (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] unknown hardware component (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] [SKIPPED] unknown component and location (requires CONFIG_DRM_XE_DEBUG)
[00:22:52] ================== [SKIPPED] test_invalid ==================
[00:22:52] ===================== [PASSED] xe_log ======================
[00:22:52] ================== no_relay (3 subtests) ===================
[00:22:52] [PASSED] xe_drops_guc2pf_if_not_ready
[00:22:52] [PASSED] xe_drops_guc2vf_if_not_ready
[00:22:52] [PASSED] xe_rejects_send_if_not_ready
[00:22:52] ==================== [PASSED] no_relay =====================
[00:22:52] ================== pf_relay (14 subtests) ==================
[00:22:52] [PASSED] pf_rejects_guc2pf_too_short
[00:22:52] [PASSED] pf_rejects_guc2pf_too_long
[00:22:52] [PASSED] pf_rejects_guc2pf_no_payload
[00:22:52] [PASSED] pf_fails_no_payload
[00:22:52] [PASSED] pf_fails_bad_origin
[00:22:52] [PASSED] pf_fails_bad_type
[00:22:52] [PASSED] pf_txn_reports_error
[00:22:52] [PASSED] pf_txn_sends_pf2guc
[00:22:52] [PASSED] pf_sends_pf2guc
[00:22:52] [SKIPPED] pf_loopback_nop (requires CONFIG_DRM_XE_DEBUG_SRIOV)
[00:22:52] [SKIPPED] pf_loopback_echo (requires CONFIG_DRM_XE_DEBUG_SRIOV)
[00:22:52] [SKIPPED] pf_loopback_fail (requires CONFIG_DRM_XE_DEBUG_SRIOV)
[00:22:52] [SKIPPED] pf_loopback_busy (requires CONFIG_DRM_XE_DEBUG_SRIOV)
[00:22:52] [SKIPPED] pf_loopback_retry (requires CONFIG_DRM_XE_DEBUG_SRIOV)
[00:22:52] ==================== [PASSED] pf_relay =====================
[00:22:52] ================== vf_relay (3 subtests) ===================
[00:22:52] [PASSED] vf_rejects_guc2vf_too_short
[00:22:52] [PASSED] vf_rejects_guc2vf_too_long
[00:22:52] [PASSED] vf_rejects_guc2vf_no_payload
[00:22:52] ==================== [PASSED] vf_relay =====================
[00:22:52] ================ pf_gt_config (9 subtests) =================
[00:22:52] [PASSED] fair_contexts_1vf
[00:22:52] [PASSED] fair_doorbells_1vf
[00:22:52] [PASSED] fair_ggtt_1vf
[00:22:52] ====================== fair_vram_1vf ======================
[00:22:52] [PASSED] 3.50 GiB
[00:22:52] [PASSED] 11.5 GiB
[00:22:52] [PASSED] 15.5 GiB
[00:22:52] [PASSED] 31.5 GiB
[00:22:52] [PASSED] 63.5 GiB
[00:22:52] [PASSED] 1.91 GiB
[00:22:52] ================== [PASSED] fair_vram_1vf ==================
[00:22:52] ================ fair_vram_1vf_admin_only =================
[00:22:52] [PASSED] 3.50 GiB
[00:22:52] [PASSED] 11.5 GiB
[00:22:52] [PASSED] 15.5 GiB
[00:22:52] [PASSED] 31.5 GiB
[00:22:52] [PASSED] 63.5 GiB
[00:22:52] [PASSED] 1.91 GiB
[00:22:52] ============ [PASSED] fair_vram_1vf_admin_only =============
[00:22:52] ====================== fair_contexts ======================
[00:22:52] [PASSED] 1 VF
[00:22:52] [PASSED] 2 VFs
[00:22:52] [PASSED] 3 VFs
[00:22:52] [PASSED] 4 VFs
[00:22:52] [PASSED] 5 VFs
[00:22:52] [PASSED] 6 VFs
[00:22:52] [PASSED] 7 VFs
[00:22:52] [PASSED] 8 VFs
[00:22:52] [PASSED] 9 VFs
[00:22:52] [PASSED] 10 VFs
[00:22:52] [PASSED] 11 VFs
[00:22:52] [PASSED] 12 VFs
[00:22:52] [PASSED] 13 VFs
[00:22:52] [PASSED] 14 VFs
[00:22:52] [PASSED] 15 VFs
[00:22:52] [PASSED] 16 VFs
[00:22:52] [PASSED] 17 VFs
[00:22:52] [PASSED] 18 VFs
[00:22:52] [PASSED] 19 VFs
[00:22:52] [PASSED] 20 VFs
[00:22:52] [PASSED] 21 VFs
[00:22:52] [PASSED] 22 VFs
[00:22:52] [PASSED] 23 VFs
[00:22:52] [PASSED] 24 VFs
[00:22:52] [PASSED] 25 VFs
[00:22:52] [PASSED] 26 VFs
[00:22:52] [PASSED] 27 VFs
[00:22:52] [PASSED] 28 VFs
[00:22:52] [PASSED] 29 VFs
[00:22:52] [PASSED] 30 VFs
[00:22:52] [PASSED] 31 VFs
[00:22:52] [PASSED] 32 VFs
[00:22:52] [PASSED] 33 VFs
[00:22:52] [PASSED] 34 VFs
[00:22:52] [PASSED] 35 VFs
[00:22:52] [PASSED] 36 VFs
[00:22:52] [PASSED] 37 VFs
[00:22:52] [PASSED] 38 VFs
[00:22:52] [PASSED] 39 VFs
[00:22:52] [PASSED] 40 VFs
[00:22:52] [PASSED] 41 VFs
[00:22:52] [PASSED] 42 VFs
[00:22:52] [PASSED] 43 VFs
[00:22:52] [PASSED] 44 VFs
[00:22:52] [PASSED] 45 VFs
[00:22:52] [PASSED] 46 VFs
[00:22:52] [PASSED] 47 VFs
[00:22:52] [PASSED] 48 VFs
[00:22:52] [PASSED] 49 VFs
[00:22:52] [PASSED] 50 VFs
[00:22:52] [PASSED] 51 VFs
[00:22:52] [PASSED] 52 VFs
[00:22:52] [PASSED] 53 VFs
[00:22:52] [PASSED] 54 VFs
[00:22:52] [PASSED] 55 VFs
[00:22:52] [PASSED] 56 VFs
[00:22:52] [PASSED] 57 VFs
[00:22:52] [PASSED] 58 VFs
[00:22:52] [PASSED] 59 VFs
[00:22:52] [PASSED] 60 VFs
[00:22:52] [PASSED] 61 VFs
[00:22:52] [PASSED] 62 VFs
[00:22:52] [PASSED] 63 VFs
[00:22:52] ================== [PASSED] fair_contexts ==================
[00:22:52] ===================== fair_doorbells ======================
[00:22:52] [PASSED] 1 VF
[00:22:52] [PASSED] 2 VFs
[00:22:52] [PASSED] 3 VFs
[00:22:52] [PASSED] 4 VFs
[00:22:52] [PASSED] 5 VFs
[00:22:52] [PASSED] 6 VFs
[00:22:52] [PASSED] 7 VFs
[00:22:52] [PASSED] 8 VFs
[00:22:52] [PASSED] 9 VFs
[00:22:52] [PASSED] 10 VFs
[00:22:52] [PASSED] 11 VFs
[00:22:52] [PASSED] 12 VFs
[00:22:52] [PASSED] 13 VFs
[00:22:52] [PASSED] 14 VFs
[00:22:52] [PASSED] 15 VFs
[00:22:52] [PASSED] 16 VFs
[00:22:52] [PASSED] 17 VFs
[00:22:52] [PASSED] 18 VFs
[00:22:52] [PASSED] 19 VFs
[00:22:52] [PASSED] 20 VFs
[00:22:52] [PASSED] 21 VFs
[00:22:52] [PASSED] 22 VFs
[00:22:52] [PASSED] 23 VFs
[00:22:52] [PASSED] 24 VFs
[00:22:52] [PASSED] 25 VFs
[00:22:52] [PASSED] 26 VFs
[00:22:52] [PASSED] 27 VFs
[00:22:52] [PASSED] 28 VFs
[00:22:52] [PASSED] 29 VFs
[00:22:52] [PASSED] 30 VFs
[00:22:52] [PASSED] 31 VFs
[00:22:52] [PASSED] 32 VFs
[00:22:52] [PASSED] 33 VFs
[00:22:52] [PASSED] 34 VFs
[00:22:52] [PASSED] 35 VFs
[00:22:52] [PASSED] 36 VFs
[00:22:52] [PASSED] 37 VFs
[00:22:52] [PASSED] 38 VFs
[00:22:52] [PASSED] 39 VFs
[00:22:52] [PASSED] 40 VFs
[00:22:52] [PASSED] 41 VFs
[00:22:52] [PASSED] 42 VFs
[00:22:52] [PASSED] 43 VFs
[00:22:52] [PASSED] 44 VFs
[00:22:52] [PASSED] 45 VFs
[00:22:52] [PASSED] 46 VFs
[00:22:52] [PASSED] 47 VFs
[00:22:52] [PASSED] 48 VFs
[00:22:52] [PASSED] 49 VFs
[00:22:52] [PASSED] 50 VFs
[00:22:52] [PASSED] 51 VFs
[00:22:52] [PASSED] 52 VFs
[00:22:52] [PASSED] 53 VFs
[00:22:52] [PASSED] 54 VFs
[00:22:52] [PASSED] 55 VFs
[00:22:52] [PASSED] 56 VFs
[00:22:52] [PASSED] 57 VFs
[00:22:52] [PASSED] 58 VFs
[00:22:52] [PASSED] 59 VFs
[00:22:52] [PASSED] 60 VFs
[00:22:52] [PASSED] 61 VFs
[00:22:52] [PASSED] 62 VFs
[00:22:52] [PASSED] 63 VFs
[00:22:52] ================= [PASSED] fair_doorbells ==================
[00:22:52] ======================== fair_ggtt ========================
[00:22:52] [PASSED] 1 VF
[00:22:52] [PASSED] 2 VFs
[00:22:52] [PASSED] 3 VFs
[00:22:52] [PASSED] 4 VFs
[00:22:52] [PASSED] 5 VFs
[00:22:52] [PASSED] 6 VFs
[00:22:52] [PASSED] 7 VFs
[00:22:52] [PASSED] 8 VFs
[00:22:52] [PASSED] 9 VFs
[00:22:52] [PASSED] 10 VFs
[00:22:52] [PASSED] 11 VFs
[00:22:52] [PASSED] 12 VFs
[00:22:52] [PASSED] 13 VFs
[00:22:52] [PASSED] 14 VFs
[00:22:52] [PASSED] 15 VFs
[00:22:52] [PASSED] 16 VFs
[00:22:52] [PASSED] 17 VFs
[00:22:52] [PASSED] 18 VFs
[00:22:52] [PASSED] 19 VFs
[00:22:52] [PASSED] 20 VFs
[00:22:52] [PASSED] 21 VFs
[00:22:52] [PASSED] 22 VFs
[00:22:52] [PASSED] 23 VFs
[00:22:52] [PASSED] 24 VFs
[00:22:52] [PASSED] 25 VFs
[00:22:52] [PASSED] 26 VFs
[00:22:52] [PASSED] 27 VFs
[00:22:52] [PASSED] 28 VFs
[00:22:52] [PASSED] 29 VFs
[00:22:52] [PASSED] 30 VFs
[00:22:52] [PASSED] 31 VFs
[00:22:52] [PASSED] 32 VFs
[00:22:52] [PASSED] 33 VFs
[00:22:52] [PASSED] 34 VFs
[00:22:52] [PASSED] 35 VFs
[00:22:52] [PASSED] 36 VFs
[00:22:52] [PASSED] 37 VFs
[00:22:52] [PASSED] 38 VFs
[00:22:52] [PASSED] 39 VFs
[00:22:52] [PASSED] 40 VFs
[00:22:52] [PASSED] 41 VFs
[00:22:52] [PASSED] 42 VFs
[00:22:52] [PASSED] 43 VFs
[00:22:52] [PASSED] 44 VFs
[00:22:52] [PASSED] 45 VFs
[00:22:52] [PASSED] 46 VFs
[00:22:52] [PASSED] 47 VFs
[00:22:52] [PASSED] 48 VFs
[00:22:52] [PASSED] 49 VFs
[00:22:52] [PASSED] 50 VFs
[00:22:52] [PASSED] 51 VFs
[00:22:52] [PASSED] 52 VFs
[00:22:52] [PASSED] 53 VFs
[00:22:52] [PASSED] 54 VFs
[00:22:52] [PASSED] 55 VFs
[00:22:52] [PASSED] 56 VFs
[00:22:52] [PASSED] 57 VFs
[00:22:52] [PASSED] 58 VFs
[00:22:52] [PASSED] 59 VFs
[00:22:52] [PASSED] 60 VFs
[00:22:52] [PASSED] 61 VFs
[00:22:52] [PASSED] 62 VFs
[00:22:52] [PASSED] 63 VFs
[00:22:52] ==================== [PASSED] fair_ggtt ====================
[00:22:52] ======================== fair_vram ========================
[00:22:52] [PASSED] 1 VF
[00:22:52] [PASSED] 2 VFs
[00:22:52] [PASSED] 3 VFs
[00:22:52] [PASSED] 4 VFs
[00:22:52] [PASSED] 5 VFs
[00:22:52] [PASSED] 6 VFs
[00:22:52] [PASSED] 7 VFs
[00:22:52] [PASSED] 8 VFs
[00:22:52] [PASSED] 9 VFs
[00:22:52] [PASSED] 10 VFs
[00:22:52] [PASSED] 11 VFs
[00:22:52] [PASSED] 12 VFs
[00:22:52] [PASSED] 13 VFs
[00:22:52] [PASSED] 14 VFs
[00:22:52] [PASSED] 15 VFs
[00:22:52] [PASSED] 16 VFs
[00:22:52] [PASSED] 17 VFs
[00:22:52] [PASSED] 18 VFs
[00:22:52] [PASSED] 19 VFs
[00:22:52] [PASSED] 20 VFs
[00:22:52] [PASSED] 21 VFs
[00:22:52] [PASSED] 22 VFs
[00:22:52] [PASSED] 23 VFs
[00:22:52] [PASSED] 24 VFs
[00:22:52] [PASSED] 25 VFs
[00:22:52] [PASSED] 26 VFs
[00:22:52] [PASSED] 27 VFs
[00:22:52] [PASSED] 28 VFs
[00:22:52] [PASSED] 29 VFs
[00:22:52] [PASSED] 30 VFs
[00:22:52] [PASSED] 31 VFs
[00:22:52] [PASSED] 32 VFs
[00:22:52] [PASSED] 33 VFs
[00:22:52] [PASSED] 34 VFs
[00:22:52] [PASSED] 35 VFs
[00:22:52] [PASSED] 36 VFs
[00:22:52] [PASSED] 37 VFs
[00:22:52] [PASSED] 38 VFs
[00:22:52] [PASSED] 39 VFs
[00:22:52] [PASSED] 40 VFs
[00:22:52] [PASSED] 41 VFs
[00:22:52] [PASSED] 42 VFs
[00:22:52] [PASSED] 43 VFs
[00:22:52] [PASSED] 44 VFs
[00:22:52] [PASSED] 45 VFs
[00:22:52] [PASSED] 46 VFs
[00:22:52] [PASSED] 47 VFs
[00:22:52] [PASSED] 48 VFs
[00:22:52] [PASSED] 49 VFs
[00:22:52] [PASSED] 50 VFs
[00:22:52] [PASSED] 51 VFs
[00:22:52] [PASSED] 52 VFs
[00:22:52] [PASSED] 53 VFs
[00:22:52] [PASSED] 54 VFs
[00:22:53] [PASSED] 55 VFs
[00:22:53] [PASSED] 56 VFs
[00:22:53] [PASSED] 57 VFs
[00:22:53] [PASSED] 58 VFs
[00:22:53] [PASSED] 59 VFs
[00:22:53] [PASSED] 60 VFs
[00:22:53] [PASSED] 61 VFs
[00:22:53] [PASSED] 62 VFs
[00:22:53] [PASSED] 63 VFs
[00:22:53] ==================== [PASSED] fair_vram ====================
[00:22:53] ================== [PASSED] pf_gt_config ===================
[00:22:53] ===================== lmtt (1 subtest) =====================
[00:22:53] ======================== test_ops =========================
[00:22:53] [PASSED] 2-level
[00:22:53] [PASSED] multi-level
[00:22:53] ==================== [PASSED] test_ops =====================
[00:22:53] ====================== [PASSED] lmtt =======================
[00:22:53] ================= sriov_packet (1 subtest) =================
[00:22:53] [PASSED] test_descriptor_init
[00:22:53] ================== [PASSED] sriov_packet ===================
[00:22:53] ================= pf_service (11 subtests) =================
[00:22:53] [PASSED] pf_negotiate_any
[00:22:53] [PASSED] pf_negotiate_base_match
[00:22:53] [PASSED] pf_negotiate_base_newer
[00:22:53] [PASSED] pf_negotiate_base_next
[00:22:53] [SKIPPED] pf_negotiate_base_older (no older minor)
[00:22:53] [PASSED] pf_negotiate_base_prev
[00:22:53] [PASSED] pf_negotiate_latest_match
[00:22:53] [PASSED] pf_negotiate_latest_newer
[00:22:53] [PASSED] pf_negotiate_latest_next
[00:22:53] [SKIPPED] pf_negotiate_latest_older (no older minor)
[00:22:53] [SKIPPED] pf_negotiate_latest_prev (no prev major)
[00:22:53] =================== [PASSED] pf_service ====================
[00:22:53] ================= xe_guc_g2g (2 subtests) ==================
[00:22:53] ============== xe_live_guc_g2g_kunit_default ==============
[00:22:53] ========= [SKIPPED] xe_live_guc_g2g_kunit_default ==========
[00:22:53] ============== xe_live_guc_g2g_kunit_allmem ===============
[00:22:53] ========== [SKIPPED] xe_live_guc_g2g_kunit_allmem ==========
[00:22:53] =================== [SKIPPED] xe_guc_g2g ===================
[00:22:53] =================== xe_mocs (2 subtests) ===================
[00:22:53] ================ xe_live_mocs_kernel_kunit ================
[00:22:53] =========== [SKIPPED] xe_live_mocs_kernel_kunit ============
[00:22:53] ================ xe_live_mocs_reset_kunit =================
[00:22:53] ============ [SKIPPED] xe_live_mocs_reset_kunit ============
[00:22:53] ==================== [SKIPPED] xe_mocs =====================
[00:22:53] ================= xe_migrate (3 subtests) ==================
[00:22:53] ================= xe_migrate_sanity_kunit =================
[00:22:53] ============ [SKIPPED] xe_migrate_sanity_kunit =============
[00:22:53] ================== xe_validate_ccs_kunit ==================
[00:22:53] ============= [SKIPPED] xe_validate_ccs_kunit ==============
[00:22:53] ============= xe_migrate_access_memory_kunit ==============
[00:22:53] ========= [SKIPPED] xe_migrate_access_memory_kunit =========
[00:22:53] =================== [SKIPPED] xe_migrate ===================
[00:22:53] ================== xe_dma_buf (1 subtest) ==================
[00:22:53] ==================== xe_dma_buf_kunit =====================
[00:22:53] ================ [SKIPPED] xe_dma_buf_kunit ================
[00:22:53] =================== [SKIPPED] xe_dma_buf ===================
[00:22:53] ================= xe_bo_shrink (1 subtest) =================
[00:22:53] =================== xe_bo_shrink_kunit ====================
[00:22:53] =============== [SKIPPED] xe_bo_shrink_kunit ===============
[00:22:53] ================== [SKIPPED] xe_bo_shrink ==================
[00:22:53] ==================== xe_bo (2 subtests) ====================
[00:22:53] ================== xe_ccs_migrate_kunit ===================
[00:22:53] ============== [SKIPPED] xe_ccs_migrate_kunit ==============
[00:22:53] ==================== xe_bo_evict_kunit ====================
[00:22:53] =============== [SKIPPED] xe_bo_evict_kunit ================
[00:22:53] ===================== [SKIPPED] xe_bo ======================
[00:22:53] =================== xe_any (9 subtests) ====================
[00:22:53] [PASSED] test_to_xe
[00:22:53] [PASSED] test_to_dev
[00:22:53] [PASSED] test_to_pdev
[00:22:53] [PASSED] test_to_drm
[00:22:53] [PASSED] test_if_pdev
[00:22:53] [PASSED] test_if_xe
[00:22:53] [PASSED] test_if_tile
[00:22:53] [PASSED] test_if_gt
[00:22:53] [PASSED] test_to_id
[00:22:53] ===================== [PASSED] xe_any ======================
[00:22:53] ==================== args (13 subtests) ====================
[00:22:53] [PASSED] count_args_test
[00:22:53] [PASSED] call_args_example
[00:22:53] [PASSED] call_args_test
[00:22:53] [PASSED] drop_first_arg_example
[00:22:53] [PASSED] drop_first_arg_test
[00:22:53] [PASSED] first_arg_example
[00:22:53] [PASSED] first_arg_test
[00:22:53] [PASSED] last_arg_example
[00:22:53] [PASSED] last_arg_test
[00:22:53] [PASSED] pick_arg_example
[00:22:53] [PASSED] if_args_example
[00:22:53] [PASSED] if_args_test
[00:22:53] [PASSED] sep_comma_example
[00:22:53] ====================== [PASSED] args =======================
[00:22:53] =================== xe_pci (3 subtests) ====================
[00:22:53] ==================== check_graphics_ip ====================
[00:22:53] [PASSED] 12.00 Xe_LP
[00:22:53] [PASSED] 12.10 Xe_LP+
[00:22:53] [PASSED] 12.55 Xe_HPG
[00:22:53] [PASSED] 12.60 Xe_HPC
[00:22:53] [PASSED] 12.70 Xe_LPG
[00:22:53] [PASSED] 12.71 Xe_LPG
[00:22:53] [PASSED] 12.74 Xe_LPG+
[00:22:53] [PASSED] 20.01 Xe2_HPG
[00:22:53] [PASSED] 20.02 Xe2_HPG
[00:22:53] [PASSED] 20.04 Xe2_LPG
[00:22:53] [PASSED] 30.00 Xe3_LPG
[00:22:53] [PASSED] 30.01 Xe3_LPG
[00:22:53] [PASSED] 30.03 Xe3_LPG
[00:22:53] [PASSED] 30.04 Xe3_LPG
[00:22:53] [PASSED] 30.05 Xe3_LPG
[00:22:53] [PASSED] 35.10 Xe3p_LPG
[00:22:53] [PASSED] 35.11 Xe3p_XPC
[00:22:53] ================ [PASSED] check_graphics_ip ================
[00:22:53] ===================== check_media_ip ======================
[00:22:53] [PASSED] 12.00 Xe_M
[00:22:53] [PASSED] 12.55 Xe_HPM
[00:22:53] [PASSED] 13.00 Xe_LPM+
[00:22:53] [PASSED] 13.01 Xe2_HPM
[00:22:53] [PASSED] 20.00 Xe2_LPM
[00:22:53] [PASSED] 30.00 Xe3_LPM
[00:22:53] [PASSED] 30.02 Xe3_LPM
[00:22:53] [PASSED] 35.00 Xe3p_LPM
[00:22:53] [PASSED] 35.03 Xe3p_HPM
[00:22:53] ================= [PASSED] check_media_ip ==================
[00:22:53] =================== check_platform_desc ===================
[00:22:53] [PASSED] 0x9A60 (TIGERLAKE)
[00:22:53] [PASSED] 0x9A68 (TIGERLAKE)
[00:22:53] [PASSED] 0x9A70 (TIGERLAKE)
[00:22:53] [PASSED] 0x9A40 (TIGERLAKE)
[00:22:53] [PASSED] 0x9A49 (TIGERLAKE)
[00:22:53] [PASSED] 0x9A59 (TIGERLAKE)
[00:22:53] [PASSED] 0x9A78 (TIGERLAKE)
[00:22:53] [PASSED] 0x9AC0 (TIGERLAKE)
[00:22:53] [PASSED] 0x9AC9 (TIGERLAKE)
[00:22:53] [PASSED] 0x9AD9 (TIGERLAKE)
[00:22:53] [PASSED] 0x9AF8 (TIGERLAKE)
[00:22:53] [PASSED] 0x4C80 (ROCKETLAKE)
[00:22:53] [PASSED] 0x4C8A (ROCKETLAKE)
[00:22:53] [PASSED] 0x4C8B (ROCKETLAKE)
[00:22:53] [PASSED] 0x4C8C (ROCKETLAKE)
[00:22:53] [PASSED] 0x4C90 (ROCKETLAKE)
[00:22:53] [PASSED] 0x4C9A (ROCKETLAKE)
[00:22:53] [PASSED] 0x4680 (ALDERLAKE_S)
[00:22:53] [PASSED] 0x4682 (ALDERLAKE_S)
[00:22:53] [PASSED] 0x4688 (ALDERLAKE_S)
[00:22:53] [PASSED] 0x468A (ALDERLAKE_S)
[00:22:53] [PASSED] 0x468B (ALDERLAKE_S)
[00:22:53] [PASSED] 0x4690 (ALDERLAKE_S)
[00:22:53] [PASSED] 0x4692 (ALDERLAKE_S)
[00:22:53] [PASSED] 0x4693 (ALDERLAKE_S)
[00:22:53] [PASSED] 0x46A0 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46A1 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46A2 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46A3 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46A6 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46A8 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46AA (ALDERLAKE_P)
[00:22:53] [PASSED] 0x462A (ALDERLAKE_P)
[00:22:53] [PASSED] 0x4626 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x4628 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46B0 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46B1 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46B2 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46B3 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46C0 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46C1 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46C2 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46C3 (ALDERLAKE_P)
[00:22:53] [PASSED] 0x46D0 (ALDERLAKE_N)
[00:22:53] [PASSED] 0x46D1 (ALDERLAKE_N)
[00:22:53] [PASSED] 0x46D2 (ALDERLAKE_N)
[00:22:53] [PASSED] 0x46D3 (ALDERLAKE_N)
[00:22:53] [PASSED] 0x46D4 (ALDERLAKE_N)
[00:22:53] [PASSED] 0xA721 (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7A1 (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7A9 (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7AC (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7AD (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA720 (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7A0 (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7A8 (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7AA (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA7AB (ALDERLAKE_P)
[00:22:53] [PASSED] 0xA780 (ALDERLAKE_S)
[00:22:53] [PASSED] 0xA781 (ALDERLAKE_S)
[00:22:53] [PASSED] 0xA782 (ALDERLAKE_S)
[00:22:53] [PASSED] 0xA783 (ALDERLAKE_S)
[00:22:53] [PASSED] 0xA788 (ALDERLAKE_S)
[00:22:53] [PASSED] 0xA789 (ALDERLAKE_S)
[00:22:53] [PASSED] 0xA78A (ALDERLAKE_S)
[00:22:53] [PASSED] 0xA78B (ALDERLAKE_S)
[00:22:53] [PASSED] 0x4905 (DG1)
[00:22:53] [PASSED] 0x4906 (DG1)
[00:22:53] [PASSED] 0x4907 (DG1)
[00:22:53] [PASSED] 0x4908 (DG1)
[00:22:53] [PASSED] 0x4909 (DG1)
[00:22:53] [PASSED] 0x56C0 (DG2)
[00:22:53] [PASSED] 0x56C2 (DG2)
[00:22:53] [PASSED] 0x56C1 (DG2)
[00:22:53] [PASSED] 0x7D51 (METEORLAKE)
[00:22:53] [PASSED] 0x7DD1 (METEORLAKE)
[00:22:53] [PASSED] 0x7D41 (METEORLAKE)
[00:22:53] [PASSED] 0x7D67 (METEORLAKE)
[00:22:53] [PASSED] 0xB640 (METEORLAKE)
[00:22:53] [PASSED] 0x56A0 (DG2)
[00:22:53] [PASSED] 0x56A1 (DG2)
[00:22:53] [PASSED] 0x56A2 (DG2)
[00:22:53] [PASSED] 0x56BE (DG2)
[00:22:53] [PASSED] 0x56BF (DG2)
[00:22:53] [PASSED] 0x5690 (DG2)
[00:22:53] [PASSED] 0x5691 (DG2)
[00:22:53] [PASSED] 0x5692 (DG2)
[00:22:53] [PASSED] 0x56A5 (DG2)
[00:22:53] [PASSED] 0x56A6 (DG2)
[00:22:53] [PASSED] 0x56B0 (DG2)
[00:22:53] [PASSED] 0x56B1 (DG2)
[00:22:53] [PASSED] 0x56BA (DG2)
[00:22:53] [PASSED] 0x56BB (DG2)
[00:22:53] [PASSED] 0x56BC (DG2)
[00:22:53] [PASSED] 0x56BD (DG2)
[00:22:53] [PASSED] 0x5693 (DG2)
[00:22:53] [PASSED] 0x5694 (DG2)
[00:22:53] [PASSED] 0x5695 (DG2)
[00:22:53] [PASSED] 0x56A3 (DG2)
[00:22:53] [PASSED] 0x56A4 (DG2)
[00:22:53] [PASSED] 0x56B2 (DG2)
[00:22:53] [PASSED] 0x56B3 (DG2)
[00:22:53] [PASSED] 0x5696 (DG2)
[00:22:53] [PASSED] 0x5697 (DG2)
[00:22:53] [PASSED] 0xB69 (PVC)
[00:22:53] [PASSED] 0xB6E (PVC)
[00:22:53] [PASSED] 0xBD4 (PVC)
[00:22:53] [PASSED] 0xBD5 (PVC)
[00:22:53] [PASSED] 0xBD6 (PVC)
[00:22:53] [PASSED] 0xBD7 (PVC)
[00:22:53] [PASSED] 0xBD8 (PVC)
[00:22:53] [PASSED] 0xBD9 (PVC)
[00:22:53] [PASSED] 0xBDA (PVC)
[00:22:53] [PASSED] 0xBDB (PVC)
[00:22:53] [PASSED] 0xBE0 (PVC)
[00:22:53] [PASSED] 0xBE1 (PVC)
[00:22:53] [PASSED] 0xBE5 (PVC)
[00:22:53] [PASSED] 0x7D40 (METEORLAKE)
[00:22:53] [PASSED] 0x7D45 (METEORLAKE)
[00:22:53] [PASSED] 0x7D55 (METEORLAKE)
[00:22:53] [PASSED] 0x7D60 (METEORLAKE)
[00:22:53] [PASSED] 0x7DD5 (METEORLAKE)
[00:22:53] [PASSED] 0x6420 (LUNARLAKE)
[00:22:53] [PASSED] 0x64A0 (LUNARLAKE)
[00:22:53] [PASSED] 0x64B0 (LUNARLAKE)
[00:22:53] [PASSED] 0xE202 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE209 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE20B (BATTLEMAGE)
[00:22:53] [PASSED] 0xE20C (BATTLEMAGE)
[00:22:53] [PASSED] 0xE20D (BATTLEMAGE)
[00:22:53] [PASSED] 0xE210 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE211 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE212 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE216 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE220 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE221 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE222 (BATTLEMAGE)
[00:22:53] [PASSED] 0xE223 (BATTLEMAGE)
[00:22:53] [PASSED] 0xB080 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB081 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB082 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB083 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB084 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB085 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB086 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB087 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB08F (PANTHERLAKE)
[00:22:53] [PASSED] 0xB090 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB0A0 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB0A1 (PANTHERLAKE)
[00:22:53] [PASSED] 0xB0B0 (PANTHERLAKE)
[00:22:53] [PASSED] 0xFD80 (PANTHERLAKE)
[00:22:53] [PASSED] 0xFD81 (PANTHERLAKE)
[00:22:53] [PASSED] 0xD740 (NOVALAKE_S)
[00:22:53] [PASSED] 0xD741 (NOVALAKE_S)
[00:22:53] [PASSED] 0xD742 (NOVALAKE_S)
[00:22:53] [PASSED] 0xD743 (NOVALAKE_S)
[00:22:53] [PASSED] 0xD745 (NOVALAKE_S)
[00:22:53] [PASSED] 0xD74A (NOVALAKE_S)
[00:22:53] [PASSED] 0xD74B (NOVALAKE_S)
[00:22:53] [PASSED] 0x674C (CRESCENTISLAND)
[00:22:53] [PASSED] 0x674D (CRESCENTISLAND)
[00:22:53] [PASSED] 0x674E (CRESCENTISLAND)
[00:22:53] [PASSED] 0x674F (CRESCENTISLAND)
[00:22:53] [PASSED] 0x6750 (CRESCENTISLAND)
[00:22:53] [PASSED] 0x6751 (CRESCENTISLAND)
[00:22:53] [PASSED] 0x6752 (CRESCENTISLAND)
[00:22:53] [PASSED] 0x6753 (CRESCENTISLAND)
[00:22:53] [PASSED] 0x6754 (CRESCENTISLAND)
[00:22:53] [PASSED] 0x6755 (CRESCENTISLAND)
[00:22:53] [PASSED] 0x6756 (CRESCENTISLAND)
[00:22:53] [PASSED] 0xD750 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD751 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD752 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD753 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD754 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD755 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD756 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD757 (NOVALAKE_P)
[00:22:53] [PASSED] 0xD75F (NOVALAKE_P)
[00:22:53] =============== [PASSED] check_platform_desc ===============
[00:22:53] ===================== [PASSED] xe_pci ======================
[00:22:53] ============= xe_rtp_tables_test (5 subtests) ==============
[00:22:53] ================== xe_rtp_table_gt_test ===================
[00:22:53] [PASSED] gt_was/14011060649
[00:22:53] [PASSED] gt_was/14011059788
[00:22:53] [PASSED] gt_was/14015795083
[00:22:53] [PASSED] gt_was/16021867713
[00:22:53] [PASSED] gt_was/14019449301
[00:22:53] [PASSED] gt_was/16028005424
[00:22:53] [PASSED] gt_was/14026578760
[00:22:53] [PASSED] gt_was/1409420604
[00:22:53] [PASSED] gt_was/1408615072
[00:22:53] [PASSED] gt_was/22010523718
[00:22:53] [PASSED] gt_was/14011006942
[00:22:53] [PASSED] gt_was/14014830051
[00:22:53] [PASSED] gt_was/18018781329
[00:22:53] [PASSED] gt_was/1509235366
[00:22:53] [PASSED] gt_was/18018781329
[00:22:53] [PASSED] gt_was/16016694945
[00:22:53] [PASSED] gt_was/14018575942
[00:22:53] [PASSED] gt_was/22016670082
[00:22:53] [PASSED] gt_was/22016670082
[00:22:53] [PASSED] gt_was/14017421178
[00:22:53] [PASSED] gt_was/16025250150
[00:22:53] [PASSED] gt_was/14021871409
[00:22:53] [PASSED] gt_was/16021865536
[00:22:53] [PASSED] gt_was/14021486841
[00:22:53] [PASSED] gt_was/14025160223
[00:22:53] [PASSED] gt_was/14026144927, 16029437861, 14026127056
[00:22:53] [PASSED] gt_was/14025635424
[00:22:53] [PASSED] gt_was/16028005424
[00:22:53] ============== [PASSED] xe_rtp_table_gt_test ===============
[00:22:53] ================== xe_rtp_table_gt_test ===================
[00:22:53] [PASSED] gt_tunings/Tuning: Blend Fill Caching Optimization Disable
[00:22:53] [PASSED] gt_tunings/Tuning: 32B Access Enable
[00:22:53] [PASSED] gt_tunings/Tuning: L3 cache
[00:22:53] [PASSED] gt_tunings/Tuning: L3 cache - media
[00:22:53] [PASSED] gt_tunings/Tuning: Compression Overfetch
[00:22:53] [PASSED] gt_tunings/Tuning: Compression Overfetch - media
[00:22:53] [PASSED] gt_tunings/Tuning: Enable compressible partial write overfetch in L3
[00:22:53] [PASSED] gt_tunings/Tuning: Enable compressible partial write overfetch in L3 - media
[00:22:53] [PASSED] gt_tunings/Tuning: L2 Overfetch Compressible Only
[00:22:53] [PASSED] gt_tunings/Tuning: L2 Overfetch Compressible Only - media
[00:22:53] [PASSED] gt_tunings/Tuning: Stateless compression control
[00:22:53] [PASSED] gt_tunings/Tuning: Stateless compression control - media
[00:22:53] [PASSED] gt_tunings/Tuning: L3 RW flush all Cache
[00:22:53] [PASSED] gt_tunings/Tuning: L3 RW flush all cache - media
[00:22:53] [PASSED] gt_tunings/Tuning: Set STLB Bank Hash Mode to 4KB
[00:22:53] [PASSED] gt_tunings/Tuning: Force All Non-Compressible Memory Reads to be 256B Overfetches
[00:22:53] ============== [PASSED] xe_rtp_table_gt_test ===============
[00:22:53] ================== xe_rtp_table_oob_test ==================
[00:22:53] [PASSED] oob_was/1607983814
[00:22:53] [PASSED] oob_was/16010904313
[00:22:53] [PASSED] oob_was/18022495364
[00:22:53] [PASSED] oob_was/22012773006
[00:22:53] [PASSED] oob_was/14014475959
[00:22:53] [PASSED] oob_was/22011391025
[00:22:53] [PASSED] oob_was/22012727170
[00:22:53] [PASSED] oob_was/22012727685
[00:22:53] [PASSED] oob_was/22016596838
[00:22:53] [PASSED] oob_was/18020744125
[00:22:53] [PASSED] oob_was/1409600907
[00:22:53] [PASSED] oob_was/22014953428
[00:22:53] [PASSED] oob_was/16017236439
[00:22:53] [PASSED] oob_was/14019821291
[00:22:53] [PASSED] oob_was/14015076503
[00:22:53] [PASSED] oob_was/22016122933
[00:22:53] [PASSED] oob_was/14018913170
[00:22:53] [PASSED] oob_was/14018094691
[00:22:53] [PASSED] oob_was/18024947630
[00:22:53] [PASSED] oob_was/16022287689
[00:22:53] [PASSED] oob_was/13011645652
[00:22:53] [PASSED] oob_was/14022293748
[00:22:53] [PASSED] oob_was/22019794406
[00:22:53] [PASSED] oob_was/22019338487
[00:22:53] [PASSED] oob_was/16023588340
[00:22:53] [PASSED] oob_was/14019789679
[00:22:53] [PASSED] oob_was/14022866841
[00:22:53] [PASSED] oob_was/16021333562
[00:22:53] [PASSED] oob_was/14016712196
[00:22:53] [PASSED] oob_was/14015568240
[00:22:53] [PASSED] oob_was/18013179988
[00:22:53] [PASSED] oob_was/1508761755
[00:22:53] [PASSED] oob_was/16023105232
[00:22:53] [PASSED] oob_was/16026508708
[00:22:53] [PASSED] oob_was/14020001231
[00:22:53] [PASSED] oob_was/16023683509
[00:22:53] [PASSED] oob_was/14025515070
[00:22:53] [PASSED] oob_was/15015404425_disable
[00:22:53] [PASSED] oob_was/16026007364
[00:22:53] [PASSED] oob_was/14020316580
[00:22:53] [PASSED] oob_was/14025883347
[00:22:53] [PASSED] oob_was/16029380221
[00:22:53] [PASSED] oob_was/22022079272
[00:22:53] [PASSED] oob_was/16029897822
[00:22:53] [PASSED] oob_was/14026539277
[00:22:53] [PASSED] oob_was/14028564128
[00:22:53] [PASSED] oob_was/14027054324
[00:22:53] [PASSED] oob_was/14025941587
[00:22:53] [PASSED] oob_was/16030224309
[00:22:53] [PASSED] oob_was/14028709524
[00:22:53] [PASSED] oob_was/14028250015
[00:22:53] [PASSED] oob_was/16031259911
[00:22:53] ============== [PASSED] xe_rtp_table_oob_test ==============
[00:22:53] ================ xe_rtp_table_dev_oob_test ================
[00:22:53] [PASSED] device_oob_was/22010954014
[00:22:53] [PASSED] device_oob_was/15015404425
[00:22:53] [PASSED] device_oob_was/22019338487_display
[00:22:53] [PASSED] device_oob_was/14022085890
[00:22:53] [PASSED] device_oob_was/14026633728
[00:22:53] [PASSED] device_oob_was/14026746987
[00:22:53] [PASSED] device_oob_was/14026779378
[00:22:53] [PASSED] device_oob_was/14028586678
[00:22:53] [PASSED] device_oob_was/14028434957
[00:22:53] ============ [PASSED] xe_rtp_table_dev_oob_test ============
[00:22:53] ========== xe_rtp_table_missing_upper_bound_test ==========
[00:22:53] [PASSED] register_whitelist/WaAllowPMDepthAndInvocationCountAccessFromUMD, 1408556865
[00:22:53] [PASSED] register_whitelist/1508744258, 14012131227, 1808121037
[00:22:53] [PASSED] register_whitelist/1806527549
[00:22:53] [PASSED] register_whitelist/allow_read_ctx_timestamp
[00:22:53] [PASSED] register_whitelist/allow_read_queue_timestamp
[00:22:53] [PASSED] register_whitelist/16014440446
[00:22:53] [PASSED] register_whitelist/16017236439
[00:22:53] [PASSED] register_whitelist/16020183090
[00:22:53] [PASSED] register_whitelist/14024997852
[00:22:53] [PASSED] register_whitelist/14024997852
[00:22:53] ====== [PASSED] xe_rtp_table_missing_upper_bound_test ======
[00:22:53] =============== [PASSED] xe_rtp_tables_test ================
[00:22:53] =================== xe_rtp (3 subtests) ====================
[00:22:53] =================== xe_rtp_rules_tests ====================
[00:22:53] [PASSED] no
[00:22:53] [PASSED] yes
[00:22:53] [PASSED] no-and-no
[00:22:53] [PASSED] no-and-yes
[00:22:53] [PASSED] yes-and-no
[00:22:53] [PASSED] yes-and-yes
[00:22:53] [PASSED] no-or-no
[00:22:53] [PASSED] no-or-yes
[00:22:53] [PASSED] yes-or-no
[00:22:53] [PASSED] yes-or-yes
[00:22:53] [PASSED] no-yes-or-yes-no
[00:22:53] [PASSED] no-yes-or-yes-yes
[00:22:53] [PASSED] yes-yes-or-no-yes
[00:22:53] [PASSED] yes-yes-or-yes-yes
[00:22:53] [PASSED] no-no-or-yes-or-no
[00:22:53] [PASSED] or
[00:22:53] [PASSED] or-yes
[00:22:53] [PASSED] or-no
[00:22:53] [PASSED] yes-or
[00:22:53] [PASSED] no-or
[00:22:53] [PASSED] no-or-or-yes
[00:22:53] [PASSED] yes-or-or-no
[00:22:53] [PASSED] no-or-or-no
[00:22:53] [PASSED] missing-context-engine-class
[00:22:53] [PASSED] missing-context-engine-class-or-yes
[00:22:53] [PASSED] missing-context-engine-class-or-or-yes
[00:22:53] =============== [PASSED] xe_rtp_rules_tests ================
[00:22:53] =============== xe_rtp_process_to_sr_tests ================
[00:22:53] [PASSED] coalesce-same-reg
[00:22:53] [PASSED] coalesce-same-reg-literal-and-func
[00:22:53] [PASSED] no-match-no-add
[00:22:53] [PASSED] two-regs-two-entries
[00:22:53] [PASSED] clr-one-set-other
[00:22:53] [PASSED] set-field
[00:22:53] [PASSED] conflict-duplicate
[00:22:53] [PASSED] conflict-not-disjoint
[00:22:53] [PASSED] conflict-not-disjoint-literal-and-func
[00:22:53] [PASSED] conflict-reg-type
[00:22:53] [PASSED] bad-mcr-reg-forced-to-regular
[00:22:53] [PASSED] bad-regular-reg-forced-to-mcr
[00:22:53] =========== [PASSED] xe_rtp_process_to_sr_tests ============
[00:22:53] ================== xe_rtp_process_tests ===================
[00:22:53] [PASSED] active1
[00:22:53] [PASSED] active2
[00:22:53] [PASSED] active-inactive
[00:22:53] [PASSED] inactive-active
[00:22:53] [PASSED] inactive-active-inactive
[00:22:53] [PASSED] inactive-inactive-inactive
[00:22:53] ============== [PASSED] xe_rtp_process_tests ===============
[00:22:53] ===================== [PASSED] xe_rtp ======================
[00:22:53] ==================== xe_wa (1 subtest) =====================
[00:22:53] ======================== xe_wa_gt =========================
[00:22:53] [PASSED] TIGERLAKE B0
[00:22:53] [PASSED] DG1 A0
[00:22:53] [PASSED] DG1 B0
[00:22:53] [PASSED] ALDERLAKE_S A0
[00:22:53] [PASSED] ALDERLAKE_S B0
[00:22:53] [PASSED] ALDERLAKE_S C0
[00:22:53] [PASSED] ALDERLAKE_S D0
[00:22:53] [PASSED] ALDERLAKE_P A0
[00:22:53] [PASSED] ALDERLAKE_P B0
[00:22:53] [PASSED] ALDERLAKE_P C0
[00:22:53] [PASSED] ALDERLAKE_S RPLS D0
[00:22:53] [PASSED] ALDERLAKE_P RPLU E0
[00:22:53] [PASSED] DG2 G10 C0
[00:22:53] [PASSED] DG2 G11 B1
[00:22:53] [PASSED] DG2 G12 A1
[00:22:53] [PASSED] METEORLAKE 12.70(Xe_LPG) A0 13.00(Xe_LPM+) A0
[00:22:53] [PASSED] METEORLAKE 12.71(Xe_LPG) A0 13.00(Xe_LPM+) A0
[00:22:53] [PASSED] METEORLAKE 12.74(Xe_LPG+) A0 13.00(Xe_LPM+) A0
[00:22:53] [PASSED] LUNARLAKE 20.04(Xe2_LPG) A0 20.00(Xe2_LPM) A0
[00:22:53] [PASSED] LUNARLAKE 20.04(Xe2_LPG) B0 20.00(Xe2_LPM) A0
[00:22:53] [PASSED] BATTLEMAGE 20.01(Xe2_HPG) A0 13.01(Xe2_HPM) A1
[00:22:53] [PASSED] PANTHERLAKE 30.00(Xe3_LPG) A0 30.00(Xe3_LPM) A0
[00:22:53] ==================== [PASSED] xe_wa_gt =====================
[00:22:53] ====================== [PASSED] xe_wa ======================
[00:22:53] ============================================================
[00:22:53] Testing complete. Ran 867 tests: passed: 838, skipped: 29
[00:22:53] Elapsed time: 42.428s total, 2.605s configuring, 39.057s building, 0.733s running
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/drm/tests/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/tests/.kunitconfig
[00:22:53] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[00:22:55] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
[00:23:21] Starting KUnit Kernel (1/1)...
[00:23:21] ============================================================
Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[00:23:21] ============ drm_test_pick_cmdline (2 subtests) ============
[00:23:21] [PASSED] drm_test_pick_cmdline_res_1920_1080_60
[00:23:21] =============== drm_test_pick_cmdline_named ===============
[00:23:21] [PASSED] NTSC
[00:23:21] [PASSED] NTSC-J
[00:23:21] [PASSED] PAL
[00:23:21] [PASSED] PAL-M
[00:23:21] =========== [PASSED] drm_test_pick_cmdline_named ===========
[00:23:21] ============== [PASSED] drm_test_pick_cmdline ==============
[00:23:21] == drm_test_atomic_get_connector_for_encoder (1 subtest) ===
[00:23:21] [PASSED] drm_test_drm_atomic_get_connector_for_encoder
[00:23:21] ==== [PASSED] drm_test_atomic_get_connector_for_encoder ====
[00:23:21] =========== drm_validate_clone_mode (2 subtests) ===========
[00:23:21] ============== drm_test_check_in_clone_mode ===============
[00:23:21] [PASSED] in_clone_mode
[00:23:21] [PASSED] not_in_clone_mode
[00:23:21] ========== [PASSED] drm_test_check_in_clone_mode ===========
[00:23:21] =============== drm_test_check_valid_clones ===============
[00:23:21] [PASSED] not_in_clone_mode
[00:23:21] [PASSED] valid_clone
[00:23:21] [PASSED] invalid_clone
[00:23:21] =========== [PASSED] drm_test_check_valid_clones ===========
[00:23:21] ============= [PASSED] drm_validate_clone_mode =============
[00:23:21] ============= drm_validate_modeset (1 subtest) =============
[00:23:21] [PASSED] drm_test_check_connector_changed_modeset
[00:23:21] ============== [PASSED] drm_validate_modeset ===============
[00:23:21] ====== drm_test_bridge_get_current_state (1 subtest) =======
[00:23:21] [PASSED] drm_test_drm_bridge_get_current_state_atomic
[00:23:21] ======== [PASSED] drm_test_bridge_get_current_state ========
[00:23:21] ====== drm_test_bridge_helper_reset_crtc (3 subtests) ======
[00:23:21] [PASSED] drm_test_drm_bridge_helper_reset_crtc_atomic
[00:23:21] [PASSED] drm_test_drm_bridge_helper_reset_crtc_atomic_disabled
[00:23:21] [PASSED] drm_test_drm_bridge_helper_hdmi_output_bus_fmts
[00:23:21] ======== [PASSED] drm_test_bridge_helper_reset_crtc ========
[00:23:21] ============== drm_bridge_alloc (2 subtests) ===============
[00:23:21] [PASSED] drm_test_drm_bridge_alloc_basic
[00:23:21] [PASSED] drm_test_drm_bridge_alloc_get_put
[00:23:21] ================ [PASSED] drm_bridge_alloc =================
[00:23:21] ============= drm_bridge_bus_fmt (5 subtests) ==============
[00:23:21] [PASSED] drm_test_bridge_rgb_yuv_rgb
[00:23:21] [PASSED] drm_test_bridge_must_convert_to_yuv444
[00:23:21] [PASSED] drm_test_bridge_hdmi_auto_rgb
[00:23:21] [PASSED] drm_test_bridge_auto_first
[00:23:21] [PASSED] drm_test_bridge_rgb_yuv_no_path
[00:23:21] =============== [PASSED] drm_bridge_bus_fmt ================
[00:23:21] ============= drm_cmdline_parser (40 subtests) =============
[00:23:21] [PASSED] drm_test_cmdline_force_d_only
[00:23:21] [PASSED] drm_test_cmdline_force_D_only_dvi
[00:23:21] [PASSED] drm_test_cmdline_force_D_only_hdmi
[00:23:21] [PASSED] drm_test_cmdline_force_D_only_not_digital
[00:23:21] [PASSED] drm_test_cmdline_force_e_only
[00:23:21] [PASSED] drm_test_cmdline_res
[00:23:21] [PASSED] drm_test_cmdline_res_vesa
[00:23:21] [PASSED] drm_test_cmdline_res_vesa_rblank
[00:23:21] [PASSED] drm_test_cmdline_res_rblank
[00:23:21] [PASSED] drm_test_cmdline_res_bpp
[00:23:21] [PASSED] drm_test_cmdline_res_refresh
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh_interlaced
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh_margins
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh_force_off
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh_force_on
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh_force_on_analog
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh_force_on_digital
[00:23:21] [PASSED] drm_test_cmdline_res_bpp_refresh_interlaced_margins_force_on
[00:23:21] [PASSED] drm_test_cmdline_res_margins_force_on
[00:23:21] [PASSED] drm_test_cmdline_res_vesa_margins
[00:23:21] [PASSED] drm_test_cmdline_name
[00:23:21] [PASSED] drm_test_cmdline_name_bpp
[00:23:21] [PASSED] drm_test_cmdline_name_option
[00:23:21] [PASSED] drm_test_cmdline_name_bpp_option
[00:23:21] [PASSED] drm_test_cmdline_rotate_0
[00:23:21] [PASSED] drm_test_cmdline_rotate_90
[00:23:21] [PASSED] drm_test_cmdline_rotate_180
[00:23:21] [PASSED] drm_test_cmdline_rotate_270
[00:23:21] [PASSED] drm_test_cmdline_hmirror
[00:23:21] [PASSED] drm_test_cmdline_vmirror
[00:23:21] [PASSED] drm_test_cmdline_margin_options
[00:23:21] [PASSED] drm_test_cmdline_multiple_options
[00:23:21] [PASSED] drm_test_cmdline_bpp_extra_and_option
[00:23:21] [PASSED] drm_test_cmdline_extra_and_option
[00:23:21] [PASSED] drm_test_cmdline_freestanding_options
[00:23:21] [PASSED] drm_test_cmdline_freestanding_force_e_and_options
[00:23:21] [PASSED] drm_test_cmdline_panel_orientation
[00:23:21] ================ drm_test_cmdline_invalid =================
[00:23:21] [PASSED] margin_only
[00:23:21] [PASSED] interlace_only
[00:23:21] [PASSED] res_missing_x
[00:23:21] [PASSED] res_missing_y
[00:23:21] [PASSED] res_bad_y
[00:23:21] [PASSED] res_missing_y_bpp
[00:23:21] [PASSED] res_bad_bpp
[00:23:21] [PASSED] res_bad_refresh
[00:23:21] [PASSED] res_bpp_refresh_force_on_off
[00:23:21] [PASSED] res_invalid_mode
[00:23:21] [PASSED] res_bpp_wrong_place_mode
[00:23:21] [PASSED] name_bpp_refresh
[00:23:21] [PASSED] name_refresh
[00:23:21] [PASSED] name_refresh_wrong_mode
[00:23:21] [PASSED] name_refresh_invalid_mode
[00:23:21] [PASSED] rotate_multiple
[00:23:21] [PASSED] rotate_invalid_val
[00:23:21] [PASSED] rotate_truncated
[00:23:21] [PASSED] invalid_option
[00:23:21] [PASSED] invalid_tv_option
[00:23:21] [PASSED] truncated_tv_option
[00:23:21] ============ [PASSED] drm_test_cmdline_invalid =============
[00:23:21] =============== drm_test_cmdline_tv_options ===============
[00:23:21] [PASSED] NTSC
[00:23:21] [PASSED] NTSC_443
[00:23:21] [PASSED] NTSC_J
[00:23:21] [PASSED] PAL
[00:23:21] [PASSED] PAL_M
[00:23:21] [PASSED] PAL_N
[00:23:21] [PASSED] SECAM
[00:23:21] [PASSED] MONO_525
[00:23:21] [PASSED] MONO_625
[00:23:21] =========== [PASSED] drm_test_cmdline_tv_options ===========
[00:23:21] =============== [PASSED] drm_cmdline_parser ================
[00:23:21] ========== drmm_connector_hdmi_init (20 subtests) ==========
[00:23:21] [PASSED] drm_test_connector_hdmi_init_valid
[00:23:21] [PASSED] drm_test_connector_hdmi_init_bpc_8
[00:23:21] [PASSED] drm_test_connector_hdmi_init_bpc_10
[00:23:21] [PASSED] drm_test_connector_hdmi_init_bpc_12
[00:23:21] [PASSED] drm_test_connector_hdmi_init_bpc_invalid
[00:23:21] [PASSED] drm_test_connector_hdmi_init_bpc_null
[00:23:21] [PASSED] drm_test_connector_hdmi_init_formats_empty
[00:23:21] [PASSED] drm_test_connector_hdmi_init_formats_no_rgb
[00:23:21] === drm_test_connector_hdmi_init_formats_yuv420_allowed ===
[00:23:21] [PASSED] supported_formats=0x9 yuv420_allowed=1
[00:23:21] [PASSED] supported_formats=0x9 yuv420_allowed=0
[00:23:21] [PASSED] supported_formats=0x5 yuv420_allowed=1
[00:23:21] [PASSED] supported_formats=0x5 yuv420_allowed=0
[00:23:21] === [PASSED] drm_test_connector_hdmi_init_formats_yuv420_allowed ===
[00:23:21] [PASSED] drm_test_connector_hdmi_init_null_ddc
[00:23:21] [PASSED] drm_test_connector_hdmi_init_null_product
[00:23:21] [PASSED] drm_test_connector_hdmi_init_null_vendor
[00:23:21] [PASSED] drm_test_connector_hdmi_init_product_length_exact
[00:23:21] [PASSED] drm_test_connector_hdmi_init_product_length_too_long
[00:23:21] [PASSED] drm_test_connector_hdmi_init_product_valid
[00:23:21] [PASSED] drm_test_connector_hdmi_init_vendor_length_exact
[00:23:21] [PASSED] drm_test_connector_hdmi_init_vendor_length_too_long
[00:23:21] [PASSED] drm_test_connector_hdmi_init_vendor_valid
[00:23:21] ========= drm_test_connector_hdmi_init_type_valid =========
[00:23:21] [PASSED] HDMI-A
[00:23:21] [PASSED] HDMI-B
[00:23:21] ===== [PASSED] drm_test_connector_hdmi_init_type_valid =====
[00:23:21] ======== drm_test_connector_hdmi_init_type_invalid ========
[00:23:21] [PASSED] Unknown
[00:23:21] [PASSED] VGA
[00:23:21] [PASSED] DVI-I
[00:23:21] [PASSED] DVI-D
[00:23:21] [PASSED] DVI-A
[00:23:21] [PASSED] Composite
[00:23:21] [PASSED] SVIDEO
[00:23:21] [PASSED] LVDS
[00:23:21] [PASSED] Component
[00:23:21] [PASSED] DIN
[00:23:21] [PASSED] DP
[00:23:21] [PASSED] TV
[00:23:21] [PASSED] eDP
[00:23:21] [PASSED] Virtual
[00:23:21] [PASSED] DSI
[00:23:21] [PASSED] DPI
[00:23:21] [PASSED] Writeback
[00:23:21] [PASSED] SPI
[00:23:21] [PASSED] USB
[00:23:21] ==== [PASSED] drm_test_connector_hdmi_init_type_invalid ====
[00:23:21] ============ [PASSED] drmm_connector_hdmi_init =============
[00:23:21] ============= drmm_connector_init (3 subtests) =============
[00:23:21] [PASSED] drm_test_drmm_connector_init
[00:23:21] [PASSED] drm_test_drmm_connector_init_null_ddc
[00:23:21] ========= drm_test_drmm_connector_init_type_valid =========
[00:23:21] [PASSED] Unknown
[00:23:21] [PASSED] VGA
[00:23:21] [PASSED] DVI-I
[00:23:21] [PASSED] DVI-D
[00:23:21] [PASSED] DVI-A
[00:23:21] [PASSED] Composite
[00:23:21] [PASSED] SVIDEO
[00:23:21] [PASSED] LVDS
[00:23:21] [PASSED] Component
[00:23:21] [PASSED] DIN
[00:23:21] [PASSED] DP
[00:23:21] [PASSED] HDMI-A
[00:23:21] [PASSED] HDMI-B
[00:23:21] [PASSED] TV
[00:23:21] [PASSED] eDP
[00:23:21] [PASSED] Virtual
[00:23:21] [PASSED] DSI
[00:23:21] [PASSED] DPI
[00:23:21] [PASSED] Writeback
[00:23:21] [PASSED] SPI
[00:23:21] [PASSED] USB
[00:23:21] ===== [PASSED] drm_test_drmm_connector_init_type_valid =====
[00:23:21] =============== [PASSED] drmm_connector_init ===============
[00:23:21] ========= drm_connector_dynamic_init (6 subtests) ==========
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_init
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_init_null_ddc
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_init_not_added
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_init_properties
[00:23:21] ===== drm_test_drm_connector_dynamic_init_type_valid ======
[00:23:21] [PASSED] Unknown
[00:23:21] [PASSED] VGA
[00:23:21] [PASSED] DVI-I
[00:23:21] [PASSED] DVI-D
[00:23:21] [PASSED] DVI-A
[00:23:21] [PASSED] Composite
[00:23:21] [PASSED] SVIDEO
[00:23:21] [PASSED] LVDS
[00:23:21] [PASSED] Component
[00:23:21] [PASSED] DIN
[00:23:21] [PASSED] DP
[00:23:21] [PASSED] HDMI-A
[00:23:21] [PASSED] HDMI-B
[00:23:21] [PASSED] TV
[00:23:21] [PASSED] eDP
[00:23:21] [PASSED] Virtual
[00:23:21] [PASSED] DSI
[00:23:21] [PASSED] DPI
[00:23:21] [PASSED] Writeback
[00:23:21] [PASSED] SPI
[00:23:21] [PASSED] USB
[00:23:21] = [PASSED] drm_test_drm_connector_dynamic_init_type_valid ==
[00:23:21] ======== drm_test_drm_connector_dynamic_init_name =========
[00:23:21] [PASSED] Unknown
[00:23:21] [PASSED] VGA
[00:23:21] [PASSED] DVI-I
[00:23:21] [PASSED] DVI-D
[00:23:21] [PASSED] DVI-A
[00:23:21] [PASSED] Composite
[00:23:21] [PASSED] SVIDEO
[00:23:21] [PASSED] LVDS
[00:23:21] [PASSED] Component
[00:23:21] [PASSED] DIN
[00:23:21] [PASSED] DP
[00:23:21] [PASSED] HDMI-A
[00:23:21] [PASSED] HDMI-B
[00:23:21] [PASSED] TV
[00:23:21] [PASSED] eDP
[00:23:21] [PASSED] Virtual
[00:23:21] [PASSED] DSI
[00:23:21] [PASSED] DPI
[00:23:21] [PASSED] Writeback
[00:23:21] [PASSED] SPI
[00:23:21] [PASSED] USB
[00:23:21] ==== [PASSED] drm_test_drm_connector_dynamic_init_name =====
[00:23:21] =========== [PASSED] drm_connector_dynamic_init ============
[00:23:21] ==== drm_connector_dynamic_register_early (4 subtests) =====
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_early_on_list
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_early_defer
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_early_no_init
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_early_no_mode_object
[00:23:21] ====== [PASSED] drm_connector_dynamic_register_early =======
[00:23:21] ======= drm_connector_dynamic_register (7 subtests) ========
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_on_list
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_no_defer
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_no_init
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_mode_object
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_sysfs
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_sysfs_name
[00:23:21] [PASSED] drm_test_drm_connector_dynamic_register_debugfs
[00:23:21] ========= [PASSED] drm_connector_dynamic_register ==========
[00:23:21] = drm_connector_attach_broadcast_rgb_property (2 subtests) =
[00:23:21] [PASSED] drm_test_drm_connector_attach_broadcast_rgb_property
[00:23:21] [PASSED] drm_test_drm_connector_attach_broadcast_rgb_property_hdmi_connector
[00:23:21] === [PASSED] drm_connector_attach_broadcast_rgb_property ===
[00:23:21] ========== drm_get_tv_mode_from_name (2 subtests) ==========
[00:23:21] ========== drm_test_get_tv_mode_from_name_valid ===========
[00:23:21] [PASSED] NTSC
[00:23:21] [PASSED] NTSC-443
[00:23:21] [PASSED] NTSC-J
[00:23:21] [PASSED] PAL
[00:23:21] [PASSED] PAL-M
[00:23:21] [PASSED] PAL-N
[00:23:21] [PASSED] SECAM
[00:23:21] [PASSED] Mono
[00:23:21] ====== [PASSED] drm_test_get_tv_mode_from_name_valid =======
[00:23:21] [PASSED] drm_test_get_tv_mode_from_name_truncated
[00:23:21] ============ [PASSED] drm_get_tv_mode_from_name ============
[00:23:21] = drm_test_connector_hdmi_compute_mode_clock (12 subtests) =
[00:23:21] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb
[00:23:21] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_10bpc
[00:23:21] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_10bpc_vic_1
[00:23:21] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_12bpc
[00:23:21] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_12bpc_vic_1
[00:23:21] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_double
[00:23:21] = drm_test_connector_hdmi_compute_mode_clock_yuv420_valid =
[00:23:21] [PASSED] VIC 96
[00:23:21] [PASSED] VIC 97
[00:23:21] [PASSED] VIC 101
[00:23:21] [PASSED] VIC 102
[00:23:21] [PASSED] VIC 106
[00:23:21] [PASSED] VIC 107
[00:23:21] === [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv420_valid ===
[00:23:21] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv420_10_bpc
[00:23:21] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv420_12_bpc
[00:23:21] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv422_8_bpc
[00:23:21] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv422_10_bpc
[00:23:21] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv422_12_bpc
[00:23:21] === [PASSED] drm_test_connector_hdmi_compute_mode_clock ====
[00:23:21] == drm_hdmi_connector_get_broadcast_rgb_name (2 subtests) ==
[00:23:21] === drm_test_drm_hdmi_connector_get_broadcast_rgb_name ====
[00:23:21] [PASSED] Automatic
[00:23:21] [PASSED] Full
[00:23:21] [PASSED] Limited 16:235
[00:23:21] === [PASSED] drm_test_drm_hdmi_connector_get_broadcast_rgb_name ===
[00:23:21] [PASSED] drm_test_drm_hdmi_connector_get_broadcast_rgb_name_invalid
[00:23:21] ==== [PASSED] drm_hdmi_connector_get_broadcast_rgb_name ====
[00:23:21] == drm_hdmi_connector_get_output_format_name (2 subtests) ==
[00:23:21] === drm_test_drm_hdmi_connector_get_output_format_name ====
[00:23:21] [PASSED] RGB
[00:23:21] [PASSED] YUV 4:2:0
[00:23:21] [PASSED] YUV 4:2:2
[00:23:21] [PASSED] YUV 4:4:4
[00:23:21] === [PASSED] drm_test_drm_hdmi_connector_get_output_format_name ===
[00:23:21] [PASSED] drm_test_drm_hdmi_connector_get_output_format_name_invalid
[00:23:21] ==== [PASSED] drm_hdmi_connector_get_output_format_name ====
[00:23:21] ============= drm_damage_helper (21 subtests) ==============
[00:23:21] [PASSED] drm_test_damage_iter_no_damage
[00:23:21] [PASSED] drm_test_damage_iter_no_damage_fractional_src
[00:23:21] [PASSED] drm_test_damage_iter_no_damage_src_moved
[00:23:21] [PASSED] drm_test_damage_iter_no_damage_fractional_src_moved
[00:23:21] [PASSED] drm_test_damage_iter_no_damage_not_visible
[00:23:21] [PASSED] drm_test_damage_iter_no_damage_no_crtc
[00:23:21] [PASSED] drm_test_damage_iter_no_damage_no_fb
[00:23:21] [PASSED] drm_test_damage_iter_simple_damage
[00:23:21] [PASSED] drm_test_damage_iter_single_damage
[00:23:21] [PASSED] drm_test_damage_iter_single_damage_intersect_src
[00:23:21] [PASSED] drm_test_damage_iter_single_damage_outside_src
[00:23:21] [PASSED] drm_test_damage_iter_single_damage_fractional_src
[00:23:21] [PASSED] drm_test_damage_iter_single_damage_intersect_fractional_src
[00:23:21] [PASSED] drm_test_damage_iter_single_damage_outside_fractional_src
[00:23:21] [PASSED] drm_test_damage_iter_single_damage_src_moved
[00:23:21] [PASSED] drm_test_damage_iter_single_damage_fractional_src_moved
[00:23:21] [PASSED] drm_test_damage_iter_damage
[00:23:21] [PASSED] drm_test_damage_iter_damage_one_intersect
[00:23:21] [PASSED] drm_test_damage_iter_damage_one_outside
[00:23:21] [PASSED] drm_test_damage_iter_damage_src_moved
[00:23:21] [PASSED] drm_test_damage_iter_damage_not_visible
[00:23:21] ================ [PASSED] drm_damage_helper ================
[00:23:21] ============== drm_dp_mst_helper (3 subtests) ==============
[00:23:21] ============== drm_test_dp_mst_calc_pbn_mode ==============
[00:23:21] [PASSED] Clock 154000 BPP 30 DSC disabled
[00:23:21] [PASSED] Clock 234000 BPP 30 DSC disabled
[00:23:21] [PASSED] Clock 297000 BPP 24 DSC disabled
[00:23:21] [PASSED] Clock 332880 BPP 24 DSC enabled
[00:23:21] [PASSED] Clock 324540 BPP 24 DSC enabled
[00:23:21] ========== [PASSED] drm_test_dp_mst_calc_pbn_mode ==========
[00:23:21] ============== drm_test_dp_mst_calc_pbn_div ===============
[00:23:21] [PASSED] Link rate 2000000 lane count 4
[00:23:21] [PASSED] Link rate 2000000 lane count 2
[00:23:21] [PASSED] Link rate 2000000 lane count 1
[00:23:21] [PASSED] Link rate 1350000 lane count 4
[00:23:21] [PASSED] Link rate 1350000 lane count 2
[00:23:21] [PASSED] Link rate 1350000 lane count 1
[00:23:21] [PASSED] Link rate 1000000 lane count 4
[00:23:21] [PASSED] Link rate 1000000 lane count 2
[00:23:21] [PASSED] Link rate 1000000 lane count 1
[00:23:21] [PASSED] Link rate 810000 lane count 4
[00:23:21] [PASSED] Link rate 810000 lane count 2
[00:23:21] [PASSED] Link rate 810000 lane count 1
[00:23:21] [PASSED] Link rate 540000 lane count 4
[00:23:21] [PASSED] Link rate 540000 lane count 2
[00:23:21] [PASSED] Link rate 540000 lane count 1
[00:23:21] [PASSED] Link rate 270000 lane count 4
[00:23:21] [PASSED] Link rate 270000 lane count 2
[00:23:21] [PASSED] Link rate 270000 lane count 1
[00:23:21] [PASSED] Link rate 162000 lane count 4
[00:23:21] [PASSED] Link rate 162000 lane count 2
[00:23:21] [PASSED] Link rate 162000 lane count 1
[00:23:21] ========== [PASSED] drm_test_dp_mst_calc_pbn_div ===========
[00:23:21] ========= drm_test_dp_mst_sideband_msg_req_decode =========
[00:23:21] [PASSED] DP_ENUM_PATH_RESOURCES with port number
[00:23:21] [PASSED] DP_POWER_UP_PHY with port number
[00:23:21] [PASSED] DP_POWER_DOWN_PHY with port number
[00:23:21] [PASSED] DP_ALLOCATE_PAYLOAD with SDP stream sinks
[00:23:21] [PASSED] DP_ALLOCATE_PAYLOAD with port number
[00:23:21] [PASSED] DP_ALLOCATE_PAYLOAD with VCPI
[00:23:21] [PASSED] DP_ALLOCATE_PAYLOAD with PBN
[00:23:21] [PASSED] DP_QUERY_PAYLOAD with port number
[00:23:21] [PASSED] DP_QUERY_PAYLOAD with VCPI
[00:23:21] [PASSED] DP_REMOTE_DPCD_READ with port number
[00:23:21] [PASSED] DP_REMOTE_DPCD_READ with DPCD address
[00:23:21] [PASSED] DP_REMOTE_DPCD_READ with max number of bytes
[00:23:21] [PASSED] DP_REMOTE_DPCD_WRITE with port number
[00:23:21] [PASSED] DP_REMOTE_DPCD_WRITE with DPCD address
[00:23:21] [PASSED] DP_REMOTE_DPCD_WRITE with data array
[00:23:21] [PASSED] DP_REMOTE_I2C_READ with port number
[00:23:21] [PASSED] DP_REMOTE_I2C_READ with I2C device ID
[00:23:21] [PASSED] DP_REMOTE_I2C_READ with transactions array
[00:23:21] [PASSED] DP_REMOTE_I2C_WRITE with port number
[00:23:21] [PASSED] DP_REMOTE_I2C_WRITE with I2C device ID
[00:23:21] [PASSED] DP_REMOTE_I2C_WRITE with data array
[00:23:21] [PASSED] DP_QUERY_STREAM_ENC_STATUS with stream ID
[00:23:21] [PASSED] DP_QUERY_STREAM_ENC_STATUS with client ID
[00:23:21] [PASSED] DP_QUERY_STREAM_ENC_STATUS with stream event
[00:23:21] [PASSED] DP_QUERY_STREAM_ENC_STATUS with valid stream event
[00:23:21] [PASSED] DP_QUERY_STREAM_ENC_STATUS with stream behavior
[00:23:21] [PASSED] DP_QUERY_STREAM_ENC_STATUS with a valid stream behavior
[00:23:21] ===== [PASSED] drm_test_dp_mst_sideband_msg_req_decode =====
[00:23:21] ================ [PASSED] drm_dp_mst_helper ================
[00:23:21] ================== drm_exec (7 subtests) ===================
[00:23:21] [PASSED] sanitycheck
[00:23:21] [PASSED] test_lock
[00:23:21] [PASSED] test_lock_unlock
[00:23:21] [PASSED] test_duplicates
[00:23:21] [PASSED] test_prepare
[00:23:21] [PASSED] test_prepare_array
[00:23:21] [PASSED] test_multiple_loops
[00:23:21] ==================== [PASSED] drm_exec =====================
[00:23:21] =========== drm_format_helper_test (17 subtests) ===========
[00:23:21] ============== drm_test_fb_xrgb8888_to_gray8 ==============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ========== [PASSED] drm_test_fb_xrgb8888_to_gray8 ==========
[00:23:21] ============= drm_test_fb_xrgb8888_to_rgb332 ==============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ========= [PASSED] drm_test_fb_xrgb8888_to_rgb332 ==========
[00:23:21] ============= drm_test_fb_xrgb8888_to_rgb565 ==============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ========= [PASSED] drm_test_fb_xrgb8888_to_rgb565 ==========
[00:23:21] ============ drm_test_fb_xrgb8888_to_xrgb1555 =============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======== [PASSED] drm_test_fb_xrgb8888_to_xrgb1555 =========
[00:23:21] ============ drm_test_fb_xrgb8888_to_argb1555 =============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======== [PASSED] drm_test_fb_xrgb8888_to_argb1555 =========
[00:23:21] ============ drm_test_fb_xrgb8888_to_rgba5551 =============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======== [PASSED] drm_test_fb_xrgb8888_to_rgba5551 =========
[00:23:21] ============= drm_test_fb_xrgb8888_to_rgb888 ==============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ========= [PASSED] drm_test_fb_xrgb8888_to_rgb888 ==========
[00:23:21] ============= drm_test_fb_xrgb8888_to_bgr888 ==============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ========= [PASSED] drm_test_fb_xrgb8888_to_bgr888 ==========
[00:23:21] ============ drm_test_fb_xrgb8888_to_argb8888 =============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======== [PASSED] drm_test_fb_xrgb8888_to_argb8888 =========
[00:23:21] =========== drm_test_fb_xrgb8888_to_xrgb2101010 ===========
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======= [PASSED] drm_test_fb_xrgb8888_to_xrgb2101010 =======
[00:23:21] =========== drm_test_fb_xrgb8888_to_argb2101010 ===========
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======= [PASSED] drm_test_fb_xrgb8888_to_argb2101010 =======
[00:23:21] ============== drm_test_fb_xrgb8888_to_mono ===============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ========== [PASSED] drm_test_fb_xrgb8888_to_mono ===========
[00:23:21] ==================== drm_test_fb_swab =====================
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ================ [PASSED] drm_test_fb_swab =================
[00:23:21] ============ drm_test_fb_xrgb8888_to_xbgr8888 =============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======== [PASSED] drm_test_fb_xrgb8888_to_xbgr8888 =========
[00:23:21] ============ drm_test_fb_xrgb8888_to_abgr8888 =============
[00:23:21] [PASSED] single_pixel_source_buffer
[00:23:21] [PASSED] single_pixel_clip_rectangle
[00:23:21] [PASSED] well_known_colors
[00:23:21] [PASSED] destination_pitch
[00:23:21] ======== [PASSED] drm_test_fb_xrgb8888_to_abgr8888 =========
[00:23:21] ================= drm_test_fb_clip_offset =================
[00:23:21] [PASSED] pass through
[00:23:21] [PASSED] horizontal offset
[00:23:21] [PASSED] vertical offset
[00:23:21] [PASSED] horizontal and vertical offset
[00:23:21] [PASSED] horizontal offset (custom pitch)
[00:23:21] [PASSED] vertical offset (custom pitch)
[00:23:21] [PASSED] horizontal and vertical offset (custom pitch)
[00:23:21] ============= [PASSED] drm_test_fb_clip_offset =============
[00:23:21] =================== drm_test_fb_memcpy ====================
[00:23:21] [PASSED] single_pixel_source_buffer: XR24 little-endian (0x34325258)
[00:23:21] [PASSED] single_pixel_source_buffer: XRA8 little-endian (0x38415258)
[00:23:21] [PASSED] single_pixel_source_buffer: YU24 little-endian (0x34325559)
[00:23:21] [PASSED] single_pixel_clip_rectangle: XB24 little-endian (0x34324258)
[00:23:21] [PASSED] single_pixel_clip_rectangle: XRA8 little-endian (0x38415258)
[00:23:21] [PASSED] single_pixel_clip_rectangle: YU24 little-endian (0x34325559)
[00:23:21] [PASSED] well_known_colors: XB24 little-endian (0x34324258)
[00:23:21] [PASSED] well_known_colors: XRA8 little-endian (0x38415258)
[00:23:21] [PASSED] well_known_colors: YU24 little-endian (0x34325559)
[00:23:21] [PASSED] destination_pitch: XB24 little-endian (0x34324258)
[00:23:21] [PASSED] destination_pitch: XRA8 little-endian (0x38415258)
[00:23:21] [PASSED] destination_pitch: YU24 little-endian (0x34325559)
[00:23:21] =============== [PASSED] drm_test_fb_memcpy ================
[00:23:21] ============= [PASSED] drm_format_helper_test ==============
[00:23:21] ================= drm_format (18 subtests) =================
[00:23:21] [PASSED] drm_test_format_block_width_invalid
[00:23:21] [PASSED] drm_test_format_block_width_one_plane
[00:23:21] [PASSED] drm_test_format_block_width_two_plane
[00:23:21] [PASSED] drm_test_format_block_width_three_plane
[00:23:21] [PASSED] drm_test_format_block_width_tiled
[00:23:21] [PASSED] drm_test_format_block_height_invalid
[00:23:21] [PASSED] drm_test_format_block_height_one_plane
[00:23:21] [PASSED] drm_test_format_block_height_two_plane
[00:23:21] [PASSED] drm_test_format_block_height_three_plane
[00:23:21] [PASSED] drm_test_format_block_height_tiled
[00:23:21] [PASSED] drm_test_format_min_pitch_invalid
[00:23:21] [PASSED] drm_test_format_min_pitch_one_plane_8bpp
[00:23:21] [PASSED] drm_test_format_min_pitch_one_plane_16bpp
[00:23:21] [PASSED] drm_test_format_min_pitch_one_plane_24bpp
[00:23:21] [PASSED] drm_test_format_min_pitch_one_plane_32bpp
[00:23:21] [PASSED] drm_test_format_min_pitch_two_plane
[00:23:21] [PASSED] drm_test_format_min_pitch_three_plane_8bpp
[00:23:21] [PASSED] drm_test_format_min_pitch_tiled
[00:23:21] =================== [PASSED] drm_format ====================
[00:23:21] ============== drm_framebuffer (10 subtests) ===============
[00:23:21] ========== drm_test_framebuffer_check_src_coords ==========
[00:23:21] [PASSED] Success: source fits into fb
[00:23:21] [PASSED] Fail: overflowing fb with x-axis coordinate
[00:23:21] [PASSED] Fail: overflowing fb with y-axis coordinate
[00:23:21] [PASSED] Fail: overflowing fb with source width
[00:23:21] [PASSED] Fail: overflowing fb with source height
[00:23:21] ====== [PASSED] drm_test_framebuffer_check_src_coords ======
[00:23:21] [PASSED] drm_test_framebuffer_cleanup
[00:23:21] =============== drm_test_framebuffer_create ===============
[00:23:21] [PASSED] ABGR8888 normal sizes
[00:23:21] [PASSED] ABGR8888 max sizes
[00:23:21] [PASSED] ABGR8888 pitch greater than min required
[00:23:21] [PASSED] ABGR8888 pitch less than min required
[00:23:21] [PASSED] ABGR8888 Invalid width
[00:23:21] [PASSED] ABGR8888 Invalid buffer handle
[00:23:21] [PASSED] No pixel format
[00:23:21] [PASSED] ABGR8888 Width 0
[00:23:21] [PASSED] ABGR8888 Height 0
[00:23:21] [PASSED] ABGR8888 Out of bound height * pitch combination
[00:23:21] [PASSED] ABGR8888 Large buffer offset
[00:23:21] [PASSED] ABGR8888 Buffer offset for inexistent plane
[00:23:21] [PASSED] ABGR8888 Invalid flag
[00:23:21] [PASSED] ABGR8888 Set DRM_MODE_FB_MODIFIERS without modifiers
[00:23:21] [PASSED] ABGR8888 Valid buffer modifier
[00:23:21] [PASSED] ABGR8888 Invalid buffer modifier(DRM_FORMAT_MOD_SAMSUNG_64_32_TILE)
[00:23:21] [PASSED] ABGR8888 Extra pitches without DRM_MODE_FB_MODIFIERS
[00:23:21] [PASSED] ABGR8888 Extra pitches with DRM_MODE_FB_MODIFIERS
[00:23:21] [PASSED] NV12 Normal sizes
[00:23:21] [PASSED] NV12 Max sizes
[00:23:21] [PASSED] NV12 Invalid pitch
[00:23:21] [PASSED] NV12 Invalid modifier/missing DRM_MODE_FB_MODIFIERS flag
[00:23:21] [PASSED] NV12 different modifier per-plane
[00:23:21] [PASSED] NV12 with DRM_FORMAT_MOD_SAMSUNG_64_32_TILE
[00:23:21] [PASSED] NV12 Valid modifiers without DRM_MODE_FB_MODIFIERS
[00:23:21] [PASSED] NV12 Modifier for inexistent plane
[00:23:21] [PASSED] NV12 Handle for inexistent plane
[00:23:21] [PASSED] NV12 Handle for inexistent plane without DRM_MODE_FB_MODIFIERS
[00:23:21] [PASSED] YVU420 DRM_MODE_FB_MODIFIERS set without modifier
[00:23:21] [PASSED] YVU420 Normal sizes
[00:23:21] [PASSED] YVU420 Max sizes
[00:23:21] [PASSED] YVU420 Invalid pitch
[00:23:21] [PASSED] YVU420 Different pitches
[00:23:21] [PASSED] YVU420 Different buffer offsets/pitches
[00:23:21] [PASSED] YVU420 Modifier set just for plane 0, without DRM_MODE_FB_MODIFIERS
[00:23:21] [PASSED] YVU420 Modifier set just for planes 0, 1, without DRM_MODE_FB_MODIFIERS
[00:23:21] [PASSED] YVU420 Modifier set just for plane 0, 1, with DRM_MODE_FB_MODIFIERS
[00:23:21] [PASSED] YVU420 Valid modifier
[00:23:21] [PASSED] YVU420 Different modifiers per plane
[00:23:21] [PASSED] YVU420 Modifier for inexistent plane
[00:23:21] [PASSED] YUV420_10BIT Invalid modifier(DRM_FORMAT_MOD_LINEAR)
[00:23:21] [PASSED] X0L2 Normal sizes
[00:23:21] [PASSED] X0L2 Max sizes
[00:23:21] [PASSED] X0L2 Invalid pitch
[00:23:21] [PASSED] X0L2 Pitch greater than minimum required
[00:23:21] [PASSED] X0L2 Handle for inexistent plane
[00:23:21] [PASSED] X0L2 Offset for inexistent plane, without DRM_MODE_FB_MODIFIERS set
[00:23:21] [PASSED] X0L2 Modifier without DRM_MODE_FB_MODIFIERS set
[00:23:21] [PASSED] X0L2 Valid modifier
[00:23:21] [PASSED] X0L2 Modifier for inexistent plane
[00:23:21] =========== [PASSED] drm_test_framebuffer_create ===========
[00:23:21] [PASSED] drm_test_framebuffer_free
[00:23:21] [PASSED] drm_test_framebuffer_init
[00:23:21] [PASSED] drm_test_framebuffer_init_bad_format
[00:23:21] [PASSED] drm_test_framebuffer_init_dev_mismatch
[00:23:21] [PASSED] drm_test_framebuffer_lookup
[00:23:21] [PASSED] drm_test_framebuffer_lookup_inexistent
[00:23:21] [PASSED] drm_test_framebuffer_modifiers_not_supported
[00:23:21] ================= [PASSED] drm_framebuffer =================
[00:23:21] ================ drm_gem_shmem (8 subtests) ================
[00:23:21] [PASSED] drm_gem_shmem_test_obj_create
[00:23:21] [PASSED] drm_gem_shmem_test_obj_create_private
[00:23:21] [PASSED] drm_gem_shmem_test_pin_pages
[00:23:21] [PASSED] drm_gem_shmem_test_vmap
[00:23:21] [PASSED] drm_gem_shmem_test_get_sg_table
[00:23:21] [PASSED] drm_gem_shmem_test_get_pages_sgt
[00:23:21] [PASSED] drm_gem_shmem_test_madvise
[00:23:21] [PASSED] drm_gem_shmem_test_purge
[00:23:21] ================== [PASSED] drm_gem_shmem ==================
[00:23:21] === drm_atomic_helper_connector_hdmi_check (29 subtests) ===
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_auto_cea_mode
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_auto_cea_mode_vic_1
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_full_cea_mode
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_full_cea_mode_vic_1
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_limited_cea_mode
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_limited_cea_mode_vic_1
[00:23:21] ====== drm_test_check_broadcast_rgb_cea_mode_yuv420 =======
[00:23:21] [PASSED] Automatic
[00:23:21] [PASSED] Full
[00:23:21] [PASSED] Limited 16:235
[00:23:21] == [PASSED] drm_test_check_broadcast_rgb_cea_mode_yuv420 ===
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_crtc_mode_changed
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_crtc_mode_not_changed
[00:23:21] [PASSED] drm_test_check_disable_connector
[00:23:21] [PASSED] drm_test_check_hdmi_funcs_reject_rate
[00:23:21] [PASSED] drm_test_check_max_tmds_rate_bpc_fallback_rgb
[00:23:21] [PASSED] drm_test_check_max_tmds_rate_bpc_fallback_yuv420
[00:23:21] [PASSED] drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv422
[00:23:21] [PASSED] drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv420
[00:23:21] [PASSED] drm_test_check_driver_unsupported_fallback_yuv420
[00:23:21] [PASSED] drm_test_check_output_bpc_crtc_mode_changed
[00:23:21] [PASSED] drm_test_check_output_bpc_crtc_mode_not_changed
[00:23:21] [PASSED] drm_test_check_output_bpc_dvi
[00:23:21] [PASSED] drm_test_check_output_bpc_format_vic_1
[00:23:21] [PASSED] drm_test_check_output_bpc_format_display_8bpc_only
[00:23:21] [PASSED] drm_test_check_output_bpc_format_display_rgb_only
[00:23:21] [PASSED] drm_test_check_output_bpc_format_driver_8bpc_only
[00:23:21] [PASSED] drm_test_check_output_bpc_format_driver_rgb_only
[00:23:21] [PASSED] drm_test_check_tmds_char_rate_rgb_8bpc
[00:23:21] [PASSED] drm_test_check_tmds_char_rate_rgb_10bpc
[00:23:21] [PASSED] drm_test_check_tmds_char_rate_rgb_12bpc
[00:23:21] ============ drm_test_check_hdmi_color_format =============
[00:23:21] [PASSED] AUTO -> RGB
[00:23:21] [PASSED] YCBCR422 -> YUV422
[00:23:21] [PASSED] YCBCR420 -> YUV420
[00:23:21] [PASSED] YCBCR444 -> YUV444
[00:23:21] [PASSED] RGB -> RGB
[00:23:21] ======== [PASSED] drm_test_check_hdmi_color_format =========
[00:23:21] ======== drm_test_check_hdmi_color_format_420_only ========
[00:23:21] [PASSED] RGB should fail
[00:23:21] [PASSED] YUV444 should fail
[00:23:21] [PASSED] YUV422 should fail
[00:23:21] [PASSED] YUV420 should work
[00:23:21] ==== [PASSED] drm_test_check_hdmi_color_format_420_only ====
[00:23:21] ===== [PASSED] drm_atomic_helper_connector_hdmi_check ======
[00:23:21] === drm_atomic_helper_connector_hdmi_reset (6 subtests) ====
[00:23:21] [PASSED] drm_test_check_broadcast_rgb_value
[00:23:21] [PASSED] drm_test_check_bpc_8_value
[00:23:21] [PASSED] drm_test_check_bpc_10_value
[00:23:21] [PASSED] drm_test_check_bpc_12_value
[00:23:21] [PASSED] drm_test_check_format_value
[00:23:21] [PASSED] drm_test_check_tmds_char_value
[00:23:21] ===== [PASSED] drm_atomic_helper_connector_hdmi_reset ======
[00:23:21] = drm_atomic_helper_connector_hdmi_mode_valid (7 subtests) =
[00:23:21] [PASSED] drm_test_check_mode_valid
[00:23:21] [PASSED] drm_test_check_mode_valid_reject
[00:23:21] [PASSED] drm_test_check_mode_valid_reject_rate
[00:23:21] [PASSED] drm_test_check_mode_valid_reject_max_clock
[00:23:21] [PASSED] drm_test_check_mode_valid_yuv420_only_max_clock
[00:23:21] [PASSED] drm_test_check_mode_valid_reject_yuv420_only_connector
[00:23:21] [PASSED] drm_test_check_mode_valid_accept_yuv420_also_connector_rgb
[00:23:21] === [PASSED] drm_atomic_helper_connector_hdmi_mode_valid ===
[00:23:21] = drm_atomic_helper_connector_hdmi_infoframes (5 subtests) =
[00:23:21] [PASSED] drm_test_check_infoframes
[00:23:21] [PASSED] drm_test_check_reject_avi_infoframe
[00:23:21] [PASSED] drm_test_check_reject_hdr_infoframe_bpc_8
[00:23:21] [PASSED] drm_test_check_reject_hdr_infoframe_bpc_10
[00:23:21] [PASSED] drm_test_check_reject_audio_infoframe
[00:23:21] === [PASSED] drm_atomic_helper_connector_hdmi_infoframes ===
[00:23:21] ================= drm_managed (2 subtests) =================
[00:23:21] [PASSED] drm_test_managed_release_action
[00:23:21] [PASSED] drm_test_managed_run_action
[00:23:21] =================== [PASSED] drm_managed ===================
[00:23:21] =================== drm_mm (6 subtests) ====================
[00:23:21] [PASSED] drm_test_mm_init
[00:23:21] [PASSED] drm_test_mm_debug
[00:23:21] [PASSED] drm_test_mm_align32
[00:23:21] [PASSED] drm_test_mm_align64
[00:23:21] [PASSED] drm_test_mm_lowest
[00:23:21] [PASSED] drm_test_mm_highest
[00:23:21] ===================== [PASSED] drm_mm ======================
[00:23:21] ============= drm_modes_analog_tv (5 subtests) =============
[00:23:21] [PASSED] drm_test_modes_analog_tv_mono_576i
[00:23:21] [PASSED] drm_test_modes_analog_tv_ntsc_480i
[00:23:21] [PASSED] drm_test_modes_analog_tv_ntsc_480i_inlined
[00:23:21] [PASSED] drm_test_modes_analog_tv_pal_576i
[00:23:21] [PASSED] drm_test_modes_analog_tv_pal_576i_inlined
[00:23:21] =============== [PASSED] drm_modes_analog_tv ===============
[00:23:21] ============== drm_panic_helper (3 subtests) ===============
[00:23:21] ============= drm_test_panic_screen_user_map ==============
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 494 x 494 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 1920 x 1080 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 RG16 little-endian (0x36314752)
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 RG24 little-endian (0x34324752)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 494 x 494 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1920 x 1080 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 RG16 little-endian (0x36314752)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 RG24 little-endian (0x34324752)
[00:23:21] ========= [PASSED] drm_test_panic_screen_user_map ==========
[00:23:21] ============= drm_test_panic_screen_user_page =============
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 494 x 494 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 1920 x 1080 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 RG16 little-endian (0x36314752)
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 RG24 little-endian (0x34324752)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 494 x 494 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1920 x 1080 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 RG16 little-endian (0x36314752)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 RG24 little-endian (0x34324752)
[00:23:21] ========= [PASSED] drm_test_panic_screen_user_page =========
[00:23:21] ========== drm_test_panic_screen_user_set_pixel ===========
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 494 x 494 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 1920 x 1080 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 RG16 little-endian (0x36314752)
[00:23:21] [PASSED] Panic screen user, mode: 1024 x 768 RG24 little-endian (0x34324752)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 494 x 494 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1920 x 1080 XR24 little-endian (0x34325258)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 RG16 little-endian (0x36314752)
[00:23:21] [PASSED] Panic screen kmsg, mode: 1024 x 768 RG24 little-endian (0x34324752)
[00:23:21] ====== [PASSED] drm_test_panic_screen_user_set_pixel =======
[00:23:21] ================ [PASSED] drm_panic_helper =================
[00:23:21] ============== drm_plane_helper (2 subtests) ===============
[00:23:21] =============== drm_test_check_plane_state ================
[00:23:21] [PASSED] clipping_simple
[00:23:21] [PASSED] clipping_rotate_reflect
[00:23:21] [PASSED] positioning_simple
[00:23:21] [PASSED] upscaling
[00:23:21] [PASSED] downscaling
[00:23:21] [PASSED] rounding1
[00:23:21] [PASSED] rounding2
[00:23:21] [PASSED] rounding3
[00:23:21] [PASSED] rounding4
[00:23:21] =========== [PASSED] drm_test_check_plane_state ============
[00:23:21] =========== drm_test_check_invalid_plane_state ============
[00:23:21] [PASSED] positioning_invalid
[00:23:21] [PASSED] upscaling_invalid
[00:23:21] [PASSED] downscaling_invalid
[00:23:21] ======= [PASSED] drm_test_check_invalid_plane_state ========
[00:23:21] ================ [PASSED] drm_plane_helper =================
[00:23:21] ====== drm_connector_helper_tv_get_modes (1 subtest) =======
[00:23:21] ====== drm_test_connector_helper_tv_get_modes_check =======
[00:23:21] [PASSED] None
[00:23:21] [PASSED] PAL
[00:23:21] [PASSED] NTSC
[00:23:21] [PASSED] Both, NTSC Default
[00:23:21] [PASSED] Both, PAL Default
[00:23:21] [PASSED] Both, NTSC Default, with PAL on command-line
[00:23:21] [PASSED] Both, PAL Default, with NTSC on command-line
[00:23:21] == [PASSED] drm_test_connector_helper_tv_get_modes_check ===
[00:23:21] ======== [PASSED] drm_connector_helper_tv_get_modes ========
[00:23:21] ================== drm_rect (9 subtests) ===================
[00:23:21] [PASSED] drm_test_rect_clip_scaled_div_by_zero
[00:23:21] [PASSED] drm_test_rect_clip_scaled_not_clipped
[00:23:21] [PASSED] drm_test_rect_clip_scaled_clipped
[00:23:21] [PASSED] drm_test_rect_clip_scaled_signed_vs_unsigned
[00:23:21] ================= drm_test_rect_intersect =================
[00:23:21] [PASSED] top-left x bottom-right: 2x2+1+1 x 2x2+0+0
[00:23:21] [PASSED] top-right x bottom-left: 2x2+0+0 x 2x2+1-1
[00:23:21] [PASSED] bottom-left x top-right: 2x2+1-1 x 2x2+0+0
[00:23:21] [PASSED] bottom-right x top-left: 2x2+0+0 x 2x2+1+1
[00:23:21] [PASSED] right x left: 2x1+0+0 x 3x1+1+0
[00:23:21] [PASSED] left x right: 3x1+1+0 x 2x1+0+0
[00:23:21] [PASSED] up x bottom: 1x2+0+0 x 1x3+0-1
[00:23:21] [PASSED] bottom x up: 1x3+0-1 x 1x2+0+0
[00:23:21] [PASSED] touching corner: 1x1+0+0 x 2x2+1+1
[00:23:21] [PASSED] touching side: 1x1+0+0 x 1x1+1+0
[00:23:21] [PASSED] equal rects: 2x2+0+0 x 2x2+0+0
[00:23:21] [PASSED] inside another: 2x2+0+0 x 1x1+1+1
[00:23:21] [PASSED] far away: 1x1+0+0 x 1x1+3+6
[00:23:21] [PASSED] points intersecting: 0x0+5+10 x 0x0+5+10
[00:23:21] [PASSED] points not intersecting: 0x0+0+0 x 0x0+5+10
[00:23:21] ============= [PASSED] drm_test_rect_intersect =============
[00:23:21] ================ drm_test_rect_calc_hscale ================
[00:23:21] [PASSED] normal use
[00:23:21] [PASSED] out of max range
[00:23:21] [PASSED] out of min range
[00:23:21] [PASSED] zero dst
[00:23:21] [PASSED] negative src
[00:23:21] [PASSED] negative dst
[00:23:21] ============ [PASSED] drm_test_rect_calc_hscale ============
[00:23:21] ================ drm_test_rect_calc_vscale ================
[00:23:21] [PASSED] normal use
[00:23:21] [PASSED] out of max range
[00:23:21] [PASSED] out of min range
[00:23:21] [PASSED] zero dst
[00:23:21] [PASSED] negative src
[00:23:21] [PASSED] negative dst
[00:23:21] ============ [PASSED] drm_test_rect_calc_vscale ============
[00:23:21] ================== drm_test_rect_rotate ===================
[00:23:21] [PASSED] reflect-x
[00:23:21] [PASSED] reflect-y
[00:23:21] [PASSED] rotate-0
[00:23:21] [PASSED] rotate-90
[00:23:21] [PASSED] rotate-180
[00:23:21] [PASSED] rotate-270
[00:23:21] ============== [PASSED] drm_test_rect_rotate ===============
[00:23:21] ================ drm_test_rect_rotate_inv =================
[00:23:21] [PASSED] reflect-x
[00:23:21] [PASSED] reflect-y
[00:23:21] [PASSED] rotate-0
[00:23:21] [PASSED] rotate-90
[00:23:21] [PASSED] rotate-180
[00:23:21] [PASSED] rotate-270
[00:23:21] ============ [PASSED] drm_test_rect_rotate_inv =============
[00:23:21] ==================== [PASSED] drm_rect =====================
[00:23:21] ============ drm_sysfb_modeset_test (1 subtest) ============
[00:23:21] ============ drm_test_sysfb_build_fourcc_list =============
[00:23:21] [PASSED] no native formats
[00:23:21] [PASSED] XRGB8888 as native format
[00:23:21] [PASSED] remove duplicates
[00:23:21] [PASSED] convert alpha formats
[00:23:21] [PASSED] random formats
[00:23:21] ======== [PASSED] drm_test_sysfb_build_fourcc_list =========
[00:23:21] ============= [PASSED] drm_sysfb_modeset_test ==============
[00:23:21] ================== drm_fixp (2 subtests) ===================
[00:23:21] [PASSED] drm_test_int2fixp
[00:23:21] [PASSED] drm_test_sm2fixp
[00:23:21] ==================== [PASSED] drm_fixp =====================
[00:23:21] ============================================================
[00:23:21] Testing complete. Ran 667 tests: passed: 667
[00:23:21] Elapsed time: 28.617s total, 2.542s configuring, 25.754s building, 0.299s running
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/drm/ttm/tests/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/ttm/tests/.kunitconfig
[00:23:22] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[00:23:24] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
[00:23:34] Starting KUnit Kernel (1/1)...
[00:23:34] ============================================================
Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[00:23:34] ================= ttm_device (5 subtests) ==================
[00:23:34] [PASSED] ttm_device_init_basic
[00:23:34] [PASSED] ttm_device_init_multiple
[00:23:34] [PASSED] ttm_device_fini_basic
[00:23:34] [PASSED] ttm_device_init_no_vma_man
[00:23:34] ================== ttm_device_init_pools ==================
[00:23:34] [PASSED] No DMA allocations, no DMA32 required
[00:23:34] [PASSED] DMA allocations, DMA32 required
[00:23:34] [PASSED] No DMA allocations, DMA32 required
[00:23:34] [PASSED] DMA allocations, no DMA32 required
[00:23:34] ============== [PASSED] ttm_device_init_pools ==============
[00:23:34] =================== [PASSED] ttm_device ====================
[00:23:34] ================== ttm_pool (8 subtests) ===================
[00:23:34] ================== ttm_pool_alloc_basic ===================
[00:23:34] [PASSED] One page
[00:23:34] [PASSED] More than one page
[00:23:34] [PASSED] Above the allocation limit
[00:23:34] [PASSED] One page, with coherent DMA mappings enabled
[00:23:34] [PASSED] Above the allocation limit, with coherent DMA mappings enabled
[00:23:34] ============== [PASSED] ttm_pool_alloc_basic ===============
[00:23:34] ============== ttm_pool_alloc_basic_dma_addr ==============
[00:23:34] [PASSED] One page
[00:23:34] [PASSED] More than one page
[00:23:34] [PASSED] Above the allocation limit
[00:23:34] [PASSED] One page, with coherent DMA mappings enabled
[00:23:34] [PASSED] Above the allocation limit, with coherent DMA mappings enabled
[00:23:34] ========== [PASSED] ttm_pool_alloc_basic_dma_addr ==========
[00:23:34] [PASSED] ttm_pool_alloc_order_caching_match
[00:23:34] [PASSED] ttm_pool_alloc_caching_mismatch
[00:23:34] [PASSED] ttm_pool_alloc_order_mismatch
[00:23:34] [PASSED] ttm_pool_free_dma_alloc
[00:23:34] [PASSED] ttm_pool_free_no_dma_alloc
[00:23:34] [PASSED] ttm_pool_fini_basic
[00:23:34] ==================== [PASSED] ttm_pool =====================
[00:23:34] ================ ttm_resource (8 subtests) =================
[00:23:34] ================= ttm_resource_init_basic =================
[00:23:34] [PASSED] Init resource in TTM_PL_SYSTEM
[00:23:34] [PASSED] Init resource in TTM_PL_VRAM
[00:23:34] [PASSED] Init resource in a private placement
[00:23:34] [PASSED] Init resource in TTM_PL_SYSTEM, set placement flags
[00:23:34] ============= [PASSED] ttm_resource_init_basic =============
[00:23:34] [PASSED] ttm_resource_init_pinned
[00:23:34] [PASSED] ttm_resource_fini_basic
[00:23:34] [PASSED] ttm_resource_manager_init_basic
[00:23:34] [PASSED] ttm_resource_manager_usage_basic
[00:23:34] [PASSED] ttm_resource_manager_set_used_basic
[00:23:34] [PASSED] ttm_sys_man_alloc_basic
[00:23:34] [PASSED] ttm_sys_man_free_basic
[00:23:34] ================== [PASSED] ttm_resource ===================
[00:23:34] =================== ttm_tt (15 subtests) ===================
[00:23:34] ==================== ttm_tt_init_basic ====================
[00:23:34] [PASSED] Page-aligned size
[00:23:34] [PASSED] Extra pages requested
[00:23:34] ================ [PASSED] ttm_tt_init_basic ================
[00:23:34] [PASSED] ttm_tt_init_misaligned
[00:23:34] [PASSED] ttm_tt_fini_basic
[00:23:34] [PASSED] ttm_tt_fini_sg
[00:23:34] [PASSED] ttm_tt_fini_shmem
[00:23:34] [PASSED] ttm_tt_create_basic
[00:23:34] [PASSED] ttm_tt_create_invalid_bo_type
[00:23:34] [PASSED] ttm_tt_create_ttm_exists
[00:23:34] [PASSED] ttm_tt_create_failed
[00:23:34] [PASSED] ttm_tt_destroy_basic
[00:23:34] [PASSED] ttm_tt_populate_null_ttm
[00:23:34] [PASSED] ttm_tt_populate_populated_ttm
[00:23:34] [PASSED] ttm_tt_unpopulate_basic
[00:23:34] [PASSED] ttm_tt_unpopulate_empty_ttm
[00:23:34] [PASSED] ttm_tt_swapin_basic
[00:23:34] ===================== [PASSED] ttm_tt ======================
[00:23:34] =================== ttm_bo (14 subtests) ===================
[00:23:34] =========== ttm_bo_reserve_optimistic_no_ticket ===========
[00:23:34] [PASSED] Cannot be interrupted and sleeps
[00:23:34] [PASSED] Cannot be interrupted, locks straight away
[00:23:34] [PASSED] Can be interrupted, sleeps
[00:23:34] ======= [PASSED] ttm_bo_reserve_optimistic_no_ticket =======
[00:23:34] [PASSED] ttm_bo_reserve_locked_no_sleep
[00:23:34] [PASSED] ttm_bo_reserve_no_wait_ticket
[00:23:34] [PASSED] ttm_bo_reserve_double_resv
[00:23:34] [PASSED] ttm_bo_reserve_interrupted
[00:23:34] [PASSED] ttm_bo_reserve_deadlock
[00:23:34] [PASSED] ttm_bo_unreserve_basic
[00:23:34] [PASSED] ttm_bo_unreserve_pinned
[00:23:34] [PASSED] ttm_bo_unreserve_bulk
[00:23:34] [PASSED] ttm_bo_fini_basic
[00:23:34] [PASSED] ttm_bo_fini_shared_resv
[00:23:34] [PASSED] ttm_bo_pin_basic
[00:23:34] [PASSED] ttm_bo_pin_unpin_resource
[00:23:34] [PASSED] ttm_bo_multiple_pin_one_unpin
[00:23:34] ===================== [PASSED] ttm_bo ======================
[00:23:34] ============== ttm_bo_validate (22 subtests) ===============
[00:23:34] ============== ttm_bo_init_reserved_sys_man ===============
[00:23:34] [PASSED] Buffer object for userspace
[00:23:34] [PASSED] Kernel buffer object
[00:23:34] [PASSED] Shared buffer object
[00:23:34] ========== [PASSED] ttm_bo_init_reserved_sys_man ===========
[00:23:34] ============== ttm_bo_init_reserved_mock_man ==============
[00:23:34] [PASSED] Buffer object for userspace
[00:23:34] [PASSED] Kernel buffer object
[00:23:34] [PASSED] Shared buffer object
[00:23:34] ========== [PASSED] ttm_bo_init_reserved_mock_man ==========
[00:23:34] [PASSED] ttm_bo_init_reserved_resv
[00:23:34] ================== ttm_bo_validate_basic ==================
[00:23:34] [PASSED] Buffer object for userspace
[00:23:34] [PASSED] Kernel buffer object
[00:23:34] [PASSED] Shared buffer object
[00:23:34] ============== [PASSED] ttm_bo_validate_basic ==============
[00:23:34] [PASSED] ttm_bo_validate_invalid_placement
[00:23:34] ============= ttm_bo_validate_same_placement ==============
[00:23:34] [PASSED] System manager
[00:23:34] [PASSED] VRAM manager
[00:23:34] ========= [PASSED] ttm_bo_validate_same_placement ==========
[00:23:34] [PASSED] ttm_bo_validate_failed_alloc
[00:23:34] [PASSED] ttm_bo_validate_pinned
[00:23:34] [PASSED] ttm_bo_validate_busy_placement
[00:23:34] ================ ttm_bo_validate_multihop =================
[00:23:34] [PASSED] Buffer object for userspace
[00:23:34] [PASSED] Kernel buffer object
[00:23:34] [PASSED] Shared buffer object
[00:23:34] ============ [PASSED] ttm_bo_validate_multihop =============
[00:23:34] ========== ttm_bo_validate_no_placement_signaled ==========
[00:23:34] [PASSED] Buffer object in system domain, no page vector
[00:23:34] [PASSED] Buffer object in system domain with an existing page vector
[00:23:34] ====== [PASSED] ttm_bo_validate_no_placement_signaled ======
[00:23:34] ======== ttm_bo_validate_no_placement_not_signaled ========
[00:23:34] [PASSED] Buffer object for userspace
[00:23:34] [PASSED] Kernel buffer object
[00:23:34] [PASSED] Shared buffer object
[00:23:34] ==== [PASSED] ttm_bo_validate_no_placement_not_signaled ====
[00:23:34] [PASSED] ttm_bo_validate_move_fence_signaled
[00:23:35] ========= ttm_bo_validate_move_fence_not_signaled =========
[00:23:35] [PASSED] Waits for GPU
[00:23:35] [PASSED] Tries to lock straight away
[00:23:35] ===== [PASSED] ttm_bo_validate_move_fence_not_signaled =====
[00:23:35] [PASSED] ttm_bo_validate_swapout
[00:23:35] [PASSED] ttm_bo_validate_happy_evict
[00:23:35] [PASSED] ttm_bo_validate_all_pinned_evict
[00:23:35] [PASSED] ttm_bo_validate_allowed_only_evict
[00:23:35] [PASSED] ttm_bo_validate_deleted_evict
[00:23:35] [PASSED] ttm_bo_validate_busy_domain_evict
[00:23:35] [PASSED] ttm_bo_validate_evict_gutting
[00:23:35] [PASSED] ttm_bo_validate_recursive_evict
[00:23:35] ================= [PASSED] ttm_bo_validate =================
[00:23:35] ============================================================
[00:23:35] Testing complete. Ran 102 tests: passed: 102
[00:23:35] Elapsed time: 13.038s total, 2.555s configuring, 10.216s building, 0.222s running
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/dma-buf/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/dma-buf/.kunitconfig
[00:23:35] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[00:23:37] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
[00:23:46] Starting KUnit Kernel (1/1)...
[00:23:46] ============================================================
Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[00:23:46] =============== dma-buf-fence (12 subtests) ================
[00:23:46] [PASSED] test_sanitycheck
[00:23:46] [PASSED] test_signaling
[00:23:46] [PASSED] test_add_callback
[00:23:46] [PASSED] test_late_add_callback
[00:23:46] [PASSED] test_rm_callback
[00:23:46] [PASSED] test_late_rm_callback
[00:23:46] [PASSED] test_status
[00:23:46] [PASSED] test_error
[00:23:46] [PASSED] test_wait
[00:23:46] [PASSED] test_wait_timeout
[00:23:46] [PASSED] test_stub
[00:23:46] [SKIPPED] test_race_signal_callback (requires at least 2 CPUs)
[00:23:46] ================== [PASSED] dma-buf-fence ==================
[00:23:46] ============ dma-buf-fence-chain (11 subtests) =============
[00:23:46] [PASSED] test_sanitycheck
[00:23:46] [PASSED] test_find_seqno
[00:23:46] [PASSED] test_find_signaled
[00:23:46] [PASSED] test_find_out_of_order
[00:23:51] [PASSED] test_find_gap
[00:23:51] [PASSED] test_find_race
[00:23:51] [PASSED] test_signal_forward
[00:23:52] [PASSED] test_signal_backward
[00:23:52] [PASSED] test_wait_forward
[00:23:52] [PASSED] test_wait_backward
[00:23:52] [PASSED] test_wait_random
[00:23:52] =============== [PASSED] dma-buf-fence-chain ===============
[00:23:52] ============ dma-buf-fence-unwrap (11 subtests) ============
[00:23:52] [PASSED] test_sanitycheck
[00:23:52] [PASSED] test_unwrap_array
[00:23:52] [PASSED] test_unwrap_chain
[00:23:52] [PASSED] test_unwrap_chain_array
[00:23:52] [PASSED] test_unwrap_merge
[00:23:52] [PASSED] test_unwrap_merge_duplicate
[00:23:52] [PASSED] test_unwrap_merge_seqno
[00:23:52] [PASSED] test_unwrap_merge_order
[00:23:52] [PASSED] test_unwrap_merge_complex
[00:23:52] [PASSED] test_unwrap_merge_complex_seqno
[00:23:52] [PASSED] test_dedup_empty
[00:23:52] ============== [PASSED] dma-buf-fence-unwrap ===============
[00:23:52] ================ dma-buf-resv (5 subtests) =================
[00:23:52] [PASSED] test_sanitycheck
[00:23:52] ===================== test_signaling ======================
[00:23:52] [PASSED] kernel
[00:23:52] [PASSED] write
[00:23:52] [PASSED] read
[00:23:52] [PASSED] bookkeep
[00:23:52] ================= [PASSED] test_signaling ==================
[00:23:52] ====================== test_for_each ======================
[00:23:52] [PASSED] kernel
[00:23:52] [PASSED] write
[00:23:52] [PASSED] read
[00:23:52] [PASSED] bookkeep
[00:23:52] ================== [PASSED] test_for_each ==================
[00:23:52] ================= test_for_each_unlocked ==================
[00:23:52] [PASSED] kernel
[00:23:52] [PASSED] write
[00:23:52] [PASSED] read
[00:23:52] [PASSED] bookkeep
[00:23:52] ============= [PASSED] test_for_each_unlocked ==============
[00:23:52] ===================== test_get_fences =====================
[00:23:52] [PASSED] kernel
[00:23:52] [PASSED] write
[00:23:52] [PASSED] read
[00:23:52] [PASSED] bookkeep
[00:23:52] ================= [PASSED] test_get_fences =================
[00:23:52] ================== [PASSED] dma-buf-resv ===================
[00:23:52] ============================================================
[00:23:52] Testing complete. Ran 51 tests: passed: 50, skipped: 1
[00:23:52] Elapsed time: 16.827s total, 2.546s configuring, 9.010s building, 5.256s running
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 13/36] drm/xe: Add debugfs stats for DMA-mapped pages per order
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
0 siblings, 1 reply; 59+ messages in thread
From: Niranjana Vishwanathapura @ 2026-12-03 0:25 UTC (permalink / raw)
To: Matthew Brost
Cc: intel-xe, dri-devel, Thomas Hellström, Natalie Vock,
Arun Pravin
On Wed, Dec 02, 2026 at 03:33:00PM -0800, Matthew Brost wrote:
>From: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>
>Expose per-page-order DMA mapping counts for the system memory that the
>xe driver maps for GPU access, split into two categories: TTM buffer
>objects, and the GPU SVM / userptr ranges (which share a single
>drm_gpusvm instance per VM).
>
>The stats are visible at:
>
> <debugfs>/dri/<N>/dma_mapped_pages
>
>and are broken out into two rows (bo, svm/userptr), one column per page
>order, mirroring the layout of the TTM pool page_pool stat.
>
>For TTM BOs the per-order counts are derived from the DMA scatter-gather
>table: each mapped segment is physically contiguous, so its page count is
>split into the largest power-of-two runs (a segment of N pages contributes
>a 2^k chunk for the largest k with 2^k <= N, repeated for the remainder).
>Driving the accounting off the sg table rather than the pages[] array keeps
>it correct even when pages[] entries are cleared while still DMA-mapped,
>as happens on the defrag page-borrowing path. Dma-buf BOs are not
>accounted for in dma_mapped_pages stats.
>
>For the SVM and userptr ranges the accounting is driven by the
>drm_gpusvm @dma_map_account callback, which fires once per dma_addr[]
>entry at the exact point the entry is DMA-mapped and unmapped. This
>makes the accounting symmetric by construction and avoids driver-side
>walks that could drift across migration, partial unmaps and the iova vs
>non-iova paths. Only DRM_INTERCONNECT_SYSTEM entries are real DMA maps
>and counted; device interconnect (VRAM, P2P) entries are skipped, so the
>counter reflects only system pages actually mapped through the DMA layer.
>
>The callback is shared between the full SVM instance (fault mode) and the
>core drm_gpusvm_pages-only instance used for userptr, so userptr
>mappings are accounted in both the CONFIG_DRM_XE_GPUSVM=y and =n (but
>CONFIG_DRM_GPUSVM=y) configurations, into the same svm/userptr counter.
>
>Since the counts are only ever consumed through debugfs, gate the counter
>storage and all accounting on CONFIG_DEBUG_FS so that builds without
>debugfs carry no extra atomic traffic or device state; the drm_gpusvm
>callback is simply left unregistered in that case.
>
>On device teardown assert that every counter has returned to zero, to
>catch any unbalanced accounting (a leaked DMA mapping) during testing.
>
>Cc: Natalie Vock <nat@pixelcluster.dev>
>Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
>Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>Signed-off-by: Matthew Brost <matthew.brost@intel.com>
>---
> drivers/gpu/drm/xe/xe_bo.c | 53 ++++++++++++++++++++---
> drivers/gpu/drm/xe/xe_debugfs.c | 26 ++++++++++++
> drivers/gpu/drm/xe/xe_device.c | 24 +++++++++++
> drivers/gpu/drm/xe/xe_device_types.h | 17 ++++++++
> drivers/gpu/drm/xe/xe_svm.c | 8 +++-
> drivers/gpu/drm/xe/xe_svm.h | 4 +-
> drivers/gpu/drm/xe/xe_userptr.c | 63 ++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_userptr.h | 7 ++++
> 8 files changed, 194 insertions(+), 8 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
>index c89b39b503fe..ff5610ba4b74 100644
>--- a/drivers/gpu/drm/xe/xe_bo.c
>+++ b/drivers/gpu/drm/xe/xe_bo.c
>@@ -398,6 +398,50 @@ struct xe_ttm_tt {
> bool purgeable;
> };
>
>+/*
>+ * xe_tt_account_dma_pages - account DMA-mapped tt pages per order
>+ * @xe: the xe device
>+ * @xe_tt: the xe_ttm_tt whose sg table to walk
>+ * @sign: +1 to add, -1 to subtract
>+ *
>+ * Walk the tt's DMA scatter-gather table and split each (physically
>+ * contiguous) segment into the largest power-of-two page runs: a segment of N
>+ * pages contributes a 2^k chunk for the largest k with 2^k <= N, repeated for
>+ * the remainder. Accumulate the count of 2^k pages into
>+ * xe->mem.dma_mapped_pages[k]. Driving this off the sg table rather than
>+ * tt->pages keeps the accounting correct even when pages[] entries are cleared
>+ * while still DMA-mapped (e.g. the defrag page-borrowing path).
>+ */
>+#if IS_ENABLED(CONFIG_DEBUG_FS)
>+static void xe_tt_account_dma_pages(struct xe_device *xe,
>+ struct xe_ttm_tt *xe_tt, int sign)
>+{
>+ struct scatterlist *sg;
>+ unsigned int i;
>+
>+ for_each_sgtable_sg(xe_tt->sg, sg, i) {
>+ unsigned long nr_pages = sg->length >> PAGE_SHIFT;
>+
>+ while (nr_pages) {
>+ unsigned int order = min_t(unsigned int,
>+ __fls(nr_pages),
>+ MAX_PAGE_ORDER);
>+ unsigned long chunk = 1UL << order;
>+
>+ atomic_long_add((long)chunk * sign,
>+ &xe->mem.dma_mapped_pages[order]);
NIT...'chunk' here uses 'order' which is clamped value.
In xe_userptr_dma_map_account(), '1UL << addr->order' is used and
addr->order is not clamped. I think it is fine, just that this
asymmetry may raise eyebrows.
>+
>+ nr_pages -= chunk;
>+ }
>+ }
>+}
>+#else
>+static void xe_tt_account_dma_pages(struct xe_device *xe,
>+ struct xe_ttm_tt *xe_tt, int sign)
>+{
>+}
>+#endif
>+
> static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
> {
> struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
>@@ -427,6 +471,7 @@ static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
> return ret;
> }
>
>+ xe_tt_account_dma_pages(xe, xe_tt, 1);
> return 0;
> }
>
>@@ -435,6 +480,7 @@ static void xe_tt_unmap_sg(struct xe_device *xe, struct ttm_tt *tt)
> struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
>
> if (xe_tt->sg) {
>+ xe_tt_account_dma_pages(xe, xe_tt, -1);
> dma_unmap_sgtable(xe->drm.dev, xe_tt->sg,
> DMA_BIDIRECTIONAL, 0);
> sg_free_table(xe_tt->sg);
>@@ -1890,11 +1936,8 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo)
> ttm_bo->sg = NULL;
> xe_tt->sg = NULL;
> } else if (xe_tt->sg) {
>- dma_unmap_sgtable(ttm_to_xe_device(ttm_bo->bdev)->drm.dev,
>- xe_tt->sg,
>- DMA_BIDIRECTIONAL, 0);
>- sg_free_table(xe_tt->sg);
>- xe_tt->sg = NULL;
>+ xe_tt_unmap_sg(ttm_to_xe_device(ttm_bo->bdev),
>+ &xe_tt->ttm);
> }
> }
>
>diff --git a/drivers/gpu/drm/xe/xe_debugfs.c b/drivers/gpu/drm/xe/xe_debugfs.c
>index bc62d1054d29..be533435097f 100644
>--- a/drivers/gpu/drm/xe/xe_debugfs.c
>+++ b/drivers/gpu/drm/xe/xe_debugfs.c
>@@ -8,6 +8,7 @@
> #include <linux/array_size.h>
> #include <linux/bits.h>
> #include <linux/debugfs.h>
>+#include <linux/mmzone.h>
> #include <linux/fault-inject.h>
> #include <linux/string_helpers.h>
>
>@@ -349,6 +350,28 @@ static int dgfx_pcie_link_residencies_show(struct seq_file *m, void *data)
> return 0;
> }
>
>+static int dma_mapped_pages_show(struct seq_file *m, void *data)
>+{
>+ struct xe_device *xe = m->private;
>+ unsigned int i;
>+
>+ seq_printf(m, "%-11s ", "");
>+ for (i = 0; i < NR_PAGE_ORDERS; i++)
>+ seq_printf(m, " ---%2u---", i);
>+ seq_printf(m, "\n%-11s:", "bo");
>+ for (i = 0; i < NR_PAGE_ORDERS; i++)
>+ seq_printf(m, " %8ld",
>+ atomic_long_read(&xe->mem.dma_mapped_pages[i]));
>+ seq_printf(m, "\n%-11s:", "svm/userptr");
>+ for (i = 0; i < NR_PAGE_ORDERS; i++)
>+ seq_printf(m, " %8ld",
>+ atomic_long_read(&xe->mem.dma_mapped_pages_svm[i]));
>+ seq_puts(m, "\n");
>+
>+ return 0;
>+}
>+DEFINE_SHOW_ATTRIBUTE(dma_mapped_pages);
>+
> static const struct drm_info_list debugfs_list[] = {
> {"info", info, 0},
> { .name = "sriov_info", .show = sriov_info, },
>@@ -768,6 +791,9 @@ void xe_debugfs_register(struct xe_device *xe)
>
> xe_ttm_vram_debugfs_init(xe, root);
>
>+ debugfs_create_file("dma_mapped_pages", 0444, root, xe,
>+ &dma_mapped_pages_fops);
>+
> for_each_tile(tile, xe, tile_id)
> xe_tile_debugfs_register(tile);
>
>diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
>index 86de5f183c0a..781324ef950d 100644
>--- a/drivers/gpu/drm/xe/xe_device.c
>+++ b/drivers/gpu/drm/xe/xe_device.c
>@@ -382,6 +382,28 @@ bool xe_device_is_admin_only(const struct xe_device *xe)
> /* Number of allocated struct xe_device */
> static atomic_t xe_device_count;
>
>+#if IS_ENABLED(CONFIG_DEBUG_FS)
>+static void xe_device_assert_dma_pages_zero(struct xe_device *xe)
>+{
>+ unsigned int i;
>+
>+ /*
>+ * All BOs, userptr VMAs and SVM ranges must have been torn down by the
>+ * time the device is destroyed, so every DMA-mapped-pages counter must
>+ * have returned to zero. A non-zero value indicates unbalanced
>+ * accounting, i.e. a missing unmap-side decrement.
>+ */
>+ for (i = 0; i < NR_PAGE_ORDERS; i++) {
>+ xe_assert(xe, !atomic_long_read(&xe->mem.dma_mapped_pages[i]));
>+ xe_assert(xe, !atomic_long_read(&xe->mem.dma_mapped_pages_svm[i]));
>+ }
>+}
>+#else
>+static void xe_device_assert_dma_pages_zero(struct xe_device *xe)
>+{
>+}
>+#endif
>+
> static void xe_device_destroy(struct drm_device *dev, void *dummy)
> {
> struct xe_device *xe = to_xe_device(dev);
>@@ -405,6 +427,8 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
>
> ttm_device_fini(&xe->ttm);
>
>+ xe_device_assert_dma_pages_zero(xe);
>+
> if (atomic_dec_and_test(&xe_device_count))
> wake_up_var(&xe_device_count);
> }
>diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
>index e4e2fba44c8e..f00fc544d21c 100644
>--- a/drivers/gpu/drm/xe/xe_device_types.h
>+++ b/drivers/gpu/drm/xe/xe_device_types.h
>@@ -6,6 +6,7 @@
> #ifndef _XE_DEVICE_TYPES_H_
> #define _XE_DEVICE_TYPES_H_
>
>+#include <linux/mmzone.h>
> #include <linux/pci.h>
> #include <linux/workqueue.h>
>
>@@ -307,6 +308,22 @@ struct xe_device {
> struct xe_shrinker *shrinker;
> /** @mem.stolen_mgr: stolen memory manager. */
> struct xe_ttm_stolen_mgr *stolen_mgr;
>+#if IS_ENABLED(CONFIG_DEBUG_FS)
>+ /**
>+ * @mem.dma_mapped_pages: number of DMA-mapped pages per page
>+ * order currently live for this device, for TTM BOs. Only
>+ * accounted when CONFIG_DEBUG_FS is enabled, since it is solely
>+ * exposed through debugfs.
>+ */
>+ atomic_long_t dma_mapped_pages[NR_PAGE_ORDERS];
>+ /**
>+ * @mem.dma_mapped_pages_svm: number of DMA-mapped pages per
>+ * page order currently live for this device, for SVM ranges
>+ * and userptr VMAs (both share a single drm_gpusvm instance).
>+ * Only accounted when CONFIG_DEBUG_FS is enabled.
>+ */
>+ atomic_long_t dma_mapped_pages_svm[NR_PAGE_ORDERS];
>+#endif
> } mem;
>
> /** @sriov: device level virtualization data */
>diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
>index bc6902b5bf57..3f90b8314132 100644
>--- a/drivers/gpu/drm/xe/xe_svm.c
>+++ b/drivers/gpu/drm/xe/xe_svm.c
>@@ -24,6 +24,7 @@
> #include "xe_tile.h"
> #include "xe_tlb_inval.h"
> #include "xe_ttm_vram_mgr.h"
>+#include "xe_userptr.h"
> #include "xe_vm.h"
> #include "xe_vm_types.h"
> #include "xe_vram_types.h"
>@@ -850,6 +851,9 @@ static const struct drm_gpusvm_ops gpusvm_ops = {
> .range_alloc = xe_svm_range_alloc,
> .range_free = xe_svm_range_free,
> .invalidate = xe_svm_invalidate,
>+#if IS_ENABLED(CONFIG_DEBUG_FS)
>+ .dma_map_account = xe_userptr_dma_map_account,
>+#endif
> };
>
> static const unsigned long fault_chunk_sizes[] = {
>@@ -947,8 +951,8 @@ int xe_svm_init(struct xe_vm *vm)
> }
> } else {
> err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
>- NULL, 0, 0, 0, NULL,
>- NULL, 0);
>+ NULL, 0, 0, 0,
>+ xe_userptr_gpusvm_ops_get(), NULL, 0);
> if (err)
> goto out_err;
> }
>diff --git a/drivers/gpu/drm/xe/xe_svm.h b/drivers/gpu/drm/xe/xe_svm.h
>index ffc1cc808102..f8b908a74ba9 100644
>--- a/drivers/gpu/drm/xe/xe_svm.h
>+++ b/drivers/gpu/drm/xe/xe_svm.h
>@@ -249,6 +249,7 @@ struct drm_pagemap *xe_drm_pagemap_from_fd(int fd, u32 region_instance);
>
> #else
> #include <linux/interval_tree.h>
>+#include "xe_userptr.h"
> #include "xe_vm.h"
>
> struct drm_pagemap_addr;
>@@ -296,7 +297,8 @@ int xe_svm_init(struct xe_vm *vm)
> {
> #if IS_ENABLED(CONFIG_DRM_GPUSVM)
> return drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
>- NULL, 0, 0, 0, NULL, NULL, 0);
>+ NULL, 0, 0, 0,
>+ xe_userptr_gpusvm_ops_get(), NULL, 0);
> #else
> return 0;
> #endif
>diff --git a/drivers/gpu/drm/xe/xe_userptr.c b/drivers/gpu/drm/xe/xe_userptr.c
>index 39806ca9f54a..28770bffeced 100644
>--- a/drivers/gpu/drm/xe/xe_userptr.c
>+++ b/drivers/gpu/drm/xe/xe_userptr.c
>@@ -8,9 +8,72 @@
>
> #include <linux/mm.h>
>
>+#include <drm/drm_pagemap.h>
>+
> #include "xe_tlb_inval.h"
> #include "xe_trace_bo.h"
>
>+#if IS_ENABLED(CONFIG_DEBUG_FS)
>+/*
>+ * xe_userptr_dma_map_account() - drm_gpusvm DMA-mapping accounting callback
>+ * @gpusvm: The GPU SVM the mapping belongs to
>+ * @addr: The address descriptor of the chunk being (un)mapped
>+ * @sign: +1 when @addr was DMA-mapped, -1 when it is being unmapped
>+ *
>+ * Account, per page order, the system-memory pages DMA-mapped for GPU access
>+ * through the drm_gpusvm_pages instance shared by userptr (and, in fault mode,
>+ * SVM). Only DRM_INTERCONNECT_SYSTEM entries are real DMA maps and counted;
>+ * device interconnect (VRAM, P2P) entries are skipped. The counts are solely
>+ * exposed through debugfs, so the callback is only registered when
>+ * CONFIG_DEBUG_FS is enabled.
>+ */
>+void xe_userptr_dma_map_account(struct drm_gpusvm *gpusvm,
>+ const struct drm_pagemap_addr *addr,
>+ int sign)
>+{
>+ struct xe_vm *vm = container_of(gpusvm, struct xe_vm, svm.gpusvm);
NIT...should gpusvm_to_vm() be moved from xe_svm.c to xe_svm.h and used here
instead?
In anycase,
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Niranjana
>+ unsigned int order = addr->order;
>+
>+ if (addr->proto != DRM_INTERCONNECT_SYSTEM)
>+ return;
>+
>+ /*
>+ * The CPU-PTE map order reported by hmm can exceed MAX_PAGE_ORDER
>+ * (e.g. an order-18 1GB mapping), so clamp the array index to avoid an
>+ * out-of-bounds access. Clamping is symmetric across the +1/-1 calls,
>+ * so the per-order counters stay balanced.
>+ */
>+ order = min(order, (unsigned int)NR_PAGE_ORDERS - 1);
>+
>+ atomic_long_add((long)(1UL << addr->order) * sign,
>+ &vm->xe->mem.dma_mapped_pages_svm[order]);
>+}
>+
>+static const struct drm_gpusvm_ops xe_userptr_gpusvm_ops = {
>+ .dma_map_account = xe_userptr_dma_map_account,
>+};
>+#endif
>+
>+/**
>+ * xe_userptr_gpusvm_ops_get() - Accounting ops for the simple gpusvm instance
>+ *
>+ * The core drm_gpusvm_pages-only instance used for userptr (and, in fault
>+ * mode, shared with SVM) is initialised with these ops so that DMA-mapped
>+ * system pages are accounted and exposed through debugfs. Returns NULL when
>+ * CONFIG_DEBUG_FS is disabled, in which case no accounting is kept and the
>+ * instance is initialised without ops.
>+ *
>+ * Return: Pointer to the restricted &drm_gpusvm_ops, or NULL.
>+ */
>+const struct drm_gpusvm_ops *xe_userptr_gpusvm_ops_get(void)
>+{
>+#if IS_ENABLED(CONFIG_DEBUG_FS)
>+ return &xe_userptr_gpusvm_ops;
>+#else
>+ return NULL;
>+#endif
>+}
>+
> static void xe_userptr_assert_in_notifier(struct xe_vm *vm)
> {
> lockdep_assert(lockdep_is_held_type(&vm->svm.gpusvm.notifier_lock, 0) ||
>diff --git a/drivers/gpu/drm/xe/xe_userptr.h b/drivers/gpu/drm/xe/xe_userptr.h
>index 179f2aca26a3..52d9734ccecc 100644
>--- a/drivers/gpu/drm/xe/xe_userptr.h
>+++ b/drivers/gpu/drm/xe/xe_userptr.h
>@@ -151,6 +151,12 @@ struct xe_userptr {
> };
>
> #if IS_ENABLED(CONFIG_DRM_GPUSVM)
>+
>+#if IS_ENABLED(CONFIG_DEBUG_FS)
>+void xe_userptr_dma_map_account(struct drm_gpusvm *gpusvm,
>+ const struct drm_pagemap_addr *addr, int sign);
>+#endif
>+
> void xe_userptr_remove(struct xe_userptr_vma *uvma);
> int xe_userptr_setup(struct xe_userptr_vma *uvma, unsigned long start,
> unsigned long range);
>@@ -161,6 +167,7 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm);
> int xe_vm_userptr_check_repin(struct xe_vm *vm);
> int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma);
> int xe_vma_userptr_check_repin(struct xe_userptr_vma *uvma);
>+const struct drm_gpusvm_ops *xe_userptr_gpusvm_ops_get(void);
> #else
> static inline void xe_userptr_remove(struct xe_userptr_vma *uvma) {}
>
>--
>2.34.1
>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 13/36] drm/xe: Add debugfs stats for DMA-mapped pages per order
2026-12-03 0:25 ` Niranjana Vishwanathapura
@ 2026-12-03 0:29 ` Matthew Brost
0 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-03 0:29 UTC (permalink / raw)
To: Niranjana Vishwanathapura
Cc: intel-xe, dri-devel, Thomas Hellström, Natalie Vock,
Arun Pravin
On Wed, Dec 02, 2026 at 04:25:31PM -0800, Niranjana Vishwanathapura wrote:
> On Wed, Dec 02, 2026 at 03:33:00PM -0800, Matthew Brost wrote:
> > From: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> >
> > Expose per-page-order DMA mapping counts for the system memory that the
> > xe driver maps for GPU access, split into two categories: TTM buffer
> > objects, and the GPU SVM / userptr ranges (which share a single
> > drm_gpusvm instance per VM).
> >
> > The stats are visible at:
> >
> > <debugfs>/dri/<N>/dma_mapped_pages
> >
> > and are broken out into two rows (bo, svm/userptr), one column per page
> > order, mirroring the layout of the TTM pool page_pool stat.
> >
> > For TTM BOs the per-order counts are derived from the DMA scatter-gather
> > table: each mapped segment is physically contiguous, so its page count is
> > split into the largest power-of-two runs (a segment of N pages contributes
> > a 2^k chunk for the largest k with 2^k <= N, repeated for the remainder).
> > Driving the accounting off the sg table rather than the pages[] array keeps
> > it correct even when pages[] entries are cleared while still DMA-mapped,
> > as happens on the defrag page-borrowing path. Dma-buf BOs are not
> > accounted for in dma_mapped_pages stats.
> >
> > For the SVM and userptr ranges the accounting is driven by the
> > drm_gpusvm @dma_map_account callback, which fires once per dma_addr[]
> > entry at the exact point the entry is DMA-mapped and unmapped. This
> > makes the accounting symmetric by construction and avoids driver-side
> > walks that could drift across migration, partial unmaps and the iova vs
> > non-iova paths. Only DRM_INTERCONNECT_SYSTEM entries are real DMA maps
> > and counted; device interconnect (VRAM, P2P) entries are skipped, so the
> > counter reflects only system pages actually mapped through the DMA layer.
> >
> > The callback is shared between the full SVM instance (fault mode) and the
> > core drm_gpusvm_pages-only instance used for userptr, so userptr
> > mappings are accounted in both the CONFIG_DRM_XE_GPUSVM=y and =n (but
> > CONFIG_DRM_GPUSVM=y) configurations, into the same svm/userptr counter.
> >
> > Since the counts are only ever consumed through debugfs, gate the counter
> > storage and all accounting on CONFIG_DEBUG_FS so that builds without
> > debugfs carry no extra atomic traffic or device state; the drm_gpusvm
> > callback is simply left unregistered in that case.
> >
> > On device teardown assert that every counter has returned to zero, to
> > catch any unbalanced accounting (a leaked DMA mapping) during testing.
> >
> > Cc: Natalie Vock <nat@pixelcluster.dev>
> > Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
> > Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > ---
> > drivers/gpu/drm/xe/xe_bo.c | 53 ++++++++++++++++++++---
> > drivers/gpu/drm/xe/xe_debugfs.c | 26 ++++++++++++
> > drivers/gpu/drm/xe/xe_device.c | 24 +++++++++++
> > drivers/gpu/drm/xe/xe_device_types.h | 17 ++++++++
> > drivers/gpu/drm/xe/xe_svm.c | 8 +++-
> > drivers/gpu/drm/xe/xe_svm.h | 4 +-
> > drivers/gpu/drm/xe/xe_userptr.c | 63 ++++++++++++++++++++++++++++
> > drivers/gpu/drm/xe/xe_userptr.h | 7 ++++
> > 8 files changed, 194 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> > index c89b39b503fe..ff5610ba4b74 100644
> > --- a/drivers/gpu/drm/xe/xe_bo.c
> > +++ b/drivers/gpu/drm/xe/xe_bo.c
> > @@ -398,6 +398,50 @@ struct xe_ttm_tt {
> > bool purgeable;
> > };
> >
> > +/*
> > + * xe_tt_account_dma_pages - account DMA-mapped tt pages per order
> > + * @xe: the xe device
> > + * @xe_tt: the xe_ttm_tt whose sg table to walk
> > + * @sign: +1 to add, -1 to subtract
> > + *
> > + * Walk the tt's DMA scatter-gather table and split each (physically
> > + * contiguous) segment into the largest power-of-two page runs: a segment of N
> > + * pages contributes a 2^k chunk for the largest k with 2^k <= N, repeated for
> > + * the remainder. Accumulate the count of 2^k pages into
> > + * xe->mem.dma_mapped_pages[k]. Driving this off the sg table rather than
> > + * tt->pages keeps the accounting correct even when pages[] entries are cleared
> > + * while still DMA-mapped (e.g. the defrag page-borrowing path).
> > + */
> > +#if IS_ENABLED(CONFIG_DEBUG_FS)
> > +static void xe_tt_account_dma_pages(struct xe_device *xe,
> > + struct xe_ttm_tt *xe_tt, int sign)
> > +{
> > + struct scatterlist *sg;
> > + unsigned int i;
> > +
> > + for_each_sgtable_sg(xe_tt->sg, sg, i) {
> > + unsigned long nr_pages = sg->length >> PAGE_SHIFT;
> > +
> > + while (nr_pages) {
> > + unsigned int order = min_t(unsigned int,
> > + __fls(nr_pages),
> > + MAX_PAGE_ORDER);
> > + unsigned long chunk = 1UL << order;
> > +
> > + atomic_long_add((long)chunk * sign,
> > + &xe->mem.dma_mapped_pages[order]);
>
> NIT...'chunk' here uses 'order' which is clamped value.
> In xe_userptr_dma_map_account(), '1UL << addr->order' is used and
> addr->order is not clamped. I think it is fine, just that this
> asymmetry may raise eyebrows.
>
> > +
> > + nr_pages -= chunk;
> > + }
> > + }
> > +}
> > +#else
> > +static void xe_tt_account_dma_pages(struct xe_device *xe,
> > + struct xe_ttm_tt *xe_tt, int sign)
> > +{
> > +}
> > +#endif
> > +
> > static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
> > {
> > struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
> > @@ -427,6 +471,7 @@ static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt)
> > return ret;
> > }
> >
> > + xe_tt_account_dma_pages(xe, xe_tt, 1);
> > return 0;
> > }
> >
> > @@ -435,6 +480,7 @@ static void xe_tt_unmap_sg(struct xe_device *xe, struct ttm_tt *tt)
> > struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
> >
> > if (xe_tt->sg) {
> > + xe_tt_account_dma_pages(xe, xe_tt, -1);
> > dma_unmap_sgtable(xe->drm.dev, xe_tt->sg,
> > DMA_BIDIRECTIONAL, 0);
> > sg_free_table(xe_tt->sg);
> > @@ -1890,11 +1936,8 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo)
> > ttm_bo->sg = NULL;
> > xe_tt->sg = NULL;
> > } else if (xe_tt->sg) {
> > - dma_unmap_sgtable(ttm_to_xe_device(ttm_bo->bdev)->drm.dev,
> > - xe_tt->sg,
> > - DMA_BIDIRECTIONAL, 0);
> > - sg_free_table(xe_tt->sg);
> > - xe_tt->sg = NULL;
> > + xe_tt_unmap_sg(ttm_to_xe_device(ttm_bo->bdev),
> > + &xe_tt->ttm);
> > }
> > }
> >
> > diff --git a/drivers/gpu/drm/xe/xe_debugfs.c b/drivers/gpu/drm/xe/xe_debugfs.c
> > index bc62d1054d29..be533435097f 100644
> > --- a/drivers/gpu/drm/xe/xe_debugfs.c
> > +++ b/drivers/gpu/drm/xe/xe_debugfs.c
> > @@ -8,6 +8,7 @@
> > #include <linux/array_size.h>
> > #include <linux/bits.h>
> > #include <linux/debugfs.h>
> > +#include <linux/mmzone.h>
> > #include <linux/fault-inject.h>
> > #include <linux/string_helpers.h>
> >
> > @@ -349,6 +350,28 @@ static int dgfx_pcie_link_residencies_show(struct seq_file *m, void *data)
> > return 0;
> > }
> >
> > +static int dma_mapped_pages_show(struct seq_file *m, void *data)
> > +{
> > + struct xe_device *xe = m->private;
> > + unsigned int i;
> > +
> > + seq_printf(m, "%-11s ", "");
> > + for (i = 0; i < NR_PAGE_ORDERS; i++)
> > + seq_printf(m, " ---%2u---", i);
> > + seq_printf(m, "\n%-11s:", "bo");
> > + for (i = 0; i < NR_PAGE_ORDERS; i++)
> > + seq_printf(m, " %8ld",
> > + atomic_long_read(&xe->mem.dma_mapped_pages[i]));
> > + seq_printf(m, "\n%-11s:", "svm/userptr");
> > + for (i = 0; i < NR_PAGE_ORDERS; i++)
> > + seq_printf(m, " %8ld",
> > + atomic_long_read(&xe->mem.dma_mapped_pages_svm[i]));
> > + seq_puts(m, "\n");
> > +
> > + return 0;
> > +}
> > +DEFINE_SHOW_ATTRIBUTE(dma_mapped_pages);
> > +
> > static const struct drm_info_list debugfs_list[] = {
> > {"info", info, 0},
> > { .name = "sriov_info", .show = sriov_info, },
> > @@ -768,6 +791,9 @@ void xe_debugfs_register(struct xe_device *xe)
> >
> > xe_ttm_vram_debugfs_init(xe, root);
> >
> > + debugfs_create_file("dma_mapped_pages", 0444, root, xe,
> > + &dma_mapped_pages_fops);
> > +
> > for_each_tile(tile, xe, tile_id)
> > xe_tile_debugfs_register(tile);
> >
> > diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> > index 86de5f183c0a..781324ef950d 100644
> > --- a/drivers/gpu/drm/xe/xe_device.c
> > +++ b/drivers/gpu/drm/xe/xe_device.c
> > @@ -382,6 +382,28 @@ bool xe_device_is_admin_only(const struct xe_device *xe)
> > /* Number of allocated struct xe_device */
> > static atomic_t xe_device_count;
> >
> > +#if IS_ENABLED(CONFIG_DEBUG_FS)
> > +static void xe_device_assert_dma_pages_zero(struct xe_device *xe)
> > +{
> > + unsigned int i;
> > +
> > + /*
> > + * All BOs, userptr VMAs and SVM ranges must have been torn down by the
> > + * time the device is destroyed, so every DMA-mapped-pages counter must
> > + * have returned to zero. A non-zero value indicates unbalanced
> > + * accounting, i.e. a missing unmap-side decrement.
> > + */
> > + for (i = 0; i < NR_PAGE_ORDERS; i++) {
> > + xe_assert(xe, !atomic_long_read(&xe->mem.dma_mapped_pages[i]));
> > + xe_assert(xe, !atomic_long_read(&xe->mem.dma_mapped_pages_svm[i]));
> > + }
> > +}
> > +#else
> > +static void xe_device_assert_dma_pages_zero(struct xe_device *xe)
> > +{
> > +}
> > +#endif
> > +
> > static void xe_device_destroy(struct drm_device *dev, void *dummy)
> > {
> > struct xe_device *xe = to_xe_device(dev);
> > @@ -405,6 +427,8 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
> >
> > ttm_device_fini(&xe->ttm);
> >
> > + xe_device_assert_dma_pages_zero(xe);
> > +
> > if (atomic_dec_and_test(&xe_device_count))
> > wake_up_var(&xe_device_count);
> > }
> > diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
> > index e4e2fba44c8e..f00fc544d21c 100644
> > --- a/drivers/gpu/drm/xe/xe_device_types.h
> > +++ b/drivers/gpu/drm/xe/xe_device_types.h
> > @@ -6,6 +6,7 @@
> > #ifndef _XE_DEVICE_TYPES_H_
> > #define _XE_DEVICE_TYPES_H_
> >
> > +#include <linux/mmzone.h>
> > #include <linux/pci.h>
> > #include <linux/workqueue.h>
> >
> > @@ -307,6 +308,22 @@ struct xe_device {
> > struct xe_shrinker *shrinker;
> > /** @mem.stolen_mgr: stolen memory manager. */
> > struct xe_ttm_stolen_mgr *stolen_mgr;
> > +#if IS_ENABLED(CONFIG_DEBUG_FS)
> > + /**
> > + * @mem.dma_mapped_pages: number of DMA-mapped pages per page
> > + * order currently live for this device, for TTM BOs. Only
> > + * accounted when CONFIG_DEBUG_FS is enabled, since it is solely
> > + * exposed through debugfs.
> > + */
> > + atomic_long_t dma_mapped_pages[NR_PAGE_ORDERS];
> > + /**
> > + * @mem.dma_mapped_pages_svm: number of DMA-mapped pages per
> > + * page order currently live for this device, for SVM ranges
> > + * and userptr VMAs (both share a single drm_gpusvm instance).
> > + * Only accounted when CONFIG_DEBUG_FS is enabled.
> > + */
> > + atomic_long_t dma_mapped_pages_svm[NR_PAGE_ORDERS];
> > +#endif
> > } mem;
> >
> > /** @sriov: device level virtualization data */
> > diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
> > index bc6902b5bf57..3f90b8314132 100644
> > --- a/drivers/gpu/drm/xe/xe_svm.c
> > +++ b/drivers/gpu/drm/xe/xe_svm.c
> > @@ -24,6 +24,7 @@
> > #include "xe_tile.h"
> > #include "xe_tlb_inval.h"
> > #include "xe_ttm_vram_mgr.h"
> > +#include "xe_userptr.h"
> > #include "xe_vm.h"
> > #include "xe_vm_types.h"
> > #include "xe_vram_types.h"
> > @@ -850,6 +851,9 @@ static const struct drm_gpusvm_ops gpusvm_ops = {
> > .range_alloc = xe_svm_range_alloc,
> > .range_free = xe_svm_range_free,
> > .invalidate = xe_svm_invalidate,
> > +#if IS_ENABLED(CONFIG_DEBUG_FS)
> > + .dma_map_account = xe_userptr_dma_map_account,
> > +#endif
> > };
> >
> > static const unsigned long fault_chunk_sizes[] = {
> > @@ -947,8 +951,8 @@ int xe_svm_init(struct xe_vm *vm)
> > }
> > } else {
> > err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
> > - NULL, 0, 0, 0, NULL,
> > - NULL, 0);
> > + NULL, 0, 0, 0,
> > + xe_userptr_gpusvm_ops_get(), NULL, 0);
> > if (err)
> > goto out_err;
> > }
> > diff --git a/drivers/gpu/drm/xe/xe_svm.h b/drivers/gpu/drm/xe/xe_svm.h
> > index ffc1cc808102..f8b908a74ba9 100644
> > --- a/drivers/gpu/drm/xe/xe_svm.h
> > +++ b/drivers/gpu/drm/xe/xe_svm.h
> > @@ -249,6 +249,7 @@ struct drm_pagemap *xe_drm_pagemap_from_fd(int fd, u32 region_instance);
> >
> > #else
> > #include <linux/interval_tree.h>
> > +#include "xe_userptr.h"
> > #include "xe_vm.h"
> >
> > struct drm_pagemap_addr;
> > @@ -296,7 +297,8 @@ int xe_svm_init(struct xe_vm *vm)
> > {
> > #if IS_ENABLED(CONFIG_DRM_GPUSVM)
> > return drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
> > - NULL, 0, 0, 0, NULL, NULL, 0);
> > + NULL, 0, 0, 0,
> > + xe_userptr_gpusvm_ops_get(), NULL, 0);
> > #else
> > return 0;
> > #endif
> > diff --git a/drivers/gpu/drm/xe/xe_userptr.c b/drivers/gpu/drm/xe/xe_userptr.c
> > index 39806ca9f54a..28770bffeced 100644
> > --- a/drivers/gpu/drm/xe/xe_userptr.c
> > +++ b/drivers/gpu/drm/xe/xe_userptr.c
> > @@ -8,9 +8,72 @@
> >
> > #include <linux/mm.h>
> >
> > +#include <drm/drm_pagemap.h>
> > +
> > #include "xe_tlb_inval.h"
> > #include "xe_trace_bo.h"
> >
> > +#if IS_ENABLED(CONFIG_DEBUG_FS)
> > +/*
> > + * xe_userptr_dma_map_account() - drm_gpusvm DMA-mapping accounting callback
> > + * @gpusvm: The GPU SVM the mapping belongs to
> > + * @addr: The address descriptor of the chunk being (un)mapped
> > + * @sign: +1 when @addr was DMA-mapped, -1 when it is being unmapped
> > + *
> > + * Account, per page order, the system-memory pages DMA-mapped for GPU access
> > + * through the drm_gpusvm_pages instance shared by userptr (and, in fault mode,
> > + * SVM). Only DRM_INTERCONNECT_SYSTEM entries are real DMA maps and counted;
> > + * device interconnect (VRAM, P2P) entries are skipped. The counts are solely
> > + * exposed through debugfs, so the callback is only registered when
> > + * CONFIG_DEBUG_FS is enabled.
> > + */
> > +void xe_userptr_dma_map_account(struct drm_gpusvm *gpusvm,
> > + const struct drm_pagemap_addr *addr,
> > + int sign)
> > +{
> > + struct xe_vm *vm = container_of(gpusvm, struct xe_vm, svm.gpusvm);
>
> NIT...should gpusvm_to_vm() be moved from xe_svm.c to xe_svm.h and used here
> instead?
>
Not a huge ROI on that and xe_svm doesn't build in some Kconfigs, I
suppose if it is inline in xe_svm.h it probably doesn't matter but I'd
rather not have include xe_svm.h just container_of.
Matt
> In anycase,
> Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
>
> Niranjana
>
> > + unsigned int order = addr->order;
> > +
> > + if (addr->proto != DRM_INTERCONNECT_SYSTEM)
> > + return;
> > +
> > + /*
> > + * The CPU-PTE map order reported by hmm can exceed MAX_PAGE_ORDER
> > + * (e.g. an order-18 1GB mapping), so clamp the array index to avoid an
> > + * out-of-bounds access. Clamping is symmetric across the +1/-1 calls,
> > + * so the per-order counters stay balanced.
> > + */
> > + order = min(order, (unsigned int)NR_PAGE_ORDERS - 1);
> > +
> > + atomic_long_add((long)(1UL << addr->order) * sign,
> > + &vm->xe->mem.dma_mapped_pages_svm[order]);
> > +}
> > +
> > +static const struct drm_gpusvm_ops xe_userptr_gpusvm_ops = {
> > + .dma_map_account = xe_userptr_dma_map_account,
> > +};
> > +#endif
> > +
> > +/**
> > + * xe_userptr_gpusvm_ops_get() - Accounting ops for the simple gpusvm instance
> > + *
> > + * The core drm_gpusvm_pages-only instance used for userptr (and, in fault
> > + * mode, shared with SVM) is initialised with these ops so that DMA-mapped
> > + * system pages are accounted and exposed through debugfs. Returns NULL when
> > + * CONFIG_DEBUG_FS is disabled, in which case no accounting is kept and the
> > + * instance is initialised without ops.
> > + *
> > + * Return: Pointer to the restricted &drm_gpusvm_ops, or NULL.
> > + */
> > +const struct drm_gpusvm_ops *xe_userptr_gpusvm_ops_get(void)
> > +{
> > +#if IS_ENABLED(CONFIG_DEBUG_FS)
> > + return &xe_userptr_gpusvm_ops;
> > +#else
> > + return NULL;
> > +#endif
> > +}
> > +
> > static void xe_userptr_assert_in_notifier(struct xe_vm *vm)
> > {
> > lockdep_assert(lockdep_is_held_type(&vm->svm.gpusvm.notifier_lock, 0) ||
> > diff --git a/drivers/gpu/drm/xe/xe_userptr.h b/drivers/gpu/drm/xe/xe_userptr.h
> > index 179f2aca26a3..52d9734ccecc 100644
> > --- a/drivers/gpu/drm/xe/xe_userptr.h
> > +++ b/drivers/gpu/drm/xe/xe_userptr.h
> > @@ -151,6 +151,12 @@ struct xe_userptr {
> > };
> >
> > #if IS_ENABLED(CONFIG_DRM_GPUSVM)
> > +
> > +#if IS_ENABLED(CONFIG_DEBUG_FS)
> > +void xe_userptr_dma_map_account(struct drm_gpusvm *gpusvm,
> > + const struct drm_pagemap_addr *addr, int sign);
> > +#endif
> > +
> > void xe_userptr_remove(struct xe_userptr_vma *uvma);
> > int xe_userptr_setup(struct xe_userptr_vma *uvma, unsigned long start,
> > unsigned long range);
> > @@ -161,6 +167,7 @@ int __xe_vm_userptr_needs_repin(struct xe_vm *vm);
> > int xe_vm_userptr_check_repin(struct xe_vm *vm);
> > int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma);
> > int xe_vma_userptr_check_repin(struct xe_userptr_vma *uvma);
> > +const struct drm_gpusvm_ops *xe_userptr_gpusvm_ops_get(void);
> > #else
> > static inline void xe_userptr_remove(struct xe_userptr_vma *uvma) {}
> >
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 14/36] drm/xe: Track BOs backed at a sub-optimal page order
2026-12-02 23:53 ` sashiko-bot
@ 2026-12-03 0:34 ` Matthew Brost
0 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-03 0:34 UTC (permalink / raw)
To: sashiko-reviews; +Cc: intel-xe, dri-devel
On Wed, Dec 02, 2026 at 11:53:58PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] drm/xe: no-op xe_bo_defrag_update() on CPU fault in
> xe_bo_fault_migrate()
> --
>
> commit 22495e3a9f5a9f486e4a553586605bb281ab160e
> Author: Matthew Brost <matthew.brost@intel.com>
>
> drm/xe: Track BOs backed at a sub-optimal page order
>
> This commit adds per-device tracking for buffer objects whose backing TT
> pages were allocated below the pool's beneficial order so they can be
> candidates for future defragmentation.
>
> > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> > index ff5610ba4b740..98c0b32e95439 100644
> > --- a/drivers/gpu/drm/xe/xe_bo.c
> > +++ b/drivers/gpu/drm/xe/xe_bo.c
> [ ... ]
> > +static bool xe_bo_needs_defrag(struct xe_bo *bo)
> > +{
> > + struct ttm_buffer_object *ttm_bo = &bo->ttm;
> > + struct ttm_tt *tt = ttm_bo->ttm;
> > +
> > + xe_bo_assert_held(bo);
> > +
> > + return xe_bo_defrag_supported(xe_bo_device(bo)) &&
> > + ttm_bo->type == ttm_bo_type_device && tt &&
> > + !xe_bo_madv_is_dontneed(bo) &&
> > + ttm_tt_is_populated(tt) &&
> > + ttm_tt_is_beneficial_order_failed(tt) &&
> > + ttm_bo->resource && ttm_bo->resource->mem_type == XE_PL_TT &&
> > + !xe_bo_is_pinned(bo);
> > +}
> [ ... ]
> > @@ -2245,9 +2379,14 @@ static int xe_bo_fault_migrate(struct xe_bo *bo, struct ttm_operation_ctx *ctx,
> > int err = 0;
> >
> > if (ttm_manager_type(tbo->bdev, tbo->resource->mem_type)->use_tt) {
> > + bool populated = tbo->ttm && ttm_tt_is_populated(tbo->ttm);
> > +
> > err = xe_bo_wait_usage_kernel(bo, ctx);
> > - if (!err)
> > + if (!err) {
> > err = ttm_bo_populate(&bo->ttm, ctx);
> > + if (!err && !populated)
> > + xe_bo_defrag_update(bo);
> > + }
> > } else if (should_migrate_to_smem(bo)) {
>
> [Severity: Medium]
> Can xe_bo_defrag_update(bo) ever add a BO to xe->mem.defrag.list from
> xe_bo_fault_migrate()?
>
This is dead code and we actually don't have to call xe_bo_defrag_update
here.
The CPU is free to fault the buffer + populate when in SYSTEM but before
GPU can use we move to TT which will call xe_bo_defrag_update in
xe_bo_move. So I'm going to remove this code in the next rev.
Matt
> Any BO resident in XE_PL_TT is already populated before xe_bo_move() runs,
> and all shrink, swapout and deferred-backing paths leave unpopulated BOs
> in XE_PL_SYSTEM. When !populated is true here, tbo->resource->mem_type is
> always XE_PL_SYSTEM, and ttm_bo_populate() populates tbo->ttm in place
> without changing the resource's mem_type. Because xe_bo_needs_defrag()
> requires ttm_bo->resource->mem_type == XE_PL_TT, BOs populated on a CPU
> page fault at a sub-optimal order will never be added to the defrag list.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=14
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move()
2026-12-02 23:55 ` sashiko-bot
@ 2026-12-03 0:45 ` Matthew Brost
0 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-03 0:45 UTC (permalink / raw)
To: sashiko-reviews; +Cc: intel-xe, dri-devel
On Wed, Dec 02, 2026 at 11:55:44PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [High] drm/xe: loss of FlatCCS extra TT pages on DGFX defrag in
> xe_bo_move()
> --
>
> commit fb1ace888ac8c6157078a250c431da6e90c2457a
> Author: Matthew Brost <matthew.brost@intel.com>
>
> drm/xe: Handle defrag moves in xe_bo_move()
>
> This commit updates xe_bo_move() to handle defragmentation moves by
> copying data from the BO's stashed defrag_old_tt to the newly allocated
> backing via xe_migrate_copy_defrag().
>
> > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> > index 98c0b32e95439..4c735ec8754ea 100644
> > --- a/drivers/gpu/drm/xe/xe_bo.c
> > +++ b/drivers/gpu/drm/xe/xe_bo.c
> > @@ -1291,6 +1291,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
> > bool move_lacks_source;
> > bool tt_has_data;
> > bool needs_clear;
> > + bool has_defrag_old_tt = !!ttm_bo->defrag_old_tt;
> > bool handle_system_ccs = (!IS_DGFX(xe) && xe_bo_needs_ccs_pages(bo) &&
> > ttm && ttm_tt_is_populated(ttm)) ? true : false;
> > int ret = 0;
>
> [ ... ]
>
> > @@ -1463,6 +1474,12 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
> >
> > fence = xe_migrate_clear(migrate, bo, new_mem, flags,
> > ctx->interruptible);
> > + } else if (has_defrag_old_tt) {
> > + struct xe_ttm_tt *old_xe_tt =
> > + container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm);
> > +
> > + fence = xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem,
> > + old_xe_tt->sg, handle_system_ccs);
> > } else {
> > fence = xe_migrate_copy(migrate, bo, bo, old_mem, new_mem,
> > handle_system_ccs, ctx->interruptible);
>
> [Severity: High]
> Does this lose the saved FlatCCS pages when defragmenting an evicted
> VRAM BO on DG2?
>
> On discrete GPUs with FlatCCS and GRAPHICS_VER(xe) < 20 (DG2), a
> compressible VRAM-only BO evicted to XE_PL_TT stores its saved FlatCCS
> state in extra TT pages starting at xe_bo_ccs_pages_start(bo), and
> xe_bo_needs_defrag() admits that evicted BO for defragmentation when
We shouldn't be defraging VRAM-only BOs which are evicted, this is real
issue and a one line fix in patch 14. Will fix.
Matt
> ttm_tt_is_beneficial_order_failed(tt) is set. During the defrag move,
> handle_system_ccs is false because IS_DGFX(xe) is true, and
> xe_migrate_copy_defrag() only copies [0, xe_bo_size(bo)), leaving any
> newly reallocated 2 MB chunk overlapping the trailing extra CCS pages in
> bo->ttm uninitialized. When the BO is later validated back to VRAM,
> corrupted FlatCCS metadata is restored.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=16
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 17/36] drm/xe: Skip self-copies for borrowed pages on defrag moves
2026-12-02 23:52 ` sashiko-bot
@ 2026-12-03 0:52 ` Matthew Brost
0 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-03 0:52 UTC (permalink / raw)
To: sashiko-reviews; +Cc: intel-xe, dri-devel
On Wed, Dec 02, 2026 at 11:52:57PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] drm/xe: WARN_ON and -EINVAL in __xe_migrate_copy() on
> extra_pages-only defrag
> - [Low] drm/xe: commit message claims stub fence on no-op copy in
> __xe_migrate_copy()
> --
>
> commit ce7de21d385e57fce79126c867241da7e3be2512
> Author: Matthew Brost <matthew.brost@intel.com>
>
> drm/xe: Skip self-copies for borrowed pages on defrag moves
>
> This commit skips GPU data blits on the defragmentation data pass for
> pages that the new ttm_tt borrowed directly from the old ttm_tt.
>
> > When an entire L0 chunk turns out to be borrowed, skip it outright: no
> > batch buffer is allocated and no GPU commands are issued, the cursors are
> > just advanced past the chunk. If every chunk of the move is borrowed the
> > copy is a complete no-op, so hand back a signaled stub fence.
>
> [Severity: Low]
> This isn't a bug, but the commit message still says a signaled stub fence
> is returned when every chunk is borrowed, whereas v5 changed
> __xe_migrate_copy() to warn on !fence and return ERR_PTR(-EINVAL).
>
Will fix.
> > diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> > index 71192fbd722d6..5b40405aaba90 100644
> > --- a/drivers/gpu/drm/xe/xe_migrate.c
> > +++ b/drivers/gpu/drm/xe/xe_migrate.c
>
> [ ... ]
>
> > @@ -1442,9 +1513,30 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
> > xe_assert(xe, IS_ALIGNED(ccs_it.start, PAGE_SIZE));
> > }
> >
> > - /* Add copy commands size here */
> > + /*
> > + * Add copy commands size here. On the defrag data pass the blit
> > + * is split into one command per run of non-borrowed pages, so
> > + * size for the number of runs actually needed.
> > + */
> > + if (skip_borrowed)
> > + ndata_blits = emit_copy_chunks(gt, NULL, 0, 0, src_L0,
> > + src_tt, dst_tt, start_page);
> > +
> > + /*
> > + * If every page in this chunk was borrowed there is nothing to
> > + * copy: don't build a batch or issue any GPU commands, just
> > + * advance the cursors past the chunk. The non-vram tt cursors
> > + * would otherwise be advanced by emit_pte().
> > + */
> > + if (skip_borrowed && !ndata_blits) {
> > + xe_res_next(&src_it, src_L0);
> > + xe_res_next(&dst_it, src_L0);
> > + size -= src_L0;
> > + continue;
> > + }
>
> [ ... ]
>
> > @@ -1529,6 +1624,15 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
> > return ERR_PTR(err);
> > }
> >
> > + /*
> > + * A defrag move always (re)allocates at least one chunk (TTM fails a
> > + * zero-progress defrag move), so at least one page differs and a job
> > + * carrying the resv dependencies is always emitted. A signaled stub
> > + * here would let the old tt be torn down under in-flight GPU work.
> > + */
> > + if (XE_WARN_ON(!fence))
> > + return ERR_PTR(-EINVAL);
> > +
> > return fence;
> > }
>
> [Severity: Medium]
> Can __xe_migrate_copy() hit XE_WARN_ON(!fence) and fail the move with
> -EINVAL when a defrag pass only reallocates pages in the trailing CCS
> extra_pages region?
>
Ugh, this looks possible with a BO over 1G. I think we will have extract
a singleton from the dma-resv bookkeep slot here if !fence.
Matt
> When xe_bo_needs_ccs_pages(bo) is true, xe_ttm_tt_create() appends
> extra_pages beyond xe_bo_size(bo) >> PAGE_SHIFT to tt->num_pages, and the
> TTM pool allocator defragments across the full [0, tt->num_pages) array.
> If all data chunks in [0, xe_bo_size(bo)) are already at beneficial order
> (either initially or after earlier budget-limited defrag passes) and only
> a beneficial-order chunk in the trailing extra_pages region is upgraded,
> TTM's defrag allocation succeeds while borrowing every data page.
> Because __xe_migrate_copy() only iterates over size = xe_bo_size(src_bo),
> emit_copy_chunks() returns 0 for every pass and the loop finishes with
> fence == NULL, triggering the warning and leaving the BO on the defrag
> list to fail again on subsequent passes.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=17
^ permalink raw reply [flat|nested] 59+ messages in thread
* ✓ Xe.CI.BAT: success for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2)
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
` (37 preceding siblings ...)
2026-12-03 0:23 ` ✓ CI.KUnit: success " Patchwork
@ 2026-12-03 0:56 ` Patchwork
38 siblings, 0 replies; 59+ messages in thread
From: Patchwork @ 2026-12-03 0:56 UTC (permalink / raw)
To: Matthew Brost; +Cc: intel-xe
[-- Attachment #1: Type: text/plain, Size: 1486 bytes --]
== Series Details ==
Series: drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2)
URL : https://patchwork.freedesktop.org/series/180217/
State : success
== Summary ==
CI Bug Log - changes from xe-6282-acd75be5933b65fbec28b648d318128a8b26593a_BAT -> xe-pw-180217v2_BAT
====================================================
Summary
-------
**SUCCESS**
No regressions found.
Participating hosts (12 -> 12)
------------------------------
No changes in participating hosts
Known issues
------------
Here are the changes found in xe-pw-180217v2_BAT that come from known issues:
### IGT changes ###
#### Possible fixes ####
* igt@core_hotunplug@unbind-rebind:
- bat-bmg-2: [ABORT][1] ([Intel XE#9841]) -> [PASS][2]
[1]: https://intel-gfx-ci.01.org/tree/intel-xe/xe-6282-acd75be5933b65fbec28b648d318128a8b26593a/bat-bmg-2/igt@core_hotunplug@unbind-rebind.html
[2]: https://intel-gfx-ci.01.org/tree/intel-xe/xe-pw-180217v2/bat-bmg-2/igt@core_hotunplug@unbind-rebind.html
[Intel XE#9841]: https://gitlab.freedesktop.org/drm/xe/kernel/issues/9841
Build changes
-------------
* Linux: xe-6282-acd75be5933b65fbec28b648d318128a8b26593a -> xe-pw-180217v2
IGT_9223: 9223
xe-6282-acd75be5933b65fbec28b648d318128a8b26593a: acd75be5933b65fbec28b648d318128a8b26593a
xe-pw-180217v2: 180217v2
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/intel-xe/xe-pw-180217v2/index.html
[-- Attachment #2: Type: text/html, Size: 2051 bytes --]
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v5 18/36] drm/xe: Add a page defragmentation worker
2026-12-03 0:12 ` sashiko-bot
@ 2026-12-03 1:00 ` Matthew Brost
0 siblings, 0 replies; 59+ messages in thread
From: Matthew Brost @ 2026-12-03 1:00 UTC (permalink / raw)
To: sashiko-reviews; +Cc: intel-xe, dri-devel
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
^ permalink raw reply [flat|nested] 59+ messages in thread
end of thread, other threads:[~2026-12-03 1:00 UTC | newest]
Thread overview: 59+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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-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-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
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.