Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Natalie Vock" <nat@pixelcluster.dev>,
	"Arun Pravin" <arunpravin.paneerselvam@amd.com>,
	dri-devel@lists.freedesktop.org, stable@vger.kernel.org,
	"Arunpravin Paneer Selvam" <Arunpravin.PaneerSelvam@amd.com>
Subject: [PATCH v3 3/3] drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at suspend
Date: Thu,  3 Dec 2026 11:47:15 +0100	[thread overview]
Message-ID: <20261203104715.270111-4-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20261203104715.270111-1-thomas.hellstrom@linux.intel.com>

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.

v2:
- Rebase

v3:
- Rebase onto latest drm-tip

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


      parent reply	other threads:[~2026-12-03 10:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:47 [PATCH v3 0/3] drm/ttm, drm/xe: Handle VRAM eviction failure at suspend Thomas Hellström
2026-12-03 10:47 ` [PATCH v3 1/3] drm/xe: Undo pinned BO eviction on suspend failure Thomas Hellström
2026-12-03 10:47 ` [PATCH v3 2/3] drm/xe: Don't fail runtime suspend permanently on VRAM eviction -ENOMEM Thomas Hellström
2026-12-03 10:47 ` Thomas Hellström [this message]

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=20261203104715.270111-4-thomas.hellstrom@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=nat@pixelcluster.dev \
    --cc=rodrigo.vivi@intel.com \
    --cc=stable@vger.kernel.org \
    /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