From: Daniel Vetter <daniel@ffwll.ch>
To: InKi Dae <daeinki@gmail.com>
Cc: Sumit Semwal <sumit.semwal@ti.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org,
linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org,
linux-media@vger.kernel.org, linux@arm.linux.org.uk,
arnd@arndb.de, jesse.barker@linaro.org, m.szyprowski@samsung.com,
rob@ti.com, t.stanislaws@samsung.com,
Sumit Semwal <sumit.semwal@linaro.org>,
daniel@ffwll.ch
Subject: Re: [RFC v2 1/2] dma-buf: Introduce dma buffer sharing mechanism
Date: Mon, 9 Jan 2012 11:27:26 +0100 [thread overview]
Message-ID: <20120109102726.GD3723@phenom.ffwll.local> (raw)
In-Reply-To: <CAAQKjZMEsuib18RYE7OvZPUqhKnvrZ8i3+EMuZSXr9KPVygo_Q@mail.gmail.com>
On Mon, Jan 09, 2012 at 07:10:25PM +0900, InKi Dae wrote:
> 2012/1/9 Daniel Vetter <daniel@ffwll.ch>:
> > On Mon, Jan 09, 2012 at 03:20:48PM +0900, InKi Dae wrote:
> >> I has test dmabuf based drm gem module for exynos and I found one problem.
> >> you can refer to this test repository:
> >> http://git.infradead.org/users/kmpark/linux-samsung/shortlog/refs/heads/exynos-drm-dmabuf
> >>
> >> at this repository, I added some exception codes for resource release
> >> in addition to Dave's patch sets.
> >>
> >> let's suppose we use dmabuf based vb2 and drm gem with physically
> >> continuous memory(no IOMMU) and we try to share allocated buffer
> >> between them(v4l2 and drm driver).
> >>
> >> 1. request memory allocation through drm gem interface.
> >> 2. request DRM_SET_PRIME ioctl with the gem handle to get a fd to the
> >> gem object.
> >> - internally, private gem based dmabuf moudle calls drm_buf_export()
> >> to register allocated gem object to fd.
> >> 3. request qbuf with the fd(got from 2) and DMABUF type to set the
> >> buffer to v4l2 based device.
> >> - internally, vb2 plug in module gets a buffer to the fd and then
> >> calls dmabuf->ops->map_dmabuf() callback to get the sg table
> >> containing physical memory info to the gem object. and then the
> >> physical memory info would be copied to vb2_xx_buf object.
> >> for DMABUF feature for v4l2 and videobuf2 framework, you can refer to
> >> this repository:
> >> git://github.com/robclark/kernel-omap4.git drmplane-dmabuf
> >>
> >> after that, if v4l2 driver want to release vb2_xx_buf object with
> >> allocated memory region by user request, how should we do?. refcount
> >> to vb2_xx_buf is dependent on videobuf2 framework. so when vb2_xx_buf
> >> object is released videobuf2 framework don't know who is using the
> >> physical memory region. so this physical memory region is released and
> >> when drm driver tries to access the region or to release it also, a
> >> problem would be induced.
> >>
> >> for this problem, I added get_shared_cnt() callback to dma-buf.h but
> >> I'm not sure that this is good way. maybe there may be better way.
> >> if there is any missing point, please let me know.
> >
> > The dma_buf object needs to hold a reference on the underlying
> > (necessarily reference-counted) buffer object when the exporter creates
> > the dma_buf handle. This reference should then get dropped in the
> > exporters dma_buf->ops->release() function, which is only getting called
> > when the last reference to the dma_buf disappears.
> >
>
> when the exporter creates the dma_buf handle(for example, gem -> fd),
> I think the refcount of gem object should be increased at this point,
> and decreased by dma_buf->ops->release() again because when the
> dma_buf is created and dma_buf_export() is called, this dma_buf refers
> to the gem object one time. and in case of inporter(fd -> gem),
> file->f_count of the dma_buf is increased and then when this gem
> object is released by user request such as drm close or
> drn_gem_close_ioctl, dma_buf_put() should be called by
> dma_buf->ops->detach() to decrease file->f_count again because the gem
> object refers to the dma_buf. for this, you can refer to my test
> repository I mentioned above. but the problem is that when a buffer is
> released by one side, another can't know whether the buffer already
> was released or not.
Nope, dma_buf_put should not be called by ->detach. The importer gets his
reference when importing the dma_buf and needs to drop that reference
himself when it's done using the buffer by calling dma_buf_put (i.e. after
the last ->detach call). I think adding separate reference counting to
->attach and ->detach is a waste of time and only papers over buggy
importers.
Additionally the importer does _not_ control the lifetime of an dma_buf
object and it's underlying backing storage. It hence may _never_ free the
backing storage itself, that's the job of the exporter.
With that cleared up, referencing the exporters underlying buffer object
from the dma_buf will just do the right thing.
> note : in case of sharing a buffer between v4l2 and drm driver, the
> memory info would be copied vb2_xx_buf to xx_gem or xx_gem to
> vb2_xx_buf through sg table. in this case, only memory info is used to
> share, not some objects.
Hm, maybe I need to take a look at the currently proposed v4l dma_buf
patches ;-) atm I don't have an idea what exactly you're talking about.
Yours, Daniel
--
Daniel Vetter
Mail: daniel@ffwll.ch
Mobile: +41 (0)79 365 57 48
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-01-09 10:25 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 8:57 [RFC v2 0/2] Introduce DMA " Sumit Semwal
2011-12-02 8:57 ` [RFC v2 1/2] dma-buf: Introduce dma " Sumit Semwal
2011-12-02 17:11 ` 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 [this message]
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
2012-01-11 1:08 ` InKi Dae
2011-12-02 8:57 ` [RFC v2 2/2] dma-buf: Documentation for buffer sharing framework Sumit Semwal
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=20120109102726.GD3723@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=arnd@arndb.de \
--cc=daeinki@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jesse.barker@linaro.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@arm.linux.org.uk \
--cc=m.szyprowski@samsung.com \
--cc=rob@ti.com \
--cc=sumit.semwal@linaro.org \
--cc=sumit.semwal@ti.com \
--cc=t.stanislaws@samsung.com \
/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