linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Souptick Joarder <jrdr.linux@gmail.com>,
	akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com,
	pawel@osciak.com, kyungmin.park@samsung.com, mchehab@kernel.org,
	linux@armlinux.org.uk, robin.murphy@arm.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCHv2 7/9] videobuf2/videobuf2-dma-sg.c: Convert to use vm_insert_range
Date: Thu, 31 Jan 2019 11:47:00 +0100	[thread overview]
Message-ID: <69e5a305-9d3b-b719-d1c6-8016e955b538@samsung.com> (raw)
In-Reply-To: <20190131031310.GA2372@jordon-HP-15-Notebook-PC>

Hi Souptick,

On 2019-01-31 04:13, Souptick Joarder wrote:
> Convert to use vm_insert_range to map range of kernel memory
> to user vma.
>
> vm_pgoff is treated in V4L2 API as a 'cookie' to select a buffer,
> not as a in-buffer offset by design and it always want to mmap a
> whole buffer from its beginning.
>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>

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

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

> ---
>  drivers/media/common/videobuf2/videobuf2-core.c    |  7 +++++++
>  .../media/common/videobuf2/videobuf2-dma-contig.c  |  6 ------
>  drivers/media/common/videobuf2/videobuf2-dma-sg.c  | 22 ++++++----------------
>  3 files changed, 13 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index 70e8c33..ca4577a 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -2175,6 +2175,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>  		goto unlock;
>  	}
>  
> +	/*
> +	 * vm_pgoff is treated in V4L2 API as a 'cookie' to select a buffer,
> +	 * not as a in-buffer offset. We always want to mmap a whole buffer
> +	 * from its beginning.
> +	 */
> +	vma->vm_pgoff = 0;
> +
>  	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
>  
>  unlock:
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index aff0ab7..46245c5 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -186,12 +186,6 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma)
>  		return -EINVAL;
>  	}
>  
> -	/*
> -	 * dma_mmap_* uses vm_pgoff as in-buffer offset, but we want to
> -	 * map whole buffer
> -	 */
> -	vma->vm_pgoff = 0;
> -
>  	ret = dma_mmap_attrs(buf->dev, vma, buf->cookie,
>  		buf->dma_addr, buf->size, buf->attrs);
>  
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> index 015e737..a800200 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> @@ -328,28 +328,18 @@ static unsigned int vb2_dma_sg_num_users(void *buf_priv)
>  static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma)
>  {
>  	struct vb2_dma_sg_buf *buf = buf_priv;
> -	unsigned long uaddr = vma->vm_start;
> -	unsigned long usize = vma->vm_end - vma->vm_start;
> -	int i = 0;
> +	int err;
>  
>  	if (!buf) {
>  		printk(KERN_ERR "No memory to map\n");
>  		return -EINVAL;
>  	}
>  
> -	do {
> -		int ret;
> -
> -		ret = vm_insert_page(vma, uaddr, buf->pages[i++]);
> -		if (ret) {
> -			printk(KERN_ERR "Remapping memory, error: %d\n", ret);
> -			return ret;
> -		}
> -
> -		uaddr += PAGE_SIZE;
> -		usize -= PAGE_SIZE;
> -	} while (usize > 0);
> -
> +	err = vm_insert_range(vma, buf->pages, buf->num_pages);
> +	if (err) {
> +		printk(KERN_ERR "Remapping memory, error: %d\n", err);
> +		return err;
> +	}
>  
>  	/*
>  	 * Use common vm_area operations to track buffer refcount.

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


           reply	other threads:[~2019-01-31 10:47 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20190131031310.GA2372@jordon-HP-15-Notebook-PC>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69e5a305-9d3b-b719-d1c6-8016e955b538@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=jrdr.linux@gmail.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@armlinux.org.uk \
    --cc=mchehab@kernel.org \
    --cc=mhocko@suse.com \
    --cc=pawel@osciak.com \
    --cc=robin.murphy@arm.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox