All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	Tomasz Figa <tfiga@chromium.org>,
	Dafna Hirschfeld <dafna.hirschfeld@collabora.com>,
	Ricardo Ribalda <ribalda@chromium.org>,
	Christoph Hellwig <hch@lst.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCHv4 8/8] videobuf2: handle non-contiguous DMA allocations
Date: Tue, 17 Aug 2021 20:56:59 +0900	[thread overview]
Message-ID: <YRukCziknzz/3/sV@google.com> (raw)
In-Reply-To: <fd1e8bbe-4cbe-9586-7c8f-0896af043d4a@xs4all.nl>

Hi,

On (21/08/03 12:15), Hans Verkuil wrote:
> >  static void *vb2_dc_vaddr(struct vb2_buffer *vb, void *buf_priv)
> >  {
> >  	struct vb2_dc_buf *buf = buf_priv;
> > -	struct dma_buf_map map;
> > -	int ret;
> >  
> > -	if (!buf->vaddr && buf->db_attach) {
> > -		ret = dma_buf_vmap(buf->db_attach->dmabuf, &map);
> > -		buf->vaddr = ret ? NULL : map.vaddr;
> > +	if (buf->vaddr)
> > +		return buf->vaddr;
> > +
> > +	if (buf->db_attach) {
> > +		struct dma_buf_map map;
> > +
> > +		if (!dma_buf_vmap(buf->db_attach->dmabuf, &map))
> > +			buf->vaddr = map.vaddr;
> > +
> > +		return buf->vaddr;
> >  	}
> >  
> > +	if (!buf->coherent_mem)
> > +		buf->vaddr = dma_vmap_noncontiguous(buf->dev, buf->size,
> > +						    buf->dma_sgt);
> >  	return buf->vaddr;
> >  }
> 
> This function really needs a bunch of comments.
> 
> What I want to see here specifically is under which circumstances this function
> can return NULL.
> 
> - dma_buf_vmap returns an error
> - for non-coherent memory dma_vmap_noncontiguous returns an error
> - coherent memory with DMA_ATTR_NO_KERNEL_MAPPING set.

OK, I added some comments.

> In the latter case, if a buffer with coherent memory and DMA_ATTR_NO_KERNEL_MAPPING
> is exported as a dma_buf, and dma_buf_vmap is called by the importer of this dma-buf,
> what happens then? I think that in that case dma_buf_vmap should return an error?

Should we error out in vb2_dc_vaddr() in this case?

---

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index d4089d0b5ec5..e1d8ae1548fa 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -102,6 +102,9 @@ static void *vb2_dc_vaddr(struct vb2_buffer *vb, void *buf_priv)
        if (buf->db_attach) {
                struct dma_buf_map map;
 
+               if (WARN_ON(buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING))
+                       return NULL;
+
                if (!dma_buf_vmap(buf->db_attach->dmabuf, &map))
                        buf->vaddr = map.vaddr;
 

---


[..]
> > @@ -362,7 +451,7 @@ static int vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf, struct dma_buf_map *map)
> >  {
> >  	struct vb2_dc_buf *buf = dbuf->priv;
> >  
> > -	dma_buf_map_set_vaddr(map, buf->vaddr);
> > +	dma_buf_map_set_vaddr(map, vb2_dc_vaddr(buf->vb, buf));
> 
> vb2_dc_vaddr() can return NULL, shouldn't this function return an error in that case?

Done, thanks.

> BTW, looking at where vb2_plane_vaddr() is called in drivers I notice that most (all?)
> drivers do not check for NULL. Somewhat scary, to be honest. That's a separate issue, though.

I may have some time in the future and can add missing if-s to the
drivers.

  reply	other threads:[~2021-08-17 11:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27  7:05 [PATCHv4 0/8] videobuf2: support new noncontiguous DMA API Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 1/8] videobuf2: rework vb2_mem_ops API Sergey Senozhatsky
2021-08-03  8:08   ` Hans Verkuil
2021-08-17 10:41     ` Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 2/8] videobuf2: inverse buffer cache_hints flags Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 3/8] videobuf2: split buffer cache_hints initialisation Sergey Senozhatsky
2021-08-03  8:10   ` Hans Verkuil
2021-08-17 10:41     ` Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 4/8] videobuf2: move cache_hints handling to allocators Sergey Senozhatsky
2021-08-03  8:11   ` Hans Verkuil
2021-08-17 10:42     ` Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 5/8] videobuf2: add V4L2_MEMORY_FLAG_NON_COHERENT flag Sergey Senozhatsky
2021-08-03  8:12   ` Hans Verkuil
2021-08-17 10:42     ` Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 6/8] videobuf2: add queue memory coherency parameter Sergey Senozhatsky
2021-08-03  8:29   ` Hans Verkuil
2021-08-17 10:43     ` Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 7/8] videobuf2: handle V4L2_MEMORY_FLAG_NON_COHERENT flag Sergey Senozhatsky
2021-08-03  8:31   ` Hans Verkuil
2021-08-17 10:43     ` Sergey Senozhatsky
2021-07-27  7:05 ` [PATCHv4 8/8] videobuf2: handle non-contiguous DMA allocations Sergey Senozhatsky
2021-08-03  8:33   ` Hans Verkuil
2021-08-03  8:39     ` Hans Verkuil
2021-08-23 10:28       ` Sergey Senozhatsky
2021-08-23 10:27     ` Sergey Senozhatsky
2021-08-03 10:15   ` Hans Verkuil
2021-08-17 11:56     ` Sergey Senozhatsky [this message]
2021-08-18  9:20       ` Tomasz Figa
2021-08-23 10:29     ` Sergey Senozhatsky

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=YRukCziknzz/3/sV@google.com \
    --to=senozhatsky@chromium.org \
    --cc=dafna.hirschfeld@collabora.com \
    --cc=hch@lst.de \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.org \
    --cc=tfiga@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.