Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>

+14 -143
-9
arch/arm/mm/dma-mapping-nommu.c
··· 241 241 void arch_teardown_dma_ops(struct device *dev) 242 242 { 243 243 } 244 - 245 - #define PREALLOC_DMA_DEBUG_ENTRIES 4096 246 - 247 - static int __init dma_debug_do_init(void) 248 - { 249 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 250 - return 0; 251 - } 252 - core_initcall(dma_debug_do_init);
-9
arch/arm/mm/dma-mapping.c
··· 1165 1165 return __dma_supported(dev, mask, false); 1166 1166 } 1167 1167 1168 - #define PREALLOC_DMA_DEBUG_ENTRIES 4096 1169 - 1170 - static int __init dma_debug_do_init(void) 1171 - { 1172 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 1173 - return 0; 1174 - } 1175 - core_initcall(dma_debug_do_init); 1176 - 1177 1168 #ifdef CONFIG_ARM_DMA_USE_IOMMU 1178 1169 1179 1170 static int __dma_info_to_prot(enum dma_data_direction dir, unsigned long attrs)
-10
arch/arm64/mm/dma-mapping.c
··· 508 508 } 509 509 arch_initcall(arm64_dma_init); 510 510 511 - #define PREALLOC_DMA_DEBUG_ENTRIES 4096 512 - 513 - static int __init dma_debug_do_init(void) 514 - { 515 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 516 - return 0; 517 - } 518 - fs_initcall(dma_debug_do_init); 519 - 520 - 521 511 #ifdef CONFIG_IOMMU_DMA 522 512 #include <linux/dma-iommu.h> 523 513 #include <linux/platform_device.h>
-11
arch/c6x/kernel/dma.c
··· 136 136 .sync_sg_for_cpu = c6x_dma_sync_sg_for_cpu, 137 137 }; 138 138 EXPORT_SYMBOL(c6x_dma_ops); 139 - 140 - /* Number of entries preallocated for DMA-API debugging */ 141 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 142 - 143 - static int __init dma_init(void) 144 - { 145 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 146 - 147 - return 0; 148 - } 149 - fs_initcall(dma_init);
-10
arch/ia64/kernel/dma-mapping.c
··· 9 9 const struct dma_map_ops *dma_ops; 10 10 EXPORT_SYMBOL(dma_ops); 11 11 12 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 13 - 14 - static int __init dma_init(void) 15 - { 16 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 17 - 18 - return 0; 19 - } 20 - fs_initcall(dma_init); 21 - 22 12 const struct dma_map_ops *dma_get_ops(struct device *dev) 23 13 { 24 14 return dma_ops;
-11
arch/microblaze/kernel/dma.c
··· 184 184 .sync_sg_for_device = dma_nommu_sync_sg_for_device, 185 185 }; 186 186 EXPORT_SYMBOL(dma_nommu_ops); 187 - 188 - /* Number of entries preallocated for DMA-API debugging */ 189 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 190 - 191 - static int __init dma_init(void) 192 - { 193 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 194 - 195 - return 0; 196 - } 197 - fs_initcall(dma_init);
-10
arch/mips/mm/dma-default.c
··· 402 402 403 403 const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops; 404 404 EXPORT_SYMBOL(mips_dma_map_ops); 405 - 406 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 407 - 408 - static int __init mips_dma_init(void) 409 - { 410 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 411 - 412 - return 0; 413 - } 414 - fs_initcall(mips_dma_init);
-11
arch/openrisc/kernel/dma.c
··· 247 247 .sync_single_for_device = or1k_sync_single_for_device, 248 248 }; 249 249 EXPORT_SYMBOL(or1k_dma_map_ops); 250 - 251 - /* Number of entries preallocated for DMA-API debugging */ 252 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 253 - 254 - static int __init dma_init(void) 255 - { 256 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 257 - 258 - return 0; 259 - } 260 - fs_initcall(dma_init);
-3
arch/powerpc/kernel/dma.c
··· 309 309 } 310 310 EXPORT_SYMBOL(dma_set_coherent_mask); 311 311 312 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 313 - 314 312 int dma_set_mask(struct device *dev, u64 dma_mask) 315 313 { 316 314 if (ppc_md.dma_set_mask) ··· 359 361 360 362 static int __init dma_init(void) 361 363 { 362 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 363 364 #ifdef CONFIG_PCI 364 365 dma_debug_add_bus(&pci_bus_type); 365 366 #endif
-9
arch/s390/pci/pci_dma.c
··· 668 668 kmem_cache_destroy(dma_region_table_cache); 669 669 } 670 670 671 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 672 - 673 - static int __init dma_debug_do_init(void) 674 - { 675 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 676 - return 0; 677 - } 678 - fs_initcall(dma_debug_do_init); 679 - 680 671 const struct dma_map_ops s390_pci_dma_ops = { 681 672 .alloc = s390_dma_alloc, 682 673 .free = s390_dma_free,
-9
arch/sh/mm/consistent.c
··· 20 20 #include <asm/cacheflush.h> 21 21 #include <asm/addrspace.h> 22 22 23 - #define PREALLOC_DMA_DEBUG_ENTRIES 4096 24 - 25 23 const struct dma_map_ops *dma_ops; 26 24 EXPORT_SYMBOL(dma_ops); 27 - 28 - static int __init dma_init(void) 29 - { 30 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 31 - return 0; 32 - } 33 - fs_initcall(dma_init); 34 25 35 26 void *dma_generic_alloc_coherent(struct device *dev, size_t size, 36 27 dma_addr_t *dma_handle, gfp_t gfp,
-2
arch/sparc/kernel/Makefile
··· 74 74 obj-$(CONFIG_SPARC64) += nmi.o 75 75 obj-$(CONFIG_SPARC64_SMP) += cpumap.o 76 76 77 - obj-y += dma.o 78 - 79 77 obj-$(CONFIG_PCIC_PCI) += pcic.o 80 78 obj-$(CONFIG_LEON_PCI) += leon_pci.o 81 79 obj-$(CONFIG_SPARC_GRPCI2)+= leon_pci_grpci2.o
-13
arch/sparc/kernel/dma.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - #include <linux/kernel.h> 3 - #include <linux/dma-mapping.h> 4 - #include <linux/dma-debug.h> 5 - 6 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 15) 7 - 8 - static int __init dma_init(void) 9 - { 10 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 11 - return 0; 12 - } 13 - fs_initcall(dma_init);
-4
arch/x86/kernel/pci-dma.c
··· 55 55 }; 56 56 EXPORT_SYMBOL(x86_dma_fallback_dev); 57 57 58 - /* Number of entries preallocated for DMA-API debugging */ 59 - #define PREALLOC_DMA_DEBUG_ENTRIES 65536 60 - 61 58 void __init pci_iommu_alloc(void) 62 59 { 63 60 struct iommu_table_entry *p; ··· 186 189 static int __init pci_iommu_init(void) 187 190 { 188 191 struct iommu_table_entry *p; 189 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 190 192 191 193 #ifdef CONFIG_PCI 192 194 dma_debug_add_bus(&pci_bus_type);
-9
arch/xtensa/kernel/pci-dma.c
··· 261 261 .mapping_error = xtensa_dma_mapping_error, 262 262 }; 263 263 EXPORT_SYMBOL(xtensa_dma_map_ops); 264 - 265 - #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 266 - 267 - static int __init xtensa_dma_init(void) 268 - { 269 - dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); 270 - return 0; 271 - } 272 - fs_initcall(xtensa_dma_init);
-6
include/linux/dma-debug.h
··· 30 30 31 31 extern void dma_debug_add_bus(struct bus_type *bus); 32 32 33 - extern void dma_debug_init(u32 num_entries); 34 - 35 33 extern int dma_debug_resize_entries(u32 num_entries); 36 34 37 35 extern void debug_dma_map_page(struct device *dev, struct page *page, ··· 95 97 #else /* CONFIG_DMA_API_DEBUG */ 96 98 97 99 static inline void dma_debug_add_bus(struct bus_type *bus) 98 - { 99 - } 100 - 101 - static inline void dma_debug_init(u32 num_entries) 102 100 { 103 101 } 104 102
+14 -7
lib/dma-debug.c
··· 41 41 #define HASH_FN_SHIFT 13 42 42 #define HASH_FN_MASK (HASH_SIZE - 1) 43 43 44 + /* allow architectures to override this if absolutely required */ 45 + #ifndef PREALLOC_DMA_DEBUG_ENTRIES 46 + #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16) 47 + #endif 48 + 44 49 enum { 45 50 dma_debug_single, 46 51 dma_debug_page, ··· 1009 1004 bus_register_notifier(bus, nb); 1010 1005 } 1011 1006 1012 - /* 1013 - * Let the architectures decide how many entries should be preallocated. 1014 - */ 1015 - void dma_debug_init(u32 num_entries) 1007 + static int dma_debug_init(void) 1016 1008 { 1009 + u32 num_entries; 1017 1010 int i; 1018 1011 1019 1012 /* Do not use dma_debug_initialized here, since we really want to be 1020 1013 * called to set dma_debug_initialized 1021 1014 */ 1022 1015 if (global_disable) 1023 - return; 1016 + return 0; 1024 1017 1025 1018 for (i = 0; i < HASH_SIZE; ++i) { 1026 1019 INIT_LIST_HEAD(&dma_entry_hash[i].list); ··· 1029 1026 pr_err("DMA-API: error creating debugfs entries - disabling\n"); 1030 1027 global_disable = true; 1031 1028 1032 - return; 1029 + return 0; 1033 1030 } 1034 1031 1035 1032 if (req_entries) 1036 1033 num_entries = req_entries; 1034 + else 1035 + num_entries = PREALLOC_DMA_DEBUG_ENTRIES; 1037 1036 1038 1037 if (prealloc_memory(num_entries) != 0) { 1039 1038 pr_err("DMA-API: debugging out of memory error - disabled\n"); 1040 1039 global_disable = true; 1041 1040 1042 - return; 1041 + return 0; 1043 1042 } 1044 1043 1045 1044 nr_total_entries = num_free_entries; ··· 1049 1044 dma_debug_initialized = true; 1050 1045 1051 1046 pr_info("DMA-API: debugging enabled by kernel config\n"); 1047 + return 0; 1052 1048 } 1049 + core_initcall(dma_debug_init); 1053 1050 1054 1051 static __init int dma_debug_cmdline(char *str) 1055 1052 {