Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] drm/ttm, drm/xe: Handle VRAM eviction failure at suspend
@ 2026-12-03  8:53 Thomas Hellström
  2026-12-03  8:53 ` [PATCH v2 1/3] drm/xe: Undo pinned BO eviction on suspend failure Thomas Hellström
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thomas Hellström @ 2026-12-03  8:53 UTC (permalink / raw)
  To: intel-xe
  Cc: Thomas Hellström, Natalie Vock, Arun Pravin, Rodrigo Vivi,
	Matthew Auld, Matthew Brost, DRI-devel

When the amount of VRAM in use exceeds the free system memory, evicting
VRAM at suspend may invoke the OOM killer, and under heavy memory
pressure the system may hang [1].

Patch 3 avoids invoking the OOM killer by having the user BO eviction
use __GFP_RETRY_MAYFAIL, so that suspend is aborted with -ENOMEM
instead. That makes eviction failures more likely, which exposes two
pre-existing issues in the failure paths, fixed by patches 1 and 2:

Patch 1 undoes the eviction of pinned BOs if suspend fails partway.
Otherwise the device continues operating with stale backups, which a
later resume restores over the live VRAM contents. This was reported
by Sashiko on v1 of patch 2.

Patch 2 converts -ENOMEM from the eviction at runtime suspend to
-EAGAIN, since runtime PM otherwise treats the error as fatal and
stops runtime-suspending the device.

The patches are ordered so that no intermediate state makes the
failure paths more likely to be hit before they are fixed. Patch 2
depends on patch 1, since retrying runtime suspend would otherwise
restore stale pinned BO backups.

v2:
- Patches 2 and 3 were previously posted separately. Combined them
  into a series.
- Patch 1: New patch. Undo pinned BO eviction on suspend failure, a
  prerequisite for patch 2. Reported by Sashiko.
- Patch 2: Reworded the commit message for the new patch order.
- Patch 3: Rebased.

Testing:
- W=1 build and checkpatch are clean.

[1] https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/9615

AI tool use: an AI coding assistant was used for review and for
drafting parts of the implementation and commit messages.

Thomas Hellström (3):
  drm/xe: Undo pinned BO eviction on suspend failure
  drm/xe: Don't fail runtime suspend permanently on VRAM eviction
    -ENOMEM
  drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at
    suspend

 drivers/gpu/drm/ttm/ttm_resource.c | 37 +++++++++++++++++++------
 drivers/gpu/drm/xe/xe_bo.c         | 26 ++++++++++++++++++
 drivers/gpu/drm/xe/xe_bo.h         |  1 +
 drivers/gpu/drm/xe/xe_bo_evict.c   | 44 ++++++++++++++++++++++++++----
 drivers/gpu/drm/xe/xe_bo_evict.h   |  1 +
 drivers/gpu/drm/xe/xe_device.c     |  5 +++-
 drivers/gpu/drm/xe/xe_pm.c         | 15 ++++++++--
 include/drm/ttm/ttm_resource.h     |  5 ++++
 8 files changed, 118 insertions(+), 16 deletions(-)

-- 
2.56.1


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

* [PATCH v2 1/3] drm/xe: Undo pinned BO eviction on suspend failure
  2026-12-03  8:53 [PATCH v2 0/3] drm/ttm, drm/xe: Handle VRAM eviction failure at suspend Thomas Hellström
@ 2026-12-03  8:53 ` Thomas Hellström
  2026-12-03  8:53 ` [PATCH v2 2/3] drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM Thomas Hellström
  2026-12-03  8:53 ` [PATCH v2 3/3] drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at suspend Thomas Hellström
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Hellström @ 2026-12-03  8:53 UTC (permalink / raw)
  To: intel-xe
  Cc: Thomas Hellström, Matthew Auld, Satyanarayana K V P,
	Matthew Brost, Rodrigo Vivi, stable, Natalie Vock, Arun Pravin,
	DRI-devel

Pinned VRAM BOs are evicted at suspend by copying their contents to a
backup object, while the BOs themselves remain in VRAM. Pinned kernel
BOs are additionally moved to the evicted lists.

