From nobody Tue Jun 30 05:22:32 2026 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 623C3C433EF for ; Mon, 24 Jan 2022 16:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243806AbiAXQkl (ORCPT ); Mon, 24 Jan 2022 11:40:41 -0500 Received: from foss.arm.com ([217.140.110.172]:40058 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243793AbiAXQkY (ORCPT ); Mon, 24 Jan 2022 11:40:24 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4E2C5101E; Mon, 24 Jan 2022 08:40:24 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6981B3F793; Mon, 24 Jan 2022 08:40:23 -0800 (PST) From: Robin Murphy To: hch@lst.de, konrad@kernel.org Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, tientzu@chromium.org, guozhengkui@vivo.com Subject: [PATCH 1/3] swiotlb: Simplify debugfs setup Date: Mon, 24 Jan 2022 16:40:17 +0000 Message-Id: <278f7915ed3ad8768c6cad671ce8f1a3d4ec085c.1643028164.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.28.0.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Debugfs functions are already stubbed out for !CONFIG_DEBUG_FS, so we can remove most of the #ifdefs, just keeping one to manually optimise away the initcall when it would do nothing. We can also simplify the code itself by factoring out the directory creation and realising that the global io_tlb_default_mem now makes debugfs_dir redundant. Signed-off-by: Robin Murphy --- kernel/dma/swiotlb.c | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index f1e7ea160b43..bdce89e053bd 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -36,9 +36,7 @@ #include #include #include -#ifdef CONFIG_DEBUG_FS #include -#endif #ifdef CONFIG_DMA_RESTRICTED_POOL #include #include @@ -758,47 +756,29 @@ bool is_swiotlb_active(struct device *dev) } EXPORT_SYMBOL_GPL(is_swiotlb_active); =20 -#ifdef CONFIG_DEBUG_FS -static struct dentry *debugfs_dir; - -static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem) +static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem, + const char *dirname) { + mem->debugfs =3D debugfs_create_dir(dirname, io_tlb_default_mem.debugfs); + if (!mem->nslabs) + return; + debugfs_create_ulong("io_tlb_nslabs", 0400, mem->debugfs, &mem->nslabs); debugfs_create_ulong("io_tlb_used", 0400, mem->debugfs, &mem->used); } =20 -static int __init swiotlb_create_default_debugfs(void) +static int __init __maybe_unused swiotlb_create_default_debugfs(void) { - struct io_tlb_mem *mem =3D &io_tlb_default_mem; - - debugfs_dir =3D debugfs_create_dir("swiotlb", NULL); - if (mem->nslabs) { - mem->debugfs =3D debugfs_dir; - swiotlb_create_debugfs_files(mem); - } + swiotlb_create_debugfs_files(&io_tlb_default_mem, "swiotlb"); return 0; } =20 +#ifdef CONFIG_DEBUG_FS late_initcall(swiotlb_create_default_debugfs); - #endif =20 #ifdef CONFIG_DMA_RESTRICTED_POOL =20 -#ifdef CONFIG_DEBUG_FS -static void rmem_swiotlb_debugfs_init(struct reserved_mem *rmem) -{ - struct io_tlb_mem *mem =3D rmem->priv; - - mem->debugfs =3D debugfs_create_dir(rmem->name, debugfs_dir); - swiotlb_create_debugfs_files(mem); -} -#else -static void rmem_swiotlb_debugfs_init(struct reserved_mem *rmem) -{ -} -#endif - struct page *swiotlb_alloc(struct device *dev, size_t size) { struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; @@ -860,7 +840,7 @@ static int rmem_swiotlb_device_init(struct reserved_mem= *rmem, =20 rmem->priv =3D mem; =20 - rmem_swiotlb_debugfs_init(rmem); + swiotlb_create_debugfs_files(mem, rmem->name); } =20 dev->dma_io_tlb_mem =3D mem; --=20 2.28.0.dirty From nobody Tue Jun 30 05:22:32 2026 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 98CA1C433EF for ; Mon, 24 Jan 2022 16:40:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243815AbiAXQku (ORCPT ); Mon, 24 Jan 2022 11:40:50 -0500 Received: from foss.arm.com ([217.140.110.172]:40074 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243800AbiAXQkZ (ORCPT ); Mon, 24 Jan 2022 11:40:25 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 65E95113E; Mon, 24 Jan 2022 08:40:25 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 80B043F793; Mon, 24 Jan 2022 08:40:24 -0800 (PST) From: Robin Murphy To: hch@lst.de, konrad@kernel.org Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, tientzu@chromium.org, guozhengkui@vivo.com Subject: [PATCH 2/3] swiotlb: Tidy up includes Date: Mon, 24 Jan 2022 16:40:18 +0000 Message-Id: <57acdf35aa8a66e40ba99d97713ed97b2e40a1f6.1643028164.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.28.0.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" SWIOTLB's includes have become a great big mess. Restore some order by consolidating the random different blocks, sorting alphabetically, and purging some clearly unnecessary entries - linux/io.h is now included unconditionally, so need not be duplicated in the restricted DMA pool case; similarly, linux/io.h subsumes asm/io.h; and by now it's a mystery why asm/dma.h was ever here at all. Signed-off-by: Robin Murphy --- kernel/dma/swiotlb.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index bdce89e053bd..f56d6504903c 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -21,38 +21,33 @@ #define pr_fmt(fmt) "software IO TLB: " fmt =20 #include +#include +#include +#include #include #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #ifdef CONFIG_DMA_RESTRICTED_POOL -#include #include #include #include #include #endif =20 -#include -#include - -#include -#include -#include -#include - #define CREATE_TRACE_POINTS #include =20 --=20 2.28.0.dirty From nobody Tue Jun 30 05:22:32 2026 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 5CE90C433F5 for ; Mon, 24 Jan 2022 16:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243796AbiAXQkt (ORCPT ); Mon, 24 Jan 2022 11:40:49 -0500 Received: from foss.arm.com ([217.140.110.172]:40084 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243804AbiAXQk0 (ORCPT ); Mon, 24 Jan 2022 11:40:26 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 864DAD6E; Mon, 24 Jan 2022 08:40:26 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 984B63F793; Mon, 24 Jan 2022 08:40:25 -0800 (PST) From: Robin Murphy To: hch@lst.de, konrad@kernel.org Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, tientzu@chromium.org, guozhengkui@vivo.com Subject: [PATCH 3/3] swiotlb: Simplify array allocation Date: Mon, 24 Jan 2022 16:40:19 +0000 Message-Id: <432f572de793ec5085a048a51fdd977cba6a5f51.1643028164.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.28.0.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Prefer kcalloc() to kzalloc(array_size()) for allocating an array. Signed-off-by: Robin Murphy --- kernel/dma/swiotlb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index f56d6504903c..44c49c3616fe 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -820,8 +820,7 @@ static int rmem_swiotlb_device_init(struct reserved_mem= *rmem, if (!mem) return -ENOMEM; =20 - mem->slots =3D kzalloc(array_size(sizeof(*mem->slots), nslabs), - GFP_KERNEL); + mem->slots =3D kcalloc(nslabs, sizeof(*mem->slots), GFP_KERNEL); if (!mem->slots) { kfree(mem); return -ENOMEM; --=20 2.28.0.dirty