[PATCH] drm/shmem-helper: Reset vma->vm_ops before calling dma_buf_mmap()

Thomas Zimmermann tzimmermann at suse.de
Tue Jul 25 18:50:43 UTC 2023


Hi

Am 24.07.23 um 13:26 schrieb Boris Brezillon:
> The dma-buf backend is supposed to provide its own vm_ops, but some
> implementation just have nothing special to do and leave vm_ops
> untouched, probably expecting this field to be zero initialized (this
> is the case with the system_heap implementation for instance).
> Let's reset vma->vm_ops to NULL to keep things working with these
> implementations.

Thanks for your patch. This bug could affect a number of GEM 
implementations. Instead of fixing this individually, could we set the 
fields conditionally at

 
https://elixir.bootlin.com/linux/v6.4/source/drivers/gpu/drm/drm_gem.c#L1042

?

Something like

   if (!object->import_attach) {
     vma->priv =
     vma->ops =
   }

plus a descriptive comment like the one you have in your patch.

Best regards
Thomas

> 
> Fixes: 26d3ac3cb04d ("drm/shmem-helpers: Redirect mmap for imported dma-buf")
> Cc: <stable at vger.kernel.org>
> Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
> Reported-by: Roman Stratiienko <roman.stratiienko at globallogic.com>
> Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
> ---
>   drivers/gpu/drm/drm_gem_shmem_helper.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index 4ea6507a77e5..baaf0e0feb06 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -623,7 +623,13 @@ int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct
>   	int ret;
>   
>   	if (obj->import_attach) {
> +		/* 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
> +		 * doesn't set those fields.
> +		 */
>   		vma->vm_private_data = NULL;
> +		vma->vm_ops = NULL;
> +
>   		ret = dma_buf_mmap(obj->dma_buf, vma, 0);
>   
>   		/* Drop the reference drm_gem_mmap_obj() acquired.*/

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20230725/8d10c2a0/attachment-0001.sig>


More information about the dri-devel mailing list