drm/panthor: Don't create a file offset for NO_MMAP BOs
Subsystems (3)
Boris Brezillon
maintainerPATCH v3 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
Changes in v3:
- Don't leak the BO ref
- Add R-bs
--- drivers/gpu/drm/panthor/panthor_drv.c | 7 +++++++ drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------ 2 files changed, 8 insertions(+), 12 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +7 -0
@@ -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,12 @@ 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 ) { + ret = -EPERM ; + goto out; + } + ret =drm_gem_create_mmap_offset (obj);if (ret) goto out;
drivers/gpu/drm/panthor/panthor_gem.c +1 -12
@@ -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
Quoted 15 lines · Boris Brezillon
Right now the
DRM_PANTHOR_BO_NO_MMAPflag is ignored bypanthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, becausepanthor_gem_mmap()will filter them out.If we error out at
mmap_offsetcreation time, we can get rid ofpanthor_gem_mmap()and calldrm_gem_shmem_object_mmapdirectly, 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 ofpanthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL
Quoted 7 lines
Changes in v3:
- Don't leak the BO ref
- Add R-bsSigned-off-by Boris Brezillon <[email protected]>Reviewed-by Steven Price <[email protected]>Reviewed-by Liviu Dudau <[email protected]>
Quoted 62 lines
--- drivers/gpu/drm/panthor/panthor_drv.c | 7 +++++++ drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------ 2 files changed, 8 insertions(+), 12 deletions(-)drivers/gpu/drm/panthor/panthor_drv.c +7
-0@@ -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,12 @@ 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 ) { + ret = -EPERM ; + goto out; + } + ret =drm_gem_create_mmap_offset (obj);if (ret) goto out;drivers/gpu/drm/panthor/panthor_gem.c +1
-13@@ -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, --
Quoted 1 line
2.49.0
Adrian Larumbe
Quoted 15 lines · On Thu, 17 Apr 2025 14:19:42 +0200 Boris Brezillon…
Right now the
DRM_PANTHOR_BO_NO_MMAPflag is ignored bypanthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can have a file offset but can't be mapped anyway, becausepanthor_gem_mmap()will filter them out.If we error out at
mmap_offsetcreation time, we can get rid ofpanthor_gem_mmap()and calldrm_gem_shmem_object_mmapdirectly, 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 ofpanthor_gem_mmap()
- Get rid of the Fixes tag and adjust the commit message accordingly
- Return ENOPERM instead of EINVAL
Quoted 7 lines
Changes in v3:
- Don't leak the BO ref
- Add R-bsSigned-off-by Boris Brezillon <[email protected]>Reviewed-by Steven Price <[email protected]>Reviewed-by Liviu Dudau <[email protected]>
Queued to drm-misc-next.
Quoted 61 lines
--- drivers/gpu/drm/panthor/panthor_drv.c | 7 +++++++ drivers/gpu/drm/panthor/panthor_gem.c | 13 +------------ 2 files changed, 8 insertions(+), 12 deletions(-)drivers/gpu/drm/panthor/panthor_drv.c +7
-0@@ -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,12 @@ 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 ) { + ret = -EPERM ; + goto out; + } + ret =drm_gem_create_mmap_offset (obj);if (ret) goto out;drivers/gpu/drm/panthor/panthor_gem.c +1
-12@@ -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,