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

dma-debug: Make leak-like behaviour apparent

Now that we can dynamically allocate DMA debug entries to cope with
drivers maintaining excessively large numbers of live mappings, a driver
which *does* actually have a bug leaking mappings (and is not unloaded)
will no longer trigger the "DMA-API: debugging out of memory - disabling"
message until it gets to actual kernel OOM conditions, which means it
could go unnoticed for a while. To that end, let's inform the user each
time the pool has grown to a multiple of its initial size, which should
make it apparent that they either have a leak or might want to increase
the preallocation size.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Tested-by: Qian Cai <cai@lca.pw>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Robin Murphy and committed by
Christoph Hellwig
ceb51173 2b9d9ac0

+18 -1
+5 -1
Documentation/DMA-API.txt
··· 747 747 When the code disables itself at runtime this is most likely because it ran 748 748 out of dma_debug_entries and was unable to allocate more on-demand. 65536 749 749 entries are preallocated at boot - if this is too low for you boot with 750 - 'dma_debug_entries=<your_desired_number>' to overwrite the default. 750 + 'dma_debug_entries=<your_desired_number>' to overwrite the default. The 751 + code will print to the kernel log each time it has dynamically allocated 752 + as many entries as were initially preallocated. This is to indicate that a 753 + larger preallocation size may be appropriate, or if it happens continually 754 + that a driver may be leaking mappings. 751 755 752 756 :: 753 757
+13
kernel/dma/debug.c
··· 691 691 return entry; 692 692 } 693 693 694 + void __dma_entry_alloc_check_leak(void) 695 + { 696 + u32 tmp = nr_total_entries % nr_prealloc_entries; 697 + 698 + /* Shout each time we tick over some multiple of the initial pool */ 699 + if (tmp < DMA_DEBUG_DYNAMIC_ENTRIES) { 700 + pr_info("dma_debug_entry pool grown to %u (%u00%%)\n", 701 + nr_total_entries, 702 + (nr_total_entries / nr_prealloc_entries)); 703 + } 704 + } 705 + 694 706 /* struct dma_entry allocator 695 707 * 696 708 * The next two functions implement the allocator for ··· 722 710 pr_err("debugging out of memory - disabling\n"); 723 711 return NULL; 724 712 } 713 + __dma_entry_alloc_check_leak(); 725 714 } 726 715 727 716 entry = __dma_entry_alloc();