Skip to content

Commit fcf77d0

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Mark some assembler symbols as non-kprobe-able
Some assembler symbols are not kprobe safe, such as handle_syscall (used as syscall exception handler), *memset*/*memcpy*/*memmove* (may cause recursive exceptions), they can not be instrumented, just blacklist them for kprobing. Here is a related problem and discussion: Link: https://lore.kernel.org/lkml/[email protected]/ Tested-by: Jeff Xie <[email protected]> Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 09e679c commit fcf77d0

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

arch/loongarch/include/asm/asm.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,14 @@
188188
#define PTRLOG 3
189189
#endif
190190

191+
/* Annotate a function as being unsuitable for kprobes. */
192+
#ifdef CONFIG_KPROBES
193+
#define _ASM_NOKPROBE(name) \
194+
.pushsection "_kprobe_blacklist", "aw"; \
195+
.quad name; \
196+
.popsection
197+
#else
198+
#define _ASM_NOKPROBE(name)
199+
#endif
200+
191201
#endif /* __ASM_ASM_H */

arch/loongarch/kernel/entry.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall)
6767

6868
RESTORE_ALL_AND_RET
6969
SYM_FUNC_END(handle_syscall)
70+
_ASM_NOKPROBE(handle_syscall)
7071

7172
SYM_CODE_START(ret_from_fork)
7273
bl schedule_tail # a0 = struct task_struct *prev

arch/loongarch/lib/memcpy.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy)
1717
ALTERNATIVE "b __memcpy_generic", \
1818
"b __memcpy_fast", CPU_FEATURE_UAL
1919
SYM_FUNC_END(memcpy)
20+
_ASM_NOKPROBE(memcpy)
2021

2122
EXPORT_SYMBOL(memcpy)
2223

@@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic)
4142
2: move a0, a3
4243
jr ra
4344
SYM_FUNC_END(__memcpy_generic)
45+
_ASM_NOKPROBE(__memcpy_generic)
4446

4547
/*
4648
* void *__memcpy_fast(void *dst, const void *src, size_t n)
@@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast)
9395
3: move a0, a3
9496
jr ra
9597
SYM_FUNC_END(__memcpy_fast)
98+
_ASM_NOKPROBE(__memcpy_fast)

arch/loongarch/lib/memmove.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ SYM_FUNC_START(memmove)
2929
b rmemcpy
3030
4: b __rmemcpy_generic
3131
SYM_FUNC_END(memmove)
32+
_ASM_NOKPROBE(memmove)
3233

3334
EXPORT_SYMBOL(memmove)
3435

@@ -39,6 +40,7 @@ SYM_FUNC_START(rmemcpy)
3940
ALTERNATIVE "b __rmemcpy_generic", \
4041
"b __rmemcpy_fast", CPU_FEATURE_UAL
4142
SYM_FUNC_END(rmemcpy)
43+
_ASM_NOKPROBE(rmemcpy)
4244

4345
/*
4446
* void *__rmemcpy_generic(void *dst, const void *src, size_t n)
@@ -64,6 +66,7 @@ SYM_FUNC_START(__rmemcpy_generic)
6466
2: move a0, a3
6567
jr ra
6668
SYM_FUNC_END(__rmemcpy_generic)
69+
_ASM_NOKPROBE(__rmemcpy_generic)
6770

6871
/*
6972
* void *__rmemcpy_fast(void *dst, const void *src, size_t n)
@@ -119,3 +122,4 @@ SYM_FUNC_START(__rmemcpy_fast)
119122
3: move a0, a3
120123
jr ra
121124
SYM_FUNC_END(__rmemcpy_fast)
125+
_ASM_NOKPROBE(__rmemcpy_fast)

arch/loongarch/lib/memset.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SYM_FUNC_START(memset)
2323
ALTERNATIVE "b __memset_generic", \
2424
"b __memset_fast", CPU_FEATURE_UAL
2525
SYM_FUNC_END(memset)
26+
_ASM_NOKPROBE(memset)
2627

2728
EXPORT_SYMBOL(memset)
2829

@@ -45,6 +46,7 @@ SYM_FUNC_START(__memset_generic)
4546
2: move a0, a3
4647
jr ra
4748
SYM_FUNC_END(__memset_generic)
49+
_ASM_NOKPROBE(__memset_generic)
4850

4951
/*
5052
* void *__memset_fast(void *s, int c, size_t n)
@@ -89,3 +91,4 @@ SYM_FUNC_START(__memset_fast)
8991
3: move a0, a3
9092
jr ra
9193
SYM_FUNC_END(__memset_fast)
94+
_ASM_NOKPROBE(__memset_fast)

0 commit comments

Comments
 (0)