mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Add vm_bind param check to ensure no overlap with kbo AS carveout
@ 2026-06-19 12:41 Adrián Larumbe
  2026-06-19 12:41 ` [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
  2026-06-19 12:41 ` [PATCH v2 2/2] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe
  0 siblings, 2 replies; 10+ messages in thread
From: Adrián Larumbe @ 2026-06-19 12:41 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: dri-devel, linux-kernel, Adrián Larumbe

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.

Signed-off-by: Adrián Larumbe <adrian.larumbe@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>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org

---
Adrián Larumbe (2):
      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 | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
---
base-commit: 2afdfc658f7a7e9ee2a67ec6663922da9c799c53
change-id: 20260614-vm_bind_checks-46075ba069a0

Best regards,
--  
Adrián Larumbe <adrian.larumbe@collabora.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check
  2026-06-19 12:41 [PATCH v2 0/2] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe
@ 2026-06-19 12:41 ` Adrián Larumbe
  2026-06-19 12:58   ` Boris Brezillon
                     ` (3 more replies)
  2026-06-19 12:41 ` [PATCH v2 2/2] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe
  1 sibling, 4 replies; 10+ messages in thread
From: Adrián Larumbe @ 2026-06-19 12:41 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  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.

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 31cc57029c12..a8de4fe6b231 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_end: Last VA in the address range VM users can map objects against. */
+	u64 user_va_end;
+
 	/** @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_end = kernel_va_start - 1;
+
 	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;
@@ -2981,6 +2986,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 (op->va + op->size > vm->user_va_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.54.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] drm/panthor: Fix comment to reflect actual struct field name
  2026-06-19 12:41 [PATCH v2 0/2] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe
  2026-06-19 12:41 ` [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
@ 2026-06-19 12:41 ` Adrián Larumbe
  2026-06-24 14:49   ` Steven Price
  1 sibling, 1 reply; 10+ messages in thread
From: Adrián Larumbe @ 2026-06-19 12:41 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  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>
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 a8de4fe6b231..d8c6d8a9e26e 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.54.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check
  2026-06-19 12:41 ` [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
@ 2026-06-19 12:58   ` Boris Brezillon
  2026-06-19 12:59   ` Boris Brezillon
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2026-06-19 12:58 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
	linux-kernel

On Fri, 19 Jun 2026 13:41:22 +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.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>

Reviewed-by: Boris Brezillon <boris.brezillon@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 31cc57029c12..a8de4fe6b231 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_end: Last VA in the address range VM users can map objects against. */
> +	u64 user_va_end;
> +
>  	/** @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_end = kernel_va_start - 1;
> +
>  	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;
> @@ -2981,6 +2986,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 (op->va + op->size > vm->user_va_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)) {
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check
  2026-06-19 12:41 ` [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
  2026-06-19 12:58   ` Boris Brezillon
@ 2026-06-19 12:59   ` Boris Brezillon
  2026-06-19 16:47     ` Adrián Larumbe
  2026-06-24 14:49   ` Steven Price
  2026-06-24 17:35   ` Adrián Larumbe
  3 siblings, 1 reply; 10+ messages in thread
From: Boris Brezillon @ 2026-06-19 12:59 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
	linux-kernel

On Fri, 19 Jun 2026 13:41:22 +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.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>

Ah, we need a Fixes tag here.

> ---
>  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 31cc57029c12..a8de4fe6b231 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_end: Last VA in the address range VM users can map objects against. */
> +	u64 user_va_end;
> +
>  	/** @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_end = kernel_va_start - 1;
> +
>  	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;
> @@ -2981,6 +2986,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 (op->va + op->size > vm->user_va_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)) {
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check
  2026-06-19 12:59   ` Boris Brezillon
@ 2026-06-19 16:47     ` Adrián Larumbe
  0 siblings, 0 replies; 10+ messages in thread
From: Adrián Larumbe @ 2026-06-19 16:47 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Adrián Larumbe, Steven Price, Liviu Dudau,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, dri-devel, linux-kernel

On 2026-06-19 14:59:06+02:00, Boris Brezillon wrote:
> On Fri, 19 Jun 2026 13:41:22 +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.
> > 
> > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> 
> Ah, we need a Fixes tag here.

Fixes: 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check
  2026-06-19 12:41 ` [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
  2026-06-19 12:58   ` Boris Brezillon
  2026-06-19 12:59   ` Boris Brezillon
@ 2026-06-24 14:49   ` Steven Price
  2026-06-24 15:14     ` Adrián Larumbe
  2026-06-24 17:35   ` Adrián Larumbe
  3 siblings, 1 reply; 10+ messages in thread
From: Steven Price @ 2026-06-24 14:49 UTC (permalink / raw)
  To: Adrián Larumbe, Boris Brezillon, Liviu Dudau,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: dri-devel, linux-kernel

On 19/06/2026 13:41, 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.
> 
> 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 31cc57029c12..a8de4fe6b231 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_end: Last VA in the address range VM users can map objects against. */
> +	u64 user_va_end;
> +
>  	/** @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_end = kernel_va_start - 1;
> +
>  	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;
> @@ -2981,6 +2986,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 (op->va + op->size > vm->user_va_end)
> +		return -EINVAL;

Minor issue, but this is off-by-one. If you attempt to map just the last
page then op->va==kernel_va_start - PAGE_SIZE and op->size == PAGE_SIZE.
But this check will reject it.

I suggest removing the "- 1" from user_vm_end, which also means it
matches the user_va_range we pass back to user space (will appropriate
comment/name updates).

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] drm/panthor: Fix comment to reflect actual struct field name
  2026-06-19 12:41 ` [PATCH v2 2/2] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe
@ 2026-06-24 14:49   ` Steven Price
  0 siblings, 0 replies; 10+ messages in thread
From: Steven Price @ 2026-06-24 14:49 UTC (permalink / raw)
  To: Adrián Larumbe, Boris Brezillon, Liviu Dudau,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: dri-devel, linux-kernel

On 19/06/2026 13:41, Adrián Larumbe wrote:
> The mismatch would pop up when building the kernel with W=1.
> 
> 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>

> ---
>  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 a8de4fe6b231..d8c6d8a9e26e 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;
>  
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check
  2026-06-24 14:49   ` Steven Price
@ 2026-06-24 15:14     ` Adrián Larumbe
  0 siblings, 0 replies; 10+ messages in thread
From: Adrián Larumbe @ 2026-06-24 15:14 UTC (permalink / raw)
  To: Steven Price
  Cc: Adrián Larumbe, Boris Brezillon, Liviu Dudau,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, dri-devel, linux-kernel

On 2026-06-24 15:49:32+01:00, Steven Price wrote:
> On 19/06/2026 13:41, 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.
> > 
> > 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 31cc57029c12..a8de4fe6b231 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_end: Last VA in the address range VM users can map objects against. */
> > +	u64 user_va_end;
> > +
> >  	/** @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_end = kernel_va_start - 1;
> > +
> >  	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;
> > @@ -2981,6 +2986,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 (op->va + op->size > vm->user_va_end)
> > +		return -EINVAL;
> 
> Minor issue, but this is off-by-one. If you attempt to map just the last
> page then op->va==kernel_va_start - PAGE_SIZE and op->size == PAGE_SIZE.
> But this check will reject it.
> 
> I suggest removing the "- 1" from user_vm_end, which also means it
> matches the user_va_range we pass back to user space (will appropriate
> comment/name updates).

On top of that, we need an overflow check on (op->va + op->size) for sparse
mappings. At the moment panthor_vm_prepare_map_op_ctx() does bound checks
for normal bindings, but since sparse mappings aren't bounded other than the
user/lernel VA space split, we'll need a fix for that to. I'll add another
Fixes: tag and reference the relevant sparse binding support commit.

> Thanks,
> Steve

Cheers,
Adrian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check
  2026-06-19 12:41 ` [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
                     ` (2 preceding siblings ...)
  2026-06-24 14:49   ` Steven Price
@ 2026-06-24 17:35   ` Adrián Larumbe
  3 siblings, 0 replies; 10+ messages in thread
From: Adrián Larumbe @ 2026-06-24 17:35 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	dri-devel, linux-kernel

On Fri, 19 Jun 2026 13:41:22 +0100, Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 31cc57029c12..a8de4fe6b231 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -2981,6 +2986,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 (op->va + op->size > vm->user_va_end)
> +		return -EINVAL;

I wrote an overflow check as follows, in panthor_vm_prepare_map_op_ctx():

/* Protect against sparse VA range overflow */
if (is_sparse && check_add_overflow(op->va, op->size, &end))
	return -EINVAL;

However, despite Shashiko's warning, it seems there's no need for this, because drm_gpuvm
core code is already performing this kind of check inside __drm_gpuvm_sm_map():

__drm_gpuvm_sm_map -> drm_gpuvm_range_valid -> drm_gpuvm_check_overflow

So even though we wouldn't catch the overflow when we test that the bind range falls within
the user_va boundary, it will be caught later at map time, and maybe that's enough?

-- 
Adrián Larumbe <adrian.larumbe@collabora.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-06-24 17:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-19 12:41 [PATCH v2 0/2] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe
2026-06-19 12:41 ` [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
2026-06-19 12:58   ` Boris Brezillon
2026-06-19 12:59   ` Boris Brezillon
2026-06-19 16:47     ` Adrián Larumbe
2026-06-24 14:49   ` Steven Price
2026-06-24 15:14     ` Adrián Larumbe
2026-06-24 17:35   ` Adrián Larumbe
2026-06-19 12:41 ` [PATCH v2 2/2] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe
2026-06-24 14:49   ` Steven Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox