From patchwork Thu Dec 5 13:21:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13895256 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 7406DE7716C for ; Thu, 5 Dec 2024 13:22:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFEFC6B009E; Thu, 5 Dec 2024 08:22:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DAF116B009F; Thu, 5 Dec 2024 08:22:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDAA16B00A0; Thu, 5 Dec 2024 08:22:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 99D586B009E for ; Thu, 5 Dec 2024 08:22:10 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1EF181415DB for ; Thu, 5 Dec 2024 13:22:10 +0000 (UTC) X-FDA: 82860968316.23.8252811 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 913E1180019 for ; Thu, 5 Dec 2024 13:21:52 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aSt1+gaq; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of leon@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=leon@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733404913; a=rsa-sha256; cv=none; b=P1Ff5VN45qGtVH+siyBMku99r5CRjkwfbpIESluypGHBQItwRsaSPP1lwEb15hHGc0rJAx eiEZSBd7J1WZrtO2nWgQYaVAJH5tWrXrFZBiks1/rBqFeEDncVOq2of3W4NgUvH7hkA0JX /L5/044cORPj6JnBh5UKQmnZDUE7zoY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aSt1+gaq; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of leon@kernel.org designates 147.75.193.91 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=1733404913; 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=w+yYZMh1Oj16FBGOCU/6MCLzMRsWqNI4i/51jPo49xLr8uKBqfkD1zwImtbDByfogfnHKs /lL25CzfrJx2/AqtF8TLbOzi7oBS420sJcSnCzZUgQ3t2Z4sidqZVVWKAak7vU3iA+8vEb eSwwQ7ri/T8Ac2HHp2tRcxOK3EDOMMw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id CAA64A43841; Thu, 5 Dec 2024 13:20:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF702C4CED1; Thu, 5 Dec 2024 13:22:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733404927; bh=YpLncFZbCC4w0IIg6h/rxYvmMz7724GLt2jYf2BJ9P8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aSt1+gaqmzXel703ljo60m8NU49Cw25z8my6mmvfnNJdEBSIcS8PxdxToWjPQe06n h3kHS/393oidMe2+xKTaLMmTTmN3QjJQdUQU/qd6pS04igYrv5S2NCUs/kaKNgTqgS AbkmkMFplFZY6vhEfpArLyyPA0P8twNZX0ED3dPphkqV6DJGOcwQqXisaNlbUJxeWZ 5Y7fwKmXc+QBK/K6u5qUyQF7r0/3STOK9aHpuakuGhH8F0hZ11UsDSZBqpt434eTeu hySxMWnn3TBjhxcCqCkhxuXcRj2m3xRrDZ4cgMy6LZzZO+Kx4UZIBrxm7NUabKqbe7 gxdefDMVn9RqA== 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 v4 10/18] docs: core-api: document the IOVA-based API Date: Thu, 5 Dec 2024 15:21:09 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 913E1180019 X-Stat-Signature: yifkjmr83pty6ifm4errpmit35pkyizm X-Rspam-User: X-HE-Tag: 1733404912-907524 X-HE-Meta: U2FsdGVkX1/J5eWY8K+cS/4WHV/HYSRkZSd+DuUiI1nRJFLrLPT25xVCVtOCx7GcuMBDIptWfPaIvrk2x69yZyXNebG0wtNQ8vQO2Aps70po5SWEXVr3c7rm10GthiRiDuBlaOaqPPzPxyGIYmB3zulyNQt6oYy7Na6oMG3BeOf7pdROdjg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=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 --------------------------------------