public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
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 5/7] drm/xe/vm: Deactivate madvise notifier on GPU touch
Date: Thu, 19 Feb 2026 14:43:10 +0530	[thread overview]
Message-ID: <20260219091312.796749-6-arvind.yadav@intel.com> (raw)
In-Reply-To: <20260219091312.796749-1-arvind.yadav@intel.com>

MADVISE_AUTORESET notifier is only needed while VMA is CPU-only.
After GPU touch, the existing SVM notifier handles munmap.

Add 'active' flag to xe_madvise_notifier, cleared on first GPU touch.
The callback checks this flag and returns early when inactive.

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.h         |  6 ++--
 drivers/gpu/drm/xe/xe_vm_madvise.c | 46 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vm_madvise.h |  2 ++
 drivers/gpu/drm/xe/xe_vm_types.h   |  2 ++
 5 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
index b9dbbb245779..3f09f5f6481f 100644
--- a/drivers/gpu/drm/xe/xe_svm.c
+++ b/drivers/gpu/drm/xe/xe_svm.c
@@ -21,6 +21,7 @@
 #include "xe_tile.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"
 
@@ -1367,8 +1368,10 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
 	lockdep_assert_held_write(&vm->lock);
 
 	/* Transition CPU-only -> GPU-touched before installing PTEs. */
