Skip to content

Commit f0e4238

Browse files
committed
drm/xe: Do not allow CPU address mirror VMA unbind if
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) v5: - Kernel doc (Thomas) v6: - Only compile if CONFIG_DRM_GPUSVM selected (CI, Lucas) Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Himal Prasad Ghimiray <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent d1e6efd commit f0e4238

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

drivers/gpu/drm/xe/xe_svm.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,18 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
434434

435435
return err;
436436
}
437+
438+
/**
439+
* xe_svm_has_mapping() - SVM has mappings
440+
* @vm: The VM.
441+
* @start: Start address.
442+
* @end: End address.
443+
*
444+
* Check if an address range has SVM mappings.
445+
*
446+
* Return: True if address range has a SVM mapping, False otherwise
447+
*/
448+
bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end)
449+
{
450+
return drm_gpusvm_has_mapping(&vm->svm.gpusvm, start, end);
451+
}

drivers/gpu/drm/xe/xe_svm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ void xe_svm_close(struct xe_vm *vm);
5757
int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
5858
struct xe_tile *tile, u64 fault_addr,
5959
bool atomic);
60+
61+
bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end);
6062
#else
6163
static inline bool xe_svm_range_pages_valid(struct xe_svm_range *range)
6264
{
@@ -86,6 +88,12 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
8688
{
8789
return 0;
8890
}
91+
92+
static inline
93+
bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end)
94+
{
95+
return false;
96+
}
8997
#endif
9098

9199
/**

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,17 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
24862486
struct xe_vma *old =
24872487
gpuva_to_vma(op->base.remap.unmap->va);
24882488
bool skip = xe_vma_is_cpu_addr_mirror(old);
2489+
u64 start = xe_vma_start(old), end = xe_vma_end(old);
2490+
2491+
if (op->base.remap.prev)
2492+
start = op->base.remap.prev->va.addr +
2493+
op->base.remap.prev->va.range;
2494+
if (op->base.remap.next)
2495+
end = op->base.remap.next->va.addr;
2496+
2497+
if (xe_vma_is_cpu_addr_mirror(old) &&
2498+
xe_svm_has_mapping(vm, start, end))
2499+
return -EBUSY;
24892500

24902501
op->remap.start = xe_vma_start(old);
24912502
op->remap.range = xe_vma_size(old);
@@ -2567,6 +2578,11 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct drm_gpuva_ops *ops,
25672578
case DRM_GPUVA_OP_UNMAP:
25682579
vma = gpuva_to_vma(op->base.unmap.va);
25692580

2581+
if (xe_vma_is_cpu_addr_mirror(vma) &&
2582+
xe_svm_has_mapping(vm, xe_vma_start(vma),
2583+
xe_vma_end(vma)))
2584+
return -EBUSY;
2585+
25702586
if (!xe_vma_is_cpu_addr_mirror(vma))
25712587
xe_vma_ops_incr_pt_update_ops(vops, op->tile_mask);
25722588
break;

0 commit comments

Comments
 (0)