From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74262C3ABB6 for ; Mon, 5 May 2025 07:02:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A80E6B00A7; Mon, 5 May 2025 03:02:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 852926B00A9; Mon, 5 May 2025 03:02:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B05F6B00A7; Mon, 5 May 2025 03:02:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4A5536B00A7 for ; Mon, 5 May 2025 03:02:39 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 339A9160218 for ; Mon, 5 May 2025 07:02:40 +0000 (UTC) X-FDA: 83407961280.24.66C5299 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf26.hostedemail.com (Postfix) with ESMTP id 9F2F914000B for ; Mon, 5 May 2025 07:02:38 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=udIyTs1j; spf=pass (imf26.hostedemail.com: domain of leon@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=leon@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746428558; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hA0xjJpkeFjKQ3aVnnAPliXao8ZHQTVnnNqCPBvGsCM=; b=ukjlKUfkvaM94dYIWwLF/M2OarBUmhxTfksJI/Ipd9NdKPjSoDrnkPoNNzp3I6RqscfTtu FpA/j3TVd5iPfh7j0ky2mnOfrPjv2zs6aDmXkHiLRBpS+X/a4ZeQbSjDMoJtI/7UF5Qpeg F+xgu8TddSZWXZee7WarNKPFiLTNYAs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=udIyTs1j; spf=pass (imf26.hostedemail.com: domain of leon@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=leon@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746428558; a=rsa-sha256; cv=none; b=fitKuDxkX7QDlTZMkBD/gqR0BZt8Wdwf2y4efQ2jgCAkLZR74XPNYRgVnaGf1y3AE/CXbb Qqnnc4ljkeEh+MoMCMPG9Y4HmgrVkskiMTfekUMhZV0WqtOKvS8ZTzwsNbNChaSB5wS2uO qsBJEkxb3MDR+23o+uitb1xeaEXKYTc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 1FEB14A5AD; Mon, 5 May 2025 07:02:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA5DBC4CEE4; Mon, 5 May 2025 07:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746428557; bh=d1+z79zg+kihe5QDvuiZPuBTqwMqD9eJrziwPARATZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=udIyTs1jU0xkkPO2JwNPXSUyJHDJzOGOAJqZEBd18QourGwZw+baXEZ9gTe8BJ0EJ DKGtIef9GidDihg430dzb3TV4U9nSk0oH0fWDOqZMUUied876JK1wN1He2oUOPQ9+s 4talNO552304u79Njy1LPb0QYEBAPSm4JRnjt0U38ZXHn3uQXTkQ6SLZmvo5VPfcSN 4oQb+HpClX6Qepsm/ir1G8Cf48WpHUEF6GV/yNoKGVauQurcR8AKjzjpLESRp4OM8E eFEoy59bj9uf5LIDs5y+12okk38f0cZDP+qoR+lYvzBX1noadVlU3+zY/zH2A2FB5S 5rtZiYk4O/uXQ== From: Leon Romanovsky To: Cc: Christoph Hellwig , Jens Axboe , Keith Busch , Jake Edge , Jonathan Corbet , Jason Gunthorpe , Zhu Yanjun , Robin Murphy , Joerg Roedel , Will Deacon , Sagi Grimberg , Bjorn Helgaas , Logan Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Andrew Morton , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, Niklas Schnelle , Chuck Lever , Luis Chamberlain , Matthew Wilcox , Dan Williams , Kanchan Joshi , Chaitanya Kulkarni , Leon Romanovsky Subject: [PATCH v11 9/9] docs: core-api: document the IOVA-based API Date: Mon, 5 May 2025 10:01:46 +0300 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9F2F914000B X-Stat-Signature: i3c4hzqjgmokmxagu7ux4dtbimsuwb4r X-HE-Tag: 1746428558-796864 X-HE-Meta: U2FsdGVkX18g1vBKnutABCsKw2XamUdAUyubWSw9jixExXynv9GIL2AP4UkAKQQ2atkaY61oNTIhxlvPOGwZ/ZKuX+/zWHNyFBs4KbK/9PnKG3W7M85hT1wdTMqSBoVXugTwBrteOK3/qBospjGEGsJ8eTpUur97KHa3XqLBSUjf3VQSMkTla4NS1xrE56zPHVLl/mlO1URrfiT0OZFHnwFjLLlHIvUWoGPqb8YDFpB6ohVYnvDx869lSTip6RzTQiNbfy1YxYC7QyWWDMhfFN2OtXoQ3WmDP5IfFGWfGprspzHDePmFVycK325leM3nK4mDPLB43w8wLzBxtihuFNeeG/SaZfScXxSDAEW1XbDGQGcw2ObhqAb7Ag/JDO7kFIt/SQtMsCu54dfUj87pfFkFPMamO1aNEkTYZFHxpJl5Nq/ww2ljg6xEwnGALBisLkBeG6p0DEsW8q/5cNL7OBY8p/tJwPeOWFPtN78AdPG1DIh5vcY93JRNJ1M+YFCyx9dRcvS1PUatNtz3Hjp6efl+xX8v3OGx2mXu3kmWvvexYPCIYuHoR1gDS/2uFE+YNVlyZwVBfq9pfcV0ULYmysj0MkMaS/uU7kgrAUu+Sbq0qS1kF77spBBrTgIMo1fTMmKUYC/mmICVjth5JjYB+433EeLZa3gSUFbUqjaASZ8DDrVvPN2fSHSpS77T2LYbXSAmccMRS2UyyqqdlV9PpktuFXzjDEaFvw2D24H715rs0zv9zF6Rd0Z4Q+V4Mmhi1twfwqZv90QkGjnRc945YHnDJNxU1jvDR2CDez4/SkO2S4P8AIIsegDWttljYFqk/oKoUjOUL2QwaFHvv0eF248+nP0ipF9rAi73AkYpO2Gt4zF+FUbbY/KkZtLJk2Vr0D9urBq+FW5W2Lq0ya3hM/le4OIA25ke+kWSAFjJuxGfmlvXq27adA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Christoph Hellwig Add an explanation of the newly added IOVA-based mapping API. Signed-off-by: Christoph Hellwig Tested-by: Jens Axboe Signed-off-by: Leon Romanovsky --- Documentation/core-api/dma-api.rst | 71 ++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/Documentation/core-api/dma-api.rst b/Documentation/core-api/dma-api.rst index 8e3cce3d0a23..2ad08517e626 100644 --- a/Documentation/core-api/dma-api.rst +++ b/Documentation/core-api/dma-api.rst @@ -530,6 +530,77 @@ routines, e.g.::: .... } +Part Ie - IOVA-based DMA mappings +--------------------------------- + +These APIs allow a very efficient mapping when using an IOMMU. They are an +optional path that requires extra code and are only recommended for drivers +where DMA mapping performance, or the space usage for storing the DMA addresses +matter. All the considerations from the previous section apply here as well. + +:: + + bool dma_iova_try_alloc(struct device *dev, struct dma_iova_state *state, + phys_addr_t phys, size_t size); + +Is used to try to allocate IOVA space for mapping operation. If it returns +false this API can't be used for the given device and the normal streaming +DMA mapping API should be used. The ``struct dma_iova_state`` is allocated +by the driver and must be kept around until unmap time. + +:: + + static inline bool dma_use_iova(struct dma_iova_state *state) + +Can be used by the driver to check if the IOVA-based API is used after a +call to dma_iova_try_alloc. This can be useful in the unmap path. + +:: + + int dma_iova_link(struct device *dev, struct dma_iova_state *state, + phys_addr_t phys, size_t offset, size_t size, + enum dma_data_direction dir, unsigned long attrs); + +Is used to link ranges to the IOVA previously allocated. The start of all +but the first call to dma_iova_link for a given state must be aligned +to the DMA merge boundary returned by ``dma_get_merge_boundary())``, and +the size of all but the last range must be aligned to the DMA merge boundary +as well. + +:: + + int dma_iova_sync(struct device *dev, struct dma_iova_state *state, + size_t offset, size_t size); + +Must be called to sync the IOMMU page tables for IOVA-range mapped by one or +more calls to ``dma_iova_link()``. + +For drivers that use a one-shot mapping, all ranges can be unmapped and the +IOVA freed by calling: + +:: + + void dma_iova_destroy(struct device *dev, struct dma_iova_state *state, + size_t mapped_len, enum dma_data_direction dir, + unsigned long attrs); + +Alternatively drivers can dynamically manage the IOVA space by unmapping +and mapping individual regions. In that case + +:: + + void dma_iova_unlink(struct device *dev, struct dma_iova_state *state, + size_t offset, size_t size, enum dma_data_direction dir, + unsigned long attrs); + +is used to unmap a range previously mapped, and + +:: + + void dma_iova_free(struct device *dev, struct dma_iova_state *state); + +is used to free the IOVA space. All regions must have been unmapped using +``dma_iova_unlink()`` before calling ``dma_iova_free()``. Part II - Non-coherent DMA allocations -------------------------------------- -- 2.49.0