]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/xe/vm: Add helper to check for default VMA memory attributes
authorHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Thu, 21 Aug 2025 17:31:01 +0000 (23:01 +0530)
committerHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Tue, 26 Aug 2025 05:55:36 +0000 (11:25 +0530)
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>
drivers/gpu/drm/xe/xe_vm.c
drivers/gpu/drm/xe/xe_vm.h
drivers/gpu/drm/xe/xe_vm_types.h

index 6574ae56a7306d25abaa47d92d66d722c443118f..e9615d5ef944409ebae1f143a92802ee29329036 100644 (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,
                        };
 
index dbb1bf3caf2deeaf85499a3ea0225ff429b738c6..1a4d67f29c6b7c8dc89cab86c2502c98561b6cca 100644 (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
index 35b6344158f5cfac5dd31422b60862f6ee8218fb..b5108d010786108495ce3091952be79d40378c31 100644 (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;
 };