All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] dma-debug: Avoid uninitialized mapping dumps
@ 2026-11-19 13:13 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 ` [PATCH v2 2/2] dma-debug: Remove obsolete mapping dump helper Avi Weiss
  0 siblings, 2 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

Booting with dma_debug=off leaves the DMA-debug hash buckets
uninitialized, but the debugfs mapping dump is still registered.
Reading dma-api/dump then traverses an uninitialized list and
causes a NULL pointer dereference in dump_show().

Patch 1 skips debugfs registration when DMA debugging was not
initialized. Patch 2 removes the obsolete debug_dma_dump_mappings()
helper and its only caller in the legacy AMD GART IOMMU code.

Validation on x86-64 QEMU:
- baseline with dma_debug=off - NULL dereference in dump_show()
- patched with dma_debug=off - dma-api debugfs directory absent
- patched with DMA debugging enabled - mapping dump readable
- both objects compiled successfully with W=1

Changes since v1:
- guard debugfs registration instead of the dump paths, as
  suggested by Anthony Iliopoulos
- remove the obsolete mapping dump helper and its AMD GART
  caller (due to feedback from Robin Murphy and Marek Szyprowski)

v1 discussion:
https://lore-kernel.gnuweeb.org/linux-iommu/05c05ec4-b321-49d4-acf7-b9fa4223dba9%40samsung.com/T/


Avi Weiss (2):
  dma-debug: Skip debugfs registration when uninitialized
  dma-debug: Remove obsolete mapping dump helper

 arch/x86/kernel/amd_gart_64.c |  1 -
 include/linux/dma-map-ops.h   |  4 ----
 kernel/dma/debug.c            | 40 ++++++-----------------------------
 3 files changed, 6 insertions(+), 39 deletions(-)


base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [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

end of thread, other threads:[~2026-11-19 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 2/2] dma-debug: Remove obsolete mapping dump helper Avi Weiss

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.