[PATCH v3 8/9] media: videobuf2: Stop using internal dma-buf lock

Hans Verkuil hverkuil at xs4all.nl
Wed Aug 24 10:32:51 UTC 2022


Nice!

Acked-by: Hans Verkuil <hverkuil-cisco at xs4all.nl>

Regards,

	Hans

On 24/08/2022 12:22, Dmitry Osipenko wrote:
> All drivers that use dma-bufs have been moved to the updated locking
> specification and now dma-buf reservation is guaranteed to be locked
> by importers during the mapping operations. There is no need to take
> the internal dma-buf lock anymore. Remove locking from the videobuf2
> memory allocators.
> 
> Acked-by: Tomasz Figa <tfiga at chromium.org>
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko at collabora.com>
> ---
>  drivers/media/common/videobuf2/videobuf2-dma-contig.c | 11 +----------
>  drivers/media/common/videobuf2/videobuf2-dma-sg.c     | 11 +----------
>  drivers/media/common/videobuf2/videobuf2-vmalloc.c    | 11 +----------
>  3 files changed, 3 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index de762dbdaf78..2c69bf0470e7 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -382,18 +382,12 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
>  	struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
>  {
>  	struct vb2_dc_attachment *attach = db_attach->priv;
> -	/* stealing dmabuf mutex to serialize map/unmap operations */
> -	struct mutex *lock = &db_attach->dmabuf->lock;
>  	struct sg_table *sgt;
>  
> -	mutex_lock(lock);
> -
>  	sgt = &attach->sgt;
>  	/* return previously mapped sg table */
> -	if (attach->dma_dir == dma_dir) {
> -		mutex_unlock(lock);
> +	if (attach->dma_dir == dma_dir)
>  		return sgt;
> -	}
>  
>  	/* release any previous cache */
>  	if (attach->dma_dir != DMA_NONE) {
> @@ -409,14 +403,11 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
>  	if (dma_map_sgtable(db_attach->dev, sgt, dma_dir,
>  			    DMA_ATTR_SKIP_CPU_SYNC)) {
>  		pr_err("failed to map scatterlist\n");
> -		mutex_unlock(lock);
>  		return ERR_PTR(-EIO);
>  	}
>  
>  	attach->dma_dir = dma_dir;
>  
> -	mutex_unlock(lock);
> -
>  	return sgt;
>  }
>  
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> index 39e11600304a..e63e718c0bf7 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> @@ -424,18 +424,12 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
>  	struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
>  {
>  	struct vb2_dma_sg_attachment *attach = db_attach->priv;
> -	/* stealing dmabuf mutex to serialize map/unmap operations */
> -	struct mutex *lock = &db_attach->dmabuf->lock;
>  	struct sg_table *sgt;
>  
> -	mutex_lock(lock);
> -
>  	sgt = &attach->sgt;
>  	/* return previously mapped sg table */
> -	if (attach->dma_dir == dma_dir) {
> -		mutex_unlock(lock);
> +	if (attach->dma_dir == dma_dir)
>  		return sgt;
> -	}
>  
>  	/* release any previous cache */
>  	if (attach->dma_dir != DMA_NONE) {
> @@ -446,14 +440,11 @@ static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
>  	/* mapping to the client with new direction */
>  	if (dma_map_sgtable(db_attach->dev, sgt, dma_dir, 0)) {
>  		pr_err("failed to map scatterlist\n");
> -		mutex_unlock(lock);
>  		return ERR_PTR(-EIO);
>  	}
>  
>  	attach->dma_dir = dma_dir;
>  
> -	mutex_unlock(lock);
> -
>  	return sgt;
>  }
>  
> diff --git a/drivers/media/common/videobuf2/videobuf2-vmalloc.c b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
> index 7831bf545874..41db707e43a4 100644
> --- a/drivers/media/common/videobuf2/videobuf2-vmalloc.c
> +++ b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
> @@ -267,18 +267,12 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
>  	struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
>  {
>  	struct vb2_vmalloc_attachment *attach = db_attach->priv;
> -	/* stealing dmabuf mutex to serialize map/unmap operations */
> -	struct mutex *lock = &db_attach->dmabuf->lock;
>  	struct sg_table *sgt;
>  
> -	mutex_lock(lock);
> -
>  	sgt = &attach->sgt;
>  	/* return previously mapped sg table */
> -	if (attach->dma_dir == dma_dir) {
> -		mutex_unlock(lock);
> +	if (attach->dma_dir == dma_dir)
>  		return sgt;
> -	}
>  
>  	/* release any previous cache */
>  	if (attach->dma_dir != DMA_NONE) {
> @@ -289,14 +283,11 @@ static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
>  	/* mapping to the client with new direction */
>  	if (dma_map_sgtable(db_attach->dev, sgt, dma_dir, 0)) {
>  		pr_err("failed to map scatterlist\n");
> -		mutex_unlock(lock);
>  		return ERR_PTR(-EIO);
>  	}
>  
>  	attach->dma_dir = dma_dir;
>  
> -	mutex_unlock(lock);
> -
>  	return sgt;
>  }
>  


More information about the lima mailing list