* [PATCH v4 0/3] Add vm_bind param check to ensure no overlap with kbo AS carveout
@ 2026-07-04 4:46 Adrián Larumbe
2026-07-04 4:46 ` [PATCH v4 1/3] drm/panthor: Check for sparse binding range overflow Adrián Larumbe
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Adrián Larumbe @ 2026-07-04 4:46 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Heiko Stuebner, Grant Likely
Cc: dri-devel, linux-kernel, Adrián Larumbe, Sashiko
Just a quick check to make sure user-supplied vm_bind regions aren't
clashing with the region reserved for kernel bo's.
I tried to introduce a similar check for panthor_vm_alloc_va(), to throw
back an error when mappings of kernel bo's against specific addresses fall
within the auto_va region. However that is not possible, since there's one
FW region that must be mapped right at CSF_MCU_SHARED_REGION_START. That
is usually not a problem, since drm_mm_insert_node_in_range() will pick
the next one available.
v3 also comes with an early bind range overflow check for sparse mappings.
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
Changes in v4:
- Deleted commit that passes single operation to panthor_vm_prepare_unmap_op_ctx.
- Moved overflow check one step above in the call stack.
- Rearranged the commits in the series.
- Link to v3: https://patch.msgid.link/20260629-vm_bind_checks-v3-0-85e6740f6c2e@collabora.com
Changes in v3:
- Fixed off-by-one error for user va range calculations.
- Added new commit for panthor_vm_prepare_unmap_op_ctx to take a whole operation.
- Added commit with bind range early overflow check.
- Link to v2: https://patch.msgid.link/20260619-vm_bind_checks-v2-0-b51abab35f71@collabora.com
Changes in v2:
- Simplified user VA range with kernel BO range overlap to a single statement.
- Link to v1: https://patch.msgid.link/20260616-vm_bind_checks-v1-0-956198602ae3@collabora.com
To: Boris Brezillon <boris.brezillon@collabora.com>
To: Steven Price <steven.price@arm.com>
To: Liviu Dudau <liviu.dudau@arm.com>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Maxime Ripard <mripard@kernel.org>
To: Thomas Zimmermann <tzimmermann@suse.de>
To: David Airlie <airlied@gmail.com>
To: Simona Vetter <simona@ffwll.ch>
To: Heiko Stuebner <heiko@sntech.de>
To: Grant Likely <grant.likely@linaro.org>
To: Adrián Larumbe <adrian.larumbe@collabora.com>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
---
Adrián Larumbe (3):
drm/panthor: Check for sparse binding range overflow
drm/panthor: Add vm_bind region with kbo range overlap check
drm/panthor: Fix comment to reflect actual struct field name
drivers/gpu/drm/panthor/panthor_mmu.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
---
base-commit: 8fca3d8dbebf8d960dad7b10db3cb4a61139454b
change-id: 20260614-vm_bind_checks-46075ba069a0
Best regards,
--
Adrián Larumbe <adrian.larumbe@collabora.com>
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v4 1/3] drm/panthor: Check for sparse binding range overflow 2026-07-04 4:46 [PATCH v4 0/3] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe @ 2026-07-04 4:46 ` Adrián Larumbe 2026-07-06 10:55 ` Liviu Dudau 2026-07-04 4:46 ` [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe 2026-07-04 4:46 ` [PATCH v4 3/3] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe 2 siblings, 1 reply; 8+ messages in thread From: Adrián Larumbe @ 2026-07-04 4:46 UTC (permalink / raw) To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner, Grant Likely Cc: dri-devel, linux-kernel, Adrián Larumbe, Sashiko This check is being already carried out 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. Reported-by: Sashiko <noreply@sashiko.dev> Closes: https://sashiko.dev/#/message/20260623204220.CDB1B1F000E9%40smtp.kernel.org Fixes: 12cf826bf1dd ("drm/panthor: Support sparse mappings") Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> --- drivers/gpu/drm/panthor/panthor_mmu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c index 31cc57029c12..163231c1703d 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -2975,12 +2975,16 @@ panthor_vm_bind_prepare_op_ctx(struct drm_file *file, { ssize_t vm_pgsz = panthor_vm_page_size(vm); struct drm_gem_object *gem; + u64 end; int ret; /* Aligned on page size. */ if (!IS_ALIGNED(op->va | op->size | op->bo_offset, vm_pgsz)) return -EINVAL; + if (check_add_overflow(op->va, op->size, &end)) + 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)) { -- 2.55.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/3] drm/panthor: Check for sparse binding range overflow 2026-07-04 4:46 ` [PATCH v4 1/3] drm/panthor: Check for sparse binding range overflow Adrián Larumbe @ 2026-07-06 10:55 ` Liviu Dudau 0 siblings, 0 replies; 8+ messages in thread From: Liviu Dudau @ 2026-07-06 10:55 UTC (permalink / raw) To: Adrián Larumbe Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner, Grant Likely, dri-devel, linux-kernel, Sashiko On Sat, Jul 04, 2026 at 05:46:44AM +0100, Adrián Larumbe wrote: > This check is being already carried out 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. > > Reported-by: Sashiko <noreply@sashiko.dev> > Closes: https://sashiko.dev/#/message/20260623204220.CDB1B1F000E9%40smtp.kernel.org > Fixes: 12cf826bf1dd ("drm/panthor: Support sparse mappings") > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Best regards, Liviu > --- > drivers/gpu/drm/panthor/panthor_mmu.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > index 31cc57029c12..163231c1703d 100644 > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > @@ -2975,12 +2975,16 @@ panthor_vm_bind_prepare_op_ctx(struct drm_file *file, > { > ssize_t vm_pgsz = panthor_vm_page_size(vm); > struct drm_gem_object *gem; > + u64 end; > int ret; > > /* Aligned on page size. */ > if (!IS_ALIGNED(op->va | op->size | op->bo_offset, vm_pgsz)) > return -EINVAL; > > + if (check_add_overflow(op->va, op->size, &end)) > + 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)) { > > -- > 2.55.0 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check 2026-07-04 4:46 [PATCH v4 0/3] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe 2026-07-04 4:46 ` [PATCH v4 1/3] drm/panthor: Check for sparse binding range overflow Adrián Larumbe @ 2026-07-04 4:46 ` Adrián Larumbe 2026-07-06 10:57 ` Liviu Dudau 2026-07-06 17:27 ` Adrián Larumbe 2026-07-04 4:46 ` [PATCH v4 3/3] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe 2 siblings, 2 replies; 8+ messages in thread From: Adrián Larumbe @ 2026-07-04 4:46 UTC (permalink / raw) To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner, Grant Likely Cc: dri-devel, linux-kernel, Adrián Larumbe 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@collabora.com> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> --- 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; + 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)) { -- 2.55.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check 2026-07-04 4:46 ` [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe @ 2026-07-06 10:57 ` Liviu Dudau 2026-07-06 17:27 ` Adrián Larumbe 1 sibling, 0 replies; 8+ messages in thread From: Liviu Dudau @ 2026-07-06 10:57 UTC (permalink / raw) To: Adrián Larumbe Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner, Grant Likely, dri-devel, linux-kernel On Sat, Jul 04, 2026 at 05:46:45AM +0100, 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@collabora.com> > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Best regards, Liviu > --- > 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; > + > 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)) { > > -- > 2.55.0 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check 2026-07-04 4:46 ` [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe 2026-07-06 10:57 ` Liviu Dudau @ 2026-07-06 17:27 ` Adrián Larumbe 1 sibling, 0 replies; 8+ messages in thread From: Adrián Larumbe @ 2026-07-06 17:27 UTC (permalink / raw) To: Adrián Larumbe Cc: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner, Grant Likely, dri-devel, linux-kernel On Sat, 04 Jul 2026 05:46:45 +0100, Adrián Larumbe <adrian.larumbe@collabora.com> 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. Just realised this was a placeholder I left before I went looking for the right commit hash for the following tag. Seems that checkpatch.pl wouldn't catch it either. -- Adrián Larumbe <adrian.larumbe@collabora.com> ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 3/3] drm/panthor: Fix comment to reflect actual struct field name 2026-07-04 4:46 [PATCH v4 0/3] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe 2026-07-04 4:46 ` [PATCH v4 1/3] drm/panthor: Check for sparse binding range overflow Adrián Larumbe 2026-07-04 4:46 ` [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe @ 2026-07-04 4:46 ` Adrián Larumbe 2026-07-06 10:58 ` Liviu Dudau 2 siblings, 1 reply; 8+ messages in thread From: Adrián Larumbe @ 2026-07-04 4:46 UTC (permalink / raw) To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner, Grant Likely Cc: dri-devel, linux-kernel, Adrián Larumbe The mismatch would pop up when building the kernel with W=1. Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Steven Price <steven.price@arm.com> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> --- drivers/gpu/drm/panthor/panthor_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c index 662a2c13b467..d09d5641e6c0 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -306,7 +306,7 @@ struct panthor_vm { /** @kernel_auto_va.start: Start of the automatic VA-range for kernel BOs. */ u64 start; - /** @kernel_auto_va.size: Size of the automatic VA-range for kernel BOs. */ + /** @kernel_auto_va.end: End of the automatic VA-range for kernel BOs. */ u64 end; } kernel_auto_va; -- 2.55.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 3/3] drm/panthor: Fix comment to reflect actual struct field name 2026-07-04 4:46 ` [PATCH v4 3/3] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe @ 2026-07-06 10:58 ` Liviu Dudau 0 siblings, 0 replies; 8+ messages in thread From: Liviu Dudau @ 2026-07-06 10:58 UTC (permalink / raw) To: Adrián Larumbe Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner, Grant Likely, dri-devel, linux-kernel On Sat, Jul 04, 2026 at 05:46:46AM +0100, Adrián Larumbe wrote: > The mismatch would pop up when building the kernel with W=1. > > Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > Reviewed-by: Steven Price <steven.price@arm.com> > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Best regards, Liviu > --- > drivers/gpu/drm/panthor/panthor_mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > index 662a2c13b467..d09d5641e6c0 100644 > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > @@ -306,7 +306,7 @@ struct panthor_vm { > /** @kernel_auto_va.start: Start of the automatic VA-range for kernel BOs. */ > u64 start; > > - /** @kernel_auto_va.size: Size of the automatic VA-range for kernel BOs. */ > + /** @kernel_auto_va.end: End of the automatic VA-range for kernel BOs. */ > u64 end; > } kernel_auto_va; > > > -- > 2.55.0 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯ ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-06 17:28 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-04 4:46 [PATCH v4 0/3] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe 2026-07-04 4:46 ` [PATCH v4 1/3] drm/panthor: Check for sparse binding range overflow Adrián Larumbe 2026-07-06 10:55 ` Liviu Dudau 2026-07-04 4:46 ` [PATCH v4 2/3] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe 2026-07-06 10:57 ` Liviu Dudau 2026-07-06 17:27 ` Adrián Larumbe 2026-07-04 4:46 ` [PATCH v4 3/3] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe 2026-07-06 10:58 ` Liviu Dudau
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.