From patchwork Wed Feb 5 14:40:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13961189 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 3956FC02194 for ; Wed, 5 Feb 2025 14:41:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD646280007; Wed, 5 Feb 2025 09:41:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8483280002; Wed, 5 Feb 2025 09:41:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E23E280007; Wed, 5 Feb 2025 09:41:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7652B280002 for ; Wed, 5 Feb 2025 09:41:37 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 30B6CA0D04 for ; Wed, 5 Feb 2025 14:41:37 +0000 (UTC) X-FDA: 83086154634.07.884205E Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf07.hostedemail.com (Postfix) with ESMTP id 9AC634000F for ; Wed, 5 Feb 2025 14:41:35 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G7y6FNpG; spf=pass (imf07.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=1738766495; 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=hhLvg5xENLD8Hdo8SBjemzkxMX4jbTWJP8evBqnvRIY=; b=5hjigd5ZJYvGpEz3LmH6TBTjuLspmgyAd8QFmS1LVI3wW1pAZRNGr6QInHO55357IrSTp6 vj4pPD0Z86bwYI1O4BNItdW5n3so6LRofrer7zCsyR8NxRP8VdU+deNCWGdM6/AN9nMi1q o/h9Xy9uwrnhaOs2iO2Mi9xWQCGzkKA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738766495; a=rsa-sha256; cv=none; b=ad+0nd8MPhc9IEgkYIlvr3nUMSTiYCjULObCBK2O36tPCqyw0I0hpVhF5fm8pji0F8Sl6h AnTV1MurHpeYTWnH9+kJ8Somru6C64P+iNnsIyL9xSmiT54Wgzou5YB14eRx4wrJ6ItYJz cn1Tk6u6cez9S9Lwio/Z6rnRFt18UhA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G7y6FNpG; spf=pass (imf07.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C5B31A436BD; Wed, 5 Feb 2025 14:39:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75406C4CEE2; Wed, 5 Feb 2025 14:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738766494; bh=bwt/yttc57skms9Ne++frz0MugkbreUIXAgb1ccLqXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G7y6FNpGumoGrA+jV3Y8fmODmJJ7PYXSr0PbcK43L3T3pldBjHH5k+mxWah92Ei0r s0NR5oe5OqAX7KCtL0D5BdnkgIx0cZFUARawFKJAZy2n1/mkwDYzYVLLJMOWBVW8nX JNGxLhON8Ukz3k0pT39ARqaLs9kOA2jwslCT4NUOY8ZPo5EYbm0UOJD2BGGoYh+tJS p6v9FAc27I6tmAoMyKhiOH0t8rhKWk0Cfs17Uwd4iJa2RHOZ6XcTk+gTVqVU0ythyC 34qrycHhfu1HNKHYq9+r7Z3G9HhUInj6L90FxWP8OkRQKfkpJVrSBY3moIVL7/ctyc 6WCrLd3BZ5jIw== 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?SsOpcsO0bWUgR2xpc3Nl?= , 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 v7 09/17] docs: core-api: document the IOVA-based API Date: Wed, 5 Feb 2025 16:40:29 +0200 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 9cuug9wuzk4xn7ppqn1y3xbt5n1bcu1y X-Rspam-User: X-Rspamd-Queue-Id: 9AC634000F X-Rspamd-Server: rspam03 X-HE-Tag: 1738766495-258594 X-HE-Meta: U2FsdGVkX197jCkra2mQ6qyUEnhoOhqf75DYnphDoIZIGz1+IBVfZ/lVTy1kcG1oLYyik1yBC7wRVBoLb+gSfSSMKs0NhKW7driW1zycfNJNaup4kB9ljJjVd2yrr1mfxOtvfQfknX/Qjz/kfrfT7vIG+/g/pzh+9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ack.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 --------------------------------------