dma-debug: add dumping facility via debugfs
authorCorentin Labbe <clabbe@baylibre.com>
Fri, 18 Jan 2019 13:44:18 +0000 (13:44 +0000)
committerChristoph Hellwig <hch@lst.de>
Fri, 1 Feb 2019 09:06:44 +0000 (10:06 +0100)
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>
Documentation/DMA-API.txt
kernel/dma/debug.c

index e133ccd..78114ee 100644 (file)
@@ -696,6 +696,9 @@ dma-api/disabled            This read-only file contains the character 'Y'
                                happen when it runs out of memory or if it was
                                disabled at boot time
 
+dma-api/dump                   This read-only file contains current DMA
+                               mappings.
+
 dma-api/error_count            This file is read-only and shows the total
                                numbers of errors found.
 
index 56cd836..45d51e8 100644 (file)
@@ -829,6 +829,33 @@ static const struct file_operations filter_fops = {
        .llseek = default_llseek,
 };
 
+static int dump_show(struct seq_file *seq, void *v)
+{
+       int idx;
+
+       for (idx = 0; idx < HASH_SIZE; idx++) {
+               struct hash_bucket *bucket = &dma_entry_hash[idx];
+               struct dma_debug_entry *entry;
+               unsigned long flags;
+
+               spin_lock_irqsave(&bucket->lock, flags);
+               list_for_each_entry(entry, &bucket->list, list) {
+                       seq_printf(seq,
+                                  "%s %s %s idx %d P=%llx N=%lx D=%llx L=%llx %s %s\n",
+                                  dev_name(entry->dev),
+                                  dev_driver_string(entry->dev),
+                                  type2name[entry->type], idx,
+                                  phys_addr(entry), entry->pfn,
+                                  entry->dev_addr, entry->size,
+                                  dir2name[entry->direction],
+                                  maperr2str[entry->map_err_type]);
+               }
+               spin_unlock_irqrestore(&bucket->lock, flags);
+       }
+       return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(dump);
+
 static void dma_debug_fs_init(void)
 {
        struct dentry *dentry = debugfs_create_dir("dma-api", NULL);
@@ -841,6 +868,7 @@ static void dma_debug_fs_init(void)
        debugfs_create_u32("min_free_entries", 0444, dentry, &min_free_entries);
        debugfs_create_u32("nr_total_entries", 0444, dentry, &nr_total_entries);
        debugfs_create_file("driver_filter", 0644, dentry, NULL, &filter_fops);
+       debugfs_create_file("dump", 0444, dentry, NULL, &dump_fops);
 }
 
 static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry)