[RFC 3/7] drm/xe/svm: Clear CPU_AUTORESET_ACTIVE on first GPU fault

Arvind Yadav
2026-02-19T09:13:35Z

Clear XE_VMA_CPU_AUTORESET_ACTIVE before installing GPU PTEs for CPU
address mirror VMAs.

This marks the one-way transition from CPU-only to GPU-touched so munmap
handling can switch from the MADVISE autoreset notifier to the existing
SVM notifier.

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_svm.c | 10 ++++++++++
drivers/gpu/drm/xe/xe_vm.h | 11 +++++++++++
2 files changed, 21 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
index cda3bf7e2418..b9dbbb245779 100644
--- a/drivers/gpu/drm/xe/xe_svm.c
+++ b/drivers/gpu/drm/xe/xe_svm.c
@@ -1209,6 +1209,9 @@ static int __xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
lockdep_assert_held_write(&vm->lock);
xe_assert(vm->xe, xe_vma_is_cpu_addr_mirror(vma));

+ /* Invariant: CPU_AUTORESET_ACTIVE cleared before reaching here. */
+ WARN_ON_ONCE(xe_vma_has_cpu_autoreset_active(vma));
+
xe_gt_stats_incr(gt, XE_GT_STATS_ID_SVM_PAGEFAULT_COUNT, 1);

retry:
@@ -1360,6 +1363,13 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
bool atomic)
{
int need_vram, ret;
+
+ lockdep_assert_held_write(&vm->lock);
+
+ /* Transition CPU-only -> GPU-touched before installing PTEs. */
+ if (xe_vma_has_cpu_autoreset_active(vma))
+ xe_vma_gpu_touch(vma);
+
retry:
need_vram = xe_vma_need_vram_for_atomic(vm->xe, vma, atomic);
if (need_vram < 0)
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index 7bf400f068ce..3dc549550c91 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -423,4 +423,15 @@ static inline struct drm_exec *xe_vm_validation_exec(struct xe_vm *vm)
((READ_ONCE(tile_present) & ~READ_ONCE(tile_invalidated)) & BIT((tile)->id))

void xe_vma_mem_attr_copy(struct xe_vma_mem_attr *to, struct xe_vma_mem_attr *from);
+
+/**
+ * xe_vma_gpu_touch() - Mark VMA as GPU-touched
+ * @vma: VMA to mark
+ *
+ * Clear XE_VMA_CPU_AUTORESET_ACTIVE. Must be done before first GPU PTE install.
+ */
+static inline void xe_vma_gpu_touch(struct xe_vma *vma)
+{
+ vma->gpuva.flags &= ~XE_VMA_CPU_AUTORESET_ACTIVE;
+}
#endif
--
2.43.0