From patchwork Fri Jan 17 10:03:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13943144 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 C5B86202C50; Fri, 17 Jan 2025 10:04:39 +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=1737108279; cv=none; b=BPDxT55QUZ13Q1sKMkc/gl76spXeK90jXENmBdYUh9mGqnOo67aVyt+ujrxoB7X94pVyYIHyPn1yUgP5VdsOg2/cBW8Qcuuwi4yaS7GXy780qfBMcjleFWa3r1aCGA/Hdy/BHTnQOf6Phc/MrXJeBBCvlcqWqfYCm1WF8/JI66s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737108279; c=relaxed/simple; bh=FJYQ7qR9hcBLpRhiPHcPvV9HvqBheLEfsFGqvBAMLaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tYg8hfzhnjSO+hzNEeqMU4jG92iPHoTt1NirRt/tYb1Bw4AnTY25casY/DqGiLVdYpy4LaAbfgcUaLla881egN+vcZ2PvWM7eQixrFcGdMWYPwzatzRiz/Yf3/FhK6Ls1RLxCdoQmeffc2+ZlVxfytDDUHs0C/qFcWOS0KGxnqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vExohzXD; 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="vExohzXD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8323C4CEDD; Fri, 17 Jan 2025 10:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737108279; bh=FJYQ7qR9hcBLpRhiPHcPvV9HvqBheLEfsFGqvBAMLaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vExohzXD6Ujd7i5ylWAXIQ8r+KiHahR4ugS8NzRN12jXXWg6XpFDS0Az2kDJdGS3b r2P83zACaoMN4Wm74N2ASzU3RY5SHuQvegOGleRrgJR0ewKZNF1R7rYaprTdiqfZta qHAONZp/pjWD0Exsf2wMAG5W74kZ9llv+fixzaMpWuVhexQbaRl57Q96SppjOh8KaZ UB7ck8uR8pWleUg587r5ORtXxR7k4/8yK6Oa7z3askZexI38iaJksqiskbye1+z2jM yfRbYsVQg1Ux+DbZ9S99dgY9nJvxXEfXBrI8xyOVSpm8JiF79noUc1A75KueNPzS9U QWTZ4Ku7NpBiA== From: Leon Romanovsky To: Christoph Hellwig , Jason Gunthorpe , Robin Murphy Cc: Jens Axboe , Joerg Roedel , Will Deacon , Sagi Grimberg , "Keith Busch" , "Bjorn Helgaas" , "Logan Gunthorpe" , "Yishai Hadas" , "Shameer Kolothum" , "Kevin Tian" , "Alex Williamson" , "Marek Szyprowski" , =?utf-8?b?SsOpcsO0bWUgR2xp?= =?utf-8?b?c3Nl?= , "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 v6 08/17] dma-mapping: add a dma_need_unmap helper Date: Fri, 17 Jan 2025 12:03:39 +0200 Message-ID: <9458f681274f4f0e5dd3bf3959e0b8a1ac9a4e7b.1737106761.git.leon@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-block@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 a71e110f1e9d..d2f358c5a25d 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -406,6 +406,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) { @@ -431,6 +432,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);