diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-03 19:13:28 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-03 19:13:28 -0400 |
commit | 1a4a2bc460721bc8f91e4c1294d39b38e5af132f (patch) | |
tree | fe646d05f6e17f05601e0a32cc796bec718ab6e7 /lib/dma-debug.c | |
parent | 110a9e42b68719f584879c5c5c727bbae90d15f9 (diff) | |
parent | 1ef55be16ed69538f89e0a6508be5e62fdc9851c (diff) |
Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull low-level x86 updates from Ingo Molnar:
"In this cycle this topic tree has become one of those 'super topics'
that accumulated a lot of changes:
- Add CONFIG_VMAP_STACK=y support to the core kernel and enable it on
x86 - preceded by an array of changes. v4.8 saw preparatory changes
in this area already - this is the rest of the work. Includes the
thread stack caching performance optimization. (Andy Lutomirski)
- switch_to() cleanups and all around enhancements. (Brian Gerst)
- A large number of dumpstack infrastructure enhancements and an
unwinder abstraction. The secret long term plan is safe(r) live
patching plus maybe another attempt at debuginfo based unwinding -
but all these current bits are standalone enhancements in a frame
pointer based debug environment as well. (Josh Poimboeuf)
- More __ro_after_init and const annotations. (Kees Cook)
- Enable KASLR for the vmemmap memory region. (Thomas Garnier)"
[ The virtually mapped stack changes are pretty fundamental, and not
x86-specific per se, even if they are only used on x86 right now. ]
* 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (70 commits)
x86/asm: Get rid of __read_cr4_safe()
thread_info: Use unsigned long for flags
x86/alternatives: Add stack frame dependency to alternative_call_2()
x86/dumpstack: Fix show_stack() task pointer regression
x86/dumpstack: Remove dump_trace() and related callbacks
x86/dumpstack: Convert show_trace_log_lvl() to use the new unwinder
oprofile/x86: Convert x86_backtrace() to use the new unwinder
x86/stacktrace: Convert save_stack_trace_*() to use the new unwinder
perf/x86: Convert perf_callchain_kernel() to use the new unwinder
x86/unwind: Add new unwind interface and implementations
x86/dumpstack: Remove NULL task pointer convention
fork: Optimize task creation by caching two thread stacks per CPU if CONFIG_VMAP_STACK=y
sched/core: Free the stack early if CONFIG_THREAD_INFO_IN_TASK
lib/syscall: Pin the task stack in collect_syscall()
x86/process: Pin the target stack in get_wchan()
x86/dumpstack: Pin the target stack when dumping it
kthread: Pin the stack via try_get_task_stack()/put_task_stack() in to_live_kthread() function
sched/core: Add try_get_task_stack() and put_task_stack()
x86/entry/64: Fix a minor comment rebase error
iommu/amd: Don't put completion-wait semaphore on stack
...
Diffstat (limited to 'lib/dma-debug.c')
-rw-r--r-- | lib/dma-debug.c | 36 |
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 | ||
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 | ||