return xe_vm_alloc_vma(vm, &map_req, true);
}
+static bool is_cpu_addr_vma_with_default_attr(struct xe_vma *vma)
+{
+ return vma && xe_vma_is_cpu_addr_mirror(vma) &&
+ !xe_svm_has_mapping(xe_vma_vm(vma), xe_vma_start(vma), xe_vma_end(vma)) &&
+ xe_vma_has_default_mem_attrs(vma);
+}
+
+/**
+ * xe_vm_find_cpu_addr_mirror_vma_range - Extend a VMA range to include adjacent CPU-mirrored VMAs
+ * @vm: VM to search within
+ * @start: Input/output pointer to the starting address of the range
+ * @end: Input/output pointer to the end address of the range
+ *
+ * Given a range defined by @start and @range, this function checks the VMAs
+ * immediately before and after the range. If those neighboring VMAs are
+ * CPU-address-mirrored and have default memory attributes, the function
+ * updates @start and @range to include them. This extended range can then
+ * be used for merging or other operations that require a unified VMA.
+ *
+ * The function does not perform the merge itself; it only computes the
+ * mergeable boundaries.
+ */
+void xe_vm_find_cpu_addr_mirror_vma_range(struct xe_vm *vm, u64 *start, u64 *end)
+{
+ struct xe_vma *prev, *next;
+
+ lockdep_assert_held(&vm->lock);
+
+ if (*start >= SZ_4K) {
+ prev = xe_vm_find_vma_by_addr(vm, *start - SZ_4K);
+ if (is_cpu_addr_vma_with_default_attr(prev))
+ *start = xe_vma_start(prev);
+ }
+
+ if (*end < vm->size) {
+ next = xe_vm_find_vma_by_addr(vm, *end + 1);
+ if (is_cpu_addr_vma_with_default_attr(next))
+ *end = xe_vma_end(next);
+ }
+}
+
/**
* xe_vm_alloc_cpu_addr_mirror_vma - Allocate CPU addr mirror vma
* @vm: Pointer to the xe_vm structure