Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp170318iog; Fri, 17 Jun 2022 01:01:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tcnAgoT2MaP30Q3zakqb57OUm5HxlMHmSjjSPw6+LAC1XA0VdPwxeK50zwDYp40/0z4b52 X-Received: by 2002:a05:6402:3325:b0:42d:e1d8:99e9 with SMTP id e37-20020a056402332500b0042de1d899e9mr10590514eda.87.1655452865550; Fri, 17 Jun 2022 01:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655452865; cv=none; d=google.com; s=arc-20160816; b=i0twewWbA2AjCsWQlHir7rdeT+ZlGWF/2NSh6/yNhKUUYLM/XnNtSr52Ec9fhsyBCC S7j5jQe/YU2bJg4Tv+CGKEjvsTx7o/mHOVMoxkelnAOvmUFp3C+Q9ffM9MwAS81JDQ0b gDq/8SabvaiLARJ0BA9cxbc8cHxVxU7AwQK9hNpjrOFEd7Vsr85juU71VPgxU34BYKKF FWTzzIyWLNDY2EfBbPnPmtOyztCMHd+mYqbWWNSBY1vG+O38r3kVSg2zfkb/arWjVHCZ ddA7T3IuIHC7TAnG0wJiKHmpLU3OyHjxCy7R/zpSTuF2GyZIdXW9++S72NPznXjWyynR 7ArQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=Xxe+QJ6kSPnmylv57503Y0BuLVtLnsRInDitHe+JLog=; b=P1Bo8GX+YO+id0sHT6kvvMCkOfvGAH3B9/Gak7OWUE4LlzxLNBU4lA/LYorcMr2mIR TiGhu9BV4GdRl7lstsYKTOCpA41vvI53e0qT7Gu6WSGo0RHmSKjHz6M8vUwMv7XBjiLw GDQqpyN9+d6xDVKhixUZ9rtWdGfRII9GoFV+Az5RtIQvYM7C0JxQidFmjEZXQQcWAy3b dgipI4uAr0c5z3ZD4BTscra1rtCUh7K8Kgz46APzndcQEmer0tAFs5RDGw/HAFh3tQGD 4oDMZqf8rxN8MbvAu4vaBaPSgbCMgQIIDK/cGf/HwEdUXRJv2z3NmD6zTXzYyy+udNXg lSPQ== 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=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a1709064fc800b0070dfd895c81si4932381ejw.647.2022.06.17.01.00.34; Fri, 17 Jun 2022 01:01:05 -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=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234739AbiFQH61 (ORCPT + 99 others); Fri, 17 Jun 2022 03:58:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234442AbiFQH60 (ORCPT ); Fri, 17 Jun 2022 03:58:26 -0400 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EBA933A10 for ; Fri, 17 Jun 2022 00:58:24 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R661e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VGeESV7_1655452700; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VGeESV7_1655452700) by smtp.aliyun-inc.com; Fri, 17 Jun 2022 15:58:21 +0800 From: Xianting Tian To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, wangkefeng.wang@huawei.com, 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, Xianting Tian Subject: [PATCH v4] RISC-V: Fixup fast call of crash_kexec() Date: Fri, 17 Jun 2022 15:58:18 +0800 Message-Id: <20220617075818.3606554-1-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 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 Reviewed-by: Kefeng Wang Signed-off-by: Xianting Tian --- 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); + bust_spinlocks(0); add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irq(&die_lock); -- 2.17.1