aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dma-debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dma-debug.c')
-rw-r--r--lib/dma-debug.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index fcfa1939ac41..06f02f6aecd2 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -22,6 +22,7 @@
22#include <linux/stacktrace.h> 22#include <linux/stacktrace.h>
23#include <linux/dma-debug.h> 23#include <linux/dma-debug.h>
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/vmalloc.h>
25#include <linux/debugfs.h> 26#include <linux/debugfs.h>
26#include <linux/uaccess.h> 27#include <linux/uaccess.h>
27#include <linux/export.h> 28#include <linux/export.h>
@@ -1164,11 +1165,32 @@ static void check_unmap(struct dma_debug_entry *ref)
1164 put_hash_bucket(bucket, &flags); 1165 put_hash_bucket(bucket, &flags);
1165} 1166}
1166 1167
1167static void check_for_stack(struct device *dev, void *addr) 1168static void check_for_stack(struct device *dev,
1169 struct page *page, size_t offset)
1168{ 1170{
1169 if (object_is_on_stack(addr)) 1171 void *addr;
1170 err_printk(dev, NULL, "DMA-API: device driver maps memory from " 1172 struct vm_struct *stack_vm_area = task_stack_vm_area(current);
1171 "stack [addr=%p]\n", addr); 1173
1174 if (!stack_vm_area) {
1175 /* Stack is direct-mapped. */
1176 if (PageHighMem(page))
1177 return;
1178 addr = page_address(page) + offset;
1179 if (object_is_on_stack(addr))
1180 err_printk(dev, NULL, "DMA-API: device driver maps memory from stack [addr=%p]\n", addr);
1181 } else {
1182 /* Stack is vmalloced. */
1183 int i;
1184
1185 for (i = 0; i < stack_vm_area->nr_pages; i++) {
1186 if (page != stack_vm_area->pages[i])
1187 continue;
1188
1189 addr = (u8 *)current->stack + i * PAGE_SIZE + offset;
1190 err_printk(dev, NULL, "DMA-API: device driver maps memory from stack [probable addr=%p]\n", addr);
1191 break;
1192 }
1193 }
1172} 1194}
1173 1195
1174static inline bool overlap(void *addr, unsigned long len, void *start, void *end) 1196static inline bool overlap(void *addr, unsigned long len, void *start, void *end)
@@ -1291,10 +1313,11 @@ void debug_dma_map_page(struct device *dev, struct page *page, size_t offset,
1291 if (map_single) 1313 if (map_single)
1292 entry->type = dma_debug_single; 1314 entry->type = dma_debug_single;
1293 1315
1316 check_for_stack(dev, page, offset);
1317
1294 if (!PageHighMem(page)) { 1318 if (!PageHighMem(page)) {
1295 void *addr = page_address(page) + offset; 1319 void *addr = page_address(page) + offset;
1296 1320
1297 check_for_stack(dev, addr);
1298 check_for_illegal_area(dev, addr, size); 1321 check_for_illegal_area(dev, addr, size);
1299 } 1322 }
1300 1323
@@ -1386,8 +1409,9 @@ void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
1386 entry->sg_call_ents = nents; 1409 entry->sg_call_ents = nents;
1387 entry->sg_mapped_ents = mapped_ents; 1410 entry->sg_mapped_ents = mapped_ents;
1388 1411
1412 check_for_stack(dev, sg_page(s), s->offset);
1413
1389 if (!PageHighMem(sg_page(s))) { 1414 if (!PageHighMem(sg_page(s))) {
1390 check_for_stack(dev, sg_virt(s));
1391 check_for_illegal_area(dev, sg_virt(s), sg_dma_len(s)); 1415 check_for_illegal_area(dev, sg_virt(s), sg_dma_len(s));
1392 } 1416 }
1393 1417