Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: intel-xe@lists.freedesktop.org,
	John Falkowski <john.falkowski@intel.com>,
	 Michal Mrozek <michal.mrozek@intel.com>
Subject: Re: [PATCH] drm/xe/uapi: Introduce a flag to disallow vm overcommit in fault mode
Date: Thu, 05 Feb 2026 09:06:24 +0100	[thread overview]
Message-ID: <4a012fa66d9eb5858f41159d5b65f790d57e6297.camel@linux.intel.com> (raw)
In-Reply-To: <aYOWWAg9O1KUhnpO@lstrano-desk.jf.intel.com>

On Wed, 2026-02-04 at 10:56 -0800, Matthew Brost wrote:
> On Wed, Feb 04, 2026 at 04:33:20PM +0100, Thomas Hellström wrote:
> > Some compute applications may try to allocate device memory to
> > probe
> > how much device memory is actually available, assuming that the
> > application will be the only one running on the particular GPU.
> > 
> > That strategy fails in fault mode since it allows VM overcommit.
> > 
> > While this could be resolved in user-space it's further complicated
> > by cgroups potentially restricting the amount of memory available
> > to the application.
> > 
> > Introduce a vm create flag, DRM_XE_VM_CREATE_NO_VM_OVERCOMMIT, that
> > allows fault mode to mimic the behaviour of !fault mode WRT this.
> > It
> > blocks evicting same vm bos during VM_BIND processing. However,
> > it does *not* block evicting same-vm bos during pagefault
> > processing, preferring eviction rather than VM banning in
> > OOM situations.
> > 
> > Cc: John Falkowski <john.falkowski@intel.com>
> > Cc: Michal Mrozek <michal.mrozek@intel.com>
> > Cc: Matthew Brost <matthew.brost@intel.com>
> > Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > ---
> >  drivers/gpu/drm/xe/xe_vm.c       | 11 +++++++++--
> >  drivers/gpu/drm/xe/xe_vm.h       |  7 +++++++
> >  drivers/gpu/drm/xe/xe_vm_types.h |  1 +
> >  include/uapi/drm/xe_drm.h        |  6 ++++++
> >  4 files changed, 23 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_vm.c
> > b/drivers/gpu/drm/xe/xe_vm.c
> > index 8fe54a998385..cf92b6e13a16 100644
> > --- a/drivers/gpu/drm/xe/xe_vm.c
> > +++ b/drivers/gpu/drm/xe/xe_vm.c
> > @@ -1938,7 +1938,8 @@ find_ufence_get(struct xe_sync_entry *syncs,
> > u32 num_syncs)
> >  
> >  #define ALL_DRM_XE_VM_CREATE_FLAGS
> > (DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE | \
> >  				    DRM_XE_VM_CREATE_FLAG_LR_MODE
> > | \
> > -				   
> > DRM_XE_VM_CREATE_FLAG_FAULT_MODE)
> > +				   
> > DRM_XE_VM_CREATE_FLAG_FAULT_MODE | \
> > +				   
> > DRM_XE_VM_CREATE_FLAG_NO_VM_OVERCOMMIT)
> >  
> >  int xe_vm_create_ioctl(struct drm_device *dev, void *data,
> >  		       struct drm_file *file)
> > @@ -1977,12 +1978,18 @@ int xe_vm_create_ioctl(struct drm_device
> > *dev, void *data,
> >  			 args->flags &
> > DRM_XE_VM_CREATE_FLAG_FAULT_MODE))
> >  		return -EINVAL;
> >  
> > +	if (XE_IOCTL_DBG(xe, !(args->flags &
> > DRM_XE_VM_CREATE_FLAG_FAULT_MODE) &&
> > +			 args->flags &
> > DRM_XE_VM_CREATE_FLAG_NO_VM_OVERCOMMIT))
> > +		return -EINVAL;
> > +
> >  	if (args->flags & DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE)
> >  		flags |= XE_VM_FLAG_SCRATCH_PAGE;
> >  	if (args->flags & DRM_XE_VM_CREATE_FLAG_LR_MODE)
> >  		flags |= XE_VM_FLAG_LR_MODE;
> >  	if (args->flags & DRM_XE_VM_CREATE_FLAG_FAULT_MODE)
> >  		flags |= XE_VM_FLAG_FAULT_MODE;
> > +	if (args->flags & DRM_XE_VM_CREATE_FLAG_NO_VM_OVERCOMMIT)
> > +		flags |= XE_VM_FLAG_NO_VM_OVERCOMMIT;
> >  
> >  	vm = xe_vm_create(xe, flags, xef);
> >  	if (IS_ERR(vm))
> > @@ -2903,7 +2910,7 @@ static int vma_lock_and_validate(struct
> > drm_exec *exec, struct xe_vma *vma,
> >  			err = drm_exec_lock_obj(exec, &bo-
> > >ttm.base);
> >  		if (!err && validate)
> >  			err = xe_bo_validate(bo, vm,
> > -					    
> > !xe_vm_in_preempt_fence_mode(vm) &&
> > +					    
> > xe_vm_allow_vm_eviction(vm) &&
> 
> One question. This is existing code but can you refresh my memory why
> we
> allow overcommit on dma-fencing VMs? Wouldn't the next exec IOCTL
> immediately fail?

Yes, but mesa can handle that by user-space eviction. In practice IIRC
they unbind everything and re-bind on demand. No care for performance.

For preempt-fence mode we have the dreaded oom-in-the-rebind-worker
which we still haven't fixed with a UMD notification, so we're forced
to avoid that if at all possible.

/Thomas


> 
> Matt
> 
> >  					     res_evict, exec);
> >  	}
> >  
> > diff --git a/drivers/gpu/drm/xe/xe_vm.h
> > b/drivers/gpu/drm/xe/xe_vm.h
> > index 288115c7844a..f849e369432b 100644
> > --- a/drivers/gpu/drm/xe/xe_vm.h
> > +++ b/drivers/gpu/drm/xe/xe_vm.h
> > @@ -220,6 +220,13 @@ static inline bool
> > xe_vm_in_preempt_fence_mode(struct xe_vm *vm)
> >  	return xe_vm_in_lr_mode(vm) && !xe_vm_in_fault_mode(vm);
> >  }
> >  
> > +static inline bool xe_vm_allow_vm_eviction(struct xe_vm *vm)
> > +{
> > +	return !xe_vm_in_lr_mode(vm) ||
> > +		(xe_vm_in_fault_mode(vm) &&
> > +		 !(vm->flags & XE_VM_FLAG_NO_VM_OVERCOMMIT));
> > +}
> > +
> >  int xe_vm_add_compute_exec_queue(struct xe_vm *vm, struct
> > xe_exec_queue *q);
> >  void xe_vm_remove_compute_exec_queue(struct xe_vm *vm, struct
> > xe_exec_queue *q);
> >  
> > diff --git a/drivers/gpu/drm/xe/xe_vm_types.h
> > b/drivers/gpu/drm/xe/xe_vm_types.h
> > index 43203e90ee3e..1f6f7e30e751 100644
> > --- a/drivers/gpu/drm/xe/xe_vm_types.h
> > +++ b/drivers/gpu/drm/xe/xe_vm_types.h
> > @@ -232,6 +232,7 @@ struct xe_vm {
> >  #define XE_VM_FLAG_TILE_ID(flags)	FIELD_GET(GENMASK(7, 6),
> > flags)
> >  #define XE_VM_FLAG_SET_TILE_ID(tile)	FIELD_PREP(GENMASK(7, 6),
> > (tile)->id)
> >  #define XE_VM_FLAG_GSC			BIT(8)
> > +#define XE_VM_FLAG_NO_VM_OVERCOMMIT     BIT(9)
> >  	unsigned long flags;
> >  
> >  	/**
> > diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
> > index 077e66a682e2..e54f8e12acd9 100644
> > --- a/include/uapi/drm/xe_drm.h
> > +++ b/include/uapi/drm/xe_drm.h
> > @@ -975,6 +975,11 @@ struct drm_xe_gem_mmap_offset {
> >   *    demand when accessed, and also allows per-VM overcommit of
> > memory.
> >   *    The xe driver internally uses recoverable pagefaults to
> > implement
> >   *    this.
> > + *  - %DRM_XE_VM_CREATE_FLAG_NO_VM_OVERCOMMIT - Requires also
> > + *    DRM_XE_VM_CREATE_FLAG_FAULT_MODE. This disallows per-VM
> > overcommit
> > + *    but only during a &DRM_IOCTL_XE_VM_BIND operation with the
> > + *    %DRM_XE_VM_BIND_FLAG_IMMEDIATE flag set. This may be useful
> > for
> > + *    user-space naively probing the amount of available memory.
> >   */
> >  struct drm_xe_vm_create {
> >  	/** @extensions: Pointer to the first extension struct, if
> > any */
> > @@ -983,6 +988,7 @@ struct drm_xe_vm_create {
> >  #define DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE	(1 << 0)
> >  #define DRM_XE_VM_CREATE_FLAG_LR_MODE	        (1 << 1)
> >  #define DRM_XE_VM_CREATE_FLAG_FAULT_MODE	(1 << 2)
> > +#define DRM_XE_VM_CREATE_FLAG_NO_VM_OVERCOMMIT  (1 << 3)
> >  	/** @flags: Flags */
> >  	__u32 flags;
> >  
> > -- 
> > 2.52.0
> > 

  reply	other threads:[~2026-02-05  8:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04 15:33 [PATCH] drm/xe/uapi: Introduce a flag to disallow vm overcommit in fault mode Thomas Hellström
2026-02-04 18:56 ` Matthew Brost
2026-02-05  8:06   ` Thomas Hellström [this message]
2026-02-05 17:58     ` Matthew Brost
2026-02-05  0:50 ` ✓ CI.KUnit: success for " Patchwork
2026-02-05  1:23 ` ✓ Xe.CI.BAT: " Patchwork
2026-02-05 16:14 ` ✓ Xe.CI.FULL: " 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=4a012fa66d9eb5858f41159d5b65f790d57e6297.camel@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=john.falkowski@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=michal.mrozek@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