From: Matthew Brost <matthew.brost@intel.com>
To: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: intel-xe@lists.freedesktop.org,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH 1/4] drm/xe: Add helper to extend CPU-mirrored VMA range for merge
Date: Tue, 23 Sep 2025 19:20:37 -0700 [thread overview]
Message-ID: <aNNVdWyd6aHEv7+E@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <20250922104316.263995-2-himal.prasad.ghimiray@intel.com>
On Mon, Sep 22, 2025 at 04:13:13PM +0530, Himal Prasad Ghimiray wrote:
> 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.
>
> 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 | 37 +++++++++++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_vm.h | 3 +++
> 2 files changed, 40 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 0cacab20ff85..4927f2fd9349 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -4343,6 +4343,43 @@ 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_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);
Otherwise LGTM.
Matt
> + if (*start > 0) {
> + prev = xe_vm_find_vma_by_addr(vm, *start - 1);
> + 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-09-24 2:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-22 10:43 [PATCH 0/4] Improve VMA merging for CPU-address-mirrored mappings Himal Prasad Ghimiray
2025-09-22 10:43 ` [PATCH 1/4] drm/xe: Add helper to extend CPU-mirrored VMA range for merge Himal Prasad Ghimiray
2025-09-24 2:20 ` Matthew Brost [this message]
2025-09-22 10:43 ` [PATCH 2/4] drm/xe: Merge adjacent default-attribute VMAs during garbage collection Himal Prasad Ghimiray
2025-09-22 10:43 ` [PATCH 3/4] drm/xe/svm: Extend MAP range to reduce vma fragmentation Himal Prasad Ghimiray
2025-09-24 2:21 ` Matthew Brost
2025-09-22 10:43 ` [PATCH 4/4] drm/xe/svm: Enable UNMAP for VMA merging operations Himal Prasad Ghimiray
2025-09-22 11:08 ` ✓ CI.KUnit: success for Improve VMA merging for CPU-address-mirrored mappings Patchwork
2025-09-22 12:31 ` Patchwork
2025-09-22 14:22 ` ✗ 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=aNNVdWyd6aHEv7+E@lstrano-desk.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--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