From: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Himal Prasad Ghimiray" <himal.prasad.ghimiray@intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: [PATCH v4 1/5] drm/xe: Add helper to extend CPU-mirrored VMA range for merge
Date: Mon, 3 Nov 2025 11:39:53 +0530 [thread overview]
Message-ID: <20251103060957.957760-2-himal.prasad.ghimiray@intel.com> (raw)
In-Reply-To: <20251103060957.957760-1-himal.prasad.ghimiray@intel.com>
Introduce xe_vm_find_cpu_addr_mirror_vma_range(), which computes an
extended range around a given range by including adjacent VMAs that are
CPU-address-mirrored and have default memory attributes. This helper is
useful for determining mergeable range without performing the actual merge.
v2
- Add assert
- Move unmap check to this patch
v3
- Decrease offset to check by SZ_4K to avoid wrong vma return in fast
lookup path
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
---
drivers/gpu/drm/xe/xe_vm.c | 41 ++++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_vm.h | 3 +++
2 files changed, 44 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 00f3520dec38..944eb35bb2b8 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -4363,6 +4363,47 @@ int xe_vm_alloc_madvise_vma(struct xe_vm *vm, uint64_t start, uint64_t range)
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
diff --git a/drivers/gpu/drm/xe/xe_vm.h b/drivers/gpu/drm/xe/xe_vm.h
index ef8a5019574e..361f10b3c453 100644
--- a/drivers/gpu/drm/xe/xe_vm.h
+++ b/drivers/gpu/drm/xe/xe_vm.h
@@ -68,6 +68,9 @@ xe_vm_find_overlapping_vma(struct xe_vm *vm, u64 start, u64 range);
bool xe_vma_has_default_mem_attrs(struct xe_vma *vma);
+void xe_vm_find_cpu_addr_mirror_vma_range(struct xe_vm *vm,
+ u64 *start,
+ u64 *end);
/**
* xe_vm_has_scratch() - Whether the vm is configured for scratch PTEs
* @vm: The vm
--
2.34.1
next prev parent reply other threads:[~2025-11-03 5:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 6:09 [PATCH v4 0/5] Improve VMA merging for CPU-address-mirrored mappings Himal Prasad Ghimiray
2025-11-03 5:53 ` ✓ CI.KUnit: success for Improve VMA merging for CPU-address-mirrored mappings (rev4) Patchwork
2025-11-03 6:09 ` Himal Prasad Ghimiray [this message]
2025-11-22 21:48 ` [PATCH v4 1/5] drm/xe: Add helper to extend CPU-mirrored VMA range for merge Matthew Brost
2025-11-03 6:09 ` [PATCH v4 2/5] drm/xe: Merge adjacent default-attribute VMAs during garbage collection Himal Prasad Ghimiray
2025-11-22 21:55 ` Matthew Brost
2025-11-03 6:09 ` [PATCH v4 3/5] drm/xe/svm: Extend MAP range to reduce vma fragmentation Himal Prasad Ghimiray
2025-11-03 6:09 ` [PATCH v4 4/5] drm/xe/svm: Enable UNMAP for VMA merging operations Himal Prasad Ghimiray
2025-11-22 22:01 ` Matthew Brost
2025-11-24 6:01 ` Ghimiray, Himal Prasad
2025-11-24 16:58 ` Matthew Brost
2025-11-03 6:09 ` [PATCH v4 5/5] drm/xe/vm: Skip ufence association for CPU address mirror VMA during MAP Himal Prasad Ghimiray
2025-11-22 22:02 ` Matthew Brost
2025-11-03 7:04 ` ✓ Xe.CI.BAT: success for Improve VMA merging for CPU-address-mirrored mappings (rev4) Patchwork
2025-11-03 8:20 ` ✗ Xe.CI.Full: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251103060957.957760-2-himal.prasad.ghimiray@intel.com \
--to=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox