Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2210056imw; Sun, 17 Jul 2022 04:03:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sb6LtUArJkmS6wVT0VtK5trO/vE9Z4Ky5/e8noUoxpV1BfaLYDMap7z8kub7U7TYND25k5 X-Received: by 2002:a17:907:3ea6:b0:72b:4a06:989a with SMTP id hs38-20020a1709073ea600b0072b4a06989amr21493692ejc.168.1658055797881; Sun, 17 Jul 2022 04:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658055797; cv=none; d=google.com; s=arc-20160816; b=zSo2eAiKJp5Z6yUvzjf5wKNXI2TT6pDRDWBS6eMvnSyBci5HV+GCkqbeTKm0tvwhiy Og18si7rOnPx8RPuSKNbu4LtWk/W6MqTkx1uYxt9AhPkOOAuCjnFFDxlSQpMU+5TBZZx 4zC6CcKyD3Bp3NrJllCrRJJS7eh4gDMhYKe96/GfwUGkKn1n6Q7LY+M7jU42m2SwZAsW CdWcoYI6VPPw/7rmZUdgA8/7av2HJM5UZlOchmK1u1+TutssUcmnwUoi+FDTgoJ5y5SI QyhuI/adBtj0IGO2WeZ6y3fm5nqBE1av6v6WodrRFAA4zJpCVbIvb5ouSJAuSqJIIhpO 9Z8w== 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=tM+p8VvNWlbdiUe2j4Hv7RiNUOzzblkWSS3lN7DINOrVbwvQF2ar0I9geW15A3y6ZK P34caZNWdLfN5aTJkOJOiHEfAclS7eG8I41RONkGteqKt9x3goTx1GALsTKpo5vxtsTu cc4fTEtN1gN4kq2iHFpQA4R1qKqRZlGz8pJ4q5Oq2zk6XYfp2UBJH0JTE8zPynki1aMz EFg8ZkuA9mu+ENC0VCoVZJFEx0NSjmXAr6iJnoWr3TTW8nGD37Ycg/hXOAIfQhRQy9Tn iMwh4GS2NqDC9cfIGofeL09tpUE+mdpi53+x1Jd5iljgut7Ynp9teg2V0o8MBMASmLsm lnww== 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 gn1-20020a1709070d0100b00729c19c5104si14190401ejc.437.2022.07.17.04.02.51; Sun, 17 Jul 2022 04:03:17 -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 S232902AbiGQKNg (ORCPT + 99 others); Sun, 17 Jul 2022 06:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232809AbiGQKNc (ORCPT ); Sun, 17 Jul 2022 06:13:32 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3579140B4 for ; Sun, 17 Jul 2022 03:13:31 -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=ay29a033018046049;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0VJXih1g_1658052806; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VJXih1g_1658052806) by smtp.aliyun-inc.com; Sun, 17 Jul 2022 18:13:27 +0800 From: Xianting Tian To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, anup@brainfault.org, heiko@sntech.de, guoren@kernel.org, mick@ics.forth.gr, alexandre.ghiti@canonical.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, crash-utility@redhat.com, huanyi.xj@alibaba-inc.com, heinrich.schuchardt@canonical.com, k-hagio-ab@nec.com, hschauhan@nulltrace.org, Xianting Tian Subject: [PATCH 1/5] RISC-V: Fixup fast call of crash_kexec() Date: Sun, 17 Jul 2022 18:13:19 +0800 Message-Id: <20220717101323.370245-2-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717101323.370245-1-xianting.tian@linux.alibaba.com> References: <20220717101323.370245-1-xianting.tian@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,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