From: Arvind Yadav <arvind.yadav@intel.com>
To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
himal.prasad.ghimiray@intel.com
Subject: [PATCH v2 1/2] drm/xe: Snapshot inline DMA addresses before staging page tables
Date: Fri, 4 Dec 2026 12:23:17 +0530 [thread overview]
Message-ID: <20261204065318.1785149-2-arvind.yadav@intel.com> (raw)
In-Reply-To: <20261204065318.1785149-1-arvind.yadav@intel.com>
Clearing inline DMA storage during unmap can race with
xe_pt_stage_bind(). The userptr path reads it without notifier_lock,
and the SVM path keeps a pointer after releasing the lock.
Protect the userptr lookup with notifier_lock and copy inline entries
for both paths. Use the copy throughout page-table staging.
For invalidated userptrs, return -EAGAIN in fault mode. Otherwise,
stage cleared PTEs and keep those tiles marked invalidated at commit
until exec or the rebind worker repins and rebinds them.
This prepares Xe for clearing inline DMA storage during unmap.
v2:
- Add a preparatory Xe patch to protect DMA lookup and snapshot
inline entries for userptr and SVM binds.
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
---
drivers/gpu/drm/xe/xe_pt.c | 82 ++++++++++++++++++++++++++++----
drivers/gpu/drm/xe/xe_pt_types.h | 2 +
2 files changed, 76 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
index 0e0bf428df0f..4a6135ab2c8d 100644
--- a/drivers/gpu/drm/xe/xe_pt.c
+++ b/drivers/gpu/drm/xe/xe_pt.c
@@ -770,6 +770,7 @@ static u32 xe_pt_target_leaf_level_from_bo(struct xe_device *xe,
* the main tree at commit time.
* @num_entries: On output contains the number of @entries used.
* @clear_pt: Clear the page table entries.
+ * @pt_cleared: Whether the staged page table entries were cleared.
*
* This function builds a disconnected page-table tree for a given address
* range. The tree is connected to the main vm tree for the gpu using
@@ -784,11 +785,12 @@ static int
xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
struct xe_svm_range *range,
struct xe_vm_pgtable_update *entries,
- u32 *num_entries, bool clear_pt)
+ u32 *num_entries, bool clear_pt, bool *pt_cleared)
{
struct xe_device *xe = tile_to_xe(tile);
struct xe_bo *bo = xe_vma_bo(vma);
struct xe_res_cursor curs = {};
+ struct drm_pagemap_addr inline_addr;
struct xe_vm *vm = xe_vma_vm(vma);
struct xe_pt_stage_bind_walk xe_walk = {
.base = {
@@ -842,6 +844,11 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
bool contiguous;
addr = xe_svm_range_first_dma(range, &contiguous);
+ /* Keep inline storage stable after dropping the notifier lock. */
+ if (contiguous) {
+ inline_addr = *addr;
+ addr = &inline_addr;
+ }
xe_res_first_dma(addr, 0, xe_svm_range_size(range),
contiguous, &curs);
xe_svm_range_debug(range, "BIND PREPARE - MIXED");
@@ -876,13 +883,38 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
if (!xe_vma_is_null(vma) && !range && !is_purged) {
if (xe_vma_is_userptr(vma)) {
+ struct xe_userptr_vma *uvma = to_userptr_vma(vma);
const struct drm_pagemap_addr *addr;
bool contiguous;
- addr = drm_gpusvm_pages_first_dma(&to_userptr_vma(vma)->userptr.pages,
- &contiguous);
+ xe_svm_notifier_lock(vm);
+ if (xe_vma_userptr_check_repin(uvma))
+ addr = NULL;
+ else
+ addr = drm_gpusvm_pages_first_dma(&uvma->userptr.pages,
+ &contiguous);
+ if (!addr) {
+ xe_svm_notifier_unlock(vm);
+ if (xe_vm_in_fault_mode(vm))
+ return -EAGAIN;
+
+ /* Exec or the rebind worker will repin invalidated userptrs. */
+ xe_walk.clear_pt = true;
+ curs.size = xe_vma_size(vma);
+ goto walk_pt;
+ }
+ if (contiguous) {
+ inline_addr = *addr;
+ addr = &inline_addr;
+ }
xe_res_first_dma(addr, 0, xe_vma_size(vma), contiguous,
&curs);
+ /*
+ * The snapshot protects cursor storage, not the DMA mapping.
+ * Fault-mode binds recheck validity at pre-commit. Other VMs
+ * repin and rebind invalidated userptrs before execution.
+ */
+ xe_svm_notifier_unlock(vm);
} else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo))
xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma),
xe_vma_size(vma), &curs);
@@ -900,6 +932,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
&xe_walk.base);
*num_entries = xe_walk.wupd.num_used_entries;
+ *pt_cleared = xe_walk.clear_pt;
return ret;
}
@@ -1291,13 +1324,14 @@ static int
xe_pt_prepare_bind(struct xe_tile *tile, struct xe_vma *vma,
struct xe_svm_range *range,
struct xe_vm_pgtable_update *entries,
- u32 *num_entries, bool invalidate_on_bind)
+ u32 *num_entries, bool invalidate_on_bind, bool *pt_cleared)
{
int err;
*num_entries = 0;
+ *pt_cleared = false;
err = xe_pt_stage_bind(tile, vma, range, entries, num_entries,
- invalidate_on_bind);
+ invalidate_on_bind, pt_cleared);
if (!err)
xe_tile_assert(tile, *num_entries);
@@ -2166,7 +2200,8 @@ static int bind_op_prepare(struct xe_vm *vm, struct xe_tile *tile,
return err;
err = xe_pt_prepare_bind(tile, vma, NULL, pt_op->entries,
- &pt_op->num_entries, invalidate_on_bind);
+ &pt_op->num_entries, invalidate_on_bind,
+ &pt_op->pt_cleared);
if (!err) {
xe_tile_assert(tile, pt_op->num_entries <=
ARRAY_SIZE(pt_op->entries));
@@ -2234,7 +2269,7 @@ static int bind_range_prepare(struct xe_vm *vm, struct xe_tile *tile,
pt_op->rebind = BIT(tile->id) & range->tile_present;
err = xe_pt_prepare_bind(tile, vma, range, pt_op->entries,
- &pt_op->num_entries, false);
+ &pt_op->num_entries, false, &pt_op->pt_cleared);
if (!err) {
xe_tile_assert(tile, pt_op->num_entries <=
ARRAY_SIZE(pt_op->entries));
@@ -2869,7 +2904,6 @@ xe_pt_update_ops_run(struct xe_device *xe, struct xe_vma_ops *vops)
xe_pt_commit(pt_op->vma, pt_op->entries,
pt_op->num_entries,
&pt_update_ops->pt_job_ops->deferred);
- pt_op->vma = NULL; /* skip in xe_pt_update_ops_abort */
tile_mask |= BIT(tile->id);
}
}
@@ -2905,6 +2939,38 @@ xe_pt_update_ops_run(struct xe_device *xe, struct xe_vma_ops *vops)
tile_mask);
}
+ /*
+ * op_commit() assumes a normal bind installed valid PTEs. Restore the
+ * actual userptr state from the staged operations, in operation order,
+ * before releasing the notifier lock. With shared page tables, tile 0
+ * determines the state for all tiles.
+ */
+ for_each_tile(tile, xe, j) {
+ struct xe_vm_pgtable_update_ops *pt_update_ops =
+ &vops->pt_update_ops[j];
+ u8 mask = xe->info.has_pt_mirror ? BIT(tile->id) : tile_mask;
+
+ if (pt_mirroring_disabled_for_tile(vm, j))
+ continue;
+
+ for (i = 0; i < get_current_op(pt_update_ops); ++i) {
+ struct xe_vm_pgtable_update_op *pt_op =
+ to_pt_op(pt_update_ops, i);
+ struct xe_vma *vma = pt_op->vma;
+
+ if (pt_op->bind && xe_vma_is_userptr(vma)) {
+ /* Pairs with READ_ONCE in xe_vm_has_valid_gpu_mapping(). */
+ if (pt_op->pt_cleared)
+ WRITE_ONCE(vma->tile_invalidated,
+ vma->tile_invalidated | mask);
+ else
+ WRITE_ONCE(vma->tile_invalidated,
+ vma->tile_invalidated & ~mask);
+ }
+ pt_op->vma = NULL; /* skip in xe_pt_update_ops_abort */
+ }
+ }
+
if (needs_svm_lock)
xe_pt_svm_userptr_notifier_unlock(vm);
diff --git a/drivers/gpu/drm/xe/xe_pt_types.h b/drivers/gpu/drm/xe/xe_pt_types.h
index 0d4bac22ee6c..56f8c2a00762 100644
--- a/drivers/gpu/drm/xe/xe_pt_types.h
+++ b/drivers/gpu/drm/xe/xe_pt_types.h
@@ -95,6 +95,8 @@ struct xe_vm_pgtable_update_op {
bool bind;
/** @rebind: is a rebind */
bool rebind;
+ /** @pt_cleared: bind staged cleared PTEs instead of DMA mappings */
+ bool pt_cleared;
};
/**
--
2.43.0
next prev parent reply other threads:[~2026-12-04 6:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:53 [PATCH v2 0/2] Fix invalidated inline DMA mappings in GPUSVM Arvind Yadav
2026-12-04 6:53 ` Arvind Yadav [this message]
2026-12-04 7:21 ` [PATCH v2 1/2] drm/xe: Snapshot inline DMA addresses before staging page tables sashiko-bot
2026-12-04 6:53 ` [PATCH v2 2/2] drm/gpusvm: Clear inline DMA mapping state on unmap Arvind Yadav
2026-12-04 7:39 ` sashiko-bot
2026-12-04 7:30 ` ✓ CI.KUnit: success for Fix invalidated inline DMA mappings in GPUSVM Patchwork
2026-12-04 8:04 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-05 5:43 ` ✗ Xe.CI.FULL: failure " 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=20261204065318.1785149-2-arvind.yadav@intel.com \
--to=arvind.yadav@intel.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.