Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4752803rwb; Tue, 20 Sep 2022 20:14:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6oea1lj4q+n/GxsdNhPWRicQewrAboSxER2waivjDMuQGiL3krq2H1G+l6e3M11hFGB60n X-Received: by 2002:a63:1344:0:b0:434:aa63:7ec1 with SMTP id 4-20020a631344000000b00434aa637ec1mr22223888pgt.189.1663730069143; Tue, 20 Sep 2022 20:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663730069; cv=none; d=google.com; s=arc-20160816; b=kkZqGwX6pOZXsdz1LIYSLGlG4k4Vic5EYoZYR22AZQPs9DHqjtrSHy2rkc7tRFYB8v 7solKN181kU7OQ+myqps4YzBGsBMqU1Uhb2M9gQcnu5tquVQN+LzEF1abHJJJYYRyu5n 5/8JwZmu5yQG8ifXicbnm/bOo+gQCJxt8tcY5N18zqTt50j9RLxPBZTR+4W8Nxp7qmOs VFV7R+Ra9gWk2iNFiKnsVPwobJRR7aifVbUsusb8FVwfGK18HWLBxQ5USB535XC1n0Nr KtImNr4EAnv+XIvcOwOiMQPWM/KQJYVZXfhmnOIaAuSGRRKhiyW/TNVA5noqQkasglAo JiYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Tpr6GF+lWtXwprzg4IqWj8OZuHobCwaeIGNSbM2eBoM=; b=Jo9h6d6katv53WHUzYQ6UOVAnlZqlwa2xU8iz2YfIDpADY5fE7v3LAtL7u9r+rSXA4 DtAbGZWS/i6tnfGt2bDWtatTUQ9KXYBwVzM34pcrlFoSrgAGV90YOE/D9zM95b18DEoG I6iwmd1uDMoOcFTPncCqu9PVJvTuXPKF7U2lVvZJ7RZ8sWY/CZAeV5+pQDJciRhmKzDX SLejAF9pp7uLI4Rr9df+4ygXLIK5ZcrDgRExgkDvsLcwHTey4hVW3WEtsGTYgtpv8N7/ gT5BmEgM0PtAMilJuZ970rGEaP4+6pe2uuLO0CJY7kJVXlGEvGTAdS7rPIDxyKVLvuP6 Ex2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x63-20020a638642000000b00438fe6610fbsi1604765pgd.838.2022.09.20.20.14.17; Tue, 20 Sep 2022 20:14:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbiIUDA3 (ORCPT + 99 others); Tue, 20 Sep 2022 23:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbiIUDAZ (ORCPT ); Tue, 20 Sep 2022 23:00:25 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF01167E8; Tue, 20 Sep 2022 20:00:23 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MXNMz1WBSzlWcH; Wed, 21 Sep 2022 10:56:15 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 21 Sep 2022 11:00:21 +0800 Received: from [10.67.108.67] (10.67.108.67) 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; Wed, 21 Sep 2022 11:00:21 +0800 Message-ID: <8b7093a5-291f-6c2f-e915-51b07d912ca1@huawei.com> Date: Wed, 21 Sep 2022 11:00:19 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.0 Subject: Re: [PATCH -next 6/7] riscv: stacktrace: Fix unwinding on ftrace_regs_call Content-Language: en-US To: Guo Ren CC: , , , , , , , , , , , , , , , , , , , References: <20220920151202.180057-1-chenzhongjin@huawei.com> <20220920151202.180057-7-chenzhongjin@huawei.com> From: Chen Zhongjin In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.108.67] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2022/9/21 9:43, Guo Ren wrote: > On Tue, Sep 20, 2022 at 11:15 PM Chen Zhongjin wrote: >> 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 >> >> .text >> >> @@ -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) > Change another register. > >> +#endif >> .endm >> >> .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 > Maybe the patch should merge with others, so separated make it hard to review. Thanks for review! Happy to see you have approved the ENCODE FP part. The patches is separated just because I wanted to paste the call trace result in commit message. I'll merge the ENCODE_FRAME_POINTER patches all together and do this in the cover. Also noticed another email for your ongoing patches. I'll review them and reply later. Best, Chen