From patchwork Wed Nov 6 13:49:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13864479 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 51B3ED44D55 for ; Wed, 6 Nov 2024 11:50:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D20E06B00A4; Wed, 6 Nov 2024 06:50:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA9586B00A5; Wed, 6 Nov 2024 06:50:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B22746B00A6; Wed, 6 Nov 2024 06:50:30 -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 9205F6B00A4 for ; Wed, 6 Nov 2024 06:50:30 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2B277121B8A for ; Wed, 6 Nov 2024 11:50:30 +0000 (UTC) X-FDA: 82755501528.21.38AB169 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf12.hostedemail.com (Postfix) with ESMTP id BBADB40024 for ; Wed, 6 Nov 2024 11:50:12 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CPKt0RmE; spf=pass (imf12.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=1730893604; 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=ufN3FHn90uJODz3lZznMDmn2tX4yEQe0kEyo2vbDgPE=; b=nXwp5gpArMXTAZ82LE03sx5GV7Brq9MEBE9rrxNRdH8Z3wCA6v2Wm7Yv6XHmnhkNUis9x1 uTInNNkosgnzm2w73zP4fI/wgY0jW2h3YeYIeP7a1PclpcNn6uBOvR3dVJj/FSqKtriCEb EXvXdUyznwKKNd8YyOLOCHC1It8XUFo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CPKt0RmE; spf=pass (imf12.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=1730893604; a=rsa-sha256; cv=none; b=ruE1ElzD/eVK0o8U4BljLnn55UukCQ2aPqdoRCR+XWOUBoMt6knaoxApXfA2OgKnTILJOu LQyrKTu7BBiU9gE7c4gzyLjDtpmsJYCtwHTNHnoJrbJq8e5eV3iFzO7lA1eeEf3T0NGgRe 9q916zrp3bVLCVJFMp4hSQ34P+Jfoh8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 7CB58A43791; Wed, 6 Nov 2024 11:48:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01EBBC4CED4; Wed, 6 Nov 2024 11:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730893827; bh=YpLncFZbCC4w0IIg6h/rxYvmMz7724GLt2jYf2BJ9P8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CPKt0RmEs+twSwZrjBuZS3z1TumSSHlANGJfIYdJlCk9AI1+NsA0YsgTfhV78rvfq qJvaJwO7y/8com5A+snU0wmAG0NDd01+hgPmXEpxeUCa2DN0GM6XmgRAKoh6sePJiM YVZqJ68T4TnWXOaZFKu/AhI3pEYtdE3GQcZfPb6erHNqj9rI6izEhCW9u8j+c6nEko C1GvD+pT9DzE3XbckN/sgPYF3XA0ZF7iMV0H/WH8anFPHPFORwIpEYcO0LABx/DW10 T/ylJ0INirZ2pg5F8EqiADFiNkkjrR87l4TRD8qCeDrN9tDGMB7bpxfJfhO3/o+3zX XGtRFLP+6hRAg== From: Leon Romanovsky To: Jens Axboe , Jason Gunthorpe , Robin Murphy , Joerg Roedel , Will Deacon , Christoph Hellwig , Sagi Grimberg Cc: 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 v2 09/17] docs: core-api: document the IOVA-based API Date: Wed, 6 Nov 2024 15:49:37 +0200 Message-ID: <64e7a24f7d59b21a16ebd86d4164b8f23f871da0.1730892663.git.leon@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BBADB40024 X-Stat-Signature: 1m7j3kdp36kq17skdbr9hak597dic5ek X-Rspam-User: X-HE-Tag: 1730893812-804323 X-HE-Meta: U2FsdGVkX1/Ud87SKV1CWxlKGwUuWfyRGlXCMlFKXgmOauG02zoeTXxtNAPhujllJ9wBo9idtiJa+jz7VQQLGCjrozCa25M6jFshrfbaCya8Putuif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rn+XNj4Q5HILbLHX+DGpj3VAPRgXS/1iWxzygjjyQa7U+5vIJ5MNp+1jEjhcfRDHeA= 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 --------------------------------------