diff mbox series

[7/9] drm/shmem-helpers: Redirect mmap for imported dma-buf

Message ID 20200511093554.211493-8-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show
Series shmem helper untangling | expand

Commit Message

Daniel Vetter May 11, 2020, 9:35 a.m. UTC
Currently this seems to work by converting the sgt into a pages array,
and then treating it like a native object. Do the right thing and
redirect mmap to the exporter.

With this nothing is calling get_pages anymore on imported dma-buf,
and we can start to remove the use of the ->pages array for that case.

v2: Rebase

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Thomas Zimmermann May 14, 2020, 7:23 a.m. UTC | #1
Hi

Am 11.05.20 um 11:35 schrieb Daniel Vetter:
> Currently this seems to work by converting the sgt into a pages array,
> and then treating it like a native object. Do the right thing and
> redirect mmap to the exporter.
> 
> With this nothing is calling get_pages anymore on imported dma-buf,
> and we can start to remove the use of the ->pages array for that case.
> 
> v2: Rebase
> 
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/drm_gem_shmem_helper.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index b9cba5cc61c3..117a7841e284 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -551,6 +551,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
>  	/* Remove the fake offset */
>  	vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
>  
> +	if (obj->import_attach)
> +		return dma_buf_mmap(obj->dma_buf, vma, 0);
> +

Just a question: how does it work with the fake value in vm_pgoffset?
The offset is a DRM-specific thing and the dma-buf exporter expects the
real offset?

With this question clarified:

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>


>  	shmem = to_drm_gem_shmem_obj(obj);
>  
>  	ret = drm_gem_shmem_get_pages(shmem);
>
Daniel Vetter May 14, 2020, 12:47 p.m. UTC | #2
On Thu, May 14, 2020 at 09:23:37AM +0200, Thomas Zimmermann wrote:
> Hi
> 
> Am 11.05.20 um 11:35 schrieb Daniel Vetter:
> > Currently this seems to work by converting the sgt into a pages array,
> > and then treating it like a native object. Do the right thing and
> > redirect mmap to the exporter.
> > 
> > With this nothing is calling get_pages anymore on imported dma-buf,
> > and we can start to remove the use of the ->pages array for that case.
> > 
> > v2: Rebase
> > 
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Noralf Trønnes <noralf@tronnes.org>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > ---
> >  drivers/gpu/drm/drm_gem_shmem_helper.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> > index b9cba5cc61c3..117a7841e284 100644
> > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> > @@ -551,6 +551,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
> >  	/* Remove the fake offset */
> >  	vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
> >  
> > +	if (obj->import_attach)
> > +		return dma_buf_mmap(obj->dma_buf, vma, 0);
> > +
> 
> Just a question: how does it work with the fake value in vm_pgoffset?
> The offset is a DRM-specific thing and the dma-buf exporter expects the
> real offset?

For drm chardev file descriptor we have one file, but want to let
userspace map arbitrary objects. So an object gets a allocated an area
within the over drm mmap space, this fake offset.

For dma-buf mmap otoh there's a 1:1 mapping between fd and object, so no
additional offset needed.
-Daniel

> 
> With this question clarified:
> 
> Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
> 
> 
> >  	shmem = to_drm_gem_shmem_obj(obj);
> >  
> >  	ret = drm_gem_shmem_get_pages(shmem);
> > 
> 
> -- 
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5, 90409 Nürnberg, Germany
> (HRB 36809, AG Nürnberg)
> Geschäftsführer: Felix Imendörffer
>
Thomas Zimmermann May 27, 2020, 6:32 p.m. UTC | #3
Hi Daniel,

what's your plan for this patch set? I'd need this patch for the udl
shmem cleanup.

Best regards
Thomas

Am 11.05.20 um 11:35 schrieb Daniel Vetter:
> Currently this seems to work by converting the sgt into a pages array,
> and then treating it like a native object. Do the right thing and
> redirect mmap to the exporter.
> 
> With this nothing is calling get_pages anymore on imported dma-buf,
> and we can start to remove the use of the ->pages array for that case.
> 
> v2: Rebase
> 
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/drm_gem_shmem_helper.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index b9cba5cc61c3..117a7841e284 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -551,6 +551,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
>  	/* Remove the fake offset */
>  	vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
>  
> +	if (obj->import_attach)
> +		return dma_buf_mmap(obj->dma_buf, vma, 0);
> +
>  	shmem = to_drm_gem_shmem_obj(obj);
>  
>  	ret = drm_gem_shmem_get_pages(shmem);
>
Daniel Vetter May 27, 2020, 7:34 p.m. UTC | #4
On Wed, May 27, 2020 at 8:32 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Hi Daniel,
>
> what's your plan for this patch set? I'd need this patch for the udl
> shmem cleanup.

