From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Tejas Upadhyay" <tejas.upadhyay@intel.com>,
"Natalie Vock" <nat@pixelcluster.dev>,
"Arun Pravin" <arunpravin.paneerselvam@amd.com>
Subject: [PATCH v4 13/33] drm/xe: Flush L2 asynchronously in xe_bo_trigger_rebind()
Date: Tue, 1 Dec 2026 15:48:55 -0800 [thread overview]
Message-ID: <20261201234915.3305331-14-matthew.brost@intel.com> (raw)
In-Reply-To: <20261201234915.3305331-1-matthew.brost@intel.com>
On L2-flush-optimized HW with a dma-resv (non-fault) VM, evicting a BO
only needs to flush the L2 cache before the migration copy runs; the
mappings themselves are torn down and rebuilt lazily via
drm_gpuvm_bo_evict() and a subsequent rebind. Today this flush is done
by waiting for the BO to go idle and then issuing a synchronous TLB
invalidation per mapping VMA from inside xe_bo_trigger_rebind(). Both
the idle wait and the synchronous invalidation stall the calling thread
while holding the BO dma-resv lock, serializing the move behind all
in-flight GPU work on the BO.
Replace this with an asynchronous flush. Add xe_vm_flush_vm_bo_tlb_async()
which, for each VMA mapping the BO on each present tile, queues a TLB
invalidation job on the tile migrate (kernel) exec queue. The jobs depend
on the BO's in-flight GPU work, captured once as a singleton over
DMA_RESV_USAGE_BOOKKEEP, so the flush only fires once the GPU is done with
the current mapping. Each job's completion fence is installed into the
BO's dma-resv as a DMA_RESV_USAGE_KERNEL fence, so the migration copy -
which waits on the resv - waits on the flush without stalling this thread.
No PTEs are zapped and vma->tile_invalidated is left untouched: the
mapping stays valid until the lazy rebind, and the only work performed
here is the L2 flush. On any failure the caller falls back to the
existing blocking wait-idle plus xe_vm_invalidate_vma() path.
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Tejas Upadhyay <tejas.upadhyay@intel.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Assisted-by: GitHub_Copilot:claude-opus-4.8
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 13 ++++
drivers/gpu/drm/xe/xe_vm.c | 125 +++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_vm.h | 5 ++
3 files changed, 143 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index ff5610ba4b74..920b7b609458 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -857,6 +857,19 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
*/
if (!xe_device_is_l2_flush_optimized(xe))
continue;
+
+ /*
+ * Attempt to flush L2 async, fallback to sync flush on
+ * failure. Skip the async attempt under no_wait_gpu
+ * (e.g. the shrinker's reclaim pass): job creation
+ * allocates with GFP_KERNEL, which must not run while
+ * holding the dma-resv lock under fs_reclaim. The sync
+ * fallback below honors no_wait_gpu (returns -EBUSY if
+ * the BO is not idle).
+ */
+ if (!ctx->no_wait_gpu &&
+ !xe_vm_flush_vm_bo_tlb_async(vm, bo, vm_bo))
+ continue;
}
if (!idle) {
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index c774804ca556..842d99a6ae1a 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -44,6 +44,7 @@
#include "xe_sync.h"
#include "xe_tile.h"
#include "xe_tlb_inval.h"
+#include "xe_tlb_inval_job.h"
#include "xe_trace_bo.h"
#include "xe_userptr.h"
#include "xe_vm_madvise.h"
@@ -4668,6 +4669,130 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
return ret;
}
+/*
+ * xe_vma_tlb_flush_client - Queue an async TLB flush for one VMA on one client
+ *
+ * Create and push a TLB invalidation job on the tile migrate (kernel) exec
+ * queue covering @vma's range, depending on @dep (the BO's in-flight GPU work)
+ * so the flush only fires once the GPU is done with the current mapping. The
+ * job's completion fence is installed into @resv as a KERNEL fence so the
+ * subsequent migration waits on the flush. No PTEs are zapped; this only
+ * flushes L2 via the TLB invalidation.
+ */
+static int xe_vma_tlb_flush_client(struct xe_vm *vm, struct xe_vma *vma,
+ struct xe_tile *tile, struct xe_gt *gt,
+ struct dma_resv *resv, struct dma_fence *dep,
+ int type)
+{
+ struct xe_exec_queue *q = xe_migrate_exec_queue(tile->migrate);
+ struct xe_tlb_inval_job *job;
+ struct dma_fence *fence;
+ int err;
+
+ job = xe_tlb_inval_job_create(q, >->tlb_inval,
+ q->tlb_inval[type].dep_scheduler, vm,
+ xe_vma_start(vma), xe_vma_end(vma), type);
+ if (IS_ERR(job))
+ return PTR_ERR(job);
+
+ err = xe_tlb_inval_job_alloc_dep(job);
+ if (err)
+ goto out_put;
+
+ err = dma_resv_reserve_fences(resv, 1);
+ if (err)
+ goto out_put;
+
+ /* Cannot fail; takes its own ref on @dep and returns a referenced fence. */
+ fence = xe_tlb_inval_job_push(job, dep);
+ dma_resv_add_fence(resv, fence, DMA_RESV_USAGE_KERNEL);
+ dma_fence_put(fence);
+
+out_put:
+ /* Drop the creation reference (destroys the job if it was not pushed). */
+ xe_tlb_inval_job_put(job);
+ return err;
+}
+
+/**
+ * xe_vm_flush_vm_bo_tlb_async - Asynchronously flush TLBs for a vm_bo's mappings
+ * @vm: The VM @vm_bo belongs to
+ * @bo: The buffer object being moved
+ * @vm_bo: The gpuvm_bo linking @bo into @vm
+ *
+ * On L2-flush-optimized HW a BO move only needs to flush L2 (via a TLB
+ * invalidation) for the BO's live mappings; the mappings themselves are torn
+ * down and rebuilt lazily via the eviction/rebind path, so no PTEs need to be
+ * zapped here. Rather than blocking the caller on a synchronous invalidation,
+ * issue a TLB invalidation job per VMA per TLB-invalidation client (per present
+ * tile, primary and media GT). Each job waits on the BO's in-flight GPU work
+ * (all dma-resv usages) and its completion fence is installed into the BO's
+ * dma-resv KERNEL slots, so the following migration waits on the flush without
+ * stalling this thread.
+ *
+ * The caller must hold the BO's dma-resv lock and @vm must not be in fault
+ * mode.
+ *
+ * Return: 0 on success, negative error code on failure. On failure the caller
+ * should fall back to the blocking xe_vm_invalidate_vma() path; any jobs
+ * already queued install harmless extra flush fences.
+ */
+int xe_vm_flush_vm_bo_tlb_async(struct xe_vm *vm, struct xe_bo *bo,
+ struct drm_gpuvm_bo *vm_bo)
+{
+ struct xe_device *xe = vm->xe;
+ struct dma_resv *resv = bo->ttm.base.resv;
+ struct dma_fence *dep = NULL;
+ struct drm_gpuva *gpuva;
+ int err;
+
+ dma_resv_assert_held(resv);
+ xe_assert(xe, !xe_vm_in_fault_mode(vm));
+
+ /*
+ * Single fence capturing all in-flight GPU work on the BO; the TLB
+ * invalidation jobs depend on it so the flush fires only once the GPU
+ * is done with the current mapping.
+ */
+ err = dma_resv_get_singleton(resv, DMA_RESV_USAGE_BOOKKEEP, &dep);
+ if (err)
+ return err;
+ if (!dep)
+ dep = dma_fence_get_stub();
+
+ drm_gpuvm_bo_for_each_va(gpuva, vm_bo) {
+ struct xe_vma *vma = gpuva_to_vma(gpuva);
+ struct xe_tile *tile;
+ u8 id;
+
+ if (xe_vma_is_null(vma) || xe_vma_is_cpu_addr_mirror(vma))
+ continue;
+
+ for_each_tile(tile, xe, id) {
+ if (!(vma->tile_present & BIT(id)))
+ continue;
+
+ err = xe_vma_tlb_flush_client(vm, vma, tile,
+ tile->primary_gt, resv, dep,
+ XE_EXEC_QUEUE_TLB_INVAL_PRIMARY_GT);
+ if (err)
+ goto out;
+
+ if (tile->media_gt) {
+ err = xe_vma_tlb_flush_client(vm, vma, tile,
+ tile->media_gt, resv, dep,
+ XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT);
+ if (err)
+ goto out;
+ }
+ }
+ }
+
+out:
+ dma_fence_put(dep);
+ return err;
+}
+
int xe_vm_validate_protected(struct xe_vm *vm)
{
struct drm_gpuva *gpuva;
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index ed590bad892c..5adf1d884bb0 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -29,6 +29,8 @@ struct ttm_buffer_object;
struct dma_fence;
+struct xe_bo;
+struct drm_gpuvm_bo;
struct xe_exec_queue;
struct xe_file;
struct xe_pagefault;
@@ -257,6 +259,9 @@ int xe_vm_invalidate_vma(struct xe_vma *vma);
int xe_vm_invalidate_vma_submit(struct xe_vma *vma, struct xe_tlb_inval_batch *batch);
+int xe_vm_flush_vm_bo_tlb_async(struct xe_vm *vm, struct xe_bo *bo,
+ struct drm_gpuvm_bo *vm_bo);
+
int xe_vm_validate_protected(struct xe_vm *vm);
static inline void xe_vm_queue_rebind_worker(struct xe_vm *vm)
--
2.34.1
next prev parent reply other threads:[~2026-12-01 23:49 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 23:48 [PATCH v4 00/33] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Matthew Brost
2026-12-01 23:48 ` [PATCH v4 01/33] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-12-01 23:48 ` [PATCH v4 02/33] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-12-01 23:48 ` [PATCH v4 03/33] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-12-01 23:48 ` [PATCH v4 04/33] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-12-01 23:59 ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 05/33] drm/ttm: Support defragmentation moves Matthew Brost
2026-12-01 23:48 ` [PATCH v4 06/33] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-12-02 0:06 ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 07/33] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-12-02 0:27 ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-01 23:48 ` [PATCH v4 09/33] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-12-02 0:23 ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 10/33] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-12-02 0:15 ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 11/33] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
2026-12-01 23:48 ` [PATCH v4 12/33] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
2026-12-01 23:48 ` Matthew Brost [this message]
2026-12-02 0:19 ` [PATCH v4 13/33] drm/xe: Flush L2 asynchronously in xe_bo_trigger_rebind() sashiko-bot
2026-12-01 23:48 ` [PATCH v4 14/33] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-12-02 0:17 ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 15/33] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-12-01 23:48 ` [PATCH v4 16/33] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-12-02 0:19 ` sashiko-bot
2026-12-01 23:48 ` [PATCH v4 17/33] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-12-02 0:16 ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 18/33] drm/xe: Add a page defragmentation worker Matthew Brost
2026-12-02 0:23 ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 19/33] drm/xe: Add defrag GT stats Matthew Brost
2026-12-01 23:49 ` [PATCH v4 20/33] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-12-02 0:12 ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 21/33] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-12-02 0:24 ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 22/33] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-02 0:09 ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 23/33] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-02 0:15 ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 24/33] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-12-01 23:49 ` [PATCH v4 25/33] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-12-01 23:49 ` [PATCH v4 26/33] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-12-01 23:49 ` [PATCH v4 27/33] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-12-01 23:49 ` [PATCH v4 28/33] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-12-01 23:49 ` [PATCH v4 29/33] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-12-02 0:17 ` sashiko-bot
2026-12-01 23:49 ` [PATCH v4 30/33] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
2026-12-01 23:49 ` [PATCH v4 31/33] drm/xe: Grow the USM batch pool to 2M and map it via a single PDE Matthew Brost
2026-12-01 23:49 ` [PATCH v4 32/33] drm/xe: Add bo_defrag debugfs entry Matthew Brost
2026-12-01 23:49 ` [PATCH v4 33/33] drm/xe: Make BO defrag tunables configurable via sysfs Matthew Brost
2026-12-02 0:20 ` sashiko-bot
2026-12-01 23:58 ` ✗ CI.checkpatch: warning for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Patchwork
2026-12-02 0:00 ` ✓ CI.KUnit: success " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201234915.3305331-14-matthew.brost@intel.com \
--to=matthew.brost@intel.com \
--cc=arunpravin.paneerselvam@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=nat@pixelcluster.dev \
--cc=tejas.upadhyay@intel.com \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox