drm/xe/vm: Add helper to check for default VMA memory attributes

Introduce a new helper function `xe_vma_has_default_mem_attrs()` to
determine whether a VMA's memory attributes are set to their default
values. This includes checks for atomic access, PAT index, and preferred
location.

Also, add a new field `default_pat_index` to `struct xe_vma_mem_attr`
to track the initial PAT index set during the first bind. This helps
distinguish between default and user-modified pat index, such as those
changed via madvise.

Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250821173104.3030148-18-himal.prasad.ghimiray@intel.com
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
This commit is contained in:
Himal Prasad Ghimiray 2025-08-21 23:01:01 +05:30
parent 002f817d61
commit 58dc430d89
3 changed files with 32 additions and 0 deletions

View file

@ -2640,6 +2640,29 @@ static int xe_vma_op_commit(struct xe_vm *vm, struct xe_vma_op *op)
return err;
}
/**
* xe_vma_has_default_mem_attrs - Check if a VMA has default memory attributes
* @vma: Pointer to the xe_vma structure to check
*
* This function determines whether the given VMA (Virtual Memory Area)
* has its memory attributes set to their default values. Specifically,
* it checks the following conditions:
*
* - `atomic_access` is `DRM_XE_VMA_ATOMIC_UNDEFINED`
* - `pat_index` is equal to `default_pat_index`
* - `preferred_loc.devmem_fd` is `DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE`
* - `preferred_loc.migration_policy` is `DRM_XE_MIGRATE_ALL_PAGES`
*
* Return: true if all attributes are at their default values, false otherwise.
*/
bool xe_vma_has_default_mem_attrs(struct xe_vma *vma)
{
return (vma->attr.atomic_access == DRM_XE_ATOMIC_UNDEFINED &&
vma->attr.pat_index == vma->attr.default_pat_index &&
vma->attr.preferred_loc.devmem_fd == DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE &&
vma->attr.preferred_loc.migration_policy == DRM_XE_MIGRATE_ALL_PAGES);
}
static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
struct xe_vma_ops *vops)
{
@ -2672,6 +2695,7 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
.migration_policy = DRM_XE_MIGRATE_ALL_PAGES,
},
.atomic_access = DRM_XE_ATOMIC_UNDEFINED,
.default_pat_index = op->map.pat_index,
.pat_index = op->map.pat_index,
};

View file

@ -66,6 +66,8 @@ static inline bool xe_vm_is_closed_or_banned(struct xe_vm *vm)
struct xe_vma *
xe_vm_find_overlapping_vma(struct xe_vm *vm, u64 start, u64 range);
bool xe_vma_has_default_mem_attrs(struct xe_vma *vma);
/**
* xe_vm_has_scratch() - Whether the vm is configured for scratch PTEs
* @vm: The vm

View file

@ -103,8 +103,14 @@ struct xe_vma_mem_attr {
*/
u32 atomic_access;
/**
* @default_pat_index: The pat index for VMA set during first bind by user.
*/
u16 default_pat_index;
/**
* @pat_index: The pat index to use when encoding the PTEs for this vma.
* same as default_pat_index unless overwritten by madvise.
*/
u16 pat_index;
};