From patchwork Sun Nov 10 13:46:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13869830 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 E14D6D6409C for ; Sun, 10 Nov 2024 13:47:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 778A36B009C; Sun, 10 Nov 2024 08:47:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7018C6B009D; Sun, 10 Nov 2024 08:47:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 555656B009E; Sun, 10 Nov 2024 08:47:55 -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 367CF6B009C for ; Sun, 10 Nov 2024 08:47:55 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B5C04120E1C for ; Sun, 10 Nov 2024 13:47:54 +0000 (UTC) X-FDA: 82770312576.12.ED363F7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf02.hostedemail.com (Postfix) with ESMTP id DB64D80006 for ; Sun, 10 Nov 2024 13:46:38 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JpQZxNP0; spf=pass (imf02.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=1731246243; 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=YwvThwxHYJJkKqaQNWxTxm91AL51oJoEpswNkB0je+M=; b=cRon3ZXMHpzilUyp8gn/xfufntjp55/3fEDO/blaCoKLPqiQhNcsbMxP9MV7IhLmmuHuQW MExTnnjUxPnhCTM39ZH4WL35sj2L9aCsxJcrKnodKiDhj/Ph6AySHaNzOAW5VK0KGrM3mH WbLv25WGCnLqofh0/5oh3zDvsfbRPdY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JpQZxNP0; spf=pass (imf02.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=1731246243; a=rsa-sha256; cv=none; b=tQ3UbfB/yIz7DGtLWhoVLqLn9SHMl8pGfg2WNgs6xPk81P7DgGGpszfuuY2CLxwKMuqrN8 oPU0k4lVq9yzlA5LTNt4o8E1G6/k6vRaIY3Zn5x0+VZColsTb1XhJxeztXJNuEWH4lekaw J6OzAxHJt+khZps4gFnFZuvjW5e38M8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1EDDCA40CFE; Sun, 10 Nov 2024 13:45:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19CC6C4CED0; Sun, 10 Nov 2024 13:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731246472; bh=5m1d0+DTyGkZRlNmd/gGqpR64QjDJCq1VneMI9ozY3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JpQZxNP0/bC5tFyQm/Gazifc4568RD+Yg/FkE3Ofni8YbtijuQWSE5/BsL9I7TRIz d/RXYEPyH8iP4wRDbG6DfLMSA6pPHJTkZz8ENUOag3L+0rObkmUTPhB7xpiELWr3Ff PdmjPeQKogd9FHcx6LxoDC82pYQerSIIilLnnSyObsXYq1XCfW+DK33ZUw9Vl2lOHi lE0hco768LIuDXY/sbzWTGLzhc9cqye91fohpaow/FYKQmoQ7EI73yVjhtxNzfk42g KHLj29NkXl9zLUClqPvWsDxqezWz3ShXkOu2k085FuuJuKznb1m1ZHnJXshTfWxjxQ AtsShAg/8wtvQ== From: Leon Romanovsky To: Jens Axboe , Jason Gunthorpe , Robin Murphy , Joerg Roedel , Will Deacon , Christoph Hellwig , Sagi Grimberg Cc: Leon Romanovsky , 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 v3 04/17] dma-mapping: Add check if IOVA can be used Date: Sun, 10 Nov 2024 15:46:51 +0200 Message-ID: <9515f330b9615de92a1864ab46acbd95e32634b6.1731244445.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: DB64D80006 X-Stat-Signature: jt7hwnuakpimbq3xtsdj1zgejgzoethn X-Rspam-User: X-HE-Tag: 1731246398-834102 X-HE-Meta: U2FsdGVkX1/4UgaLP5A9zCV4bZX7JLRGQFsFIbyW0gwaIzHaIL8zGEbD0NYw7MLW7yUX33cCoMURXha8SE4YYr+zdm/9nYNOROPPg3wjVzrHea5xH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YXMidoDJ9Q48+nV8qHGWQ6zJTx8uYd6ZV5Lxuuo/pWp/v5rddq8twjeBcog5BAj1DOIexIkR7BwvtvKnU4ZjORcUJ71buRgyki/RBE0sjsTWgmr5u7vjkfjT8NgDZy1Q== 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: Leon Romanovsky This patch adds a check if IOVA can be used for the specific transaction. In the new API a DMA mapping transaction is identified by a struct dma_iova_state, which holds some recomputed information for the transaction which does not change for each page being mapped. Signed-off-by: Leon Romanovsky --- include/linux/dma-mapping.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 1524da363734..6075e0708deb 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -76,6 +76,20 @@ #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1)) +struct dma_iova_state { + size_t __size; +}; + +/* + * Use the high bit to mark if we used swiotlb for one or more ranges. + */ +#define DMA_IOVA_USE_SWIOTLB (1ULL << 63) + +static inline size_t dma_iova_size(struct dma_iova_state *state) +{ + return state->__size & ~DMA_IOVA_USE_SWIOTLB; +} + #ifdef CONFIG_DMA_API_DEBUG void debug_dma_mapping_error(struct device *dev, dma_addr_t dma_addr); void debug_dma_map_single(struct device *dev, const void *addr, @@ -281,6 +295,25 @@ static inline int dma_mmap_noncontiguous(struct device *dev, } #endif /* CONFIG_HAS_DMA */ +#ifdef CONFIG_IOMMU_DMA +/** + * dma_use_iova - check if the IOVA API is used for this state + * @state: IOVA state + * + * Return %true if the DMA transfers uses the dma_iova_*() calls or %false if + * they can't be used. + */ +static inline bool dma_use_iova(struct dma_iova_state *state) +{ + return state->__size != 0; +} +#else /* CONFIG_IOMMU_DMA */ +static inline bool dma_use_iova(struct dma_iova_state *state) +{ + return false; +} +#endif /* CONFIG_IOMMU_DMA */ + #if defined(CONFIG_HAS_DMA) && defined(CONFIG_DMA_NEED_SYNC) void __dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, size_t size, enum dma_data_direction dir);