Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe/pm: Refuse suspend/hibernate when used VRAM exceeds available memory
@ 2026-11-04 13:51 Karthik Poosa
  2026-11-04 15:26 ` ✓ CI.KUnit: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Karthik Poosa @ 2026-11-04 13:51 UTC (permalink / raw)
  To: intel-xe
  Cc: rodrigo.vivi, anshuman.gupta, badal.nilawar, raag.jadav,
	riana.tauro, himal.prasad.ghimiray, joonas.lahtinen,
	Karthik Poosa

On PM_SUSPEND_PREPARE and PM_HIBERNATION_PREPARE the driver evicts VRAM
contents to system memory. If more VRAM is in use than system memory can
hold, eviction fails in the notifier, which only logs it, and the
transition then fails later during device suspend.

Compare VRAM usage across all VRAM regions with available system memory
(si_mem_available()) plus free swap, since evicted user BOs can be
swapped out by the shrinker. If it doesn't fit, fail with -ENOMEM before
taking the runtime PM reference or starting eviction, so the transition
is cancelled cleanly up front.

This is a best-effort check: usage can change between the check and the
eviction, and pinned BO backups cannot be swapped.

Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
---
 drivers/gpu/drm/xe/xe_pm.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index f7e2770252ec..85698361f2ba 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -9,6 +9,8 @@
 #include <linux/pm_runtime.h>
 #include <linux/suspend.h>
 #include <linux/dmi.h>
+#include <linux/mm.h>
+#include <linux/swap.h>
 
 #include <drm/drm_managed.h>
 #include <drm/ttm/ttm_placement.h>
@@ -439,6 +441,24 @@ static int xe_pm_notifier_callback(struct notifier_block *nb,
 	case PM_SUSPEND_PREPARE:
 	{
 		struct xe_validation_ctx ctx;
+		struct ttm_resource_manager *man;
+		u64 vram_used = 0, sys_avail;
+		int i;
+
+		for (i = XE_PL_VRAM0; i <= XE_PL_VRAM1; ++i) {
+			man = ttm_manager_type(&xe->ttm, i);
+			if (man)
+				vram_used += ttm_resource_manager_usage(man);
+		}
+
+		/* Evicted user BOs may be swapped out by the shrinker */
+		sys_avail = (u64)(si_mem_available() + get_nr_swap_pages()) << PAGE_SHIFT;
+		if (vram_used > sys_avail) {
+			drm_warn(&xe->drm,
+				 "Used VRAM %llu MiB exceeds available system memory %llu MiB, refusing suspend/hibernate\n",
+				 vram_used / SZ_1M, sys_avail / SZ_1M);
+			return notifier_from_errno(-ENOMEM);
+		}
 
 		reinit_completion(&xe->pm_block);
 		xe_pm_block_begin_signalling();
-- 
2.25.1


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

end of thread, other threads:[~2026-12-01 21:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 13:51 [PATCH] drm/xe/pm: Refuse suspend/hibernate when used VRAM exceeds available memory Karthik Poosa
2026-11-04 15:26 ` ✓ CI.KUnit: success for " Patchwork
2026-11-04 16:04 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-04 16:26 ` [PATCH] " Thomas Hellström
2026-12-01 21:37   ` Rodrigo Vivi
2026-11-05  7:10 ` ✓ Xe.CI.FULL: 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