Skip to content

Commit f5e2d81

Browse files
seehearfeeltsbogend
authored andcommitted
MIPS: Use NOKPROBE_SYMBOL() instead of __kprobes annotation
If define CONFIG_KPROBES, __kprobes annotation forces the whole function into the ".kprobes.text" section, NOKPROBE_SYMBOL() only stores the given function address in the "_kprobe_blacklist" section which is introduced to maintain kprobes blacklist. Modify the related code to use NOKPROBE_SYMBOL() to protect functions from kprobes instead of __kprobes annotation under arch/mips. No obvious functional change in this patch, some more work needs to be done to fix the kernel panic when execute the following testcase on mips: # cd tools/testing/selftests/ftrace # ./ftracetest test.d/kprobe/multiple_kprobes.tc Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent eab691b commit f5e2d81

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

arch/mips/kernel/kprobes.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ static const union mips_instruction breakpoint2_insn = {
4444
DEFINE_PER_CPU(struct kprobe *, current_kprobe);
4545
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
4646

47-
static int __kprobes insn_has_delayslot(union mips_instruction insn)
47+
static int insn_has_delayslot(union mips_instruction insn)
4848
{
4949
return __insn_has_delay_slot(insn);
5050
}
51+
NOKPROBE_SYMBOL(insn_has_delayslot);
5152

5253
/*
5354
* insn_has_ll_or_sc function checks whether instruction is ll or sc
@@ -56,7 +57,7 @@ static int __kprobes insn_has_delayslot(union mips_instruction insn)
5657
* instructions; cannot do much about breakpoint in the middle of
5758
* ll/sc pair; it is upto user to avoid those places
5859
*/
59-
static int __kprobes insn_has_ll_or_sc(union mips_instruction insn)
60+
static int insn_has_ll_or_sc(union mips_instruction insn)
6061
{
6162
int ret = 0;
6263

@@ -72,8 +73,9 @@ static int __kprobes insn_has_ll_or_sc(union mips_instruction insn)
7273
}
7374
return ret;
7475
}
76+
NOKPROBE_SYMBOL(insn_has_ll_or_sc);
7577

76-
int __kprobes arch_prepare_kprobe(struct kprobe *p)
78+
int arch_prepare_kprobe(struct kprobe *p)
7779
{
7880
union mips_instruction insn;
7981
union mips_instruction prev_insn;
@@ -132,26 +134,30 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
132134
out:
133135
return ret;
134136
}
137+
NOKPROBE_SYMBOL(arch_prepare_kprobe);
135138

136-
void __kprobes arch_arm_kprobe(struct kprobe *p)
139+
void arch_arm_kprobe(struct kprobe *p)
137140
{
138141
*p->addr = breakpoint_insn;
139142
flush_insn_slot(p);
140143
}
144+
NOKPROBE_SYMBOL(arch_arm_kprobe);
141145

142-
void __kprobes arch_disarm_kprobe(struct kprobe *p)
146+
void arch_disarm_kprobe(struct kprobe *p)
143147
{
144148
*p->addr = p->opcode;
145149
flush_insn_slot(p);
146150
}
151+
NOKPROBE_SYMBOL(arch_disarm_kprobe);
147152

148-
void __kprobes arch_remove_kprobe(struct kprobe *p)
153+
void arch_remove_kprobe(struct kprobe *p)
149154
{
150155
if (p->ainsn.insn) {
151156
free_insn_slot(p->ainsn.insn, 0);
152157
p->ainsn.insn = NULL;
153158
}
154159
}
160+
NOKPROBE_SYMBOL(arch_remove_kprobe);
155161

