Re: [RFC 14/15] drm/xe/vm: Add xe_vma_supports_access_ctr() helper

Summers, Stuart
2026-04-22T20:54:40Z

On Wed, 2026-03-18 at 13:14 +0530, Himal Prasad Ghimiray wrote:
> Hardware access counter slots are finite resources. Add a helper
> to determine whether a VMA is eligible for access counting, so
> callers can avoid wasting slots on BOs that cannot benefit from
> migration hints.
>
> A VMA is eligible if:
>   - The device is a discrete GPU (access counters unused on iGPU)
>   - It is a CPU address mirror (SVM) VMA, which is always migratable
>   - The backing BO has more than one placement region
>   - The BO is not already resident in VRAM local to the triggering
> tile
>
> Userptr and null VMAs are excluded as they have no associated BO.
>
> Signed-off-by: Himal Prasad Ghimiray
> <himal.prasad.ghimiray@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_vm.c | 41
> ++++++++++++++++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_vm.h |  3 +++
>  2 files changed, 44 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 659504ec5a13..7f979d6205f4 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -4356,6 +4356,47 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot
> *snap)
>         kvfree(snap);
>  }
>
> +/**
> + * xe_vma_supports_access_ctr - Determine if VMA is eligible for
> access counting
> + * @xe: Pointer to the Xe device structure
> + * @vma: The VMA
> + * @tile: Tile with which VMA bound is associated to
> + *
> + * Note, access counters are not used unless enabled in LRC.
> + */
> +bool xe_vma_supports_access_ctr(struct xe_device *xe,
> +                               struct xe_vma *vma,
> +                               struct xe_tile *tile)
> +{
> +       struct xe_bo *bo = xe_vma_bo(vma);
> +       struct ttm_resource *res;
> +
> +       if (!IS_DGFX(xe))
> +               return false;
> +
> +       if (xe_vma_is_cpu_addr_mirror(vma))
> +               return true;
> +
> +       /* userptr or using null vma*/
> +       if (!bo)

Good to assert the bo lock here...

Thanks,
Stuart

> +               return false;
> +
> +       res = bo->ttm.resource;
> +       /* if for some reason no backing store, nothing to migrate */
> +       if (!res)
> +               return false;
> +
> +       /* cannot migrate if single placement */
> +       if (bo->placement.num_placement <= 1)
> +               return false;
> +
> +       /* cannot migrate to ourself (already in VRAM local to @tile)
> */
> +       if (!tile->mem.vram || res->mem_type == tile->mem.vram-
> >placement)
> +               return false;
> +
> +       return true;
> +}
> +
>  /**
>   * xe_vma_need_vram_for_atomic - Check if VMA needs VRAM migration
> for atomic operations
>   * @xe: Pointer to the Xe device structure
> diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
> index 127cecfcb80b..17844ef0f0b7 100644
> --- a/drivers/gpu/drm/xe/xe_vm.h
> +++ b/drivers/gpu/drm/xe/xe_vm.h
> @@ -178,6 +178,9 @@ struct xe_vma *xe_vm_find_vma_by_addr(struct
> xe_vm *vm, u64 page_addr);
>
>  int xe_vma_need_vram_for_atomic(struct xe_device *xe, struct xe_vma
> *vma, bool is_atomic);
>
> +bool xe_vma_supports_access_ctr(struct xe_device *xe, struct xe_vma
> *vma,
> +                               struct xe_tile *tile);
> +
>  int xe_vm_alloc_madvise_vma(struct xe_vm *vm, uint64_t addr,
> uint64_t size);
>
>  int xe_vm_alloc_cpu_addr_mirror_vma(struct xe_vm *vm, uint64_t addr,
> uint64_t size);