From nobody Fri Sep 5 20:03:51 2025 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 5C652C38159 for ; Tue, 23 Aug 2022 12:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359531AbiHWMGI (ORCPT ); Tue, 23 Aug 2022 08:06:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359279AbiHWMBE (ORCPT ); Tue, 23 Aug 2022 08:01:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B80E956B4; Tue, 23 Aug 2022 02:35:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 315C461460; Tue, 23 Aug 2022 09:34:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 394E3C433D6; Tue, 23 Aug 2022 09:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661247277; bh=IRbIsN0AupDAgZNVGkixlOAzpjRVaFRHazxcux/MI2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ngbQ7Ig83h54zVaLbk9c2Vglrp3xb4xRrOrMjI5OGSP4WIfZD8TxIj3roF9YWzMW4 3Jd+N1GqNzeVUrWrxu8K9ZTpNz6BQoK1CObpSwBDrIKFqXCPv3Il4wb5ZPxCNpGMps Ry0qapn3yzRlXeRJnzIE1wwkNQ+155oMsiIz2Yo4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guo Ren , Xianting Tian , Palmer Dabbelt , Sasha Levin Subject: [PATCH 5.4 375/389] RISC-V: Add fast call path of crash_kexec() Date: Tue, 23 Aug 2022 10:27:33 +0200 Message-Id: <20220823080131.217915484@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xianting Tian [ Upstream commit 3f1901110a89b0e2e13adb2ac8d1a7102879ea98 ] 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=3D) at drivers/= test_crash.c:81 81 *(int *)p =3D 0xdead; (gdb) (gdb) bt #0 0xffffffe00064d5c0 in test_thread (data=3D) at drivers/= test_crash.c:81 #1 0x0000000000000000 in ?? () Test code to produce NULL address dereference in test_crash.c, void *p =3D NULL; *(int *)p =3D 0xdead; Reviewed-by: Guo Ren Tested-by: Xianting Tian Signed-off-by: Xianting Tian Link: https://lore.kernel.org/r/20220606082308.2883458-1-xianting.tian@linu= x.alibaba.com Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- 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 473de3ae8bb7..ae462037910b 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include #include @@ -43,6 +44,9 @@ void die(struct pt_regs *regs, const char *str) =20 ret =3D notify_die(DIE_OOPS, str, regs, 0, regs->scause, SIGSEGV); =20 + if (regs && kexec_should_crash(current)) + crash_kexec(regs); + bust_spinlocks(0); add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irq(&die_lock); --=20 2.35.1