Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D713C61DA4 for ; Fri, 27 Jan 2023 13:18:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234650AbjA0NSr (ORCPT ); Fri, 27 Jan 2023 08:18:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234704AbjA0NSY (ORCPT ); Fri, 27 Jan 2023 08:18:24 -0500 Received: from cstnet.cn (smtp80.cstnet.cn [159.226.251.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5BF5C2B089 for ; Fri, 27 Jan 2023 05:17:56 -0800 (PST) Received: from cgk-Precision-3650-Tower.. (unknown [219.141.235.82]) by APP-01 (Coremail) with SMTP id qwCowADX3Eg9zNNjDyF3Ag--.52827S16; Fri, 27 Jan 2023 21:06:11 +0800 (CST) From: Chen Guokai To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, rostedt@goodmis.org, mingo@redhat.com, sfr@canb.auug.org.au Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, liaochang1@huawei.com Subject: [PATCH v6 12/13] riscv/kprobe: Move exception related symbols to .kprobe_blacklist Date: Fri, 27 Jan 2023 21:05:40 +0800 Message-Id: <20230127130541.1250865-13-chenguokai17@mails.ucas.ac.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127130541.1250865-1-chenguokai17@mails.ucas.ac.cn> References: <20230127130541.1250865-1-chenguokai17@mails.ucas.ac.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowADX3Eg9zNNjDyF3Ag--.52827S16 X-Coremail-Antispam: 1UD129KBjvJXoW7uw45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vjDU 0xZFpf9x07jzmhrUUUUU= X-Originating-IP: [219.141.235.82] X-CM-SenderInfo: xfkh0w5xrntxyrx6ztxlovh3xfdvhtffof0/1tbiAwkEE2PTrr4g2AAAsF Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liao Chang Due to the generic exception entry and exit code is part of the critical path for kprobe breakpoint and uprobe syscall entry, set a kprobe on the assembly symbols in entry.S result in kernel stack overflow crash, hence it has to explicitly blacklist it, requiring a new _ASM_NOKPROBE() asm helper. Signed-off-by: Liao Chang --- arch/riscv/include/asm/asm.h | 10 ++++++++++ arch/riscv/kernel/entry.S | 12 ++++++++++++ arch/riscv/kernel/mcount.S | 1 + 3 files changed, 23 insertions(+) diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h index 816e753de636..5d9f13d8b809 100644 --- a/arch/riscv/include/asm/asm.h +++ b/arch/riscv/include/asm/asm.h @@ -81,6 +81,16 @@ .endr .endm +#ifdef CONFIG_KPROBES +#define _ASM_NOKPROBE(entry) \ + .pushsection "_kprobe_blacklist", "aw" ; \ + .balign SZREG ; \ + REG_ASM entry ; \ + .popsection +#else +#define _ASM_NOKPROBE(entry) +#endif + #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_ASM_H */ diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 99d38fdf8b18..9e8882a78523 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -606,3 +606,15 @@ ENTRY(__user_rt_sigreturn) scall END(__user_rt_sigreturn) #endif + +_ASM_NOKPROBE(handle_exception) +_ASM_NOKPROBE(_restore_kernel_tpsp) +_ASM_NOKPROBE(_save_context) +_ASM_NOKPROBE(ret_from_exception) +_ASM_NOKPROBE(ret_from_syscall) +_ASM_NOKPROBE(__switch_to) +_ASM_NOKPROBE(ret_from_syscall_rejected) +_ASM_NOKPROBE(restore_all) +_ASM_NOKPROBE(resume_kernel) +_ASM_NOKPROBE(resume_userspace) +_ASM_NOKPROBE(check_syscall_nr) diff --git a/arch/riscv/kernel/mcount.S b/arch/riscv/kernel/mcount.S index 30102aadc4d7..7393b8895ef3 100644 --- a/arch/riscv/kernel/mcount.S +++ b/arch/riscv/kernel/mcount.S @@ -54,6 +54,7 @@ ENTRY(ftrace_stub) #endif ret ENDPROC(ftrace_stub) +_ASM_NOKPROBE(MCOUNT_NAME) #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(return_to_handler) -- 2.34.1