Skip to content

Commit 9326638

Browse files
mhiramathitachiingomolnar
authored andcommitted
kprobes, x86: Use NOKPROBE_SYMBOL() instead of __kprobes annotation
Use NOKPROBE_SYMBOL macro for protecting functions from kprobes instead of __kprobes annotation under arch/x86. This applies nokprobe_inline annotation for some cases, because NOKPROBE_SYMBOL() will inhibit inlining by referring the symbol address. This just folds a bunch of previous NOKPROBE_SYMBOL() cleanup patches for x86 to one patch. Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Link: http://lkml.kernel.org/r/20140417081814.26341.51656.stgit@ltc230.yrl.intra.hitachi.co.jp Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Borislav Petkov <bp@suse.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Fernando Luis Vázquez Cao <fernando_b1@lab.ntt.co.jp> Cc: Gleb Natapov <gleb@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Jesper Nilsson <jesper.nilsson@axis.com> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Jiri Slaby <jslaby@suse.cz> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Jonathan Lebon <jlebon@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Matt Fleming <matt.fleming@intel.com> Cc: Michel Lespinasse <walken@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Seiji Aguchi <seiji.aguchi@hds.com> Cc: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com> Cc: Tejun Heo <tj@kernel.org> Cc: Vineet Gupta <vgupta@synopsys.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 9c54b61 commit 9326638

12 files changed

Lines changed: 122 additions & 69 deletions

File tree

‎arch/x86/include/asm/traps.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dotraplinkage void do_segment_not_present(struct pt_regs *, long);
6868
dotraplinkage void do_stack_segment(struct pt_regs *, long);
6969
#ifdef CONFIG_X86_64
7070
dotraplinkage void do_double_fault(struct pt_regs *, long);
71-
asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *);
71+
asmlinkage struct pt_regs *sync_regs(struct pt_regs *);
7272
#endif
7373
dotraplinkage void do_general_protection(struct pt_regs *, long);
7474
dotraplinkage void do_page_fault(struct pt_regs *, unsigned long);

‎arch/x86/kernel/apic/hw_nmi.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void arch_trigger_all_cpu_backtrace(void)
6060
smp_mb__after_clear_bit();
6161
}
6262

63-
static int __kprobes
63+
static int
6464
arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
6565
{
6666
int cpu;
@@ -80,6 +80,7 @@ arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
8080

8181
return NMI_DONE;
8282
}
83+
NOKPROBE_SYMBOL(arch_trigger_all_cpu_backtrace_handler);
8384

8485
static int __init register_trigger_all_cpu_backtrace(void)
8586
{

‎arch/x86/kernel/cpu/perf_event.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ void perf_events_lapic_init(void)
12921292
apic_write(APIC_LVTPC, APIC_DM_NMI);
12931293
}
12941294

1295-
static int __kprobes
1295+
static int
12961296
perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
12971297
{
12981298
u64 start_clock;
@@ -1310,6 +1310,7 @@ perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
13101310

13111311
return ret;
13121312
}
1313+
NOKPROBE_SYMBOL(perf_event_nmi_handler);
13131314

13141315
struct event_constraint emptyconstraint;
13151316
struct event_constraint unconstrained;

‎arch/x86/kernel/cpu/perf_event_amd_ibs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
593593
return 1;
594594
}
595595

596-
static int __kprobes
596+
static int
597597
perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
598598
{
599599
int handled = 0;
@@ -606,6 +606,7 @@ perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
606606

607607
return handled;
608608
}
609+
NOKPROBE_SYMBOL(perf_ibs_nmi_handler);
609610

