From patchwork Thu Dec 5 13:21:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13895255 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 9AFFDE7716C for ; Thu, 5 Dec 2024 13:22:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 178E16B009C; Thu, 5 Dec 2024 08:22:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 01A766B009D; Thu, 5 Dec 2024 08:22:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD5E76B009E; Thu, 5 Dec 2024 08:22:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BCFC96B009C for ; Thu, 5 Dec 2024 08:22:06 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8422CAFA1C for ; Thu, 5 Dec 2024 13:22:06 +0000 (UTC) X-FDA: 82860968022.06.0A2073B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf26.hostedemail.com (Postfix) with ESMTP id 04266140010 for ; Thu, 5 Dec 2024 13:21:52 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O4Mi6PlM; spf=pass (imf26.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=1733404917; 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=Bt1viYiK1SsSKpPlU7M1enBqu7KQc/jtkzFWNQZShjc=; b=OOHxkT1XZBjvMa4zwuYtz6qIk40pfJnYudCm8OXnP3VYlCjByv2jqUjRFuvD/cWitcrMRN AYY6CPOaWblh2f9fagCOSQmAdxi4CsBrVUbK0NJ4Wfgn1V6JlPHuAeT6d3f/CWSL9AcRqT /B7ziNwLnne4K7hTyNA/P5Ob714Yaco= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733404917; a=rsa-sha256; cv=none; b=O4keAeeDgxmybJ22t4GZEdBX7Uqx5ONeZ+nNzxYG7UOPpnFZ2k4syZk5Yo5cE524WLqr2H gBnt6aJmEVW01zWf62SeRMZGoCgbtpIZaioSTpLRG/EQz5hDyFZ+i/Os+uMSMLpK17Kswe tCGn8nPSPIXcdiA5EQ33Zv/Q6G1U5Tk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O4Mi6PlM; spf=pass (imf26.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 33943A43838; Thu, 5 Dec 2024 13:20:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D91C4CED1; Thu, 5 Dec 2024 13:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733404923; bh=c7G0IPK1mqvX8tD+gZt9wA9o0XSfmNwzbfc+aT5KHkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4Mi6PlMc5Kk5ONaki5WsllSppTqpgAa328x+Stl1A9wYBWAFD8nbJXEZENsWBe5a Ox/ODlM7KuZ2PJkCwJ6rb6QzK1So9RSL/tJ6cGOtyUsMiWfwuKrO5m8V9TF3AhQAv5 Xi4Z5qhRN/Q+ze5bwYUQYkblhXXN8iF+xHXhL+/qycoVOEVV6zBshynwV90neUbwrq vHCjJ091bFqflzXkFftJ1Gc0N5DSMs4yefOFG2Jrpct8bsXYFWwHCqi2OWod1I6vOy SSOUaxGpz1rvG8uSvOefAqbKaOoCpt+zyiA8qYixIGrcKtaJ8VsUy1/z2EniKDUQjO x6BWHFHmlr3oQ== 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 v4 05/18] dma-mapping: Add check if IOVA can be used Date: Thu, 5 Dec 2024 15:21:04 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 04266140010 X-Stat-Signature: cbkorpntocm8zyd9fh8sjj754od3pnen X-Rspam-User: X-HE-Tag: 1733404912-291051 X-HE-Meta: U2FsdGVkX1/8mIBEHp/LMsKdqFPAxedvmddPoo41YdYy5nE53ddPVkq3nZOO1mKQozX0raobQJ88bRxtMwxNGq31Prd892jeJYwvZVSRwLLLJO2l6iHtPpLOTsjr7XJxBPFQi5hI4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o35uBibyCYS0qSkjyxU= 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 b79925b1c433..0d1fc0a2fc0f 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -72,6 +72,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, @@ -277,6 +291,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);