dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Arvind Yadav <arvind.yadav@intel.com>
To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com,
	thomas.hellstrom@linux.intel.com
Subject: [RFC v3 3/7] drm/xe/svm: Clear CPU_AUTORESET_ACTIVE on first GPU fault
Date: Thu,  4 Jun 2026 15:20:08 +0530	[thread overview]
Message-ID: <20260604095012.367231-4-arvind.yadav@intel.com> (raw)
In-Reply-To: <20260604095012.367231-1-arvind.yadav@intel.com>

CPU address mirror VMAs start with cpu_autoreset_active set, indicating
they are still CPU-only.

Clear cpu_autoreset_active after successful fault handling. A successful
return means the fault address already has a valid GPU mapping or PTEs
were installed. Prefetch faults that do not establish a mapping return an
error and do not transition the state.

v2:
  - Move xe_vma_gpu_touch() to the success path in
    xe_svm_handle_pagefault() so prefetch faults that find no range do
    not transition the state. (Matt)
  - Add xe_vma_gpu_touch() helper in xe_vm.h and use
    vma->cpu_autoreset_active instead of vma->gpuva.flags. (Matt)

v3:
  - Drop lockdep_assert_held_write from xe_svm_handle_pagefault. (Matt)
  - Re-fetch the VMA in xe_pagefault_service() before clearing state.
  - Move gpu_touch from xe_svm_handle_pagefault to xe_pagefault_service
    (Matt)

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_pagefault.c | 10 +++++++++-
 drivers/gpu/drm/xe/xe_vm.h        | 13 +++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_pagefault.c b/drivers/gpu/drm/xe/xe_pagefault.c
index dd3c068e1a39..f64d3df08261 100644
--- a/drivers/gpu/drm/xe/xe_pagefault.c
+++ b/drivers/gpu/drm/xe/xe_pagefault.c
@@ -215,8 +215,16 @@ static int xe_pagefault_service(struct xe_pagefault *pf)
 		err = xe_pagefault_handle_vma(gt, vma, atomic);
 
 unlock_vm:
-	if (!err)
+	if (!err) {
+		/* Re-fetch, fault handling may have replaced the VMA. */
+		vma = xe_vm_find_vma_by_addr(vm, pf->consumer.page_addr);
 		vm->usm.last_fault_vma = vma;
+
+		/* First successful GPU fault ends CPU-only state. */
+		if (vma && xe_vma_is_cpu_addr_mirror(vma) &&
+		    xe_vma_has_cpu_autoreset_active(vma))
+			xe_vma_gpu_touch(vma);
+	}
 	up_write(&vm->lock);
 	xe_vm_put(vm);
 
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index 0dd201cce968..0ad704b05687 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -450,4 +450,17 @@ 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 a VMA as no longer CPU-only
+ * @vma: VMA to update
+ *
+ * Clear cpu_autoreset_active after the first successful GPU fault-in.
+ * Caller must hold vm->lock in write mode.
+ */
+static inline void xe_vma_gpu_touch(struct xe_vma *vma)
+{
+	lockdep_assert_held_write(&xe_vma_vm(vma)->lock);
+	vma->cpu_autoreset_active = false;
+}
 #endif
-- 
2.43.0


  parent reply	other threads:[~2026-06-04  9:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04  9:50 [RFC v3 0/7] drm/xe/svm: Add MMU notifier-based madvise autoreset on munmap Arvind Yadav
2026-06-04  9:50 ` [RFC v3 1/7] drm/xe/vm: Track CPU_AUTORESET state in xe_vma Arvind Yadav
2026-06-04  9:50 ` [RFC v3 2/7] drm/xe/vm: Preserve cpu_autoreset_active across GPUVA operations Arvind Yadav
2026-06-04 10:07   ` sashiko-bot
2026-06-04  9:50 ` Arvind Yadav [this message]
2026-06-04  9:50 ` [RFC v3 4/7] drm/xe/vm: Add madvise autoreset notifier worker Arvind Yadav
2026-06-04 10:14   ` sashiko-bot
2026-06-04  9:50 ` [RFC v3 5/7] drm/xe/vm: Disable madvise notifier on GPU touch Arvind Yadav
2026-06-04 10:03   ` sashiko-bot
2026-06-04  9:50 ` [RFC v3 6/7] drm/xe/vm: Wire MADVISE_AUTORESET notifiers into VM lifecycle Arvind Yadav
2026-06-04 10:05   ` sashiko-bot
2026-06-04  9:50 ` [RFC v3 7/7] drm/xe/svm: Correct memory attribute reset for partial unmap Arvind Yadav
2026-06-04 10:12   ` sashiko-bot

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=20260604095012.367231-4-arvind.yadav@intel.com \
    --to=arvind.yadav@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --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