610611
static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name)
611612
{

‎arch/x86/kernel/dumpstack.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
200200
static int die_owner = -1;
201201
static unsigned int die_nest_count;
202202

203-
unsigned __kprobes long oops_begin(void)
203+
unsigned long oops_begin(void)
204204
{
205205
int cpu;
206206
unsigned long flags;
@@ -223,8 +223,9 @@ unsigned __kprobes long oops_begin(void)
223223
return flags;
224224
}
225225
EXPORT_SYMBOL_GPL(oops_begin);
226+
NOKPROBE_SYMBOL(oops_begin);
226227

227-
void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
228+
void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
228229
{
229230
if (regs && kexec_should_crash(current))
230231
crash_kexec(regs);
@@ -247,8 +248,9 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
247248
panic("Fatal exception");
248249
do_exit(signr);
249250
}
251+
NOKPROBE_SYMBOL(oops_end);
250252

251-
int __kprobes __die(const char *str, struct pt_regs *regs, long err)
253+
int __die(const char *str, struct pt_regs *regs, long err)
252254
{
253255
#ifdef CONFIG_X86_32
254256
unsigned short ss;
@@ -291,6 +293,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
291293
#endif
292294
return 0;
293295
}
296+
NOKPROBE_SYMBOL(__die);
294297

295298
/*
296299
* This is gone through when something in the kernel has done something bad

‎arch/x86/kernel/kprobes/core.c‎

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ struct kretprobe_blackpoint kretprobe_blacklist[] = {
112112

113113
const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
114114

115-
static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
115+
static nokprobe_inline void
116+
__synthesize_relative_insn(void *from, void *to, u8 op)
116117
{
117118
struct __arch_relative_insn {
118119
u8 op;
@@ -125,21 +126,23 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
125126
}
126127

127128
/* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
128-
void __kprobes synthesize_reljump(void *from, void *to)
129+
void synthesize_reljump(void *from, void *to)
129130
{
130131
__synthesize_relative_insn(from, to, RELATIVEJUMP_OPCODE);
131132
}
133+
NOKPROBE_SYMBOL(synthesize_reljump);
132134

133135
/* Insert a call instruction at address 'from', which calls address 'to'.*/
134-
void __kprobes synthesize_relcall(void *from, void *to)
136+
void synthesize_relcall(void *from, void *to)
135137
{
136138
__synthesize_relative_insn(from, to, RELATIVECALL_OPCODE);
137139
}
140+
NOKPROBE_SYMBOL(synthesize_relcall);
138141

139142
/*
140143
* Skip the prefixes of the instruction.
141144
*/
142-
static kprobe_opcode_t *__kprobes skip_prefixes(kprobe_opcode_t *insn)
145+
static kprobe_opcode_t *skip_prefixes(kprobe_opcode_t *insn)
143146
{
144147
insn_attr_t attr;
145148

@@ -154,6 +157,7 @@ static kprobe_opcode_t *__kprobes skip_prefixes(kprobe_opcode_t *insn)
154157
#endif
155158
return insn;
156159
}
160+
NOKPROBE_SYMBOL(skip_prefixes);
157161

158162
/*
159163
* Returns non-zero if opcode is boostable.
@@ -425,24 +429,27 @@ void arch_remove_kprobe(struct kprobe *p)
425429
}
426430
}
427431

428-
static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
432+
static nokprobe_inline void
433+
save_previous_kprobe(struct kprobe_ctlblk *kcb)
429434
{
430435
kcb->prev_kprobe.kp = kprobe_running();
431436
kcb->prev_kprobe.status = kcb->kprobe_status;
432437
kcb->prev_kprobe.old_flags = kcb->kprobe_old_flags;
433438
kcb->prev_kprobe.saved_flags = kcb->kprobe_saved_flags;
434439
}
435440

436-
static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
441+
static nokprobe_inline void
442+
restore_previous_kprobe(struct kprobe_ctlblk *kcb)
437443
{
438444
__this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
439445
kcb->kprobe_status = kcb->prev_kprobe.status;
440446
kcb->kprobe_old_flags = kcb->prev_kprobe.old_flags;
441447
kcb->kprobe_saved_flags = kcb->prev_kprobe.saved_flags;
442448
}
443449

444-
static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
445-
struct kprobe_ctlblk *kcb)
450+
static nokprobe_inline void
451+
set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
452+
struct kprobe_ctlblk *kcb)
446453
{
447454
__this_cpu_write(current_kprobe, p);
448455
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,
451458
kcb->kprobe_saved_flags &= ~X86_EFLAGS_IF;
452459
}
453460

454-
static void __kprobes clear_btf(void)
461+
static nokprobe_inline void clear_btf(void)
455462
{
456463
if (test_thread_flag(TIF_BLOCKSTEP)) {
457464
unsigned long debugctl = get_debugctlmsr();
@@ -461,7 +468,7 @@ static void __kprobes clear_btf(void)
461468
}
462469
}
463470

464-
static void __kprobes restore_btf(void)
471+
static nokprobe_inline void restore_btf(void)
465472
{
466473
if (test_thread_flag(TIF_BLOCKSTEP)) {
467474
unsigned long debugctl = get_debugctlmsr();
@@ -471,8 +478,7 @@ static void __kprobes restore_btf(void)
471478
}
472479
}
473480

474-
void __kprobes
475-
arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
481+
void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
476482
{
477483
unsigned long *sara = stack_addr(regs);
478484

@@ -481,9 +487,10 @@ arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
481487
/* Replace the return addr with trampoline addr */
482488
*sara = (unsigned long) &kretprobe_trampoline;
483489
}
490+
NOKPROBE_SYMBOL(arch_prepare_kretprobe);
484491

