diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-13 15:55:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-13 15:55:49 -0400 |
commit | 8603596a327c978534f5c45db135e6c36b4b1425 (patch) | |
tree | 7270af18e4d1c42986672eb5673d55c7dfa678cf /arch/x86/kernel | |
parent | de5d1b39ea0b38a9f4dfb08966042b7b91e2df30 (diff) | |
parent | ec2cb7a526d49b65576301e183448fb51ee543a6 (diff) |
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf update from Thomas Gleixner:
"The perf crowd presents:
Kernel updates:
- Removal of jprobes
- Cleanup and consolidatation the handling of kprobes
- Cleanup and consolidation of hardware breakpoints
- The usual pile of fixes and updates to PMUs and event descriptors
Tooling updates:
- Updates and improvements all over the place. Nothing outstanding,
just the (good) boring incremental grump work"
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (103 commits)
perf trace: Do not require --no-syscalls to suppress strace like output
perf bpf: Include uapi/linux/bpf.h from the 'perf trace' script's bpf.h
perf tools: Allow overriding MAX_NR_CPUS at compile time
perf bpf: Show better message when failing to load an object
perf list: Unify metric group description format with PMU event description
perf vendor events arm64: Update ThunderX2 implementation defined pmu core events
perf cs-etm: Generate branch sample for CS_ETM_TRACE_ON packet
perf cs-etm: Generate branch sample when receiving a CS_ETM_TRACE_ON packet
perf cs-etm: Support dummy address value for CS_ETM_TRACE_ON packet
perf cs-etm: Fix start tracing packet handling
perf build: Fix installation directory for eBPF
perf c2c report: Fix crash for empty browser
perf tests: Fix indexing when invoking subtests
perf trace: Beautify the AF_INET & AF_INET6 'socket' syscall 'protocol' args
perf trace beauty: Add beautifiers for 'socket''s 'protocol' arg
perf trace beauty: Do not print NULL strarray entries
perf beauty: Add a generator for IPPROTO_ socket's protocol constants
tools include uapi: Grab a copy of linux/in.h
perf tests: Fix complex event name parsing
perf evlist: Fix error out while applying initial delay and LBR
...
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r-- | arch/x86/kernel/hw_breakpoint.c | 131 | ||||
-rw-r--r-- | arch/x86/kernel/kprobes/common.h | 10 | ||||
-rw-r--r-- | arch/x86/kernel/kprobes/core.c | 124 | ||||
-rw-r--r-- | arch/x86/kernel/kprobes/ftrace.c | 49 | ||||
-rw-r--r-- | arch/x86/kernel/kprobes/opt.c | 1 |
5 files changed, 90 insertions, 225 deletions
diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index 8771766d46b6..34a5c1715148 100644 --- a/arch/x86/kernel/hw_breakpoint.c +++ b/arch/x86/kernel/hw_breakpoint.c | |||
@@ -169,28 +169,29 @@ void arch_uninstall_hw_breakpoint(struct perf_event *bp) | |||
169 | set_dr_addr_mask(0, i); | 169 | set_dr_addr_mask(0, i); |
170 | } | 170 | } |
171 | 171 | ||
172 | /* | 172 | static int arch_bp_generic_len(int x86_len) |
173 | * Check for virtual address in kernel space. | ||
174 | */ | ||
175 | int arch_check_bp_in_kernelspace(struct perf_event *bp) | ||
176 | { | 173 | { |
177 | unsigned int len; | 174 | switch (x86_len) { |
178 | unsigned long va; | 175 | case X86_BREAKPOINT_LEN_1: |
179 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); | 176 | return HW_BREAKPOINT_LEN_1; |
180 | 177 | case X86_BREAKPOINT_LEN_2: | |
181 | va = info->address; | 178 | return HW_BREAKPOINT_LEN_2; |
182 | len = bp->attr.bp_len; | 179 | case X86_BREAKPOINT_LEN_4: |
183 | 180 | return HW_BREAKPOINT_LEN_4; | |
184 | /* | 181 | #ifdef CONFIG_X86_64 |
185 | * We don't need to worry about va + len - 1 overflowing: | 182 | case X86_BREAKPOINT_LEN_8: |
186 | * we already require that va is aligned to a multiple of len. | 183 | return HW_BREAKPOINT_LEN_8; |
187 | */ | 184 | #endif |
188 | return (va >= TASK_SIZE_MAX) || ((va + len - 1) >= TASK_SIZE_MAX); | 185 | default: |
186 | return -EINVAL; | ||
187 | } | ||
189 | } | 188 | } |
190 | 189 | ||
191 | int arch_bp_generic_fields(int x86_len, int x86_type, | 190 | int arch_bp_generic_fields(int x86_len, int x86_type, |
192 | int *gen_len, int *gen_type) | 191 | int *gen_len, int *gen_type) |
193 | { | 192 | { |
193 | int len; | ||
194 | |||
194 | /* Type */ | 195 | /* Type */ |
195 | switch (x86_type) { | 196 | switch (x86_type) { |
196 | case X86_BREAKPOINT_EXECUTE: | 197 | case X86_BREAKPOINT_EXECUTE: |
@@ -211,42 +212,47 @@ int arch_bp_generic_fields(int x86_len, int x86_type, | |||
211 | } | 212 | } |
212 | 213 | ||
213 | /* Len */ | 214 | /* Len */ |
214 | switch (x86_len) { | 215 | len = arch_bp_generic_len(x86_len); |
215 | case X86_BREAKPOINT_LEN_1: | 216 | if (len < 0) |
216 | *gen_len = HW_BREAKPOINT_LEN_1; | ||
217 | break; | ||
218 | case X86_BREAKPOINT_LEN_2: | ||
219 | *gen_len = HW_BREAKPOINT_LEN_2; | ||
220 | break; | ||
221 | case X86_BREAKPOINT_LEN_4: | ||
222 | *gen_len = HW_BREAKPOINT_LEN_4; | ||
223 | break; | ||
224 | #ifdef CONFIG_X86_64 | ||
225 | case X86_BREAKPOINT_LEN_8: | ||
226 | *gen_len = HW_BREAKPOINT_LEN_8; | ||
227 | break; | ||
228 | #endif | ||
229 | default: | ||
230 | return -EINVAL; | 217 | return -EINVAL; |
231 | } | 218 | *gen_len = len; |
232 | 219 | ||
233 | return 0; | 220 | return 0; |
234 | } | 221 | } |
235 | 222 | ||
236 | 223 | /* | |
237 | static int arch_build_bp_info(struct perf_event *bp) | 224 | * Check for virtual address in kernel space. |
225 | */ | ||
226 | int arch_check_bp_in_kernelspace(struct arch_hw_breakpoint *hw) | ||
238 | { | 227 | { |
239 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); | 228 | unsigned long va; |
229 | int len; | ||
240 | 230 | ||
241 | info->address = bp->attr.bp_addr; | 231 | va = hw->address; |
232 | len = arch_bp_generic_len(hw->len); | ||
233 | WARN_ON_ONCE(len < 0); | ||
234 | |||
235 | /* | ||
236 | * We don't need to worry about va + len - 1 overflowing: | ||
237 | * we already require that va is aligned to a multiple of len. | ||
238 | */ | ||
239 | return (va >= TASK_SIZE_MAX) || ((va + len - 1) >= TASK_SIZE_MAX); | ||
240 | } | ||
241 | |||
242 | static int arch_build_bp_info(struct perf_event *bp, | ||
243 | const struct perf_event_attr *attr, | ||
244 | struct arch_hw_breakpoint *hw) | ||
245 | { | ||
246 | hw->address = attr->bp_addr; | ||
247 | hw->mask = 0; | ||
242 | 248 | ||
243 | /* Type */ | 249 | /* Type */ |
244 | switch (bp->attr.bp_type) { | 250 | switch (attr->bp_type) { |
245 | case HW_BREAKPOINT_W: | 251 | case HW_BREAKPOINT_W: |
246 | info->type = X86_BREAKPOINT_WRITE; | 252 | hw->type = X86_BREAKPOINT_WRITE; |
247 | break; | 253 | break; |
248 | case HW_BREAKPOINT_W | HW_BREAKPOINT_R: | 254 | case HW_BREAKPOINT_W | HW_BREAKPOINT_R: |
249 | info->type = X86_BREAKPOINT_RW; | 255 | hw->type = X86_BREAKPOINT_RW; |
250 | break; | 256 | break; |
251 | case HW_BREAKPOINT_X: | 257 | case HW_BREAKPOINT_X: |
252 | /* | 258 | /* |
@@ -254,23 +260,23 @@ static int arch_build_bp_info(struct perf_event *bp) | |||
254 | * acceptable for kprobes. On non-kprobes kernels, we don't | 260 | * acceptable for kprobes. On non-kprobes kernels, we don't |
255 | * allow kernel breakpoints at all. | 261 | * allow kernel breakpoints at all. |
256 | */ | 262 | */ |
257 | if (bp->attr.bp_addr >= TASK_SIZE_MAX) { | 263 | if (attr->bp_addr >= TASK_SIZE_MAX) { |
258 | #ifdef CONFIG_KPROBES | 264 | #ifdef CONFIG_KPROBES |
259 | if (within_kprobe_blacklist(bp->attr.bp_addr)) | 265 | if (within_kprobe_blacklist(attr->bp_addr)) |
260 | return -EINVAL; | 266 | return -EINVAL; |
261 | #else | 267 | #else |
262 | return -EINVAL; | 268 | return -EINVAL; |
263 | #endif | 269 | #endif |
264 | } | 270 | } |
265 | 271 | ||
266 | info->type = X86_BREAKPOINT_EXECUTE; | 272 | hw->type = X86_BREAKPOINT_EXECUTE; |
267 | /* | 273 | /* |
268 | * x86 inst breakpoints need to have a specific undefined len. | 274 | * x86 inst breakpoints need to have a specific undefined len. |
269 | * But we still need to check userspace is not trying to setup | 275 | * But we still need to check userspace is not trying to setup |
270 | * an unsupported length, to get a range breakpoint for example. | 276 | * an unsupported length, to get a range breakpoint for example. |
271 | */ | 277 | */ |
272 | if (bp->attr.bp_len == sizeof(long)) { | 278 | if (attr->bp_len == sizeof(long)) { |
273 | info->len = X86_BREAKPOINT_LEN_X; | 279 | hw->len = X86_BREAKPOINT_LEN_X; |
274 | return 0; | 280 | return 0; |
275 | } | 281 | } |
276 | default: | 282 | default: |
@@ -278,28 +284,26 @@ static int arch_build_bp_info(struct perf_event *bp) | |||
278 | } | 284 | } |
279 | 285 | ||
280 | /* Len */ | 286 | /* Len */ |
281 | info->mask = 0; | 287 | switch (attr->bp_len) { |
282 | |||
283 | switch (bp->attr.bp_len) { | ||
284 | case HW_BREAKPOINT_LEN_1: | 288 | case HW_BREAKPOINT_LEN_1: |
285 | info->len = X86_BREAKPOINT_LEN_1; | 289 | hw->len = X86_BREAKPOINT_LEN_1; |
286 | break; | 290 | break; |
287 | case HW_BREAKPOINT_LEN_2: | 291 | case HW_BREAKPOINT_LEN_2: |
288 | info->len = X86_BREAKPOINT_LEN_2; | 292 | hw->len = X86_BREAKPOINT_LEN_2; |
289 | break; | 293 | break; |
290 | case HW_BREAKPOINT_LEN_4: | 294 | case HW_BREAKPOINT_LEN_4: |
291 | info->len = X86_BREAKPOINT_LEN_4; | 295 | hw->len = X86_BREAKPOINT_LEN_4; |
292 | break; | 296 | break; |
293 | #ifdef CONFIG_X86_64 | 297 | #ifdef CONFIG_X86_64 |
294 | case HW_BREAKPOINT_LEN_8: | 298 | case HW_BREAKPOINT_LEN_8: |
295 | info->len = X86_BREAKPOINT_LEN_8; | 299 | hw->len = X86_BREAKPOINT_LEN_8; |
296 | break; | 300 | break; |
297 | #endif | 301 | #endif |
298 | default: | 302 | default: |
299 | /* AMD range breakpoint */ | 303 | /* AMD range breakpoint */ |
300 | if (!is_power_of_2(bp->attr.bp_len)) | 304 | if (!is_power_of_2(attr->bp_len)) |
301 | return -EINVAL; | 305 | return -EINVAL; |
302 | if (bp->attr.bp_addr & (bp->attr.bp_len - 1)) | 306 | if (attr->bp_addr & (attr->bp_len - 1)) |
303 | return -EINVAL; | 307 | return -EINVAL; |
304 | 308 | ||
305 | if (!boot_cpu_has(X86_FEATURE_BPEXT)) | 309 | if (!boot_cpu_has(X86_FEATURE_BPEXT)) |
@@ -312,8 +316,8 @@ static int arch_build_bp_info(struct perf_event *bp) | |||
312 | * breakpoints, then we'll have to check for kprobe-blacklisted | 316 | * breakpoints, then we'll have to check for kprobe-blacklisted |
313 | * addresses anywhere in the range. | 317 | * addresses anywhere in the range. |
314 | */ | 318 | */ |
315 | info->mask = bp->attr.bp_len - 1; | 319 | hw->mask = attr->bp_len - 1; |
316 | info->len = X86_BREAKPOINT_LEN_1; | 320 | hw->len = X86_BREAKPOINT_LEN_1; |
317 | } | 321 | } |
318 | 322 | ||
319 | return 0; | 323 | return 0; |
@@ -322,22 +326,23 @@ static int arch_build_bp_info(struct perf_event *bp) | |||
322 | /* | 326 | /* |
323 | * Validate the arch-specific HW Breakpoint register settings | 327 | * Validate the arch-specific HW Breakpoint register settings |
324 | */ | 328 | */ |
325 | int arch_validate_hwbkpt_settings(struct perf_event *bp) | 329 | int hw_breakpoint_arch_parse(struct perf_event *bp, |
330 | const struct perf_event_attr *attr, | ||
331 | struct arch_hw_breakpoint *hw) | ||
326 | { | 332 | { |
327 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); | ||
328 | unsigned int align; | 333 | unsigned int align; |
329 | int ret; | 334 | int ret; |
330 | 335 | ||
331 | 336 | ||
332 | ret = arch_build_bp_info(bp); | 337 | ret = arch_build_bp_info(bp, attr, hw); |
333 | if (ret) | 338 | if (ret) |
334 | return ret; | 339 | return ret; |
335 | 340 | ||
336 | switch (info->len) { | 341 | switch (hw->len) { |
337 | case X86_BREAKPOINT_LEN_1: | 342 | case X86_BREAKPOINT_LEN_1: |
338 | align = 0; | 343 | align = 0; |
339 | if (info->mask) | 344 | if (hw->mask) |
340 | align = info->mask; | 345 | align = hw->mask; |
341 | break; | 346 | break; |
342 | case X86_BREAKPOINT_LEN_2: | 347 | case X86_BREAKPOINT_LEN_2: |
343 | align = 1; | 348 | align = 1; |
@@ -358,7 +363,7 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp) | |||
358 | * Check that the low-order bits of the address are appropriate | 363 | * Check that the low-order bits of the address are appropriate |
359 | * for the alignment implied by len. | 364 | * for the alignment implied by len. |
360 | */ | 365 | */ |
361 | if (info->address & align) | 366 | if (hw->address & align) |
362 | return -EINVAL; | 367 | return -EINVAL; |
363 | 368 | ||
364 | return 0; | 369 | return 0; |
diff --git a/arch/x86/kernel/kprobes/common.h b/arch/x86/kernel/kprobes/common.h index ae38dccf0c8f..2b949f4fd4d8 100644 --- a/arch/x86/kernel/kprobes/common.h +++ b/arch/x86/kernel/kprobes/common.h | |||
@@ -105,14 +105,4 @@ static inline unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsig | |||
105 | } | 105 | } |
106 | #endif | 106 | #endif |
107 | 107 | ||
108 | #ifdef CONFIG_KPROBES_ON_FTRACE | ||
109 | extern int skip_singlestep(struct kprobe *p, struct pt_regs *regs, | ||
110 | struct kprobe_ctlblk *kcb); | ||
111 | #else | ||
112 | static inline int skip_singlestep(struct kprobe *p, struct pt_regs *regs, | ||
113 | struct kprobe_ctlblk *kcb) | ||
114 | { | ||
115 | return 0; | ||
116 | } | ||
117 | #endif | ||
118 | #endif | 108 | #endif |
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 6f4d42377fe5..b0d1e81c96bb 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c | |||
@@ -66,8 +66,6 @@ | |||
66 | 66 | ||
67 | #include "common.h" | 67 | #include "common.h" |
68 | 68 | ||
69 | void jprobe_return_end(void); | ||
70 | |||
71 | DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL; | 69 | DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL; |
72 | DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); | 70 | DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); |
73 | 71 | ||
@@ -395,8 +393,6 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn) | |||
395 | - (u8 *) real; | 393 | - (u8 *) real; |
396 | if ((s64) (s32) newdisp != newdisp) { | 394 | if ((s64) (s32) newdisp != newdisp) { |
397 | pr_err("Kprobes error: new displacement does not fit into s32 (%llx)\n", newdisp); | 395 | pr_err("Kprobes error: new displacement does not fit into s32 (%llx)\n", newdisp); |
398 | pr_err("\tSrc: %p, Dest: %p, old disp: %x\n", | ||
399 | src, real, insn->displacement.value); | ||
400 | return 0; | 396 | return 0; |
401 | } | 397 | } |
402 | disp = (u8 *) dest + insn_offset_displacement(insn); | 398 | disp = (u8 *) dest + insn_offset_displacement(insn); |
@@ -596,7 +592,6 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs, | |||
596 | * stepping. | 592 | * stepping. |
597 | */ | 593 | */ |
598 | regs->ip = (unsigned long)p->ainsn.insn; | 594 | regs->ip = (unsigned long)p->ainsn.insn; |
599 | preempt_enable_no_resched(); | ||
600 | return; | 595 | return; |
601 | } | 596 | } |
602 | #endif | 597 | #endif |
@@ -640,8 +635,7 @@ static int reenter_kprobe(struct kprobe *p, struct pt_regs *regs, | |||
640 | * Raise a BUG or we'll continue in an endless reentering loop | 635 | * Raise a BUG or we'll continue in an endless reentering loop |
641 | * and eventually a stack overflow. | 636 | * and eventually a stack overflow. |
642 | */ | 637 | */ |
643 | printk(KERN_WARNING "Unrecoverable kprobe detected at %p.\n", | 638 | pr_err("Unrecoverable kprobe detected.\n"); |
644 | p->addr); | ||
645 | dump_kprobe(p); | 639 | dump_kprobe(p); |
646 | BUG(); | 640 | BUG(); |
647 | default: | 641 | default: |
@@ -669,12 +663,10 @@ int kprobe_int3_handler(struct pt_regs *regs) | |||
669 | 663 | ||
670 | addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t)); | 664 | addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t)); |
671 | /* | 665 | /* |
672 | * We don't want to be preempted for the entire | 666 | * We don't want to be preempted for the entire duration of kprobe |
673 | * duration of kprobe processing. We conditionally | 667 | * processing. Since int3 and debug trap disables irqs and we clear |
674 | * re-enable preemption at the end of this function, | 668 | * IF while singlestepping, it must be no preemptible. |
675 | * and also in reenter_kprobe() and setup_singlestep(). | ||
676 | */ | 669 | */ |
677 | preempt_disable(); | ||
678 | 670 | ||
679 | kcb = get_kprobe_ctlblk(); | 671 | kcb = get_kprobe_ctlblk(); |
680 | p = get_kprobe(addr); | 672 | p = get_kprobe(addr); |
@@ -690,13 +682,14 @@ int kprobe_int3_handler(struct pt_regs *regs) | |||
690 | /* | 682 | /* |
691 | * If we have no pre-handler or it returned 0, we | 683 | * If we have no pre-handler or it returned 0, we |
692 | * continue with normal processing. If we have a | 684 | * continue with normal processing. If we have a |
693 | * pre-handler and it returned non-zero, it prepped | 685 | * pre-handler and it returned non-zero, that means |
694 | * for calling the break_handler below on re-entry | 686 | * user handler setup registers to exit to another |
695 | * for jprobe processing, so get out doing nothing | 687 | * instruction, we must skip the single stepping. |
696 | * more here. | ||
697 | */ | 688 | */ |
698 | if (!p->pre_handler || !p->pre_handler(p, regs)) | 689 | if (!p->pre_handler || !p->pre_handler(p, regs)) |
699 | setup_singlestep(p, regs, kcb, 0); | 690 | setup_singlestep(p, regs, kcb, 0); |
691 | else | ||
692 | reset_current_kprobe(); | ||
700 | return 1; | 693 | return 1; |
701 | } | 694 | } |
702 | } else if (*addr != BREAKPOINT_INSTRUCTION) { | 695 | } else if (*addr != BREAKPOINT_INSTRUCTION) { |
@@ -710,18 +703,9 @@ int kprobe_int3_handler(struct pt_regs *regs) | |||
710 | * the original instruction. | 703 | * the original instruction. |
711 | */ | 704 | */ |
712 | regs->ip = (unsigned long)addr; | 705 | regs->ip = (unsigned long)addr; |
713 | preempt_enable_no_resched(); | ||
714 | return 1; | 706 | return 1; |
715 | } else if (kprobe_running()) { | ||
716 | p = __this_cpu_read(current_kprobe); | ||
717 | if (p->break_handler && p->break_handler(p, regs)) { | ||
718 | if (!skip_singlestep(p, regs, kcb)) | ||
719 | setup_singlestep(p, regs, kcb, 0); | ||
720 | return 1; | ||
721 | } | ||
722 | } /* else: not a kprobe fault; let the kernel handle it */ | 707 | } /* else: not a kprobe fault; let the kernel handle it */ |
723 | 708 | ||
724 | preempt_enable_no_resched(); | ||
725 | return 0; | 709 | return 0; |
726 | } | 710 | } |
727 | NOKPROBE_SYMBOL(kprobe_int3_handler); | 711 | NOKPROBE_SYMBOL(kprobe_int3_handler); |
@@ -972,8 +956,6 @@ int kprobe_debug_handler(struct pt_regs *regs) | |||
972 | } | 956 | } |
973 | reset_current_kprobe(); | 957 | reset_current_kprobe(); |
974 | out: | 958 | out: |
975 | preempt_enable_no_resched(); | ||
976 | |||
977 | /* | 959 | /* |
978 | * if somebody else is singlestepping across a probe point, flags | 960 | * if somebody else is singlestepping across a probe point, flags |
979 | * will have TF set, in which case, continue the remaining processing | 961 | * will have TF set, in which case, continue the remaining processing |
@@ -1020,7 +1002,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr) | |||
1020 | restore_previous_kprobe(kcb); | 1002 | restore_previous_kprobe(kcb); |
1021 | else | 1003 | else |
1022 | reset_current_kprobe(); | 1004 | reset_current_kprobe(); |
1023 | preempt_enable_no_resched(); | ||
1024 | } else if (kcb->kprobe_status == KPROBE_HIT_ACTIVE || | 1005 | } else if (kcb->kprobe_status == KPROBE_HIT_ACTIVE || |
1025 | kcb->kprobe_status == KPROBE_HIT_SSDONE) { | 1006 | kcb->kprobe_status == KPROBE_HIT_SSDONE) { |
1026 | /* | 1007 | /* |
@@ -1083,93 +1064,6 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, | |||
1083 | } | 1064 | } |
1084 | NOKPROBE_SYMBOL(kprobe_exceptions_notify); | 1065 | NOKPROBE_SYMBOL(kprobe_exceptions_notify); |
1085 | 1066 | ||
1086 | int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) | ||
1087 | { | ||
1088 | struct jprobe *jp = container_of(p, struct jprobe, kp); | ||
1089 | unsigned long addr; | ||
1090 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); | ||
1091 | |||
1092 | kcb->jprobe_saved_regs = *regs; | ||
1093 | kcb->jprobe_saved_sp = stack_addr(regs); | ||
1094 | addr = (unsigned long)(kcb->jprobe_saved_sp); | ||
1095 | |||
1096 | /* | ||
1097 | * As Linus pointed out, gcc assumes that the callee | ||
1098 | * owns the argument space and could overwrite it, e.g. | ||
1099 | * tailcall optimization. So, to be absolutely safe | ||
1100 | * we also save and restore enough stack bytes to cover | ||
1101 | * the argument area. | ||
1102 | * Use __memcpy() to avoid KASAN stack out-of-bounds reports as we copy | ||
1103 | * raw stack chunk with redzones: | ||
1104 | */ | ||
1105 | __memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr, MIN_STACK_SIZE(addr)); | ||
1106 | regs->ip = (unsigned long)(jp->entry); | ||
1107 | |||
1108 | /* | ||
1109 | * jprobes use jprobe_return() which skips the normal return | ||
1110 | * path of the function, and this messes up the accounting of the | ||
1111 | * function graph tracer to get messed up. | ||
1112 | * | ||
1113 | * Pause function graph tracing while performing the jprobe function. | ||
1114 | */ | ||
1115 | pause_graph_tracing(); | ||
1116 | return 1; | ||
1117 | } | ||
1118 | NOKPROBE_SYMBOL(setjmp_pre_handler); | ||
1119 | |||
1120 | void jprobe_return(void) | ||
1121 | { | ||
1122 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); | ||
1123 | |||
1124 | /* Unpoison stack redzones in the frames we are going to jump over. */ | ||
1125 | kasan_unpoison_stack_above_sp_to(kcb->jprobe_saved_sp); | ||
1126 | |||
1127 | asm volatile ( | ||
1128 | #ifdef CONFIG_X86_64 | ||
1129 | " xchg %%rbx,%%rsp \n" | ||
1130 | #else | ||
1131 | " xchgl %%ebx,%%esp \n" | ||
1132 | #endif | ||
1133 | " int3 \n" | ||
1134 | " .globl jprobe_return_end\n" | ||
1135 | " jprobe_return_end: \n" | ||
1136 | " nop \n"::"b" | ||
1137 | (kcb->jprobe_saved_sp):"memory"); | ||
1138 | } | ||
1139 | NOKPROBE_SYMBOL(jprobe_return); | ||
1140 | NOKPROBE_SYMBOL(jprobe_return_end); | ||
1141 | |||
1142 | int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) | ||
1143 | { | ||
1144 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); | ||
1145 | u8 *addr = (u8 *) (regs->ip - 1); | ||
1146 | struct jprobe *jp = container_of(p, struct jprobe, kp); | ||
1147 | void *saved_sp = kcb->jprobe_saved_sp; | ||
1148 | |||
1149 | if ((addr > (u8 *) jprobe_return) && | ||
1150 | (addr < (u8 *) jprobe_return_end)) { | ||
1151 | if (stack_addr(regs) != saved_sp) { | ||
1152 | struct pt_regs *saved_regs = &kcb->jprobe_saved_regs; | ||
1153 | printk(KERN_ERR | ||
1154 | "current sp %p does not match saved sp %p\n", | ||
1155 | stack_addr(regs), saved_sp); | ||
1156 | printk(KERN_ERR "Saved registers for jprobe %p\n", jp); | ||
1157 | show_regs(saved_regs); | ||
1158 | printk(KERN_ERR "Current registers\n"); | ||
1159 | show_regs(regs); | ||
1160 | BUG(); | ||
1161 | } | ||
1162 | /* It's OK to start function graph tracing again */ | ||
1163 | unpause_graph_tracing(); | ||
1164 | *regs = kcb->jprobe_saved_regs; | ||
1165 | __memcpy(saved_sp, kcb->jprobes_stack, MIN_STACK_SIZE(saved_sp)); | ||
1166 | preempt_enable_no_resched(); | ||
1167 | return 1; | ||
1168 | } | ||
1169 | return 0; | ||
1170 | } | ||
1171 | NOKPROBE_SYMBOL(longjmp_break_handler); | ||
1172 | |||
1173 | bool arch_within_kprobe_blacklist(unsigned long addr) | 1067 | bool arch_within_kprobe_blacklist(unsigned long addr) |
1174 | { | 1068 | { |
1175 | bool is_in_entry_trampoline_section = false; | 1069 | bool is_in_entry_trampoline_section = false; |
diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c index 8dc0161cec8f..ef819e19650b 100644 --- a/arch/x86/kernel/kprobes/ftrace.c +++ b/arch/x86/kernel/kprobes/ftrace.c | |||
@@ -25,36 +25,6 @@ | |||
25 | 25 | ||
26 | #include "common.h" | 26 | #include "common.h" |
27 | 27 | ||
28 | static nokprobe_inline | ||
29 | void __skip_singlestep(struct kprobe *p, struct pt_regs *regs, | ||
30 | struct kprobe_ctlblk *kcb, unsigned long orig_ip) | ||
31 | { | ||
32 | /* | ||
33 | * Emulate singlestep (and also recover regs->ip) | ||
34 | * as if there is a 5byte nop | ||
35 | */ | ||
36 | regs->ip = (unsigned long)p->addr + MCOUNT_INSN_SIZE; | ||
37 | if (unlikely(p->post_handler)) { | ||
38 | kcb->kprobe_status = KPROBE_HIT_SSDONE; | ||
39 | p->post_handler(p, regs, 0); | ||
40 | } | ||
41 | __this_cpu_write(current_kprobe, NULL); | ||
42 | if (orig_ip) | ||
43 | regs->ip = orig_ip; | ||
44 | } | ||
45 | |||
46 | int skip_singlestep(struct kprobe *p, struct pt_regs *regs, | ||
47 | struct kprobe_ctlblk *kcb) | ||
48 | { | ||
49 | if (kprobe_ftrace(p)) { | ||
50 | __skip_singlestep(p, regs, kcb, 0); | ||
51 | preempt_enable_no_resched(); | ||
52 | return 1; | ||
53 | } | ||
54 | return 0; | ||
55 | } | ||
56 | NOKPROBE_SYMBOL(skip_singlestep); | ||
57 | |||
58 | /* Ftrace callback handler for kprobes -- called under preepmt disabed */ | 28 | /* Ftrace callback handler for kprobes -- called under preepmt disabed */ |
59 | void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, | 29 | void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, |
60 | struct ftrace_ops *ops, struct pt_regs *regs) | 30 | struct ftrace_ops *ops, struct pt_regs *regs) |
@@ -75,18 +45,25 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, | |||
75 | /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */ | 45 | /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */ |
76 | regs->ip = ip + sizeof(kprobe_opcode_t); | 46 | regs->ip = ip + sizeof(kprobe_opcode_t); |
77 | 47 | ||
78 | /* To emulate trap based kprobes, preempt_disable here */ | ||
79 | preempt_disable(); | ||
80 | __this_cpu_write(current_kprobe, p); | 48 | __this_cpu_write(current_kprobe, p); |
81 | kcb->kprobe_status = KPROBE_HIT_ACTIVE; | 49 | kcb->kprobe_status = KPROBE_HIT_ACTIVE; |
82 | if (!p->pre_handler || !p->pre_handler(p, regs)) { | 50 | if (!p->pre_handler || !p->pre_handler(p, regs)) { |
83 | __skip_singlestep(p, regs, kcb, orig_ip); | 51 | /* |
84 | preempt_enable_no_resched(); | 52 | * Emulate singlestep (and also recover regs->ip) |
53 | * as if there is a 5byte nop | ||
54 | */ | ||
55 | regs->ip = (unsigned long)p->addr + MCOUNT_INSN_SIZE; | ||
56 | if (unlikely(p->post_handler)) { | ||
57 | kcb->kprobe_status = KPROBE_HIT_SSDONE; | ||
58 | p->post_handler(p, regs, 0); | ||
59 | } | ||
60 | regs->ip = orig_ip; | ||
85 | } | 61 | } |
86 | /* | 62 | /* |
87 | * If pre_handler returns !0, it sets regs->ip and | 63 | * If pre_handler returns !0, it changes regs->ip. We have to |
88 | * resets current kprobe, and keep preempt count +1. | 64 | * skip emulating post_handler. |
89 | */ | 65 | */ |
66 | __this_cpu_write(current_kprobe, NULL); | ||
90 | } | 67 | } |
91 | } | 68 | } |
92 | NOKPROBE_SYMBOL(kprobe_ftrace_handler); | 69 | NOKPROBE_SYMBOL(kprobe_ftrace_handler); |
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 203d398802a3..eaf02f2e7300 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c | |||
@@ -491,7 +491,6 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter) | |||
491 | regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX; | 491 | regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX; |
492 | if (!reenter) | 492 | if (!reenter) |
493 | reset_current_kprobe(); | 493 | reset_current_kprobe(); |
494 | preempt_enable_no_resched(); | ||
495 | return 1; | 494 | return 1; |
496 | } | 495 | } |
497 | return 0; | 496 | return 0; |