From nobody Sun May 24 18:42:58 2026 Received: from outbound.baidu.com (mx15.baidu.com [111.202.115.100]) by smtp.subspace.kernel.org (Postfix) with SMTP id 022491EEE6; Sun, 24 May 2026 03:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.115.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779594047; cv=none; b=r5LL6Imlm7XxHMbKC2/GMawOCcZHkBx14lIFi6V1d0KH19DTg2CV3wXqV7m242Rex3yRqDx/7AkMKaTIO+ZF9LA9lmlD/2yQy27jEdhBOGDLvtP+q5EPh5aU03GY0lfo7RKXnpnHCOz3jSbXUUltSgBXJrXKjlHXSN23N6Dow4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779594047; c=relaxed/simple; bh=TTMcFEgS05TesDbxW/WAMF5khbNWWESvl8qqMzSMtso=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=i6AYfaxh1gCdQC41lk0DWZ5cuGe8ev14U4ElR86HHC9o7THKQHEubAI0PdRJhAjDTwM8XKn1kwJn0kM39ds9MJKvXmhONMiYIOwTgIdSAlwOYVbHDcJjWJPlrt+Ev64SJ2yldM4dEMIg/9antJ0+pXF8WjYeNNY5Jx32eTWXP9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b=QE3QCUwG; arc=none smtp.client-ip=111.202.115.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b="QE3QCUwG" X-MD-Sfrom: lirongqing@baidu.com X-MD-SrcIP: 172.31.50.47 From: lirongqing To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , , , , , CC: Li RongQing Subject: [PATCH] mm/dmapool: use static key for boot-time debug enablement Date: Sat, 23 May 2026 23:40:15 -0400 Message-ID: <20260524034015.1830-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: bjkjy-exc5.internal.baidu.com (172.31.50.49) To bjkjy-exc3.internal.baidu.com (172.31.50.47) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baidu.com; s=selector1; t=1779594034; bh=auEp3spqgbRyV4sCde7hRJzHFuKPJdXALEUCtoAvLcE=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=QE3QCUwGI/DujzhE8vDKfe9pde7/bghEybQBvcw4mcs/xnn+LyfJaVL8SqWLL7iDA zg6Lzqxx3nCTOFbKqdhiwPmCKrcMQslcYUfFk/lpepWe0bhFwYGosIdqJ+tfdkiXf8 oDYvHCVLi3Ajb9g/tGke6RMoCeRowoucTLqYvkFF7zNqYiqoXY18VYPJbV5r7Wld9n oFgVoIKRczD6+Ix9M1w4Zq9W9LwNjaBqlopFnyIo+k9JvIh2RMkvs8l92lVz9a+Yhj ybEo0YAPGiVzhmmqk5Cxo7KevrvwvzwDtLI6wWl0AXV+1pDIRH5Z70YkxhglqiWdWX VzH248hBxeSDQ== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li RongQing Replace the #ifdef CONFIG_SLUB_DEBUG_ON conditional compilation with a static key (dmapool_debug_enabled). This allows enabling dmapool debugging at boot time via: dmapool_debug Instead of requiring CONFIG_SLUB_DEBUG_ON at compile time. Benefits: - Debugging can be enabled without rebuilding the kernel - Uses standard kernel static_key mechanism with minimal overhead Suggested-by: Vlastimil Babka (SUSE) Signed-off-by: Li RongQing Cc: Andrew Morton Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Michal Hocko --- Documentation/admin-guide/kernel-parameters.txt | 5 +++ mm/dmapool.c | 52 ++++++++++++++-------= ---- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 4d0f545..35ed9dc 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1333,6 +1333,11 @@ Kernel parameters =20 dis_ucode_ldr [X86] Disable the microcode loader. =20 + dmapool_debug [MM] + Enable DMA pool debugging. This enables memory + poisoning and validation for DMA pool allocations. + Useful for debugging DMA API misuse. + dma_debug=3Doff If the kernel is compiled with DMA_API_DEBUG support, this option disables the debugging code at boot. =20 diff --git a/mm/dmapool.c b/mm/dmapool.c index 5d8af6e..d26f19c 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c @@ -35,10 +35,23 @@ #include #include #include +#include +#include =20 -#ifdef CONFIG_SLUB_DEBUG_ON -#define DMAPOOL_DEBUG 1 -#endif +/* + * Debugging support for dmapool using static key. + * + * This allows enabling dmapool debug at boot time via: + * dmapool_debug + */ +static DEFINE_STATIC_KEY_FALSE(dmapool_debug_enabled); + +static int __init dmapool_debug_setup(char *str) +{ + static_branch_enable(&dmapool_debug_enabled); + return 1; +} +__setup("dmapool_debug", dmapool_debug_setup); =20 struct dma_block { struct dma_block *next_block; @@ -92,13 +105,15 @@ static ssize_t pools_show(struct device *dev, struct d= evice_attribute *attr, cha =20 static DEVICE_ATTR_RO(pools); =20 -#ifdef DMAPOOL_DEBUG static void pool_check_block(struct dma_pool *pool, struct dma_block *bloc= k, gfp_t mem_flags) { u8 *data =3D (void *)block; int i; =20 + if (!static_branch_unlikely(&dmapool_debug_enabled)) + return; + for (i =3D sizeof(struct dma_block); i < pool->size; i++) { if (data[i] =3D=3D POOL_POISON_FREED) continue; @@ -133,8 +148,14 @@ static struct dma_page *pool_find_page(struct dma_pool= *pool, dma_addr_t dma) =20 static bool pool_block_err(struct dma_pool *pool, void *vaddr, dma_addr_t = dma) { - struct dma_block *block =3D pool->next_block; struct dma_page *page; + struct dma_block *block; + + if (!static_branch_unlikely(&dmapool_debug_enabled)) { + if (want_init_on_free()) + memset(vaddr, 0, pool->size); + return false; + } =20 page =3D pool_find_page(pool, dma); if (!page) { @@ -143,6 +164,7 @@ static bool pool_block_err(struct dma_pool *pool, void = *vaddr, dma_addr_t dma) return true; } =20 + block =3D pool->next_block; while (block) { if (block !=3D vaddr) { block =3D block->next_block; @@ -159,25 +181,9 @@ static bool pool_block_err(struct dma_pool *pool, void= *vaddr, dma_addr_t dma) =20 static void pool_init_page(struct dma_pool *pool, struct dma_page *page) { - memset(page->vaddr, POOL_POISON_FREED, pool->allocation); -} -#else -static void pool_check_block(struct dma_pool *pool, struct dma_block *bloc= k, - gfp_t mem_flags) -{ -} - -static bool pool_block_err(struct dma_pool *pool, void *vaddr, dma_addr_t = dma) -{ - if (want_init_on_free()) - memset(vaddr, 0, pool->size); - return false; -} - -static void pool_init_page(struct dma_pool *pool, struct dma_page *page) -{ + if (static_branch_unlikely(&dmapool_debug_enabled)) + memset(page->vaddr, POOL_POISON_FREED, pool->allocation); } -#endif =20 static struct dma_block *pool_block_pop(struct dma_pool *pool) { --=20 2.9.4