diff mbox series

[v2,1/2] media: videobuf2-dma-sg: fix vmap and vunmap callbacks

Message ID 20221125153450.344392-1-m.grzeschik@pengutronix.de
State New
Headers show
Series [v2,1/2] media: videobuf2-dma-sg: fix vmap and vunmap callbacks | expand

Commit Message

Michael Grzeschik Nov. 25, 2022, 3:34 p.m. UTC
For dmabuf import users to be able to use the vaddr from another
videobuf2-dma-sg source, the exporter needs to set a proper vaddr on
vb2_dma_sg_dmabuf_ops_vmap callback.

This patch adds vm_map_ram on map if buf->vaddr was not set, and also
adds the vb2_dma_sg_dmabuf_ops_vunmap function to remove the mapping
afterwards.

Cc: stable <stable@kernel.org>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

---
v1 -> v2: using vmap and vunmap instead of vm_map_ram and vm_unmap_ram

 .../media/common/videobuf2/videobuf2-dma-sg.c    | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Michael Grzeschik Jan. 24, 2023, 10:34 p.m. UTC | #1
Gentle Ping!

On Fri, Nov 25, 2022 at 04:34:49PM +0100, Michael Grzeschik wrote:
>For dmabuf import users to be able to use the vaddr from another
>videobuf2-dma-sg source, the exporter needs to set a proper vaddr on
>vb2_dma_sg_dmabuf_ops_vmap callback.
>
>This patch adds vm_map_ram on map if buf->vaddr was not set, and also
>adds the vb2_dma_sg_dmabuf_ops_vunmap function to remove the mapping
>afterwards.
>
>Cc: stable <stable@kernel.org>
>Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>
>---
>v1 -> v2: using vmap and vunmap instead of vm_map_ram and vm_unmap_ram
>
> .../media/common/videobuf2/videobuf2-dma-sg.c    | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
>diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
>index fa69158a65b1fd..dcb8de5ab3e84a 100644
>--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
>+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
>@@ -496,11 +496,26 @@ static int vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf,
> {
> 	struct vb2_dma_sg_buf *buf = dbuf->priv;
>
>+	if (!buf->vaddr)
>+		buf->vaddr = vmap(buf->pages, buf->num_pages, VM_MAP,
>+				  PAGE_KERNEL);
>+
> 	iosys_map_set_vaddr(map, buf->vaddr);
>
> 	return 0;
> }
>
>+static void vb2_dma_sg_dmabuf_ops_vunmap(struct dma_buf *dbuf,
>+				      struct iosys_map *map)
>+{
>+	struct vb2_dma_sg_buf *buf = dbuf->priv;
>+
>+	if (buf->vaddr)
>+		vunmap(buf->vaddr);
>+
>+	buf->vaddr = NULL;
>+}
>+
> static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
> 	struct vm_area_struct *vma)
> {
>@@ -515,6 +530,7 @@ static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
> 	.begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access,
> 	.end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access,
> 	.vmap = vb2_dma_sg_dmabuf_ops_vmap,
>+	.vunmap = vb2_dma_sg_dmabuf_ops_vunmap,
> 	.mmap = vb2_dma_sg_dmabuf_ops_mmap,
> 	.release = vb2_dma_sg_dmabuf_ops_release,
> };
>-- 
>2.30.2
>
Hans Verkuil July 18, 2023, 8:40 a.m. UTC | #2
Hi Michael,

I'm going through some old patches in patchwork and found this one.
Is this patch specifically for the uvc gadget driver, or is it a
generic fix? If it is the latter (I suspect it is), then can you
post this as a v3 by itself and rebased to the latest kernel?

The fact that it was combined with the uvc gadget patch in the patch
series is the main reason for this delay (see also my upcoming reply
to patch 2/2).

Regards,

	Hans

