From patchwork Tue Dec 17 13:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13911736 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 A211DE77187 for ; Tue, 17 Dec 2024 13:01:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E75E6B00C8; Tue, 17 Dec 2024 08:01:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 272E76B00C9; Tue, 17 Dec 2024 08:01:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C7046B00CA; Tue, 17 Dec 2024 08:01:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D78876B00C8 for ; Tue, 17 Dec 2024 08:01:32 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 91E4DA0734 for ; Tue, 17 Dec 2024 13:01:32 +0000 (UTC) X-FDA: 82904461836.04.5261EB6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 6A0FF1A002A for ; Tue, 17 Dec 2024 13:00:58 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="HEKE/+zX"; spf=pass (imf19.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 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=1734440476; 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=I8zeuz1LusMcrZY1ZH3SbXwbZVAiaCQQJNl/hX6DDvQ=; b=R4rQ7omy0uB+WHkgj6yOzXSM8d0qIAYyx/QtheSZC6dwLCCXq2Y98D2eehDANHJtS/+5bx qcWSmeqdoNMgJ/Igh3nBPU7p6A4o6V+TU0MJTcL6uY7R0WkkWVE0sBhBq8zgf3DS++ZRfW PdY2b3GsGr4RP2FHSq5m0KTe99z5wzU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734440476; a=rsa-sha256; cv=none; b=d+bmid7mch9E5PrSNzvat1sWPB3b9ffJB3bZ5gaJ0/Iki3K5e29ES39QwoemsNXoZ/pWmx uUjs/8BLAKUg/x802ilXj633GZrsEPKNbWCbkvv4Yi1f7RjLErJ8+XB5+aQWuuO1naQGuI JoXy4Zi0F0UggwdvgClh4yXZPwu/lXA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="HEKE/+zX"; spf=pass (imf19.hostedemail.com: domain of leon@kernel.org designates 139.178.84.217 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 dfw.source.kernel.org (Postfix) with ESMTP id 6F5845C62C4; Tue, 17 Dec 2024 13:00:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E3CFC4CED4; Tue, 17 Dec 2024 13:01:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734440489; bh=iIU3nAodcPqgXhM415qJ6UO7wN8Xjlyg5zHcBf3DQZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEKE/+zX+ZdFZ/bWCF8cQSMXArY/rreeS3qzRw8Eeu6EzOGw/Z1JrKiOfPOyVSkFH kHZlx+qqB7dSpSCgCpOCMOtZc+Fo8v+6UYjKoFb2Xd9zDNsuFoI0OOuBsJxZPl7pJh dNSTnpKCfVe82F/lCx8zqFy3TaxV2gFUGzc7/qFSsbzSmOi5OQoKMuHthehZMzeMam eLzSmHxPiLYfsTmC8Jw/a52JDN/ZH/+lyrzoi8FkhpRTZjxnQa6rv9eItSzpWooiYV CxiBLRT9PR8d8JkpFs8QBkshTvp9Yc+wF1IOA4vnuA3uNmm5kbPutlclWHDhQx3klo D9T+xxGicipwg== 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 v5 08/17] dma-mapping: add a dma_need_unmap helper Date: Tue, 17 Dec 2024 15:00:26 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6A0FF1A002A X-Stat-Signature: ttg7eqkq7d8tsyi86cbzfkwb1ys8ju3q X-Rspam-User: X-HE-Tag: 1734440458-159654 X-HE-Meta: U2FsdGVkX189YY9hEsSqgQl23TLG0kj5zbj6ByaLDjRwlpkfjnDHF3jyYu42suWC0q2D3D4B12oJDgxnhw0A083u5n5OG0Bel1BG6wVvxAb0+El3hFBtEG6XDMe+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PlM8aE1QDYfEoueC2+Nu7f/op3nh2xetjMF5hHHVC8vPQZn6vyTbPAivf/ 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 | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index f4d717e17bde..bda090beb9b1 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -407,6 +407,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) { @@ -432,6 +433,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);