Skip to contentSkip to conversation

drm/panthor: Fix handling of NO_MMAP BOs

PATCH Applied Akash Goel 3 participants 7 messages Oct 13 – Oct 15

Subsystems (3)
lore
Share & tools
lore

Akash Goel

author
#0 lore raw

PATCH v2 1/2 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 adds a check in the mmap callback of Panthor driver to fail the mmap() attempts on BOs created with NO_MMAP flag. The check covers private BOs as well as the prime exported BOs that are mmapped using prime fd.

v2:
- Fix breakage of mmap() on exported BOs that didn't have BO_MMAP_OFFSET ioctl invoked for them.

Fixes 68cbf96b1e9b ("drm/panthor: Part ways with drm_gem_shmem_object")
---
 drivers/gpu/drm/panthor/panthor_gem.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_gem.c +3 -0
index c07a44057e42..22b57ab6f929 100644
@@ -744,6 +744,9 @@ static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *v
 	struct panthor_gem_object *bo = to_panthor_bo(obj);
 	int ret;
 
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;
+
 	if (drm_gem_is_imported(obj)) {
 		/* Reset both vm_ops and vm_private_data, so we don't end up with
 		 * vm_ops pointing to our implementation if the dma-buf backend
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 2/2 drm/panthor: Remove redundant drm_gem_create_mmap_offset() call from BO_MMAP_OFFSET ioctl

This commit removes the call to drm_gem_create_mmap_offset() from the BO_MMAP_OFFSET ioctl handler. The call was redundant and didn't have any effect as file offset range is allocated unconditionally at the BO creation time.

v2:
- New patch

---
 drivers/gpu/drm/panthor/panthor_drv.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +1 -5
index 1ca8aedd83f4..dc8d0191aef4 100644
@@ -1081,7 +1081,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	struct drm_panthor_bo_mmap_offset *args = data;
 	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
-	int ret;
+	int ret = 0;
 
 	if (args->pad)
 		return -EINVAL;
@@ -1096,10 +1096,6 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 		goto out;
 	}
 
-	ret = drm_gem_create_mmap_offset(obj);
-	if (ret)
-		goto out;
-
 	args->offset = drm_vma_node_offset_addr(&obj->vma_node);
 
 out:
Signature · 1 line
2.25.1
maintainer Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] drm/panthor: Remove redundant drm_gem_create_mmap_offset() call from BO_MMAP_OFFSET ioctl

Quoted 10 lines · Akash Goel

This commit removes the call to drm_gem_create_mmap_offset() from the BO_MMAP_OFFSET ioctl handler. The call was redundant and didn't have any effect as file offset range is allocated unconditionally at the BO creation time.

v2:
- New patch

Best regards,
Liviu

Quoted 31 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +1 -5
index 1ca8aedd83f4..dc8d0191aef4 100644
@@ -1081,7 +1081,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	struct drm_panthor_bo_mmap_offset *args = data;
 	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
-	int ret;
+	int ret = 0;
 
 	if (args->pad)
 		return -EINVAL;
@@ -1096,10 +1096,6 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 		goto out;
 	}
 
-	ret = drm_gem_create_mmap_offset(obj);
-	if (ret)
-		goto out;
-
 	args->offset = drm_vma_node_offset_addr(&obj->vma_node);
 
 out:
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 Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] drm/panthor: Remove redundant drm_gem_create_mmap_offset() call from BO_MMAP_OFFSET ioctl

In reply to Akash Goel
Quoted 10 lines · Akash Goel

This commit removes the call to drm_gem_create_mmap_offset() from the BO_MMAP_OFFSET ioctl handler. The call was redundant and didn't have any effect as file offset range is allocated unconditionally at the BO creation time.

v2:
- New patch

Quoted 28 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +1 -5
index 1ca8aedd83f4..dc8d0191aef4 100644
@@ -1081,7 +1081,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	struct drm_panthor_bo_mmap_offset *args = data;
 	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
-	int ret;
+	int ret = 0;
 
 	if (args->pad)
 		return -EINVAL;
@@ -1096,10 +1096,6 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 		goto out;
 	}
 
-	ret = drm_gem_create_mmap_offset(obj);
-	if (ret)
-		goto out;
-
 	args->offset = drm_vma_node_offset_addr(&obj->vma_node);
 
 out:
maintainer Reviewed-by on v2 1/2
#4 lore raw
In reply to Akash Goel
Quoted 11 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 adds a check in the mmap callback of Panthor driver to fail the mmap() attempts on BOs created with NO_MMAP flag. The check covers private BOs as well as the prime exported BOs that are mmapped using prime fd.

Quoted 7 lines

v2:
- Fix breakage of mmap() on exported BOs that didn't have BO_MMAP_OFFSET ioctl invoked for them.

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

Best regards,
Liviu

Quoted 21 lines
---
 drivers/gpu/drm/panthor/panthor_gem.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_gem.c +3 -0
index c07a44057e42..22b57ab6f929 100644
@@ -744,6 +744,9 @@ static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *v
 	struct panthor_gem_object *bo = to_panthor_bo(obj);
 	int ret;
 
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;
+
 	if (drm_gem_is_imported(obj)) {
 		/* Reset both vm_ops and vm_private_data, so we don't end up with
 		 * vm_ops pointing to our implementation if the dma-buf backend
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 Reviewed-by on v2 1/2
#5 lore raw
In reply to Akash Goel
Quoted 11 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 adds a check in the mmap callback of Panthor driver to fail the mmap() attempts on BOs created with NO_MMAP flag. The check covers private BOs as well as the prime exported BOs that are mmapped using prime fd.

Quoted 7 lines

v2:
- Fix breakage of mmap() on exported BOs that didn't have BO_MMAP_OFFSET ioctl invoked for them.

Fixes 68cbf96b1e9b ("drm/panthor: Part ways with drm_gem_shmem_object")
Quoted 18 lines
---
 drivers/gpu/drm/panthor/panthor_gem.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_gem.c +3 -0
index c07a44057e42..22b57ab6f929 100644
@@ -744,6 +744,9 @@ static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *v
 	struct panthor_gem_object *bo = to_panthor_bo(obj);
 	int ret;
 
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;
+
 	if (drm_gem_is_imported(obj)) {
 		/* Reset both vm_ops and vm_private_data, so we don't end up with
 		 * vm_ops pointing to our implementation if the dma-buf backend
maintainer Applied
#6 lore raw
In reply to Akash Goel
Quoted 11 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 adds a check in the mmap callback of Panthor driver to fail the mmap() attempts on BOs created with NO_MMAP flag. The check covers private BOs as well as the prime exported BOs that are mmapped using prime fd.

Quoted 7 lines

v2:
- Fix breakage of mmap() on exported BOs that didn't have BO_MMAP_OFFSET ioctl invoked for them.

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

Pushed to drm-misc-next.

Best regards,
Liviu

Quoted 21 lines
---
 drivers/gpu/drm/panthor/panthor_gem.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/panthor/panthor_gem.c +3 -0
index c07a44057e42..22b57ab6f929 100644
@@ -744,6 +744,9 @@ static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *v
 	struct panthor_gem_object *bo = to_panthor_bo(obj);
 	int ret;
 
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;
+
 	if (drm_gem_is_imported(obj)) {
 		/* Reset both vm_ops and vm_private_data, so we don't end up with
 		 * vm_ops pointing to our implementation if the dma-buf backend
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!  /
  ---------------
    ¯\_(ツ)_/¯