From patchwork Tue Dec 17 13:00:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13911737 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 D5E17E7717F for ; Tue, 17 Dec 2024 13:01:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 644276B00C9; Tue, 17 Dec 2024 08:01:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F24D6B00CA; Tue, 17 Dec 2024 08:01:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 446066B00CB; Tue, 17 Dec 2024 08:01:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 244796B00C9 for ; Tue, 17 Dec 2024 08:01:37 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CD3041206F1 for ; Tue, 17 Dec 2024 13:01:36 +0000 (UTC) X-FDA: 82904460828.09.04B8330 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 114B04002B for ; Tue, 17 Dec 2024 13:01:06 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tg6kK2qm; spf=pass (imf11.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 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=1734440481; 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=FivAkKc0r+9eSGFzmi8AZllUegxRDjjKNjdzcznvaiJryj/zOq7vWcgLoXmVPzJVa4isNv HQ14CY3pEjfREt1FpDnu9FRenyTe79YgfW5b0Win9H8eSxDQIuFChYl3tNXfZLc9zyIrzz ZbvMA1SgVt7PaLLKtXdZucZScfec/k8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tg6kK2qm; spf=pass (imf11.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 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=1734440481; a=rsa-sha256; cv=none; b=tiOcLhsTrA7sSvPLqFe+XiIAuBsqjCoUv7BxcnYKZ14Quwm2pFgiUxnnLcbMZePaSLEpZ4 RzB/wyXjDl/0sjasyQ0P+o3G5G0kASvBa+EW5EOSWrC5vavs8UWCUIS/pvaBQ9RiwMeYg0 htqVhWI2x6E0dXjWbm5/EEAF1oNlXZI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CD8155C6277; Tue, 17 Dec 2024 13:00:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEB4CC4CED4; Tue, 17 Dec 2024 13:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734440493; bh=YpLncFZbCC4w0IIg6h/rxYvmMz7724GLt2jYf2BJ9P8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tg6kK2qmIeXpkyBNAqUrrqpIInx6lG68O8eFGOoTI8XlWOQ90vnCxtLWpLCg3tek7 +mkSXSecJXcyowLYbWlFKUYpU5IKIAIKW2kjJwASaVqUxg6ZGk0MawOxgOx096mmdA 1JWSgjuN8fvdqalE10IOhWVwBLAdG1cZh1RLoJD8VYIcWolggNPLaGeD/7ejY5raSl x4YO2o5/6l2S5lCxfVeuhfanErorNgKvKbOo37Q2mxbwIw60ldyMRklbWCuAPFALdS 5ryuX75bpg0AGVGtp/oNQRa1i9qgi4vC/P+5pstrlHvkt/yXuT1PmW7FWkOn57+C1E VZySTGqqNUXTA== 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 v5 09/17] docs: core-api: document the IOVA-based API Date: Tue, 17 Dec 2024 15:00:27 +0200 Message-ID: <8f1fc0969bf7d7db11bd27d4c6b7510ef8c3ae5e.1734436840.git.leon@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 114B04002B X-Stat-Signature: kxdi3br4jg4mrgbjux4nmc7eobkcf4tm X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734440466-554541 X-HE-Meta: U2FsdGVkX18J72sPcRDz2GSXgAijJDX5hDjqoNGfCa/G2IE+7SP7gRv8UYaGlmGA8cVXzIwzt4G4L7zD3D/mwyAC7n0NR32t0iSQpjbx3PnGLiN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UVgPqqlNXPk5opxMpH9QZIfxPaFS654Hmzl5ql8= 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 --------------------------------------