Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 138931
b: refs/heads/master
c: 6c132d1
h: refs/heads/master
i:
  138929: 0228c87
  138927: 74b850c
v: v3
  • Loading branch information
David Woodhouse authored and Joerg Roedel committed Mar 17, 2009
1 parent 388e73b commit d277e39
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 187f9c3f05373df4f7cbae2e656450acdbba7558
refs/heads/master: 6c132d1bcdc716e898b4092bb1abc696505c37e7
52 changes: 38 additions & 14 deletions trunk/lib/dma-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <linux/scatterlist.h>
#include <linux/dma-mapping.h>
#include <linux/stacktrace.h>
#include <linux/dma-debug.h>
#include <linux/spinlock.h>
#include <linux/debugfs.h>
Expand All @@ -39,6 +40,8 @@ enum {
dma_debug_coherent,
};

#define DMA_DEBUG_STACKTRACE_ENTRIES 5

struct dma_debug_entry {
struct list_head list;
struct device *dev;
Expand All @@ -49,6 +52,10 @@ struct dma_debug_entry {
int direction;
int sg_call_ents;
int sg_mapped_ents;
#ifdef CONFIG_STACKTRACE
struct stack_trace stacktrace;
unsigned long st_entries[DMA_DEBUG_STACKTRACE_ENTRIES];
#endif
};

struct hash_bucket {
Expand Down Expand Up @@ -108,12 +115,23 @@ static const char *dir2name[4] = { "DMA_BIDIRECTIONAL", "DMA_TO_DEVICE",
* system log than the user configured. This variable is
* writeable via debugfs.
*/
#define err_printk(dev, format, arg...) do { \
static inline void dump_entry_trace(struct dma_debug_entry *entry)
{
#ifdef CONFIG_STACKTRACE
if (entry) {
printk(KERN_WARNING "Mapped at:\n");
print_stack_trace(&entry->stacktrace, 0);
}
#endif
}

#define err_printk(dev, entry, format, arg...) do { \
error_count += 1; \
if (show_all_errors || show_num_errors > 0) { \
WARN(1, "%s %s: " format, \
dev_driver_string(dev), \
dev_name(dev) , ## arg); \
dump_entry_trace(entry); \
} \
if (!show_all_errors && show_num_errors > 0) \
show_num_errors -= 1; \
Expand Down Expand Up @@ -260,6 +278,12 @@ static struct dma_debug_entry *dma_entry_alloc(void)
list_del(&entry->list);
memset(entry, 0, sizeof(*entry));

#ifdef CONFIG_STACKTRACE
entry->stacktrace.max_entries = DMA_DEBUG_STACKTRACE_ENTRIES;
entry->stacktrace.entries = entry->st_entries;
entry->stacktrace.skip = 2;
save_stack_trace(&entry->stacktrace);
#endif
num_free_entries -= 1;
if (num_free_entries < min_free_entries)
min_free_entries = num_free_entries;
Expand Down Expand Up @@ -457,31 +481,31 @@ static void check_unmap(struct dma_debug_entry *ref)
entry = hash_bucket_find(bucket, ref);

if (!entry) {
err_printk(ref->dev, "DMA-API: device driver tries "
err_printk(ref->dev, NULL, "DMA-API: device driver tries "
"to free DMA memory it has not allocated "
"[device address=0x%016llx] [size=%llu bytes]\n",
ref->dev_addr, ref->size);
goto out;
}

if (ref->size != entry->size) {
err_printk(ref->dev, "DMA-API: device driver frees "
err_printk(ref->dev, entry, "DMA-API: device driver frees "
"DMA memory with different size "
"[device address=0x%016llx] [map size=%llu bytes] "
"[unmap size=%llu bytes]\n",
ref->dev_addr, entry->size, ref->size);
}

if (ref->type != entry->type) {
err_printk(ref->dev, "DMA-API: device driver frees "
err_printk(ref->dev, entry, "DMA-API: device driver frees "
"DMA memory with wrong function "
"[device address=0x%016llx] [size=%llu bytes] "
"[mapped as %s] [unmapped as %s]\n",
ref->dev_addr, ref->size,
type2name[entry->type], type2name[ref->type]);
} else if ((entry->type == dma_debug_coherent) &&
(ref->paddr != entry->paddr)) {
err_printk(ref->dev, "DMA-API: device driver frees "
err_printk(ref->dev, entry, "DMA-API: device driver frees "
"DMA memory with different CPU address "
"[device address=0x%016llx] [size=%llu bytes] "
"[cpu alloc address=%p] [cpu free address=%p]",
Expand All @@ -491,7 +515,7 @@ static void check_unmap(struct dma_debug_entry *ref)

if (ref->sg_call_ents && ref->type == dma_debug_sg &&
ref->sg_call_ents != entry->sg_call_ents) {
err_printk(ref->dev, "DMA-API: device driver frees "
err_printk(ref->dev, entry, "DMA-API: device driver frees "
"DMA sg list with different entry count "
"[map count=%d] [unmap count=%d]\n",
entry->sg_call_ents, ref->sg_call_ents);
Expand All @@ -502,7 +526,7 @@ static void check_unmap(struct dma_debug_entry *ref)
* DMA API don't handle this properly, so check for it here
*/
if (ref->direction != entry->direction) {
err_printk(ref->dev, "DMA-API: device driver frees "
err_printk(ref->dev, entry, "DMA-API: device driver frees "
"DMA memory with different direction "
"[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [unmapped with %s]\n",
Expand All @@ -521,8 +545,8 @@ static void check_unmap(struct dma_debug_entry *ref)
static void check_for_stack(struct device *dev, void *addr)
{
if (object_is_on_stack(addr))
err_printk(dev, "DMA-API: device driver maps memory from stack"
" [addr=%p]\n", addr);
err_printk(dev, NULL, "DMA-API: device driver maps memory from"
"stack [addr=%p]\n", addr);
}

static void check_sync(struct device *dev, dma_addr_t addr,
Expand All @@ -543,15 +567,15 @@ static void check_sync(struct device *dev, dma_addr_t addr,
entry = hash_bucket_find(bucket, &ref);

if (!entry) {
err_printk(dev, "DMA-API: device driver tries "
err_printk(dev, NULL, "DMA-API: device driver tries "
"to sync DMA memory it has not allocated "
"[device address=0x%016llx] [size=%llu bytes]\n",
addr, size);
goto out;
}

if ((offset + size) > entry->size) {
err_printk(dev, "DMA-API: device driver syncs"
err_printk(dev, entry, "DMA-API: device driver syncs"
" DMA memory outside allocated range "
"[device address=0x%016llx] "
"[allocation size=%llu bytes] [sync offset=%llu] "
Expand All @@ -560,7 +584,7 @@ static void check_sync(struct device *dev, dma_addr_t addr,
}

if (direction != entry->direction) {
err_printk(dev, "DMA-API: device driver syncs "
err_printk(dev, entry, "DMA-API: device driver syncs "
"DMA memory with different direction "
"[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [synced with %s]\n",
Expand All @@ -574,7 +598,7 @@ static void check_sync(struct device *dev, dma_addr_t addr,

if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) &&
!(direction == DMA_TO_DEVICE))
err_printk(dev, "DMA-API: device driver syncs "
err_printk(dev, entry, "DMA-API: device driver syncs "
"device read-only DMA memory for cpu "
"[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [synced with %s]\n",
Expand All @@ -584,7 +608,7 @@ static void check_sync(struct device *dev, dma_addr_t addr,

if (!to_cpu && !(entry->direction == DMA_TO_DEVICE) &&
!(direction == DMA_FROM_DEVICE))
err_printk(dev, "DMA-API: device driver syncs "
err_printk(dev, entry, "DMA-API: device driver syncs "
"device write-only DMA memory to device "
"[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [synced with %s]\n",
Expand Down

0 comments on commit d277e39

Please sign in to comment.