From patchwork Wed Oct 30 15:12:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13856687 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 AAC6ED5CCB3 for ; Wed, 30 Oct 2024 15:14:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 444356B0082; Wed, 30 Oct 2024 11:14:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F0F46B00A6; Wed, 30 Oct 2024 11:14:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 219FD6B00AA; Wed, 30 Oct 2024 11:14:11 -0400 (EDT) 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 F1C376B0082 for ; Wed, 30 Oct 2024 11:14:10 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AFB02140E93 for ; Wed, 30 Oct 2024 15:14:10 +0000 (UTC) X-FDA: 82730612538.20.3F7172D Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf14.hostedemail.com (Postfix) with ESMTP id 2F98C100019 for ; Wed, 30 Oct 2024 15:13:40 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YiKlu4D9; spf=pass (imf14.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=1730301088; 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=DVzPaReK6bZLdA6DSR8HvqCwZ/5n23XgmH66ialyCvo=; b=ufMFe7Pd6O/LVEzunT2r+kr2436mmkcwassawml4K4HjBcPG8fBNySQlNMyPo6VPqaLluf s4rC5u3RoFbDE+Wt1xXsk8o7dgy/lY9asPEpbqRhr0tiZAKAgUl8W+e2c3tdv1ZCnrFtJU hZBS+SQJ61LxiD9Kw9pBUpoIyRgPatY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730301088; a=rsa-sha256; cv=none; b=tukXgzP4RQVqxMXrPHp3jGpJ6IPbzDgRvMLZewzD459Hc6C4Y3I4XU4jOpbs//9QH1BJo7 7m05Y1CCHcWWw305gmsCHEoVvOFWYv5P5GSs7JaUcr5jjWIr4RyVWpXpBt7KrVsIF0A1I7 TqaopVds8R8+GpR46pOdDeAlT7nRpEM= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YiKlu4D9; spf=pass (imf14.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 86FDDA42606; Wed, 30 Oct 2024 15:12:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A444C4CECF; Wed, 30 Oct 2024 15:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730301248; bh=v8Tw1BMcIKkWkecbyVD2bjlFo11chEXusLhfEENOi8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YiKlu4D9JMFXIyH5CmKlxglMedckpIJ1J4QcbKrlh88l8Zu1/lpOaJ+4iUCQ32VdQ 1/w/S5Ll4gaGts1LS/6zNykS3hYIj37SlotuNs/IhO5EgX3KFxe41mBrokI8wyI7ef Gp2Gs1Tzb7aT+be/27/nlttyo0HlPv0As+XQTeqwvrhqhAVeILkoq/Cwoi8TsWZpvI aBmJLDqQ92v/ZE4BX9FujIHUuLZQOX3O5CnOraEuYgV/e6eeIWHRzr4MvlA36P0xgm K2m6ssfopeA4RM+gktE/POocZtuUrG4q4SRR0Dqn+ON1d1X1m2VtsMaoVQg3qJTO5i ESfBwP4gKV70w== 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 Subject: [PATCH v1 09/17] docs: core-api: document the IOVA-based API Date: Wed, 30 Oct 2024 17:12:55 +0200 Message-ID: <881ef0bcf9aa971e995fbdd00776c5140a7b5b3d.1730298502.git.leon@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2F98C100019 X-Stat-Signature: me8ekwqiisi6jdu3tmp7qpzntcna9koh X-HE-Tag: 1730301220-434284 X-HE-Meta: U2FsdGVkX19I7bJ+IOG0JjEXNON3PQSmHzhc5/tX+Sp2tO98I5335udSJLw0YIuIfQxbX7kJgi5+GnXA9dSSncTTujixyaQdZFSUWwNTlsgQ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pkJRMbypVffwRfksZbphyzMIa5p1sChBM8qqY/PTuYgw4QIopRTbdTsqBOnuc= 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..6095696a65a7 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 consideration 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 previous 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 --------------------------------------