Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp805921pxb; Fri, 13 Aug 2021 06:47:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/FOXQtQdmTpfYTSvO6csuf3XHcT4rC94DsYXy3DDzLujNpl2IhZ7jmeW640cM3apryb6/ X-Received: by 2002:a17:906:fb08:: with SMTP id lz8mr2489994ejb.547.1628862445917; Fri, 13 Aug 2021 06:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628862445; cv=none; d=google.com; s=arc-20160816; b=fED2JBkjSouODF6/EZncbCtjBcW0WjYOIY8J1DvNQmk8FX2Q3QJNB5OkqdXqRK9yLR VgjaDraGwecYHCAURIfb051ZYBslRfxSF/pJFqKWeVgv3fvDt7n6WJxbjguZYRn2VCB7 e8aH0T5XHHtLpVfOdAms6uYILDDEq1fzuEuAgYMn7WCocvPR+bDz2PV+A+2V19ImaYXq Pj4t5J4HL0NSXb5kIFBMT6X1OhgILxmdtrQHc68L1y1o+tLKMi0F8F+hwqR0uPrka7jN lZdnLf9vSiqH3lmBe/EBTOGcnXSXRBGjs75jTugQ2Aw7Oz8m4N+6Kqax67n7F73DATlM HJGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:cc:to:subject:from:date; bh=nG1S1IBlnZx1HNHd1b87rjvrbzjlAECRIJJapLCtS+Y=; b=FGIT5fVIBOdUxKbiqdiKXVdauGpEjX8UEAhhI8GvuFb/E2xTk/oG7uD/Wj0OL223+e 4S8o7J5wvp9WUYR0EY4rqreXqRAfDsbZxdT3MPryC2dn8F0BnCcO1hIxHIrQ582de82o /nbRpxwK4B6F1ktTVEpC/0v2uPPTv4FIzsDvaMBpzwiInED/Gge0SsJnKBC5BEQrbdb0 xBFwUv4QiaKR5A8ODk2tvTodjOh87aoMCwZ4HN17R485yy9I7Yk1oPCKT5fA/hT2OZOu XRlwRLIsbofdlUQg4rtKOsS/xoLVkLoULxkLZqY2uEoMTtJ0j+5oj5T2wKbARjSlRo8o iDug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c6si1701781ede.289.2021.08.13.06.46.58; Fri, 13 Aug 2021 06:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240335AbhHMLmG (ORCPT + 99 others); Fri, 13 Aug 2021 07:42:06 -0400 Received: from aposti.net ([89.234.176.197]:46710 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239938AbhHMLmF (ORCPT ); Fri, 13 Aug 2021 07:42:05 -0400 Date: Fri, 13 Aug 2021 13:41:26 +0200 From: Paul Cercueil Subject: IIO, dmabuf, io_uring To: Jonathan Cameron , Sumit Semwal , Christian =?iso-8859-1?b?S/ZuaWc=?= , Christoph Hellwig Cc: linux-iio@vger.kernel.org, io-uring@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Hennerich , Alexandru Ardelean Message-Id: <2H0SXQ.2KIK2PBVRFWH2@crapouillou.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, A few months ago we (ADI) tried to upstream the interface we use with our high-speed ADCs and DACs. It is a system with custom ioctls on the iio device node to dequeue and enqueue buffers (allocated with dma_alloc_coherent), that can then be mmap'd by userspace applications. Anyway, it was ultimately denied entry [1]; this API was okay in ~2014 when it was designed but it feels like re-inventing the wheel in 2021. Back to the drawing table, and we'd like to design something that we can actually upstream. This high-speed interface looks awfully similar to DMABUF, so we may try to implement a DMABUF interface for IIO, unless someone has a better idea. Our first usecase is, we want userspace applications to be able to dequeue buffers of samples (from ADCs), and/or enqueue buffers of samples (for DACs), and to be able to manipulate them (mmapped buffers). With a DMABUF interface, I guess the userspace application would dequeue a dma buffer from the driver, mmap it, read/write the data, unmap it, then enqueue it to the IIO driver again so that it can be disposed of. Does that sound sane? Our second usecase is - and that's where things get tricky - to be able to stream the samples to another computer for processing, over Ethernet or USB. Our typical setup is a high-speed ADC/DAC on a dev board with a FPGA and a weak soft-core or low-power CPU; processing the data in-situ is not an option. Copying the data from one buffer to another is not an option either (way too slow), so we absolutely want zero-copy. Usual userspace zero-copy techniques (vmsplice+splice, MSG_ZEROCOPY etc) don't really work with mmapped kernel buffers allocated for DMA [2] and/or have a huge overhead, so the way I see it, we would also need DMABUF support in both the Ethernet stack and USB (functionfs) stack. However, as far as I understood, DMABUF is mostly a DRM/V4L2 thing, so I am really not sure we have the right idea here. And finally, there is the new kid in town, io_uring. I am not very literate about the topic, but it does not seem to be able to handle DMA buffers (yet?). The idea that we could dequeue a buffer of samples from the IIO device and send it over the network in one single syscall is appealing, though. Any thoughts? Feedback would be greatly appreciated. Cheers, -Paul [1]: https://lore.kernel.org/linux-iio/20210217073638.21681-1-alexandru.ardelean@analog.com/T/#m6b853addb77959c55e078fbb06828db33d4bf3d7 [2]: https://newbedev.com/zero-copy-user-space-tcp-send-of-dma-mmap-coherent-mapped-memory