Re: [PATCH v6 11/12] drm/xe/madvise: Enable purgeable buffer object IOCTL support

Thomas Hellström
2026-03-10T10:23:52Z

On Tue, 2026-03-03 at 20:50 +0530, Arvind Yadav wrote:
> Hook the madvise_purgeable() handler into the madvise IOCTL now that
> all
> supporting infrastructure is complete:
>
>  - Core purge implementation (patch 3)
>  - BO state tracking and helpers (patches 1-2)
>  - Per-VMA purgeable state tracking (patch 6)
>  - Shrinker integration for memory reclamation (patch 10)
>
> This final patch enables userspace to use the
> DRM_XE_VMA_ATTR_PURGEABLE_STATE
> madvise type to mark buffers as WILLNEED/DONTNEED and receive the
> retained
> status indicating whether buffers were purged.
>
> The feature was kept disabled in earlier patches to maintain
> bisectability
> and ensure all components are in place before exposing to userspace.
>
> Userspace can detect kernel support for purgeable BOs by checking the
> DRM_XE_QUERY_CONFIG_FLAG_HAS_PURGING_SUPPORT flag in the query_config
> response.
>
> v6:
>   - Add DRM_XE_QUERY_CONFIG_FLAG_HAS_PURGING_SUPPORT for userspace
>     feature detection. (Jose)
>
> Suggested-by: Matthew Brost <matthew.brost@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Signed-off-by: Himal Prasad Ghimiray
> <himal.prasad.ghimiray@intel.com>
> Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>

Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

> ---
>  drivers/gpu/drm/xe/xe_query.c      |  2 ++
>  drivers/gpu/drm/xe/xe_vm_madvise.c | 22 +++++-----------------
>  2 files changed, 7 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_query.c
> b/drivers/gpu/drm/xe/xe_query.c
> index 34db266b723f..e535c77405b9 100644
> --- a/drivers/gpu/drm/xe/xe_query.c
> +++ b/drivers/gpu/drm/xe/xe_query.c
> @@ -340,6 +340,8 @@ static int query_config(struct xe_device *xe,
> struct drm_xe_device_query *query)
>   DRM_XE_QUERY_CONFIG_FLAG_HAS_NO_COMPRESSION_
> HINT;
>   config->info[DRM_XE_QUERY_CONFIG_FLAGS] |=
>   DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY;
> + config->info[DRM_XE_QUERY_CONFIG_FLAGS] |=
> + DRM_XE_QUERY_CONFIG_FLAG_HAS_PURGING_SUPPORT
> ;
>   config->info[DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT] =
>   xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K ? SZ_64K
> : SZ_4K;
>   config->info[DRM_XE_QUERY_CONFIG_VA_BITS] = xe-
> >info.va_bits;
> diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.c
> b/drivers/gpu/drm/xe/xe_vm_madvise.c
> index ab83e94980e4..746e9b7b47bb 100644
> --- a/drivers/gpu/drm/xe/xe_vm_madvise.c
> +++ b/drivers/gpu/drm/xe/xe_vm_madvise.c
> @@ -337,18 +337,11 @@ void xe_bo_recompute_purgeable_state(struct
> xe_bo *bo)
>   *
>   * Handles DONTNEED/WILLNEED/PURGED states. Tracks if any BO was
> purged
>   * in details->has_purged_bo for later copy to userspace.
> - *
> - * Note: Marked __maybe_unused until hooked into madvise_funcs[] in
> the
> - * final patch to maintain bisectability. The NULL placeholder in
> the
> - * array ensures proper -EINVAL return for userspace until all
> supporting
> - * infrastructure (shrinker, per-VMA tracking) is complete.
>   */
> -static void __maybe_unused madvise_purgeable(struct xe_device *xe,
> -      struct xe_vm *vm,
> -      struct xe_vma **vmas,
> -      int num_vmas,
> -      struct drm_xe_madvise
> *op,
> -      struct
> xe_madvise_details *details)
> +static void madvise_purgeable(struct xe_device *xe, struct xe_vm
> *vm,
> +       struct xe_vma **vmas, int num_vmas,
> +       struct drm_xe_madvise *op,
> +       struct xe_madvise_details *details)
>  {
>   int i;
>
> @@ -412,12 +405,7 @@ static const madvise_func madvise_funcs[] = {
>   [DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC] =
> madvise_preferred_mem_loc,
>   [DRM_XE_MEM_RANGE_ATTR_ATOMIC] = madvise_atomic,
>   [DRM_XE_MEM_RANGE_ATTR_PAT] = madvise_pat_index,
> - /*
> - * Purgeable support implemented but not enabled yet to
> maintain
> - * bisectability. Will be set to madvise_purgeable() in
> final patch
> - * when all infrastructure (shrinker, VMA tracking) is
> complete.
> - */
> - [DRM_XE_VMA_ATTR_PURGEABLE_STATE] = NULL,
> + [DRM_XE_VMA_ATTR_PURGEABLE_STATE] = madvise_purgeable,
>  };
>
>  static u8 xe_zap_ptes_in_madvise_range(struct xe_vm *vm, u64 start,
> u64 end)