From: Arvind Yadav <arvind.yadav@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com,
thomas.hellstrom@linux.intel.com
Subject: [RFC v2 5/7] drm/xe/vm: Deactivate madvise notifier on GPU touch
Date: Mon, 6 Apr 2026 14:28:28 +0530 [thread overview]
Message-ID: <20260406085830.1118431-6-arvind.yadav@intel.com> (raw)
In-Reply-To: <20260406085830.1118431-1-arvind.yadav@intel.com>
MADVISE_AUTORESET notifier is only needed while the VMA is CPU-only.
After GPU touch, SVM notifiers handle munmap.
Gate the callback on an active flag and clear it on first GPU touch in
xe_vm_madvise_gpu_touch(), making the callback a no-op.
v2:
- Use plain bool active; callback reads it lockless. (Matt)
- Use wq check and mt_for_each in deactivate path. (Matt)
- Add lockdep_assert_held_write(&vm->lock) to xe_vm_madvise_gpu_touch().
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 | 5 ++-
drivers/gpu/drm/xe/xe_vm_madvise.c | 52 ++++++++++++++++++++++++++++--
drivers/gpu/drm/xe/xe_vm_madvise.h | 2 ++
drivers/gpu/drm/xe/xe_vm_types.h | 7 ++++
4 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
index fd57c9d41db8..b6544947d861 100644
--- a/drivers/gpu/drm/xe/xe_svm.c
+++ b/drivers/gpu/drm/xe/xe_svm.c
@@ -22,6 +22,7 @@
#include "xe_tlb_inval.h"
#include "xe_ttm_vram_mgr.h"
#include "xe_vm.h"
+#include "xe_vm_madvise.h"
#include "xe_vm_types.h"
#include "xe_vram_types.h"
@@ -1414,8 +1415,10 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
* Mark the VMA as GPU-touched only after a successful fault-in.
* Prefetch faults that find no range must not transition this state.
*/
- if (!ret && xe_vma_has_cpu_autoreset_active(vma))
+ if (!ret && xe_vma_has_cpu_autoreset_active(vma)) {
xe_vma_gpu_touch(vma);
+ xe_vm_madvise_gpu_touch(vm, vma);
+ }
return ret;
}
diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.c b/drivers/gpu/drm/xe/xe_vm_madvise.c
index bdeb2e8e0f2c..4c57cac63d13 100644
--- a/drivers/gpu/drm/xe/xe_vm_madvise.c
+++ b/drivers/gpu/drm/xe/xe_vm_madvise.c
@@ -981,10 +981,10 @@ static bool xe_madvise_notifier_callback(struct mmu_interval_notifier *mni,
struct xe_vm *vm = notifier->vm;
u64 start, end;
- if (range->event != MMU_NOTIFY_UNMAP)
+ if (range->event != MMU_NOTIFY_UNMAP || !notifier->active)
return true;
- /* Skip non-blockable contexts; correctness is ensured by cpu_autoreset_active. */
+ /* Skip non-blockable contexts; cpu_autoreset_active handles fallback. */
if (!mmu_notifier_range_blockable(range))
return true;
@@ -1157,6 +1157,7 @@ int xe_vm_madvise_register_notifier_range(struct xe_vm *vm, u64 start, u64 end)
notifier->vm = xe_vm_get(vm);
notifier->vma_start = start;
notifier->vma_end = end;
+ notifier->active = true;
INIT_LIST_HEAD(¬ifier->list);
spin_lock_init(¬ifier->work_lock);
INIT_WORK(¬ifier->work, xe_madvise_work_func);
@@ -1221,3 +1222,50 @@ int xe_vm_madvise_register_notifier_range(struct xe_vm *vm, u64 start, u64 end)
return err;
}
+/**
+ * xe_vm_deactivate_madvise_notifier_for_range - Disable notifier callbacks
+ * @vm: VM
+ * @start: Start address (page-aligned)
+ * @end: End address (page-aligned)
+ *
+ * Clear @active on notifiers in [start, end) so future callbacks no-op.
+ * Removal is handled in xe_vm_madvise_fini().
+ */
+void xe_vm_deactivate_madvise_notifier_for_range(struct xe_vm *vm, u64 start, u64 end)
+{
+ struct xe_madvise_notifier *notifier;
+ unsigned long index = start;
+
+ lockdep_assert_held_write(&vm->lock);
+
+ /* No-op if madvise infrastructure is not available. */
+ if (!vm->svm.madvise_work.wq)
+ return;
+
+ /* Plain walk to deactivate overlapping notifiers. */
+ mt_for_each(&vm->svm.madvise_notifiers, notifier, index, end - 1)
+ notifier->active = false;
+}
+
+/**
+ * xe_vm_madvise_gpu_touch() - Suppress madvise callbacks after GPU touch
+ * @vm: VM
+ * @vma: VMA that was GPU-touched
+ *
+ * Clears @active on this VMA's notifiers so future callbacks no-op.
+ * Already-queued work still runs but no-ops: the worker rechecks
+ * cpu_autoreset_active under vm->lock and skips GPU-touched VMAs.
+ */
+void xe_vm_madvise_gpu_touch(struct xe_vm *vm, struct xe_vma *vma)
+{
+ lockdep_assert_held_write(&vm->lock);
+
+ /* Guard: only deactivate notifiers for AUTORESET-marked VMAs. */
+ if (!(vma->gpuva.flags & XE_VMA_MADV_AUTORESET))
+ return;
+
+ xe_vm_deactivate_madvise_notifier_for_range(vm,
+ xe_vma_start(vma),
+ xe_vma_end(vma));
+}
+
diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.h b/drivers/gpu/drm/xe/xe_vm_madvise.h
index 111953de4d2f..3c6f4d9e8343 100644
--- a/drivers/gpu/drm/xe/xe_vm_madvise.h
+++ b/drivers/gpu/drm/xe/xe_vm_madvise.h
@@ -22,4 +22,6 @@ void xe_bo_recompute_purgeable_state(struct xe_bo *bo);
int xe_vm_madvise_init(struct xe_vm *vm);
void xe_vm_madvise_fini(struct xe_vm *vm);
int xe_vm_madvise_register_notifier_range(struct xe_vm *vm, u64 start, u64 end);
+void xe_vm_deactivate_madvise_notifier_for_range(struct xe_vm *vm, u64 start, u64 end);
+void xe_vm_madvise_gpu_touch(struct xe_vm *vm, struct xe_vma *vma);
#endif
diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h
index 93e777f010f9..850245042dd8 100644
--- a/drivers/gpu/drm/xe/xe_vm_types.h
+++ b/drivers/gpu/drm/xe/xe_vm_types.h
@@ -50,6 +50,13 @@ struct xe_madvise_notifier {
u64 vma_start;
/** @vma_end: End address of VMA being tracked */
u64 vma_end;
+ /**
+ * @active: Fast-path gate; cleared on GPU touch so callbacks bail
+ * early. Not authoritative — worker rechecks cpu_autoreset_active
+ * under vm->lock, so a stale read only causes redundant work.
+ * Written under vm->lock; read lockless in the callback.
+ */
+ bool active;
/** @list: Used only in xe_vm_madvise_fini() to stage notifiers for removal. */
struct list_head list;
/** @work_lock: Serialises work_pending, work_start and work_end. */
--
2.43.0
next prev parent reply other threads:[~2026-04-06 8:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 8:58 [RFC v2 0/7] drm/xe/svm: Add MMU notifier-based madvise autoreset on munmap Arvind Yadav
2026-04-06 8:58 ` [RFC v2 1/7] drm/xe/vm: Track CPU_AUTORESET state in xe_vma Arvind Yadav
2026-04-30 4:07 ` Matthew Brost
2026-04-06 8:58 ` [RFC v2 2/7] drm/xe/vm: Preserve cpu_autoreset_active across GPUVA operations Arvind Yadav
2026-04-30 4:29 ` Matthew Brost
2026-04-06 8:58 ` [RFC v2 3/7] drm/xe/svm: Clear CPU_AUTORESET_ACTIVE on first GPU fault Arvind Yadav
2026-04-30 4:26 ` Matthew Brost
2026-04-06 8:58 ` [RFC v2 4/7] drm/xe/vm: Add madvise autoreset interval notifier worker infrastructure Arvind Yadav
2026-04-06 8:58 ` Arvind Yadav [this message]
2026-04-06 8:58 ` [RFC v2 6/7] drm/xe/vm: Wire MADVISE_AUTORESET notifiers into VM lifecycle Arvind Yadav
2026-04-06 8:58 ` [RFC v2 7/7] drm/xe/svm: Correct memory attribute reset for partial unmap Arvind Yadav
2026-04-30 5:02 ` Matthew Brost
2026-04-30 5:08 ` Matthew Brost
2026-04-06 9:04 ` ✗ CI.checkpatch: warning for drm/xe/svm: Add MMU notifier-based madvise autoreset on munmap (rev2) Patchwork
2026-04-06 9:06 ` ✓ CI.KUnit: success " Patchwork
2026-04-06 9:54 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-06 12:36 ` ✓ Xe.CI.FULL: " 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=20260406085830.1118431-6-arvind.yadav@intel.com \
--to=arvind.yadav@intel.com \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@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