Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+32
+24
drivers/gpu/drm/xe/xe_vm.c
··· 2640 2640 return err; 2641 2641 } 2642 2642 2643 + /** 2644 + * xe_vma_has_default_mem_attrs - Check if a VMA has default memory attributes 2645 + * @vma: Pointer to the xe_vma structure to check 2646 + * 2647 + * This function determines whether the given VMA (Virtual Memory Area) 2648 + * has its memory attributes set to their default values. Specifically, 2649 + * it checks the following conditions: 2650 + * 2651 + * - `atomic_access` is `DRM_XE_VMA_ATOMIC_UNDEFINED` 2652 + * - `pat_index` is equal to `default_pat_index` 2653 + * - `preferred_loc.devmem_fd` is `DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE` 2654 + * - `preferred_loc.migration_policy` is `DRM_XE_MIGRATE_ALL_PAGES` 2655 + * 2656 + * Return: true if all attributes are at their default values, false otherwise. 2657 + */ 2658 + bool xe_vma_has_default_mem_attrs(struct xe_vma *vma) 2659 + { 2660 + return (vma->attr.atomic_access == DRM_XE_ATOMIC_UNDEFINED && 2661 + vma->attr.pat_index == vma->attr.default_pat_index && 2662 + vma->attr.preferred_loc.devmem_fd == DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE && 2663 + vma->attr.preferred_loc.migration_policy == DRM_XE_MIGRATE_ALL_PAGES); 2664 + } 2665 + 2643 2666 static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops, 2644 2667 struct xe_vma_ops *vops) 2645 2668 { ··· 2695 2672 .migration_policy = DRM_XE_MIGRATE_ALL_PAGES, 2696 2673 }, 2697 2674 .atomic_access = DRM_XE_ATOMIC_UNDEFINED, 2675 + .default_pat_index = op->map.pat_index, 2698 2676 .pat_index = op->map.pat_index, 2699 2677 }; 2700 2678
+2
drivers/gpu/drm/xe/xe_vm.h
··· 66 66 struct xe_vma * 67 67 xe_vm_find_overlapping_vma(struct xe_vm *vm, u64 start, u64 range); 68 68 69 + bool xe_vma_has_default_mem_attrs(struct xe_vma *vma); 70 + 69 71 /** 70 72 * xe_vm_has_scratch() - Whether the vm is configured for scratch PTEs 71 73 * @vm: The vm
+6
drivers/gpu/drm/xe/xe_vm_types.h
··· 104 104 u32 atomic_access; 105 105 106 106 /** 107 + * @default_pat_index: The pat index for VMA set during first bind by user. 108 + */ 109 + u16 default_pat_index; 110 + 111 + /** 107 112 * @pat_index: The pat index to use when encoding the PTEs for this vma. 113 + * same as default_pat_index unless overwritten by madvise. 108 114 */ 109 115 u16 pat_index; 110 116 };