aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2014-06-05 05:18:34 -0400
committerIngo Molnar <mingo@kernel.org>2014-06-05 06:26:50 -0400
commit10b0256496fd6c162478547f7c6df1e052e87644 (patch)
tree7037905737ae83a86a5cdb376cd1d66f7f407e2e /arch
parentc56d34064b6eb9f9cde9e35bbfe16eedf3d81f94 (diff)
parent69902c718c0b476e94ed7fccd3cf29ca39fe433a (diff)
Merge branch 'perf/kprobes' into perf/core
Conflicts: arch/x86/kernel/traps.c The kprobes enhancements are fully cooked, ship them upstream. Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/include/asm/asm.h7
-rw-r--r--arch/x86/include/asm/kprobes.h2
-rw-r--r--arch/x86/include/asm/traps.h2
-rw-r--r--arch/x86/kernel/alternative.c3
-rw-r--r--arch/x86/kernel/apic/hw_nmi.c3
-rw-r--r--arch/x86/kernel/cpu/common.c4
-rw-r--r--arch/x86/kernel/cpu/perf_event.c3
-rw-r--r--arch/x86/kernel/cpu/perf_event_amd_ibs.c3
-rw-r--r--arch/x86/kernel/dumpstack.c9
-rw-r--r--arch/x86/kernel/entry_32.S33
-rw-r--r--arch/x86/kernel/entry_64.S20
-rw-r--r--arch/x86/kernel/hw_breakpoint.c5
-rw-r--r--arch/x86/kernel/kprobes/core.c128
-rw-r--r--arch/x86/kernel/kprobes/ftrace.c17
-rw-r--r--arch/x86/kernel/kprobes/opt.c32
-rw-r--r--arch/x86/kernel/kvm.c4
-rw-r--r--arch/x86/kernel/nmi.c18
-rw-r--r--arch/x86/kernel/paravirt.c6
-rw-r--r--arch/x86/kernel/traps.c35
-rw-r--r--arch/x86/lib/thunk_32.S3
-rw-r--r--arch/x86/lib/thunk_64.S3
-rw-r--r--arch/x86/mm/fault.c29
22 files changed, 195 insertions, 174 deletions
diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 4582e8e1cd1a..7730c1c5c83a 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -57,6 +57,12 @@
57 .long (from) - . ; \ 57 .long (from) - . ; \
58 .long (to) - . + 0x7ffffff0 ; \ 58 .long (to) - . + 0x7ffffff0 ; \
59 .popsection 59 .popsection
60
61# define _ASM_NOKPROBE(entry) \
62 .pushsection "_kprobe_blacklist","aw" ; \
63 _ASM_ALIGN ; \
64 _ASM_PTR (entry); \
65 .popsection
60#else 66#else
61# define _ASM_EXTABLE(from,to) \ 67# define _ASM_EXTABLE(from,to) \
62 " .pushsection \"__ex_table\",\"a\"\n" \ 68 " .pushsection \"__ex_table\",\"a\"\n" \
@@ -71,6 +77,7 @@
71 " .long (" #from ") - .\n" \ 77 " .long (" #from ") - .\n" \
72 " .long (" #to ") - . + 0x7ffffff0\n" \ 78 " .long (" #to ") - . + 0x7ffffff0\n" \
73 " .popsection\n" 79 " .popsection\n"
80/* For C file, we already have NOKPROBE_SYMBOL macro */
74#endif 81#endif
75 82
76#endif /* _ASM_X86_ASM_H */ 83#endif /* _ASM_X86_ASM_H */
diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
index 9454c167629f..53cdfb2857ab 100644
--- a/arch/x86/include/asm/kprobes.h
+++ b/arch/x86/include/asm/kprobes.h
@@ -116,4 +116,6 @@ struct kprobe_ctlblk {
116extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr); 116extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
117extern int kprobe_exceptions_notify(struct notifier_block *self, 117extern int kprobe_exceptions_notify(struct notifier_block *self,
118 unsigned long val, void *data); 118 unsigned long val, void *data);
119extern int kprobe_int3_handler(struct pt_regs *regs);
120extern int kprobe_debug_handler(struct pt_regs *regs);
119#endif /* _ASM_X86_KPROBES_H */ 121#endif /* _ASM_X86_KPROBES_H */
diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h
index a7b212db9e04..cf69d050aa6e 100644
--- a/arch/x86/include/asm/traps.h
+++ b/arch/x86/include/asm/traps.h
@@ -68,7 +68,7 @@ dotraplinkage void do_segment_not_present(struct pt_regs *, long);
68dotraplinkage void do_stack_segment(struct pt_regs *, long); 68dotraplinkage void do_stack_segment(struct pt_regs *, long);
69#ifdef CONFIG_X86_64 69#ifdef CONFIG_X86_64
70dotraplinkage void do_double_fault(struct pt_regs *, long); 70dotraplinkage void do_double_fault(struct pt_regs *, long);
71asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *); 71asmlinkage struct pt_regs *sync_regs(struct pt_regs *);
72#endif 72#endif
73dotraplinkage void do_general_protection(struct pt_regs *, long); 73dotraplinkage void do_general_protection(struct pt_regs *, long);
74dotraplinkage void do_page_fault(struct pt_regs *, unsigned long); 74dotraplinkage void do_page_fault(struct pt_regs *, unsigned long);
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index df94598ad05a..703130f469ec 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -5,7 +5,6 @@
5#include <linux/mutex.h> 5#include <linux/mutex.h>
6#include <linux/list.h> 6#include <linux/list.h>
7#include <linux/stringify.h> 7#include <linux/stringify.h>
8#include <linux/kprobes.h>
9#include <linux/mm.h> 8#include <linux/mm.h>
10#include <linux/vmalloc.h> 9#include <linux/vmalloc.h>
11#include <linux/memory.h> 10#include <linux/memory.h>
@@ -551,7 +550,7 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
551 * 550 *
552 * Note: Must be called under text_mutex. 551 * Note: Must be called under text_mutex.
553 */ 552 */
554void *__kprobes text_poke(void *addr, const void *opcode, size_t len) 553void *text_poke(void *addr, const void *opcode, size_t len)
555{ 554{
556 unsigned long flags; 555 unsigned long flags;
557 char *vaddr; 556 char *vaddr;
diff --git a/arch/x86/kernel/apic/hw_nmi.c b/arch/x86/kernel/apic/hw_nmi.c
index a698d7165c96..73eb5b336f63 100644
--- a/arch/x86/kernel/apic/hw_nmi.c
+++ b/arch/x86/kernel/apic/hw_nmi.c
@@ -60,7 +60,7 @@ void arch_trigger_all_cpu_backtrace(void)
60 smp_mb__after_clear_bit(); 60 smp_mb__after_clear_bit();
61} 61}
62 62
63static int __kprobes 63static int
64arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs) 64arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
65{ 65{
66 int cpu; 66 int cpu;
@@ -80,6 +80,7 @@ arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
80 80
81 return NMI_DONE; 81 return NMI_DONE;
82} 82}
83NOKPROBE_SYMBOL(arch_trigger_all_cpu_backtrace_handler);
83 84
84static int __init register_trigger_all_cpu_backtrace(void) 85static int __init register_trigger_all_cpu_backtrace(void)
85{ 86{
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a135239badb7..5af696dddd1d 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -8,6 +8,7 @@
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/sched.h> 9#include <linux/sched.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/kprobes.h>
11#include <linux/kgdb.h> 12#include <linux/kgdb.h>
12#include <linux/smp.h> 13#include <linux/smp.h>
13#include <linux/io.h> 14#include <linux/io.h>
@@ -1160,6 +1161,7 @@ int is_debug_stack(unsigned long addr)
1160 (addr <= __get_cpu_var(debug_stack_addr) && 1161 (addr <= __get_cpu_var(debug_stack_addr) &&
1161 addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ)); 1162 addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ));
1162} 1163}
1164NOKPROBE_SYMBOL(is_debug_stack);
1163 1165
1164DEFINE_PER_CPU(u32, debug_idt_ctr); 1166DEFINE_PER_CPU(u32, debug_idt_ctr);
1165 1167
@@ -1168,6 +1170,7 @@ void debug_stack_set_zero(void)
1168 this_cpu_inc(debug_idt_ctr); 1170 this_cpu_inc(debug_idt_ctr);
1169 load_current_idt(); 1171 load_current_idt();
1170} 1172}
1173NOKPROBE_SYMBOL(debug_stack_set_zero);
1171 1174
1172void debug_stack_reset(void) 1175void debug_stack_reset(void)
1173{ 1176{
@@ -1176,6 +1179,7 @@ void debug_stack_reset(void)
1176 if (this_cpu_dec_return(debug_idt_ctr) == 0) 1179 if (this_cpu_dec_return(debug_idt_ctr) == 0)
1177 load_current_idt(); 1180 load_current_idt();
1178} 1181}
1182NOKPROBE_SYMBOL(debug_stack_reset);
1179 1183
1180#else /* CONFIG_X86_64 */ 1184#else /* CONFIG_X86_64 */
1181 1185
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 89f3b7c1af20..32029e35f2b9 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1293,7 +1293,7 @@ void perf_events_lapic_init(void)
1293 apic_write(APIC_LVTPC, APIC_DM_NMI); 1293 apic_write(APIC_LVTPC, APIC_DM_NMI);
1294} 1294}
1295 1295
1296static int __kprobes 1296static int
1297perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs) 1297perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
1298{ 1298{
1299 u64 start_clock; 1299 u64 start_clock;
@@ -1311,6 +1311,7 @@ perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
1311 1311
1312 return ret; 1312 return ret;
1313} 1313}
1314NOKPROBE_SYMBOL(perf_event_nmi_handler);
1314 1315
1315struct event_constraint emptyconstraint; 1316struct event_constraint emptyconstraint;
1316struct event_constraint unconstrained; 1317struct event_constraint unconstrained;
diff --git a/arch/x86/kernel/cpu/perf_event_amd_ibs.c b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
index 4c36bbe3173a..cbb1be3ed9e4 100644
--- a/arch/x86/kernel/cpu/perf_event_amd_ibs.c
+++ b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
@@ -593,7 +593,7 @@ out:
593 return 1; 593 return 1;
594} 594}
595 595
596static int __kprobes 596static int
597perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs) 597perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
598{ 598{
599 int handled = 0; 599 int handled = 0;
@@ -606,6 +606,7 @@ perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
606 606
607 return handled; 607 return handled;
608} 608}
609NOKPROBE_SYMBOL(perf_ibs_nmi_handler);
609 610
610static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name) 611static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name)
611{ 612{
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index d9c12d3022a7..b74ebc7c4402 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -200,7 +200,7 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
200static int die_owner = -1; 200static int die_owner = -1;
201static unsigned int die_nest_count; 201static unsigned int die_nest_count;
202 202
203unsigned __kprobes long oops_begin(void) 203unsigned long oops_begin(void)
204{ 204{
205 int cpu; 205 int cpu;
206 unsigned long flags; 206 unsigned long flags;
@@ -223,8 +223,9 @@ unsigned __kprobes long oops_begin(void)
223 return flags; 223 return flags;
224} 224}
225EXPORT_SYMBOL_GPL(oops_begin); 225EXPORT_SYMBOL_GPL(oops_begin);
226NOKPROBE_SYMBOL(oops_begin);
226 227
227void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) 228void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
228{ 229{
229 if (regs && kexec_should_crash(current)) 230 if (regs && kexec_should_crash(current))
230 crash_kexec(regs); 231 crash_kexec(regs);
@@ -247,8 +248,9 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
247 panic("Fatal exception"); 248 panic("Fatal exception");
248 do_exit(signr); 249 do_exit(signr);
249} 250}
251NOKPROBE_SYMBOL(oops_end);
250 252
251int __kprobes __die(const char *str, struct pt_regs *regs, long err) 253int __die(const char *str, struct pt_regs *regs, long err)
252{ 254{
253#ifdef CONFIG_X86_32 255#ifdef CONFIG_X86_32
254 unsigned short ss; 256 unsigned short ss;
@@ -291,6 +293,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
291#endif 293#endif
292 return 0; 294 return 0;
293} 295}
296NOKPROBE_SYMBOL(__die);
294 297
295/* 298/*
296 * This is gone through when something in the kernel has done something bad 299 * This is gone through when something in the kernel has done something bad
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index a2a4f4697889..0ca5bf1697bb 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -315,10 +315,6 @@ ENTRY(ret_from_kernel_thread)
315ENDPROC(ret_from_kernel_thread) 315ENDPROC(ret_from_kernel_thread)
316 316
317/* 317/*
318 * Interrupt exit functions should be protected against kprobes
319 */
320 .pushsection .kprobes.text, "ax"
321/*
322 * Return to user mode is not as complex as all this looks, 318 * Return to user mode is not as complex as all this looks,
323 * but we want the default path for a system call return to 319 * but we want the default path for a system call return to
324 * go as quickly as possible which is why some of this is 320 * go as quickly as possible which is why some of this is
@@ -372,10 +368,6 @@ need_resched:
372END(resume_kernel) 368END(resume_kernel)
373#endif 369#endif
374 CFI_ENDPROC 370 CFI_ENDPROC
375/*
376 * End of kprobes section
377 */
378 .popsection
379 371
380/* SYSENTER_RETURN points to after the "sysenter" instruction in 372/* SYSENTER_RETURN points to after the "sysenter" instruction in
381 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */ 373 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
@@ -495,10 +487,6 @@ sysexit_audit:
495 PTGS_TO_GS_EX 487 PTGS_TO_GS_EX
496ENDPROC(ia32_sysenter_target) 488ENDPROC(ia32_sysenter_target)
497 489
498/*
499 * syscall stub including irq exit should be protected against kprobes
500 */
501 .pushsection .kprobes.text, "ax"
502 # system call handler stub 490 # system call handler stub
503ENTRY(system_call) 491ENTRY(system_call)
504 RING0_INT_FRAME # can't unwind into user space anyway 492 RING0_INT_FRAME # can't unwind into user space anyway
@@ -691,10 +679,6 @@ syscall_badsys:
691 jmp resume_userspace 679 jmp resume_userspace
692END(syscall_badsys) 680END(syscall_badsys)
693 CFI_ENDPROC 681 CFI_ENDPROC
694/*
695 * End of kprobes section
696 */
697 .popsection
698 682
699.macro FIXUP_ESPFIX_STACK 683.macro FIXUP_ESPFIX_STACK
700/* 684/*
@@ -781,10 +765,6 @@ common_interrupt:
781ENDPROC(common_interrupt) 765ENDPROC(common_interrupt)
782 CFI_ENDPROC 766 CFI_ENDPROC
783 767
784/*
785 * Irq entries should be protected against kprobes
786 */
787 .pushsection .kprobes.text, "ax"
788#define BUILD_INTERRUPT3(name, nr, fn) \ 768#define BUILD_INTERRUPT3(name, nr, fn) \
789ENTRY(name) \ 769ENTRY(name) \
790 RING0_INT_FRAME; \ 770 RING0_INT_FRAME; \
@@ -961,10 +941,6 @@ ENTRY(spurious_interrupt_bug)
961 jmp error_code 941 jmp error_code
962 CFI_ENDPROC 942 CFI_ENDPROC
963END(spurious_interrupt_bug) 943END(spurious_interrupt_bug)
964/*
965 * End of kprobes section
966 */
967 .popsection
968 944
969#ifdef CONFIG_XEN 945#ifdef CONFIG_XEN
970/* Xen doesn't set %esp to be precisely what the normal sysenter 946/* Xen doesn't set %esp to be precisely what the normal sysenter
@@ -1239,11 +1215,6 @@ return_to_handler:
1239 jmp *%ecx 1215 jmp *%ecx
1240#endif 1216#endif
1241 1217
1242/*
1243 * Some functions should be protected against kprobes
1244 */
1245 .pushsection .kprobes.text, "ax"
1246
1247#ifdef CONFIG_TRACING 1218#ifdef CONFIG_TRACING
1248ENTRY(trace_page_fault) 1219ENTRY(trace_page_fault)
1249 RING0_EC_FRAME 1220 RING0_EC_FRAME
@@ -1453,7 +1424,3 @@ ENTRY(async_page_fault)
1453END(async_page_fault) 1424END(async_page_fault)
1454#endif 1425#endif
1455 1426
1456/*
1457 * End of kprobes section
1458 */
1459 .popsection
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 1e96c3628bf2..43bb38951660 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -487,8 +487,6 @@ ENDPROC(native_usergs_sysret64)
487 TRACE_IRQS_OFF 487 TRACE_IRQS_OFF
488 .endm 488 .endm
489 489
490/* save complete stack frame */
491 .pushsection .kprobes.text, "ax"
492ENTRY(save_paranoid) 490ENTRY(save_paranoid)
493 XCPT_FRAME 1 RDI+8 491 XCPT_FRAME 1 RDI+8
494 cld 492 cld
@@ -517,7 +515,6 @@ ENTRY(save_paranoid)
5171: ret 5151: ret
518 CFI_ENDPROC 516 CFI_ENDPROC
519END(save_paranoid) 517END(save_paranoid)
520 .popsection
521 518
522/* 519/*
523 * A newly forked process directly context switches into this address. 520 * A newly forked process directly context switches into this address.
@@ -975,10 +972,6 @@ END(interrupt)
975 call \func 972 call \func
976 .endm 973 .endm
977 974
978/*
979 * Interrupt entry/exit should be protected against kprobes
980 */
981 .pushsection .kprobes.text, "ax"
982 /* 975 /*
983 * The interrupt stubs push (~vector+0x80) onto the stack and 976 * The interrupt stubs push (~vector+0x80) onto the stack and
984 * then jump to common_interrupt. 977 * then jump to common_interrupt.
@@ -1113,10 +1106,6 @@ ENTRY(retint_kernel)
1113 1106
1114 CFI_ENDPROC 1107 CFI_ENDPROC
1115END(common_interrupt) 1108END(common_interrupt)
1116/*
1117 * End of kprobes section
1118 */
1119 .popsection
1120 1109
1121/* 1110/*
1122 * APIC interrupts. 1111 * APIC interrupts.
@@ -1477,11 +1466,6 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
1477 hyperv_callback_vector hyperv_vector_handler 1466 hyperv_callback_vector hyperv_vector_handler
1478#endif /* CONFIG_HYPERV */ 1467#endif /* CONFIG_HYPERV */
1479 1468
1480/*
1481 * Some functions should be protected against kprobes
1482 */
1483 .pushsection .kprobes.text, "ax"
1484
1485paranoidzeroentry_ist debug do_debug DEBUG_STACK 1469paranoidzeroentry_ist debug do_debug DEBUG_STACK
1486paranoidzeroentry_ist int3 do_int3 DEBUG_STACK 1470paranoidzeroentry_ist int3 do_int3 DEBUG_STACK
1487paranoiderrorentry stack_segment do_stack_segment 1471paranoiderrorentry stack_segment do_stack_segment
@@ -1898,7 +1882,3 @@ ENTRY(ignore_sysret)
1898 CFI_ENDPROC 1882 CFI_ENDPROC
1899END(ignore_sysret) 1883END(ignore_sysret)
1900 1884
1901/*
1902 * End of kprobes section
1903 */
1904 .popsection
diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index a67b47c31314..5f9cf20cdb68 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -32,7 +32,6 @@
32#include <linux/irqflags.h> 32#include <linux/irqflags.h>
33#include <linux/notifier.h> 33#include <linux/notifier.h>
34#include <linux/kallsyms.h> 34#include <linux/kallsyms.h>
35#include <linux/kprobes.h>
36#include <linux/percpu.h> 35#include <linux/percpu.h>
37#include <linux/kdebug.h> 36#include <linux/kdebug.h>
38#include <linux/kernel.h> 37#include <linux/kernel.h>
@@ -424,7 +423,7 @@ EXPORT_SYMBOL_GPL(hw_breakpoint_restore);
424 * NOTIFY_STOP returned for all other cases 423 * NOTIFY_STOP returned for all other cases
425 * 424 *
426 */ 425 */
427static int __kprobes hw_breakpoint_handler(struct die_args *args) 426static int hw_breakpoint_handler(struct die_args *args)
428{ 427{
429 int i, cpu, rc = NOTIFY_STOP; 428 int i, cpu, rc = NOTIFY_STOP;
430 struct perf_event *bp; 429 struct perf_event *bp;
@@ -511,7 +510,7 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
511/* 510/*
512 * Handle debug exception notifications. 511 * Handle debug exception notifications.
513 */ 512 */
514int __kprobes hw_breakpoint_exceptions_notify( 513int hw_breakpoint_exceptions_notify(
515 struct notifier_block *unused, unsigned long val, void *data) 514 struct notifier_block *unused, unsigned long val, void *data)
516{ 515{
517 if (val != DIE_DEBUG) 516 if (val != DIE_DEBUG)
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 61b17dc2c277..7596df664901 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -112,7 +112,8 @@ struct kretprobe_blackpoint kretprobe_blacklist[] = {
112 112
113const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist); 113const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
114 114
115static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op) 115static nokprobe_inline void
116__synthesize_relative_insn(void *from, void *to, u8 op)
116{ 117{
117 struct __arch_relative_insn { 118 struct __arch_relative_insn {
118 u8 op; 119 u8 op;
@@ -125,21 +126,23 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
125} 126}
126 127
127/* Insert a jump instruction at address 'from', which jumps to address 'to'.*/ 128/* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
128void __kprobes synthesize_reljump(void *from, void *to) 129void synthesize_reljump(void *from, void *to)
129{ 130{
130 __synthesize_relative_insn(from, to, RELATIVEJUMP_OPCODE); 131 __synthesize_relative_insn(from, to, RELATIVEJUMP_OPCODE);
131} 132}
133NOKPROBE_SYMBOL(synthesize_reljump);
132 134
133/* Insert a call instruction at address 'from', which calls address 'to'.*/ 135/* Insert a call instruction at address 'from', which calls address 'to'.*/
134void __kprobes synthesize_relcall(void *from, void *to) 136void synthesize_relcall(void *from, void *to)
135{ 137{
136 __synthesize_relative_insn(from, to, RELATIVECALL_OPCODE); 138 __synthesize_relative_insn(from, to, RELATIVECALL_OPCODE);
137} 139}
140NOKPROBE_SYMBOL(synthesize_relcall);
138 141
139/* 142/*
140 * Skip the prefixes of the instruction. 143 * Skip the prefixes of the instruction.
141 */ 144 */
142static kprobe_opcode_t *__kprobes skip_prefixes(kprobe_opcode_t *insn) 145static kprobe_opcode_t *skip_prefixes(kprobe_opcode_t *insn)
143{ 146{
144 insn_attr_t attr; 147 insn_attr_t attr;
145 148
@@ -154,12 +157,13 @@ static kprobe_opcode_t *__kprobes skip_prefixes(kprobe_opcode_t *insn)
154#endif 157#endif
155 return insn; 158 return insn;
156} 159}
160NOKPROBE_SYMBOL(skip_prefixes);
157 161
158/* 162/*
159 * Returns non-zero if opcode is boostable. 163 * Returns non-zero if opcode is boostable.
160 * RIP relative instructions are adjusted at copying time in 64 bits mode 164 * RIP relative instructions are adjusted at copying time in 64 bits mode
161 */ 165 */
162int __kprobes can_boost(kprobe_opcode_t *opcodes) 166int can_boost(kprobe_opcode_t *opcodes)
163{ 167{
164 kprobe_opcode_t opcode; 168 kprobe_opcode_t opcode;
165 kprobe_opcode_t *orig_opcodes = opcodes; 169 kprobe_opcode_t *orig_opcodes = opcodes;
@@ -260,7 +264,7 @@ unsigned long recover_probed_instruction(kprobe_opcode_t *buf, unsigned long add
260} 264}
261 265
262/* Check if paddr is at an instruction boundary */ 266/* Check if paddr is at an instruction boundary */
263static int __kprobes can_probe(unsigned long paddr) 267static int can_probe(unsigned long paddr)
264{ 268{
265 unsigned long addr, __addr, offset = 0; 269 unsigned long addr, __addr, offset = 0;
266 struct insn insn; 270 struct insn insn;
@@ -299,7 +303,7 @@ static int __kprobes can_probe(unsigned long paddr)
299/* 303/*
300 * Returns non-zero if opcode modifies the interrupt flag. 304 * Returns non-zero if opcode modifies the interrupt flag.
301 */ 305 */
302static int __kprobes is_IF_modifier(kprobe_opcode_t *insn) 306static int is_IF_modifier(kprobe_opcode_t *insn)
303{ 307{
304 /* Skip prefixes */ 308 /* Skip prefixes */
305 insn = skip_prefixes(insn); 309 insn = skip_prefixes(insn);
@@ -322,7 +326,7 @@ static int __kprobes is_IF_modifier(kprobe_opcode_t *insn)
322 * If not, return null. 326 * If not, return null.
323 * Only applicable to 64-bit x86. 327 * Only applicable to 64-bit x86.
324 */ 328 */
325int __kprobes __copy_instruction(u8 *dest, u8 *src) 329int __copy_instruction(u8 *dest, u8 *src)
326{ 330{
327 struct insn insn; 331 struct insn insn;
328 kprobe_opcode_t buf[MAX_INSN_SIZE]; 332 kprobe_opcode_t buf[MAX_INSN_SIZE];
@@ -365,7 +369,7 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
365 return insn.length; 369 return insn.length;
366} 370}
367 371
368static int __kprobes arch_copy_kprobe(struct kprobe *p) 372static int arch_copy_kprobe(struct kprobe *p)
369{ 373{
370 int ret; 374 int ret;
371 375
@@ -392,7 +396,7 @@ static int __kprobes arch_copy_kprobe(struct kprobe *p)
392 return 0; 396 return 0;
393} 397}
394 398
395int __kprobes arch_prepare_kprobe(struct kprobe *p) 399int arch_prepare_kprobe(struct kprobe *p)
396{ 400{
397 if (alternatives_text_reserved(p->addr, p->addr)) 401 if (alternatives_text_reserved(p->addr, p->addr))
398 return -EINVAL; 402 return -EINVAL;
@@ -407,17 +411,17 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
407 return arch_copy_kprobe(p); 411 return arch_copy_kprobe(p);
408} 412}
409 413
410void __kprobes arch_arm_kprobe(struct kprobe *p) 414void arch_arm_kprobe(struct kprobe *p)
411{ 415{
412 text_poke(p->addr, ((unsigned char []){BREAKPOINT_INSTRUCTION}), 1); 416 text_poke(p->addr, ((unsigned char []){BREAKPOINT_INSTRUCTION}), 1);
413} 417}
414 418
415void __kprobes arch_disarm_kprobe(struct kprobe *p) 419void arch_disarm_kprobe(struct kprobe *p)
416{ 420{
417 text_poke(p->addr, &p->opcode, 1); 421 text_poke(p->addr, &p->opcode, 1);
418} 422}
419 423
420void __kprobes arch_remove_kprobe(struct kprobe *p) 424void arch_remove_kprobe(struct kprobe *p)
421{ 425{
422 if (p->ainsn.insn) { 426 if (p->ainsn.insn) {
423 free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1)); 427 free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
@@ -425,7 +429,8 @@ void __kprobes arch_remove_kprobe(struct kprobe *p)
425 } 429 }
426} 430}
427 431
428static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) 432static nokprobe_inline void
433save_previous_kprobe(struct kprobe_ctlblk *kcb)
429{ 434{
430 kcb->prev_kprobe.kp = kprobe_running(); 435 kcb->prev_kprobe.kp = kprobe_running();
431 kcb->prev_kprobe.status = kcb->kprobe_status; 436 kcb->prev_kprobe.status = kcb->kprobe_status;
@@ -433,7 +438,8 @@ static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
433 kcb->prev_kprobe.saved_flags = kcb->kprobe_saved_flags; 438 kcb->prev_kprobe.saved_flags = kcb->kprobe_saved_flags;
434} 439}
435 440
436static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb) 441static nokprobe_inline void
442restore_previous_kprobe(struct kprobe_ctlblk *kcb)
437{ 443{
438 __this_cpu_write(current_kprobe, kcb->prev_kprobe.kp); 444 __this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
439 kcb->kprobe_status = kcb->prev_kprobe.status; 445 kcb->kprobe_status = kcb->prev_kprobe.status;
@@ -441,8 +447,9 @@ static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
441 kcb->kprobe_saved_flags = kcb->prev_kprobe.saved_flags; 447 kcb->kprobe_saved_flags = kcb->prev_kprobe.saved_flags;
442} 448}
443 449
444static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs, 450static nokprobe_inline void
445 struct kprobe_ctlblk *kcb) 451set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
452 struct kprobe_ctlblk *kcb)
446{ 453{
447 __this_cpu_write(current_kprobe, p); 454 __this_cpu_write(current_kprobe, p);
448 kcb->kprobe_saved_flags = kcb->kprobe_old_flags 455 kcb->kprobe_saved_flags = kcb->kprobe_old_flags
@@ -451,7 +458,7 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
451 kcb->kprobe_saved_flags &= ~X86_EFLAGS_IF; 458 kcb->kprobe_saved_flags &= ~X86_EFLAGS_IF;
452} 459}
453 460
454static void __kprobes clear_btf(void) 461static nokprobe_inline void clear_btf(void)
455{ 462{
456 if (test_thread_flag(TIF_BLOCKSTEP)) { 463 if (test_thread_flag(TIF_BLOCKSTEP)) {
457 unsigned long debugctl = get_debugctlmsr(); 464 unsigned long debugctl = get_debugctlmsr();
@@ -461,7 +468,7 @@ static void __kprobes clear_btf(void)
461 } 468 }
462} 469}
463 470
464static void __kprobes restore_btf(void) 471static nokprobe_inline void restore_btf(void)
465{ 472{
466 if (test_thread_flag(TIF_BLOCKSTEP)) { 473 if (test_thread_flag(TIF_BLOCKSTEP)) {
467 unsigned long debugctl = get_debugctlmsr(); 474 unsigned long debugctl = get_debugctlmsr();
@@ -471,8 +478,7 @@ static void __kprobes restore_btf(void)
471 } 478 }
472} 479}
473 480
474void __kprobes 481void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
475arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
476{ 482{
477 unsigned long *sara = stack_addr(regs); 483 unsigned long *sara = stack_addr(regs);
478 484
@@ -481,9 +487,10 @@ arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
481 /* Replace the return addr with trampoline addr */ 487 /* Replace the return addr with trampoline addr */
482 *sara = (unsigned long) &kretprobe_trampoline; 488 *sara = (unsigned long) &kretprobe_trampoline;
483} 489}
490NOKPROBE_SYMBOL(arch_prepare_kretprobe);
484 491
485static void __kprobes 492static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
486setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb, int reenter) 493 struct kprobe_ctlblk *kcb, int reenter)
487{ 494{
488 if (setup_detour_execution(p, regs, reenter)) 495 if (setup_detour_execution(p, regs, reenter))
489 return; 496 return;
@@ -519,22 +526,24 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
519 else 526 else
520 regs->ip = (unsigned long)p->ainsn.insn; 527 regs->ip = (unsigned long)p->ainsn.insn;
521} 528}
529NOKPROBE_SYMBOL(setup_singlestep);
522 530
523/* 531/*
524 * We have reentered the kprobe_handler(), since another probe was hit while 532 * We have reentered the kprobe_handler(), since another probe was hit while
525 * within the handler. We save the original kprobes variables and just single 533 * within the handler. We save the original kprobes variables and just single
526 * step on the instruction of the new probe without calling any user handlers. 534 * step on the instruction of the new probe without calling any user handlers.
527 */ 535 */
528static int __kprobes 536static int reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
529reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb) 537 struct kprobe_ctlblk *kcb)
530{ 538{
531 switch (kcb->kprobe_status) { 539 switch (kcb->kprobe_status) {
532 case KPROBE_HIT_SSDONE: 540 case KPROBE_HIT_SSDONE:
533 case KPROBE_HIT_ACTIVE: 541 case KPROBE_HIT_ACTIVE:
542 case KPROBE_HIT_SS:
534 kprobes_inc_nmissed_count(p); 543 kprobes_inc_nmissed_count(p);
535 setup_singlestep(p, regs, kcb, 1); 544 setup_singlestep(p, regs, kcb, 1);
536 break; 545 break;
537 case KPROBE_HIT_SS: 546 case KPROBE_REENTER:
538 /* A probe has been hit in the codepath leading up to, or just 547 /* A probe has been hit in the codepath leading up to, or just
539 * after, single-stepping of a probed instruction. This entire 548 * after, single-stepping of a probed instruction. This entire
540 * codepath should strictly reside in .kprobes.text section. 549 * codepath should strictly reside in .kprobes.text section.
@@ -553,12 +562,13 @@ reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb
553 562
554 return 1; 563 return 1;
555} 564}
565NOKPROBE_SYMBOL(reenter_kprobe);
556 566
557/* 567/*
558 * Interrupts are disabled on entry as trap3 is an interrupt gate and they 568 * Interrupts are disabled on entry as trap3 is an interrupt gate and they
559 * remain disabled throughout this function. 569 * remain disabled throughout this function.
560 */ 570 */
561static int __kprobes kprobe_handler(struct pt_regs *regs) 571int kprobe_int3_handler(struct pt_regs *regs)
562{ 572{
563 kprobe_opcode_t *addr; 573 kprobe_opcode_t *addr;
564 struct kprobe *p; 574 struct kprobe *p;
@@ -621,12 +631,13 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
621 preempt_enable_no_resched(); 631 preempt_enable_no_resched();
622 return 0; 632 return 0;
623} 633}
634NOKPROBE_SYMBOL(kprobe_int3_handler);
624 635
625/* 636/*
626 * When a retprobed function returns, this code saves registers and 637 * When a retprobed function returns, this code saves registers and
627 * calls trampoline_handler() runs, which calls the kretprobe's handler. 638 * calls trampoline_handler() runs, which calls the kretprobe's handler.
628 */ 639 */
629static void __used __kprobes kretprobe_trampoline_holder(void) 640static void __used kretprobe_trampoline_holder(void)
630{ 641{
631 asm volatile ( 642 asm volatile (
632 ".global kretprobe_trampoline\n" 643 ".global kretprobe_trampoline\n"
@@ -657,11 +668,13 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
657#endif 668#endif
658 " ret\n"); 669 " ret\n");
659} 670}
671NOKPROBE_SYMBOL(kretprobe_trampoline_holder);
672NOKPROBE_SYMBOL(kretprobe_trampoline);
660 673
661/* 674/*
662 * Called from kretprobe_trampoline 675 * Called from kretprobe_trampoline
663 */ 676 */
664__visible __used __kprobes void *trampoline_handler(struct pt_regs *regs) 677__visible __used void *trampoline_handler(struct pt_regs *regs)
665{ 678{
666 struct kretprobe_instance *ri = NULL; 679 struct kretprobe_instance *ri = NULL;
667 struct hlist_head *head, empty_rp; 680 struct hlist_head *head, empty_rp;
@@ -747,6 +760,7 @@ __visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
747 } 760 }
748 return (void *)orig_ret_address; 761 return (void *)orig_ret_address;
749} 762}
763NOKPROBE_SYMBOL(trampoline_handler);
750 764
751/* 765/*
752 * Called after single-stepping. p->addr is the address of the 766 * Called after single-stepping. p->addr is the address of the
@@ -775,8 +789,8 @@ __visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
775 * jump instruction after the copied instruction, that jumps to the next 789 * jump instruction after the copied instruction, that jumps to the next
776 * instruction after the probepoint. 790 * instruction after the probepoint.
777 */ 791 */
778static void __kprobes 792static void resume_execution(struct kprobe *p, struct pt_regs *regs,
779resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb) 793 struct kprobe_ctlblk *kcb)
780{ 794{
781 unsigned long *tos = stack_addr(regs); 795 unsigned long *tos = stack_addr(regs);
782 unsigned long copy_ip = (unsigned long)p->ainsn.insn; 796 unsigned long copy_ip = (unsigned long)p->ainsn.insn;
@@ -851,12 +865,13 @@ resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
851no_change: 865no_change:
852 restore_btf(); 866 restore_btf();
853} 867}
868NOKPROBE_SYMBOL(resume_execution);
854 869
855/* 870/*
856 * Interrupts are disabled on entry as trap1 is an interrupt gate and they 871 * Interrupts are disabled on entry as trap1 is an interrupt gate and they
857 * remain disabled throughout this function. 872 * remain disabled throughout this function.
858 */ 873 */
859static int __kprobes post_kprobe_handler(struct pt_regs *regs) 874int kprobe_debug_handler(struct pt_regs *regs)
860{ 875{
861 struct kprobe *cur = kprobe_running(); 876 struct kprobe *cur = kprobe_running();
862 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 877 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -891,8 +906,9 @@ out:
891 906
892 return 1; 907 return 1;
893} 908}
909NOKPROBE_SYMBOL(kprobe_debug_handler);
894 910
895int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr) 911int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
896{ 912{
897 struct kprobe *cur = kprobe_running(); 913 struct kprobe *cur = kprobe_running();
898 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 914 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -949,12 +965,13 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
949 965
950 return 0; 966 return 0;
951} 967}
968NOKPROBE_SYMBOL(kprobe_fault_handler);
952 969
953/* 970/*
954 * Wrapper routine for handling exceptions. 971 * Wrapper routine for handling exceptions.
955 */ 972 */
956int __kprobes 973int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
957kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *data) 974 void *data)
958{ 975{
959 struct die_args *args = data; 976 struct die_args *args = data;
960 int ret = NOTIFY_DONE; 977 int ret = NOTIFY_DONE;
@@ -962,22 +979,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
962 if (args->regs && user_mode_vm(args->regs)) 979 if (args->regs && user_mode_vm(args->regs))
963 return ret; 980 return ret;
964 981
965 switch (val) { 982 if (val == DIE_GPF) {
966 case DIE_INT3:
967 if (kprobe_handler(args->regs))
968 ret = NOTIFY_STOP;
969 break;
970 case DIE_DEBUG:
971 if (post_kprobe_handler(args->regs)) {
972 /*
973 * Reset the BS bit in dr6 (pointed by args->err) to
974 * denote completion of processing
975 */
976 (*(unsigned long *)ERR_PTR(args->err)) &= ~DR_STEP;
977 ret = NOTIFY_STOP;
978 }
979 break;
980 case DIE_GPF:
981 /* 983 /*
982 * To be potentially processing a kprobe fault and to 984 * To be potentially processing a kprobe fault and to
983 * trust the result from kprobe_running(), we have 985 * trust the result from kprobe_running(), we have
@@ -986,14 +988,12 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
986 if (!preemptible() && kprobe_running() && 988 if (!preemptible() && kprobe_running() &&
987 kprobe_fault_handler(args->regs, args->trapnr)) 989 kprobe_fault_handler(args->regs, args->trapnr))
988 ret = NOTIFY_STOP; 990 ret = NOTIFY_STOP;
989 break;
990 default:
991 break;
992 } 991 }
993 return ret; 992 return ret;
994} 993}
994NOKPROBE_SYMBOL(kprobe_exceptions_notify);
995 995
996int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 996int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
997{ 997{
998 struct jprobe *jp = container_of(p, struct jprobe, kp); 998 struct jprobe *jp = container_of(p, struct jprobe, kp);
999 unsigned long addr; 999 unsigned long addr;
@@ -1017,8 +1017,9 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
1017 regs->ip = (unsigned long)(jp->entry); 1017 regs->ip = (unsigned long)(jp->entry);
1018 return 1; 1018 return 1;
1019} 1019}
1020NOKPROBE_SYMBOL(setjmp_pre_handler);
1020 1021
1021void __kprobes jprobe_return(void) 1022void jprobe_return(void)
1022{ 1023{
1023 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 1024 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
1024 1025
@@ -1034,8 +1035,10 @@ void __kprobes jprobe_return(void)
1034 " nop \n"::"b" 1035 " nop \n"::"b"
1035 (kcb->jprobe_saved_sp):"memory"); 1036 (kcb->jprobe_saved_sp):"memory");
1036} 1037}
1038NOKPROBE_SYMBOL(jprobe_return);
1039NOKPROBE_SYMBOL(jprobe_return_end);
1037 1040
1038int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) 1041int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
1039{ 1042{
1040 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 1043 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
1041 u8 *addr = (u8 *) (regs->ip - 1); 1044 u8 *addr = (u8 *) (regs->ip - 1);
@@ -1063,13 +1066,22 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
1063 } 1066 }
1064 return 0; 1067 return 0;
1065} 1068}
1069NOKPROBE_SYMBOL(longjmp_break_handler);
1070
1071bool arch_within_kprobe_blacklist(unsigned long addr)
1072{
1073 return (addr >= (unsigned long)__kprobes_text_start &&
1074 addr < (unsigned long)__kprobes_text_end) ||
1075 (addr >= (unsigned long)__entry_text_start &&
1076 addr < (unsigned long)__entry_text_end);
1077}
1066 1078
1067int __init arch_init_kprobes(void) 1079int __init arch_init_kprobes(void)
1068{ 1080{
1069 return 0; 1081 return 0;
1070} 1082}
1071 1083
1072int __kprobes arch_trampoline_kprobe(struct kprobe *p) 1084int arch_trampoline_kprobe(struct kprobe *p)
1073{ 1085{
1074 return 0; 1086 return 0;
1075} 1087}
diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c
index 23ef5c556f06..717b02a22e67 100644
--- a/arch/x86/kernel/kprobes/ftrace.c
+++ b/arch/x86/kernel/kprobes/ftrace.c
@@ -25,8 +25,9 @@
25 25
26#include "common.h" 26#include "common.h"
27 27
28static int __skip_singlestep(struct kprobe *p, struct pt_regs *regs, 28static nokprobe_inline
29 struct kprobe_ctlblk *kcb) 29int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
30 struct kprobe_ctlblk *kcb)
30{ 31{
31 /* 32 /*
32 * Emulate singlestep (and also recover regs->ip) 33 * Emulate singlestep (and also recover regs->ip)
@@ -41,18 +42,19 @@ static int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
41 return 1; 42 return 1;
42} 43}
43 44
44int __kprobes skip_singlestep(struct kprobe *p, struct pt_regs *regs, 45int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
45 struct kprobe_ctlblk *kcb) 46 struct kprobe_ctlblk *kcb)
46{ 47{
47 if (kprobe_ftrace(p)) 48 if (kprobe_ftrace(p))
48 return __skip_singlestep(p, regs, kcb); 49 return __skip_singlestep(p, regs, kcb);
49 else 50 else
50 return 0; 51 return 0;
51} 52}
53NOKPROBE_SYMBOL(skip_singlestep);
52 54
53/* Ftrace callback handler for kprobes */ 55/* Ftrace callback handler for kprobes */
54void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, 56void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
55 struct ftrace_ops *ops, struct pt_regs *regs) 57 struct ftrace_ops *ops, struct pt_regs *regs)
56{ 58{
57 struct kprobe *p; 59 struct kprobe *p;
58 struct kprobe_ctlblk *kcb; 60 struct kprobe_ctlblk *kcb;
@@ -84,8 +86,9 @@ void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
84end: 86end:
85 local_irq_restore(flags); 87 local_irq_restore(flags);
86} 88}
89NOKPROBE_SYMBOL(kprobe_ftrace_handler);
87 90
88int __kprobes arch_prepare_kprobe_ftrace(struct kprobe *p) 91int arch_prepare_kprobe_ftrace(struct kprobe *p)
89{ 92{
90 p->ainsn.insn = NULL; 93 p->ainsn.insn = NULL;
91 p->ainsn.boostable = -1; 94 p->ainsn.boostable = -1;
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 898160b42e43..f304773285ae 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -77,7 +77,7 @@ found:
77} 77}
78 78
79/* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */ 79/* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
80static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val) 80static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
81{ 81{
82#ifdef CONFIG_X86_64 82#ifdef CONFIG_X86_64
83 *addr++ = 0x48; 83 *addr++ = 0x48;
@@ -138,7 +138,8 @@ asm (
138#define INT3_SIZE sizeof(kprobe_opcode_t) 138#define INT3_SIZE sizeof(kprobe_opcode_t)
139 139
140/* Optimized kprobe call back function: called from optinsn */ 140/* Optimized kprobe call back function: called from optinsn */
141static void __kprobes optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs) 141static void
142optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
142{ 143{
143 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 144 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
144 unsigned long flags; 145 unsigned long flags;
@@ -168,8 +169,9 @@ static void __kprobes optimized_callback(struct optimized_kprobe *op, struct pt_
168 } 169 }
169 local_irq_restore(flags); 170 local_irq_restore(flags);
170} 171}
172NOKPROBE_SYMBOL(optimized_callback);
171 173
172static int __kprobes copy_optimized_instructions(u8 *dest, u8 *src) 174static int copy_optimized_instructions(u8 *dest, u8 *src)
173{ 175{
174 int len = 0, ret; 176 int len = 0, ret;
175 177
@@ -189,7 +191,7 @@ static int __kprobes copy_optimized_instructions(u8 *dest, u8 *src)
189} 191}
190 192
191/* Check whether insn is indirect jump */ 193/* Check whether insn is indirect jump */
192static int __kprobes insn_is_indirect_jump(struct insn *insn) 194static int insn_is_indirect_jump(struct insn *insn)
193{ 195{
194 return ((insn->opcode.bytes[0] == 0xff && 196 return ((insn->opcode.bytes[0] == 0xff &&
195 (X86_MODRM_REG(insn->modrm.value) & 6) == 4) || /* Jump */ 197 (X86_MODRM_REG(insn->modrm.value) & 6) == 4) || /* Jump */
@@ -224,7 +226,7 @@ static int insn_jump_into_range(struct insn *insn, unsigned long start, int len)
224} 226}
225 227
226/* Decode whole function to ensure any instructions don't jump into target */ 228/* Decode whole function to ensure any instructions don't jump into target */
227static int __kprobes can_optimize(unsigned long paddr) 229static int can_optimize(unsigned long paddr)
228{ 230{
229 unsigned long addr, size = 0, offset = 0; 231 unsigned long addr, size = 0, offset = 0;
230 struct insn insn; 232 struct insn insn;
@@ -275,7 +277,7 @@ static int __kprobes can_optimize(unsigned long paddr)
275} 277}
276 278
277/* Check optimized_kprobe can actually be optimized. */ 279/* Check optimized_kprobe can actually be optimized. */
278int __kprobes arch_check_optimized_kprobe(struct optimized_kprobe *op) 280int arch_check_optimized_kprobe(struct optimized_kprobe *op)
279{ 281{
280 int i; 282 int i;
281 struct kprobe *p; 283 struct kprobe *p;
@@ -290,15 +292,15 @@ int __kprobes arch_check_optimized_kprobe(struct optimized_kprobe *op)
290} 292}
291 293
292/* Check the addr is within the optimized instructions. */ 294/* Check the addr is within the optimized instructions. */
293int __kprobes 295int arch_within_optimized_kprobe(struct optimized_kprobe *op,
294arch_within_optimized_kprobe(struct optimized_kprobe *op, unsigned long addr) 296 unsigned long addr)
295{ 297{
296 return ((unsigned long)op->kp.addr <= addr && 298 return ((unsigned long)op->kp.addr <= addr &&
297 (unsigned long)op->kp.addr + op->optinsn.size > addr); 299 (unsigned long)op->kp.addr + op->optinsn.size > addr);
298} 300}
299 301
300/* Free optimized instruction slot */ 302/* Free optimized instruction slot */
301static __kprobes 303static
302void __arch_remove_optimized_kprobe(struct optimized_kprobe *op, int dirty) 304void __arch_remove_optimized_kprobe(struct optimized_kprobe *op, int dirty)
303{ 305{
304 if (op->optinsn.insn) { 306 if (op->optinsn.insn) {
@@ -308,7 +310,7 @@ void __arch_remove_optimized_kprobe(struct optimized_kprobe *op, int dirty)
308 } 310 }
309} 311}
310 312
311void __kprobes arch_remove_optimized_kprobe(struct optimized_kprobe *op) 313void arch_remove_optimized_kprobe(struct optimized_kprobe *op)
312{ 314{
313 __arch_remove_optimized_kprobe(op, 1); 315 __arch_remove_optimized_kprobe(op, 1);
314} 316}
@@ -318,7 +320,7 @@ void __kprobes arch_remove_optimized_kprobe(struct optimized_kprobe *op)
318 * Target instructions MUST be relocatable (checked inside) 320 * Target instructions MUST be relocatable (checked inside)
319 * This is called when new aggr(opt)probe is allocated or reused. 321 * This is called when new aggr(opt)probe is allocated or reused.
320 */ 322 */
321int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op) 323int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
322{ 324{
323 u8 *buf; 325 u8 *buf;
324 int ret; 326 int ret;
@@ -372,7 +374,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
372 * Replace breakpoints (int3) with relative jumps. 374 * Replace breakpoints (int3) with relative jumps.
373 * Caller must call with locking kprobe_mutex and text_mutex. 375 * Caller must call with locking kprobe_mutex and text_mutex.
374 */ 376 */
375void __kprobes arch_optimize_kprobes(struct list_head *oplist) 377void arch_optimize_kprobes(struct list_head *oplist)
376{ 378{
377 struct optimized_kprobe *op, *tmp; 379 struct optimized_kprobe *op, *tmp;
378 u8 insn_buf[RELATIVEJUMP_SIZE]; 380 u8 insn_buf[RELATIVEJUMP_SIZE];
@@ -398,7 +400,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
398} 400}
399 401
400/* Replace a relative jump with a breakpoint (int3). */ 402/* Replace a relative jump with a breakpoint (int3). */
401void __kprobes arch_unoptimize_kprobe(struct optimized_kprobe *op) 403void arch_unoptimize_kprobe(struct optimized_kprobe *op)
402{ 404{
403 u8 insn_buf[RELATIVEJUMP_SIZE]; 405 u8 insn_buf[RELATIVEJUMP_SIZE];
404 406
@@ -424,8 +426,7 @@ extern void arch_unoptimize_kprobes(struct list_head *oplist,
424 } 426 }
425} 427}
426 428
427int __kprobes 429int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
428setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
429{ 430{
430 struct optimized_kprobe *op; 431 struct optimized_kprobe *op;
431 432
@@ -441,3 +442,4 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
441 } 442 }
442 return 0; 443 return 0;
443} 444}
445NOKPROBE_SYMBOL(setup_detour_execution);
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 0331cb389d68..d81abcbfe501 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -251,8 +251,9 @@ u32 kvm_read_and_reset_pf_reason(void)
251 return reason; 251 return reason;
252} 252}
253EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason); 253EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason);
254NOKPROBE_SYMBOL(kvm_read_and_reset_pf_reason);
254 255
255dotraplinkage void __kprobes 256dotraplinkage void
256do_async_page_fault(struct pt_regs *regs, unsigned long error_code) 257do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
257{ 258{
258 enum ctx_state prev_state; 259 enum ctx_state prev_state;
@@ -276,6 +277,7 @@ do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
276 break; 277 break;
277 } 278 }
278} 279}
280NOKPROBE_SYMBOL(do_async_page_fault);
279 281
280static void __init paravirt_ops_setup(void) 282static void __init paravirt_ops_setup(void)
281{ 283{
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index b4872b999a71..c3e985d1751c 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -110,7 +110,7 @@ static void nmi_max_handler(struct irq_work *w)
110 a->handler, whole_msecs, decimal_msecs); 110 a->handler, whole_msecs, decimal_msecs);
111} 111}
112 112
113static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b) 113static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
114{ 114{
115 struct nmi_desc *desc = nmi_to_desc(type); 115 struct nmi_desc *desc = nmi_to_desc(type);
116 struct nmiaction *a; 116 struct nmiaction *a;
@@ -146,6 +146,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
146 /* return total number of NMI events handled */ 146 /* return total number of NMI events handled */
147 return handled; 147 return handled;
148} 148}
149NOKPROBE_SYMBOL(nmi_handle);
149 150
150int __register_nmi_handler(unsigned int type, struct nmiaction *action) 151int __register_nmi_handler(unsigned int type, struct nmiaction *action)
151{ 152{
@@ -208,7 +209,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
208} 209}
209EXPORT_SYMBOL_GPL(unregister_nmi_handler); 210EXPORT_SYMBOL_GPL(unregister_nmi_handler);
210 211
211static __kprobes void 212static void
212pci_serr_error(unsigned char reason, struct pt_regs *regs) 213pci_serr_error(unsigned char reason, struct pt_regs *regs)
213{ 214{
214 /* check to see if anyone registered against these types of errors */ 215 /* check to see if anyone registered against these types of errors */
@@ -238,8 +239,9 @@ pci_serr_error(unsigned char reason, struct pt_regs *regs)
238 reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_SERR; 239 reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_SERR;
239 outb(reason, NMI_REASON_PORT); 240 outb(reason, NMI_REASON_PORT);
240} 241}
242NOKPROBE_SYMBOL(pci_serr_error);
241 243
242static __kprobes void 244static void
243io_check_error(unsigned char reason, struct pt_regs *regs) 245io_check_error(unsigned char reason, struct pt_regs *regs)
244{ 246{
245 unsigned long i; 247 unsigned long i;
@@ -269,8 +271,9 @@ io_check_error(unsigned char reason, struct pt_regs *regs)
269 reason &= ~NMI_REASON_CLEAR_IOCHK; 271 reason &= ~NMI_REASON_CLEAR_IOCHK;
270 outb(reason, NMI_REASON_PORT); 272 outb(reason, NMI_REASON_PORT);
271} 273}
274NOKPROBE_SYMBOL(io_check_error);
272 275
273static __kprobes void 276static void
274unknown_nmi_error(unsigned char reason, struct pt_regs *regs) 277unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
275{ 278{
276 int handled; 279 int handled;
@@ -298,11 +301,12 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
298 301
299 pr_emerg("Dazed and confused, but trying to continue\n"); 302 pr_emerg("Dazed and confused, but trying to continue\n");
300} 303}
304NOKPROBE_SYMBOL(unknown_nmi_error);
301 305
302static DEFINE_PER_CPU(bool, swallow_nmi); 306static DEFINE_PER_CPU(bool, swallow_nmi);
303static DEFINE_PER_CPU(unsigned long, last_nmi_rip); 307static DEFINE_PER_CPU(unsigned long, last_nmi_rip);
304 308
305static __kprobes void default_do_nmi(struct pt_regs *regs) 309static void default_do_nmi(struct pt_regs *regs)
306{ 310{
307 unsigned char reason = 0; 311 unsigned char reason = 0;
308 int handled; 312 int handled;
@@ -401,6 +405,7 @@ static __kprobes void default_do_nmi(struct pt_regs *regs)
401 else 405 else
402 unknown_nmi_error(reason, regs); 406 unknown_nmi_error(reason, regs);
403} 407}
408NOKPROBE_SYMBOL(default_do_nmi);
404 409
405/* 410/*
406 * NMIs can hit breakpoints which will cause it to lose its 411 * NMIs can hit breakpoints which will cause it to lose its
@@ -520,7 +525,7 @@ static inline void nmi_nesting_postprocess(void)
520} 525}
521#endif 526#endif
522 527
523dotraplinkage notrace __kprobes void 528dotraplinkage notrace void
524do_nmi(struct pt_regs *regs, long error_code) 529do_nmi(struct pt_regs *regs, long error_code)
525{ 530{
526 nmi_nesting_preprocess(regs); 531 nmi_nesting_preprocess(regs);
@@ -537,6 +542,7 @@ do_nmi(struct pt_regs *regs, long error_code)
537 /* On i386, may loop back to preprocess */ 542 /* On i386, may loop back to preprocess */
538 nmi_nesting_postprocess(); 543 nmi_nesting_postprocess();
539} 544}
545NOKPROBE_SYMBOL(do_nmi);
540 546
541void stop_nmi(void) 547void stop_nmi(void)
542{ 548{
diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
index 1b10af835c31..548d25f00c90 100644
--- a/arch/x86/kernel/paravirt.c
+++ b/arch/x86/kernel/paravirt.c
@@ -23,6 +23,7 @@
23#include <linux/efi.h> 23#include <linux/efi.h>
24#include <linux/bcd.h> 24#include <linux/bcd.h>
25#include <linux/highmem.h> 25#include <linux/highmem.h>
26#include <linux/kprobes.h>
26 27
27#include <asm/bug.h> 28#include <asm/bug.h>
28#include <asm/paravirt.h> 29#include <asm/paravirt.h>
@@ -389,6 +390,11 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
389 .end_context_switch = paravirt_nop, 390 .end_context_switch = paravirt_nop,
390}; 391};
391 392
393/* At this point, native_get/set_debugreg has real function entries */
394NOKPROBE_SYMBOL(native_get_debugreg);
395NOKPROBE_SYMBOL(native_set_debugreg);
396NOKPROBE_SYMBOL(native_load_idt);
397
392struct pv_apic_ops pv_apic_ops = { 398struct pv_apic_ops pv_apic_ops = {
393#ifdef CONFIG_X86_LOCAL_APIC 399#ifdef CONFIG_X86_LOCAL_APIC
394 .startup_ipi_hook = paravirt_nop, 400 .startup_ipi_hook = paravirt_nop,
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 3fdb20548c4b..461926b0577c 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -107,7 +107,7 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
107 preempt_count_dec(); 107 preempt_count_dec();
108} 108}
109 109
110static int __kprobes 110static nokprobe_inline int
111do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str, 111do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
112 struct pt_regs *regs, long error_code) 112 struct pt_regs *regs, long error_code)
113{ 113{
@@ -168,7 +168,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
168 return info; 168 return info;
169} 169}
170 170
171static void __kprobes 171static void
172do_trap(int trapnr, int signr, char *str, struct pt_regs *regs, 172do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
173 long error_code, siginfo_t *info) 173 long error_code, siginfo_t *info)
174{ 174{
@@ -202,6 +202,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
202 202
203 force_sig_info(signr, info ?: SEND_SIG_PRIV, tsk); 203 force_sig_info(signr, info ?: SEND_SIG_PRIV, tsk);
204} 204}
205NOKPROBE_SYMBOL(do_trap);
205 206
206static void do_error_trap(struct pt_regs *regs, long error_code, char *str, 207static void do_error_trap(struct pt_regs *regs, long error_code, char *str,
207 unsigned long trapnr, int signr) 208 unsigned long trapnr, int signr)
@@ -277,7 +278,7 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
277} 278}
278#endif 279#endif
279 280
280dotraplinkage void __kprobes 281dotraplinkage void
281do_general_protection(struct pt_regs *regs, long error_code) 282do_general_protection(struct pt_regs *regs, long error_code)
282{ 283{
283 struct task_struct *tsk; 284 struct task_struct *tsk;
@@ -323,9 +324,10 @@ do_general_protection(struct pt_regs *regs, long error_code)
323exit: 324exit:
324 exception_exit(prev_state); 325 exception_exit(prev_state);
325} 326}
327NOKPROBE_SYMBOL(do_general_protection);
326 328
327/* May run on IST stack. */ 329/* May run on IST stack. */
328dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_code) 330dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
329{ 331{
330 enum ctx_state prev_state; 332 enum ctx_state prev_state;
331 333
@@ -341,13 +343,18 @@ dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_co
341 if (poke_int3_handler(regs)) 343 if (poke_int3_handler(regs))
342 return; 344 return;
343 345
344 prev_state = exception_enter();
345#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP 346#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
346 if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP, 347 if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
347 SIGTRAP) == NOTIFY_STOP) 348 SIGTRAP) == NOTIFY_STOP)
348 goto exit; 349 goto exit;
349#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ 350#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
350 351
352#ifdef CONFIG_KPROBES
353 if (kprobe_int3_handler(regs))
354 return;
355#endif
356 prev_state = exception_enter();
357
351 if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP, 358 if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
352 SIGTRAP) == NOTIFY_STOP) 359 SIGTRAP) == NOTIFY_STOP)
353 goto exit; 360 goto exit;
@@ -364,6 +371,7 @@ dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_co
364exit: 371exit:
365 exception_exit(prev_state); 372 exception_exit(prev_state);
366} 373}
374NOKPROBE_SYMBOL(do_int3);
367 375
368#ifdef CONFIG_X86_64 376#ifdef CONFIG_X86_64
369/* 377/*
@@ -371,7 +379,7 @@ exit:
371 * for scheduling or signal handling. The actual stack switch is done in 379 * for scheduling or signal handling. The actual stack switch is done in
372 * entry.S 380 * entry.S
373 */ 381 */
374asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs) 382asmlinkage struct pt_regs *sync_regs(struct pt_regs *eregs)
375{ 383{
376 struct pt_regs *regs = eregs; 384 struct pt_regs *regs = eregs;
377 /* Did already sync */ 385 /* Did already sync */
@@ -390,6 +398,7 @@ asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
390 *regs = *eregs; 398 *regs = *eregs;
391 return regs; 399 return regs;
392} 400}
401NOKPROBE_SYMBOL(sync_regs);
393#endif 402#endif
394 403
395/* 404/*
@@ -416,7 +425,7 @@ asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
416 * 425 *
417 * May run on IST stack. 426 * May run on IST stack.
418 */ 427 */
419dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code) 428dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
420{ 429{
421 struct task_struct *tsk = current; 430 struct task_struct *tsk = current;
422 enum ctx_state prev_state; 431 enum ctx_state prev_state;
@@ -424,8 +433,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
424 unsigned long dr6; 433 unsigned long dr6;
425 int si_code; 434 int si_code;
426 435
427 prev_state = exception_enter();
428
429 get_debugreg(dr6, 6); 436 get_debugreg(dr6, 6);
430 437
431 /* Filter out all the reserved bits which are preset to 1 */ 438 /* Filter out all the reserved bits which are preset to 1 */
@@ -454,6 +461,12 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
454 /* Store the virtualized DR6 value */ 461 /* Store the virtualized DR6 value */
455 tsk->thread.debugreg6 = dr6; 462 tsk->thread.debugreg6 = dr6;
456 463
464#ifdef CONFIG_KPROBES
465 if (kprobe_debug_handler(regs))
466 goto exit;
467#endif
468 prev_state = exception_enter();
469
457 if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code, 470 if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code,
458 SIGTRAP) == NOTIFY_STOP) 471 SIGTRAP) == NOTIFY_STOP)
459 goto exit; 472 goto exit;
@@ -496,6 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
496exit: 509exit:
497 exception_exit(prev_state); 510 exception_exit(prev_state);
498} 511}
512NOKPROBE_SYMBOL(do_debug);
499 513
500/* 514/*
501 * Note that we play around with the 'TS' bit in an attempt to get 515 * Note that we play around with the 'TS' bit in an attempt to get
@@ -667,7 +681,7 @@ void math_state_restore(void)
667} 681}
668EXPORT_SYMBOL_GPL(math_state_restore); 682EXPORT_SYMBOL_GPL(math_state_restore);
669 683
670dotraplinkage void __kprobes 684dotraplinkage void
671do_device_not_available(struct pt_regs *regs, long error_code) 685do_device_not_available(struct pt_regs *regs, long error_code)
672{ 686{
673 enum ctx_state prev_state; 687 enum ctx_state prev_state;
@@ -693,6 +707,7 @@ do_device_not_available(struct pt_regs *regs, long error_code)
693#endif 707#endif
694 exception_exit(prev_state); 708 exception_exit(prev_state);
695} 709}
710NOKPROBE_SYMBOL(do_device_not_available);
696 711
697#ifdef CONFIG_X86_32 712#ifdef CONFIG_X86_32
698dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) 713dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
diff --git a/arch/x86/lib/thunk_32.S b/arch/x86/lib/thunk_32.S
index 2930ae05d773..28f85c916712 100644
--- a/arch/x86/lib/thunk_32.S
+++ b/arch/x86/lib/thunk_32.S
@@ -4,8 +4,8 @@
4 * (inspired by Andi Kleen's thunk_64.S) 4 * (inspired by Andi Kleen's thunk_64.S)
5 * Subject to the GNU public license, v.2. No warranty of any kind. 5 * Subject to the GNU public license, v.2. No warranty of any kind.
6 */ 6 */
7
8 #include <linux/linkage.h> 7 #include <linux/linkage.h>
8 #include <asm/asm.h>
9 9
10#ifdef CONFIG_TRACE_IRQFLAGS 10#ifdef CONFIG_TRACE_IRQFLAGS
11 /* put return address in eax (arg1) */ 11 /* put return address in eax (arg1) */
@@ -22,6 +22,7 @@
22 popl %ecx 22 popl %ecx
23 popl %eax 23 popl %eax
24 ret 24 ret
25 _ASM_NOKPROBE(\name)
25 .endm 26 .endm
26 27
27 thunk_ra trace_hardirqs_on_thunk,trace_hardirqs_on_caller 28 thunk_ra trace_hardirqs_on_thunk,trace_hardirqs_on_caller
diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
index a63efd6bb6a5..92d9feaff42b 100644
--- a/arch/x86/lib/thunk_64.S
+++ b/arch/x86/lib/thunk_64.S
@@ -8,6 +8,7 @@
8#include <linux/linkage.h> 8#include <linux/linkage.h>
9#include <asm/dwarf2.h> 9#include <asm/dwarf2.h>
10#include <asm/calling.h> 10#include <asm/calling.h>
11#include <asm/asm.h>
11 12
12 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */ 13 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
13 .macro THUNK name, func, put_ret_addr_in_rdi=0 14 .macro THUNK name, func, put_ret_addr_in_rdi=0
@@ -25,6 +26,7 @@
25 call \func 26 call \func
26 jmp restore 27 jmp restore
27 CFI_ENDPROC 28 CFI_ENDPROC
29 _ASM_NOKPROBE(\name)
28 .endm 30 .endm
29 31
30#ifdef CONFIG_TRACE_IRQFLAGS 32#ifdef CONFIG_TRACE_IRQFLAGS
@@ -43,3 +45,4 @@ restore:
43 RESTORE_ARGS 45 RESTORE_ARGS
44 ret 46 ret
45 CFI_ENDPROC 47 CFI_ENDPROC
48 _ASM_NOKPROBE(restore)
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 8e5722992677..f83bd0de5eef 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -8,7 +8,7 @@
8#include <linux/kdebug.h> /* oops_begin/end, ... */ 8#include <linux/kdebug.h> /* oops_begin/end, ... */
9#include <linux/module.h> /* search_exception_table */ 9#include <linux/module.h> /* search_exception_table */
10#include <linux/bootmem.h> /* max_low_pfn */ 10#include <linux/bootmem.h> /* max_low_pfn */
11#include <linux/kprobes.h> /* __kprobes, ... */ 11#include <linux/kprobes.h> /* NOKPROBE_SYMBOL, ... */
12#include <linux/mmiotrace.h> /* kmmio_handler, ... */ 12#include <linux/mmiotrace.h> /* kmmio_handler, ... */
13#include <linux/perf_event.h> /* perf_sw_event */ 13#include <linux/perf_event.h> /* perf_sw_event */
14#include <linux/hugetlb.h> /* hstate_index_to_shift */ 14#include <linux/hugetlb.h> /* hstate_index_to_shift */
@@ -45,7 +45,7 @@ enum x86_pf_error_code {
45 * Returns 0 if mmiotrace is disabled, or if the fault is not 45 * Returns 0 if mmiotrace is disabled, or if the fault is not
46 * handled by mmiotrace: 46 * handled by mmiotrace:
47 */ 47 */
48static inline int __kprobes 48static nokprobe_inline int
49kmmio_fault(struct pt_regs *regs, unsigned long addr) 49kmmio_fault(struct pt_regs *regs, unsigned long addr)
50{ 50{
51 if (unlikely(is_kmmio_active())) 51 if (unlikely(is_kmmio_active()))
@@ -54,7 +54,7 @@ kmmio_fault(struct pt_regs *regs, unsigned long addr)
54 return 0; 54 return 0;
55} 55}
56 56
57static inline int __kprobes kprobes_fault(struct pt_regs *regs) 57static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
58{ 58{
59 int ret = 0; 59 int ret = 0;
60 60
@@ -261,7 +261,7 @@ void vmalloc_sync_all(void)
261 * 261 *
262 * Handle a fault on the vmalloc or module mapping area 262 * Handle a fault on the vmalloc or module mapping area
263 */ 263 */
264static noinline __kprobes int vmalloc_fault(unsigned long address) 264static noinline int vmalloc_fault(unsigned long address)
265{ 265{
266 unsigned long pgd_paddr; 266 unsigned long pgd_paddr;
267 pmd_t *pmd_k; 267 pmd_t *pmd_k;
@@ -291,6 +291,7 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
291 291
292 return 0; 292 return 0;
293} 293}
294NOKPROBE_SYMBOL(vmalloc_fault);
294 295
295/* 296/*
296 * Did it hit the DOS screen memory VA from vm86 mode? 297 * Did it hit the DOS screen memory VA from vm86 mode?
@@ -358,7 +359,7 @@ void vmalloc_sync_all(void)
358 * 359 *
359 * This assumes no large pages in there. 360 * This assumes no large pages in there.
360 */ 361 */
361static noinline __kprobes int vmalloc_fault(unsigned long address) 362static noinline int vmalloc_fault(unsigned long address)
362{ 363{
363 pgd_t *pgd, *pgd_ref; 364 pgd_t *pgd, *pgd_ref;
364 pud_t *pud, *pud_ref; 365 pud_t *pud, *pud_ref;
@@ -425,6 +426,7 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
425 426
426 return 0; 427 return 0;
427} 428}
429NOKPROBE_SYMBOL(vmalloc_fault);
428 430
429#ifdef CONFIG_CPU_SUP_AMD 431#ifdef CONFIG_CPU_SUP_AMD
430static const char errata93_warning[] = 432static const char errata93_warning[] =
@@ -927,7 +929,7 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
927 * There are no security implications to leaving a stale TLB when 929 * There are no security implications to leaving a stale TLB when
928 * increasing the permissions on a page. 930 * increasing the permissions on a page.
929 */ 931 */
930static noinline __kprobes int 932static noinline int
931spurious_fault(unsigned long error_code, unsigned long address) 933spurious_fault(unsigned long error_code, unsigned long address)
932{ 934{
933 pgd_t *pgd; 935 pgd_t *pgd;
@@ -975,6 +977,7 @@ spurious_fault(unsigned long error_code, unsigned long address)
975 977
976 return ret; 978 return ret;
977} 979}
980NOKPROBE_SYMBOL(spurious_fault);
978 981
979int show_unhandled_signals = 1; 982int show_unhandled_signals = 1;
980 983
@@ -1030,7 +1033,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
1030 * {,trace_}do_page_fault() have notrace on. Having this an actual function 1033 * {,trace_}do_page_fault() have notrace on. Having this an actual function
1031 * guarantees there's a function trace entry. 1034 * guarantees there's a function trace entry.
1032 */ 1035 */
1033static void __kprobes noinline 1036static noinline void
1034__do_page_fault(struct pt_regs *regs, unsigned long error_code, 1037__do_page_fault(struct pt_regs *regs, unsigned long error_code,
1035 unsigned long address) 1038 unsigned long address)
1036{ 1039{
@@ -1253,8 +1256,9 @@ good_area:
1253 1256
1254 up_read(&mm->mmap_sem); 1257 up_read(&mm->mmap_sem);
1255} 1258}
1259NOKPROBE_SYMBOL(__do_page_fault);
1256 1260
1257dotraplinkage void __kprobes notrace 1261dotraplinkage void notrace
1258do_page_fault(struct pt_regs *regs, unsigned long error_code) 1262do_page_fault(struct pt_regs *regs, unsigned long error_code)
1259{ 1263{
1260 unsigned long address = read_cr2(); /* Get the faulting address */ 1264 unsigned long address = read_cr2(); /* Get the faulting address */
@@ -1272,10 +1276,12 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
1272 __do_page_fault(regs, error_code, address); 1276 __do_page_fault(regs, error_code, address);
1273 exception_exit(prev_state); 1277 exception_exit(prev_state);
1274} 1278}
1279NOKPROBE_SYMBOL(do_page_fault);
1275 1280
1276#ifdef CONFIG_TRACING 1281#ifdef CONFIG_TRACING
1277static void trace_page_fault_entries(unsigned long address, struct pt_regs *regs, 1282static nokprobe_inline void
1278 unsigned long error_code) 1283trace_page_fault_entries(unsigned long address, struct pt_regs *regs,
1284 unsigned long error_code)
1279{ 1285{
1280 if (user_mode(regs)) 1286 if (user_mode(regs))
1281 trace_page_fault_user(address, regs, error_code); 1287 trace_page_fault_user(address, regs, error_code);
@@ -1283,7 +1289,7 @@ static void trace_page_fault_entries(unsigned long address, struct pt_regs *regs
1283 trace_page_fault_kernel(address, regs, error_code); 1289 trace_page_fault_kernel(address, regs, error_code);
1284} 1290}
1285 1291
1286dotraplinkage void __kprobes notrace 1292dotraplinkage void notrace
1287trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) 1293trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
1288{ 1294{
1289 /* 1295 /*
@@ -1300,4 +1306,5 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
1300 __do_page_fault(regs, error_code, address); 1306 __do_page_fault(regs, error_code, address);
1301 exception_exit(prev_state); 1307 exception_exit(prev_state);
1302} 1308}
1309NOKPROBE_SYMBOL(trace_do_page_fault);
1303#endif /* CONFIG_TRACING */ 1310#endif /* CONFIG_TRACING */