diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dma-debug.c | 36 | ||||
-rw-r--r-- | lib/syscall.c | 15 |
2 files changed, 43 insertions, 8 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 | ||
1167 | static void check_for_stack(struct device *dev, void *addr) | 1168 | static 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 | ||
1174 | static inline bool overlap(void *addr, unsigned long len, void *start, void *end) | 1196 | static 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 | ||
diff --git a/lib/syscall.c b/lib/syscall.c index e30e03932480..63239e097b13 100644 --- a/lib/syscall.c +++ b/lib/syscall.c | |||
@@ -7,9 +7,19 @@ static int collect_syscall(struct task_struct *target, long *callno, | |||
7 | unsigned long args[6], unsigned int maxargs, | 7 | unsigned long args[6], unsigned int maxargs, |
8 | unsigned long *sp, unsigned long *pc) | 8 | unsigned long *sp, unsigned long *pc) |
9 | { | 9 | { |
10 | struct pt_regs *regs = task_pt_regs(target); | 10 | struct pt_regs *regs; |
11 | if (unlikely(!regs)) | 11 | |
12 | if (!try_get_task_stack(target)) { | ||
13 | /* Task has no stack, so the task isn't in a syscall. */ | ||
14 | *callno = -1; | ||
15 | return 0; | ||
16 | } | ||
17 | |||
18 | regs = task_pt_regs(target); | ||
19 | if (unlikely(!regs)) { | ||
20 | put_task_stack(target); | ||
12 | return -EAGAIN; | 21 | return -EAGAIN; |
22 | } | ||
13 | 23 | ||
14 | *sp = user_stack_pointer(regs); | 24 | *sp = user_stack_pointer(regs); |
15 | *pc = instruction_pointer(regs); | 25 | *pc = instruction_pointer(regs); |
@@ -18,6 +28,7 @@ static int collect_syscall(struct task_struct *target, long *callno, | |||
18 | if (*callno != -1L && maxargs > 0) | 28 | if (*callno != -1L && maxargs > 0) |
19 | syscall_get_arguments(target, regs, 0, maxargs, args); | 29 | syscall_get_arguments(target, regs, 0, maxargs, args); |
20 | 30 | ||
31 | put_task_stack(target); | ||
21 | return 0; | 32 | return 0; |
22 | } | 33 | } |
23 | 34 | ||