media: videobuf2-dma-contig: Invalidate vmap range before DMA range

Message ID 20220119081417.20604-1-senozhatsky@chromium.org (mailing list archive)
State Accepted, archived
Delegated to: Hans Verkuil
Headers
Series media: videobuf2-dma-contig: Invalidate vmap range before DMA range |

Commit Message

Sergey Senozhatsky Jan. 19, 2022, 8:14 a.m. UTC
  Christoph suggests [1] that invalidating vmap range before
direct mapping range makes more sense.

[1]: https://lore.kernel.org/all/20220111085958.GA22795@lst.de/
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 .../media/common/videobuf2/videobuf2-dma-contig.c    | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
  

Comments

Marek Szyprowski Jan. 19, 2022, 8:32 a.m. UTC | #1
On 19.01.2022 09:14, Sergey Senozhatsky wrote:
> Christoph suggests [1] that invalidating vmap range before
> direct mapping range makes more sense.
>
> [1]: https://lore.kernel.org/all/20220111085958.GA22795@lst.de/
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>

Right.

Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
>   .../media/common/videobuf2/videobuf2-dma-contig.c    | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index 7c4096e62173..0e3f264122af 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -132,12 +132,12 @@ static void vb2_dc_prepare(void *buf_priv)
>   	if (!buf->non_coherent_mem)
>   		return;
>   
> -	/* For both USERPTR and non-coherent MMAP */
> -	dma_sync_sgtable_for_device(buf->dev, sgt, buf->dma_dir);
> -
>   	/* Non-coherent MMAP only */
>   	if (buf->vaddr)
>   		flush_kernel_vmap_range(buf->vaddr, buf->size);
> +
> +	/* For both USERPTR and non-coherent MMAP */
> +	dma_sync_sgtable_for_device(buf->dev, sgt, buf->dma_dir);
>   }
>   
>   static void vb2_dc_finish(void *buf_priv)
> @@ -152,12 +152,12 @@ static void vb2_dc_finish(void *buf_priv)
>   	if (!buf->non_coherent_mem)
>   		return;
>   
> -	/* For both USERPTR and non-coherent MMAP */
> -	dma_sync_sgtable_for_cpu(buf->dev, sgt, buf->dma_dir);
> -
>   	/* Non-coherent MMAP only */
>   	if (buf->vaddr)
>   		invalidate_kernel_vmap_range(buf->vaddr, buf->size);
> +
> +	/* For both USERPTR and non-coherent MMAP */
> +	dma_sync_sgtable_for_cpu(buf->dev, sgt, buf->dma_dir);
>   }
>   
>   /*********************************************/

Best regards
  
Christoph Hellwig Jan. 20, 2022, 7:50 a.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
  

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index 7c4096e62173..0e3f264122af 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -132,12 +132,12 @@  static void vb2_dc_prepare(void *buf_priv)
 	if (!buf->non_coherent_mem)
 		return;
 
-	/* For both USERPTR and non-coherent MMAP */
-	dma_sync_sgtable_for_device(buf->dev, sgt, buf->dma_dir);
-
 	/* Non-coherent MMAP only */
 	if (buf->vaddr)
 		flush_kernel_vmap_range(buf->vaddr, buf->size);
+
+	/* For both USERPTR and non-coherent MMAP */
+	dma_sync_sgtable_for_device(buf->dev, sgt, buf->dma_dir);
 }
 
 static void vb2_dc_finish(void *buf_priv)
@@ -152,12 +152,12 @@  static void vb2_dc_finish(void *buf_priv)
 	if (!buf->non_coherent_mem)
 		return;
 
-	/* For both USERPTR and non-coherent MMAP */
-	dma_sync_sgtable_for_cpu(buf->dev, sgt, buf->dma_dir);
-
 	/* Non-coherent MMAP only */
 	if (buf->vaddr)
 		invalidate_kernel_vmap_range(buf->vaddr, buf->size);
+
+	/* For both USERPTR and non-coherent MMAP */
+	dma_sync_sgtable_for_cpu(buf->dev, sgt, buf->dma_dir);
 }
 
 /*********************************************/