diff mbox series

riscv: blacklist assembly symbols for kprobe

Message ID 20231004131009.409193-1-cleger@rivosinc.com (mailing list archive)
State Accepted
Commit 5014396af9bbac0f28d9afee7eae405206d01ee7
Headers show
Series riscv: blacklist assembly symbols for kprobe | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR fail PR summary
conchuod/patch-1-test-13 success .github/scripts/patches/verify_signedoff.sh
conchuod/patch-1-test-1 success .github/scripts/patches/build_rv32_defconfig.sh
conchuod/patch-1-test-2 success .github/scripts/patches/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 success .github/scripts/patches/build_rv64_gcc_allmodconfig.sh
conchuod/patch-1-test-4 success .github/scripts/patches/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-1-test-5 success .github/scripts/patches/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-1-test-6 fail .github/scripts/patches/checkpatch.sh
conchuod/patch-1-test-7 success .github/scripts/patches/dtb_warn_rv64.sh
conchuod/patch-1-test-8 success .github/scripts/patches/header_inline.sh
conchuod/patch-1-test-9 success .github/scripts/patches/kdoc.sh
conchuod/patch-1-test-10 success .github/scripts/patches/module_param.sh
conchuod/patch-1-test-11 success .github/scripts/patches/verify_fixes.sh
conchuod/patch-1-test-12 success .github/scripts/patches/verify_signedoff.sh

Commit Message

Clément Léger Oct. 4, 2023, 1:10 p.m. UTC
Adding kprobes on some assembly functions (mainly exception handling)
will result in crashes (either recursive trap or panic). To avoid such
errors, add ASM_NOKPROBE() macro which allow adding specific symbols
into the __kprobe_blacklist section and use to blacklist the following
symbols that showed to be problematic:
- handle_exception()
- ret_from_exception()
- handle_kernel_stack_overflow()

Signed-off-by: Clément Léger <cleger@rivosinc.com>
---
 arch/riscv/include/asm/asm.h | 10 ++++++++++
 arch/riscv/kernel/entry.S    |  3 +++
 2 files changed, 13 insertions(+)

Comments

Charlie Jenkins Oct. 9, 2023, 5:43 p.m. UTC | #1
On Wed, Oct 04, 2023 at 03:10:09PM +0200, Clément Léger wrote:
> Adding kprobes on some assembly functions (mainly exception handling)
> will result in crashes (either recursive trap or panic). To avoid such
> errors, add ASM_NOKPROBE() macro which allow adding specific symbols
> into the __kprobe_blacklist section and use to blacklist the following
> symbols that showed to be problematic:
> - handle_exception()
> - ret_from_exception()
> - handle_kernel_stack_overflow()
> 
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> ---
>  arch/riscv/include/asm/asm.h | 10 ++++++++++
>  arch/riscv/kernel/entry.S    |  3 +++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h
> index 114bbadaef41..9194e334de15 100644
> --- a/arch/riscv/include/asm/asm.h
> +++ b/arch/riscv/include/asm/asm.h
> @@ -142,6 +142,16 @@
>  	REG_L x31, PT_T6(sp)
>  	.endm
>  
> +/* Annotate a function as being unsuitable for kprobes. */
> +#ifdef CONFIG_KPROBES
> +#define ASM_NOKPROBE(name)				\
> +	.pushsection "_kprobe_blacklist", "aw";		\
> +	RISCV_PTR name;					\
> +	.popsection
> +#else
> +#define ASM_NOKPROBE(name)
> +#endif
> +
>  #endif /* __ASSEMBLY__ */
>  
>  #endif /* _ASM_RISCV_ASM_H */
> diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
> index 143a2bb3e697..f24bc4eeedde 100644
> --- a/arch/riscv/kernel/entry.S
> +++ b/arch/riscv/kernel/entry.S
> @@ -101,6 +101,7 @@ _save_context:
>  1:
>  	tail do_trap_unknown
>  SYM_CODE_END(handle_exception)
> +ASM_NOKPROBE(handle_exception)
>  
>  /*
>   * The ret_from_exception must be called with interrupt disabled. Here is the
> @@ -167,6 +168,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
>  	sret
>  #endif
>  SYM_CODE_END(ret_from_exception)
> +ASM_NOKPROBE(ret_from_exception)
>  
>  #ifdef CONFIG_VMAP_STACK
>  SYM_CODE_START_LOCAL(handle_kernel_stack_overflow)
> @@ -254,6 +256,7 @@ restore_caller_reg:
>  	move a0, sp
>  	tail handle_bad_stack
>  SYM_CODE_END(handle_kernel_stack_overflow)
> +ASM_NOKPROBE(handle_kernel_stack_overflow)
>  #endif
>  
>  SYM_CODE_START(ret_from_fork)
> -- 
> 2.42.0
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
patchwork-bot+linux-riscv@kernel.org Jan. 25, 2024, 9:30 p.m. UTC | #2
Hello:

This patch was applied to riscv/linux.git (for-next)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Wed,  4 Oct 2023 15:10:09 +0200 you wrote:
> Adding kprobes on some assembly functions (mainly exception handling)
> will result in crashes (either recursive trap or panic). To avoid such
> errors, add ASM_NOKPROBE() macro which allow adding specific symbols
> into the __kprobe_blacklist section and use to blacklist the following
> symbols that showed to be problematic:
> - handle_exception()
> - ret_from_exception()
> - handle_kernel_stack_overflow()
> 
> [...]

Here is the summary with links:
  - riscv: blacklist assembly symbols for kprobe
    https://git.kernel.org/riscv/c/5014396af9bb

You are awesome, thank you!
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h
index 114bbadaef41..9194e334de15 100644
--- a/arch/riscv/include/asm/asm.h
+++ b/arch/riscv/include/asm/asm.h
@@ -142,6 +142,16 @@ 
 	REG_L x31, PT_T6(sp)
 	.endm
 
+/* Annotate a function as being unsuitable for kprobes. */
+#ifdef CONFIG_KPROBES
+#define ASM_NOKPROBE(name)				\
+	.pushsection "_kprobe_blacklist", "aw";		\
+	RISCV_PTR name;					\
+	.popsection
+#else
+#define ASM_NOKPROBE(name)
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_RISCV_ASM_H */
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 143a2bb3e697..f24bc4eeedde 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -101,6 +101,7 @@  _save_context:
 1:
 	tail do_trap_unknown
 SYM_CODE_END(handle_exception)
+ASM_NOKPROBE(handle_exception)
 
 /*
  * The ret_from_exception must be called with interrupt disabled. Here is the
@@ -167,6 +168,7 @@  SYM_CODE_START_NOALIGN(ret_from_exception)
 	sret
 #endif
 SYM_CODE_END(ret_from_exception)
+ASM_NOKPROBE(ret_from_exception)
 
 #ifdef CONFIG_VMAP_STACK
 SYM_CODE_START_LOCAL(handle_kernel_stack_overflow)
@@ -254,6 +256,7 @@  restore_caller_reg:
 	move a0, sp
 	tail handle_bad_stack
 SYM_CODE_END(handle_kernel_stack_overflow)
+ASM_NOKPROBE(handle_kernel_stack_overflow)
 #endif
 
 SYM_CODE_START(ret_from_fork)