Skip to contentSkip to conversation

dma-debug cleanups, including removing the arch hook

PATCH In review Christoph Hellwig 3 participants 12 messages Apr 24, 2018 – May 8, 2018

Subsystems (19)
lore
Share & tools
lore
#0 lore raw

Hi all,

this series has a few dma-debug cleanups, most notably removing the need for architectures to explicitly initialize dma-debug.

#1 lore raw

PATCH 1/3 dma-debug: move initialization to common code

Most mainstream architectures are using 65536 entries, so lets stick to that. If someone is really desperate to override it that can still be done through <asm/dma-mapping.h>, but I'd rather see a really good rationale for that.

dma_debug_init is now called as a core_initcall, which for many architectures means much earlier, and provides dma-debug functionality earlier in the boot process. This should be safe as it only relies on the memory allocator already being available.

---
 arch/arm/mm/dma-mapping-nommu.c |  9 ---------
 arch/arm/mm/dma-mapping.c       |  9 ---------
 arch/arm64/mm/dma-mapping.c     | 10 ----------
 arch/c6x/kernel/dma.c           | 11 -----------
 arch/ia64/kernel/dma-mapping.c  | 10 ----------
 arch/microblaze/kernel/dma.c    | 11 -----------
 arch/mips/mm/dma-default.c      | 10 ----------
 arch/openrisc/kernel/dma.c      | 11 -----------
 arch/powerpc/kernel/dma.c       |  3 ---
 arch/s390/pci/pci_dma.c         |  9 ---------
 arch/sh/mm/consistent.c         |  9 ---------
 arch/sparc/kernel/Makefile      |  2 --
 arch/sparc/kernel/dma.c         | 13 -------------
 arch/x86/kernel/pci-dma.c       |  4 ----
 arch/xtensa/kernel/pci-dma.c    |  9 ---------
 include/linux/dma-debug.h       |  6 ------
 lib/dma-debug.c                 | 21 ++++++++++++++-------
 17 files changed, 14 insertions(+), 143 deletions(-)
 delete mode 100644 arch/sparc/kernel/dma.c
arch/arm/mm/dma-mapping-nommu.c +0 -9
index 619f24a42d09..f448a0663b10 100644
@@ -241,12 +241,3 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
 void arch_teardown_dma_ops(struct device *dev)
 {
 }
-
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-core_initcall(dma_debug_do_init);
arch/arm/mm/dma-mapping.c +0 -9
index 8c398fedbbb6..c26bf83f44ca 100644
@@ -1165,15 +1165,6 @@ int arm_dma_supported(struct device *dev, u64 mask)
 	return __dma_supported(dev, mask, false);
 }
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-core_initcall(dma_debug_do_init);
-
 #ifdef CONFIG_ARM_DMA_USE_IOMMU
 
 static int __dma_info_to_prot(enum dma_data_direction dir, unsigned long attrs)
arch/arm64/mm/dma-mapping.c +0 -10
index a96ec0181818..db01f2709842 100644
@@ -508,16 +508,6 @@ static int __init arm64_dma_init(void)
 }
 arch_initcall(arm64_dma_init);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_debug_do_init);
-
-
 #ifdef CONFIG_IOMMU_DMA
 #include <linux/dma-iommu.h>
 #include <linux/platform_device.h>
