From patchwork Sun Oct 27 14: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: 13852555 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 9CF3AD13562 for ; Sun, 27 Oct 2024 14:21:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 882106B008A; Sun, 27 Oct 2024 10:21:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80D1B6B008C; Sun, 27 Oct 2024 10:21:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65D276B0092; Sun, 27 Oct 2024 10:21:46 -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 43D9B6B008A for ; Sun, 27 Oct 2024 10:21:46 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0FF22ABC6C for ; Sun, 27 Oct 2024 14:21:03 +0000 (UTC) X-FDA: 82719595392.11.434EE4F Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf23.hostedemail.com (Postfix) with ESMTP id 17CA0140018 for ; Sun, 27 Oct 2024 14:21:29 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZoVzrJRd; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.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=1730038731; 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=wibN4VAST41CcyfvIg2BKFVG+mY/YchxgBdatItCUFOJ3Y7xaqvf8W2AxycbOxpLSJDp5n 7U0fTGfikXIcUYTfwpdJkNHsP0PeSVFPaGAyecTwjLC+AFNRyXje/tfYIyhuCyXS1C7PoK W216+QnoXekpbjv8t1TlOEQvE3r3Lx4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730038731; a=rsa-sha256; cv=none; b=ImHBlafTP/gWUocvkPDs+oYN790h7ABPjNXtui8eU5p7P9AuvmT1w0QEYX3243iCM9KhDB AHrGKy8B7CCD+ptGNNAeBrHg5dEHj+F89lYy2C14vNBoV271rik6rP4Y3hNFdFngdxEZZu mjmMvAxkr3D6k14wzeKKOSP0rKdNpCM= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZoVzrJRd; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of leon@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=leon@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id ADE43A40F9C; Sun, 27 Oct 2024 14:19:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9AA2C4CEC3; Sun, 27 Oct 2024 14:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730038903; bh=Lk+QUmdhMcbaHNbOGFaFlupW/NnaXwQbfPX5iL2RGqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZoVzrJRdd8rbuT6L+Xi5EMaR91AubipgWfrJzgY4JanYIOix9GILLMyRG2Xftdq+D lvrjY2oCt9XfFuqUh3vIevkzrvt0atPYbUaWw6Pm4Ef6wiC0RsEWSs63z9vUuUJP2Z Exza5dLmVV1JWpGz7EmA7eXKpzaBn72zgcq/WewExhzpFWYJjBWcm6nQgFMuMchQbV bmSbUpVoeD9Br3okWLfdemzPmx6pAYzml6afn/7ySUeHq5DwWPvSPtv3xBRXzwj+Zo kAWWFq5krUcNCImhCceSB8D3j9OASgP8EKBeMBugYciQuO3BvEw7YndlF7mwhOLJTk 4S9LNT9t1ys+g== 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 04/18] dma-mapping: Add check if IOVA can be used Date: Sun, 27 Oct 2024 16:21:04 +0200 Message-ID: <6225a5bcc7fc584abfc6d0ed0473b7b2a24a2df2.1730037276.git.leon@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 17CA0140018 X-Stat-Signature: obnxdweudguz78esbrpa7dpfuebkr6x6 X-Rspam-User: X-HE-Tag: 1730038889-438092 X-HE-Meta: U2FsdGVkX19hF/VPFIGdhUW0NsL0GMSGLsgjDu7xSekF15UmtDSwnTFGgqArGgENjaNpZ7h2PK7GNfU8ydL+L+j8MnFyR3iiL3weyD1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La320Y6I96rJhHfzzVJQ8jkZsNIr2kjAmGsrwoUi0ZjaOnv48w= 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);