diff mbox series

[09/10] arm64: probes: Move magic BRK values into brk-imm.h

Message ID 20190301132809.24653-10-will.deacon@arm.com (mailing list archive)
State New, archived
Headers show
Series Rework debug exception handling code | expand

Commit Message

Will Deacon March 1, 2019, 1:28 p.m. UTC
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.

Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/include/asm/brk-imm.h        | 4 ++++
 arch/arm64/include/asm/debug-monitors.h | 7 ++-----
 arch/arm64/include/asm/esr.h            | 4 +---
 arch/arm64/kernel/debug-monitors.c      | 2 +-
 arch/arm64/kernel/probes/kprobes.c      | 2 +-
 arch/arm64/kernel/probes/uprobes.c      | 2 +-
 arch/arm64/kernel/traps.c               | 2 +-
 7 files changed, 11 insertions(+), 12 deletions(-)

Comments

Mark Rutland March 1, 2019, 2:16 p.m. UTC | #1
On Fri, Mar 01, 2019 at 01:28:08PM +0000, Will Deacon wrote:
> 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.
> 
> Signed-off-by: Will Deacon <will.deacon@arm.com>

Modulo the latent bug with KASAN immediates I mentioned in a prior
patch:

Reviewed-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/include/asm/brk-imm.h        | 4 ++++
>  arch/arm64/include/asm/debug-monitors.h | 7 ++-----
>  arch/arm64/include/asm/esr.h            | 4 +---
>  arch/arm64/kernel/debug-monitors.c      | 2 +-
>  arch/arm64/kernel/probes/kprobes.c      | 2 +-
>  arch/arm64/kernel/probes/uprobes.c      | 2 +-
>  arch/arm64/kernel/traps.c               | 2 +-
>  7 files changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/brk-imm.h b/arch/arm64/include/asm/brk-imm.h
> index 2945fe6cd863..645ea26cca81 100644
> --- a/arch/arm64/include/asm/brk-imm.h
> +++ b/arch/arm64/include/asm/brk-imm.h
> @@ -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
> diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h
> index 2b136f0f6a35..5a731757a3c4 100644
> --- a/arch/arm64/include/asm/debug-monitors.h
> +++ b/arch/arm64/include/asm/debug-monitors.h
> @@ -65,12 +65,9 @@
>  #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
> diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h
> index 52233f00d53d..3541720189c9 100644
> --- a/arch/arm64/include/asm/esr.h
> +++ b/arch/arm64/include/asm/esr.h
> @@ -156,9 +156,7 @@
>  				 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
> diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
> index d9616c34a270..55d46ed6ccc2 100644
> --- a/arch/arm64/kernel/debug-monitors.c
> +++ b/arch/arm64/kernel/debug-monitors.c
> @@ -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)
> -		if ((esr & BRK64_ESR_MASK) == hook->imm)
> +		if ((esr & ESR_ELx_BRK64_ISS_COMMENT_MASK) == hook->imm)
>  			fn = hook->fn;
>  	rcu_read_unlock();
>  
> diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
> index 30502a3c8cf0..42a30f23b85f 100644
> --- a/arch/arm64/kernel/probes/kprobes.c
> +++ b/arch/arm64/kernel/probes/kprobes.c
> @@ -475,7 +475,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,
>  };
>  
> diff --git a/arch/arm64/kernel/probes/uprobes.c b/arch/arm64/kernel/probes/uprobes.c
> index f37ab9567676..605945eac1f8 100644
> --- a/arch/arm64/kernel/probes/uprobes.c
> +++ b/arch/arm64/kernel/probes/uprobes.c
> @@ -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,
>  };
>  
> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index 3bcd56dd94fa..387c5e18cc46 100644
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -1019,7 +1019,7 @@ int __init early_brk64(unsigned long addr, unsigned int esr,
>  		struct pt_regs *regs)
>  {
>  #ifdef CONFIG_KASAN_SW_TAGS
> -	if ((esr & BRK64_ESR_MASK) == KASAN_BRK_IMM)
> +	if ((esr & ESR_ELx_BRK64_ISS_COMMENT_MASK) == KASAN_BRK_IMM)
>  		return kasan_handler(regs, esr) != DBG_HOOK_HANDLED;
>  #endif
>  	return bug_handler(regs, esr) != DBG_HOOK_HANDLED;
> -- 
> 2.11.0
>
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/brk-imm.h b/arch/arm64/include/asm/brk-imm.h
index 2945fe6cd863..645ea26cca81 100644
--- a/arch/arm64/include/asm/brk-imm.h
+++ b/arch/arm64/include/asm/brk-imm.h
@@ -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
diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h
index 2b136f0f6a35..5a731757a3c4 100644
--- a/arch/arm64/include/asm/debug-monitors.h
+++ b/arch/arm64/include/asm/debug-monitors.h
@@ -65,12 +65,9 @@ 
 #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
diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h
index 52233f00d53d..3541720189c9 100644
--- a/arch/arm64/include/asm/esr.h
+++ b/arch/arm64/include/asm/esr.h
@@ -156,9 +156,7 @@ 
 				 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
diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
index d9616c34a270..55d46ed6ccc2 100644
--- a/arch/arm64/kernel/debug-monitors.c
+++ b/arch/arm64/kernel/debug-monitors.c
@@ -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)
-		if ((esr & BRK64_ESR_MASK) == hook->imm)
+		if ((esr & ESR_ELx_BRK64_ISS_COMMENT_MASK) == hook->imm)
 			fn = hook->fn;
 	rcu_read_unlock();
 
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 30502a3c8cf0..42a30f23b85f 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -475,7 +475,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,
 };
 
diff --git a/arch/arm64/kernel/probes/uprobes.c b/arch/arm64/kernel/probes/uprobes.c
index f37ab9567676..605945eac1f8 100644
--- a/arch/arm64/kernel/probes/uprobes.c
+++ b/arch/arm64/kernel/probes/uprobes.c
@@ -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,
 };
 
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index 3bcd56dd94fa..387c5e18cc46 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -1019,7 +1019,7 @@  int __init early_brk64(unsigned long addr, unsigned int esr,
 		struct pt_regs *regs)
 {
 #ifdef CONFIG_KASAN_SW_TAGS
-	if ((esr & BRK64_ESR_MASK) == KASAN_BRK_IMM)
+	if ((esr & ESR_ELx_BRK64_ISS_COMMENT_MASK) == KASAN_BRK_IMM)
 		return kasan_handler(regs, esr) != DBG_HOOK_HANDLED;
 #endif
 	return bug_handler(regs, esr) != DBG_HOOK_HANDLED;