If suspend fails after some or all pinned BOs have been evicted, either
in xe_bo_evict_all() itself, for example due to -ENOMEM when allocating
a backup object, or in a later suspend step, nothing undoes this, and
the device continues operating with the stale backups. That causes:

- A subsequent suspend skipping the BOs on the evicted lists, and the
  following resume overwriting their VRAM contents with stale data.
- The backup objects of pinned external BOs being leaked through a
  reference cycle when the BOs are later unpinned.
- A subsequent PM notifier prepare step hitting the
  xe_assert(xe, !bo->backup_obj) in xe_bo_notifier_prepare_pinned().

This has been an issue since the initial driver. Before commit
86f69c26113c ("drm/xe: use backup object for pinned save/restore"),
pinned BOs were instead moved out of VRAM, and with a failed suspend,
the GuC would continue to access the freed VRAM through the GGTT while
the CPU would access the moved copy. This patch only addresses the
backup object scheme.

Add xe_bo_evict_all_undo() that drops the backup objects created by the
eviction and moves the pinned kernel BOs back to the present lists, and
call it on failure in xe_bo_evict_all() and on failures after
xe_bo_evict_all() in the system- and runtime suspend paths. Backup
objects pre-allocated by the PM notifier are kept and released as
usual by the notifier.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Fixes: 86f69c26113c ("drm/xe: use backup object for pinned save/restore")
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Satyanarayana K V P <satyanarayana.k.v.p@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: intel-xe@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v6.16+
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/xe/xe_bo.c       | 26 +++++++++++++++++++++
 drivers/gpu/drm/xe/xe_bo.h       |  1 +
 drivers/gpu/drm/xe/xe_bo_evict.c | 39 ++++++++++++++++++++++++++++----
 drivers/gpu/drm/xe/xe_bo_evict.h |  1 +
 drivers/gpu/drm/xe/xe_device.c   |  5 +++-
 drivers/gpu/drm/xe/xe_pm.c       |  5 +++-
 6 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index c89b39b503fe..af7365581f09 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1786,6 +1786,32 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
 	return ret;
 }
 
+/**
+ * xe_bo_evict_pinned_undo() - Undo a pinned VRAM object eviction
+ * @bo: The buffer object for which to undo the eviction.
+ *
+ * Drop the backup object created by xe_bo_evict_pinned(), if any. Backup
+ * objects pre-allocated by xe_bo_notifier_prepare_pinned() are kept and
+ * released by xe_bo_notifier_unprepare_pinned(). Only valid if the VRAM
+ * contents of @bo were preserved since the eviction.
+ *
+ * Return: Always returns 0.
+ */
+int xe_bo_evict_pinned_undo(struct xe_bo *bo)
+{
+	struct xe_bo *backup;
+
+	xe_bo_lock(bo, false);
+	backup = bo->backup_obj;
+	if (backup && !xe_bo_is_pinned(backup)) {
+		bo->backup_obj = NULL;
+		xe_bo_put(backup);
+	}
+	xe_bo_unlock(bo);
+
+	return 0;
+}
+
 /**
  * xe_bo_restore_pinned() - Restore a pinned VRAM object
  * @bo: The buffer object to move.
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 6a1ae07d2904..bb3cb90cbfc4 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -440,6 +440,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type, struct ttm_operation_ctx *ctc,
 int xe_bo_evict(struct xe_bo *bo, struct drm_exec *exec);
 
 int xe_bo_evict_pinned(struct xe_bo *bo);
+int xe_bo_evict_pinned_undo(struct xe_bo *bo);
 int xe_bo_notifier_prepare_pinned(struct xe_bo *bo);
 int xe_bo_notifier_unprepare_pinned(struct xe_bo *bo);
 int xe_bo_restore_pinned(struct xe_bo *bo);
diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c
index ab7cba57fb3c..61986422772c 100644
--- a/drivers/gpu/drm/xe/xe_bo_evict.c
+++ b/drivers/gpu/drm/xe/xe_bo_evict.c
@@ -227,12 +227,43 @@ int xe_bo_evict_all(struct xe_device *xe)
 	for_each_tile(tile, xe, id)
 		xe_tile_migrate_wait(tile);
 
+	if (!ret)
+		ret = xe_bo_apply_to_pinned(xe, &xe->pinned.early.kernel_bo_present,
+					    &xe->pinned.early.evicted,
+					    xe_bo_evict_pinned);
+
 	if (ret)
-		return ret;
+		xe_bo_evict_all_undo(xe);
+
+	return ret;
+}
+
+/**
+ * xe_bo_evict_all_undo - undo the pinned BO eviction of xe_bo_evict_all()
+ * @xe: xe device
+ *
+ * Drop the backups of pinned BOs created by xe_bo_evict_all() and move
+ * evicted pinned kernel BOs back to the present lists, without restoring
+ * their contents. Non-pinned user BOs are left evicted.
+ *
+ * This function should be called if suspend fails after xe_bo_evict_all()
+ * while VRAM contents are still preserved, so that a subsequent suspend
+ * doesn't skip the BOs, and a subsequent resume doesn't restore stale
+ * contents.
+ */
+void xe_bo_evict_all_undo(struct xe_device *xe)
+{
+	(void)xe_bo_apply_to_pinned(xe, &xe->pinned.late.external,
+				    &xe->pinned.late.external,
+				    xe_bo_evict_pinned_undo);
+
+	(void)xe_bo_apply_to_pinned(xe, &xe->pinned.late.evicted,
+				    &xe->pinned.late.kernel_bo_present,
+				    xe_bo_evict_pinned_undo);
 
-	return xe_bo_apply_to_pinned(xe, &xe->pinned.early.kernel_bo_present,
-				     &xe->pinned.early.evicted,
-				     xe_bo_evict_pinned);
+	(void)xe_bo_apply_to_pinned(xe, &xe->pinned.early.evicted,
+				    &xe->pinned.early.kernel_bo_present,
+				    xe_bo_evict_pinned_undo);
 }
 
 static int xe_bo_map_ggtt(struct xe_bo *bo)
