From patchwork Wed Oct 30 15:12:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13856681 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 66EE6D5CCB3 for ; Wed, 30 Oct 2024 15:13:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E51938E0005; Wed, 30 Oct 2024 11:13:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E00F48E0001; Wed, 30 Oct 2024 11:13:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C548F8E0005; Wed, 30 Oct 2024 11:13:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A03F78E0001 for ; Wed, 30 Oct 2024 11:13:49 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6192080C8F for ; Wed, 30 Oct 2024 15:13:49 +0000 (UTC) X-FDA: 82730612286.27.2BD64C9 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf02.hostedemail.com (Postfix) with ESMTP id A95428001E for ; Wed, 30 Oct 2024 15:12:58 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=psdZpNNG; spf=pass (imf02.hostedemail.com: domain of leon@kernel.org designates 147.75.193.91 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=1730301066; 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=18NPGuceQo1bRh7brK8gmz6Fjwz/7GYqhz5ykldBY5M=; b=3fh7ubnZ7ddemhbAEfY2a9oLc1UakY3N2jbhy+t3/bs+Z8WX234ZWvnCXlGho8/4MTfAOI LnkFFbX99bZhoaFq+aPX8hHOAwkksBZXoOe9IxC5LVUKXpWhq8h9cgln/LssJtUQW9CmGe ZF3BbAyw+NrLbqmoSbUsy5qYGEzoduA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730301066; a=rsa-sha256; cv=none; b=gC8/k9wxiyil4qd8ZgGb3xn15WG+6MaIofz4QH1cOkSc5Yd24Jiuce6mRv3Dmb8m9rnDqg 8Q0k3EyI4KFoaiNOUM0+VwmvRE3IuYOaWhnFFZxzT634eKyXsAsISRn8z6glt6Ao51DfHt NgXVA2ca4ARYF+8FystycjGJvnpfzkU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=psdZpNNG; spf=pass (imf02.hostedemail.com: domain of leon@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=leon@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 66212A418C0; Wed, 30 Oct 2024 15:11:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3607CC4CECE; Wed, 30 Oct 2024 15:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730301226; bh=QGhPEI3S06TBMrjanRSWwBEaYlCHA0taHYk6+dEHPl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=psdZpNNGJcibprE+79HbooZm4yrYRQ0Yu1vOnpFXCYC6sQg7aj8A9kDoxv4O9iKda vpq6+UnL42B2GDmqpeaSgxnZCKXUatA37GWb2vauJWt+5W1nRqHtmPp04iI93g57tu KT11sUZqFdMvorZZWFhUeI1GodNfUEPOp44eQcLTwPEUO4I48Oa3RCy8kMqfiQy3y+ RLbv/eCj019iM7aJEV8UauLvHM/qFQekp0H0w4ukWgIMTJw+cem8+gNMj9xEujliUm wkqpnJG2GZLxNNnsYjzykT+M6nMB7eALtxtpI40Fb1ze4vYyPccY02MSuZC0u2g5z0 R8WSAEimTxIEA== 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 Subject: [PATCH v1 08/17] dma-mapping: add a dma_need_unmap helper Date: Wed, 30 Oct 2024 17:12:54 +0200 Message-ID: <00385b3557fa074865d37b0ac613d2cb28bcb741.1730298502.git.leon@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 8d8wfdhbte8z6mg7hu9gagccydpn9he8 X-Rspamd-Queue-Id: A95428001E X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1730301178-401748 X-HE-Meta: U2FsdGVkX1/NjImkcPw1c0myJzplgEUBJY2970GHKavTXSrbwg/qPZPAFKEwV+h869fWe4q43rCf1eYA72J2kGeGc1f7yvgFi4kpoEX7XrR0VqDGupD6ME4fqCbBbb0xEFehZtQr9F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HRSTTkcjurrId7rQ818DZGHK32qNN7o4gJBg+FyvkSc6LGHWqRT5SLMLWx+FwFBRGK2IP 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 | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 8074a3b5c807..6906edde505d 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -410,6 +410,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) { @@ -435,6 +436,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);