From: daeinki@gmail.com (InKi Dae)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC v2 1/2] dma-buf: Introduce dma buffer sharing mechanism
Date: Tue, 10 Jan 2012 18:19:08 +0900 [thread overview]
Message-ID: <CAAQKjZOxMR-s3Fc9toXspN_a7azj==4mzAnCffWio8oEXyC9pQ@mail.gmail.com> (raw)
In-Reply-To: <CAAQKjZPH10a0-yjyUrqPYWv2nyZ9m2KJ6nm2d+pAqRb2CxRwsQ@mail.gmail.com>
2012/1/10 InKi Dae <daeinki@gmail.com>:
> 2012/1/10 Semwal, Sumit <sumit.semwal@ti.com>:
>> On Tue, Jan 10, 2012 at 7:44 AM, Rob Clark <rob@ti.com> wrote:
>>> On Mon, Jan 9, 2012 at 7:34 PM, InKi Dae <daeinki@gmail.com> wrote:
>>>> 2012/1/10 Rob Clark <rob@ti.com>:
>>>> at least with no IOMMU, the memory information(containing physical
>>>> memory address) would be copied to vb2_xx_buf object if drm gem
>>>> exported its own buffer and vb2 wants to use that buffer at this time,
>>>> sg table is used to share that buffer. and the problem I pointed out
>>>> is that this buffer(also physical memory region) could be released by
>>>> vb2 framework(as you know, vb2_xx_buf object and the memory region for
>>>> buf->dma_addr pointing) but the Exporter(drm gem) couldn't know that
>>>> so some problems would be induced once drm gem tries to release or
>>>> access that buffer. and I have tried to resolve this issue adding
>>>> get_shared_cnt() callback to dma-buf.h but I'm not sure that this is
>>>> good way. maybe there would be better way.
>> Hi Inki,
>> As also mentioned in the documentation patch, importer (the user of
>> the buffer) - in this case for current RFC patches on
>> v4l2-as-a-user[1] vb2 framework - shouldn't release the backing memory
>> of the buffer directly - it should only use the dma-buf callbacks in
>> the right sequence to let the exporter know that it is done using this
>> buffer, so the exporter can release it if allowed and needed.
>
> thank you for your comments.:) and below are some tables about dmabuf
> operations with ideal use and these tables indicate reference count of
> when buffer is created, shared and released. so if there are any
> problems, please let me know. P.S. these are just simple cases so
> there would be others.
>
>
> in case of using only drm gem and dmabuf,
>
> operations ? ? ? ? ? ? ? ? ? ? ? gem refcount ? ?file f_count ? buf refcount
> ------------------------------------------------------------------------------------------------
> 1. gem create ? ? ? ? ? ? ? ? ? A:1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? A:0
> 2. export(handle A -> fd) ? ?A:2 ? ? ? ? ? ? ? ?A:1 ? ? ? ? ? ? ?A:0
> 3. import(fd -> handle B) ? ?A:2, B:1 ? ? ? ? A:2 ? ? ? ? ? ? ?A:1
> 4. file close(A) ? ? ? ? ? ? ? ? ?A:2, B:1 ? ? ? ? A:1 ? ? ? ? ? ? ?A:1
> 5. gem close(A) ? ? ? ? ? ? ? ?A:1, B:1 ? ? ? ? A:1 ? ? ? ? ? ? ?A:1
> 6. gem close(B) ? ? ? ? ? ? ? ?A:1, B:0 ? ? ? ? A:1 ? ? ? ? ? ? ?A:0
> 7. file close(A) ? ? ? ? ? ? ? ? ?A:0 ? ? ? ? ? ? ? ?A:0
> -----------------------------------------------------------------------------------------------
> 3. handle B shares the buf of handle A.
> 6. release handle B but its buf.
> 7. release gem handle A and dmabuf of file A and also physical memory region.
>
>
> and in case of using drm gem, vb2 and dmabuf,
>
> operations ? ? ? ? ? ? ? ? ?gem, vb2 refcount ? ?file f_count ? buf refcount
> ------------------------------------------------------------------------------------------------
> 1. gem create ? ? ? ? ? ? ? ? ? A:1 ? ? ? ? ? ? ? ? A:0
> ? (GEM side)
> 2. export(handle A -> fd) ? ?A:2 ? ? ? ? ? ? ? ? A:1 ? ? ? ? ? ? ?A:0
> ? (GEM side)
> 3. import(fd -> handle B) ? ?A:2, B:1 ? ? ? ? ?A:2 ? ? ? ? ? ? ?A:1
> ? (VB2 side)
> 4. file close(A) ? ? ? ? ? ? ? ? ?A:2, B:1 ? ? ? ? ?A:1 ? ? ? ? ? ? ?A:1
> ? (VB2 side)
> 5. vb2 close(B) ? ? ? ? ? ? ? ? A:2, B:0 ? ? ? ? ?A:1 ? ? ? ? ? ? ?A:0
> ? (VB2 side)
> 6. gem close(A) ? ? ? ? ? ? ? ?A:1 ? ? ? ? ? ? ? ?A:1 ? ? ? ? ? ? ?A:0
> ? (GEM side)
> 7. file close(A) ? ? ? ? ? ? ? ? ?A:0 ? ? ? ? ? ? ? ?A:0
> ? (GEM side)
> ------------------------------------------------------------------------------------------------
> 3. vb2 handle B is shared with the buf of gem handle A.
> 5. release vb2 handle B and decrease refcount of the buf pointed by it.
> 7. release gem handle A and dmabuf of file A and also physical memory region.
>
Ah, sorry, it seems that file close shouldn't be called because
file->f_count of the file would be dropped by Importer and if f_count
is 0 then the file would be released by fput() so I'm not sure but
again:
in case of using only drm gem and dmabuf,
operations gem refcount file f_count buf refcount
--------------------------------------------------------------------------------------------------
1. gem create(A) A:1 A:0
2. export(handle A -> fd) A:2 A:1 A:0
3. import(fd -> handle B) A:2, B:1 A:2 A:1
4. gem close(B) A:2, B:release A:1 A:0
5. gem close(A) A:1, A:1 A:0
6. gem close(A) A:release A:release A:release
-------------------------------------------------------------------------------------------------
and in case of using drm gem, vb2 and dmabuf,
operations gem, vb2 refcount file f_count buf refcount
------------------------------------------------------------------------------------------------
1. gem create A:1 A:0 A:0
(GEM side)
2. export(handle A -> fd) A:2 A:1 A:0
(GEM side)
3. import(fd -> handle B) A:2, B:1 A:2 A:1
(VB2 side)
5. vb2 close(B) A:2, B:release A:1 A:0
(VB2 side)
6. gem close(A) A:1 A:1 A:0
(GEM side)
6. gem close(A) A:release A:release A:release
(GEM side)
------------------------------------------------------------------------------------------------
>>>
>>> the exporter (in this case your driver's drm/gem bits) shouldn't
>>> release that mapping / sgtable until the importer (in this case v4l2)
>>> calls dma_buf_unmap fxn..
>>>
>>> It would be an error if the importer did a dma_buf_put() without first
>>> calling dma_buf_unmap_attachment() (if currently mapped) and then
>>> dma_buf_detach() (if currently attached). ?Perhaps somewhere there
>>> should be some sanity checking debug code which could be enabled to do
>>> a WARN_ON() if the importer does the wrong thing. ?It shouldn't really
>>> be part of the API, I don't think, but it actually does seem like a
>>> good thing, esp. as new drivers start trying to use dmabuf, to have
>>> some debug options which could be enabled.
>>>
>>> It is entirely possible that something was missed on the vb2 patches,
>>> but the way it is intended to work is like this:
>>> https://github.com/robclark/kernel-omap4/blob/0961428143cd10269223e3d0f24bc3a66a96185f/drivers/media/video/videobuf2-core.c#L92
>>>
>>> where it does a detach() before the dma_buf_put(), and the vb2-contig
>>> backend checks here that it is also unmapped():
>>> https://github.com/robclark/kernel-omap4/blob/0961428143cd10269223e3d0f24bc3a66a96185f/drivers/media/video/videobuf2-dma-contig.c#L251
>>
>> The proposed RFC for V4L2 adaptation at [1] does exactly the same
>> thing; detach() before dma_buf_put(), and check in vb2-contig backend
>> for unmapped() as mentioned above.
>>
>>>
>>> BR,
>>> -R
>>>
>> BR,
>> Sumit.
>>
>> [1]: V4l2 as a dma-buf user RFC:
>> http://comments.gmane.org/gmane.linux.drivers.video-input-infrastructure/42966
next prev parent reply other threads:[~2012-01-10 9:19 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 8:57 [RFC v2 0/2] Introduce DMA buffer sharing mechanism Sumit Semwal
[not found] ` <1322816252-19955-2-git-send-email-sumit.semwal@ti.com>
2011-12-02 17:11 ` [RFC v2 1/2] dma-buf: Introduce dma " Konrad Rzeszutek Wilk
2011-12-05 9:48 ` Semwal, Sumit
2011-12-05 17:18 ` Arnd Bergmann
2011-12-05 18:55 ` Daniel Vetter
2011-12-05 19:29 ` Arnd Bergmann
2011-12-05 20:58 ` Daniel Vetter
2011-12-05 22:04 ` Arnd Bergmann
2011-12-05 22:33 ` Daniel Vetter
2011-12-05 20:46 ` Rob Clark
2011-12-05 21:23 ` Daniel Vetter
2011-12-05 22:11 ` Rob Clark
2011-12-05 22:33 ` Daniel Vetter
2011-12-06 13:16 ` Arnd Bergmann
2011-12-06 15:28 ` Daniel Vetter
2011-12-07 13:27 ` Semwal, Sumit
2011-12-07 13:40 ` Arnd Bergmann
2011-12-08 21:44 ` [Linaro-mm-sig] " Daniel Vetter
2011-12-09 14:13 ` Arnd Bergmann
2011-12-09 14:24 ` Alan Cox
2011-12-10 4:01 ` Daniel Vetter
2011-12-12 16:48 ` Arnd Bergmann
2011-12-19 6:16 ` Semwal, Sumit
2011-12-20 15:41 ` Arnd Bergmann
2011-12-20 16:41 ` Rob Clark
2011-12-20 17:14 ` Daniel Vetter
2011-12-21 17:27 ` Arnd Bergmann
2011-12-21 19:04 ` Daniel Vetter
2011-12-23 10:00 ` Semwal, Sumit
2011-12-23 17:10 ` Rob Clark
2011-12-20 9:03 ` Sakari Ailus
2011-12-20 15:36 ` Arnd Bergmann
2012-01-01 20:53 ` Sakari Ailus
2012-01-01 23:12 ` Rob Clark
2011-12-13 13:33 ` Hans Verkuil
2011-12-05 22:09 ` Arnd Bergmann
2011-12-05 22:15 ` Rob Clark
2011-12-05 22:35 ` Rob Clark
2011-12-07 6:35 ` Semwal, Sumit
2011-12-07 10:11 ` Arnd Bergmann
2011-12-07 11:02 ` Semwal, Sumit
2011-12-07 11:34 ` Arnd Bergmann
2011-12-09 22:50 ` [Linaro-mm-sig] " Robert Morell
2011-12-10 11:13 ` Mauro Carvalho Chehab
2011-12-12 22:44 ` Robert Morell
2011-12-13 15:10 ` Arnd Bergmann
2011-12-20 2:05 ` Robert Morell
2011-12-20 14:29 ` Anca Emanuel
2012-01-09 6:20 ` InKi Dae
2012-01-09 8:10 ` Daniel Vetter
2012-01-09 8:11 ` [Linaro-mm-sig] " Dave Airlie
2012-01-09 10:10 ` InKi Dae
2012-01-09 10:27 ` Daniel Vetter
2012-01-09 12:06 ` InKi Dae
2012-01-09 16:02 ` Daniel Vetter
2012-01-09 15:17 ` Rob Clark
2012-01-10 1:34 ` InKi Dae
2012-01-10 2:14 ` Rob Clark
2012-01-10 6:09 ` Semwal, Sumit
2012-01-10 7:28 ` InKi Dae
2012-01-10 9:19 ` InKi Dae [this message]
2012-01-11 1:08 ` InKi Dae
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='CAAQKjZOxMR-s3Fc9toXspN_a7azj==4mzAnCffWio8oEXyC9pQ@mail.gmail.com' \
--to=daeinki@gmail.com \
--cc=linux-arm-kernel@lists.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;
as well as URLs for NNTP newsgroup(s).