I was pinging some people for a tested-by, I kinda don't want to push
this entirely untested. I think at least one of the rendering drivers
using shmem would be nice to run this on, I've pinged Rob Herring a
bit.
-Daniel

>
> Best regards
> Thomas
>
> Am 11.05.20 um 11:35 schrieb Daniel Vetter:
> > Currently this seems to work by converting the sgt into a pages array,
> > and then treating it like a native object. Do the right thing and
> > redirect mmap to the exporter.
> >
> > With this nothing is calling get_pages anymore on imported dma-buf,
> > and we can start to remove the use of the ->pages array for that case.
> >
> > v2: Rebase
> >
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Noralf Trønnes <noralf@tronnes.org>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > ---
> >  drivers/gpu/drm/drm_gem_shmem_helper.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> > index b9cba5cc61c3..117a7841e284 100644
> > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> > @@ -551,6 +551,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
> >       /* Remove the fake offset */
> >       vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
> >
> > +     if (obj->import_attach)
> > +             return dma_buf_mmap(obj->dma_buf, vma, 0);
> > +
> >       shmem = to_drm_gem_shmem_obj(obj);
> >
> >       ret = drm_gem_shmem_get_pages(shmem);
> >
>
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5, 90409 Nürnberg, Germany
> (HRB 36809, AG Nürnberg)
> Geschäftsführer: Felix Imendörffer
>
Thomas Zimmermann May 28, 2020, 12:53 p.m. UTC | #5
Hi

Am 27.05.20 um 21:34 schrieb Daniel Vetter:
> On Wed, May 27, 2020 at 8:32 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>>
>> Hi Daniel,
>>
>> what's your plan for this patch set? I'd need this patch for the udl
>> shmem cleanup.
> 
> I was pinging some people for a tested-by, I kinda don't want to push
> this entirely untested. I think at least one of the rendering drivers
> using shmem would be nice to run this on, I've pinged Rob Herring a
> bit.

OK, makes sense. FWIW I tested the patchset with udl as secondary
adapter. No problems noticed.

Tested-by: Thomas Zimmermann <tzimmermann@suse.de>

Best regards
Thomas

> -Daniel
> 
>>
>> Best regards
>> Thomas
>>
>> Am 11.05.20 um 11:35 schrieb Daniel Vetter:
>>> Currently this seems to work by converting the sgt into a pages array,
>>> and then treating it like a native object. Do the right thing and
>>> redirect mmap to the exporter.
>>>
>>> With this nothing is calling get_pages anymore on imported dma-buf,
>>> and we can start to remove the use of the ->pages array for that case.
>>>
>>> v2: Rebase
>>>
>>> Cc: Gerd Hoffmann <kraxel@redhat.com>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Noralf Trønnes <noralf@tronnes.org>
>>> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
>>> ---
>>>  drivers/gpu/drm/drm_gem_shmem_helper.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
>>> index b9cba5cc61c3..117a7841e284 100644
>>> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
>>> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
>>> @@ -551,6 +551,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
>>>       /* Remove the fake offset */
>>>       vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
>>>
>>> +     if (obj->import_attach)
>>> +             return dma_buf_mmap(obj->dma_buf, vma, 0);
>>> +
>>>       shmem = to_drm_gem_shmem_obj(obj);
>>>
>>>       ret = drm_gem_shmem_get_pages(shmem);
>>>
>>
>> --
>> Thomas Zimmermann
>> Graphics Driver Developer
>> SUSE Software Solutions Germany GmbH
>> Maxfeldstr. 5, 90409 Nürnberg, Germany
>> (HRB 36809, AG Nürnberg)
>> Geschäftsführer: Felix Imendörffer
>>
> 
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index b9cba5cc61c3..117a7841e284 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -551,6 +551,9 @@  int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 	/* Remove the fake offset */
 	vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
 
+	if (obj->import_attach)
+		return dma_buf_mmap(obj->dma_buf, vma, 0);
+
 	shmem = to_drm_gem_shmem_obj(obj);
 
 	ret = drm_gem_shmem_get_pages(shmem);