From nobody Thu Apr 2 23:01:51 2026 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 94C1CC6FA8E for ; Tue, 20 Sep 2022 15:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231564AbiITPQZ (ORCPT ); Tue, 20 Sep 2022 11:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbiITPPv (ORCPT ); Tue, 20 Sep 2022 11:15:51 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4768F61129; Tue, 20 Sep 2022 08:15:49 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MX4l06HjSzlW5D; Tue, 20 Sep 2022 23:11:40 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 23:15:46 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 23:15:46 +0800 From: Chen Zhongjin To: , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH -next 6/7] riscv: stacktrace: Fix unwinding on ftrace_regs_call Date: Tue, 20 Sep 2022 23:12:01 +0800 Message-ID: <20220920151202.180057-7-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220920151202.180057-1-chenzhongjin@huawei.com> References: <20220920151202.180057-1-chenzhongjin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When unwinding on ftrace_regs_call, the traced function will be skipped because ftrace_regs_caller doesn't save the fp and ra. Save the encoded fp so that we can get the pt_regs so that we can unwind from ftrace_regs_call to the traced function. Also the pt_regs->status should be set as kernel mode. Stacktrace before this patch: Call Trace: ... [] handler_pre+0x30/0x4a [kprobe_unwind] [] aggr_pre_handler+0x60/0x94 [] kprobe_ftrace_handler+0x13e/0x188 [] ftrace_regs_call+0x8/0x10 [] do_one_initcall+0x4c/0x1f2 [] do_init_module+0x56/0x210 ... Stacktrace after this patch: Call Trace: ... [] handler_pre+0x30/0x4a [kprobe_unwind] [] aggr_pre_handler+0x60/0x94 [] kprobe_ftrace_handler+0x13e/0x188 [] ftrace_regs_call+0x8/0x10 + [] empty_call+0x0/0x1e [kprobe_unwind] [] do_one_initcall+0x4c/0x1f2 [] do_init_module+0x56/0x210 ... Signed-off-by: Chen Zhongjin --- arch/riscv/kernel/mcount-dyn.S | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index d171eca623b6..56a4014c392f 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -10,6 +10,8 @@ #include #include #include +#include +#include =20 .text =20 @@ -97,6 +99,11 @@ REG_S x29, PT_T4(sp) REG_S x30, PT_T5(sp) REG_S x31, PT_T6(sp) + +#ifdef CONFIG_FRAME_POINTER + li s0, SR_PP + REG_S s0, PT_STATUS(sp) +#endif .endm =20 .macro RESTORE_ALL @@ -172,6 +179,7 @@ ENDPROC(ftrace_caller) #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS ENTRY(ftrace_regs_caller) SAVE_ALL + ENCODE_FRAME_POINTER =20 addi a0, ra, -FENTRY_RA_OFFSET la a1, function_trace_op --=20 2.17.1