arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line
PATCH v2 1/2 arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line
Commit 36dadef23fcc ("kprobes: Init kprobes in early_initcall") enabled using kprobes from early_initcall. Unfortunately at this point the hardware debug infrastructure is not operational. The OS lock may still be locked, and the hardware watchpoints may have unknown values when kprobe enables debug monitors to single-step instructions.
Rather than using hardware single-step, append a BRK instruction after the instruction to be executed out-of-line.
---
v2:
* Remove patch_text() helper
* Mask all of DAIF during trampoline
v1: https://lore.kernel.org/linux-arm-kernel/[email protected]/
--- arch/arm64/include/asm/brk-imm.h | 2 + arch/arm64/include/asm/debug-monitors.h | 1 + arch/arm64/include/asm/kprobes.h | 2 +- arch/arm64/kernel/probes/kprobes.c | 69 +++++++++---------------- 4 files changed, 27 insertions(+), 47 deletions(-)
arch/arm64/include/asm/brk-imm.h +2 -0
@@ -10,6 +10,7 @@* #imm16 values used for BRK instruction generation * 0x004: for installing kprobes * 0x005: for installing uprobes +* 0x006: for kprobe software single-step * Allowed values for kgdb are 0x400 - 0x7ff * 0x100: for triggering a fault on purpose (reserved) * 0x400: for dynamic BRK instruction
@@ -19,6 +20,7 @@*/ #define KPROBES_BRK_IMM 0x004#define UPROBES_BRK_IMM 0x005 +#define KPROBES_BRK_SS_IMM 0x006#define FAULT_BRK_IMM 0x100#define KGDB_DYN_DBG_BRK_IMM 0x400#define KGDB_COMPILED_DBG_BRK_IMM 0x401
arch/arm64/include/asm/debug-monitors.h +1 -0
@@ -53,6 +53,7 @@/* kprobes BRK opcodes with ESR encoding */ #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (KPROBES_BRK_IMM << 5)) +#define BRK64_OPCODE_KPROBES_SS (AARCH64_BREAK_MON | (KPROBES_BRK_SS_IMM << 5))/* uprobes BRK opcodes with ESR encoding */ #define BRK64_OPCODE_UPROBES (AARCH64_BREAK_MON | (UPROBES_BRK_IMM << 5))
arch/arm64/include/asm/kprobes.h +1 -1
@@ -16,7 +16,7 @@#include <linux/percpu.h> #define __ARCH_WANT_KPROBES_INSN_SLOT -#define MAX_INSN_SIZE 1 +#define MAX_INSN_SIZE 2#define flush_insn_slot (p) do { } while (0)#define kretprobe_blacklist_size 0
arch/arm64/kernel/probes/kprobes.c +23 -46
151 lines not on this page · raw message
Signature · 7 lines
2.29.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/2 arm64: kprobes: Remove redundant kprobe_step_ctx
From: Masami Hiramatsu <[email protected]>
The kprobe_step_ctx (kcb->ss_ctx) has ss_pending and match_addr, but those are redundant because those can be replaced by KPROBE_HIT_SS and &cur_kprobe->ainsn.api.insn[1] respectively.
To simplify the code, remove the kprobe_step_ctx.
--- arch/arm64/include/asm/kprobes.h | 7 ---- arch/arm64/kernel/probes/kprobes.c | 53 +++++++----------------------- 2 files changed, 12 insertions(+), 48 deletions(-)
arch/arm64/include/asm/kprobes.h +0 -7
@@ -28,18 +28,11 @@ struct prev_kprobe {unsigned int status; }; -/* Single step context for kprobe */ -struct kprobe_step_ctx { -unsigned long ss_pending; -unsigned long match_addr; -}; -/* per-cpu kprobe control block */ struct kprobe_ctlblk {unsigned int kprobe_status;unsigned long saved_irqflag;struct prev_kprobe prev_kprobe; -struct kprobe_step_ctx ss_ctx; };void arch_remove_kprobe (struct kprobe *);
arch/arm64/kernel/probes/kprobes.c +12 -41
98 lines not on this page · raw message
Signature · 7 lines
2.29.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 2/2] arm64: kprobes: Remove redundant kprobe_step_ctx
Quoted 7 lines · Jean-Philippe Brucker
From: Masami Hiramatsu <[email protected]>
The
kprobe_step_ctx(kcb->ss_ctx) hasss_pendingandmatch_addr, but those are redundant because those can be replaced byKPROBE_HIT_SSand &cur_kprobe->ainsn.api.insn[1] respectively.
To simplify the code, remove thekprobe_step_ctx.
Quoted 6 lines
Reviewed-by Jean-Philippe Brucker <[email protected]>Signed-off-by Masami Hiramatsu <[email protected]>--- arch/arm64/include/asm/kprobes.h | 7 ---- arch/arm64/kernel/probes/kprobes.c | 53 +++++++----------------------- 2 files changed, 12 insertions(+), 48 deletions(-)
Catalin should be able to queue this at -rc3, once the first patch has landed in mainline.
Cheers,
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 2/2] arm64: kprobes: Remove redundant kprobe_step_ctx
Quoted 15 lines · Will Deacon
Quoted 7 lines · Jean-Philippe Brucker
From: Masami Hiramatsu <[email protected]>
The
kprobe_step_ctx(kcb->ss_ctx) hasss_pendingandmatch_addr, but those are redundant because those can be replaced byKPROBE_HIT_SSand &cur_kprobe->ainsn.api.insn[1] respectively.
To simplify the code, remove thekprobe_step_ctx.Quoted 6 lines
Reviewed-by Jean-Philippe Brucker <[email protected]>Signed-off-by Masami Hiramatsu <[email protected]>--- arch/arm64/include/asm/kprobes.h | 7 ---- arch/arm64/kernel/probes/kprobes.c | 53 +++++++----------------------- 2 files changed, 12 insertions(+), 48 deletions(-)
Quoted 4 lines
Acked-by Will Deacon <[email protected]>Catalin should be able to queue this at -rc3, once the first patch has landed in mainline.
I queued it but couldn't convince "b4 ty" to reply to patch 2:
https://git.kernel.org/arm64/c/ba090f9cafd53dbabe0f0a8c4ccae44203d3731b
Signature · 6 lines
Catalin _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerQuoted 8 lines · Jean-Philippe Brucker
Commit
36dadef23fcc("kprobes: Init kprobes inearly_initcall") enabled using kprobes fromearly_initcall. Unfortunately at this point the hardware debug infrastructure is not operational. The OS lock may still be locked, and the hardware watchpoints may have unknown values when kprobe enables debug monitors to single-step instructions.Rather than using hardware single-step, append a BRK instruction after the instruction to be executed out-of-line.
Applied first patch to arm64 (for-next/fixes), thanks!
[1/2] arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line
https://git.kernel.org/arm64/c/7ee31a3aa8f4
Cheers,
Signature · 10 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel