Skip to contentSkip to conversation

Add vm_bind param check to ensure no overlap with kbo AS carveout

PATCH Superseded Adrián Larumbe 4 participants 12 messages Jun 19 – Jun 24

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add vm_bind param check to ensure no overlap with kbo AS carveout

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.

---
Changes in v2:
- Simplified user VA range with kernel BO range overlap to a single statement.
- Link to v1: https://patch.msgid.link/[email protected]

To: Boris Brezillon <[email protected]>
To: Steven Price <[email protected]>
To: Liviu Dudau <[email protected]>
To: Maarten Lankhorst <[email protected]>
To: Maxime Ripard <[email protected]>
To: Thomas Zimmermann <[email protected]>
To: David Airlie <[email protected]>
To: Simona Vetter <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
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,

Signature · 1 line
Adrián Larumbe <[email protected]>
#1 lore raw

PATCH v2 1/2 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.

---
 drivers/gpu/drm/panthor/panthor_mmu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +9 -0
index 31cc57029c12..a8de4fe6b231 100644
@@ -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)) {
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 1/2
#2 lore raw

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

Quoted 5 lines · On Fri, 19 Jun 2026 13:41:22 +0100 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.

Quoted 7 lines

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.

Quoted 39 lines
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +9 -0
index 31cc57029c12..a8de4fe6b231 100644
@@ -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)) {
maintainer
#3 lore raw

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

In reply to Adrián Larumbe
Quoted 5 lines · On Fri, 19 Jun 2026 13:41:22 +0100 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.

Quoted 7 lines

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.

Ah, we need a Fixes tag here.

Quoted 39 lines
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +9 -0
index 31cc57029c12..a8de4fe6b231 100644
@@ -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)) {
#4 lore raw

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

Quoted 14 lines · Boris Brezillon
Quoted 11 lines · On Fri, 19 Jun 2026 13:41:22 +0100 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.

Quoted 3 lines
Quoted 1 line

Ah, we need a Fixes tag here.

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

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

In reply to Adrián Larumbe
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The overlap check incorrectly rejects valid user VA mappings that end exactly at the upper boundary of the user VA space, effectively reducing the usable user VA space by one page.

Pre-existing issues:
- [High] The bounds check for the kernel-reserved VA range lacks integer overflow protection, allowing an attacker to bypass it and trigger undefined behavior and hardware register corruption. --

commit 544d7f2ab2018dcefc4327336a2da6f6a37e4d4f
Author: Adrián Larumbe <[email protected]>

drm/panthor: Add vm_bind region with kbo range overlap check

This patch adds a check to ensure that user VM mappings do not overlap with the kernel BO address space carve-out. It sets a boundary for the user VA range at VM creation and enforces it during the vm_bind ioctl.

Quoted 4 lines
drivers/gpu/drm/panthor/panthor_mmu.c +0 -0
index 31cc57029c12c..a8de4fe6b231b 100644

[ ... ]

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_mmu.c +2 -0
@@ -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);

[ ... ]

drivers/gpu/drm/panthor/panthor_mmu.c panthor_vm_bind_prepare_op_ctx(struct drm_file *file, · line 2991

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_mmu.c +3 -0
@@ -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;

[Severity: Medium]
Since op->va + op->size represents the exclusive end of the mapping, and vm->user_va_end is the inclusive upper bound (kernel_va_start - 1), does this reject valid mappings that end exactly at the boundary?

If a mapping ends exactly at kernel_va_start, op->va + op->size will be equal to kernel_va_start. The condition kernel_va_start > kernel_va_start - 1 will evaluate to true and return -EINVAL, effectively reducing the usable user VA space by one page.

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for this bounds check to be bypassed due to integer overflow?

If an unprivileged user calls the vm_bind ioctl with a sparse mapping and parameters that overflow when added (for example, va = 0x200000 and size = 0xffffffffffe00000), the wrapped va + size evaluates to 0. This successfully bypasses the new check.

Later in the execution path, this bypass triggers undefined behavior when pack_region_range() calculates region_end = start + size, which wraps to 0. This makes region_end - 1 equal to -1 (0xffffffffffffffff). The call to fls64(*region_start ^ (region_end - 1)) then evaluates to 64, leading to region_width = 63 and a shift by 64 (1ull << 64), which is undefined behavior in C and corrupts the lockaddr hardware register.

Quoted 4 lines
drivers/gpu/drm/panthor/panthor_mmu.c +1 -0
+
 	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)) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#6 lore raw

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

Quoted 48 lines · On 2026-06-23 20:42:20+00:00, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The overlap check incorrectly rejects valid user VA mappings that end exactly at the upper boundary of the user VA space, effectively reducing the usable user VA space by one page.

Pre-existing issues:
- [High] The bounds check for the kernel-reserved VA range lacks integer overflow protection, allowing an attacker to bypass it and trigger undefined behavior and hardware register corruption. --

