From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91A97D13562 for ; Sun, 27 Oct 2024 14:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SqsRPvKex7cm/CMiQHjz3yXGqiB/OJXlfjJSO7FlhgI=; b=xYF6TDpPUX4ImsuGxYqrUdInIm 6E0NYgTIa0AKtRLCTObDcBeEyi6pNW0HLEpURLHp+poBjZIYmrXHUkdp5kJgO8rlY/cA9zbAD3QbB sgtyywVe2RJ7VC0T3aIdIqrj1uTLHsDe9zVTy+J25toDZxdIuN67ylgP4uhTs6n3uI5zwl3VDnFhR 3+O2/pu9+F6XitoAImMPHn0wVhemx/tc+k0DDAe/mUff1NBNZpY6PZ/IjjozbD6QcLjHCoLwRbgap IgfQ9oD0kiyZ6Q4ppCQiPEaWpLL0BigUwse0dY6OCBSniLoGu1S7sK/2FLXwhbaMNrTeYOEv96I0S zw0swulQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t549m-00000008KKL-1FXU; Sun, 27 Oct 2024 14:22:14 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t549Z-00000008K7b-3Ofp for linux-nvme@lists.infradead.org; Sun, 27 Oct 2024 14:22:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C108EA40F9B; Sun, 27 Oct 2024 14:20:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C823CC4CEE5; Sun, 27 Oct 2024 14:21:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730038920; bh=E0mwC287J+JVGCuete1tXAWszQr+5mVGJICiBM6Bbwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u7uZy6FQUuTRVdjyJS+f2O25SgyVfds4jIYtDwXnwnzdXm9qmTDAfM6108w0SJp6V RYLV7aB8mTg8rA55P2vaJ2mFfY1BZwXsgHv/WQ5eFvQMp1tETi/S9i+QD13XvbxLsj t181rumEA9YbHlPzju+nJ0FGojfmArJCFHNulyXqDm0O4ZxDw88kj5m+88WBcYwsKG N/DOT+4wqMVPIS6QfwV81ed6vXVNuYzGgT4saY2ELt6BQE8HRM0aCzYwA/+s90liba i1nLhVEcObKHs8fsKZEzNlA+wu2nIwnS3S90n9FpHsXaNuZWdGwSFCKe9BeMzIPKgs Lm0Z5R7DWaYyg== 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?q?J=C3=A9r=C3=B4me=20Glisse?= , 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 08/18] dma-mapping: add a dma_need_unmap helper Date: Sun, 27 Oct 2024 16:21:08 +0200 Message-ID: <2916b8526078cadd5107588610aed1c2db6d4d70.1730037276.git.leon@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241027_072202_172431_FE6771FB X-CRM114-Status: GOOD ( 14.72 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org 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 | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 50f0edfe7350..c3edd6c3e1ab 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -409,6 +409,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) { @@ -434,6 +435,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 864a1121bf08..daa97a650778 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -442,6 +442,26 @@ 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; +#ifdef CONFIG_DMA_NEED_SYNC + if (!dev->dma_skip_sync) + return true; +#endif + 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); -- 2.46.2