Skip to contentSkip to conversation

drm/panthor: Fix handling of NO_MMAP BOs

PATCH Superseded Akash Goel 3 participants 4 messages Sep 22 – Oct 12

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Akash Goel

author
#0 lore raw

PATCH 1/1 drm/panthor: Fix handling of NO_MMAP BOs

The BOs created with DRM_PANTHOR_BO_NO_MMAP flag are not supposed to be mmappable by the Userspace. But after the rework to support shrinker, it became possible to mmap NO_MMAP BOs. Userspace could second guess the file offset range, allocated unconditionally at the BO creation time, and create a CPU mapping. There may not be any adverse effect of such a CPU mapping though.
This commit removes the unconditional allocation of file offset range when a user/kernel BO is created. For user BOs, allocation of file offset range would be done from BO_MMAP_OFFSET ioctl handler which has a check for NO_MMAP flag. For kernel BOs, there is no need to allocate file offset range.

Fixes 68cbf96b1e9b ("drm/panthor: Part ways with drm_gem_shmem_object")
---
 drivers/gpu/drm/panthor/panthor_gem.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/gpu/drm/panthor/panthor_gem.c +0 -4
index c07a44057e42..5cfe66537e87 100644
@@ -1021,10 +1021,6 @@ panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
 	mapping_set_gfp_mask(bo->base.filp->f_mapping,
 			     GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
 
-	ret = drm_gem_create_mmap_offset(&bo->base);
-	if (ret)
-		goto err_put;
-
 	if (exclusive_vm) {
 		bo->exclusive_vm_root_gem = panthor_vm_root_gem(exclusive_vm);
 		drm_gem_object_get(bo->exclusive_vm_root_gem);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · On Tue, 22 Sep 2026 11:07:43 +0100 Akash Goel <[email protected]> wrote:

The BOs created with DRM_PANTHOR_BO_NO_MMAP flag are not supposed to be mmappable by the Userspace. But after the rework to support shrinker, it became possible to mmap NO_MMAP BOs. Userspace could second guess the file offset range, allocated unconditionally at the BO creation time, and create a CPU mapping. There may not be any adverse effect of such a CPU mapping though.
This commit removes the unconditional allocation of file offset range when a user/kernel BO is created. For user BOs, allocation of file offset range would be done from BO_MMAP_OFFSET ioctl handler which has a check for NO_MMAP flag. For kernel BOs, there is no need to allocate file offset range.

Quoted 3 lines
Fixes 68cbf96b1e9b ("drm/panthor: Part ways with drm_gem_shmem_object")
Quoted 19 lines
---
 drivers/gpu/drm/panthor/panthor_gem.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/gpu/drm/panthor/panthor_gem.c +0 -4
index c07a44057e42..5cfe66537e87 100644
@@ -1021,10 +1021,6 @@ panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
 	mapping_set_gfp_mask(bo->base.filp->f_mapping,
 			     GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
 
-	ret = drm_gem_create_mmap_offset(&bo->base);
-	if (ret)
-		goto err_put;
-
 	if (exclusive_vm) {
 		bo->exclusive_vm_root_gem = panthor_vm_root_gem(exclusive_vm);
 		drm_gem_object_get(bo->exclusive_vm_root_gem);
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Akash Goel
Quoted 12 lines · Akash Goel

The BOs created with DRM_PANTHOR_BO_NO_MMAP flag are not supposed to be mmappable by the Userspace. But after the rework to support shrinker, it became possible to mmap NO_MMAP BOs. Userspace could second guess the file offset range, allocated unconditionally at the BO creation time, and create a CPU mapping. There may not be any adverse effect of such a CPU mapping though.
This commit removes the unconditional allocation of file offset range when a user/kernel BO is created. For user BOs, allocation of file offset range would be done from BO_MMAP_OFFSET ioctl handler which has a check for NO_MMAP flag. For kernel BOs, there is no need to allocate file offset range.

Quoted 3 lines
Fixes 68cbf96b1e9b ("drm/panthor: Part ways with drm_gem_shmem_object")

Best regards,
Liviu

Quoted 22 lines
---
 drivers/gpu/drm/panthor/panthor_gem.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/gpu/drm/panthor/panthor_gem.c +0 -4
index c07a44057e42..5cfe66537e87 100644
@@ -1021,10 +1021,6 @@ panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
 	mapping_set_gfp_mask(bo->base.filp->f_mapping,
 			     GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
 
-	ret = drm_gem_create_mmap_offset(&bo->base);
-	if (ret)
-		goto err_put;
-
 	if (exclusive_vm) {
 		bo->exclusive_vm_root_gem = panthor_vm_root_gem(exclusive_vm);
 		drm_gem_object_get(bo->exclusive_vm_root_gem);
Signature · 1 line
2.25.1
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
maintainer
#3 lore raw
In reply to Akash Goel
Quoted 12 lines · On Tue, 22 Sep 2026 11:07:43 +0100 Akash Goel <[email protected]> wrote:

The BOs created with DRM_PANTHOR_BO_NO_MMAP flag are not supposed to be mmappable by the Userspace. But after the rework to support shrinker, it became possible to mmap NO_MMAP BOs. Userspace could second guess the file offset range, allocated unconditionally at the BO creation time, and create a CPU mapping. There may not be any adverse effect of such a CPU mapping though.
This commit removes the unconditional allocation of file offset range when a user/kernel BO is created. For user BOs, allocation of file offset range would be done from BO_MMAP_OFFSET ioctl handler which has a check for NO_MMAP flag. For kernel BOs, there is no need to allocate file offset range.

Quoted 3 lines
Fixes 68cbf96b1e9b ("drm/panthor: Part ways with drm_gem_shmem_object")

Just a heads-up in case someone was considering merging this patch:
we've just realized this breaks mmap() on exported BOs that didn't have a ioctl(BO_MMAP_OFFSET) on them.

Quoted 19 lines
---
 drivers/gpu/drm/panthor/panthor_gem.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/gpu/drm/panthor/panthor_gem.c +0 -4
index c07a44057e42..5cfe66537e87 100644
@@ -1021,10 +1021,6 @@ panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
 	mapping_set_gfp_mask(bo->base.filp->f_mapping,
 			     GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
 
-	ret = drm_gem_create_mmap_offset(&bo->base);
-	if (ret)
-		goto err_put;
-
 	if (exclusive_vm) {
 		bo->exclusive_vm_root_gem = panthor_vm_root_gem(exclusive_vm);
 		drm_gem_object_get(bo->exclusive_vm_root_gem);