intel: Add support for madvise purgeable VMAs in Xe KMD

Initially this uAPI was part of the first public version of Xe KMD uAPI but as
it did not had any users it was removed in some of fixes releases of the
Linux version that added Xe KMD but I missed to update the comment in Mesa.

At that time this uAPI had a restriction that did not allowed us to use, it
was compatible with VMs created with DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE but now
this flag is supported so here implementing it.

Link: https://patchwork.freedesktop.org/series/156651/
Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40573>
This commit is contained in:
José Roberto de Souza 2026-03-03 13:06:30 -08:00 committed by Marge Bot
parent b2293977e4
commit cbc1ec206d
4 changed files with 30 additions and 6 deletions

View file

@ -31,6 +31,7 @@
#include "iris/iris_bufmgr.h"
#include "iris/iris_batch.h"
#include "iris/iris_context.h"
#include "util/u_debug.h"
#include "drm-uapi/xe_drm.h"
@ -202,12 +203,31 @@ xe_gem_vm_unbind(struct iris_bo *bo)
static bool
xe_bo_madvise(struct iris_bo *bo, enum iris_madvice state)
{
/* Only applicable if VM was created with DRM_XE_VM_CREATE_FAULT_MODE but
* that is not compatible with DRM_XE_VM_CREATE_SCRATCH_PAGE
*
* So returning as retained.
*/
return true;
struct iris_bufmgr *bufmgr = bo->bufmgr;
const struct intel_device_info *devinfo = iris_bufmgr_get_device_info(bufmgr);
struct drm_xe_madvise madvise = {};
uint32_t retained_val = 0;
/* If not supported bo are always retained */
if (!devinfo->has_madvise_purgeable)
return true;
madvise.start = bo->address;
madvise.range = bo->size;
madvise.vm_id = iris_bufmgr_get_global_vm_id(bufmgr);
madvise.type = DRM_XE_VMA_ATTR_PURGEABLE_STATE;
/* Same values between iris_madvice and Xe KMD */
STATIC_ASSERT(IRIS_MADVICE_WILL_NEED == DRM_XE_VMA_PURGEABLE_STATE_WILLNEED);
STATIC_ASSERT(IRIS_MADVICE_DONT_NEED == DRM_XE_VMA_PURGEABLE_STATE_DONTNEED);
madvise.purge_state_val.val = state;
madvise.purge_state_val.retained_ptr = (uintptr_t)&retained_val;
if (intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_XE_MADVISE, &madvise)) {
debug_warn_once("DRM_XE_VMA_ATTR_PURGEABLE_STATE failed at least once\n");
return false;
}
return retained_val;
}
static int

View file

@ -615,6 +615,7 @@ bool intel_device_info_i915_get_info_from_fd(int fd, struct intel_device_info *d
get_context_param(fd, 0, I915_CONTEXT_PARAM_GTT_SIZE, &devinfo->gtt_size);
devinfo->has_tiling_uapi = has_get_tiling(fd);
devinfo->has_userptr_uapi = has_userptr(fd);
devinfo->has_madvise_purgeable = true;
devinfo->has_caching_uapi =
devinfo->platform < INTEL_PLATFORM_DG2_START && !devinfo->has_local_mem;
if (devinfo->ver > 12 || intel_device_info_is_mtl_or_arl(devinfo))

View file

@ -310,6 +310,7 @@ Struct("intel_device_info",
Member("bool", "supports_low_latency_hint"),
Member("bool", "xe2_has_no_compression_hint"),
Member("bool", "xe_has_state_cache_perf_fix"),
Member("bool", "has_madvise_purgeable"),
Member("bool", "has_userptr_uapi"),
Member("bool", "has_coarse_pixel_primitive_and_cb", compiler_field=True,

View file

@ -79,6 +79,8 @@ xe_query_config(int fd, struct intel_device_info *devinfo)
devinfo->xe2_has_no_compression_hint = true;
if (config->info[DRM_XE_QUERY_CONFIG_FLAGS] & DRM_XE_QUERY_CONFIG_FLAG_HAS_DISABLE_STATE_CACHE_PERF_FIX)
devinfo->xe_has_state_cache_perf_fix = true;
if (config->info[DRM_XE_QUERY_CONFIG_FLAGS] & DRM_XE_QUERY_CONFIG_FLAG_HAS_PURGING_SUPPORT)
devinfo->has_madvise_purgeable = true;
if (!has_gmd_ip_version(devinfo))
devinfo->revision = (config->info[DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID] >> 16) & 0xFFFF;