Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1215423imi; Fri, 1 Jul 2022 05:34:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vGEOIFdi62dfXtHKc9NbyIiEKj4lRnSwDw3ORIqMp5JbKSlqvOwP3hW4OIyN4mogLg6W6P X-Received: by 2002:a05:6a00:4107:b0:527:fbd1:ce54 with SMTP id bu7-20020a056a00410700b00527fbd1ce54mr12670365pfb.45.1656678894204; Fri, 01 Jul 2022 05:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656678894; cv=none; d=google.com; s=arc-20160816; b=ahyGKr9qznrzdA4WV7qwhREicCdzl3RrNuIee6icH0uil1R+gus79WuXp2ufvRgoAr 10mjfNu2/kBvpfLsd5wDfNbgpBXOYI49iIExFOzZnFCVjK3rLnFotaOiaDL2xYq8jJP+ /vY2+88OC/pSkYZnYfQi69QM9EPmjr70gt7upyXEAshPEkueLBiXpHd48HpcE7mp9DNJ ciOpvecakYl2PfbByqc0WE8Jf251A0QXpdivvGh8WjsXZ3qcv/UZgzFkQ4YbunEjGcjc sJsAfblqmj7oE+Ezffn+8Vsc6HMNwu3RAB0NiOgr6zj48KYHkc9V3Yj60oCxc4jnCGEu lj9A== 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=T5daJHzsqWBOg4AFnWn7YTDNWKtTkAeJqAG/CghAbBa5r1sAQw/VcWA4UHvbG+KY8R OhQ1SUzkDO3n46szb5HiX8rzrik17LNVLlOEbA2yXwkaNKKrOT+A1Ye8YZN/MyQ2z2zm WeomyjgiDj0IPOQXodT6u69VCFKYRtneuU84lOTEGQ78i+zylIjVLMZ6kOQ9W8xDK0n2 dxzC2DfIn1mfWMLkuGFNfmoHZa7uPJD9xO4oCNAfi9HQRQ5g9v+vtjxRvBItdAL137e4 fBauRtlnHVv6ptssuMhJ5xCWBdQdlBS6hb4xyfN1lvEZmmyVjcE/TzF2QWD7jVOBYX+G 8BOQ== 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 c31-20020a634e1f000000b003fd943bd42asi1979431pgb.20.2022.07.01.05.34.41; Fri, 01 Jul 2022 05:34:54 -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 S236111AbiGAMF7 (ORCPT + 99 others); Fri, 1 Jul 2022 08:05:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235973AbiGAMF5 (ORCPT ); Fri, 1 Jul 2022 08:05:57 -0400 Received: from out199-14.us.a.mail.aliyun.com (out199-14.us.a.mail.aliyun.com [47.90.199.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A49BD83F00 for ; Fri, 1 Jul 2022 05:05:56 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R401e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VI2XUXD_1656677152; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VI2XUXD_1656677152) by smtp.aliyun-inc.com; Fri, 01 Jul 2022 20:05:52 +0800 From: Xianting Tian To: palmer@dabbelt.com Cc: guoren@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Xianting Tian Subject: [PATCH v5 2/3] RISC-V: Fixup fast call of crash_kexec() Date: Fri, 1 Jul 2022 20:05:47 +0800 Message-Id: <20220701120548.228261-3-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220701120548.228261-1-xianting.tian@linux.alibaba.com> References: <20220701120548.228261-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