commit 544d7f2ab2018dcefc4327336a2da6f6a37e4d4f
Author: Adrián Larumbe <[email protected]>

drm/panthor: Add vm_bind region with kbo range overlap check

This patch adds a check to ensure that user VM mappings do not overlap with the kernel BO address space carve-out. It sets a boundary for the user VA range at VM creation and enforces it during the vm_bind ioctl.

Quoted 4 lines
drivers/gpu/drm/panthor/panthor_mmu.c +0 -0
index 31cc57029c12c..a8de4fe6b231b 100644

[ ... ]

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_mmu.c +2 -0
@@ -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);

[ ... ]

drivers/gpu/drm/panthor/panthor_mmu.c panthor_vm_bind_prepare_op_ctx(struct drm_file *file, · line 2991

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_mmu.c +3 -0
@@ -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;

[Severity: Medium]
Since op->va + op->size represents the exclusive end of the mapping, and vm->user_va_end is the inclusive upper bound (kernel_va_start - 1), does this reject valid mappings that end exactly at the boundary?

Quoted 4 lines

If a mapping ends exactly at kernel_va_start, op->va + op->size will be equal to kernel_va_start. The condition kernel_va_start > kernel_va_start - 1 will evaluate to true and return -EINVAL, effectively reducing the usable user VA space by one page.

Looks like a boundary condition, I guess testing like

	if (op->va + op->size - 1> vm->user_va_end)
		return -EINVAL;

should be enough.

Quoted 9 lines

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for this bounds check to be bypassed due to integer overflow?

If an unprivileged user calls the vm_bind ioctl with a sparse mapping and parameters that overflow when added (for example, va = 0x200000 and size = 0xffffffffffe00000), the wrapped va + size evaluates to 0. This successfully bypasses the new check.

Quoted 6 lines

Later in the execution path, this bypass triggers undefined behavior when pack_region_range() calculates region_end = start + size, which wraps to 0. This makes region_end - 1 equal to -1 (0xffffffffffffffff). The call to fls64(*region_start ^ (region_end - 1)) then evaluates to 64, leading to region_width = 63 and a shift by 64 (1ull << 64), which is undefined behavior in C and corrupts the lockaddr hardware register.

I don't think this is relevant as an existing issue because panthor_vm_prepare_map_op_ctx() will clamp the size to bo->base.size. However, we must still check for overflow in the sparse binding case.

maintainer
#7 lore raw

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

In reply to Adrián Larumbe
Quoted 40 lines · 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.

---
 drivers/gpu/drm/panthor/panthor_mmu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +5 -0
index 31cc57029c12..a8de4fe6b231 100644
@@ -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;

drivers/gpu/drm/panthor/panthor_mmu.c panthor_vm_bind_prepare_op_ctx(struct drm_file *file, · line 2991

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +3 -0
@@ -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

Quoted 5 lines
drivers/gpu/drm/panthor/panthor_mmu.c +1 -0
+
 	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)) {
#8 lore raw

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

Quoted 53 lines · Steven Price
Quoted 40 lines · 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.

---
 drivers/gpu/drm/panthor/panthor_mmu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +5 -0
index 31cc57029c12..a8de4fe6b231 100644
@@ -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;

drivers/gpu/drm/panthor/panthor_mmu.c panthor_vm_bind_prepare_op_ctx(struct drm_file *file, · line 2991

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +3 -0
@@ -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.

Quoted 3 lines

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.

Quoted 2 lines

Thanks,
Steve

Cheers,
Adrian

#9 lore raw

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

In reply to Adrián Larumbe

drivers/gpu/drm/panthor/panthor_mmu.c panthor_vm_bind_prepare_op_ctx(struct drm_file *file, · line 2991

Quoted 11 lines · Adrián Larumbe
drivers/gpu/drm/panthor/panthor_mmu.c +3 -0
index 31cc57029c12..a8de4fe6b231 100644
@@ -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?

Signature · 1 line
Adrián Larumbe <[email protected]>
#10 lore raw

PATCH v2 2/2 drm/panthor: Fix comment to reflect actual struct field name

In reply to Adrián Larumbe

The mismatch would pop up when building the kernel with W=1.

---
 drivers/gpu/drm/panthor/panthor_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_mmu.c +1 -1
index a8de4fe6b231..d8c6d8a9e26e 100644
@@ -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;
 
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 2/2
#11 lore raw

Re: [PATCH v2 2/2] drm/panthor: Fix comment to reflect actual struct field name

Quoted 4 lines · Adrián Larumbe

The mismatch would pop up when building the kernel with W=1.

Quoted 18 lines
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_mmu.c +1 -1
index a8de4fe6b231..d8c6d8a9e26e 100644
@@ -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;