From patchwork Wed Nov 6 13:49:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13864483 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 69AECD44D55 for ; Wed, 6 Nov 2024 11:50:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF0F48D0002; Wed, 6 Nov 2024 06:50:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE1DC8D0001; Wed, 6 Nov 2024 06:50:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5D9D8D0002; Wed, 6 Nov 2024 06:50:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A0C108D0001 for ; Wed, 6 Nov 2024 06:50:46 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 498E1121BC0 for ; Wed, 6 Nov 2024 11:50:46 +0000 (UTC) X-FDA: 82755502452.15.78163F3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id 336BF40023 for ; Wed, 6 Nov 2024 11:50:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DTnn4MzH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=leon@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730893785; a=rsa-sha256; cv=none; b=Mhw6rdlv/4QFMGPYGFvpZDbC1o81k88beiY0gGxI7RWTMY1OHGXiULIjZhKOWfhIEQLM/h HzUQ0zKn1kvUZFzD3KppAjBA8LldYgj5Ng6Grt5Qdzo2s/d963v/JE2XZzSmEttvFL6lBE tdXJhdjP09j9X2Me6wVMjuKRiP+K+N0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DTnn4MzH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=leon@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730893785; 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=Z3pBKzGf+Mt7Ymd8XSOAKoUlqDkaXqPwcs+QH+eUxMI=; b=7iuO6hEwvSd41bMLfX+nwicWLlH2r0FsZ3shCL23UDEFV5ovG9+mLtJ56jLUgwZHyP1Q0e dCDQiG/98g/y0wcFF1t4eaDWEB+V5oTC9wgVhisqZnva5opJnlyDXePtqkmz7tBS9Wo937 jxr5VWMBolj7eG2cJxcIyclmtz1f3ko= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 04BF45C0352; Wed, 6 Nov 2024 11:49:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EF33C4CECD; Wed, 6 Nov 2024 11:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730893843; bh=LHJNxaQG7ChuUixJnwwD1gA8ae7lNW9rHKLNGhRoomU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DTnn4MzH+oAPg7W92s2F2YgvnMYo/zEaX/iZq5VFwiEnkddFR41aanJcX78jDpULb L1L4UzLDppcWda0UpAebDB4f/BCMiJBspLY5x5bdsXxx0P2I0oBe6/Z9V9BTOgMuWz rQorpNRGdvWDJ5LtVIB7NP4CFp482nT3+E1YxaSJrMu1ndvm84UtuCjmYBlErzkOhk apHm42FJGn1WxkU4irqD5ZBXclq4KmRZLHcxiG7BijI6tvo6xfROXF9XhoRgfjp2hX gBpT2XPe9ACdpoBxQaT9M4hJrF2YwYQ0Ahn8t0ygOvEtQZro1bTC8ZDDh3DrlCQ2/s ph87PvkEyJAjQ== 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 v2 08/17] dma-mapping: add a dma_need_unmap helper Date: Wed, 6 Nov 2024 15:49:36 +0200 Message-ID: <00385b3557fa074865d37b0ac613d2cb28bcb741.1730892663.git.leon@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 336BF40023 X-Rspamd-Server: rspam01 X-Stat-Signature: mdardiebhmxfcipkdxnaxn4e61zbyr5p X-HE-Tag: 1730893817-855262 X-HE-Meta: U2FsdGVkX1/tUN0T3xYtV+q2RWrcrHkn07MPnW/D0UzsqRnKT2rAXPHef+wbnUNT9ORvrZ7HH+ypnmS23Co9/Cwn8vULHg2vDAMN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ob6POKGFG/LN8YXsiZpRZBqphksDHMs8/AM6EPKPfcUEfvEaGnPYrql5Q1ILW4j9EvP+57MQ2g7cmI7K5unf5ed8iqKd0NzSN/Q2sdy6OxHcP1BlQ6a7q0bKYyZFQVg3e+85HaS3Sbnsg64IcfpjqaUqZOyX32Uaumwqt6uiF1Wuw= 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);