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: 13895318 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F198C225781; Thu, 5 Dec 2024 13:22:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733404936; cv=none; b=C/OJEwU8lveGGMIb1F7gUdVwTPxi3FCqfauzidLoyjwXWzplmhojQTLGxTuKAaqlMklLU2rUnCZ+XBHsCr1rsD1nPSFe0SBAmdPIxgqQTFGyDVxFzHdb7F+A5zo0MvSEbsPyGgOJD06hHRv6vu1Or+Y6lrdqs/JHRBrq/+s1kVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733404936; c=relaxed/simple; bh=D18vqz7ozylSYyTDiUizIC6+IP11dnR8Bul5eGSUEKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DJSBXAjtBgnzkHsMUxWXTropoXKffpyOfIeCYgiO9DI8V5Kv0oZ3O+LPssKZ+a6sT8si3s/gkQGsie6Qxg0oedaMFIZkOPvcJF0LW1rYkNSCIRV1tk45+JHogQF4Y+eFQm1Gm2Bzbt4q5W7g7iNU/xkhgLYUNzZmAqFpLH60Dcw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bm19PU8a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bm19PU8a" 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: Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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);