Skip to content

Commit

Permalink
dma-debug: add dumping facility via debugfs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
montjoie authored and Christoph Hellwig committed Feb 1, 2019
1 parent 8e4d81b commit 0a3b192
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Documentation/DMA-API.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
28 changes: 28 additions & 0 deletions kernel/dma/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit 0a3b192

Please sign in to comment.