diff mbox

[3/3] drm/tegra: fb: Implement ->fb_mmap() callback

Message ID 20180207174556.25401-3-thierry.reding@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Thierry Reding Feb. 7, 2018, 5:45 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

This fixes hangs with legacy applications that use the mmap() syscall on
the fbdev device to map framebuffer memory. The fbdev implementation for
mmap() creates a mapping that conflicts with DRM usage and causes a hang
when the memory is accessed through the mapping.

Reported-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/gpu/drm/tegra/fb.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Stefan Agner Feb. 7, 2018, 7:24 p.m. UTC | #1
On 07.02.2018 18:45, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> This fixes hangs with legacy applications that use the mmap() syscall on
> the fbdev device to map framebuffer memory. The fbdev implementation for
> mmap() creates a mapping that conflicts with DRM usage and causes a hang
> when the memory is accessed through the mapping.

That helps using applications making use of mmap & fbdev on an Apalis
TK1!

Tested-by: Stefan Agner <stefan@agner.ch>

--
Stefan

> 
> Reported-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  drivers/gpu/drm/tegra/fb.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c
> index 001cb77e2f59..0786159edef3 100644
> --- a/drivers/gpu/drm/tegra/fb.c
> +++ b/drivers/gpu/drm/tegra/fb.c
> @@ -224,12 +224,28 @@ struct drm_framebuffer *tegra_fb_create(struct
> drm_device *drm,
>  }
>  
>  #ifdef CONFIG_DRM_FBDEV_EMULATION
> +static int tegra_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
> +{
> +	struct drm_fb_helper *helper = info->par;
> +	struct tegra_bo *bo;
> +	int err;
> +
> +	bo = tegra_fb_get_plane(helper->fb, 0);
> +
> +	err = drm_gem_mmap_obj(&bo->gem, bo->gem.size, vma);
> +	if (err < 0)
> +		return err;
> +
> +	return __tegra_gem_mmap(&bo->gem, vma);
> +}
> +
>  static struct fb_ops tegra_fb_ops = {
>  	.owner = THIS_MODULE,
>  	DRM_FB_HELPER_DEFAULT_OPS,
>  	.fb_fillrect = drm_fb_helper_sys_fillrect,
>  	.fb_copyarea = drm_fb_helper_sys_copyarea,
>  	.fb_imageblit = drm_fb_helper_sys_imageblit,
> +	.fb_mmap = tegra_fb_mmap,
>  };
>  
>  static int tegra_fbdev_probe(struct drm_fb_helper *helper,
Marcel Ziswiler Feb. 8, 2018, 12:52 a.m. UTC | #2
On Wed, 2018-02-07 at 18:45 +0100, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>

> 

> This fixes hangs with legacy applications that use the mmap() syscall

> on

> the fbdev device to map framebuffer memory. The fbdev implementation

> for

> mmap() creates a mapping that conflicts with DRM usage and causes a

> hang

> when the memory is accessed through the mapping.


With that legacy Qt4e applications run just fine now on Apalis TK1
running Linux kernel 4.14.18.

Thanks, Thierry!

Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>


Reported-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

> ---

>  drivers/gpu/drm/tegra/fb.c | 16 ++++++++++++++++

>  1 file changed, 16 insertions(+)

> 

> diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c

> index 001cb77e2f59..0786159edef3 100644

> --- a/drivers/gpu/drm/tegra/fb.c

> +++ b/drivers/gpu/drm/tegra/fb.c

> @@ -224,12 +224,28 @@ struct drm_framebuffer *tegra_fb_create(struct

> drm_device *drm,

>  }

>  

>  #ifdef CONFIG_DRM_FBDEV_EMULATION

> +static int tegra_fb_mmap(struct fb_info *info, struct vm_area_struct

> *vma)

> +{

> +	struct drm_fb_helper *helper = info->par;

> +	struct tegra_bo *bo;

> +	int err;

> +

> +	bo = tegra_fb_get_plane(helper->fb, 0);

> +

> +	err = drm_gem_mmap_obj(&bo->gem, bo->gem.size, vma);

> +	if (err < 0)

> +		return err;

> +

> +	return __tegra_gem_mmap(&bo->gem, vma);

> +}

> +

>  static struct fb_ops tegra_fb_ops = {

>  	.owner = THIS_MODULE,

>  	DRM_FB_HELPER_DEFAULT_OPS,

>  	.fb_fillrect = drm_fb_helper_sys_fillrect,

>  	.fb_copyarea = drm_fb_helper_sys_copyarea,

>  	.fb_imageblit = drm_fb_helper_sys_imageblit,

> +	.fb_mmap = tegra_fb_mmap,

>  };

>  

>  static int tegra_fbdev_probe(struct drm_fb_helper *helper,
diff mbox

Patch

diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c
index 001cb77e2f59..0786159edef3 100644
--- a/drivers/gpu/drm/tegra/fb.c
+++ b/drivers/gpu/drm/tegra/fb.c
@@ -224,12 +224,28 @@  struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
 }
 
 #ifdef CONFIG_DRM_FBDEV_EMULATION
+static int tegra_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
+{
+	struct drm_fb_helper *helper = info->par;
+	struct tegra_bo *bo;
+	int err;
+
+	bo = tegra_fb_get_plane(helper->fb, 0);
+
+	err = drm_gem_mmap_obj(&bo->gem, bo->gem.size, vma);
+	if (err < 0)
+		return err;
+
+	return __tegra_gem_mmap(&bo->gem, vma);
+}
+
 static struct fb_ops tegra_fb_ops = {
 	.owner = THIS_MODULE,
 	DRM_FB_HELPER_DEFAULT_OPS,
 	.fb_fillrect = drm_fb_helper_sys_fillrect,
 	.fb_copyarea = drm_fb_helper_sys_copyarea,
 	.fb_imageblit = drm_fb_helper_sys_imageblit,
+	.fb_mmap = tegra_fb_mmap,
 };
 
 static int tegra_fbdev_probe(struct drm_fb_helper *helper,