From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Tomasz Figa <tfiga@chromium.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>,
Marek Szyprowski <m.szyprowski@samsung.com>,
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: [PATCHv5 8/8] videobuf2: handle non-contiguous DMA allocations
Date: Thu, 9 Sep 2021 14:12:09 +0900 [thread overview]
Message-ID: <YTmXqZvokzsKwXLT@google.com> (raw)
In-Reply-To: <YSzZUjZvtW11AFGE@chromium.org>
Hi Tomasz,
On (21/08/30 22:12), Tomasz Figa wrote:
[..]
> > + /* This takes care of DMABUF and user-enforced cache sync hint */
> > if (buf->vb->skip_cache_sync_on_prepare)
> > return;
> >
> > + /*
> > + * Coherent MMAP buffers do not need to be synced, unlike USERPTR
> > + * and non-coherent MMAP buffers.
> > + */
> > + if (buf->vb->memory == V4L2_MEMORY_MMAP && !buf->non_coherent_mem)
> > + return;
>
> nit: Would it make sense to also set buf->non_coherent_mem to 1 in
> vb2_dc_get_userptr() and simplify this check?
Sounds good. Done.
> > +
> > if (!sgt)
>
> Is there a case when this would be true at this point?
We always set ->dma_sgt only for non-coherent buffers at allocation time.
The rest (including this if-condition) is form the upstream code.
Why was it added there. For USERPTR and coherent MMAP?
> > 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->non_coherent_mem && buf->vaddr)
>
> Then this could check only for buf->vaddr.
>
> > + flush_kernel_vmap_range(buf->vaddr, buf->size);
> > }
> >
> > static void vb2_dc_finish(void *buf_priv)
> > @@ -115,13 +152,26 @@ static void vb2_dc_finish(void *buf_priv)
>
> Same comments as for _prepare.
Done.
> > +static int vb2_dc_alloc_non_coherent(struct vb2_dc_buf *buf)
> > +{
> > + struct vb2_queue *q = buf->vb->vb2_queue;
> > +
> > + buf->dma_sgt = dma_alloc_noncontiguous(buf->dev,
> > + buf->size,
> > + buf->dma_dir,
> > + GFP_KERNEL | q->gfp_flags,
> > + buf->attrs);
> > + if (!buf->dma_sgt)
> > + return -ENOMEM;
> > +
> > + buf->dma_addr = sg_dma_address(buf->dma_sgt->sgl);
> > +
> > + /*
> > + * For requests that need kernel mapping (DMA_ATTR_NO_KERNEL_MAPPING
> > + * bit is cleared) we perform dma_vmap_noncontiguous() in vb2_dc_vaddr()
> > + */
>
> Current code now ignores the attribute, so this comment isn't entirely
> accurate. Maybe it's better to remove the mention of the attribute and
> instead say that for non_coherent buffers the kernel mapping is created on
> demand?
Done.
> > static int vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf, struct dma_buf_map *map)
> > {
> > - struct vb2_dc_buf *buf = dbuf->priv;
> > + struct vb2_dc_buf *buf;
> > + void *vaddr;
> > +
> > + buf = dbuf->priv;
> > + vaddr = vb2_dc_vaddr(buf->vb, buf);
> > + if (!vaddr)
> > + return -EINVAL;
> >
> > - dma_buf_map_set_vaddr(map, buf->vaddr);
> > + dma_buf_map_set_vaddr(map, vaddr);
> >
> > return 0;
> > }
> > @@ -390,6 +499,9 @@ static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf)
> > int ret;
> > struct sg_table *sgt;
> >
> > + if (buf->non_coherent_mem)
> > + return buf->dma_sgt;
>
> Wouldn't this lead to a double free in vb2_dc_put()?
Most likely. Done, thank you.
prev parent reply other threads:[~2021-09-09 5:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-23 12:22 [PATCHv5 0/8] videobuf2: support new noncontiguous DMA API Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 1/8] videobuf2: rework vb2_mem_ops API Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 2/8] videobuf2: inverse buffer cache_hints flags Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 3/8] videobuf2: split buffer cache_hints initialisation Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 4/8] videobuf2: move cache_hints handling to allocators Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 5/8] videobuf2: add V4L2_MEMORY_FLAG_NON_COHERENT flag Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 6/8] videobuf2: add queue memory coherency parameter Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 7/8] videobuf2: handle V4L2_MEMORY_FLAG_NON_COHERENT flag Sergey Senozhatsky
2021-08-23 12:22 ` [PATCHv5 8/8] videobuf2: handle non-contiguous DMA allocations Sergey Senozhatsky
2021-08-30 13:12 ` Tomasz Figa
2021-09-09 5:12 ` Sergey Senozhatsky [this message]
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=YTmXqZvokzsKwXLT@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=m.szyprowski@samsung.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox