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>,
"Satyanarayana K V P" <satyanarayana.k.v.p@intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
stable@vger.kernel.org, "Natalie Vock" <nat@pixelcluster.dev>,
"Arun Pravin" <arunpravin.paneerselvam@amd.com>,
DRI-devel <dri-devel@lists.freedesktop.org>
Subject: [PATCH v3 1/3] drm/xe: Undo pinned BO eviction on suspend failure
Date: Thu, 3 Dec 2026 11:47:13 +0100 [thread overview]
Message-ID: <20261203104715.270111-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20261203104715.270111-1-thomas.hellstrom@linux.intel.com>
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.
v3:
- Rebase onto latest drm-tip
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 af96394b4b31..aae30237d86c 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -1455,7 +1455,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;
}
}
@@ -1474,6 +1474,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 e3eb4118d461..00d321a7d646 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -589,7 +589,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;
}
for_each_gt(gt, xe, id)
@@ -605,6 +605,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
next parent reply other threads:[~2026-12-03 10:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261203104715.270111-1-thomas.hellstrom@linux.intel.com>
2026-12-03 10:47 ` Thomas Hellström [this message]
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 ` [PATCH v3 3/3] drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at suspend Thomas Hellström
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-2-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=satyanarayana.k.v.p@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