From nobody Tue Sep 16 14:33:02 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21469C3DA7D for ; Tue, 3 Jan 2023 19:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238889AbjACTTu (ORCPT ); Tue, 3 Jan 2023 14:19:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233958AbjACTTA (ORCPT ); Tue, 3 Jan 2023 14:19:00 -0500 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 435E115FCC for ; Tue, 3 Jan 2023 11:16:23 -0800 (PST) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 303IGIJn001055 for ; Tue, 3 Jan 2023 11:16:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=QzKwUsIi8fNNyxqU4gSlX689JPGZXFMKHp3FG8bPQk0=; b=YM/iCJ3o6HKArA7nL6LTrutZomDvnOw56HpdIUvyLO75ES706rfmrHO5dPYgK/RpfbGy IXnxxlaF8vptl6L8lc22Dc3vB1V0sTBxBlSuT4wWW4fyolpy5uKkojKMovhOlNIWhNTv hlyGuTioplr/tQW1QCKa4uR7ElS2v/d8bXVq2sOL1qaFXNB+qDLBuw2YcH3FQDeLVAiz +l3L2m0K0GOhGz4TeNuAUN1B6mKZHIZqQxxydgCnKzKqT8i09IXqvlutA1BIkAdC8F9l T3y3ch390raZME2aKn2oWOz+0fvZlW/koEJkguWmD6kv5LjW5i7sZ2J94daLuJKLpvTT ww== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3mtkt0sxf9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 03 Jan 2023 11:16:22 -0800 Received: from twshared8047.05.ash9.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 3 Jan 2023 11:16:20 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id 4EC4BE1F5E1A; Tue, 3 Jan 2023 11:15:55 -0800 (PST) From: Keith Busch To: , , Matthew Wilcox , Christoph Hellwig CC: Tony Battersby , Kernel Team , Keith Busch Subject: [PATCHv3 09/12] dmapool: simplify freeing Date: Tue, 3 Jan 2023 11:15:48 -0800 Message-ID: <20230103191551.3254778-10-kbusch@meta.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230103191551.3254778-1-kbusch@meta.com> References: <20230103191551.3254778-1-kbusch@meta.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: 6n8oV55mLMnsH-Si-F2SnqpIsQW4iP4j X-Proofpoint-GUID: 6n8oV55mLMnsH-Si-F2SnqpIsQW4iP4j X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-03_07,2023-01-03_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Keith Busch The actions for busy and not busy are mostly the same, so combine these and remove the unnecessary function. Also, the pool is about to be freed so there's no need to poison the page data since we only check for poison on alloc, which can't be done on a freed pool. Signed-off-by: Keith Busch Reviewed-by: Christoph Hellwig --- mm/dmapool.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/mm/dmapool.c b/mm/dmapool.c index 6862b4e763891..4dab48e7e0d75 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * DMA Pool allocator +* DMA Pool allocator * * Copyright 2001 David Brownell * Copyright 2007 Intel Corporation @@ -241,18 +241,6 @@ static inline bool is_page_busy(struct dma_page *page) return page->in_use !=3D 0; } =20 -static void pool_free_page(struct dma_pool *pool, struct dma_page *page) -{ - dma_addr_t dma =3D page->dma; - -#ifdef DMAPOOL_DEBUG - memset(page->vaddr, POOL_POISON_FREED, pool->allocation); -#endif - dma_free_coherent(pool->dev, pool->allocation, page->vaddr, dma); - list_del(&page->page_list); - kfree(page); -} - /** * dma_pool_destroy - destroys a pool of dma memory blocks. * @pool: dma pool that will be destroyed @@ -280,14 +268,14 @@ void dma_pool_destroy(struct dma_pool *pool) mutex_unlock(&pools_reg_lock); =20 list_for_each_entry_safe(page, tmp, &pool->page_list, page_list) { - if (is_page_busy(page)) { + if (!is_page_busy(page)) + dma_free_coherent(pool->dev, pool->allocation, + page->vaddr, page->dma); + else dev_err(pool->dev, "%s %s, %p busy\n", __func__, pool->name, page->vaddr); - /* leak the still-in-use consistent memory */ - list_del(&page->page_list); - kfree(page); - } else - pool_free_page(pool, page); + list_del(&page->page_list); + kfree(page); } =20 kfree(pool); --=20 2.30.2