485-
static void __kprobes
486-
setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb, int reenter)
492+
static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
493+
struct kprobe_ctlblk *kcb, int reenter)
487494
{
488495
if (setup_detour_execution(p, regs, reenter))
489496
return;
@@ -519,14 +526,15 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
519526
else
520527
regs->ip = (unsigned long)p->ainsn.insn;
521528
}
529+
NOKPROBE_SYMBOL(setup_singlestep);
522530

523531
/*
524532
* We have reentered the kprobe_handler(), since another probe was hit while
525533
* within the handler. We save the original kprobes variables and just single
526534
* step on the instruction of the new probe without calling any user handlers.
527535
*/
528-
static int __kprobes
529-
reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
536+
static int reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
537+
struct kprobe_ctlblk *kcb)
530538
{
531539
switch (kcb->kprobe_status) {
532540
case KPROBE_HIT_SSDONE:
@@ -554,12 +562,13 @@ reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb
554562

555563
return 1;
556564
}
565+
NOKPROBE_SYMBOL(reenter_kprobe);
557566

558567
/*
559568
* Interrupts are disabled on entry as trap3 is an interrupt gate and they
560569
* remain disabled throughout this function.
561570
*/
562-
int __kprobes kprobe_int3_handler(struct pt_regs *regs)
571+
int kprobe_int3_handler(struct pt_regs *regs)
563572
{
564573
kprobe_opcode_t *addr;
565574
struct kprobe *p;
@@ -622,12 +631,13 @@ int __kprobes kprobe_int3_handler(struct pt_regs *regs)
622631
preempt_enable_no_resched();
623632
return 0;
624633
}
634+
NOKPROBE_SYMBOL(kprobe_int3_handler);
625635

626636
/*
627637
* When a retprobed function returns, this code saves registers and
628638
* calls trampoline_handler() runs, which calls the kretprobe's handler.
629639
*/
630-
static void __used __kprobes kretprobe_trampoline_holder(void)
640+
static void __used kretprobe_trampoline_holder(void)
631641
{
632642
asm volatile (
633643
".global kretprobe_trampoline\n"
@@ -658,11 +668,13 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
658668
#endif
659669
" ret\n");
660670
}
671+
NOKPROBE_SYMBOL(kretprobe_trampoline_holder);
672+
NOKPROBE_SYMBOL(kretprobe_trampoline);
661673

662674
/*
663675
* Called from kretprobe_trampoline
664676
*/
665-
__visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
677+
__visible __used void *trampoline_handler(struct pt_regs *regs)
666678
{
667679
struct kretprobe_instance *ri = NULL;
668680
struct hlist_head *head, empty_rp;
@@ -748,6 +760,7 @@ __visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
748760
}
749761
return (void *)orig_ret_address;
750762
}
763+
NOKPROBE_SYMBOL(trampoline_handler);
751764

