Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: Karthik Poosa <karthik.poosa@intel.com>,
	<intel-xe@lists.freedesktop.org>,  <anshuman.gupta@intel.com>,
	<badal.nilawar@intel.com>, <raag.jadav@intel.com>,
	<riana.tauro@intel.com>, <himal.prasad.ghimiray@intel.com>,
	<joonas.lahtinen@intel.com>
Subject: Re: [PATCH] drm/xe/pm: Refuse suspend/hibernate when used VRAM exceeds available memory
Date: Tue, 1 Dec 2026 16:37:38 -0500	[thread overview]
Message-ID: <aw8-Ikmc6bQ9Wjpj@intel.com> (raw)
In-Reply-To: <593e16359e311d7206c0bf9ea960d271020950ba.camel@linux.intel.com>

On Wed, Nov 04, 2026 at 05:26:19PM +0100, Thomas Hellström wrote:
> Hi!
> 
> On Wed, 2026-11-04 at 19:21 +0530, Karthik Poosa wrote:
> > 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>
> 
> We have this one here:
> https://patchwork.freedesktop.org/patch/761451/?series=176481&rev=1
> 
> See also the link for the upstream issue.
> 
> But there are complications. Even if the suspend doesn't drain all
> available system memory due to the above, then other allocators may due
> to the suspend has already drained all memory.
> 
> Also zram swap may give incorrect values of available swap,
> and multiple devices suspending may be more subject to TOCTOU errors.
> 
> So in addition to all of these suggestions here, IMO want a variant
> that checks for each bo about to be evicted the available memory + swap
> and leave a reasonable amount of memory.
> 
> https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/9615

I'm wondering if it is possible to get some protection in place like
this patch while we don't get the proper one?!

> 
> /Thomas
> 
> 
> > ---
> >  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();

  reply	other threads:[~2026-12-01 21:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-05  7:10 ` ✓ Xe.CI.FULL: success for " Patchwork

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=aw8-Ikmc6bQ9Wjpj@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=joonas.lahtinen@intel.com \
    --cc=karthik.poosa@intel.com \
    --cc=raag.jadav@intel.com \
    --cc=riana.tauro@intel.com \
    --cc=thomas.hellstrom@linux.intel.com \
    /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