diff --git a/drivers/gpu/drm/xe/xe_bo_evict.h b/drivers/gpu/drm/xe/xe_bo_evict.h
index aabba06f0abf..6dbdab3ebb66 100644
--- a/drivers/gpu/drm/xe/xe_bo_evict.h
+++ b/drivers/gpu/drm/xe/xe_bo_evict.h
@@ -9,6 +9,7 @@
 struct xe_device;
 
 int xe_bo_evict_all(struct xe_device *xe);
+void xe_bo_evict_all_undo(struct xe_device *xe);
 int xe_bo_evict_all_user(struct xe_device *xe);
 int xe_bo_notifier_prepare_all_pinned(struct xe_device *xe);
 void xe_bo_notifier_unprepare_all_pinned(struct xe_device *xe);
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 86de5f183c0a..6d40ab29d59e 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -1444,7 +1444,7 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr)
 		for_each_gt(gt, xe, id) {
 			err = xe_gt_suspend(gt);
 			if (err)
-				goto err_display;
+				goto err_evict;
 		}
 	}
 
@@ -1460,6 +1460,9 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr)
 
 	return 0;
 
+err_evict:
+	if (xe_pm_needs_bo_evict(xe, hibernate))
+		xe_bo_evict_all_undo(xe);
 err_display:
 	xe_display_pm_resume(xe);
 	xe_pxp_pm_resume(xe->pxp);
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index f73f68bd449b..103290fd6445 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -588,7 +588,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
 	for_each_gt(gt, xe, id) {
 		err = xe->d3cold.allowed ? xe_gt_suspend(gt) : xe_gt_runtime_suspend(gt);
 		if (err)
-			goto out_resume;
+			goto out_evict;
 	}
 
 	xe_irq_suspend(xe);
@@ -601,6 +601,9 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
 	xe_pm_write_callback_task(xe, NULL);
 	return 0;
 
+out_evict:
+	if (xe->d3cold.allowed)
+		xe_bo_evict_all_undo(xe);
 out_resume:
 	xe_pm_update_pme_enabled(xe, false);
 	xe_display_pm_runtime_resume(xe);
-- 
2.56.1


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

