[PATCH v4 17/33] drm/xe: Do not allow CPU address mirror VMA unbind if the GPU has bindings
Thomas Hellström
thomas.hellstrom at linux.intel.com
Fri Feb 7 13:01:12 UTC 2025
On Wed, 2025-01-29 at 11:51 -0800, Matthew Brost wrote:
> uAPI is designed with the use case that only mapping a BO to a
> malloc'd
> address will unbind a CPU-address mirror VMA. Therefore, allowing a
> CPU-address mirror VMA to unbind when the GPU has bindings in the
> range
> being unbound does not make much sense. This behavior is not
> supported,
> as it simplifies the code. This decision can always be revisited if a
> use case arises.
>
> v3:
> - s/arrises/arises (Thomas)
> - s/system allocator/GPU address mirror (Thomas)
> - Kernel doc (Thomas)
> - Newline between function defs (Thomas)
>
> Signed-off-by: Matthew Brost <matthew.brost at intel.com>
> ---
> drivers/gpu/drm/xe/xe_svm.c | 5 +++++
> drivers/gpu/drm/xe/xe_svm.h | 2 ++
> drivers/gpu/drm/xe/xe_vm.c | 16 ++++++++++++++++
> 3 files changed, 23 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_svm.c
> b/drivers/gpu/drm/xe/xe_svm.c
> index 03c5cbcacb0e..56ece53b2069 100644
> --- a/drivers/gpu/drm/xe/xe_svm.c
> +++ b/drivers/gpu/drm/xe/xe_svm.c
> @@ -428,3 +428,8 @@ int xe_svm_handle_pagefault(struct xe_vm *vm,
> struct xe_vma *vma,
>
> return err;
> }
> +
> +bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end)
Kerneldoc?
> +{
> + return drm_gpusvm_has_mapping(&vm->svm.gpusvm, start, end);
> +}
> diff --git a/drivers/gpu/drm/xe/xe_svm.h
> b/drivers/gpu/drm/xe/xe_svm.h
> index ef5bc4e919e8..b181c174ca61 100644
> --- a/drivers/gpu/drm/xe/xe_svm.h
> +++ b/drivers/gpu/drm/xe/xe_svm.h
> @@ -46,6 +46,8 @@ int xe_svm_handle_pagefault(struct xe_vm *vm,
> struct xe_vma *vma,
> struct xe_tile *tile, u64 fault_addr,
> bool atomic);
>
> +bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end);
> +
> static inline bool xe_svm_range_pages_valid(struct xe_svm_range
> *range)
And here.
> {
> return drm_gpusvm_range_pages_valid(range->base.gpusvm,
> &range->base);
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 6fa446884955..d8c78ecd54ec 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -2398,6 +2398,17 @@ static int vm_bind_ioctl_ops_parse(struct
> xe_vm *vm, struct drm_gpuva_ops *ops,
> struct xe_vma *old =
> gpuva_to_vma(op->base.remap.unmap-
> >va);
> bool skip = xe_vma_is_cpu_addr_mirror(old);
> + u64 start = xe_vma_start(old), end =
> xe_vma_end(old);
> +
> + if (op->base.remap.prev)
> + start = op->base.remap.prev->va.addr
> +
> + op->base.remap.prev-
> >va.range;
> + if (op->base.remap.next)
> + end = op->base.remap.next->va.addr;
> +
> + if (xe_vma_is_cpu_addr_mirror(old) &&
> + xe_svm_has_mapping(vm, start, end))
> + return -EBUSY;
>
> op->remap.start = xe_vma_start(old);
> op->remap.range = xe_vma_size(old);
> @@ -2480,6 +2491,11 @@ static int vm_bind_ioctl_ops_parse(struct
> xe_vm *vm, struct drm_gpuva_ops *ops,
> {
> struct xe_vma *vma = gpuva_to_vma(op-
> >base.unmap.va);
>
> + if (xe_vma_is_cpu_addr_mirror(vma) &&
> + xe_svm_has_mapping(vm,
> xe_vma_start(vma),
> + xe_vma_end(vma)))
> + return -EBUSY;
> +
> if (!xe_vma_is_cpu_addr_mirror(vma))
> xe_vma_ops_incr_pt_update_ops(vops,
> op->tile_mask);
> break;
Thanks,
Thomas
More information about the dri-devel
mailing list