From patchwork Thu Dec 5 13:21:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13895258 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 5CF58E7716D for ; Thu, 5 Dec 2024 13:22:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9C376B00A2; Thu, 5 Dec 2024 08:22:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4AE66B00A3; Thu, 5 Dec 2024 08:22:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEBAA6B00A4; Thu, 5 Dec 2024 08:22:18 -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 AD40B6B00A2 for ; Thu, 5 Dec 2024 08:22:18 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6909D121561 for ; Thu, 5 Dec 2024 13:22:18 +0000 (UTC) X-FDA: 82860968652.21.D0FAEE4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id D1DA24000E for ; Thu, 5 Dec 2024 13:22:09 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Bm19PU8a; spf=pass (imf12.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=1733404926; 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=mKKj2fxdlfVW5aD6CuypLf8UD3gAjKHN6VknXiRkV6g=; b=cDFmry34Yu8W10DWM/Ugnm3dlcOBOkelVUboS5VzZxpiBZXbymfKbQK9KyY1VO71+CQVU0 0EsxbzSLW5pgqlrhs5qg9njn0sf0EriaEb44OEqXStDBL2rAB/ublx2jsssO+d4Mbd+aqH LJQ2kz8k2W3zt1IyT0GOovqYWGH7/bc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Bm19PU8a; spf=pass (imf12.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733404926; a=rsa-sha256; cv=none; b=CwfqhsPIv9zW3aNEAjXL9Dtcobwnj4LDd+npnljkDQFTMbJCvg0O6je+W+8y4eP5jwiSG9 GCWX9Sz7FuwGo7+OlBNrcJ/OOzzzwavjNGBLsUj5YJzIBhiRmmCmr63ZW0Xb66GV3tx1/d YsiipoJLtpxaEqSFwWs8X2zaZ9o7pno= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0B0E85C6483; Thu, 5 Dec 2024 13:21:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1BFCC4CED1; Thu, 5 Dec 2024 13:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733404935; bh=D18vqz7ozylSYyTDiUizIC6+IP11dnR8Bul5eGSUEKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bm19PU8a+nItwL7s5OcINejqFYglblqmJlzdrbI5jAac+IoAXWIGi3TDk5Me1nbJX ehdIlS1u9UItY1EaONBD2NIwiqlEOa0s7pgkEyTp4NENwDZgHm9sEhmjhVaNv0qtph kCz+xw3PC94YX8OX5iQ7PUbTYjQzcmAPgCLadgd2OQ7mT0UMbBZUDrd18ojOj9ctk7 btygs26HiFfSEp/BBHpqoRtwnClx9LvnYJD74cmNdF28ixr1edqeIzjmiED5jomff1 WDZDVQ8ku2GZk9LTy3rc8piHNwJ9naJCp40wCws5ekHCmfTdIGdjVEmGV4kmINxvbK sSc6CAa188wtQ== From: Leon Romanovsky To: Jens Axboe , Jason Gunthorpe , Robin Murphy , Joerg Roedel , Will Deacon , Christoph Hellwig , Sagi Grimberg Cc: 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 09/18] dma-mapping: add a dma_need_unmap helper Date: Thu, 5 Dec 2024 15:21:08 +0200 Message-ID: <7f68ddea2a2070b639352d5f912968f1116fb8bc.1733398913.git.leon@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: 63gtg4mqdzkkxzyo4m9aq5ptssh1e3dp X-Rspamd-Queue-Id: D1DA24000E X-Rspam-User: X-HE-Tag: 1733404929-440094 X-HE-Meta: U2FsdGVkX1+p9ethoI0z405uB64+v6ZkwqAnEa1T4EEfPYS2DlLfgZoq7qJHBka55ruRDlYj7gwQTJgKPR+ZgOQnPG4gcTgYF8s3Lr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4HmsCAau2rqEQXxA4Q6736YyHC6igLyPzGaniBzX5fm5v47nVvDk1pICT1ltLTMFREiJMGkzN7+8cuF1XJX0m 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: Christoph Hellwig Add helper that allows a driver to skip calling dma_unmap_* if the DMA layer can guarantee that they are no-nops. Signed-off-by: Christoph Hellwig Signed-off-by: Leon Romanovsky --- include/linux/dma-mapping.h | 5 +++++ kernel/dma/mapping.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 28b271e8e9b9..78ca600f29d3 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -407,6 +407,7 @@ static inline bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) { return dma_dev_need_sync(dev) ? __dma_need_sync(dev, dma_addr) : false; } +bool dma_need_unmap(struct device *dev); #else /* !CONFIG_HAS_DMA || !CONFIG_DMA_NEED_SYNC */ static inline bool dma_dev_need_sync(const struct device *dev) { @@ -432,6 +433,10 @@ static inline bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) { return false; } +static inline bool dma_need_unmap(struct device *dev) +{ + return false; +} #endif /* !CONFIG_HAS_DMA || !CONFIG_DMA_NEED_SYNC */ struct page *dma_alloc_pages(struct device *dev, size_t size, diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index cda127027e48..3c3204ad2839 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -443,6 +443,24 @@ bool __dma_need_sync(struct device *dev, dma_addr_t dma_addr) } EXPORT_SYMBOL_GPL(__dma_need_sync); +/** + * dma_need_unmap - does this device need dma_unmap_* operations + * @dev: device to check + * + * If this function returns %false, drivers can skip calling dma_unmap_* after + * finishing an I/O. This function must be called after all mappings that might + * need to be unmapped have been performed. + */ +bool dma_need_unmap(struct device *dev) +{ + if (!dma_map_direct(dev, get_dma_ops(dev))) + return true; + if (!dev->dma_skip_sync) + return true; + return IS_ENABLED(CONFIG_DMA_API_DEBUG); +} +EXPORT_SYMBOL_GPL(dma_need_unmap); + static void dma_setup_need_sync(struct device *dev) { const struct dma_map_ops *ops = get_dma_ops(dev);