From mboxrd@z Thu Jan 1 00:00:00 1970 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 47871C433EF for ; Tue, 7 Jun 2022 01:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbiFGBqK (ORCPT ); Mon, 6 Jun 2022 21:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233175AbiFGBqH (ORCPT ); Mon, 6 Jun 2022 21:46:07 -0400 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEC979877A for ; Mon, 6 Jun 2022 18:46:05 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R561e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VFbCL8E_1654566361; Received: from B-LB6YLVDL-0141.local(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VFbCL8E_1654566361) by smtp.aliyun-inc.com; Tue, 07 Jun 2022 09:46:02 +0800 Subject: Re: [PATCH v3] RISC-V: Add fixup to support fast call of crash_kexec() To: Kefeng Wang , paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, philipp.tomsich@vrull.eu, ebiederm@xmission.com, heiko@sntech.de, vitaly.wool@konsulko.com, tongtiangen@huawei.com, guoren@kernel.org Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20220606123750.2884245-1-xianting.tian@linux.alibaba.com> From: Xianting Tian Message-ID: Date: Tue, 7 Jun 2022 09:46:01 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/6/7 上午9:21, Kefeng Wang 写道: > > On 2022/6/6 20:37, Xianting Tian wrote: >> Currently, almost all archs (x86, arm64, mips...) support fast call >> of crash_kexec() when "regs && kexec_should_crash()" is true. But >> RISC-V not, it can only enter crash system via panic(). However panic() >> doesn't pass the regs of the real accident scene to crash_kexec(), >> it caused we can't get accurate backtrace via gdb, >>     $ riscv64-linux-gnu-gdb vmlinux vmcore >>     Reading symbols from vmlinux... >>     [New LWP 95] >>     #0  console_unlock () at kernel/printk/printk.c:2557 >>     2557                    if (do_cond_resched) >>     (gdb) bt >>     #0  console_unlock () at kernel/printk/printk.c:2557 >>     #1  0x0000000000000000 in ?? () >> >> With the patch we can get the accurate backtrace, >>     $ riscv64-linux-gnu-gdb vmlinux vmcore >>     Reading symbols from vmlinux... >>     [New LWP 95] >>     #0  0xffffffe00063a4e0 in test_thread (data=) at >> drivers/test_crash.c:81 >>     81             *(int *)p = 0xdead; >>     (gdb) >>     (gdb) bt >>     #0  0xffffffe00064d5c0 in test_thread (data=) at >> drivers/test_crash.c:81 >>     #1  0x0000000000000000 in ?? () >> >> Test code to produce NULL address dereference in test_crash.c, >>     void *p = NULL; >>     *(int *)p = 0xdead; >> >> Fixes: 76d2a0493a17 ("RISC-V: Init and Halt Code") >> Reviewed-by: Guo Ren >> Signed-off-by: Xianting Tian >> --- >> Changes from v1: >> - simplify the commit message >> Changes from v2: >> - add fixup in title >> --- >>   arch/riscv/kernel/traps.c | 4 ++++ >>   1 file changed, 4 insertions(+) >> >> diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c >> index b40426509244..39d0f8bba4b4 100644 >> --- a/arch/riscv/kernel/traps.c >> +++ b/arch/riscv/kernel/traps.c >> @@ -16,6 +16,7 @@ >>   #include >>   #include >>   #include >> +#include >>     #include >>   #include >> @@ -44,6 +45,9 @@ void die(struct pt_regs *regs, const char *str) >>         ret = notify_die(DIE_OOPS, str, regs, 0, regs->cause, SIGSEGV); >>   +    if (regs && kexec_should_crash(current)) >> +        crash_kexec(regs); >> + > > It seems that the regs won't be null, right? except that, Autually both regs won't be null, But if it is triggered by panic() , the regs are got via riscv_crash_save_regs(), which are the regs of that moment, but not the real accident scene. > > Reviewed-by: Kefeng Wang > >>       bust_spinlocks(0); >>       add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); >>       spin_unlock_irq(&die_lock);