Skip to contentSkip to conversation

drm/panthor: Don't create a file offset for NO_MMAP BOs

PATCH Superseded Boris Brezillon 4 participants 6 messages Apr 17, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Boris Brezillon

author maintainer
#0 lore raw

PATCH v2 1/1 drm/panthor: Don't create a file offset for NO_MMAP BOs

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, because panthor_gem_mmap() will filter them out.

If we error out at mmap_offset creation time, we can get rid of panthor_gem_mmap() and call drm_gem_shmem_object_mmap directly, and we get rid of this inconsistency of having an mmap offset for a BO that can never be mmap-ed.

Changes in v2:
- Get rid of panthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL

---
 drivers/gpu/drm/panthor/panthor_drv.c |  5 +++++
 drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------
 2 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 06fe46e32073..7cd131af340d 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EPERM;
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
drivers/gpu/drm/panthor/panthor_gem.c +1 -12
index fd014ccc3bfc..22d78cef9c66 100644
@@ -129,17 +129,6 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
 	return ERR_PTR(ret);
 }
 
-static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
-{
-	struct panthor_gem_object *bo = to_panthor_bo(obj);
-
-	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
-	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
-		return -EINVAL;
-
-	return drm_gem_shmem_object_mmap(obj, vma);
-}
-
 static struct dma_buf *
 panthor_gem_prime_export(struct drm_gem_object *obj, int flags)
 {
@@ -169,7 +158,7 @@ static const struct drm_gem_object_funcs panthor_gem_funcs = {
 	.get_sg_table = drm_gem_shmem_object_get_sg_table,
 	.vmap = drm_gem_shmem_object_vmap,
 	.vunmap = drm_gem_shmem_object_vunmap,
-	.mmap = panthor_gem_mmap,
+	.mmap = drm_gem_shmem_object_mmap,
 	.status = panthor_gem_status,
 	.export = panthor_gem_prime_export,
 	.vm_ops = &drm_gem_shmem_vm_ops,
Signature · 1 line
2.49.0
author maintainer
#1 lore raw
Quoted 10 lines · On Thu, 17 Apr 2025 11:32:47 +0200 Boris Brezillon…

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, because panthor_gem_mmap() will filter them out.

If we error out at mmap_offset creation time, we can get rid of panthor_gem_mmap() and call drm_gem_shmem_object_mmap directly, and we get rid of this inconsistency of having an mmap offset for a BO that can never be mmap-ed.

Quoted 6 lines

Changes in v2:
- Get rid of panthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL

Liviu, Steve, I intentionally dropped your R-bs because this v2 gets rid of panthor_gem_mmap(), and I want a confirmation that you're okay with that.

Quoted 59 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c |  5 +++++
 drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------
 2 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 06fe46e32073..7cd131af340d 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EPERM;
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
drivers/gpu/drm/panthor/panthor_gem.c +1 -12
index fd014ccc3bfc..22d78cef9c66 100644
@@ -129,17 +129,6 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
 	return ERR_PTR(ret);
 }
 
-static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
-{
-	struct panthor_gem_object *bo = to_panthor_bo(obj);
-
-	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
-	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
-		return -EINVAL;
-
-	return drm_gem_shmem_object_mmap(obj, vma);
-}
-
 static struct dma_buf *
 panthor_gem_prime_export(struct drm_gem_object *obj, int flags)
 {
@@ -169,7 +158,7 @@ static const struct drm_gem_object_funcs panthor_gem_funcs = {
 	.get_sg_table = drm_gem_shmem_object_get_sg_table,
 	.vmap = drm_gem_shmem_object_vmap,
 	.vunmap = drm_gem_shmem_object_vunmap,
-	.mmap = panthor_gem_mmap,
+	.mmap = drm_gem_shmem_object_mmap,
 	.status = panthor_gem_status,
 	.export = panthor_gem_prime_export,
 	.vm_ops = &drm_gem_shmem_vm_ops,
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Boris Brezillon
Quoted 10 lines · Boris Brezillon

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, because panthor_gem_mmap() will filter them out.

If we error out at mmap_offset creation time, we can get rid of panthor_gem_mmap() and call drm_gem_shmem_object_mmap directly, and we get rid of this inconsistency of having an mmap offset for a BO that can never be mmap-ed.

Quoted 6 lines

Changes in v2:
- Get rid of panthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL

Quoted 59 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c |  5 +++++
 drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------
 2 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 06fe46e32073..7cd131af340d 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EPERM;
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
drivers/gpu/drm/panthor/panthor_gem.c +1 -12
index fd014ccc3bfc..22d78cef9c66 100644
@@ -129,17 +129,6 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
 	return ERR_PTR(ret);
 }
 
-static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
-{
-	struct panthor_gem_object *bo = to_panthor_bo(obj);
-
-	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
-	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
-		return -EINVAL;
-
-	return drm_gem_shmem_object_mmap(obj, vma);
-}
-
 static struct dma_buf *
 panthor_gem_prime_export(struct drm_gem_object *obj, int flags)
 {
@@ -169,7 +158,7 @@ static const struct drm_gem_object_funcs panthor_gem_funcs = {
 	.get_sg_table = drm_gem_shmem_object_get_sg_table,
 	.vmap = drm_gem_shmem_object_vmap,
 	.vunmap = drm_gem_shmem_object_vunmap,
-	.mmap = panthor_gem_mmap,
+	.mmap = drm_gem_shmem_object_mmap,
 	.status = panthor_gem_status,
 	.export = panthor_gem_prime_export,
 	.vm_ops = &drm_gem_shmem_vm_ops,
#3 lore raw
In reply to Boris Brezillon
Quoted 34 lines · Boris Brezillon

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, because panthor_gem_mmap() will filter them out.

If we error out at mmap_offset creation time, we can get rid of panthor_gem_mmap() and call drm_gem_shmem_object_mmap directly, and we get rid of this inconsistency of having an mmap offset for a BO that can never be mmap-ed.

Changes in v2:
- Get rid of panthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL

---
  drivers/gpu/drm/panthor/panthor_drv.c |  5 +++++
  drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------
  2 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 06fe46e32073..7cd131af340d 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
  					struct drm_file *file)
  {
  	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
  	struct drm_gem_object *obj;
  	int ret;
 

drivers/gpu/drm/panthor/panthor_drv.c static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data, · line 956

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_drv.c +3 -0
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
  	if (!obj)
  		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EPERM;

Just a drive-by-comment: are we not leaking the bo ref here?

Quoted 35 lines
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
+
  	ret = drm_gem_create_mmap_offset(obj);
  	if (ret)
  		goto out;
drivers/gpu/drm/panthor/panthor_gem.c +1 -12
index fd014ccc3bfc..22d78cef9c66 100644
@@ -129,17 +129,6 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
  	return ERR_PTR(ret);
  }
 
-static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
-{
-	struct panthor_gem_object *bo = to_panthor_bo(obj);
-
-	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
-	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
-		return -EINVAL;
-
-	return drm_gem_shmem_object_mmap(obj, vma);
-}
-
  static struct dma_buf *
  panthor_gem_prime_export(struct drm_gem_object *obj, int flags)
  {
@@ -169,7 +158,7 @@ static const struct drm_gem_object_funcs panthor_gem_funcs = {
  	.get_sg_table = drm_gem_shmem_object_get_sg_table,
  	.vmap = drm_gem_shmem_object_vmap,
  	.vunmap = drm_gem_shmem_object_vunmap,
-	.mmap = panthor_gem_mmap,
+	.mmap = drm_gem_shmem_object_mmap,
  	.status = panthor_gem_status,
  	.export = panthor_gem_prime_export,
  	.vm_ops = &drm_gem_shmem_vm_ops,
author maintainer
#4 lore raw
Quoted 38 lines · On Thu, 17 Apr 2025 10:53:23 +0100 Matthew Auld <[email protected]> wrote:
Quoted 37 lines · Boris Brezillon

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, because panthor_gem_mmap() will filter them out.

If we error out at mmap_offset creation time, we can get rid of panthor_gem_mmap() and call drm_gem_shmem_object_mmap directly, and we get rid of this inconsistency of having an mmap offset for a BO that can never be mmap-ed.

Changes in v2:
- Get rid of panthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL

---
  drivers/gpu/drm/panthor/panthor_drv.c |  5 +++++
  drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------
  2 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 06fe46e32073..7cd131af340d 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
  					struct drm_file *file)
  {
  	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
  	struct drm_gem_object *obj;
  	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
  	if (!obj)
  		return -ENOENT;
 
Quoted 5 lines

drivers/gpu/drm/panthor/panthor_drv.c static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data, · line 956

Quoted 3 lines
drivers/gpu/drm/panthor/panthor_drv.c +3 -0
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EPERM;  

Just a drive-by-comment: are we not leaking the bo ref here?

We certainly are, good catch!

Quoted 37 lines
Quoted 36 lines
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
+
  	ret = drm_gem_create_mmap_offset(obj);
  	if (ret)
  		goto out;
drivers/gpu/drm/panthor/panthor_gem.c +1 -12
index fd014ccc3bfc..22d78cef9c66 100644
@@ -129,17 +129,6 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
  	return ERR_PTR(ret);
  }
 
-static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
-{
-	struct panthor_gem_object *bo = to_panthor_bo(obj);
-
-	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
-	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
-		return -EINVAL;
-
-	return drm_gem_shmem_object_mmap(obj, vma);
-}
-
  static struct dma_buf *
  panthor_gem_prime_export(struct drm_gem_object *obj, int flags)
  {
@@ -169,7 +158,7 @@ static const struct drm_gem_object_funcs panthor_gem_funcs = {
  	.get_sg_table = drm_gem_shmem_object_get_sg_table,
  	.vmap = drm_gem_shmem_object_vmap,
  	.vunmap = drm_gem_shmem_object_vunmap,
-	.mmap = panthor_gem_mmap,
+	.mmap = drm_gem_shmem_object_mmap,
  	.status = panthor_gem_status,
  	.export = panthor_gem_prime_export,
  	.vm_ops = &drm_gem_shmem_vm_ops,  
maintainer Reviewed-by on v2 1/1
#5 lore raw
In reply to Boris Brezillon
Quoted 34 lines · Boris Brezillon

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, because panthor_gem_mmap() will filter them out.

If we error out at mmap_offset creation time, we can get rid of panthor_gem_mmap() and call drm_gem_shmem_object_mmap directly, and we get rid of this inconsistency of having an mmap offset for a BO that can never be mmap-ed.

Changes in v2:
- Get rid of panthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL

---
 drivers/gpu/drm/panthor/panthor_drv.c |  5 +++++
 drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------
 2 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 06fe46e32073..7cd131af340d 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 

drivers/gpu/drm/panthor/panthor_drv.c static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data, · line 957

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_drv.c +4 -0
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EPERM;
+

As Matthew already noticed, we need to set ret to -EPERM and goto out.

With that change,

Best regards,
Liviu

Quoted 37 lines
drivers/gpu/drm/panthor/panthor_drv.c +0 -0
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
drivers/gpu/drm/panthor/panthor_gem.c +1 -12
index fd014ccc3bfc..22d78cef9c66 100644
@@ -129,17 +129,6 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
 	return ERR_PTR(ret);
 }
 
-static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
-{
-	struct panthor_gem_object *bo = to_panthor_bo(obj);
-
-	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
-	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
-		return -EINVAL;
-
-	return drm_gem_shmem_object_mmap(obj, vma);
-}
-
 static struct dma_buf *
 panthor_gem_prime_export(struct drm_gem_object *obj, int flags)
 {
@@ -169,7 +158,7 @@ static const struct drm_gem_object_funcs panthor_gem_funcs = {
 	.get_sg_table = drm_gem_shmem_object_get_sg_table,
 	.vmap = drm_gem_shmem_object_vmap,
 	.vunmap = drm_gem_shmem_object_vunmap,
-	.mmap = panthor_gem_mmap,
+	.mmap = drm_gem_shmem_object_mmap,
 	.status = panthor_gem_status,
 	.export = panthor_gem_prime_export,
 	.vm_ops = &drm_gem_shmem_vm_ops,
Signature · 1 line
2.49.0
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