Re: [PATCH] LoongArch/rethook: Replace kretprobe with rethook on loongarch

From: Tiezhu Yang
Date: Mon Jun 12 2023 - 03:44:21 EST




On 06/12/2023 01:49 PM, jianghaoran wrote:
That's an adaptation of commit f3a112c0c40d ("x86,rethook,kprobes:
Replace kretprobe with rethook on x86") to loongarch.

Replaces the kretprobe code with rethook on loongarch. With this patch,
kretprobe on loongarch uses the rethook instead of kretprobe specific
trampoline code.

Signed-off-by: jianghaoran<jianghaoran@xxxxxxxxxx>
Signed-off-by: jhrhhao<jhrhhao@xxxxxxx>

Please check Signed-off-by's "<first> <last> <email>" order
and spelling. Should it be "Haoran Jiang <jianghaoran@xxxxxxxxxx>"?
Please refer the following link:
https://lore.kernel.org/all/CAEf4BzYS5mj+0ZBA2HKW3=kB1cjZ3wdiJZ2OP9gSLE4e7WB_wQ@xxxxxxxxxxxxxx/

---
arch/loongarch/Kconfig | 1 +
arch/loongarch/include/asm/kprobes.h | 3 ---
arch/loongarch/kernel/Makefile | 3 ++-
arch/loongarch/kernel/kprobes.c | 20 --------------
arch/loongarch/kernel/rethook.c | 27 +++++++++++++++++++
arch/loongarch/kernel/rethook.h | 9 +++++++
...obes_trampoline.S => rethook_trampoline.S} | 6 ++---
7 files changed, 42 insertions(+), 27 deletions(-)
create mode 100644 arch/loongarch/kernel/rethook.c
create mode 100644 arch/loongarch/kernel/rethook.h
rename arch/loongarch/kernel/{kprobes_trampoline.S => rethook_trampoline.S} (93%)

...

--- a/arch/loongarch/kernel/kprobes.c
+++ b/arch/loongarch/kernel/kprobes.c
@@ -378,26 +378,6 @@ int __init arch_init_kprobes(void)
return 0;
}

-/* ASM function that handles the kretprobes must not be probed */
-NOKPROBE_SYMBOL(__kretprobe_trampoline);
-
-/* Called from __kretprobe_trampoline */
-void __used *trampoline_probe_handler(struct pt_regs *regs)
-{
- return (void *)kretprobe_trampoline_handler(regs, NULL);
-}
-NOKPROBE_SYMBOL(trampoline_probe_handler);
-
-void arch_prepare_kretprobe(struct kretprobe_instance *ri,
- struct pt_regs *regs)
-{
- ri->ret_addr = (kprobe_opcode_t *)regs->regs[1];
- ri->fp = NULL;
-
- /* Replace the return addr with trampoline addr */
- regs->regs[1] = (unsigned long)&__kretprobe_trampoline;
-}
-NOKPROBE_SYMBOL(arch_prepare_kretprobe);


When git am this patch, there exists the following warning:

Applying: LoongArch/rethook: Replace kretprobe with rethook on loongarch
.git/rebase-apply/patch:131: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

So please remove the blank line.

int arch_trampoline_kprobe(struct kprobe *p)

...

-SYM_CODE_END(__kretprobe_trampoline)
+SYM_CODE_END(arch_rethook_trampoline)

This patch is almost same with commit b57c2f124098 ("riscv: add
riscv rethook implementation"), it is better to provide this info
in the commit message.

The code itself looks good to me, I am doing the test.

Thanks,
Tiezhu