From: "Semwal, Sumit" <sumit.semwal@ti.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: 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,
jesse.barker@linaro.org, m.szyprowski@samsung.com, rob@ti.com,
daniel@ffwll.ch, t.stanislaws@samsung.com,
Sumit Semwal <sumit.semwal@linaro.org>
Subject: Re: [RFC v2 1/2] dma-buf: Introduce dma buffer sharing mechanism
Date: Wed, 7 Dec 2011 12:05:12 +0530 [thread overview]
Message-ID: <CAB2ybb8-0_HupO95UUvLN9ovVxnU+uvn4UXbwqZLSFuC9MZs0w@mail.gmail.com> (raw)
In-Reply-To: <201112051718.48324.arnd@arndb.de>
Hi Arnd,
Thanks for your review!
On Mon, Dec 5, 2011 at 10:48 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Friday 02 December 2011, Sumit Semwal wrote:
>> This is the first step in defining a dma buffer sharing mechanism.
>
> This looks very nice, but there are a few things I don't understand yet
> and a bunch of trivial comments I have about things I spotted.
>
> Do you have prototype exporter and consumer drivers that you can post
> for clarification?
>
> In the patch 2, you have a section about migration that mentions that
> it is possible to export a buffer that can be migrated after it
> is already mapped into one user driver. How does that work when
> the physical addresses are mapped into a consumer device already?
I guess I need to clear it up in the documentation - when I said "once
all ongoing access is completed" - I meant to say "once all current
users have finished accessing and have unmapped this buffer". So I
agree with Rob - the migration would only be possible for "attached
but unmapped" buffers. I will update the documentation.
>
>> diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
>> index 21cf46f..07d8095 100644
>> --- a/drivers/base/Kconfig
>> +++ b/drivers/base/Kconfig
>> @@ -174,4 +174,14 @@ config SYS_HYPERVISOR
>>
>> source "drivers/base/regmap/Kconfig"
>>
>> +config DMA_SHARED_BUFFER
>> + bool "Buffer framework to be shared between drivers"
>> + default n
>> + depends on ANON_INODES
>
> I would make this 'select ANON_INODES', like the other users of this
> feature.
Sure.
>
>> + return dmabuf;
>> +}
>> +EXPORT_SYMBOL(dma_buf_export);
>
> I agree with Konrad, this should definitely be EXPORT_SYMBOL_GPL,
> because it's really a low-level function that I would expect
> to get used by in-kernel subsystems providing the feature to
> users and having back-end drivers, but it's not the kind of thing
> we want out-of-tree drivers to mess with.
Agreed.
>
>> +/**
>> + * dma_buf_fd - returns a file descriptor for the given dma_buf
>> + * @dmabuf: [in] pointer to dma_buf for which fd is required.
>> + *
>> + * On success, returns an associated 'fd'. Else, returns error.
>> + */
>> +int dma_buf_fd(struct dma_buf *dmabuf)
>> +{
>> + int error, fd;
>> +
>> + if (!dmabuf->file)
>> + return -EINVAL;
>> +
>> + error = get_unused_fd_flags(0);
>
> Why not simply get_unused_fd()?
:) oversight. Will correct.
>
>> +/**
>> + * dma_buf_attach - Add the device to dma_buf's attachments list; optionally,
>> + * calls attach() of dma_buf_ops to allow device-specific attach functionality
>> + * @dmabuf: [in] buffer to attach device to.
>> + * @dev: [in] device to be attached.
>> + *
>> + * Returns struct dma_buf_attachment * for this attachment; may return NULL.
>> + *
>
> Or may return a negative error code. It's better to be consistent here:
> either always return NULL on error, or change the allocation error to
> ERR_PTR(-ENOMEM).
Ok, that makes sense.
>
>> + */
>> +struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
>> + struct device *dev)
>> +{
>> + struct dma_buf_attachment *attach;
>> + int ret;
>> +
>> + BUG_ON(!dmabuf || !dev);
>> +
>> + attach = kzalloc(sizeof(struct dma_buf_attachment), GFP_KERNEL);
>> + if (attach == NULL)
>> + goto err_alloc;
>> +
>> + mutex_lock(&dmabuf->lock);
>> +
>> + attach->dev = dev;
>> + attach->dmabuf = dmabuf;
>> + if (dmabuf->ops->attach) {
>> + ret = dmabuf->ops->attach(dmabuf, dev, attach);
>> + if (!ret)
>> + goto err_attach;
>
> You probably mean "if (ret)" here instead of "if (!ret)", right?
yes - a stupid one! will correct.
>
>> + /* allow allocator to take care of cache ops */
>> + void (*sync_sg_for_cpu) (struct dma_buf *, struct device *);
>> + void (*sync_sg_for_device)(struct dma_buf *, struct device *);
>
> I don't see how this works with multiple consumers: For the streaming
> DMA mapping, there must be exactly one owner, either the device or
> the CPU. Obviously, this rule needs to be extended when you get to
> multiple devices and multiple device drivers, plus possibly user
> mappings. Simply assigning the buffer to "the device" from one
> driver does not block other drivers from touching the buffer, and
> assigning it to "the cpu" does not stop other hardware that the
> code calling sync_sg_for_cpu is not aware of.
>
> The only way to solve this that I can think of right now is to
> mandate that the mappings are all coherent (i.e. noncachable
> on noncoherent architectures like ARM). If you do that, you no
> longer need the sync_sg_for_* calls.
I will take yours and Daniel's suggestion, and remove these; if at all
they're needed, we can add them back again later, with
/s/device/attachment as suggested by Daniel.
>
>> +#ifdef CONFIG_DMA_SHARED_BUFFER
>
> Do you have a use case for making the interface compile-time disabled?
> I had assumed that any code using it would make no sense if it's not
> available so you don't actually need this.
Ok. Though if we keep the interface compile-time disabled, the users
can actually check and fail or fall-back gracefully when the API is
not available; If I remove it, anyways the users would need to do the
same compile time check whether API is available or not, right?
>
> Arnd
Thanks, and best regards,
~Sumit.
--
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:[~2011-12-07 6:35 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 [this message]
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
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=CAB2ybb8-0_HupO95UUvLN9ovVxnU+uvn4UXbwqZLSFuC9MZs0w@mail.gmail.com \
--to=sumit.semwal@ti.com \
--cc=arnd@arndb.de \
--cc=daniel@ffwll.ch \
--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=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