]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/svm: Extend MAP range to reduce vma fragmentation
authorHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Tue, 25 Nov 2025 07:56:26 +0000 (13:26 +0530)
committerHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Wed, 26 Nov 2025 10:12:33 +0000 (15:42 +0530)
When DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR is set during VM_BIND_OP_MAP,
the mapping logic now checks adjacent cpu_addr_mirror VMAs with default
attributes and expands the mapping range accordingly. This ensures that
bo_unmap operations ideally target the same area and helps reduce
fragmentation by coalescing nearby compatible VMAs into a single mapping.

Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patch.msgid.link/20251125075628.1182481-4-himal.prasad.ghimiray@intel.com
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
drivers/gpu/drm/xe/xe_vm.c

index fc11a1a6f979fc8f5471e7c2fd97bc7aaf81c67e..2681039f32214e2ee5cb6f96c991fa8d526e8516 100644 (file)
@@ -2233,6 +2233,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_vma_ops *vops,
        struct drm_gpuva_ops *ops;
        struct drm_gpuva_op *__op;
        struct drm_gpuvm_bo *vm_bo;
+       u64 range_start = addr;
        u64 range_end = addr + range;
        int err;
 
@@ -2245,10 +2246,14 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_vma_ops *vops,
 
        switch (operation) {
        case DRM_XE_VM_BIND_OP_MAP:
+               if (flags & DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR)
+                       xe_vm_find_cpu_addr_mirror_vma_range(vm, &range_start, &range_end);
+
+               fallthrough;
        case DRM_XE_VM_BIND_OP_MAP_USERPTR: {
                struct drm_gpuvm_map_req map_req = {
-                       .map.va.addr = addr,
-                       .map.va.range = range,
+                       .map.va.addr = range_start,
+                       .map.va.range = range_end - range_start,
                        .map.gem.obj = obj,
                        .map.gem.offset = bo_offset_or_userptr,
                };