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: 13856699 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 4004C216A1C; Wed, 30 Oct 2024 15:13:46 +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=1730301227; cv=none; b=uLTp8Rml2hsjO8PrIIuqXhxnstlYCryoBQ25qBby+MVdlrc1KXoxvt0uoCdLsboivaFJyzSNaD6j4kXevgOmpTColIAXKy4nx5pYRmSthn57SULdov6oIRI21vopcO9syFhXEkRaetFu3UrrhVihW5mC0J3s38Dd6aThpcTZOFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730301227; c=relaxed/simple; bh=QGhPEI3S06TBMrjanRSWwBEaYlCHA0taHYk6+dEHPl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R+JdYhWdCwfIMcocQCZyDlsE8wQiivDB3MQM+Bu+XHtP3L3l/Rwv7jr/YqKUugFq0+PUB2R4yCydGXnqea5sRL4sVkO6n1oKPj+MPlH+JZfaH2Xit+5Bgd0POTWi/5XLymVzN4p0S8gwiCk/83QQoLQRLDEBLgJQu3wTaETD7JU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=psdZpNNG; 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="psdZpNNG" 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: 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 | 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);