* [PATCH v2 1/2] dma-debug: Skip debugfs registration when uninitialized
2026-11-19 13:13 [PATCH v2 0/2] dma-debug: Avoid uninitialized mapping dumps Avi Weiss
@ 2026-11-19 13:13 ` Avi Weiss
2026-11-19 13:13 ` [PATCH v2 2/2] dma-debug: Remove obsolete mapping dump helper Avi Weiss
1 sibling, 0 replies; 3+ messages in thread
From: Avi Weiss @ 2026-11-19 13:13 UTC (permalink / raw)
To: m.szyprowski, robin.murphy; +Cc: ailiop, iommu, linux-kernel, x86, Avi Weiss
dma_debug_init() returns without initializing the hash buckets when DMA
API debugging is disabled at boot. dma_debug_fs_init() still registers
the debugfs files, allowing a read of dma-api/dump to traverse an
uninitialized list and dereference NULL.
Skip debugfs registration unless dma_debug_initialized is set. Keep
the files available if debugging disables itself after initialization,
so previously recorded mappings remain accessible.
Fixes: 173735c346c4 ("dma-debug: fix debugfs initialization order")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
v2:
- check dma_debug_initialized before registering the debugfs
files instead of guarding both dump functions
kernel/dma/debug.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 36c1f7cbb2ae..6e554dcfc9b9 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -839,7 +839,12 @@ static const struct file_operations filter_fops = {
static int __init dma_debug_fs_init(void)
{
- struct dentry *dentry = debugfs_create_dir("dma-api", NULL);
+ struct dentry *dentry;
+
+ if (!dma_debug_initialized)
+ return 0;
+
+ dentry = debugfs_create_dir("dma-api", NULL);
debugfs_create_bool("disabled", 0444, dentry, &global_disable);
debugfs_create_u32("error_count", 0444, dentry, &error_count);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2 2/2] dma-debug: Remove obsolete mapping dump helper
2026-11-19 13:13 [PATCH v2 0/2] dma-debug: Avoid uninitialized mapping dumps Avi Weiss
2026-11-19 13:13 ` [PATCH v2 1/2] dma-debug: Skip debugfs registration when uninitialized Avi Weiss
@ 2026-11-19 13:13 ` Avi Weiss
1 sibling, 0 replies; 3+ messages in thread
From: Avi Weiss @ 2026-11-19 13:13 UTC (permalink / raw)
To: m.szyprowski, robin.murphy; +Cc: ailiop, iommu, linux-kernel, x86, Avi Weiss
debug_dma_dump_mappings() is only called by the legacy AMD GART IOMMU
leak diagnostic. The helper traverses DMA-debug hash buckets even when
DMA debugging was never initialized.
Remove the helper, its declarations and the GART call. Keep the GART
stack trace for diagnosing IOMMU exhaustion.
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
arch/x86/kernel/amd_gart_64.c | 1 -
include/linux/dma-map-ops.h | 4 ----
kernel/dma/debug.c | 33 ---------------------------------
3 files changed, 38 deletions(-)
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index b5f1f031d45b..965844299a1b 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -157,7 +157,6 @@ static void dump_leak(void)
dump = 1;
show_stack(NULL, NULL, KERN_ERR);
- debug_dma_dump_mappings(NULL);
}
#endif
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index afaf2c12189b..eb32ed923455 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -418,14 +418,10 @@ static inline void arch_teardown_dma_ops(struct device *dev)
#ifdef CONFIG_DMA_API_DEBUG
void dma_debug_add_bus(const struct bus_type *bus);
-void debug_dma_dump_mappings(struct device *dev);
#else
static inline void dma_debug_add_bus(const struct bus_type *bus)
{
}
-static inline void debug_dma_dump_mappings(struct device *dev)
-{
-}
#endif /* CONFIG_DMA_API_DEBUG */
extern const struct dma_map_ops dma_dummy_ops;
diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 6e554dcfc9b9..f1b6f7b9aa14 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -535,39 +535,6 @@ static void active_cacheline_remove(struct dma_debug_entry *entry)
spin_unlock_irqrestore(&radix_lock, flags);
}
-/*
- * Dump mappings entries on kernel space for debugging purposes
- */
-void debug_dma_dump_mappings(struct device *dev)
-{
- int idx;
- phys_addr_t cln;
-
- for (idx = 0; idx < HASH_SIZE; idx++) {
- struct hash_bucket *bucket = &dma_entry_hash[idx];
- struct dma_debug_entry *entry;
- unsigned long flags;
-
- spin_lock_irqsave(&bucket->lock, flags);
- list_for_each_entry(entry, &bucket->list, list) {
- if (!dev || dev == entry->dev) {
- cln = to_cacheline_number(entry);
- dev_info(entry->dev,
- "%s idx %d P=%pa D=%llx L=%llx cln=%pa %s %s attrs=0x%lx\n",
- type2name[entry->type], idx,
- &entry->paddr, entry->dev_addr,
- entry->size, &cln,
- dir2name[entry->direction],
- maperr2str[entry->map_err_type],
- entry->attrs);
- }
- }
- spin_unlock_irqrestore(&bucket->lock, flags);
-
- cond_resched();
- }
-}
-
/*
* Dump mappings entries on user space via debugfs
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread