Skip to content

Commit 474197a

Browse files
committed
Merge tag 'dma-mapping-6.6-2023-09-09' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping fixes from Christoph Hellwig: - move a dma-debug call that prints a message out from a lock that's causing problems with the lock order in serial drivers (Sergey Senozhatsky) - fix the CONFIG_DMA_NUMA_CMA Kconfig entry to have the right dependency and not default to y (Christoph Hellwig) - move an ifdef a bit to remove a __maybe_unused that seems to trip up some sensitivities (Christoph Hellwig) - revert a bogus check in the CMA allocator (Zhenhua Huang) * tag 'dma-mapping-6.6-2023-09-09' of git://git.infradead.org/users/hch/dma-mapping: Revert "dma-contiguous: check for memory region overlap" dma-pool: remove a __maybe_unused label in atomic_pool_expand dma-contiguous: fix the Kconfig entry for CONFIG_DMA_NUMA_CMA dma-debug: don't call __dma_entry_alloc_check_leak() under free_entries_lock
2 parents 060249b + f875db4 commit 474197a

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

kernel/dma/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ if DMA_CMA
160160

161161
config DMA_NUMA_CMA
162162
bool "Enable separate DMA Contiguous Memory Area for NUMA Node"
163-
default NUMA
163+
depends on NUMA
164164
help
165165
Enable this option to get numa CMA areas so that NUMA devices
166166
can get local memory by DMA coherent APIs.

kernel/dma/contiguous.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,6 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
473473
return -EBUSY;
474474
}
475475

476-
if (memblock_is_region_reserved(rmem->base, rmem->size)) {
477-
pr_info("Reserved memory: overlap with other memblock reserved region\n");
478-
return -EBUSY;
479-
}
480-
481476
if (!of_get_flat_dt_prop(node, "reusable", NULL) ||
482477
of_get_flat_dt_prop(node, "no-map", NULL))
483478
return -EINVAL;

kernel/dma/debug.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,19 @@ static struct dma_debug_entry *__dma_entry_alloc(void)
637637
return entry;
638638
}
639639

640-
static void __dma_entry_alloc_check_leak(void)
640+
/*
641+
* This should be called outside of free_entries_lock scope to avoid potential
642+
* deadlocks with serial consoles that use DMA.
643+
*/
644+
static void __dma_entry_alloc_check_leak(u32 nr_entries)
641645
{
642-
u32 tmp = nr_total_entries % nr_prealloc_entries;
646+
u32 tmp = nr_entries % nr_prealloc_entries;
643647

644648
/* Shout each time we tick over some multiple of the initial pool */
645649
if (tmp < DMA_DEBUG_DYNAMIC_ENTRIES) {
646650
pr_info("dma_debug_entry pool grown to %u (%u00%%)\n",
647-
nr_total_entries,
648-
(nr_total_entries / nr_prealloc_entries));
651+
nr_entries,
652+
(nr_entries / nr_prealloc_entries));
649653
}
650654
}
651655

@@ -656,8 +660,10 @@ static void __dma_entry_alloc_check_leak(void)
656660
*/
657661
static struct dma_debug_entry *dma_entry_alloc(void)
658662
{
663+
bool alloc_check_leak = false;
659664
struct dma_debug_entry *entry;
660665
unsigned long flags;
666+
u32 nr_entries;
661667

662668
spin_lock_irqsave(&free_entries_lock, flags);
663669
if (num_free_entries == 0) {
@@ -667,13 +673,17 @@ static struct dma_debug_entry *dma_entry_alloc(void)
667673
pr_err("debugging out of memory - disabling\n");
668674
return NULL;
669675
}
670-
__dma_entry_alloc_check_leak();
676+
alloc_check_leak = true;
677+
nr_entries = nr_total_entries;
671678
}
672679

673680
entry = __dma_entry_alloc();
674681

675682
spin_unlock_irqrestore(&free_entries_lock, flags);
676683

684+
if (alloc_check_leak)
685+
__dma_entry_alloc_check_leak(nr_entries);
686+
677687
#ifdef CONFIG_STACKTRACE
678688
entry->stack_len = stack_trace_save(entry->stack_entries,
679689
ARRAY_SIZE(entry->stack_entries),

kernel/dma/pool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size,
135135
remove_mapping:
136136
#ifdef CONFIG_DMA_DIRECT_REMAP
137137
dma_common_free_remap(addr, pool_size);
138-
#endif
139-
free_page: __maybe_unused
138+
free_page:
140139
__free_pages(page, order);
140+
#endif
141141
out:
142142
return ret;
143143
}

0 commit comments

Comments
 (0)