arm64: probes: Move magic BRK values into brk-imm.h
authorWill Deacon <will.deacon@arm.com>
Tue, 26 Feb 2019 15:06:42 +0000 (15:06 +0000)
committerWill Deacon <will.deacon@arm.com>
Tue, 9 Apr 2019 10:21:13 +0000 (11:21 +0100)
kprobes and uprobes reserve some BRK immediates for installing their
probes. Define these along with the other reservations in brk-imm.h
and rename the ESR definitions to be consistent with the others that we
already have.

Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/include/asm/brk-imm.h
arch/arm64/include/asm/debug-monitors.h
arch/arm64/include/asm/esr.h
arch/arm64/kernel/debug-monitors.c
arch/arm64/kernel/probes/kprobes.c
arch/arm64/kernel/probes/uprobes.c
arch/arm64/kernel/traps.c

index fec9e138464101fac9f1e0ba5f161e7cccc6e471..d84294064e6a086c654843d09636f6351dfa7afd 100644 (file)
@@ -11,6 +11,8 @@
 
 /*
  * #imm16 values used for BRK instruction generation
+ * 0x004: for installing kprobes
+ * 0x005: for installing uprobes
  * Allowed values for kgdb are 0x400 - 0x7ff
  * 0x100: for triggering a fault on purpose (reserved)
  * 0x400: for dynamic BRK instruction
@@ -18,6 +20,8 @@
  * 0x800: kernel-mode BUG() and WARN() traps
  * 0x9xx: tag-based KASAN trap (allowed values 0x900 - 0x9ff)
  */
+#define KPROBES_BRK_IMM                        0x004
+#define UPROBES_BRK_IMM                        0x005
 #define FAULT_BRK_IMM                  0x100
 #define KGDB_DYN_DBG_BRK_IMM           0x400
 #define KGDB_COMPILED_DBG_BRK_IMM      0x401
index 7d37cfa5cc16652bb5ef2c901b2fb361924094bc..0679f781696d410240184e05710123c5e7ab70ec 100644 (file)
 #define CACHE_FLUSH_IS_SAFE            1
 
 /* kprobes BRK opcodes with ESR encoding  */
-#define BRK64_ESR_MASK         0xFFFF
-#define BRK64_ESR_KPROBES      0x0004
-#define BRK64_OPCODE_KPROBES   (AARCH64_BREAK_MON | (BRK64_ESR_KPROBES << 5))
+#define BRK64_OPCODE_KPROBES   (AARCH64_BREAK_MON | (KPROBES_BRK_IMM << 5))
 /* uprobes BRK opcodes with ESR encoding  */
-#define BRK64_ESR_UPROBES      0x0005
-#define BRK64_OPCODE_UPROBES   (AARCH64_BREAK_MON | (BRK64_ESR_UPROBES << 5))
+#define BRK64_OPCODE_UPROBES   (AARCH64_BREAK_MON | (UPROBES_BRK_IMM << 5))
 
 /* AArch32 */
 #define DBG_ESR_EVT_BKPT       0x4
index 52233f00d53d8af8974f74c870e42b3fa93f533c..3541720189c95c728360e7f78833438e330a8373 100644 (file)
                                 ESR_ELx_WFx_ISS_WFI)
 
 /* BRK instruction trap from AArch64 state */
-#define ESR_ELx_VAL_BRK64(imm)                                 \
-       ((ESR_ELx_EC_BRK64 << ESR_ELx_EC_SHIFT) | ESR_ELx_IL |  \
-        ((imm) & 0xffff))
+#define ESR_ELx_BRK64_ISS_COMMENT_MASK 0xffff
 
 /* ISS field definitions for System instruction traps */
 #define ESR_ELx_SYS64_ISS_RES0_SHIFT   22
index f4d8cda8830d832181767d5b3e36a7bb239df939..2692a0a27cf3ab3ac79b114fb11fd343ea884dfa 100644 (file)
@@ -317,7 +317,7 @@ static int call_break_hook(struct pt_regs *regs, unsigned int esr)
 
        rcu_read_lock();
        list_for_each_entry_rcu(hook, list, node) {
-               unsigned int comment = esr & BRK64_ESR_MASK;
+               unsigned int comment = esr & ESR_ELx_BRK64_ISS_COMMENT_MASK;
 
                if ((comment & ~hook->mask) == hook->imm)
                        fn = hook->fn;
index 000f32d1a75642692a6be01a290710598ca07803..2509fcb6d4048a17c20760741e8b33f22137f7fd 100644 (file)
@@ -470,7 +470,7 @@ kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr)
 }
 
 static struct break_hook kprobes_break_hook = {
-       .imm = BRK64_ESR_KPROBES,
+       .imm = KPROBES_BRK_IMM,
        .fn = kprobe_breakpoint_handler,
 };
 
index f37ab956767615ba90e15b57a2df34cec21255d4..605945eac1f843d221d47c67177ee46068a9916d 100644 (file)
@@ -191,7 +191,7 @@ static int uprobe_single_step_handler(struct pt_regs *regs,
 
 /* uprobe breakpoint handler hook */
 static struct break_hook uprobes_break_hook = {
-       .imm = BRK64_ESR_UPROBES,
+       .imm = UPROBES_BRK_IMM,
        .fn = uprobe_breakpoint_handler,
 };
 
index 091379744d2f1ecb983d101c8498a807f2e1f1b2..74598396e0bf4c71b00cb345fbef329d0ce9d694 100644 (file)
@@ -1024,7 +1024,7 @@ int __init early_brk64(unsigned long addr, unsigned int esr,
                struct pt_regs *regs)
 {
 #ifdef CONFIG_KASAN_SW_TAGS
-       unsigned int comment = esr & BRK64_ESR_MASK;
+       unsigned int comment = esr & ESR_ELx_BRK64_ISS_COMMENT_MASK;
 
        if ((comment & ~KASAN_BRK_MASK) == KASAN_BRK_IMM)
                return kasan_handler(regs, esr) != DBG_HOOK_HANDLED;