From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Inki Dae <inki.dae@samsung.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 18:21:27 +0000 [thread overview]
Message-ID: <20130617182127.GM2718@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <CAAQKjZOokFKN85pygVnm7ShSa+O0ZzwxvQ0rFssgNLp+RO5pGg@mail.gmail.com>
On Tue, Jun 18, 2013 at 02:19:04AM +0900, Inki Dae wrote:
> It seems like that all pages of the scatterlist should be mapped with
> DMA every time DMA operation is started (or drm_xxx_set_src_dma_buffer
> function call), and the pages should be unmapped from DMA again every
> time DMA operation is completed: internally, including each cache
> operation.
Correct.
> Isn't that big overhead?
Yes, if you _have_ to do a cache operation to ensure that the DMA agent
can see the data the CPU has written.
> And If there is no problem, we should accept such overhead?
If there is no problem then why are we discussing this and why do we need
this API extension? :)
> Actually, drm_gem_fd_to_handle() includes to map a
> given dmabuf with iommu table (just logical data) of the DMA. And then, the
> device address (or iova) already mapped will be set to buffer register of
> the DMA with drm_xxx_set_src/dst_dma_buffer(handle1, ...) call.
Consider this with a PIPT cache:
dma_map_sg() - at this point, the kernel addresses of these
buffers are cleaned and invalidated for the DMA
userspace writes to the buffer, the data sits in the CPU cache
Because the cache is PIPT, this data becomes visible to the
kernel as well.
DMA is started, and it writes to the buffer
Now, at this point, which is the correct data? The data physically in the
RAM which the DMA has written, or the data in the CPU cache. It may
the answer is - they both are, and the loss of either can be a potential
data corruption issue - there is no way to tell which data should be
kept but the system is in an inconsistent state and _one_ of them will
have to be discarded.
dma_unmap_sg() - at this point, the kernel addresses of the
buffers are _invalidated_ and any data in those
cache lines is discarded
Which also means that the data in userspace will also be discarded with
PIPT caches.
This is precisely why we have buffer rules associated with the DMA API,
which are these:
dma_map_sg()
- the buffer transfers ownership from the CPU to the DMA agent.
- the CPU may not alter the buffer in any way.
while (cpu_wants_access) {
dma_sync_sg_for_cpu()
- the buffer transfers ownership from the DMA to the CPU.
- the DMA may not alter the buffer in any way.
dma_sync_sg_for_device()
- the buffer transfers ownership from the CPU to the DMA
- the CPU may not alter the buffer in any way.
}
dma_unmap_sg()
- the buffer transfers ownership from the DMA to the CPU.
- the DMA may not alter the buffer in any way.
Any violation of that is likely to lead to data corruption. Now, some
may say that the DMA API is only about the kernel mapping. Yes it is,
because it takes no regard what so ever about what happens with the
userspace mappings. This is absolutely true when you have VIVT or
aliasing VIPT caches.
Now consider that with a PIPT cache, or a non-aliasing VIPT cache (which
is exactly the same behaviourally from this aspect) any modification of
a userspace mapping is precisely the same as modifying the kernel space
mapping - and what you find is that the above rules end up _inherently_
applying to the userspace mappings as well.
In other words, userspace applications which have mapped the buffers
must _also_ respect these rules.
And there's no way in hell that I'd ever trust userspace to get this
anywhere near right, and I *really* do not like these kinds of internal
kernel API rules being exposed to userspace.
And so the idea that userspace should be allowed to setup DMA transfers
via "set source buffer", "set destination buffer" calls into an API is
just plain rediculous. No, userspace should be allowed to ask for
"please copy from buffer X to buffer Y using this transform".
Also remember that drm_xxx_set_src/dst_dma_buffer() would have to
deal with the DRM object IDs for the buffer, and not the actual buffer
information themselves - that is kept within the kernel, so the kernel
knows what's happening.
next prev parent reply other threads:[~2013-06-17 18:21 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
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 [this message]
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=20130617182127.GM2718@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=inki.dae@samsung.com \
--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).