Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp211726iof; Mon, 6 Jun 2022 01:42:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/HftfdeTFohItPZsun3fOz1lW1L+SF3/YjhBIOaQ2XCQkA7EGz7Nx+7zyhVituAhX4ojx X-Received: by 2002:a63:c00c:0:b0:3fc:dc35:6192 with SMTP id h12-20020a63c00c000000b003fcdc356192mr19100593pgg.7.1654504962570; Mon, 06 Jun 2022 01:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654504962; cv=none; d=google.com; s=arc-20160816; b=NSOvpiKFQnBOmrrPaNViBLdF5ZHCGv41qO60sn4wLApufZlOfMrXW3uGXJvX5owL8P A/MP0FhB1xMKgOsUPt9YzlvCza3jaRwZ3TlIGt0dmsJPa+1nhAUHkNmUqyQF7CJnaciH WUWo5LWV2Xdny+kt4oT2JAto5NtD8a1gZwE5eMrQ9LzGrmdbChLqyzVYakDyb2P1ZvpI tNRPqS899hLcdR7Usn3JH7O4x0ZO8+TYi43X2a/JyLhzwQJSdEMNMaV2o0cehlr6eKsX q6IsinNzxpDDenZjPTmeoCdA9AaSqGcJCIcPrb5tAYmACWUiST4aF1NoSPcDTctTQayv eQNQ== 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=XtSPu9hp+xeuJ0mp8HKoCQ/pXSdCD0X1cPoiYUjDCVs=; b=wa7MOf7qAGv8xTqnjUxSUQr62ygZ8KdywLcmBeyH1JtiYHZ0bYMfIbOEqtsxkGYGZO O4hF2rUlNEs66enlxTVakm18DdRnRNgM8Ln2+tu6H56WD9wRXGXxQ7voX4D9WGKBuUa2 7VrWysAM1Dj7KRXR3I/U3fGPaxNCf2LTQFYpeDL5K5mjrKhTPdQr0m1ARaXTJVqClx76 MZabu/5uMpJRybHYirnBvlycERBfA7x+iEMwKNshNWMDJ+x2u+0caqmkzOvsosWxEEi7 I1/wWEh3Fycq07udX4/wmEk4g4xZHuWzGt80E7Zqg7WrSqNstvxW+eFAeiH/KHP6F3vy eHOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 198-20020a6301cf000000b003fd8a009a30si6476773pgb.264.2022.06.06.01.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 01:42:42 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ADCFE3F890; Mon, 6 Jun 2022 01:23:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbiFFIXT (ORCPT + 99 others); Mon, 6 Jun 2022 04:23:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbiFFIXS (ORCPT ); Mon, 6 Jun 2022 04:23:18 -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 26E6110C8 for ; Mon, 6 Jun 2022 01:23:15 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VFUVkL4_1654503791; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VFUVkL4_1654503791) by smtp.aliyun-inc.com(127.0.0.1); Mon, 06 Jun 2022 16:23:12 +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: [RESEND PATCH v2] RISC-V: Add fast call path of crash_kexec() Date: Mon, 6 Jun 2022 16:23:08 +0800 Message-Id: <20220606082308.2883458-1-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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; Reviewed-by: Guo Ren Tested-by: Xianting Tian Signed-off-by: Xianting Tian --- Changes from v1: - simplify the commit message --- 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 fe92e119e6a3..e666ebfa2a64 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