From: "Christian König" <christian.koenig@amd.com>
To: "Nuno Sá" <noname.nuno@gmail.com>, "Nuno Sa" <nuno.sa@analog.com>,
"Vinod Koul" <vkoul@kernel.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Jonathan Cameron" <jic23@kernel.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Paul Cercueil" <paul@crapouillou.net>
Cc: Daniel Vetter <daniel@ffwll.ch>,
Michael Hennerich <Michael.Hennerich@analog.com>,
linux-doc@vger.kernel.org, dmaengine@vger.kernel.org,
linux-iio@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH v7 3/6] iio: core: Add new DMABUF interface infrastructure
Date: Mon, 4 Mar 2024 14:41:44 +0100 [thread overview]
Message-ID: <8962f6cf-7e5e-4bfe-a86b-cbb66a815187@amd.com> (raw)
In-Reply-To: <796e8189-0e1a-46d4-8251-7963e56704ac@amd.com>
Trying to send this once more as text only.
Am 04.03.24 um 14:40 schrieb Christian König:
> Am 04.03.24 um 14:28 schrieb Nuno Sá:
>> On Mon, 2024-03-04 at 13:44 +0100, Christian König wrote:
>>> Am 23.02.24 um 13:14 schrieb Nuno Sa:
>>>> From: Paul Cercueil<paul@crapouillou.net>
>>>>
>>>> Add the necessary infrastructure to the IIO core to support a new
>>>> optional DMABUF based interface.
>>>>
>>>> With this new interface, DMABUF objects (externally created) can be
>>>> attached to a IIO buffer, and subsequently used for data transfer.
>>>>
>>>> A userspace application can then use this interface to share DMABUF
>>>> objects between several interfaces, allowing it to transfer data in a
>>>> zero-copy fashion, for instance between IIO and the USB stack.
>>>>
>>>> The userspace application can also memory-map the DMABUF objects, and
>>>> access the sample data directly. The advantage of doing this vs. the
>>>> read() interface is that it avoids an extra copy of the data between the
>>>> kernel and userspace. This is particularly userful for high-speed
>>>> devices which produce several megabytes or even gigabytes of data per
>>>> second.
>>>>
>>>> As part of the interface, 3 new IOCTLs have been added:
>>>>
>>>> IIO_BUFFER_DMABUF_ATTACH_IOCTL(int fd):
>>>> Attach the DMABUF object identified by the given file descriptor to the
>>>> buffer.
>>>>
>>>> IIO_BUFFER_DMABUF_DETACH_IOCTL(int fd):
>>>> Detach the DMABUF object identified by the given file descriptor from
>>>> the buffer. Note that closing the IIO buffer's file descriptor will
>>>> automatically detach all previously attached DMABUF objects.
>>>>
>>>> IIO_BUFFER_DMABUF_ENQUEUE_IOCTL(struct iio_dmabuf *):
>>>> Request a data transfer to/from the given DMABUF object. Its file
>>>> descriptor, as well as the transfer size and flags are provided in the
>>>> "iio_dmabuf" structure.
>>>>
>>>> These three IOCTLs have to be performed on the IIO buffer's file
>>>> descriptor, obtained using the IIO_BUFFER_GET_FD_IOCTL() ioctl.
>>> A few nit picks and one bug below, apart from that looks good to me.
>> Hi Christian,
>>
>> Thanks for looking at it. I'll just add some comment on the bug below and for
>> the other stuff I hope Paul is already able to step in and reply to it. My
>> assumption (which seems to be wrong) is that the dmabuf bits should be already
>> good to go as they should be pretty similar to the USB part of it.
>>
>> ...
>>
>>>> + if (dma_to_ram) {
>>>> + /*
>>>> + * If we're writing to the DMABUF, make sure we don't have
>>>> + * readers
>>>> + */
>>>> + retl = dma_resv_wait_timeout(dmabuf->resv,
>>>> + DMA_RESV_USAGE_READ, true,
>>>> + timeout);
>>>> + if (retl == 0)
>>>> + retl = -EBUSY;
>>>> + if (retl < 0) {
>>>> + ret = (int)retl;
>>>> + goto err_resv_unlock;
>>>> + }
>>>> + }
>>>> +
>>>> + if (buffer->access->lock_queue)
>>>> + buffer->access->lock_queue(buffer);
>>>> +
>>>> + ret = dma_resv_reserve_fences(dmabuf->resv, 1);
>>>> + if (ret)
>>>> + goto err_queue_unlock;
>>>> +
>>>> + dma_resv_add_fence(dmabuf->resv, &fence->base,
>>>> + dma_resv_usage_rw(dma_to_ram));
>>> That is incorrect use of the function dma_resv_usage_rw(). That function
>>> is for retrieving fences and not adding them.
>>>
>>> See the function implementation and comments, when you use it like this
>>> you get exactly what you don't want.
>>>
>> Does that mean that the USB stuff [1] is also wrong?
>>
>> [1]:https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/tree/drivers/usb/gadget/function/f_fs.c?h=usb-next#n1669
>
> Yes, that's broken as well. The dma_resv_usage_rw() function is
> supposed to be used while retrieving fences.
>
> In other words your "if (dma_to_ram) ..." above is incorrect as well.
> That one should look more like this:
> /*
> * Writes needs to wait for other writes and reads, but readers only have to wait for writers.
> */
>
> retl = dma_resv_wait_timeout(dmabuf->resv, dma_resv_usage_rw(dma_to_ram), timeout);
>
> Regards,
> Christian.
>
>> - Nuno Sá
>>
>>
>
next prev parent reply other threads:[~2024-03-04 13:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-23 12:13 [PATCH v7 0/6] iio: new DMABUF based API Nuno Sa
2024-02-23 12:13 ` [PATCH v7 1/6] dmaengine: Add API function dmaengine_prep_peripheral_dma_vec() Nuno Sa
2024-03-04 11:10 ` Nuno Sá
2024-02-23 12:14 ` [PATCH v7 2/6] dmaengine: dma-axi-dmac: Implement device_prep_peripheral_dma_vec Nuno Sa
2024-02-23 12:14 ` [PATCH v7 3/6] iio: core: Add new DMABUF interface infrastructure Nuno Sa
2024-03-04 12:44 ` Christian König
2024-03-04 13:28 ` Nuno Sá
[not found] ` <796e8189-0e1a-46d4-8251-7963e56704ac@amd.com>
2024-03-04 13:41 ` Christian König [this message]
2024-03-04 14:29 ` Paul Cercueil
2024-03-04 15:13 ` Christian König
2024-03-04 13:59 ` Paul Cercueil
[not found] ` <63f8a0f5-55a4-47c9-99d7-bb0b8ad22b3a@amd.com>
2024-03-04 14:20 ` Paul Cercueil
2024-02-23 12:14 ` [PATCH v7 4/6] iio: buffer-dma: Enable support for DMABUFs Nuno Sa
2024-02-23 12:14 ` [PATCH v7 5/6] iio: buffer-dmaengine: Support new DMABUF based userspace API Nuno Sa
2024-02-23 12:14 ` [PATCH v7 6/6] Documentation: iio: Document high-speed DMABUF based API Nuno Sa
2024-03-03 17:42 ` [PATCH v7 0/6] iio: new " Jonathan Cameron
2024-03-04 7:59 ` Nuno Sá
2024-03-05 10:07 ` Jonathan Cameron
2024-03-05 10:16 ` Paul Cercueil
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=8962f6cf-7e5e-4bfe-a86b-cbb66a815187@amd.com \
--to=christian.koenig@amd.com \
--cc=Michael.Hennerich@analog.com \
--cc=corbet@lwn.net \
--cc=daniel@ffwll.ch \
--cc=dmaengine@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=noname.nuno@gmail.com \
--cc=nuno.sa@analog.com \
--cc=paul@crapouillou.net \
--cc=sumit.semwal@linaro.org \
--cc=vkoul@kernel.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