hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/kernel/dma/debug.c
....@@ -606,15 +606,19 @@
606606 return entry;
607607 }
608608
609
-static void __dma_entry_alloc_check_leak(void)
609
+/*
610
+ * This should be called outside of free_entries_lock scope to avoid potential
611
+ * deadlocks with serial consoles that use DMA.
612
+ */
613
+static void __dma_entry_alloc_check_leak(u32 nr_entries)
610614 {
611
- u32 tmp = nr_total_entries % nr_prealloc_entries;
615
+ u32 tmp = nr_entries % nr_prealloc_entries;
612616
613617 /* Shout each time we tick over some multiple of the initial pool */
614618 if (tmp < DMA_DEBUG_DYNAMIC_ENTRIES) {
615619 pr_info("dma_debug_entry pool grown to %u (%u00%%)\n",
616
- nr_total_entries,
617
- (nr_total_entries / nr_prealloc_entries));
620
+ nr_entries,
621
+ (nr_entries / nr_prealloc_entries));
618622 }
619623 }
620624
....@@ -625,8 +629,10 @@
625629 */
626630 static struct dma_debug_entry *dma_entry_alloc(void)
627631 {
632
+ bool alloc_check_leak = false;
628633 struct dma_debug_entry *entry;
629634 unsigned long flags;
635
+ u32 nr_entries;
630636
631637 spin_lock_irqsave(&free_entries_lock, flags);
632638 if (num_free_entries == 0) {
....@@ -636,13 +642,17 @@
636642 pr_err("debugging out of memory - disabling\n");
637643 return NULL;
638644 }
639
- __dma_entry_alloc_check_leak();
645
+ alloc_check_leak = true;
646
+ nr_entries = nr_total_entries;
640647 }
641648
642649 entry = __dma_entry_alloc();
643650
644651 spin_unlock_irqrestore(&free_entries_lock, flags);
645652
653
+ if (alloc_check_leak)
654
+ __dma_entry_alloc_check_leak(nr_entries);
655
+
646656 #ifdef CONFIG_STACKTRACE
647657 entry->stack_len = stack_trace_save(entry->stack_entries,
648658 ARRAY_SIZE(entry->stack_entries),