From patchwork Wed Nov 6 13:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13864474 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 DA8D7D44D55 for ; Wed, 6 Nov 2024 11:50:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7055A6B009B; Wed, 6 Nov 2024 06:50:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 693236B009C; Wed, 6 Nov 2024 06:50:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5090E6B009D; Wed, 6 Nov 2024 06:50:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 250096B009B for ; Wed, 6 Nov 2024 06:50:09 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C4C76AC9DF for ; Wed, 6 Nov 2024 11:50:08 +0000 (UTC) X-FDA: 82755501108.11.FE5F2AB Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf03.hostedemail.com (Postfix) with ESMTP id 54D852001E for ; Wed, 6 Nov 2024 11:49:51 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mO7dSWXm; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.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=1730893748; a=rsa-sha256; cv=none; b=x00beFHMuOjHEsw3x/U+fzvrPbOPmhgQ2t7lCAjI2ggGIRcPFiUA17ked0LyOjhJaYomzR dcO2uaLEOmn6cbsnXzk+GZfHeBH37CYz/Vq0D31ned7qe4DVhqlrNucnsb2gOZQXcIf5LM 1hCZUpsEbJT7vvzlumFvuN+tSVtGtU0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mO7dSWXm; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.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=1730893748; 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=8CHkBcItOREgzmZlhAm1WhxrrLHlP3YZiQPzdVabBXrvmGPR9orN07Rx3mPBAozRlZEmet 5ahyUgPeUdYU5Zu7vvFQ+zLdQk8xVzJn2IeEVAagcemk+b9bY365PhAeCd54S0dDg+fBmQ 1AWdMzzVMW1U7cJN6o32hwkazSBp00w= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 828C4A436C2; Wed, 6 Nov 2024 11:48:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 476E1C4CECD; Wed, 6 Nov 2024 11:50:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730893806; bh=5m1d0+DTyGkZRlNmd/gGqpR64QjDJCq1VneMI9ozY3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mO7dSWXmiZ99GIsBdYxSEYRTk6D2Az3TJpZ0KsmSOB4tmmwbxMg0TuU5NUH60rPgc rmRE+kBOQkA+TdqWXv1r4StfEMAdyXwbqW76fWYN34OG+ycmpT8BvlMf4ZK5ZOD3LF tFbZG96PCgnv34FQz8tVb8FVVuy26K6OftRiwa/2QnGbndnwXrnMMuUSdRTBQ24z8q RAHa6UcB+8/texMoVAt0OVOGPpGIiyNwTdw6cTdFE+hpvO18mP2SgH9GILBPneNH3W Zrx56malyUyHJjvSULFuL2u6Nl+4+123CrLeAgrLBgDWOkuFYs+FHrC+vIepTGOrrN oSHeaIKFsgQhg== 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 v2 04/17] dma-mapping: Add check if IOVA can be used Date: Wed, 6 Nov 2024 15:49:32 +0200 Message-ID: <9515f330b9615de92a1864ab46acbd95e32634b6.1730892663.git.leon@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 54D852001E X-Rspamd-Server: rspam11 X-Stat-Signature: rp1nui94w9twbpz7h7u5s9yi9ho3emfh X-HE-Tag: 1730893791-540939 X-HE-Meta: U2FsdGVkX1+TA6Z5+j6DZkNE+I3aEpYplonIXzhWwOGXOY2jN68do1/cp3qprXu42kn1VEUo0Hz6ke97HgNtm2CgRF3qc/9/7wbFOYWwO1dw+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lFawgajpcla0clWAjyONUKsbHyTtAqLm1QPs6VgIkmheN0DPGJELwV2nIw+DvCUUPJqNuH804tEGkPk/m1pBDYW0n2SGK+IMkqaRSKEdZ9m6vPE2zkW3tnph7SQXJuiKNevQuvLPisuu 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);