Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1029082rdb; Fri, 19 Jan 2024 06:14:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi31mqR2xHmILMjCF4JarclCSGWOIqjdzWQjW3UQABMgQBgnOc1qtdENPnjcnRtxCWoS9b X-Received: by 2002:a2e:a281:0:b0:2cc:a253:a4a4 with SMTP id k1-20020a2ea281000000b002cca253a4a4mr1615308lja.21.1705673672775; Fri, 19 Jan 2024 06:14:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705673672; cv=pass; d=google.com; s=arc-20160816; b=qYu3EvnzJDt66t7t0bpswTykiprzimMkxqHyBZQowEDLU5LTC1RM09DyukQurC45zc TVa2BkG5B82Lz0wBx0ZxR5LexI2JR06YLkM+WonRBdRdAQ4DgM4jxHMYTEKc/XXQaPHc VMiLswbNIFwRUrrz13df2YkmmzGjP8dU6PJt6tZ5jKLREay5zxR4o7EvSAZ7DjZrboiu xhClOqM1oH4Ny0IBTTkFjoDwLeJuJ08l2CUEdYiIOCOczmiMFScCjgEglkJ8WH2H8TUO WQ6W6B1lOyoClER5CG0rMoFjgUpMwhcV93Fn7hdKTZMB4H8L8heWzJc2Gfn3Adm2cwDU uX7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=FX6y2yjuW0nuJFiEqsV4ftraJscIV4V40Vy+XAQTjhI=; fh=3Xwiw3h4BuSZxa4g5nlxoJvEg1Pn4zGp9h0k4mfsabo=; b=WeRpiATq7eA3M71tImzpO7c1tD6uqL/TNFqZgIQCIWsnyZD2QxW+KME59VDMvaj4rd q8Znf3hRRJTLGVkmbiILbm4VzSscvP00PlyuXKOEtRCZ0hQmRf0nB0xDUWWRhkFLiBXX aX9mUNtebrOnCUpZ5wNsNi7DfUcU6tRWHXV3rlQwZSxc6o32pr7rXMMwWCHi68EWr4QA Hu9qXgKsEcKEWrQtQq9tdOtiLQ6NfxE9aEd4ufPwVa1ArryPj3TMg5Rqwj8ZqSIPFbL8 db8AyuGWR3vGJfmpDKs4t1Vyr1YJhRbI3YtPQUmmxbnd+Pve2MsvPUpB/ePziVnwxCYz YQPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=AZOYG5ed; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-31247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dm21-20020a05640222d500b0055a47c706d1si1084261edb.282.2024.01.19.06.14.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 06:14:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=AZOYG5ed; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-31247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 811911F258AF for ; Fri, 19 Jan 2024 14:14:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A6E553E17; Fri, 19 Jan 2024 14:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="AZOYG5ed" Received: from aposti.net (aposti.net [89.234.176.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7BC01E48F; Fri, 19 Jan 2024 14:14:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.234.176.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705673655; cv=none; b=WYAuDDYJrEQYYnJeWKXLDpx2sZcwkE7Ee/IxsKv+3ILyRuAeKtJC4SECpCVhVWuHuzhDK00ESgHKu+NoLiZH6K98rvL6t4hWZzYOnHL0zFYZN4kwUZgrZrWMqnVyHkt2afGX/jWHgTungSgeQIEGEOFh3YGWYHkuUsHCP13LhHE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705673655; c=relaxed/simple; bh=YxMO7K0SAFW1fxIxiyYDZizLbqPwVgtTZ5V/DA1a3aA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=n70C0PheOY4aZm+w+F+XeUlHH4WSs+IHr1EYWLJl72c2xaPx/9uuAl0mYPtjmcaKQMVxSx9kNoq1Ev79SAD1GRchZsWUJFUIPj+2W2LDrp68iKCYoQ09nTWrcc6CfjdRrGfqUShxzNiteuAqBHxKGifMCNPx8r5TzmUS2uDTktI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net; spf=pass smtp.mailfrom=crapouillou.net; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b=AZOYG5ed; arc=none smtp.client-ip=89.234.176.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=crapouillou.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1705673650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FX6y2yjuW0nuJFiEqsV4ftraJscIV4V40Vy+XAQTjhI=; b=AZOYG5edVZIWA1BlCrUR1yaolBTzcIodYuTj1R0BojE/dH4mDiXy2R/lk6N0eIGpYjQRnM moRjihZ1MzvjxwroPPnCYYSyUbr+Q/3G8gPUFgTrqIdY8BEH1tinjcH5f3aUwn3o497Y5W cxzgdFEi3srEEHMggkSKv9wlfR3+Gjo= From: Paul Cercueil To: Greg Kroah-Hartman , Jonathan Corbet , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: Jonathan Cameron , =?UTF-8?q?Nuno=20S=C3=A1?= , Michael Hennerich , linux-usb@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Paul Cercueil Subject: [PATCH v5 0/6] usb: gadget: functionfs: DMABUF import interface Date: Fri, 19 Jan 2024 15:13:56 +0100 Message-ID: <20240119141402.44262-1-paul@crapouillou.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, This is the v5 of my patchset that adds a new DMABUF import interface to FunctionFS. Daniel / Sima suggested that I should cache the dma_buf_attachment while the DMABUF is attached to the interface, instead of mapping/unmapping the DMABUF for every transfer (also because unmapping is not possible in the dma_fence's critical section). This meant having to add new dma_buf_begin_access() / dma_buf_end_access() functions that the driver can call to ensure cache coherency. These two functions are provided by the new patch [1/6], and an implementation for udmabuf was added in [2/6] - see the changelog below. This patchset was successfully tested with CONFIG_LOCKDEP, no errors were reported in dmesg while using the interface. This interface is being used at Analog Devices, to transfer data from high-speed transceivers to USB in a zero-copy fashion, using also the DMABUF import interface to the IIO subsystem which is being upstreamed in parallel [1]. The two are used by the Libiio software [2]. On a ZCU102 board with a FMComms3 daughter board, using the combination of these two new interfaces yields a drastic improvement of the throughput, from about 127 MiB/s using IIO's buffer read/write interface + read/write to the FunctionFS endpoints, to about 274 MiB/s when passing around DMABUFs, for a lower CPU usage (0.85 load avg. before, vs. 0.65 after). Right now, *technically* there are no users of this interface, as Analog Devices wants to wait until both interfaces are accepted upstream to merge the DMABUF code in Libiio into the main branch, and Jonathan wants to wait and see if this patchset is accepted to greenlight the DMABUF interface in IIO as well. I think this isn't really a problem; once everybody is happy with its part of the cake, we can merge them all at once. This is obviously for 5.9, and based on next-20240119. Changelog: - [1/6]: New patch - [2/6]: New patch - [5/6]: - Cache the dma_buf_attachment while the DMABUF is attached. - Use dma_buf_begin/end_access() to ensure that the DMABUF data will be coherent to the hardware. - Remove comment about cache-management and dma_buf_unmap_attachment(), since we now use dma_buf_begin/end_access(). - Select DMA_SHARED_BUFFER in Kconfig entry - Add Christian's ACK Cheers, -Paul [1] https://lore.kernel.org/linux-iio/219abc43b4fdd4a13b307ed2efaa0e6869e68e3f.camel@gmail.com/T/ [2] https://github.com/analogdevicesinc/libiio/tree/pcercuei/dev-new-dmabuf-api Paul Cercueil (6): dma-buf: Add dma_buf_{begin,end}_access() dma-buf: udmabuf: Implement .{begin,end}_access usb: gadget: Support already-mapped DMA SGs usb: gadget: functionfs: Factorize wait-for-endpoint code usb: gadget: functionfs: Add DMABUF import interface Documentation: usb: Document FunctionFS DMABUF API Documentation/usb/functionfs.rst | 36 ++ drivers/dma-buf/dma-buf.c | 66 ++++ drivers/dma-buf/udmabuf.c | 27 ++ drivers/usb/gadget/Kconfig | 1 + drivers/usb/gadget/function/f_fs.c | 502 ++++++++++++++++++++++++++-- drivers/usb/gadget/udc/core.c | 7 +- include/linux/dma-buf.h | 37 ++ include/linux/usb/gadget.h | 2 + include/uapi/linux/usb/functionfs.h | 41 +++ 9 files changed, 698 insertions(+), 21 deletions(-) -- 2.43.0