-	if (xe_vma_has_cpu_autoreset_active(vma))
+	if (xe_vma_has_cpu_autoreset_active(vma)) {
 		xe_vma_gpu_touch(vma);
+		xe_vm_madvise_gpu_touch(vm, vma);
+	}
 
 retry:
 	need_vram = xe_vma_need_vram_for_atomic(vm->xe, vma, atomic);
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index 3dc549550c91..f353ab928e4c 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -426,12 +426,14 @@ void xe_vma_mem_attr_copy(struct xe_vma_mem_attr *to, struct xe_vma_mem_attr *fr
 
 /**
  * xe_vma_gpu_touch() - Mark VMA as GPU-touched
- * @vma: VMA to mark
+ * @vma: VMA to transition
  *
- * Clear XE_VMA_CPU_AUTORESET_ACTIVE. Must be done before first GPU PTE install.
+ * Clears CPU_AUTORESET_ACTIVE flag. Call xe_vm_madvise_gpu_touch() separately
+ * to deactivate the madvise notifier.
  */
 static inline void xe_vma_gpu_touch(struct xe_vma *vma)
 {
 	vma->gpuva.flags &= ~XE_VMA_CPU_AUTORESET_ACTIVE;
 }
+
 #endif
diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.c b/drivers/gpu/drm/xe/xe_vm_madvise.c
index 4c0ffb100bcc..98663707d039 100644
--- a/drivers/gpu/drm/xe/xe_vm_madvise.c
+++ b/drivers/gpu/drm/xe/xe_vm_madvise.c
@@ -657,6 +657,9 @@ static bool xe_madvise_notifier_callback(struct mmu_interval_notifier *mni,
 	if (range->event != MMU_NOTIFY_UNMAP)
 		return true;
 
+	if (!atomic_read(&notifier->active))
+		return true;
+
 	/*
 	 * Best-effort: skip in non-blockable contexts to avoid building up work.
 	 * Correctness does not rely on this notifier - CPU_AUTORESET_ACTIVE flag
@@ -857,6 +860,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;
+	atomic_set(&notifier->active, 1);
 	INIT_LIST_HEAD(&notifier->list);
 
 	err = mmu_interval_notifier_insert(&notifier->mmu_notifier,
@@ -894,3 +898,45 @@ int xe_vm_madvise_register_notifier_range(struct xe_vm *vm, u64 start, u64 end)
 
 	return 0;
 }
+
+/**
+ * xe_vm_deactivate_madvise_notifier_for_range - Deactivate notifier for a range
+ * @vm: VM
+ * @start: Start address (page-aligned)
+ * @end: End address (page-aligned)
+ *
+ * Called when GPU touches a VMA - disables munmap processing for this range.
+ * Notifier remains registered but callback becomes a no-op until VM teardown.
+ */
+void xe_vm_deactivate_madvise_notifier_for_range(struct xe_vm *vm, u64 start, u64 end)
+{
+	struct xe_madvise_notifier *notifier;
+
+	/* Skip if madvise infrastructure not initialized */
+	if (!READ_ONCE(vm->svm.madvise_work.wq))
+		return;
+
+	mutex_lock(&vm->svm.madvise_notifiers.lock);
+	/* Deactivate overlapping notifiers (VMA splits may create multiple) */
+	list_for_each_entry(notifier, &vm->svm.madvise_notifiers.list, list) {
+		if (notifier->vma_start < end && notifier->vma_end > start)
+			atomic_set(&notifier->active, 0);
+	}
+	mutex_unlock(&vm->svm.madvise_notifiers.lock);
+}
+
+/**
+ * xe_vm_madvise_gpu_touch() - Deactivate madvise notifier on GPU touch
+ * @vm: VM
+ * @vma: VMA that was GPU-touched
+ *
+ * Deactivates the madvise notifier for this VMA's range after GPU touch.
+ * Call after xe_vma_gpu_touch() clears the CPU_AUTORESET_ACTIVE flag.
+ */
+void xe_vm_madvise_gpu_touch(struct xe_vm *vm, struct xe_vma *vma)
+{
+	if (vma->gpuva.flags & XE_VMA_MADV_AUTORESET)
+		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 ba9cd7912113..91417062a33e 100644
--- a/drivers/gpu/drm/xe/xe_vm_madvise.h
+++ b/drivers/gpu/drm/xe/xe_vm_madvise.h
@@ -19,5 +19,7 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data,
 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 eb978995000c..9cdae3492472 100644
--- a/drivers/gpu/drm/xe/xe_vm_types.h
+++ b/drivers/gpu/drm/xe/xe_vm_types.h
@@ -48,6 +48,8 @@ struct xe_madvise_notifier {
 	u64 vma_end;
 	/** @list: Link in vm->svm.madvise_notifiers.list */
 	struct list_head list;
+	/** @active: Cleared when GPU touches VMA to avoid callback overhead */
+	atomic_t active;
 };
 
 #if IS_ENABLED(CONFIG_DRM_XE_DEBUG)
-- 
2.43.0


  parent reply	other threads:[~2026-02-19  9:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19  9:13 [RFC 0/7] drm/xe/svm: Add MMU notifier-based madvise autoreset on munmap Arvind Yadav
2026-02-19  9:13 ` [RFC 1/7] drm/xe/vm: Add CPU_AUTORESET_ACTIVE VMA flag Arvind Yadav
2026-02-19  9:13 ` [RFC 2/7] drm/xe/vm: Preserve CPU_AUTORESET_ACTIVE across GPUVA operations Arvind Yadav
2026-02-19  9:13 ` [RFC 3/7] drm/xe/svm: Clear CPU_AUTORESET_ACTIVE on first GPU fault Arvind Yadav
2026-02-20 20:12   ` Matthew Brost
2026-02-20 22:33     ` Matthew Brost
2026-03-05  3:38       ` Yadav, Arvind
2026-02-19  9:13 ` [RFC 4/7] drm/xe/vm: Add madvise autoreset interval notifier worker infrastructure Arvind Yadav
2026-02-25 23:34   ` Matthew Brost
2026-03-09  7:07     ` Yadav, Arvind
2026-03-09  9:32       ` Thomas Hellström
2026-03-11  6:34         ` Yadav, Arvind
2026-02-19  9:13 ` Arvind Yadav [this message]
2026-02-19  9:13 ` [RFC 6/7] drm/xe/vm: Wire MADVISE_AUTORESET notifiers into VM lifecycle Arvind Yadav
2026-02-19  9:13 ` [RFC 7/7] drm/xe/svm: Correct memory attribute reset for partial unmap Arvind Yadav
2026-02-19  9:40 ` ✗ CI.checkpatch: warning for drm/xe/svm: Add MMU notifier-based madvise autoreset on munmap Patchwork
2026-02-19  9:42 ` ✓ CI.KUnit: success " Patchwork
2026-02-19 10:40 ` ✓ Xe.CI.BAT: " Patchwork
2026-02-19 13:04 ` ✗ 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=20260219091312.796749-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