From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Inki Dae <daeinki@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@canonical.com>,
linux-fbdev <linux-fbdev@vger.kernel.org>,
Kyungmin Park <kyungmin.park@samsung.com>,
DRI mailing list <dri-devel@lists.freedesktop.org>,
Rob Clark <robdclark@gmail.com>,
"myungjoo.ham" <myungjoo.ham@samsung.com>,
YoungJun Cho <yj44.cho@samsung.com>,
Daniel Vetter <daniel@ffwll.ch>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Subject: Re: [RFC PATCH v2] dmabuf-sync: Introduce buffer synchronization framework
Date: Mon, 17 Jun 2013 15:42:37 +0000 [thread overview]
Message-ID: <20130617154237.GJ2718@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <CAAQKjZO_t_kZkU46bUPTpoJs_oE1KkEqS2OTrTYjjJYZzBf+XA@mail.gmail.com>
On Tue, Jun 18, 2013 at 12:03:31AM +0900, Inki Dae wrote:
> 2013/6/17 Russell King - ARM Linux <linux@arm.linux.org.uk>
> Exactly right. But that is not definitely my point. Could you please see
> the below simple example?:
> (Presume that CPU and DMA share a buffer and the buffer is mapped with user
> space as cachable)
>
> handle1 = drm_gem_fd_to_handle(a dmabuf fd); ----> 1
> ...
> va1 = drm_gem_mmap(handle1);
> va2 = drm_gem_mmap(handle2);
> va3 = malloc(size);
> ...
>
> while (conditions) {
> memcpy(va1, some data, size);
Nooooooooooooooooooooooooooooooooooooooooooooo!
Well, the first thing to say here is that under the requirements of the
DMA API, the above is immediately invalid, because you're writing to a
buffer which under the terms of the DMA API is currently owned by the
DMA agent, *not* by the CPU. You're supposed to call dma_sync_sg_for_cpu()
before you do that - but how is userspace supposed to know that requirement?
Why should userspace even _have_ to know these requirements of the DMA
API?
It's also entirely possible that drm_gem_fd_to_handle() (which indirectly
causes dma_map_sg() on the buffers scatterlist) followed by mmap'ing it
into userspace is a bug too, as it has the potential to touch caches or
stuff in ways that maybe the DMA or IOMMU may not expect - but I'm not
going to make too big a deal about that, because I don't think we have
anything that picky.
However, the first point above is the most important one, and exposing
the quirks of the DMA API to userland is certainly not a nice thing to be
doing. This needs to be fixed - we can't go and enforce an API which is
deeply embedded within the kernel all the way out to userland.
What we need is something along the lines of:
(a) dma_buf_map_attachment() _not_ to map the scatterlist for DMA.
or
(b) drm_gem_prime_import() not to call dma_buf_map_attachment() at all.
and for the scatterlist to be mapped for DMA at the point where the DMA
operation is initiated, and unmapped at the point where the DMA operation
is complete.
So no, the problem is not that we need more APIs and code - we need the
existing kernel API fixed so that we don't go exposing userspace to the
requirements of the DMA API. Unless we do that, we're going to end
up with a huge world of pain, where kernel architecture people need to
audit every damned DRM userspace implementation that happens to be run
on their platform, and that's not something arch people really can
afford to do.
Basically, I think the dma_buf stuff needs to be rewritten with the
requirements of the DMA API in the forefront of whosever mind is doing
the rewriting.
Note: the existing stuff does have the nice side effect of being able
to pass buffers which do not have a struct page * associated with them
through the dma_buf API - I think we can still preserve that by having
dma_buf provide a couple of new APIs to do the SG list map/sync/unmap,
but in any case we need to fix the existing API so that:
dma_buf_map_attachment() becomes dma_buf_get_sg()
dma_buf_unmap_attachment() becomes dma_buf_put_sg()
both getting rid of the DMA direction argument, and then we have four
new dma_buf calls:
dma_buf_map_sg()
dma_buf_unmap_sg()
dma_buf_sync_sg_for_cpu()
dma_buf_sync_sg_for_device()
which do the actual sg map/unmap via the DMA API *at the appropriate
time for DMA*.
So, the summary of this is - at the moment, I regard DRM Prime and dmabuf
to be utterly broken in design for architectures such as ARM where the
requirements of the DMA API have to be followed if you're going to have
a happy life.
next prev parent reply other threads:[~2013-06-17 15:42 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-13 8:28 [RFC PATCH] dmabuf-sync: Introduce buffer synchronization framework Inki Dae
2013-06-13 11:25 ` Inki Dae
2013-06-13 17:26 ` Russell King - ARM Linux
2013-06-14 2:32 ` Inki Dae
2013-06-17 11:15 ` [RFC PATCH v2] " Inki Dae
2013-06-17 11:34 ` Maarten Lankhorst
2013-06-17 13:04 ` Inki Dae
2013-06-17 13:31 ` Russell King - ARM Linux
[not found] ` <CAAQKjZO_t_kZkU46bUPTpoJs_oE1KkEqS2OTrTYjjJYZzBf+XA@mail.gmail.com>
2013-06-17 15:42 ` Russell King - ARM Linux [this message]
2013-06-17 16:01 ` Russell King - ARM Linux
[not found] ` <CAAQKjZOokFKN85pygVnm7ShSa+O0ZzwxvQ0rFssgNLp+RO5pGg@mail.gmail.com>
2013-06-17 18:21 ` Russell King - ARM Linux
2013-06-18 7:00 ` Daniel Vetter
2013-06-18 10:46 ` Russell King - ARM Linux
2013-06-25 9:23 ` Daniel Vetter
2013-06-26 17:18 ` Russell King - ARM Linux
2013-06-17 13:31 ` Maarten Lankhorst
2013-06-18 5:27 ` Inki Dae
2013-06-18 8:43 ` Russell King - ARM Linux
2013-06-18 9:04 ` Inki Dae
2013-06-18 9:38 ` Russell King - ARM Linux
2013-06-18 9:47 ` Lucas Stach
2013-06-19 5:45 ` Inki Dae
2013-06-19 10:22 ` Lucas Stach
2013-06-19 9:10 ` [RFC PATCH v3] " Inki Dae
2013-06-19 10:44 ` [RFC PATCH v2] " Inki Dae
2013-06-19 12:34 ` Lucas Stach
[not found] ` <CAAQKjZNJD4HpnJQ7iE+Gez36066M6U0YQeUEdA0+UcSOKqeghg@mail.gmail.com>
2013-06-19 18:29 ` Russell King - ARM Linux
2013-06-20 6:43 ` Inki Dae
2013-06-20 7:47 ` Lucas Stach
2013-06-20 8:17 ` Russell King - ARM Linux
2013-06-20 8:26 ` Lucas Stach
2013-06-20 8:24 ` Inki Dae
2013-06-20 10:11 ` Lucas Stach
2013-06-20 11:15 ` Inki Dae
2013-06-21 8:54 ` Lucas Stach
[not found] ` <CAAQKjZOxOMuL3zh_yV7tU2LBcZ7oVryiKa+LgjTM5HLY+va8zQ@mail.gmail.com>
2013-06-21 12:27 ` Lucas Stach
2013-06-21 16:55 ` Inki Dae
2013-06-21 19:02 ` Jerome Glisse
[not found] ` <CAAQKjZNnJRddACHzD+VF=A8vJpt9SEy2ttnS3Kw0y3hexu8dnw@mail.gmail.com>
2013-06-25 11:32 ` [RFC PATCH] " Rob Clark
2013-06-25 14:17 ` Inki Dae
2013-06-25 14:49 ` Jerome Glisse
2013-06-26 16:06 ` 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=20130617154237.GJ2718@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=daeinki@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=kyungmin.park@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@canonical.com \
--cc=myungjoo.ham@samsung.com \
--cc=robdclark@gmail.com \
--cc=yj44.cho@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;
as well as URLs for NNTP newsgroup(s).