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

dma-debug: add dumping facility via debugfs

While debugging a DMA mapping leak, I needed to access
debug_dma_dump_mappings() but easily from user space.

This patch adds a /sys/kernel/debug/dma-api/dump file which contain all
current DMA mapping.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Corentin Labbe and committed by
Christoph Hellwig
0a3b192c 8e4d81b9

+31
+3
Documentation/DMA-API.txt
··· 696 696 happen when it runs out of memory or if it was 697 697 disabled at boot time 698 698 699 + dma-api/dump This read-only file contains current DMA 700 + mappings. 701 + 699 702 dma-api/error_count This file is read-only and shows the total 700 703 numbers of errors found. 701 704
+28
kernel/dma/debug.c
··· 829 829 .llseek = default_llseek, 830 830 }; 831 831 832 + static int dump_show(struct seq_file *seq, void *v) 833 + { 834 + int idx; 835 + 836 + for (idx = 0; idx < HASH_SIZE; idx++) { 837 + struct hash_bucket *bucket = &dma_entry_hash[idx]; 838 + struct dma_debug_entry *entry; 839 + unsigned long flags; 840 + 841 + spin_lock_irqsave(&bucket->lock, flags); 842 + list_for_each_entry(entry, &bucket->list, list) { 843 + seq_printf(seq, 844 + "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx %s %s\n", 845 + dev_name(entry->dev), 846 + dev_driver_string(entry->dev), 847 + type2name[entry->type], idx, 848 + phys_addr(entry), entry->pfn, 849 + entry->dev_addr, entry->size, 850 + dir2name[entry->direction], 851 + maperr2str[entry->map_err_type]); 852 + } 853 + spin_unlock_irqrestore(&bucket->lock, flags); 854 + } 855 + return 0; 856 + } 857 + DEFINE_SHOW_ATTRIBUTE(dump); 858 + 832 859 static void dma_debug_fs_init(void) 833 860 { 834 861 struct dentry *dentry = debugfs_create_dir("dma-api", NULL); ··· 868 841 debugfs_create_u32("min_free_entries", 0444, dentry, &min_free_entries); 869 842 debugfs_create_u32("nr_total_entries", 0444, dentry, &nr_total_entries); 870 843 debugfs_create_file("driver_filter", 0644, dentry, NULL, &filter_fops); 844 + debugfs_create_file("dump", 0444, dentry, NULL, &dump_fops); 871 845 } 872 846 873 847 static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry)