[2/2] drm/vgem: Replace opencoded version of drm_gem_dumb_map_offset()
diff mbox series

Message ID 20200707160012.1299338-2-chris@chris-wilson.co.uk
State New
Headers show
Series
  • [1/2] drm/vgem: Do not allocate backing shmemfs file for an import dmabuf object
Related show

Commit Message

Chris Wilson July 7, 2020, 4 p.m. UTC
drm_gem_dumb_map_offset() now exists and does everything
vgem_gem_dump_map does and *ought* to do.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/vgem/vgem_drv.c | 28 +---------------------------
 1 file changed, 1 insertion(+), 27 deletions(-)

Comments

Daniel Vetter July 8, 2020, 9:56 a.m. UTC | #1
On Tue, Jul 07, 2020 at 05:00:12PM +0100, Chris Wilson wrote:
> drm_gem_dumb_map_offset() now exists and does everything
> vgem_gem_dump_map does and *ought* to do.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/vgem/vgem_drv.c | 28 +---------------------------
>  1 file changed, 1 insertion(+), 27 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
> index eb3b7cdac941..866cff537f28 100644
> --- a/drivers/gpu/drm/vgem/vgem_drv.c
> +++ b/drivers/gpu/drm/vgem/vgem_drv.c
> @@ -236,32 +236,6 @@ static int vgem_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>  	return 0;
>  }
>  
> -static int vgem_gem_dumb_map(struct drm_file *file, struct drm_device *dev,
> -			     uint32_t handle, uint64_t *offset)
> -{
> -	struct drm_gem_object *obj;
> -	int ret;
> -
> -	obj = drm_gem_object_lookup(file, handle);
> -	if (!obj)
> -		return -ENOENT;
> -
> -	if (!obj->filp) {
> -		ret = -EINVAL;
> -		goto unref;
> -	}
> -
> -	ret = drm_gem_create_mmap_offset(obj);
> -	if (ret)
> -		goto unref;
> -
> -	*offset = drm_vma_node_offset_addr(&obj->vma_node);
> -unref:
> -	drm_gem_object_put_unlocked(obj);
> -
> -	return ret;
> -}
> -
>  static struct drm_ioctl_desc vgem_ioctls[] = {
>  	DRM_IOCTL_DEF_DRV(VGEM_FENCE_ATTACH, vgem_fence_attach_ioctl, DRM_RENDER_ALLOW),
>  	DRM_IOCTL_DEF_DRV(VGEM_FENCE_SIGNAL, vgem_fence_signal_ioctl, DRM_RENDER_ALLOW),
> @@ -455,7 +429,7 @@ static struct drm_driver vgem_driver = {
>  	.fops				= &vgem_driver_fops,
>  
>  	.dumb_create			= vgem_gem_dumb_create,
> -	.dumb_map_offset		= vgem_gem_dumb_map,
> +	.dumb_map_offset		= drm_gem_dumb_map_offset,

Even better: Just delete it, it's the default. With that:

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Also maybe cc: stable, since this should stop the mmap attempts on
imported dma-buf? Or will this break stuff ...
-Daniel

>  
>  	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
>  	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
> -- 
> 2.27.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chris Wilson July 8, 2020, 2:53 p.m. UTC | #2
Quoting Daniel Vetter (2020-07-08 10:56:19)
> On Tue, Jul 07, 2020 at 05:00:12PM +0100, Chris Wilson wrote:
> > drm_gem_dumb_map_offset() now exists and does everything
> > vgem_gem_dump_map does and *ought* to do.
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> >  drivers/gpu/drm/vgem/vgem_drv.c | 28 +---------------------------
> >  1 file changed, 1 insertion(+), 27 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
> > index eb3b7cdac941..866cff537f28 100644
> > --- a/drivers/gpu/drm/vgem/vgem_drv.c
> > +++ b/drivers/gpu/drm/vgem/vgem_drv.c
> > @@ -236,32 +236,6 @@ static int vgem_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
> >       return 0;
> >  }
> >  
> > -static int vgem_gem_dumb_map(struct drm_file *file, struct drm_device *dev,
> > -                          uint32_t handle, uint64_t *offset)
> > -{
> > -     struct drm_gem_object *obj;
> > -     int ret;
> > -
> > -     obj = drm_gem_object_lookup(file, handle);
> > -     if (!obj)
> > -             return -ENOENT;
> > -
> > -     if (!obj->filp) {
> > -             ret = -EINVAL;
> > -             goto unref;
> > -     }
> > -
> > -     ret = drm_gem_create_mmap_offset(obj);
> > -     if (ret)
> > -             goto unref;
> > -
> > -     *offset = drm_vma_node_offset_addr(&obj->vma_node);
> > -unref:
> > -     drm_gem_object_put_unlocked(obj);
> > -
> > -     return ret;
> > -}
> > -
> >  static struct drm_ioctl_desc vgem_ioctls[] = {
> >       DRM_IOCTL_DEF_DRV(VGEM_FENCE_ATTACH, vgem_fence_attach_ioctl, DRM_RENDER_ALLOW),
> >       DRM_IOCTL_DEF_DRV(VGEM_FENCE_SIGNAL, vgem_fence_signal_ioctl, DRM_RENDER_ALLOW),
> > @@ -455,7 +429,7 @@ static struct drm_driver vgem_driver = {
> >       .fops                           = &vgem_driver_fops,
> >  
> >       .dumb_create                    = vgem_gem_dumb_create,
> > -     .dumb_map_offset                = vgem_gem_dumb_map,
> > +     .dumb_map_offset                = drm_gem_dumb_map_offset,
> 
> Even better: Just delete it, it's the default. With that:
> 
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
> Also maybe cc: stable, since this should stop the mmap attempts on
> imported dma-buf? Or will this break stuff ...

commit 90378e58919285637aa0f063c04ba0c6449d98b1 [v4.15]
Author: Noralf Trønnes <noralf@tronnes.org>
Date:   Thu Aug 17 18:21:30 2017 +0200

    drm/gem: drm_gem_dumb_map_offset(): reject dma-buf

and

commit db61152703c64133e42b8c720a83ff36e1824bb1 [v4.14]
Author: Noralf Trønnes <noralf@tronnes.org>
Date:   Sun Jul 23 21:16:17 2017 +0200

    drm/gem: Add drm_gem_dumb_map_offset()

It became default at the same time:

commit 0be8d63a840ab7cacb08f1af1f2395be0fe3b698 [v4.14]
Author: Noralf Trønnes <noralf@tronnes.org>
Date:   Sun Jul 23 21:16:18 2017 +0200

    drm/dumb-buffers: Add defaults for .dumb_map_offset and .dumb_destroy

The bug was in

commit af33a9190d0226251e9cbc137c88a707b0bbe356 [v4.13]
Author: Laura Abbott <labbott@redhat.com>
Date:   Thu May 4 11:45:48 2017 -0700

    drm/vgem: Enable dmabuf import interfaces

The drm_gem_dumb_map_offset is much older than I thought it was, and
while I suspected you might have suggested making it an automatic default,
I looked in the wrong place for the caller.

It's the cleaner fix, so this deserves the cc:stable more than the
first and covers the same lts.
-Chris

Patch
diff mbox series

diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
index eb3b7cdac941..866cff537f28 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.c
+++ b/drivers/gpu/drm/vgem/vgem_drv.c
@@ -236,32 +236,6 @@  static int vgem_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
 	return 0;
 }
 
-static int vgem_gem_dumb_map(struct drm_file *file, struct drm_device *dev,
-			     uint32_t handle, uint64_t *offset)
-{
-	struct drm_gem_object *obj;
-	int ret;
-
-	obj = drm_gem_object_lookup(file, handle);
-	if (!obj)
-		return -ENOENT;
-
-	if (!obj->filp) {
-		ret = -EINVAL;
-		goto unref;
-	}
-
-	ret = drm_gem_create_mmap_offset(obj);
-	if (ret)
-		goto unref;
-
-	*offset = drm_vma_node_offset_addr(&obj->vma_node);
-unref:
-	drm_gem_object_put_unlocked(obj);
-
-	return ret;
-}
-
 static struct drm_ioctl_desc vgem_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(VGEM_FENCE_ATTACH, vgem_fence_attach_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(VGEM_FENCE_SIGNAL, vgem_fence_signal_ioctl, DRM_RENDER_ALLOW),
@@ -455,7 +429,7 @@  static struct drm_driver vgem_driver = {
 	.fops				= &vgem_driver_fops,
 
 	.dumb_create			= vgem_gem_dumb_create,
-	.dumb_map_offset		= vgem_gem_dumb_map,
+	.dumb_map_offset		= drm_gem_dumb_map_offset,
 
 	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
 	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,