Skip to contentSkip to conversation

drm/cma: Fix recent regression of mmap() in the MMU case.

PATCH In review Eric Anholt 2 participants 2 messages Apr 17, 2017 – Apr 18, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/cma: Fix recent regression of mmap() in the MMU case.

The stub get_unmapped_area() function was actually getting called, so all of our mmap()s failed.

Cc Yannick Fertre <[email protected]>
Fixes 97bf3a9aa60f ("drm/cma: Update DEFINE_DRM_GEM_CMA_FOPS to add get_unmapped_area")
---
 include/drm/drm_gem_cma_helper.h | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
include/drm/drm_gem_cma_helper.h +8 -10
index 7320b140545a..b42529e0fae0 100644
@@ -26,6 +26,13 @@ to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
 	return container_of(gem_obj, struct drm_gem_cma_object, base);
 }
 
+#ifndef CONFIG_MMU
+#define DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
+	.get_unmapped_area	= drm_gem_cma_get_unmapped_area,
+#else
+#define DRM_GEM_CMA_UNMAPPED_AREA_FOPS
+#endif
+
 /**
  * DEFINE_DRM_GEM_CMA_FOPS() - macro to generate file operations for CMA drivers
  * @name: name for the generated structure
@@ -50,7 +57,7 @@ to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
 		.read		= drm_read,\
 		.llseek		= noop_llseek,\
 		.mmap		= drm_gem_cma_mmap,\
-		.get_unmapped_area	= drm_gem_cma_get_unmapped_area,\
+		DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
 	}
 
 /* free GEM object */
@@ -86,15 +93,6 @@ unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
 					    unsigned long len,
 					    unsigned long pgoff,
 					    unsigned long flags);
-#else
-static inline unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
-							  unsigned long addr,
-							  unsigned long len,
-							  unsigned long pgoff,
-							  unsigned long flags)
-{
-	return -EINVAL;
-}
 #endif
 
 #ifdef CONFIG_DEBUG_FS
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eric Anholt

The stub get_unmapped_area() function was actually getting called, so all of our mmap()s failed.

Cc Yannick Fertre <[email protected]>
Fixes 97bf3a9aa60f ("drm/cma: Update DEFINE_DRM_GEM_CMA_FOPS to add get_unmapped_area")

Oh drat, I assumed the core would only call this when needed, but things don't work like that.

The strange thing is that in some cases ->mm->get_unmapped_area overwrites fops->get_unmapped_area, but not for do_mmap in the mmu case. Seems not entirely thought out to me ...
-Daniel

Quoted 54 lines
---
 include/drm/drm_gem_cma_helper.h | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
include/drm/drm_gem_cma_helper.h +8 -10
index 7320b140545a..b42529e0fae0 100644
@@ -26,6 +26,13 @@ to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
 	return container_of(gem_obj, struct drm_gem_cma_object, base);
 }
 
+#ifndef CONFIG_MMU
+#define DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
+	.get_unmapped_area	= drm_gem_cma_get_unmapped_area,
+#else
+#define DRM_GEM_CMA_UNMAPPED_AREA_FOPS
+#endif
+
 /**
  * DEFINE_DRM_GEM_CMA_FOPS() - macro to generate file operations for CMA drivers
  * @name: name for the generated structure
@@ -50,7 +57,7 @@ to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
 		.read		= drm_read,\
 		.llseek		= noop_llseek,\
 		.mmap		= drm_gem_cma_mmap,\
-		.get_unmapped_area	= drm_gem_cma_get_unmapped_area,\
+		DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
 	}
 
 /* free GEM object */
@@ -86,15 +93,6 @@ unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
 					    unsigned long len,
 					    unsigned long pgoff,
 					    unsigned long flags);
-#else
-static inline unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
-							  unsigned long addr,
-							  unsigned long len,
-							  unsigned long pgoff,
-							  unsigned long flags)
-{
-	return -EINVAL;
-}
 #endif
 
 #ifdef CONFIG_DEBUG_FS
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel