Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp202234imw; Fri, 8 Jul 2022 01:02:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vCKiOOwCYYGSS7+FXqlDGmtM0LHVzVUfofPMMNTxx6Pln/u/GC8nstOdZRSla7yfRz2r5R X-Received: by 2002:a17:90a:ff94:b0:1ef:8e7b:c93f with SMTP id hf20-20020a17090aff9400b001ef8e7bc93fmr2663876pjb.104.1657267321466; Fri, 08 Jul 2022 01:02:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657267321; cv=none; d=google.com; s=arc-20160816; b=RydutJBHDa1w4vjq4DFMScvlpALnzTYq6FhuG55WgoEwNdYEHYmaSFfQKUtRizajZf AYwA4qkAVk7MThmb+2eLEtYdChNLrMit7J5lC2YIoQZn6jxeCJ3tRcLVvmpB+ux1T1Qx kq6Eu42beJfJk/Dw0P1ImYd71gBHM4nmFRsuvz7aKoperPvyG9M8hxZRaOqrWHwIUL0P h6WGq1cND3sy6Pf3QRUSw5z63iwo+llJya/Y1738KzXTF3zNzLeXlCc5QcjxezRUJCon d4NT5l0blggjZfGXdRga8RAimEph6wwbMo67oldm5CbvlQ4MU0ml6auRSFa3ybyaGO3h 1WbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=Xxe+QJ6kSPnmylv57503Y0BuLVtLnsRInDitHe+JLog=; b=ZQCZGIKgf4QkCyy7C18psjJbrupcjR+nFP0+Wj238gBYzykvNXvFh+7fHzG9tW7EuE XILUqWcKLdIxJOmT6sKXSeskC7TgPULI3AJrMpf3CS9+pGrELUU0Kho+vLiae3OR5oYz PQlYnJq1nyqeIf7UocAIeq6kHcE5a+aGtT2LTFkQh7TU2g7ORyAc5EDJ+XXa5IuzJ1k4 C75Bi/hgk36Iltz2mHOrVF+ykrYDgyju6VyBxmrITAYhwf3a++ULXRtM1haNejzVTeqA 3n5qtqEdsf++Wg49X3Uc+psvd4WnuhPAQvxUoLW+KhDMlhWmOWkRfmpezGkFujMRaQUp Yxtw== 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 h11-20020a170902f54b00b0016bfdca1243si12173416plf.275.2022.07.08.01.01.33; Fri, 08 Jul 2022 01:02:01 -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 S237621AbiGHHcC (ORCPT + 99 others); Fri, 8 Jul 2022 03:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237607AbiGHHb7 (ORCPT ); Fri, 8 Jul 2022 03:31:59 -0400 Received: from out199-1.us.a.mail.aliyun.com (out199-1.us.a.mail.aliyun.com [47.90.199.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 714537C1AB for ; Fri, 8 Jul 2022 00:31:58 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VIicMb8_1657265513; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VIicMb8_1657265513) by smtp.aliyun-inc.com; Fri, 08 Jul 2022 15:31:54 +0800 From: Xianting Tian To: palmer@dabbelt.com Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, guoren@kernel.org, Xianting Tian Subject: [RESEND PATCH V5 1/2] RISC-V: Fixup fast call of crash_kexec() Date: Fri, 8 Jul 2022 15:31:49 +0800 Message-Id: <20220708073150.352830-2-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220708073150.352830-1-xianting.tian@linux.alibaba.com> References: <20220708073150.352830-1-xianting.tian@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,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