* [PATCH v2 2/3] drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM
  2026-12-03  8:53 [PATCH v2 0/3] drm/ttm, drm/xe: Handle VRAM eviction failure at suspend Thomas Hellström
  2026-12-03  8:53 ` [PATCH v2 1/3] drm/xe: Undo pinned BO eviction on suspend failure Thomas Hellström
@ 2026-12-03  8:53 ` Thomas Hellström
  2026-12-03  9:43   ` sashiko-bot
  2026-12-03  8:53 ` [PATCH v2 3/3] drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at suspend Thomas Hellström
  2 siblings, 1 reply; 5+ messages in thread
From: Thomas Hellström @ 2026-12-03  8:53 UTC (permalink / raw)
  To: intel-xe
  Cc: Thomas Hellström, Matthew Brost, Rodrigo Vivi, stable,
	Natalie Vock, Arun Pravin, Matthew Auld, DRI-devel

If evicting VRAM to system memory fails with -ENOMEM during runtime
suspend to D3cold, the error is returned to the runtime PM core.
Runtime PM treats any error other than -EAGAIN or -EBUSY from the
->runtime_suspend() callback as fatal, records it in
dev->power.runtime_error, and refuses further runtime PM operations
on the device until the error is cleared.

Memory shortage is a transient condition. Backup objects for pinned
BOs are already allocated with __GFP_RETRY_MAYFAIL, and a following
patch makes eviction of non-pinned BOs use it as well, which makes
-ENOMEM more likely to occur. Convert -ENOMEM from the eviction to
-EAGAIN so that the device stays active and runtime suspend is retried
at a later idle transition.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: intel-xe@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v6.8+
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/xe/xe_pm.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index 103290fd6445..f1dc97afb72a 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -581,8 +581,16 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
 
 	if (xe->d3cold.allowed) {
 		err = xe_bo_evict_all(xe);
-		if (err)
+		if (err) {
+			/*
+			 * Runtime PM treats errors other than -EAGAIN and
+			 * -EBUSY as fatal, so report memory shortage as
+			 * transient to allow a later retry.
+			 */
+			if (err == -ENOMEM)
+				err = -EAGAIN;
 			goto out_resume;
+		}
 	}
 
 	for_each_gt(gt, xe, id) {
-- 
2.56.1


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

* [PATCH v2 3/3] drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at suspend
  2026-12-03  8:53 [PATCH v2 0/3] drm/ttm, drm/xe: Handle VRAM eviction failure at suspend Thomas Hellström
  2026-12-03  8:53 ` [PATCH v2 1/3] drm/xe: Undo pinned BO eviction on suspend failure Thomas Hellström
  2026-12-03  8:53 ` [PATCH v2 2/3] drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM Thomas Hellström
@ 2026-12-03  8:53 ` Thomas Hellström
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Hellström @ 2026-12-03  8:53 UTC (permalink / raw)
  To: intel-xe
  Cc: Thomas Hellström, Matthew Auld, Matthew Brost, Rodrigo Vivi,
	Natalie Vock, Arun Pravin, dri-devel, stable,
	Arunpravin Paneer Selvam

When evicting user BOs from VRAM at suspend time, allocating system
memory for the eviction may currently invoke the OOM killer. Under
memory pressure it is preferable to abort the suspend and return
-ENOMEM rather than killing processes.

TTM's ttm_resource_manager_evict_all() uses a default operation
context, which doesn't allow the caller to request
__GFP_RETRY_MAYFAIL allocations. Introduce
ttm_resource_manager_evict_all_ctx() taking a caller-supplied
struct ttm_operation_ctx, keeping ttm_resource_manager_evict_all()
as an exported wrapper using a default context so that existing
users are unaffected. Also honor the ctx interruptible setting when
waiting for the eviction fences.

Use the new function from xe_bo_evict_all_user() with
gfp_retry_mayfail set.

Note that the PM notifier eviction is best-effort and ignores errors.
Any remaining BOs are evicted again from the .suspend() callback,
where an -ENOMEM might then cause the suspend to be aborted.

Fixes: c6a4d46ec1d7 ("drm/xe: evict user memory in PM notifier")
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: intel-xe@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v6.16+
Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/9615
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/ttm/ttm_resource.c | 37 +++++++++++++++++++++++-------
 drivers/gpu/drm/xe/xe_bo_evict.c   |  5 +++-
 include/drm/ttm/ttm_resource.h     |  5 ++++
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 2db5d9bbfbe7..d1eccaeb1047 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -568,24 +568,26 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,
 }
 EXPORT_SYMBOL(ttm_resource_manager_init);
 
-/*
- * ttm_resource_manager_evict_all
- *
+/**
+ * ttm_resource_manager_evict_all_ctx() - Evict all objects from a manager
  * @bdev: device to use
  * @man: manager to use
+ * @ctx: operation context for the eviction
  *
  * Evict all the objects out of a memory manager until it is empty.
  * Part of memory manager cleanup sequence.
+ *
+ * Return: 0 on success, negative error code on failure.
  */
-int ttm_resource_manager_evict_all(struct ttm_device *bdev,
-				   struct ttm_resource_manager *man)
+int ttm_resource_manager_evict_all_ctx(struct ttm_device *bdev,
+				       struct ttm_resource_manager *man,
+				       struct ttm_operation_ctx *ctx)
 {
-	struct ttm_operation_ctx ctx = { };
 	struct dma_fence *fence;
 	int ret, i;
 
 	do {
-		ret = ttm_bo_evict_first(bdev, man, &ctx);
+		ret = ttm_bo_evict_first(bdev, man, ctx);
 		cond_resched();
 	} while (!ret);
 
@@ -600,7 +602,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
 		if (fence && !dma_fence_is_signaled(fence)) {
 			dma_fence_get(fence);
 			spin_unlock(&man->eviction_lock);
-			ret = dma_fence_wait(fence, false);
+			ret = dma_fence_wait(fence, ctx->interruptible);
 			dma_fence_put(fence);
 			if (ret)
 				return ret;
@@ -611,6 +613,25 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
 
 	return ret;
 }
+EXPORT_SYMBOL(ttm_resource_manager_evict_all_ctx);
+
+/**
+ * ttm_resource_manager_evict_all() - Evict all objects from a manager
+ * @bdev: device to use
+ * @man: manager to use
+ *
+ * Same as ttm_resource_manager_evict_all_ctx() using a default,
+ * non-interruptible operation context.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int ttm_resource_manager_evict_all(struct ttm_device *bdev,
+				   struct ttm_resource_manager *man)
+{
+	struct ttm_operation_ctx ctx = { };
+
+	return ttm_resource_manager_evict_all_ctx(bdev, man, &ctx);
+}
 EXPORT_SYMBOL(ttm_resource_manager_evict_all);
 
 /**
diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c
index 61986422772c..7fdbe32473ab 100644
--- a/drivers/gpu/drm/xe/xe_bo_evict.c
+++ b/drivers/gpu/drm/xe/xe_bo_evict.c
@@ -156,6 +156,9 @@ static int xe_bo_evict_all_ccs(struct ttm_resource_manager *man)
  */
 int xe_bo_evict_all_user(struct xe_device *xe)
 {
+	struct ttm_operation_ctx ctx = {
+		.gfp_retry_mayfail = true,
+	};
 	struct ttm_device *bdev = &xe->ttm;
 	u32 mem_type;
 	int ret;
@@ -182,7 +185,7 @@ int xe_bo_evict_all_user(struct xe_device *xe)
 			continue;
 		}
 
-		ret = ttm_resource_manager_evict_all(bdev, man);
+		ret = ttm_resource_manager_evict_all_ctx(bdev, man, &ctx);
 		if (ret)
 			return ret;
 	}
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index d90e1cffa862..103a241525e6 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -42,6 +42,7 @@ struct dmem_cgroup_device;
 struct dmem_cgroup_region;
 struct drm_printer;
 struct ttm_device;
+struct ttm_operation_ctx;
 struct ttm_resource_manager;
 struct ttm_resource;
 struct ttm_place;
@@ -488,6 +489,10 @@ void ttm_resource_manager_set_dmem_region(struct ttm_resource_manager *man,
 int ttm_resource_manager_dmem_reclaim(struct dmem_cgroup_pool_state *pool,
 				      u64 target_bytes, void *priv);
 
+int ttm_resource_manager_evict_all_ctx(struct ttm_device *bdev,
+				       struct ttm_resource_manager *man,
+				       struct ttm_operation_ctx *ctx);
+
 int ttm_resource_manager_evict_all(struct ttm_device *bdev,
 				   struct ttm_resource_manager *man);
 
-- 
2.56.1


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

* Re: [PATCH v2 2/3] drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM
  2026-12-03  8:53 ` [PATCH v2 2/3] drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM Thomas Hellström
@ 2026-12-03  9:43   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-03  9:43 UTC (permalink / raw)
  To: Thomas Hellström, intel-xe; +Cc: DRI-devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe: -EAGAIN in xe_pm_runtime_suspend() self-retriggers
  OOM retry storm
--

commit 432d67d7cb644bed2d1d62b6cc14bc747772f450
Author: Thomas Hellström <thomas.hellstrom@linux.intel.com>

drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM

This commit converts -ENOMEM returned by xe_bo_evict_all() during D3cold
runtime suspend into -EAGAIN so the runtime PM core does not record a
permanent runtime error on the device.

> diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
> index 103290fd6445c..f1dc97afb72a2 100644
> --- a/drivers/gpu/drm/xe/xe_pm.c
> +++ b/drivers/gpu/drm/xe/xe_pm.c
> @@ -581,8 +581,16 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
>  
>  	if (xe->d3cold.allowed) {
>  		err = xe_bo_evict_all(xe);
> -		if (err)
> +		if (err) {
> +			/*
> +			 * Runtime PM treats errors other than -EAGAIN and
> +			 * -EBUSY as fatal, so report memory shortage as
> +			 * transient to allow a later retry.
> +			 */
> +			if (err == -ENOMEM)
> +				err = -EAGAIN;
>  			goto out_resume;
> +		}
>  	}

[Severity: Medium]
Can returning -EAGAIN here trigger an unbounded runtime suspend retry loop
while the GPU is idle under persistent memory pressure?

During xe_bo_evict_all(), evicting a BO on xe->pinned.late.external or
xe->pinned.late.kernel_bo_present submits a migration job via
xe_sched_job_create(), which calls xe_pm_runtime_get_noresume().  If a later
pinned BO hits -ENOMEM, xe_bo_evict_all_undo() discards all new backups.

When that migration job finishes, drm_sched_free_job_work() runs on the
scheduler submit_wq worker and calls xe_sched_job_destroy() ->
xe_pm_runtime_put().  Because current is not xe->pm_callback_task, it calls
pm_runtime_mark_last_busy() and pm_runtime_put() instead of the noidle path.

Because -EAGAIN leaves dev->power.runtime_error clear, that off-thread put
either refreshes last_busy before rpm_suspend() checks autosuspend expiration
or drops usage_count to zero after RPM_ACTIVE is restored and queues
RPM_REQ_IDLE.  Either way, autosuspend re-arms every autosuspend_delay_ms.

Each retry drives repeated __GFP_RETRY_MAYFAIL reclaim on a memory-starved
host, submits GPU copies whose backups are immediately undone, and runs full
display D3cold teardown and re-init via xe_display_disable_d3cold().  Falling
back to D3hot on -ENOMEM would avoid this self-retriggering loop.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203085321.235694-1-thomas.hellstrom@linux.intel.com?part=2

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

end of thread, other threads:[~2026-12-03  9:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  8:53 [PATCH v2 0/3] drm/ttm, drm/xe: Handle VRAM eviction failure at suspend Thomas Hellström
2026-12-03  8:53 ` [PATCH v2 1/3] drm/xe: Undo pinned BO eviction on suspend failure Thomas Hellström
2026-12-03  8:53 ` [PATCH v2 2/3] drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM Thomas Hellström
2026-12-03  9:43   ` sashiko-bot
2026-12-03  8:53 ` [PATCH v2 3/3] drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at suspend Thomas Hellström

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