arch/c6x/kernel/dma.c +0 -11
index 9fff8be75f58..31e1a9ec3a9c 100644
@@ -136,14 +136,3 @@ const struct dma_map_ops c6x_dma_ops = {
 	.sync_sg_for_cpu	= c6x_dma_sync_sg_for_cpu,
 };
 EXPORT_SYMBOL(c6x_dma_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/ia64/kernel/dma-mapping.c +0 -10
index f2d57e66fd86..7a471d8d67d4 100644
@@ -9,16 +9,6 @@ int iommu_detected __read_mostly;
 const struct dma_map_ops *dma_ops;
 EXPORT_SYMBOL(dma_ops);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
-
 const struct dma_map_ops *dma_get_ops(struct device *dev)
 {
 	return dma_ops;
arch/microblaze/kernel/dma.c +0 -11
index c91e8cef98dd..3145e7dc8ab1 100644
@@ -184,14 +184,3 @@ const struct dma_map_ops dma_nommu_ops = {
 	.sync_sg_for_device	= dma_nommu_sync_sg_for_device,
 };
 EXPORT_SYMBOL(dma_nommu_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/mips/mm/dma-default.c +0 -10
index dcafa43613b6..f9fef0028ca2 100644
@@ -402,13 +402,3 @@ static const struct dma_map_ops mips_default_dma_map_ops = {
 
 const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
 EXPORT_SYMBOL(mips_dma_map_ops);
-
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init mips_dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(mips_dma_init);
arch/openrisc/kernel/dma.c +0 -11
index a945f00011b4..ec7fd45704d2 100644
@@ -247,14 +247,3 @@ const struct dma_map_ops or1k_dma_map_ops = {
 	.sync_single_for_device = or1k_sync_single_for_device,
 };
 EXPORT_SYMBOL(or1k_dma_map_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/powerpc/kernel/dma.c +0 -3
index da20569de9d4..138157deeadf 100644
@@ -309,8 +309,6 @@ int dma_set_coherent_mask(struct device *dev, u64 mask)
 }
 EXPORT_SYMBOL(dma_set_coherent_mask);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
 int dma_set_mask(struct device *dev, u64 dma_mask)
 {
 	if (ppc_md.dma_set_mask)
@@ -361,7 +359,6 @@ EXPORT_SYMBOL_GPL(dma_get_required_mask);
 
 static int __init dma_init(void)
 {
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
 #ifdef CONFIG_PCI
 	dma_debug_add_bus(&pci_bus_type);
 #endif
arch/s390/pci/pci_dma.c +0 -9
index 2d15d84c20ed..5dee7a922589 100644
@@ -668,15 +668,6 @@ void zpci_dma_exit(void)
 	kmem_cache_destroy(dma_region_table_cache);
 }
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	(1 << 16)
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_debug_do_init);
-
 const struct dma_map_ops s390_pci_dma_ops = {
 	.alloc		= s390_dma_alloc,
 	.free		= s390_dma_free,
arch/sh/mm/consistent.c +0 -9
index 8ce98691d822..35ea3099a3b6 100644
@@ -20,18 +20,9 @@
 #include <asm/cacheflush.h>
 #include <asm/addrspace.h>
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
 const struct dma_map_ops *dma_ops;
 EXPORT_SYMBOL(dma_ops);
 
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_init);
-
 void *dma_generic_alloc_coherent(struct device *dev, size_t size,
 				 dma_addr_t *dma_handle, gfp_t gfp,
 				 unsigned long attrs)
arch/sparc/kernel/Makefile +0 -2
index 76cb57750dda..84cfc5a428d6 100644
@@ -74,8 +74,6 @@ obj-$(CONFIG_SPARC64)	+= pcr.o
 obj-$(CONFIG_SPARC64)	+= nmi.o
 obj-$(CONFIG_SPARC64_SMP) += cpumap.o
 
-obj-y                     += dma.o
-
 obj-$(CONFIG_PCIC_PCI)    += pcic.o
 obj-$(CONFIG_LEON_PCI)    += leon_pci.o
 obj-$(CONFIG_SPARC_GRPCI2)+= leon_pci_grpci2.o
arch/sparc/kernel/dma.c deleted +0 -13
deleted file mode 100644
index f73e7597c971..000000000000
@@ -1,13 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/kernel.h>
-#include <linux/dma-mapping.h>
-#include <linux/dma-debug.h>
-
-#define PREALLOC_DMA_DEBUG_ENTRIES       (1 << 15)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_init);
arch/x86/kernel/pci-dma.c +0 -4
index 77625b60a510..bcbaa2e8031e 100644
@@ -55,9 +55,6 @@ struct device x86_dma_fallback_dev = {
 };
 EXPORT_SYMBOL(x86_dma_fallback_dev);
 
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES       65536
-
 void __init pci_iommu_alloc(void)
 {
 	struct iommu_table_entry *p;
@@ -189,7 +186,6 @@ EXPORT_SYMBOL(arch_dma_supported);
 static int __init pci_iommu_init(void)
 {
 	struct iommu_table_entry *p;
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
 
 #ifdef CONFIG_PCI
 	dma_debug_add_bus(&pci_bus_type);
arch/xtensa/kernel/pci-dma.c +0 -9
index 732631ce250f..392b4a80ebc2 100644
@@ -261,12 +261,3 @@ const struct dma_map_ops xtensa_dma_map_ops = {
 	.mapping_error = xtensa_dma_mapping_error,
 };
 EXPORT_SYMBOL(xtensa_dma_map_ops);
-
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init xtensa_dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(xtensa_dma_init);
include/linux/dma-debug.h +0 -6
index c7d844f09c3a..a785f2507159 100644
@@ -30,8 +30,6 @@ struct bus_type;
 
 extern void dma_debug_add_bus(struct bus_type *bus);
 
-extern void dma_debug_init(u32 num_entries);
-
 extern int dma_debug_resize_entries(u32 num_entries);
 
 extern void debug_dma_map_page(struct device *dev, struct page *page,
@@ -100,10 +98,6 @@ static inline void dma_debug_add_bus(struct bus_type *bus)
 {
 }
 
-static inline void dma_debug_init(u32 num_entries)
-{
-}
-
 static inline int dma_debug_resize_entries(u32 num_entries)
 {
 	return 0;
lib/dma-debug.c +14 -7
index 7f5cdc1e6b29..712a897174e4 100644
@@ -41,6 +41,11 @@
 #define HASH_FN_SHIFT   13
 #define HASH_FN_MASK    (HASH_SIZE - 1)
 
+/* allow architectures to override this if absolutely required */
+#ifndef PREALLOC_DMA_DEBUG_ENTRIES
+#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
+#endif
+
 enum {
 	dma_debug_single,
 	dma_debug_page,
@@ -1004,18 +1009,16 @@ void dma_debug_add_bus(struct bus_type *bus)
 	bus_register_notifier(bus, nb);
 }
 
-/*
- * Let the architectures decide how many entries should be preallocated.
- */
-void dma_debug_init(u32 num_entries)
+static int dma_debug_init(void)
 {
+	u32 num_entries;
 	int i;
 
 	/* Do not use dma_debug_initialized here, since we really want to be
 	 * called to set dma_debug_initialized
 	 */
 	if (global_disable)
-		return;
+		return 0;
 
 	for (i = 0; i < HASH_SIZE; ++i) {
 		INIT_LIST_HEAD(&dma_entry_hash[i].list);
@@ -1026,17 +1029,19 @@ void dma_debug_init(u32 num_entries)
 		pr_err("DMA-API: error creating debugfs entries - disabling\n");
 		global_disable = true;
 
-		return;
+		return 0;
 	}
 
 	if (req_entries)
 		num_entries = req_entries;
+	else
+		num_entries = PREALLOC_DMA_DEBUG_ENTRIES;
 
 	if (prealloc_memory(num_entries) != 0) {
 		pr_err("DMA-API: debugging out of memory error - disabled\n");
 		global_disable = true;
 
-		return;
+		return 0;
 	}
 
 	nr_total_entries = num_free_entries;
@@ -1044,7 +1049,9 @@ void dma_debug_init(u32 num_entries)
 	dma_debug_initialized = true;
 
 	pr_info("DMA-API: debugging enabled by kernel config\n");
+	return 0;
 }
+core_initcall(dma_debug_init);
 
 static __init int dma_debug_cmdline(char *str)
 {
Signature · 1 line
2.17.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] dma-debug: move initialization to common code

Quoted 9 lines · Christoph Hellwig

Most mainstream architectures are using 65536 entries, so lets stick to that. If someone is really desperate to override it that can still be done through <asm/dma-mapping.h>, but I'd rather see a really good rationale for that.

dma_debug_init is now called as a core_initcall, which for many architectures means much earlier, and provides dma-debug functionality earlier in the boot process. This should be safe as it only relies on the memory allocator already being available.

Quoted 406 lines
---
  arch/arm/mm/dma-mapping-nommu.c |  9 ---------
  arch/arm/mm/dma-mapping.c       |  9 ---------
  arch/arm64/mm/dma-mapping.c     | 10 ----------
  arch/c6x/kernel/dma.c           | 11 -----------
  arch/ia64/kernel/dma-mapping.c  | 10 ----------
  arch/microblaze/kernel/dma.c    | 11 -----------
  arch/mips/mm/dma-default.c      | 10 ----------
  arch/openrisc/kernel/dma.c      | 11 -----------
  arch/powerpc/kernel/dma.c       |  3 ---
  arch/s390/pci/pci_dma.c         |  9 ---------
  arch/sh/mm/consistent.c         |  9 ---------
  arch/sparc/kernel/Makefile      |  2 --
  arch/sparc/kernel/dma.c         | 13 -------------
  arch/x86/kernel/pci-dma.c       |  4 ----
  arch/xtensa/kernel/pci-dma.c    |  9 ---------
  include/linux/dma-debug.h       |  6 ------
  lib/dma-debug.c                 | 21 ++++++++++++++-------
  17 files changed, 14 insertions(+), 143 deletions(-)

delete mode 100644 arch/sparc/kernel/dma.c

arch/arm/mm/dma-mapping-nommu.c +0 -9
index 619f24a42d09..f448a0663b10 100644
@@ -241,12 +241,3 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
  void arch_teardown_dma_ops(struct device *dev)
  {
  }
-
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-core_initcall(dma_debug_do_init);
arch/arm/mm/dma-mapping.c +0 -9
index 8c398fedbbb6..c26bf83f44ca 100644
@@ -1165,15 +1165,6 @@ int arm_dma_supported(struct device *dev, u64 mask)
  	return __dma_supported(dev, mask, false);
  }
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-core_initcall(dma_debug_do_init);
-
  #ifdef CONFIG_ARM_DMA_USE_IOMMU
 
  static int __dma_info_to_prot(enum dma_data_direction dir, unsigned long attrs)
arch/arm64/mm/dma-mapping.c +0 -10
index a96ec0181818..db01f2709842 100644
@@ -508,16 +508,6 @@ static int __init arm64_dma_init(void)
  }
  arch_initcall(arm64_dma_init);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_debug_do_init);
-
-
  #ifdef CONFIG_IOMMU_DMA
  #include <linux/dma-iommu.h>
  #include <linux/platform_device.h>
arch/c6x/kernel/dma.c +0 -11
index 9fff8be75f58..31e1a9ec3a9c 100644
@@ -136,14 +136,3 @@ const struct dma_map_ops c6x_dma_ops = {
  	.sync_sg_for_cpu	= c6x_dma_sync_sg_for_cpu,
  };
  EXPORT_SYMBOL(c6x_dma_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/ia64/kernel/dma-mapping.c +0 -10
index f2d57e66fd86..7a471d8d67d4 100644
@@ -9,16 +9,6 @@ int iommu_detected __read_mostly;
  const struct dma_map_ops *dma_ops;
  EXPORT_SYMBOL(dma_ops);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
-
  const struct dma_map_ops *dma_get_ops(struct device *dev)
  {
  	return dma_ops;
arch/microblaze/kernel/dma.c +0 -11
index c91e8cef98dd..3145e7dc8ab1 100644
@@ -184,14 +184,3 @@ const struct dma_map_ops dma_nommu_ops = {
  	.sync_sg_for_device	= dma_nommu_sync_sg_for_device,
  };
  EXPORT_SYMBOL(dma_nommu_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/mips/mm/dma-default.c +0 -10
index dcafa43613b6..f9fef0028ca2 100644
@@ -402,13 +402,3 @@ static const struct dma_map_ops mips_default_dma_map_ops = {
 
  const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
  EXPORT_SYMBOL(mips_dma_map_ops);
-
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init mips_dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(mips_dma_init);
arch/openrisc/kernel/dma.c +0 -11
index a945f00011b4..ec7fd45704d2 100644
@@ -247,14 +247,3 @@ const struct dma_map_ops or1k_dma_map_ops = {
  	.sync_single_for_device = or1k_sync_single_for_device,
  };
  EXPORT_SYMBOL(or1k_dma_map_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/powerpc/kernel/dma.c +0 -3
index da20569de9d4..138157deeadf 100644
@@ -309,8 +309,6 @@ int dma_set_coherent_mask(struct device *dev, u64 mask)
  }
  EXPORT_SYMBOL(dma_set_coherent_mask);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
  int dma_set_mask(struct device *dev, u64 dma_mask)
  {
  	if (ppc_md.dma_set_mask)
@@ -361,7 +359,6 @@ EXPORT_SYMBOL_GPL(dma_get_required_mask);
 
  static int __init dma_init(void)
  {
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
  #ifdef CONFIG_PCI
  	dma_debug_add_bus(&pci_bus_type);
  #endif
arch/s390/pci/pci_dma.c +0 -9
index 2d15d84c20ed..5dee7a922589 100644
@@ -668,15 +668,6 @@ void zpci_dma_exit(void)
  	kmem_cache_destroy(dma_region_table_cache);
  }
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	(1 << 16)
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_debug_do_init);
-
  const struct dma_map_ops s390_pci_dma_ops = {
  	.alloc		= s390_dma_alloc,
  	.free		= s390_dma_free,
arch/sh/mm/consistent.c +0 -9
index 8ce98691d822..35ea3099a3b6 100644
@@ -20,18 +20,9 @@
  #include <asm/cacheflush.h>
  #include <asm/addrspace.h>
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
  const struct dma_map_ops *dma_ops;
  EXPORT_SYMBOL(dma_ops);
 
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_init);
-
  void *dma_generic_alloc_coherent(struct device *dev, size_t size,
  				 dma_addr_t *dma_handle, gfp_t gfp,
  				 unsigned long attrs)
arch/sparc/kernel/Makefile +0 -2
index 76cb57750dda..84cfc5a428d6 100644
@@ -74,8 +74,6 @@ obj-$(CONFIG_SPARC64)	+= pcr.o
  obj-$(CONFIG_SPARC64)	+= nmi.o
  obj-$(CONFIG_SPARC64_SMP) += cpumap.o
 
-obj-y                     += dma.o
-
  obj-$(CONFIG_PCIC_PCI)    += pcic.o
  obj-$(CONFIG_LEON_PCI)    += leon_pci.o
  obj-$(CONFIG_SPARC_GRPCI2)+= leon_pci_grpci2.o
arch/sparc/kernel/dma.c deleted +0 -13
deleted file mode 100644
index f73e7597c971..000000000000
@@ -1,13 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/kernel.h>
-#include <linux/dma-mapping.h>
-#include <linux/dma-debug.h>
-
-#define PREALLOC_DMA_DEBUG_ENTRIES       (1 << 15)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_init);
arch/x86/kernel/pci-dma.c +0 -4
index 77625b60a510..bcbaa2e8031e 100644
@@ -55,9 +55,6 @@ struct device x86_dma_fallback_dev = {
  };
  EXPORT_SYMBOL(x86_dma_fallback_dev);
 
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES       65536
-
  void __init pci_iommu_alloc(void)
  {
  	struct iommu_table_entry *p;
@@ -189,7 +186,6 @@ EXPORT_SYMBOL(arch_dma_supported);
  static int __init pci_iommu_init(void)
  {
  	struct iommu_table_entry *p;
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
 
  #ifdef CONFIG_PCI
  	dma_debug_add_bus(&pci_bus_type);
arch/xtensa/kernel/pci-dma.c +0 -9
index 732631ce250f..392b4a80ebc2 100644
@@ -261,12 +261,3 @@ const struct dma_map_ops xtensa_dma_map_ops = {
  	.mapping_error = xtensa_dma_mapping_error,
  };
  EXPORT_SYMBOL(xtensa_dma_map_ops);
-
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init xtensa_dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(xtensa_dma_init);
include/linux/dma-debug.h +0 -6
index c7d844f09c3a..a785f2507159 100644
@@ -30,8 +30,6 @@ struct bus_type;
 
  extern void dma_debug_add_bus(struct bus_type *bus);
 
-extern void dma_debug_init(u32 num_entries);
-
  extern int dma_debug_resize_entries(u32 num_entries);
 
  extern void debug_dma_map_page(struct device *dev, struct page *page,
@@ -100,10 +98,6 @@ static inline void dma_debug_add_bus(struct bus_type *bus)
  {
  }
 
-static inline void dma_debug_init(u32 num_entries)
-{
-}
-
  static inline int dma_debug_resize_entries(u32 num_entries)
  {
  	return 0;
lib/dma-debug.c +14 -7
index 7f5cdc1e6b29..712a897174e4 100644
@@ -41,6 +41,11 @@
  #define HASH_FN_SHIFT   13
  #define HASH_FN_MASK    (HASH_SIZE - 1)
 
+/* allow architectures to override this if absolutely required */
+#ifndef PREALLOC_DMA_DEBUG_ENTRIES
+#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
+#endif
+
  enum {
  	dma_debug_single,
  	dma_debug_page,
@@ -1004,18 +1009,16 @@ void dma_debug_add_bus(struct bus_type *bus)
  	bus_register_notifier(bus, nb);
  }
 
-/*
- * Let the architectures decide how many entries should be preallocated.
- */
-void dma_debug_init(u32 num_entries)
+static int dma_debug_init(void)
  {
+	u32 num_entries;
  	int i;
 
  	/* Do not use dma_debug_initialized here, since we really want to be
  	 * called to set dma_debug_initialized
  	 */
  	if (global_disable)
-		return;
+		return 0;
 
  	for (i = 0; i < HASH_SIZE; ++i) {
  		INIT_LIST_HEAD(&dma_entry_hash[i].list);
@@ -1026,17 +1029,19 @@ void dma_debug_init(u32 num_entries)
  		pr_err("DMA-API: error creating debugfs entries - disabling\n");
  		global_disable = true;
 
-		return;
+		return 0;
  	}
 
  	if (req_entries)
  		num_entries = req_entries;
+	else
+		num_entries = PREALLOC_DMA_DEBUG_ENTRIES;
 
  	if (prealloc_memory(num_entries) != 0) {
  		pr_err("DMA-API: debugging out of memory error - disabled\n");
  		global_disable = true;
 
-		return;
+		return 0;
  	}
 
  	nr_total_entries = num_free_entries;
@@ -1044,7 +1049,9 @@ void dma_debug_init(u32 num_entries)
  	dma_debug_initialized = true;
 
  	pr_info("DMA-API: debugging enabled by kernel config\n");
+	return 0;
  }
+core_initcall(dma_debug_init);
 
  static __init int dma_debug_cmdline(char *str)
  {
Acked-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] dma-debug: move initialization to common code

In reply to Christoph Hellwig

Hi Christoph,

Quoted 11 lines · Christoph Hellwig

Most mainstream architectures are using 65536 entries, so lets stick to that. If someone is really desperate to override it that can still be done through <asm/dma-mapping.h>, but I'd rather see a really good rationale for that.

dma_debug_init is now called as a core_initcall, which for many architectures means much earlier, and provides dma-debug functionality earlier in the boot process. This should be safe as it only relies on the memory allocator already being available.

Nice! Unification of this is definitely needed and solves the issues reported some time ago:

https://patchwork.kernel.org/patch/9429637/ (arm)
https://patchwork.kernel.org/patch/9431161/ (arm64, rejected)

Quoted 395 lines
---
  arch/arm/mm/dma-mapping-nommu.c |  9 ---------
  arch/arm/mm/dma-mapping.c       |  9 ---------
  arch/arm64/mm/dma-mapping.c     | 10 ----------
  arch/c6x/kernel/dma.c           | 11 -----------
  arch/ia64/kernel/dma-mapping.c  | 10 ----------
  arch/microblaze/kernel/dma.c    | 11 -----------
  arch/mips/mm/dma-default.c      | 10 ----------
  arch/openrisc/kernel/dma.c      | 11 -----------
  arch/powerpc/kernel/dma.c       |  3 ---
  arch/s390/pci/pci_dma.c         |  9 ---------
  arch/sh/mm/consistent.c         |  9 ---------
  arch/sparc/kernel/Makefile      |  2 --
  arch/sparc/kernel/dma.c         | 13 -------------
  arch/x86/kernel/pci-dma.c       |  4 ----
  arch/xtensa/kernel/pci-dma.c    |  9 ---------
  include/linux/dma-debug.h       |  6 ------
  lib/dma-debug.c                 | 21 ++++++++++++++-------
  17 files changed, 14 insertions(+), 143 deletions(-)

delete mode 100644 arch/sparc/kernel/dma.c

arch/arm/mm/dma-mapping-nommu.c +0 -9
index 619f24a42d09..f448a0663b10 100644
@@ -241,12 +241,3 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
  void arch_teardown_dma_ops(struct device *dev)
  {
  }
-
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-core_initcall(dma_debug_do_init);
arch/arm/mm/dma-mapping.c +0 -9
index 8c398fedbbb6..c26bf83f44ca 100644
@@ -1165,15 +1165,6 @@ int arm_dma_supported(struct device *dev, u64 mask)
  	return __dma_supported(dev, mask, false);
  }
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-core_initcall(dma_debug_do_init);
-
  #ifdef CONFIG_ARM_DMA_USE_IOMMU
 
  static int __dma_info_to_prot(enum dma_data_direction dir, unsigned long attrs)
arch/arm64/mm/dma-mapping.c +0 -10
index a96ec0181818..db01f2709842 100644
@@ -508,16 +508,6 @@ static int __init arm64_dma_init(void)
  }
  arch_initcall(arm64_dma_init);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_debug_do_init);
-
-
  #ifdef CONFIG_IOMMU_DMA
  #include <linux/dma-iommu.h>
  #include <linux/platform_device.h>
arch/c6x/kernel/dma.c +0 -11
index 9fff8be75f58..31e1a9ec3a9c 100644
@@ -136,14 +136,3 @@ const struct dma_map_ops c6x_dma_ops = {
  	.sync_sg_for_cpu	= c6x_dma_sync_sg_for_cpu,
  };
  EXPORT_SYMBOL(c6x_dma_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/ia64/kernel/dma-mapping.c +0 -10
index f2d57e66fd86..7a471d8d67d4 100644
@@ -9,16 +9,6 @@ int iommu_detected __read_mostly;
  const struct dma_map_ops *dma_ops;
  EXPORT_SYMBOL(dma_ops);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
-
  const struct dma_map_ops *dma_get_ops(struct device *dev)
  {
  	return dma_ops;
arch/microblaze/kernel/dma.c +0 -11
index c91e8cef98dd..3145e7dc8ab1 100644
@@ -184,14 +184,3 @@ const struct dma_map_ops dma_nommu_ops = {
  	.sync_sg_for_device	= dma_nommu_sync_sg_for_device,
  };
  EXPORT_SYMBOL(dma_nommu_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/mips/mm/dma-default.c +0 -10
index dcafa43613b6..f9fef0028ca2 100644
@@ -402,13 +402,3 @@ static const struct dma_map_ops mips_default_dma_map_ops = {
 
  const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
  EXPORT_SYMBOL(mips_dma_map_ops);
-
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init mips_dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(mips_dma_init);
arch/openrisc/kernel/dma.c +0 -11
index a945f00011b4..ec7fd45704d2 100644
@@ -247,14 +247,3 @@ const struct dma_map_ops or1k_dma_map_ops = {
  	.sync_single_for_device = or1k_sync_single_for_device,
  };
  EXPORT_SYMBOL(or1k_dma_map_ops);
-
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-
-	return 0;
-}
-fs_initcall(dma_init);
arch/powerpc/kernel/dma.c +0 -3
index da20569de9d4..138157deeadf 100644
@@ -309,8 +309,6 @@ int dma_set_coherent_mask(struct device *dev, u64 mask)
  }
  EXPORT_SYMBOL(dma_set_coherent_mask);
 
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
  int dma_set_mask(struct device *dev, u64 dma_mask)
  {
  	if (ppc_md.dma_set_mask)
@@ -361,7 +359,6 @@ EXPORT_SYMBOL_GPL(dma_get_required_mask);
 
  static int __init dma_init(void)
  {
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
  #ifdef CONFIG_PCI
  	dma_debug_add_bus(&pci_bus_type);
  #endif
arch/s390/pci/pci_dma.c +0 -9
index 2d15d84c20ed..5dee7a922589 100644
@@ -668,15 +668,6 @@ void zpci_dma_exit(void)
  	kmem_cache_destroy(dma_region_table_cache);
  }
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	(1 << 16)
-
-static int __init dma_debug_do_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_debug_do_init);
-
  const struct dma_map_ops s390_pci_dma_ops = {
  	.alloc		= s390_dma_alloc,
  	.free		= s390_dma_free,
arch/sh/mm/consistent.c +0 -9
index 8ce98691d822..35ea3099a3b6 100644
@@ -20,18 +20,9 @@
  #include <asm/cacheflush.h>
  #include <asm/addrspace.h>
 
-#define PREALLOC_DMA_DEBUG_ENTRIES	4096
-
  const struct dma_map_ops *dma_ops;
  EXPORT_SYMBOL(dma_ops);
 
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_init);
-
  void *dma_generic_alloc_coherent(struct device *dev, size_t size,
  				 dma_addr_t *dma_handle, gfp_t gfp,
  				 unsigned long attrs)
arch/sparc/kernel/Makefile +0 -2
index 76cb57750dda..84cfc5a428d6 100644
@@ -74,8 +74,6 @@ obj-$(CONFIG_SPARC64)	+= pcr.o
  obj-$(CONFIG_SPARC64)	+= nmi.o
  obj-$(CONFIG_SPARC64_SMP) += cpumap.o
 
-obj-y                     += dma.o
-
  obj-$(CONFIG_PCIC_PCI)    += pcic.o
  obj-$(CONFIG_LEON_PCI)    += leon_pci.o
  obj-$(CONFIG_SPARC_GRPCI2)+= leon_pci_grpci2.o
arch/sparc/kernel/dma.c deleted +0 -13
deleted file mode 100644
index f73e7597c971..000000000000
@@ -1,13 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/kernel.h>
-#include <linux/dma-mapping.h>
-#include <linux/dma-debug.h>
-
-#define PREALLOC_DMA_DEBUG_ENTRIES       (1 << 15)
-
-static int __init dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(dma_init);
arch/x86/kernel/pci-dma.c +0 -4
index 77625b60a510..bcbaa2e8031e 100644
@@ -55,9 +55,6 @@ struct device x86_dma_fallback_dev = {
  };
  EXPORT_SYMBOL(x86_dma_fallback_dev);
 
-/* Number of entries preallocated for DMA-API debugging */
-#define PREALLOC_DMA_DEBUG_ENTRIES       65536
-
  void __init pci_iommu_alloc(void)
  {
  	struct iommu_table_entry *p;
@@ -189,7 +186,6 @@ EXPORT_SYMBOL(arch_dma_supported);
  static int __init pci_iommu_init(void)
  {
  	struct iommu_table_entry *p;
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
 
  #ifdef CONFIG_PCI
  	dma_debug_add_bus(&pci_bus_type);
arch/xtensa/kernel/pci-dma.c +0 -9
index 732631ce250f..392b4a80ebc2 100644
@@ -261,12 +261,3 @@ const struct dma_map_ops xtensa_dma_map_ops = {
  	.mapping_error = xtensa_dma_mapping_error,
  };
  EXPORT_SYMBOL(xtensa_dma_map_ops);
-
-#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
-
-static int __init xtensa_dma_init(void)
-{
-	dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
-	return 0;
-}
-fs_initcall(xtensa_dma_init);
include/linux/dma-debug.h +0 -6
index c7d844f09c3a..a785f2507159 100644
@@ -30,8 +30,6 @@ struct bus_type;
 
  extern void dma_debug_add_bus(struct bus_type *bus);
 
-extern void dma_debug_init(u32 num_entries);
-
  extern int dma_debug_resize_entries(u32 num_entries);
 
  extern void debug_dma_map_page(struct device *dev, struct page *page,
@@ -100,10 +98,6 @@ static inline void dma_debug_add_bus(struct bus_type *bus)
  {
  }
 
-static inline void dma_debug_init(u32 num_entries)
-{
-}
-
  static inline int dma_debug_resize_entries(u32 num_entries)
  {
  	return 0;
lib/dma-debug.c +12 -7
index 7f5cdc1e6b29..712a897174e4 100644
@@ -41,6 +41,11 @@
  #define HASH_FN_SHIFT   13
  #define HASH_FN_MASK    (HASH_SIZE - 1)
 
+/* allow architectures to override this if absolutely required */
+#ifndef PREALLOC_DMA_DEBUG_ENTRIES
+#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
+#endif
+
  enum {
  	dma_debug_single,
  	dma_debug_page,
@@ -1004,18 +1009,16 @@ void dma_debug_add_bus(struct bus_type *bus)
  	bus_register_notifier(bus, nb);
  }
 
-/*
- * Let the architectures decide how many entries should be preallocated.
- */
-void dma_debug_init(u32 num_entries)
+static int dma_debug_init(void)
  {
+	u32 num_entries;
  	int i;
 
  	/* Do not use dma_debug_initialized here, since we really want to be
  	 * called to set dma_debug_initialized
  	 */
  	if (global_disable)
-		return;
+		return 0;
 
  	for (i = 0; i < HASH_SIZE; ++i) {
  		INIT_LIST_HEAD(&dma_entry_hash[i].list);
@@ -1026,17 +1029,19 @@ void dma_debug_init(u32 num_entries)
  		pr_err("DMA-API: error creating debugfs entries - disabling\n");
  		global_disable = true;
 
-		return;
+		return 0;
  	}
 
  	if (req_entries)
  		num_entries = req_entries;
+	else
+		num_entries = PREALLOC_DMA_DEBUG_ENTRIES;
 
  	if (prealloc_memory(num_entries) != 0) {
  		pr_err("DMA-API: debugging out of memory error - disabled\n");
  		global_disable = true;
 
-		return;
+		return 0;
  	}
 
  	nr_total_entries = num_free_entries;

lib/dma-debug.c void dma_debug_init(u32 num_entries) · line 1057

Quoted 9 lines
lib/dma-debug.c +2 -0
@@ -1044,7 +1049,9 @@ void dma_debug_init(u32 num_entries)
  	dma_debug_initialized = true;
 
  	pr_info("DMA-API: debugging enabled by kernel config\n");
+	return 0;
  }
+core_initcall(dma_debug_init);
 
  static __init int dma_debug_cmdline(char *str)
  {

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#4 lore raw

PATCH 2/3 dma-debug: simplify counting of preallocated requests

In reply to Christoph Hellwig

Just keep a single variable with a descriptive name instead of two with confusing names.

---
 lib/dma-debug.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
lib/dma-debug.c +4 -16
index 712a897174e4..075253cb613b 100644
@@ -132,7 +132,7 @@ static u32 min_free_entries;
 static u32 nr_total_entries;
 
 /* number of preallocated entries requested by kernel cmdline */
-static u32 req_entries;
+static u32 nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES;
 
 /* debugfs dentry's for the stuff above */
 static struct dentry *dma_debug_dent        __read_mostly;
@@ -1011,7 +1011,6 @@ void dma_debug_add_bus(struct bus_type *bus)
 
 static int dma_debug_init(void)
 {
-	u32 num_entries;
 	int i;
 
 	/* Do not use dma_debug_initialized here, since we really want to be
@@ -1032,12 +1031,7 @@ static int dma_debug_init(void)
 		return 0;
 	}
 
-	if (req_entries)
-		num_entries = req_entries;
-	else
-		num_entries = PREALLOC_DMA_DEBUG_ENTRIES;
-
-	if (prealloc_memory(num_entries) != 0) {
+	if (prealloc_memory(nr_prealloc_entries) != 0) {
 		pr_err("DMA-API: debugging out of memory error - disabled\n");
 		global_disable = true;
 
@@ -1068,16 +1062,10 @@ static __init int dma_debug_cmdline(char *str)
 
 static __init int dma_debug_entries_cmdline(char *str)
 {
-	int res;
-
 	if (!str)
 		return -EINVAL;
-
-	res = get_option(&str, &req_entries);
-
-	if (!res)
-		req_entries = 0;
-
+	if (!get_option(&str, &nr_prealloc_entries))
+		nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES;
 	return 0;
 }
 
Signature · 1 line
2.17.0
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] dma-debug: simplify counting of preallocated requests

Quoted 2 lines · Christoph Hellwig

Just keep a single variable with a descriptive name instead of two with confusing names.

Quoted 60 lines
---
  lib/dma-debug.c | 20 ++++----------------
  1 file changed, 4 insertions(+), 16 deletions(-)
lib/dma-debug.c +4 -16
index 712a897174e4..075253cb613b 100644
@@ -132,7 +132,7 @@ static u32 min_free_entries;
  static u32 nr_total_entries;
 
  /* number of preallocated entries requested by kernel cmdline */
-static u32 req_entries;
+static u32 nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES;
 
  /* debugfs dentry's for the stuff above */
  static struct dentry *dma_debug_dent        __read_mostly;
@@ -1011,7 +1011,6 @@ void dma_debug_add_bus(struct bus_type *bus)
 
  static int dma_debug_init(void)
  {
-	u32 num_entries;
  	int i;
 
  	/* Do not use dma_debug_initialized here, since we really want to be
@@ -1032,12 +1031,7 @@ static int dma_debug_init(void)
  		return 0;
  	}
 
-	if (req_entries)
-		num_entries = req_entries;
-	else
-		num_entries = PREALLOC_DMA_DEBUG_ENTRIES;
-
-	if (prealloc_memory(num_entries) != 0) {
+	if (prealloc_memory(nr_prealloc_entries) != 0) {
  		pr_err("DMA-API: debugging out of memory error - disabled\n");
  		global_disable = true;
 
@@ -1068,16 +1062,10 @@ static __init int dma_debug_cmdline(char *str)
 
  static __init int dma_debug_entries_cmdline(char *str)
  {
-	int res;
-
  	if (!str)
  		return -EINVAL;
-
-	res = get_option(&str, &req_entries);
-
-	if (!res)
-		req_entries = 0;
-
+	if (!get_option(&str, &nr_prealloc_entries))
+		nr_prealloc_entries = PREALLOC_DMA_DEBUG_ENTRIES;
  	return 0;
  }
 
#6 lore raw

PATCH 3/3 dma-debug: unexport dma_debug_resize_entries and debug_dma_dump_mappings

In reply to Christoph Hellwig

Only used by the AMD GART driver, which must be built in.

---
 lib/dma-debug.c | 2 --
 1 file changed, 2 deletions(-)
lib/dma-debug.c +0 -2
index 075253cb613b..6a1ebaa83623 100644
@@ -444,7 +444,6 @@ void debug_dma_dump_mappings(struct device *dev)
 		spin_unlock_irqrestore(&bucket->lock, flags);
 	}
 }
-EXPORT_SYMBOL(debug_dma_dump_mappings);
 
 /*
  * For each mapping (initial cacheline in the case of
@@ -753,7 +752,6 @@ int dma_debug_resize_entries(u32 num_entries)
 
 	return ret;
 }
-EXPORT_SYMBOL(dma_debug_resize_entries);
 
 /*
  * DMA-API debugging init code
Signature · 1 line
2.17.0
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] dma-debug: unexport dma_debug_resize_entries and debug_dma_dump_mappings

Quoted 1 line · Christoph Hellwig

Only used by the AMD GART driver, which must be built in.

FWIW debug_dma_dump_mappings() is also called by the Intel VT-d driver, but the same reasoning still applies. This does rather beg the question of whether it's right to have bits of low-level dma-debug internals *only* called by a couple of IOMMU drivers, but that can wait for another day.

Quoted 26 lines
---
  lib/dma-debug.c | 2 --
  1 file changed, 2 deletions(-)
lib/dma-debug.c +0 -2
index 075253cb613b..6a1ebaa83623 100644
@@ -444,7 +444,6 @@ void debug_dma_dump_mappings(struct device *dev)
  		spin_unlock_irqrestore(&bucket->lock, flags);
  	}
  }
-EXPORT_SYMBOL(debug_dma_dump_mappings);
 
  /*
   * For each mapping (initial cacheline in the case of
@@ -753,7 +752,6 @@ int dma_debug_resize_entries(u32 num_entries)
 
  	return ret;
  }
-EXPORT_SYMBOL(dma_debug_resize_entries);
 
  /*
   * DMA-API debugging init code
#8 lore raw

Re: [PATCH 3/3] dma-debug: unexport dma_debug_resize_entries and debug_dma_dump_mappings

Quoted 5 lines · Robin Murphy
Quoted 1 line · Christoph Hellwig

Only used by the AMD GART driver, which must be built in.

FWIW debug_dma_dump_mappings() is also called by the Intel VT-d driver, but the same reasoning still applies.

I'll update the changelog.

Quoted 3 lines

This does rather beg the question of
whether it's right to have bits of low-level dma-debug internals *only* called by a couple of IOMMU drivers, but that can wait for another day.

My gut feeling is that it is wrong, but I didn't have time to look into the details and history of how this happened.

#9 lore raw

[PATCH 4/3] dma-debug: remove CONFIG_HAVE_DMA_API_DEBUG

In reply to Christoph Hellwig

There is no arch specific code required for dma-debug, so there is no need to opt into the support either.

---
 .../io/dma-api-debug/arch-support.txt         | 31 -------------------
 arch/Kconfig                                  |  3 --
 arch/arm/Kconfig                              |  1 -
 arch/arm64/Kconfig                            |  1 -
 arch/c6x/Kconfig                              |  1 -
 arch/ia64/Kconfig                             |  1 -
 arch/microblaze/Kconfig                       |  1 -
 arch/mips/Kconfig                             |  1 -
 arch/powerpc/Kconfig                          |  1 -
 arch/riscv/Kconfig                            |  1 -
 arch/s390/Kconfig                             |  1 -
 arch/sh/Kconfig                               |  1 -
 arch/sparc/Kconfig                            |  1 -
 arch/x86/Kconfig                              |  1 -
 arch/xtensa/Kconfig                           |  1 -
 lib/Kconfig.debug                             |  1 -
 16 files changed, 48 deletions(-)
 delete mode 100644 Documentation/features/io/dma-api-debug/arch-support.txt
Documentation/features/io/dma-api-debug/arch-support.txt deleted +0 -31
deleted file mode 100644
index e438ed675623..000000000000
@@ -1,31 +0,0 @@
-#
-# Feature name:          dma-api-debug
-#         Kconfig:       HAVE_DMA_API_DEBUG
-#         description:   arch supports DMA debug facilities
-#
-    -----------------------
-    |         arch |status|
-    -----------------------
-    |       alpha: | TODO |
-    |         arc: | TODO |
-    |         arm: |  ok  |
-    |       arm64: |  ok  |
-    |         c6x: |  ok  |
-    |       h8300: | TODO |
-    |     hexagon: | TODO |
-    |        ia64: |  ok  |
-    |        m68k: | TODO |
-    |  microblaze: |  ok  |
-    |        mips: |  ok  |
-    |       nios2: | TODO |
-    |    openrisc: | TODO |
-    |      parisc: | TODO |
-    |     powerpc: |  ok  |
-    |        s390: |  ok  |
-    |          sh: |  ok  |
-    |       sparc: |  ok  |
-    |          um: | TODO |
-    |   unicore32: | TODO |
-    |         x86: |  ok  |
-    |      xtensa: |  ok  |
-    -----------------------
arch/Kconfig +0 -3
index 8e0d665c8d53..f07a1a99e5db 100644
@@ -278,9 +278,6 @@ config HAVE_CLK
 	  The <linux/clk.h> calls support software clock gating and
 	  thus are a key power management tool on many systems.
 
-config HAVE_DMA_API_DEBUG
-	bool
-
 config HAVE_HW_BREAKPOINT
 	bool
 	depends on PERF_EVENTS
arch/arm/Kconfig +0 -1
index 676977bdfe33..c43f5bb55ac8 100644
@@ -60,7 +60,6 @@ config ARM
 	select HAVE_CONTEXT_TRACKING
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS if MMU
 	select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU
 	select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
arch/arm64/Kconfig +0 -1
index db51b6445744..b25ed7834f6c 100644
@@ -105,7 +105,6 @@ config ARM64
 	select HAVE_CONTEXT_TRACKING
 	select HAVE_DEBUG_BUGVERBOSE
 	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS
arch/c6x/Kconfig +0 -1
index c6b4dd1418b4..8c088b96e372 100644
@@ -10,7 +10,6 @@ config C6X
 	select GENERIC_ATOMIC64
 	select GENERIC_IRQ_SHOW
 	select HAVE_ARCH_TRACEHOOK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_MEMBLOCK
 	select SPARSE_IRQ
 	select IRQ_DOMAIN
arch/ia64/Kconfig +0 -1
index 9485b5490eca..2067289fad4a 100644
@@ -29,7 +29,6 @@ config IA64
 	select HAVE_FUNCTION_TRACER
 	select TTY
 	select HAVE_ARCH_TRACEHOOK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_MEMBLOCK
 	select HAVE_MEMBLOCK_NODE_MAP
 	select HAVE_VIRT_CPU_ACCOUNTING
arch/microblaze/Kconfig +0 -1
index 3817a3e2146c..d14782100088 100644
@@ -19,7 +19,6 @@ config MICROBLAZE
 	select HAVE_ARCH_HASH
 	select HAVE_ARCH_KGDB
 	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_GRAPH_TRACER
arch/mips/Kconfig +0 -1
index 0f619b8c0e9e..2dcdc13cd65d 100644
@@ -42,7 +42,6 @@ config MIPS
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DEBUG_STACKOVERFLOW
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_EXIT_THREAD
arch/powerpc/Kconfig +0 -1
index 1887f8f86a77..268fd46fc3c7 100644
@@ -181,7 +181,6 @@ config PPC
 	select HAVE_CONTEXT_TRACKING		if PPC64
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DEBUG_STACKOVERFLOW
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_DYNAMIC_FTRACE_WITH_REGS	if MPROFILE_KERNEL
 	select HAVE_EBPF_JIT			if PPC64
arch/riscv/Kconfig +0 -1
index 17212ba54ee3..95e2da34aaad 100644
@@ -23,7 +23,6 @@ config RISCV
 	select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A
 	select HAVE_MEMBLOCK
 	select HAVE_MEMBLOCK_NODE_MAP
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_GENERIC_DMA_COHERENT
 	select IRQ_DOMAIN
arch/s390/Kconfig +0 -1
index b794a2ab6d15..6a64287ec1da 100644
@@ -130,7 +130,6 @@ config S390
 	select HAVE_CMPXCHG_LOCAL
 	select HAVE_COPY_THREAD_TLS
 	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
 	select DMA_DIRECT_OPS
 	select HAVE_DYNAMIC_FTRACE
arch/sh/Kconfig +0 -1
index 9417f70e008e..7d521926041e 100644
@@ -13,7 +13,6 @@ config SUPERH
 	select HAVE_OPROFILE
 	select HAVE_GENERIC_DMA_COHERENT
 	select HAVE_ARCH_TRACEHOOK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_PERF_EVENTS
 	select HAVE_DEBUG_BUGVERBOSE
 	select ARCH_HAVE_CUSTOM_GPIO_H
arch/sparc/Kconfig +0 -1
index c1cfc17eb504..435dbc033afe 100644
@@ -25,7 +25,6 @@ config SPARC
 	select RTC_CLASS
 	select RTC_DRV_M48T59
 	select RTC_SYSTOHC
-	select HAVE_DMA_API_DEBUG
 	select HAVE_ARCH_JUMP_LABEL if SPARC64
 	select GENERIC_IRQ_SHOW
 	select ARCH_WANT_IPC_PARSE_VERSION
arch/x86/Kconfig +0 -1
index aad35c568681..3eeca48a146b 100644
@@ -135,7 +135,6 @@ config X86
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DEBUG_STACKOVERFLOW
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_DYNAMIC_FTRACE_WITH_REGS
arch/xtensa/Kconfig +0 -1
index c921e8bccdc8..17df332269b2 100644
@@ -19,7 +19,6 @@ config XTENSA
 	select HAVE_ARCH_KASAN if MMU
 	select HAVE_CC_STACKPROTECTOR
 	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_EXIT_THREAD
 	select HAVE_FUNCTION_TRACER
lib/Kconfig.debug +0 -1
index 685ed2dd4384..d5175eb7b917 100644
@@ -1634,7 +1634,6 @@ config PROVIDE_OHCI1394_DMA_INIT
 
 config DMA_API_DEBUG
 	bool "Enable debugging of DMA-API usage"
-	depends on HAVE_DMA_API_DEBUG
 	select NEED_DMA_MAP_STATE
 	help
 	  Enable this option to debug the use of the DMA API by device drivers.
Signature · 1 line
2.17.0
Reviewed-by
#10 lore raw

Re: [PATCH 4/3] dma-debug: remove CONFIG_HAVE_DMA_API_DEBUG

Quoted 2 lines · Christoph Hellwig

There is no arch specific code required for dma-debug, so there is no need to opt into the support either.

Makes sense, and a purely negative diffstat is always pleasing :)

Quoted 241 lines
---
  .../io/dma-api-debug/arch-support.txt         | 31 -------------------
  arch/Kconfig                                  |  3 --
  arch/arm/Kconfig                              |  1 -
  arch/arm64/Kconfig                            |  1 -
  arch/c6x/Kconfig                              |  1 -
  arch/ia64/Kconfig                             |  1 -
  arch/microblaze/Kconfig                       |  1 -
  arch/mips/Kconfig                             |  1 -
  arch/powerpc/Kconfig                          |  1 -
  arch/riscv/Kconfig                            |  1 -
  arch/s390/Kconfig                             |  1 -
  arch/sh/Kconfig                               |  1 -
  arch/sparc/Kconfig                            |  1 -
  arch/x86/Kconfig                              |  1 -
  arch/xtensa/Kconfig                           |  1 -
  lib/Kconfig.debug                             |  1 -
  16 files changed, 48 deletions(-)

delete mode 100644 Documentation/features/io/dma-api-debug/arch-support.txt

Documentation/features/io/dma-api-debug/arch-support.txt deleted +0 -31
deleted file mode 100644
index e438ed675623..000000000000
@@ -1,31 +0,0 @@
-#
-# Feature name:          dma-api-debug
-#         Kconfig:       HAVE_DMA_API_DEBUG
-#         description:   arch supports DMA debug facilities
-#
-    -----------------------
-    |         arch |status|
-    -----------------------
-    |       alpha: | TODO |
-    |         arc: | TODO |
-    |         arm: |  ok  |
-    |       arm64: |  ok  |
-    |         c6x: |  ok  |
-    |       h8300: | TODO |
-    |     hexagon: | TODO |
-    |        ia64: |  ok  |
-    |        m68k: | TODO |
-    |  microblaze: |  ok  |
-    |        mips: |  ok  |
-    |       nios2: | TODO |
-    |    openrisc: | TODO |
-    |      parisc: | TODO |
-    |     powerpc: |  ok  |
-    |        s390: |  ok  |
-    |          sh: |  ok  |
-    |       sparc: |  ok  |
-    |          um: | TODO |
-    |   unicore32: | TODO |
-    |         x86: |  ok  |
-    |      xtensa: |  ok  |
-    -----------------------
arch/Kconfig +0 -3
index 8e0d665c8d53..f07a1a99e5db 100644
@@ -278,9 +278,6 @@ config HAVE_CLK
  	  The <linux/clk.h> calls support software clock gating and
  	  thus are a key power management tool on many systems.
 
-config HAVE_DMA_API_DEBUG
-	bool
-
  config HAVE_HW_BREAKPOINT
  	bool
  	depends on PERF_EVENTS
arch/arm/Kconfig +0 -1
index 676977bdfe33..c43f5bb55ac8 100644
@@ -60,7 +60,6 @@ config ARM
  	select HAVE_CONTEXT_TRACKING
  	select HAVE_C_RECORDMCOUNT
  	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DMA_CONTIGUOUS if MMU
  	select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU
  	select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
arch/arm64/Kconfig +0 -1
index db51b6445744..b25ed7834f6c 100644
@@ -105,7 +105,6 @@ config ARM64
  	select HAVE_CONTEXT_TRACKING
  	select HAVE_DEBUG_BUGVERBOSE
  	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DMA_CONTIGUOUS
  	select HAVE_DYNAMIC_FTRACE
  	select HAVE_EFFICIENT_UNALIGNED_ACCESS
arch/c6x/Kconfig +0 -1
index c6b4dd1418b4..8c088b96e372 100644
@@ -10,7 +10,6 @@ config C6X
  	select GENERIC_ATOMIC64
  	select GENERIC_IRQ_SHOW
  	select HAVE_ARCH_TRACEHOOK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_MEMBLOCK
  	select SPARSE_IRQ
  	select IRQ_DOMAIN
arch/ia64/Kconfig +0 -1
index 9485b5490eca..2067289fad4a 100644
@@ -29,7 +29,6 @@ config IA64
  	select HAVE_FUNCTION_TRACER
  	select TTY
  	select HAVE_ARCH_TRACEHOOK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_MEMBLOCK
  	select HAVE_MEMBLOCK_NODE_MAP
  	select HAVE_VIRT_CPU_ACCOUNTING
arch/microblaze/Kconfig +0 -1
index 3817a3e2146c..d14782100088 100644
@@ -19,7 +19,6 @@ config MICROBLAZE
  	select HAVE_ARCH_HASH
  	select HAVE_ARCH_KGDB
  	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DYNAMIC_FTRACE
  	select HAVE_FTRACE_MCOUNT_RECORD
  	select HAVE_FUNCTION_GRAPH_TRACER
arch/mips/Kconfig +0 -1
index 0f619b8c0e9e..2dcdc13cd65d 100644
@@ -42,7 +42,6 @@ config MIPS
  	select HAVE_C_RECORDMCOUNT
  	select HAVE_DEBUG_KMEMLEAK
  	select HAVE_DEBUG_STACKOVERFLOW
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DMA_CONTIGUOUS
  	select HAVE_DYNAMIC_FTRACE
  	select HAVE_EXIT_THREAD
arch/powerpc/Kconfig +0 -1
index 1887f8f86a77..268fd46fc3c7 100644
@@ -181,7 +181,6 @@ config PPC
  	select HAVE_CONTEXT_TRACKING		if PPC64
  	select HAVE_DEBUG_KMEMLEAK
  	select HAVE_DEBUG_STACKOVERFLOW
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DYNAMIC_FTRACE
  	select HAVE_DYNAMIC_FTRACE_WITH_REGS	if MPROFILE_KERNEL
  	select HAVE_EBPF_JIT			if PPC64
arch/riscv/Kconfig +0 -1
index 17212ba54ee3..95e2da34aaad 100644
@@ -23,7 +23,6 @@ config RISCV
  	select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A
  	select HAVE_MEMBLOCK
  	select HAVE_MEMBLOCK_NODE_MAP
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DMA_CONTIGUOUS
  	select HAVE_GENERIC_DMA_COHERENT
  	select IRQ_DOMAIN
arch/s390/Kconfig +0 -1
index b794a2ab6d15..6a64287ec1da 100644
@@ -130,7 +130,6 @@ config S390
  	select HAVE_CMPXCHG_LOCAL
  	select HAVE_COPY_THREAD_TLS
  	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DMA_CONTIGUOUS
  	select DMA_DIRECT_OPS
  	select HAVE_DYNAMIC_FTRACE
arch/sh/Kconfig +0 -1
index 9417f70e008e..7d521926041e 100644
@@ -13,7 +13,6 @@ config SUPERH
  	select HAVE_OPROFILE
  	select HAVE_GENERIC_DMA_COHERENT
  	select HAVE_ARCH_TRACEHOOK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_PERF_EVENTS
  	select HAVE_DEBUG_BUGVERBOSE
  	select ARCH_HAVE_CUSTOM_GPIO_H
arch/sparc/Kconfig +0 -1
index c1cfc17eb504..435dbc033afe 100644
@@ -25,7 +25,6 @@ config SPARC
  	select RTC_CLASS
  	select RTC_DRV_M48T59
  	select RTC_SYSTOHC
-	select HAVE_DMA_API_DEBUG
  	select HAVE_ARCH_JUMP_LABEL if SPARC64
  	select GENERIC_IRQ_SHOW
  	select ARCH_WANT_IPC_PARSE_VERSION
arch/x86/Kconfig +0 -1
index aad35c568681..3eeca48a146b 100644
@@ -135,7 +135,6 @@ config X86
  	select HAVE_C_RECORDMCOUNT
  	select HAVE_DEBUG_KMEMLEAK
  	select HAVE_DEBUG_STACKOVERFLOW
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DMA_CONTIGUOUS
  	select HAVE_DYNAMIC_FTRACE
  	select HAVE_DYNAMIC_FTRACE_WITH_REGS
arch/xtensa/Kconfig +0 -1
index c921e8bccdc8..17df332269b2 100644
@@ -19,7 +19,6 @@ config XTENSA
  	select HAVE_ARCH_KASAN if MMU
  	select HAVE_CC_STACKPROTECTOR
  	select HAVE_DEBUG_KMEMLEAK
-	select HAVE_DMA_API_DEBUG
  	select HAVE_DMA_CONTIGUOUS
  	select HAVE_EXIT_THREAD
  	select HAVE_FUNCTION_TRACER
lib/Kconfig.debug +0 -1
index 685ed2dd4384..d5175eb7b917 100644
@@ -1634,7 +1634,6 @@ config PROVIDE_OHCI1394_DMA_INIT
 
  config DMA_API_DEBUG
  	bool "Enable debugging of DMA-API usage"
-	depends on HAVE_DMA_API_DEBUG
  	select NEED_DMA_MAP_STATE
  	help
  	  Enable this option to debug the use of the DMA API by device drivers.
#11 lore raw
In reply to Christoph Hellwig

Any comments? I'd like to move forward with this rather sooner than later, so any reviews welcome!

Quoted 8 lines · Christoph Hellwig

Hi all,

this series has a few dma-debug cleanups, most notably removing the need for architectures to explicitly initialize dma-debug.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

---end quoted text---