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 D08A2C369CB for ; Wed, 23 Apr 2025 08:14:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C1F06B002E; Wed, 23 Apr 2025 04:14:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 950C26B002F; Wed, 23 Apr 2025 04:14:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C56F6B0030; Wed, 23 Apr 2025 04:14:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5A5246B002E for ; Wed, 23 Apr 2025 04:14:38 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C88C3C179E for ; Wed, 23 Apr 2025 08:14:38 +0000 (UTC) X-FDA: 83364597036.10.C573BFE Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf28.hostedemail.com (Postfix) with ESMTP id 49C98C0005 for ; Wed, 23 Apr 2025 08:14:37 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pxwe7iTc; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of leon@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=leon@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745396077; a=rsa-sha256; cv=none; b=Rzoh4T3g/jQ+xtwfg0o1Z9Chr+4KckWu7vRfxpGVJ2QeLERUixMqA7DT5un2VjHyPmJjsX VbqWHpvQ5nj/atIn/T2d0XGbIL5wJzBdU5Ymrjksaaoh/eE6B9EfMdGMb6VpRYw1/INKrz ynGBxWX8xBcdSPbdNDZ6YuUlQzgYQbA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pxwe7iTc; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of leon@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=leon@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745396077; 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=AbmtzoWbyKvy5LspWBa4yoKz2Z4w+i42U4lYr5DugKPyTDpe17WEczUo2XUCXP3jR1VBb5 Na8YRzipipIBNzYy78wSKrYDa1V578Ij7OrRAPxYfsGLe02uG+xgiIuypHSeIkIZxaYxZ8 Zdo8PHqAujenZ5QYNmA0LvKx/Glus3k= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id CDCA24A43E; Wed, 23 Apr 2025 08:14:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F16CC4CEE2; Wed, 23 Apr 2025 08:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745396076; bh=d1+z79zg+kihe5QDvuiZPuBTqwMqD9eJrziwPARATZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pxwe7iTcgrDrrJrmcOzX972ifQ9D6JVEhDyjPcwwbwuVl5WBAXYDa/8l4DwaLlO1Y vWsvyN8+xhjntksq9HHQv/U5yDIQ7bXtbs603iaK9U11b3NwRT8KTo7Y16zEYpBwAb tekXO0ynYv4MEb0+spPpvw7nl4VYxfxNCatQQ4wLsfvGxwO1M7Nx+Fq7d37PGV8eWi FEqyUa6I1tPF5wbesUJJBhjietyGAKhO/Ixdu0i9NC9A91a0SuSF5RdIyowf8I/PLc cdrRTsuDCiC9V64kjPfH592VX/vNZGPVXZWQfZlhD2D+uTZMCYmKBCur2EngxrpVBY rnT3jQf4b8oTQ== From: Leon Romanovsky To: Marek Szyprowski , Jens Axboe , Christoph Hellwig , Keith Busch Cc: 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 v9 09/24] docs: core-api: document the IOVA-based API Date: Wed, 23 Apr 2025 11:13:00 +0300 Message-ID: <7d5cf410e923a22c519ea60f4f35e3c9f8f845e3.1745394536.git.leon@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 49C98C0005 X-Stat-Signature: fgjpomcnj7jgw7jfxeattzarrfgynysw X-Rspam-User: X-HE-Tag: 1745396077-670978 X-HE-Meta: U2FsdGVkX1/3pCm9fnHewJNDmjjoZPxJ0m/HcC0aEobr4mxvyR3utsJUELFU/lfjIXjuvR3jyF8AfLnmyUANyoSShEfPGjo9fyCyQwWEopUWAndMe2vBcVF8tvuVBbZCNI4ttAKVXgseJslc257ER3D2w5d0pfBK4rSQ02qoyx9PED/g8pigcbSO8ITfrKO8Gra+k3klLAXdIVIk4s3adk09O4AFK9hgAMNBWQ1jW546oS65JlsmlVHQNxqo+kg7xobNZnRn6F2lTj2ZgBVpMp+N/EYf+i8CTFiwWzLAMgouW0Qjx9E1yA+NVwMIs8rSCAIFwvJ7wnVoN/TnhBvYuJL/44sNlOdArAem7ZiMamblrcxfUWblbYznKZS4a9knSJbvSOSyEAlOIIYdF43ciDQ3fJWLYMk/4S0MLHO0fkKgFn94wOC8Fl89yUKtF5jepE5NJ1IUTbGq4FOknQBSzbNCZcHMGG6MBG/lr9PIU9bhwrgym3ZNs+FEiiuiuqLdafX+ejboc9SIZYxNB4DKJy11dapJbR2bg9/xCxQLsWtIuiawn8F2q0me5CZgo6a84ywDmb/77E0yuBRbUf1OzhgHAks/6Kzm1O/Fg4Li48EeQoyfITnr0s5rDNU/rD2bwvsuE/A2fpQKeiDCTDW/Tq1+yusqux6rxLwYctoeC1IG16W2ZMK0WrffbkI8Ed63pq90xRNKWLuJmhVm6iNeJbpv9+vRuEuI9FfFBfhwzmOVRCQHJPwHX89zL/bzNN6n/KC7dmODk/mXsjJtxlqP8vHlwEvzutwzxqjFgqDMCJhHMc34O3fhnorflO0OPaeOxrjiUs3P/E71Fshygk1Y3w1sCxFib2Ia/Fo/rmvyosIOT9CQvoRR5FLiWWfWdGhkeXQ3m0/2EBNz/Dm+ub3a9pwi3OZg1kL3iF9A0InnKLJhDjrfwVG24Q== 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