752765
/*
753766
* Called after single-stepping. p->addr is the address of the
@@ -776,8 +789,8 @@ __visible __used __kprobes void *trampoline_handler(struct pt_regs *regs)
776789
* jump instruction after the copied instruction, that jumps to the next
777790
* instruction after the probepoint.
778791
*/
779-
static void __kprobes
780-
resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
792+
static void resume_execution(struct kprobe *p, struct pt_regs *regs,
793+
struct kprobe_ctlblk *kcb)
781794
{
782795
unsigned long *tos = stack_addr(regs);
783796
unsigned long copy_ip = (unsigned long)p->ainsn.insn;
@@ -852,12 +865,13 @@ resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
852865
no_change:
853866
restore_btf();
854867
}
868+
NOKPROBE_SYMBOL(resume_execution);
855869

856870
/*
857871
* Interrupts are disabled on entry as trap1 is an interrupt gate and they
858872
* remain disabled throughout this function.
859873
*/
860-
int __kprobes kprobe_debug_handler(struct pt_regs *regs)
874+
int kprobe_debug_handler(struct pt_regs *regs)
861875
{
862876
struct kprobe *cur = kprobe_running();
863877
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -892,8 +906,9 @@ int __kprobes kprobe_debug_handler(struct pt_regs *regs)
892906

893907
return 1;
894908
}
909+
NOKPROBE_SYMBOL(kprobe_debug_handler);
895910

896-
int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
911+
int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
897912
{
898913
struct kprobe *cur = kprobe_running();
899914
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -950,12 +965,13 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
950965

951966
return 0;
952967
}
968+
NOKPROBE_SYMBOL(kprobe_fault_handler);
953969

954970
/*
955971
* Wrapper routine for handling exceptions.
956972
*/
957-
int __kprobes
958-
kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *data)
973+
int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
974+
void *data)
959975
{
960976
struct die_args *args = data;
961977
int ret = NOTIFY_DONE;
@@ -975,8 +991,9 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
975991
}
976992
return ret;
977993
}
994+
NOKPROBE_SYMBOL(kprobe_exceptions_notify);
978995

979-
int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
996+
int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
980997
{
981998
struct jprobe *jp = container_of(p, struct jprobe, kp);
982999
unsigned long addr;
@@ -1000,8 +1017,9 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
10001017
regs->ip = (unsigned long)(jp->entry);
10011018
return 1;
10021019
}
1020+
NOKPROBE_SYMBOL(setjmp_pre_handler);
10031021

1004-
void __kprobes jprobe_return(void)
1022+
void jprobe_return(void)
10051023
{
10061024
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
10071025

@@ -1017,8 +1035,10 @@ void __kprobes jprobe_return(void)
10171035
" nop \n"::"b"
10181036
(kcb->jprobe_saved_sp):"memory");
10191037
}
1038+
NOKPROBE_SYMBOL(jprobe_return);
1039+
NOKPROBE_SYMBOL(jprobe_return_end);
10201040

1021-
int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
1041+
int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
10221042
{
10231043
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
10241044
u8 *addr = (u8 *) (regs->ip - 1);
@@ -1046,6 +1066,7 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
10461066
}
10471067
return 0;
10481068
}
1069+
NOKPROBE_SYMBOL(longjmp_break_handler);
10491070

10501071
bool arch_within_kprobe_blacklist(unsigned long addr)
10511072
{

0 commit comments

Comments
 (0)