Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] drm/xe: Retry when drm_gpusvm_get_pages() gives -EBUSY
@ 2026-11-24 15:23 Tomasz Lis
  2026-11-24 15:27 ` Matthew Auld
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Tomasz Lis @ 2026-11-24 15:23 UTC (permalink / raw)
  To: intel-xe
  Cc: Michał Winiarski, Piotr Piórkowski, Satyanarayana K V P,
	Matthew Auld, Matthew Brost

drm_gpusvm_get_pages() returns -EBUSY when its HMM retry budget is
exhausted. This can happen when the range was repeatedly invalidated
or faulting was slow. This is transient, but the callers treat -EBUSY
as fatal.

The behavior causes sporadic fails after a VF post-migration recovery,
if drm_gpusvm_get_pages() run in parallel with the recovery, and the
recovery took longer than HMM_RANGE_DEFAULT_TIMEOUT (which isn't rare,
as the kernel bound to VF is running on virtual CPU).

Example signature of the issue:
  xe 0000:00:04.0: [drm] VM worker error: -16
  xe 0000:00:04.0: [drm] Trying to schedule after vm is closed or banned

Convert -EBUSY to -EAGAIN in both wrappers around drm_gpusvm_get_pages(),
through a common helper. The rebind worker, exec, the pagefault loop and
the SVM fault path already have a retry implemented on -EAGAIN.

xe_vma_userptr_pin_pages() can now return -EAGAIN instead of -EBUSY, so
update the VMA creation path in xe_vm.c, which maps this error to
-ENOMEM. Tis way the bind ioctl keeps returning the same error as before.

Signed-off-by: Tomasz Lis <tomasz.lis@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/xe/xe_svm.c     |  2 +-
 drivers/gpu/drm/xe/xe_userptr.c | 16 ++++++++++------
 drivers/gpu/drm/xe/xe_vm.c      |  8 ++++----
 drivers/gpu/drm/xe/xe_vm.h      | 16 ++++++++++++++++
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
index bc6902b5bf57..ffc624171d50 100644
--- a/drivers/gpu/drm/xe/xe_svm.c
+++ b/drivers/gpu/drm/xe/xe_svm.c
@@ -1624,7 +1624,7 @@ int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
 		drm_gpusvm_range_evict(&vm->svm.gpusvm, &range->base);
 	}
 
-	return err;
+	return xe_gpusvm_get_pages_err(err);
 }
 
 /**
diff --git a/drivers/gpu/drm/xe/xe_userptr.c b/drivers/gpu/drm/xe/xe_userptr.c
index 9c1dac0fce6f..423c190ac68d 100644
--- a/drivers/gpu/drm/xe/xe_userptr.c
+++ b/drivers/gpu/drm/xe/xe_userptr.c
@@ -10,6 +10,7 @@
 
 #include "xe_tlb_inval.h"
 #include "xe_trace_bo.h"
+#include "xe_vm.h"
 
 static void xe_userptr_assert_in_notifier(struct xe_vm *vm)
 {
@@ -84,6 +85,7 @@ int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma)
 		.device_private_page_owner = xe_svm_private_page_owner(vm, false),
 		.allow_mixed = true,
 	};
+	int err;
 
 	xe_vma_userptr_lockdep(uvma);
 	xe_assert(xe, xe_vma_is_userptr(vma));
@@ -91,12 +93,14 @@ int xe_vma_userptr_pin_pages(struct xe_userptr_vma *uvma)
 	if (vma->gpuva.flags & XE_VMA_DESTROYED)
 		return 0;
 
-	return drm_gpusvm_get_pages(&vm->svm.gpusvm, &uvma->userptr.pages, 1,
-				    uvma->userptr.notifier.mm,
-				    &uvma->userptr.notifier,
-				    xe_vma_userptr(vma),
-				    xe_vma_userptr(vma) + xe_vma_size(vma),
-				    &ctx);
+	err = drm_gpusvm_get_pages(&vm->svm.gpusvm, &uvma->userptr.pages, 1,
+				   uvma->userptr.notifier.mm,
+				   &uvma->userptr.notifier,
+				   xe_vma_userptr(vma),
+				   xe_vma_userptr(vma) + xe_vma_size(vma),
+				   &ctx);
+
+	return xe_gpusvm_get_pages_err(err);
 }
 
 static struct mmu_interval_notifier_finish *
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index dd855876f571..6e6937870ac6 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -2746,11 +2746,11 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 			err = xe_vma_userptr_pin_pages(to_userptr_vma(vma));
 			/*
 			 * -EBUSY has dedicated meaning that a user fence
-			 * attached to the VMA is busy, in practice
-			 * xe_vma_userptr_pin_pages can only fail with -EBUSY if
-			 * we are low on memory so convert this to -ENOMEM.
+			 * attached to the VMA is busy. xe_vma_userptr_pin_pages
+			 * reports exhausted HMM retries as -EAGAIN, which makes
+			 * no sense for the bind ioctl, so convert it to -ENOMEM.
 			 */
-			if (err == -EBUSY)
+			if (err == -EAGAIN)
 				err = -ENOMEM;
 		}
 	}
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index b1c5f940bcc5..ba24f2e6022e 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -38,6 +38,22 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef)
 struct xe_vm *xe_vm_lookup(struct xe_file *xef, u32 id);
 int xe_vma_cmp_vma_cb(const void *key, const struct rb_node *node);
 
+/**
+ * xe_gpusvm_get_pages_err() - Translate an error from drm_gpusvm_get_pages()
+ * @err: error code returned by drm_gpusvm_get_pages()
+ *
+ * drm_gpusvm_get_pages() returns -EBUSY when its HMM retry budget ran out,
+ * because the range was repeatedly invalidated or faulting was slow. That is
+ * transient, so report -EAGAIN to let the callers retry. -EBUSY would be
+ * treated as fatal, and has other meanings in the VM code.
+ *
+ * Return: @err, with -EBUSY replaced by -EAGAIN
+ */
+static inline int xe_gpusvm_get_pages_err(int err)
+{
+	return err == -EBUSY ? -EAGAIN : err;
+}
+
 static inline struct xe_vm *xe_vm_get(struct xe_vm *vm)
 {
 	drm_gpuvm_get(&vm->gpuvm);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-24 16:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 15:23 [PATCH v1] drm/xe: Retry when drm_gpusvm_get_pages() gives -EBUSY Tomasz Lis
2026-11-24 15:27 ` Matthew Auld
2026-11-24 16:15   ` Lis, Tomasz
2026-11-24 15:51 ` ✓ CI.KUnit: success for " Patchwork
2026-11-24 15:54 ` [PATCH v1] " sashiko-bot
2026-11-24 16:32 ` ✓ Xe.CI.BAT: success for " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox