Skip to contentSkip to conversation

arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line

PATCH In review Mark-PK Tsai 2 participants 2 messages Jun 15, 2022 – Jun 20, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line

From: Jean-Philippe Brucker <[email protected]>

commit 7ee31a3aa8f490c6507bc4294df6b70bed1c593e upstream.

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.

---
 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
index e3d47b52161d..ec7720dbe2c8 100644
@@ -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
index d825e3585e28..0253691c4b3a 100644
@@ -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
index 97e511d645a2..8699ce30f587 100644
@@ -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 · 1 line
2.18.0
#1 lore raw
Quoted 13 lines · Mark-PK Tsai

From: Jean-Philippe Brucker <[email protected]>

commit 7ee31a3aa8f490c6507bc4294df6b70bed1c593e upstream.

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.

Quoted 9 lines

Now queued up, thanks.

greg k-h