On 24/01/2023 23:34, Michael Grzeschik wrote:
> Gentle Ping!
> 
> On Fri, Nov 25, 2022 at 04:34:49PM +0100, Michael Grzeschik wrote:
>> For dmabuf import users to be able to use the vaddr from another
>> videobuf2-dma-sg source, the exporter needs to set a proper vaddr on
>> vb2_dma_sg_dmabuf_ops_vmap callback.
>>
>> This patch adds vm_map_ram on map if buf->vaddr was not set, and also
>> adds the vb2_dma_sg_dmabuf_ops_vunmap function to remove the mapping
>> afterwards.
>>
>> Cc: stable <stable@kernel.org>
>> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>>
>> ---
>> v1 -> v2: using vmap and vunmap instead of vm_map_ram and vm_unmap_ram
>>
>> .../media/common/videobuf2/videobuf2-dma-sg.c    | 16 ++++++++++++++++
>> 1 file changed, 16 insertions(+)
>>
>> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
>> index fa69158a65b1fd..dcb8de5ab3e84a 100644
>> --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
>> +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
>> @@ -496,11 +496,26 @@ static int vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf,
>> {
>>     struct vb2_dma_sg_buf *buf = dbuf->priv;
>>
>> +    if (!buf->vaddr)
>> +        buf->vaddr = vmap(buf->pages, buf->num_pages, VM_MAP,
>> +                  PAGE_KERNEL);
>> +
>>     iosys_map_set_vaddr(map, buf->vaddr);
>>
>>     return 0;
>> }
>>
>> +static void vb2_dma_sg_dmabuf_ops_vunmap(struct dma_buf *dbuf,
>> +                      struct iosys_map *map)
>> +{
>> +    struct vb2_dma_sg_buf *buf = dbuf->priv;
>> +
>> +    if (buf->vaddr)
>> +        vunmap(buf->vaddr);
>> +
>> +    buf->vaddr = NULL;
>> +}
>> +
>> static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
>>     struct vm_area_struct *vma)
>> {
>> @@ -515,6 +530,7 @@ static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
>>     .begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access,
>>     .end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access,
>>     .vmap = vb2_dma_sg_dmabuf_ops_vmap,
>> +    .vunmap = vb2_dma_sg_dmabuf_ops_vunmap,
>>     .mmap = vb2_dma_sg_dmabuf_ops_mmap,
>>     .release = vb2_dma_sg_dmabuf_ops_release,
>> };
>> -- 
>> 2.30.2
>>
>
Michael Grzeschik Oct. 31, 2023, 10:46 p.m. UTC | #3
Hi Hans,

On Tue, Jul 18, 2023 at 10:40:57AM +0200, Hans Verkuil wrote:
>I'm going through some old patches in patchwork and found this one.
>Is this patch specifically for the uvc gadget driver, or is it a
>generic fix? If it is the latter (I suspect it is), then can you
>post this as a v3 by itself and rebased to the latest kernel?

I will just send v3 then. It is totally working without other
dependencies. This is long overdue.

>The fact that it was combined with the uvc gadget patch in the patch
>series is the main reason for this delay (see also my upcoming reply
>to patch 2/2).

I will look into this aswell.

Thanks,
Michael
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
index fa69158a65b1fd..dcb8de5ab3e84a 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -496,11 +496,26 @@  static int vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf,
 {
 	struct vb2_dma_sg_buf *buf = dbuf->priv;
 
+	if (!buf->vaddr)
+		buf->vaddr = vmap(buf->pages, buf->num_pages, VM_MAP,
+				  PAGE_KERNEL);
+
 	iosys_map_set_vaddr(map, buf->vaddr);
 
 	return 0;
 }
 
+static void vb2_dma_sg_dmabuf_ops_vunmap(struct dma_buf *dbuf,
+				      struct iosys_map *map)
+{
+	struct vb2_dma_sg_buf *buf = dbuf->priv;
+
+	if (buf->vaddr)
+		vunmap(buf->vaddr);
+
+	buf->vaddr = NULL;
+}
+
 static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
 	struct vm_area_struct *vma)
 {
@@ -515,6 +530,7 @@  static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
 	.begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access,
 	.end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access,
 	.vmap = vb2_dma_sg_dmabuf_ops_vmap,
+	.vunmap = vb2_dma_sg_dmabuf_ops_vunmap,
 	.mmap = vb2_dma_sg_dmabuf_ops_mmap,
 	.release = vb2_dma_sg_dmabuf_ops_release,
 };