156162
static void save_previous_kprobe(struct kprobe_ctlblk *kcb)
157163
{
@@ -257,7 +263,7 @@ static void prepare_singlestep(struct kprobe *p, struct pt_regs *regs,
257263
* breakpoint trap. In case of branch instructions, the target
258264
* epc to be restored.
259265
*/
260-
static void __kprobes resume_execution(struct kprobe *p,
266+
static void resume_execution(struct kprobe *p,
261267
struct pt_regs *regs,
262268
struct kprobe_ctlblk *kcb)
263269
{
@@ -268,8 +274,9 @@ static void __kprobes resume_execution(struct kprobe *p,
268274
regs->cp0_epc = orig_epc + 4;
269275
}
270276
}
277+
NOKPROBE_SYMBOL(resume_execution);
271278

272-
static int __kprobes kprobe_handler(struct pt_regs *regs)
279+
static int kprobe_handler(struct pt_regs *regs)
273280
{
274281
struct kprobe *p;
275282
int ret = 0;
@@ -367,6 +374,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
367374
return ret;
368375

369376
}
377+
NOKPROBE_SYMBOL(kprobe_handler);
370378

371379
static inline int post_kprobe_handler(struct pt_regs *regs)
372380
{
@@ -415,7 +423,7 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
415423
/*
416424
* Wrapper routine for handling exceptions.
417425
*/
418-
int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
426+
int kprobe_exceptions_notify(struct notifier_block *self,
419427
unsigned long val, void *data)
420428
{
421429

@@ -446,6 +454,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
446454
}
447455
return ret;
448456
}
457+
NOKPROBE_SYMBOL(kprobe_exceptions_notify);
449458

450459
/*
451460
* Function return probe trampoline:
@@ -469,7 +478,7 @@ static void __used kretprobe_trampoline_holder(void)
469478

470479
void __kretprobe_trampoline(void);
471480

472-
void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
481+
void arch_prepare_kretprobe(struct kretprobe_instance *ri,
473482
struct pt_regs *regs)
474483
{
475484
ri->ret_addr = (kprobe_opcode_t *) regs->regs[31];
@@ -478,11 +487,12 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
478487
/* Replace the return addr with trampoline addr */
479488
regs->regs[31] = (unsigned long)__kretprobe_trampoline;
480489
}
490+
NOKPROBE_SYMBOL(arch_prepare_kretprobe);
481491

482492
/*
483493
* Called when the probe at kretprobe trampoline is hit
484494
*/
485-
static int __kprobes trampoline_probe_handler(struct kprobe *p,
495+
static int trampoline_probe_handler(struct kprobe *p,
486496
struct pt_regs *regs)
487497
{
488498
instruction_pointer(regs) = __kretprobe_trampoline_handler(regs, NULL);
@@ -493,14 +503,16 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
493503
*/
494504
return 1;
495505
}
506+
NOKPROBE_SYMBOL(trampoline_probe_handler);
496507

497-
int __kprobes arch_trampoline_kprobe(struct kprobe *p)
508+
int arch_trampoline_kprobe(struct kprobe *p)
498509
{
499510
if (p->addr == (kprobe_opcode_t *)__kretprobe_trampoline)
500511
return 1;
501512

502513
return 0;
503514
}
515+
NOKPROBE_SYMBOL(arch_trampoline_kprobe);
504516

505517
static struct kprobe trampoline_p = {
506518
.addr = (kprobe_opcode_t *)__kretprobe_trampoline,

arch/mips/mm/fault.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int show_unhandled_signals = 1;
3535
* and the problem, and then passes it off to one of the appropriate
3636
* routines.
3737
*/
38-
static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write,
38+
static void __do_page_fault(struct pt_regs *regs, unsigned long write,
3939
unsigned long address)
4040
{
4141
struct vm_area_struct * vma = NULL;
@@ -322,8 +322,9 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write,
322322
}
323323
#endif
324324
}
325+
NOKPROBE_SYMBOL(__do_page_fault);
325326

326-
asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
327+
asmlinkage void do_page_fault(struct pt_regs *regs,
327328
unsigned long write, unsigned long address)
328329
{
329330
enum ctx_state prev_state;
@@ -332,3 +333,4 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
332333
__do_page_fault(regs, write, address);
333334
exception_exit(prev_state);
334335
}
336+
NOKPROBE_SYMBOL(do_page_fault);

0 commit comments

Comments
 (0)