mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 13:14:02 +02:00
drm/panthor: Add vm_bind region with kbo range overlap check
When a VM is created, caller has to specify the range of the address space
carve-out set aside for mapping kernel BO's. That means vm_bind mappings of
UM-exposed BO's should not intersect with that region, but at the moment
we're not checking this.
At first, I thought of giving these values to drm_gpuvm_init() through its
reserve_{offset, range} arguments, but it turns out that is meant for VM
address spans that are not managed through the usual drm_gpuvm split/merge
circuit, so storing the end of the user VA range at VM creation time and
doing a quick check in the vm_bind ioctl path was the simplest workaround.
The new check also makes sure vm_bind range doesn't overflow the size of a
64-bit unsigned integer. That was already being done further down the call
stack inside drm_gpuvm_sm_map -> drm_gpuvm_range_valid, but it's best to
fail early in the driver before GPUVM functions are invoked so that we
won't waste time allocating vm_bind context resources.
Fixes: 12cf826bf1 ("drm/panthor: Support sparse mappings")
Fixes: 647810ec24 ("drm/panthor: Add the MMU/VM logical block")
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Link: https://patch.msgid.link/20260720-vm_bind_checks-v6-1-c2c7dbe93a73@collabora.com
Signed-off-by: Steven Price <steven.price@arm.com>
This commit is contained in:
parent
8321b093fa
commit
985f5e12f3
|
|
@ -310,6 +310,9 @@ struct panthor_vm {
|
|||
u64 end;
|
||||
} kernel_auto_va;
|
||||
|
||||
/** @user_va_range: Upper boundary of VAs VM users can map objects against. */
|
||||
u64 user_va_range;
|
||||
|
||||
/** @as: Address space related fields. */
|
||||
struct {
|
||||
/**
|
||||
|
|
@ -2892,6 +2895,8 @@ panthor_vm_create(struct panthor_device *ptdev, bool for_mcu,
|
|||
va_range = full_va_range;
|
||||
}
|
||||
|
||||
vm->user_va_range = kernel_va_start;
|
||||
|
||||
mutex_init(&vm->mm_lock);
|
||||
drm_mm_init(&vm->mm, kernel_va_start, kernel_va_size);
|
||||
vm->kernel_auto_va.start = auto_kernel_va_start;
|
||||
|
|
@ -2980,6 +2985,10 @@ panthor_vm_bind_prepare_op_ctx(struct drm_file *file,
|
|||
if (!IS_ALIGNED(op->va | op->size | op->bo_offset, vm_pgsz))
|
||||
return -EINVAL;
|
||||
|
||||
/* We don't allow mappings that overlap with kbo's reserved range */
|
||||
if (range_overflows(op->va, op->size, vm->user_va_range))
|
||||
return -EINVAL;
|
||||
|
||||
switch (op->flags & DRM_PANTHOR_VM_BIND_OP_TYPE_MASK) {
|
||||
case DRM_PANTHOR_VM_BIND_OP_TYPE_MAP:
|
||||
if (!(op->flags & DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user