Re: [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check

From: Steven Price

Date: Thu Jul 09 2026 - 04:27:04 EST


On 04/07/2026 05:46, Adrián Larumbe wrote:
> 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.
>
> Fixes: tag and reference the relevant sparse binding support commit.
> Fixes: 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
> Reviewed-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>
> Signed-off-by: Adrián Larumbe <adrian.larumbe@xxxxxxxxxxxxx>
> ---
> drivers/gpu/drm/panthor/panthor_mmu.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 163231c1703d..662a2c13b467 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -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 {
> /**
> @@ -2893,6 +2896,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;
> @@ -2985,6 +2990,10 @@ panthor_vm_bind_prepare_op_ctx(struct drm_file *file,
> if (check_add_overflow(op->va, op->size, &end))
> return -EINVAL;
>
> + /* We don't allow mappings that overlap with kbo's reserved range */
> + if (end > vm->user_va_range)
> + return -EINVAL;
> +

Squashing this with the previous patch we can do this in one check:

if (range_overflows(op->va, op->size, vm->user_va_range))
return -EINVAL;

Thanks,
Steve

> 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)) {
>