From patchwork Fri Jan 17 10:03:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13943123 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 53604C02183 for ; Fri, 17 Jan 2025 10:04:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3CAB28000B; Fri, 17 Jan 2025 05:04:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CED52280001; Fri, 17 Jan 2025 05:04:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3FAA28000B; Fri, 17 Jan 2025 05:04:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 92486280001 for ; Fri, 17 Jan 2025 05:04:31 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4A783141897 for ; Fri, 17 Jan 2025 10:04:31 +0000 (UTC) X-FDA: 83016509142.04.8491464 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf23.hostedemail.com (Postfix) with ESMTP id B8ED6140011 for ; Fri, 17 Jan 2025 10:04:29 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CoIahJnD; spf=pass (imf23.hostedemail.com: domain of leon@kernel.org designates 147.75.193.91 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=1737108269; 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=DmK8WgvpG/Zyw/VfypmEnIWMyF/z1YcxGAx9FI5n4dU=; b=WXSVTACCT4RiKz+S/tYVAdNdRNKMEQtjP7PtS4uyBDEea6LsEuOULFFpNnG/HGrKf0Uw7p rAWVmvZg3pEpLQk2q2x4W+VEXTTRHbXdv6T1QlE+VUJ9UrwwVHEt5Uu+HoEq7rJa95t5jr l+REoYEoUBAc6ZwmkuZEu1O9M4WHeHw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CoIahJnD; spf=pass (imf23.hostedemail.com: domain of leon@kernel.org designates 147.75.193.91 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=1737108269; a=rsa-sha256; cv=none; b=G29E18iaW7pYZv5d442u5rIQLUS1kF5gzSSkRHVmKgUgjep1IePHaYeJKeU7OKZwMGlxWe VMRYh5gGGQ7e7agmbaOekPzr9LGcjwAUPG1g77YHh05syJnnu+bS/yGVeNR1/+FxJcszLE 6r8Cya05MvJejxgzgJffO/brWP0ViW0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1DF05A41B24; Fri, 17 Jan 2025 10:02:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05194C4CEE4; Fri, 17 Jan 2025 10:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737108268; bh=KG1gfl9h8v/ucKbjkssx+J8kG9zIxS1cy+tMx8hgV6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CoIahJnDuJR3UhGA/T5o/6xqvX4Vo+/WCukiV+L09L3RCeb5wcfMsl/yTuAlcuWrd rFGWjTxBkDE+yqJR+lGWaNqRhNMVEBUFrpTAQ075ZaMvGBlLWZsq1TyUUNl/U0yzBU K/p3HKd/TStOciDIXSdIVFHLdmOaVjpk/fdziHQvjd7L/b9mh9HM/ki+j30W6QgzED BNDpSlsn4D9uTMU0kjQoFzlhd7cSyM1loeB1VLrZxyQ6M3Oy7Ron9GpQf9PVeF8Sl7 2+yIIsHZrbUNyLj3CF5/ey28U5yMlN7Y7G0RRsl/JZr45nYIwf6MrMg7zng625jlVe QNb7oGQy7sNPA== From: Leon Romanovsky To: Christoph Hellwig , Jason Gunthorpe , Robin Murphy Cc: Jens Axboe , Joerg Roedel , Will Deacon , Sagi Grimberg , "Keith Busch" , "Bjorn Helgaas" , "Logan Gunthorpe" , "Yishai Hadas" , "Shameer Kolothum" , "Kevin Tian" , "Alex Williamson" , "Marek Szyprowski" , =?utf-8?b?SsOpcsO0bWUgR2xp?= =?utf-8?b?c3Nl?= , "Andrew Morton" , "Jonathan Corbet" , 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, "Randy Dunlap" Subject: [PATCH v6 09/17] docs: core-api: document the IOVA-based API Date: Fri, 17 Jan 2025 12:03:40 +0200 Message-ID: <6060892b1f02ec6a640928e4866cd6752b56b8d8.1737106761.git.leon@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: B8ED6140011 X-Stat-Signature: rsj4uhzyic6sd1atmq3i6yuret9ky99q X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737108269-888096 X-HE-Meta: U2FsdGVkX1+1CnUp2f7W44DrSQiLLCmWTirz0NABXymEqemZ/3MiG5G1wr7IISCQhPS7fBihVXvdFs4h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LdLc6008ziAScmxxMnTTep2E0veKXjTso+/DCXD+/z+PPWPVkAsXux0oASUaaySiIMLQ= 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 Signed-off-by: Leon Romanovsky --- Documentation/core-api/dma-api.rst | 70 ++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Documentation/core-api/dma-api.rst b/Documentation/core-api/dma-api.rst index 8e3cce3d0a23..61d6f4fe3d88 100644 --- a/Documentation/core-api/dma-api.rst +++ b/Documentation/core-api/dma-api.rst @@ -530,6 +530,76 @@ 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, + 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 --------------------------------------