Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v3 3/4] drm/xe: Bump prefetch BO LRU via GPUSVM devmem callback
Date: Fri, 25 Sep 2026 18:59:22 -0700	[thread overview]
Message-ID: <arcm+iAe5Ac7Yhab@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <arcmWgk9TsnR6Nbf@gsse-cloud1.jf.intel.com>

On Fri, Sep 25, 2026 at 06:56:42PM -0700, Matthew Brost wrote:
> On Tue, Sep 22, 2026 at 10:08:03AM +0530, Himal Prasad Ghimiray wrote:
> > Add xe_svm_devmem_lru_bump() and set it as drm_gpusvm_ctx.devmem_fn in
> > the prefetch worker so each backing BO is moved to the LRU tail during
> > get_pages.
> > 
> > v2:
> > - Guard xe_svm_devmem_lru_bump() against foreign device-memory
> >   allocations before casting to xe_bo: return early when
> >   devmem_allocation->ops != &dpagemap_devmem_ops. A shared
> >   device_private_page_owner can hand us another driver's allocation.
> >   (Matthew Brost / Sashiko AI review)
> > - Add stub for function (CI)
> > 
> > v3:
> > - Guard xe_svm_devmem_lru_bump() body with CONFIG_DRM_XE_PAGEMAP; it
> >   references dpagemap_devmem_ops and to_xe_bo(), which only exist when
> >   PAGEMAP is enabled. Fixes the build with GPUSVM=y, PAGEMAP=n.
> >   (Sashiko AI review)
> > 
> > Suggested-by: Matthew Brost <matthew.brost@intel.com>
> > Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> > ---
> >  drivers/gpu/drm/xe/xe_svm.c | 30 ++++++++++++++++++++++++++++++
> >  drivers/gpu/drm/xe/xe_svm.h |  7 +++++++
> >  drivers/gpu/drm/xe/xe_vm.c  |  1 +
> >  3 files changed, 38 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
> > index f39e647512ad..018836ecbb06 100644
> > --- a/drivers/gpu/drm/xe/xe_svm.c
> > +++ b/drivers/gpu/drm/xe/xe_svm.c
> > @@ -9,6 +9,7 @@
> >  #include <drm/drm_managed.h>
> >  #include <drm/drm_pagemap.h>
> >  #include <drm/drm_pagemap_util.h>
> > +#include <drm/ttm/ttm_bo.h>
> >  
> >  #include "xe_bo.h"
> >  #include "xe_exec_queue_types.h"
> > @@ -1625,6 +1626,35 @@ int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
> >  	return err;
> >  }
> >  
> > +/**
> > + * xe_svm_devmem_lru_bump() - Move a range's backing BO to the TTM LRU tail
> > + * @devmem_allocation: The device-memory allocation backing the range's pages
> > + *
> > + * Intended as a &drm_gpusvm_ctx.devmem_fn. Runs under the GPUSVM notifier lock;
> > + * the dma-resv trylock avoids inverting against eviction/shrinker, which take
> > + * dma-resv before the notifier lock. A contended BO is simply skipped.
> 
> This kernel doc isn't right.
> 
> - get_pages() calls ctx.devmem_fn under the notifier
> - the notifier lock is path of reclaim so dma-resv can't be taken under
>   the notifier lock

s/can't be taken under/can't be taken with blocking under/

Matt

> - dma-resv also is an outer lock of the notifier when memory is
>   allocated + migrated
> - in practice because BO is private (dedicated dma-resv) a trylock
>   should always work unless it moving elsewhere, e.g., eviction
> 
> Somehow tie this all together into a coherent kernel doc.
> 
> > + *
> > + * A shared device_private_page_owner can hand us allocations backed by a
> > + * foreign driver; skip anything that is not an xe BO before casting.
> 
> s/xe/Xe
> 
> Otherwise LGTM.
> 
> Matt
> 
> > + */
> > +void xe_svm_devmem_lru_bump(struct drm_pagemap_devmem *devmem_allocation)
> > +{
> > +#if IS_ENABLED(CONFIG_DRM_XE_PAGEMAP)
> > +	struct xe_bo *bo;
> > +
> > +	if (devmem_allocation->ops != &dpagemap_devmem_ops)
> > +		return;
> > +
> > +	bo = to_xe_bo(devmem_allocation);
> > +
> > +	if (!dma_resv_trylock(bo->ttm.base.resv))
> > +		return;
> > +
> > +	ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
> > +	dma_resv_unlock(bo->ttm.base.resv);
> > +#endif
> > +}
> > +
> >  /**
> >   * xe_svm_ranges_zap_ptes_in_range - clear ptes of svm ranges in input range
> >   * @vm: Pointer to the xe_vm structure
> > diff --git a/drivers/gpu/drm/xe/xe_svm.h b/drivers/gpu/drm/xe/xe_svm.h
> > index 2ef4ef026ccd..585ad64b672b 100644
> > --- a/drivers/gpu/drm/xe/xe_svm.h
> > +++ b/drivers/gpu/drm/xe/xe_svm.h
> > @@ -128,6 +128,8 @@ struct xe_svm_range *xe_svm_range_find_or_insert(struct xe_vm *vm, u64 addr,
> >  int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
> >  			   struct drm_gpusvm_ctx *ctx);
> >  
> > +void xe_svm_devmem_lru_bump(struct drm_pagemap_devmem *devmem_allocation);
> > +
> >  bool xe_svm_range_needs_migrate_to_vram(struct xe_svm_range *range, struct xe_vma *vma,
> >  					const struct drm_pagemap *dpagemap);
> >  
> > @@ -356,6 +358,11 @@ int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
> >  	return -EINVAL;
> >  }
> >  
> > +static inline
> > +void xe_svm_devmem_lru_bump(struct drm_pagemap_devmem *devmem_allocation)
> > +{
> > +}
> > +
> >  static inline struct xe_svm_range *to_xe_range(struct drm_gpusvm_range *r)
> >  {
> >  	return NULL;
> > diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> > index 6b793ef31537..0fdc740f1a41 100644
> > --- a/drivers/gpu/drm/xe/xe_vm.c
> > +++ b/drivers/gpu/drm/xe/xe_vm.c
> > @@ -3260,6 +3260,7 @@ static int prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops *vops,
> >  	ctx.devmem_possible = devmem_possible;
> >  	ctx.check_pages_threshold = devmem_possible ? SZ_64K : 0;
> >  	ctx.device_private_page_owner = xe_svm_private_page_owner(vm, !dpagemap);
> > +	ctx.devmem_fn = xe_svm_devmem_lru_bump;
> >  
> >  	skip_threads =  op->prefetch_range.ranges_count == 1 ||
> >  		(!dpagemap && !(vops->flags &
> > -- 
> > 2.43.0
> > 

  reply	other threads:[~2026-09-26  1:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  4:38 [PATCH v3 0/4] Refresh TTM LRU on SVM prefetch Himal Prasad Ghimiray
2026-09-22  4:38 ` [PATCH v3 1/4] drm/pagemap: Add helper to access backing devmem allocation Himal Prasad Ghimiray
2026-09-22  4:38 ` [PATCH v3 2/4] drm/gpusvm: Add devmem callback to get_pages Himal Prasad Ghimiray
2026-09-26  1:42   ` Matthew Brost
2026-09-22  4:38 ` [PATCH v3 3/4] drm/xe: Bump prefetch BO LRU via GPUSVM devmem callback Himal Prasad Ghimiray
2026-09-26  1:56   ` Matthew Brost
2026-09-26  1:59     ` Matthew Brost [this message]
2026-09-28  3:42       ` Ghimiray, Himal Prasad
2026-09-22  4:38 ` [PATCH v3 4/4] drm/xe: Bump prefetch BO LRU for already-valid ranges Himal Prasad Ghimiray
2026-09-26  1:57   ` Matthew Brost
2026-09-22  4:43 ` ✓ CI.KUnit: success for Refresh TTM LRU on SVM prefetch (rev3) Patchwork
2026-09-22  5:39 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-09-22 13:40 ` ✓ Xe.CI.FULL: success " Patchwork
2026-09-26  0:38 ` ✓ Xe.CI.BAT: success for Refresh TTM LRU on SVM prefetch (rev4) Patchwork
2026-09-26  9:48 ` ✓ 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=arcm+iAe5Ac7Yhab@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.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