From mboxrd@z Thu Jan 1 00:00:00 1970 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 C5C05E68942 for ; Thu, 31 Oct 2024 01:42:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 571276B0099; Wed, 30 Oct 2024 21:42:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 520EF6B009B; Wed, 30 Oct 2024 21:42:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E8866B009C; Wed, 30 Oct 2024 21:42:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1989A6B0099 for ; Wed, 30 Oct 2024 21:42:14 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0602BACF5B for ; Thu, 31 Oct 2024 01:42:09 +0000 (UTC) X-FDA: 82732195476.01.91EDE40 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id D0CC0140016 for ; Thu, 31 Oct 2024 01:41:47 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=S6EPMqUn; spf=none (imf26.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=rdunlap@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730338847; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fq4kJNH2CAE848TPhhysdxKjBpD694h5FnzeuEmb1qg=; b=Fil2OMP/OLFuh4y7+4/FFp+fWTrV+m4CU2uSSePIF2pafMYsz3U24Wg4iexC1LmuzVH+pc RiBWI9l8eXa8KPLM4NsbCq7FTB1LvFzKAMn9AkBG0H1PegTeGaN1b3FmTqd9I9RIC8R7pI 2eN0x2GwlJAahvkrtqaYW+9XBBo1WcY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730338847; a=rsa-sha256; cv=none; b=IfxoVV4CIsaV58cxksQdvqqOGcxaFNex2AZR5zYKBxQ2Pm6IpZgkQFyeUDBQjG0x1oxX4E 6R937NEZye/hzw//wFWZzCOSFVCqGor4zpVmQIRsAQCQUudNSswL2I4Ug+paXxSUsxg7sU 3TpxZ9gce/FJ2aqTubg8pqm2fInmMZY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=S6EPMqUn; spf=none (imf26.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=rdunlap@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description; bh=fq4kJNH2CAE848TPhhysdxKjBpD694h5FnzeuEmb1qg=; b=S6EPMqUnjSMOY2vNcllwd8p6Ox BPtRyDbTyKdeu8zN7/wLUeNEzO4yOt1VTpHholffpA3y2fXCRmfGBwbaq+MhS7i6uXvZPqK8EWMf1 vdnR+ykKcs42+hETXuNdH86QIsFdTsFb5DdA2bI/GBKPhibpWGo8LZ3PBdnL6MNt66IGi5rIDxwfh Nm4PIrdldIDwzVjNZc3a6VarZ5m10jD/+0k0wQ6vaP/5ECeWPGuh0sdOuXzd7qA+HFGDz97uZOAV8 aVCodx/6OFerCofoyBUjDKwTi3nqK7mNz0BN5W9cwhuz4xTFN0XerCsGsF3834u0w+0svVHPsvvbO Jz1tZyPw==; Received: from [50.53.2.24] (helo=[192.168.254.17]) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t6KBm-0000000E8Yj-17R7; Thu, 31 Oct 2024 01:41:31 +0000 Message-ID: <19cf7d58-4a28-4ce8-9524-8c99fdc79062@infradead.org> Date: Wed, 30 Oct 2024 18:41:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 09/17] docs: core-api: document the IOVA-based API To: Leon Romanovsky , 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 References: <881ef0bcf9aa971e995fbdd00776c5140a7b5b3d.1730298502.git.leon@kernel.org> Content-Language: en-US From: Randy Dunlap In-Reply-To: <881ef0bcf9aa971e995fbdd00776c5140a7b5b3d.1730298502.git.leon@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam10 X-Stat-Signature: ks59b5dode318imshkc7grf138umabaf X-Rspamd-Queue-Id: D0CC0140016 X-Rspam-User: X-HE-Tag: 1730338907-969272 X-HE-Meta: U2FsdGVkX191oLSj291aUiee6b09U5TBc5TzAyP+EitTvDeHuyW2UVh1SxHQtKYtpc+lC3mTMRjiwduWQVlOStinMqjY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dDswY+sQxZZrZ/CASbSOsnKCQBBIvk3qsIS8mY2xgTpp1zYDLVCYmrR2dfgvOkC4mgwe7bx3rie8Au1x+Q6bE28+rQnqkzOSfS/I5WwBz2X7c6o5Kxk445AYO26Zbassjdykjityyvo5Iac7E= 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: (nits) On 10/30/24 8:12 AM, Leon Romanovsky wrote: > 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. considerations > + > +:: > + > + 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 previously > + > +:: > + > + 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 > -------------------------------------- -- ~Randy