From patchwork Wed Oct 30 15:12:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13856677 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 AA275D5CCB9 for ; Wed, 30 Oct 2024 15:13:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 418F98D000B; Wed, 30 Oct 2024 11:13:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C6238D0001; Wed, 30 Oct 2024 11:13:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23FC88D000B; Wed, 30 Oct 2024 11:13:36 -0400 (EDT) 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 0293C8D0001 for ; Wed, 30 Oct 2024 11:13:35 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B8FAF120DC8 for ; Wed, 30 Oct 2024 15:13:35 +0000 (UTC) X-FDA: 82730611404.09.223AAC6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 6249220009 for ; Wed, 30 Oct 2024 15:13:07 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OvNAG5mt; spf=pass (imf13.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 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=1730301053; 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=3MQIVTpPUFkgHQ2kL+3oRPWGhhug+8ZedKPylFoOF7U=; b=KOf2kYIiC2bS/Mq1n2LYJKCDuFBskgtCDSGzyYw2+nsl3LHySbQCVmgz4u/NcVE02WLHBh 74OPecvT64xkV6GutOVPlKpNsSkV+NCgmJj9DpRWOEc1ByRH7SCKutHAGwEk3YXE0Nv/nw Djur2L7dFvg2a00NgpKZlN4lpB6kb7o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730301053; a=rsa-sha256; cv=none; b=QrLneA6Lff1/FbL9Kf7+uMF2P+ctt/psnrJk63SwT2FOUgyN+FGFzs3+iZSHwkX2/hlK/f yGvQPY8sCXDM1cZEPQHZGq1hTXbWEf2//bctdn2GWcjclHCnw8zJbR/C1Jr9h6B6vj13e2 QyEZ2C5hvPVbXs684/ARqeAwWWSEfeY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OvNAG5mt; spf=pass (imf13.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 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 dfw.source.kernel.org (Postfix) with ESMTP id 3B60F5C5EFD; Wed, 30 Oct 2024 15:12:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14BBEC4CECE; Wed, 30 Oct 2024 15:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730301212; bh=Lk+QUmdhMcbaHNbOGFaFlupW/NnaXwQbfPX5iL2RGqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OvNAG5mtLwTxS6yIXlexDZ921FgcNRyBgt2vMt4axYlqHFpW8SmDoqG5XbqxbzCM8 L7YW2Ct+xt9DP7bWW4sEvI5Wk9Wp/VMbr4ZP6P2mhmfX2LN/xOGuLsqWCbQA/Y4XCM ke1UZ9s0S7fVl2ZM1mE1d3tLVQ3/k+XbRZtRTXEq0Rn0ieVLumeCOVrHFxa/qmcS/D g36jMcwkC2j0oYQVEtJ2jNNs911O3lVzzsZ2W0PtVH26+srz/cOSgTXvIBCehUYB2y T3ONlc1oOu+WKGhena4V70d3gbHxgyVwE0sdFDVFAQhJXi8on9dtDc9xba76vFc57v v/H2iFVgh9BjQ== 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 Subject: [PATCH v1 04/17] dma-mapping: Add check if IOVA can be used Date: Wed, 30 Oct 2024 17:12:50 +0200 Message-ID: <9515f330b9615de92a1864ab46acbd95e32634b6.1730298502.git.leon@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: wgxctu31pf8jyg35eq3sawhsp43zhhhk X-Rspamd-Queue-Id: 6249220009 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1730301187-706574 X-HE-Meta: U2FsdGVkX18DQur+CpDdDaMomIobiXQQKP47zTRPWMEhBHPEv9B6UWkNzL3qmdms8e6LwSlflu3J5l8UjtZWMs7F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QwjXmABkJIV3I7xoEeJyebHKduS6wpCW8TgsjgJnUy1wIZHVLossyoM1D/l0t1VidNgc8HpFFujdI= 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);