Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2190143iob; Sun, 15 May 2022 10:37:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+EKOI0hXAhOSgY6m1BXuqKY6ZPYwUWHdshwwk02ja0Leyt/dZU/bvy+3SVL336gr/vkol X-Received: by 2002:a17:906:9c82:b0:6e1:2c94:1616 with SMTP id fj2-20020a1709069c8200b006e12c941616mr12186595ejc.64.1652636235802; Sun, 15 May 2022 10:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652636235; cv=none; d=google.com; s=arc-20160816; b=vCrMsR5jmk2XjJdnAFQsyHaZHtQ6JnwqGlIhlzfP3BAjRWwHRl2YEQht230XA3Yyb9 QlrhFBb5OYpdu7BI+MC2Ybwoy0sCqz5LC1fAlHivtUP+2Lop3m5x8IstxM2UDdOwOugm qcOiBw/dTcJ0nzCSdgP/QThTfIOsKQfpF0pFHBBl5sKCgNoDQ0PPnrqrDxdvfGzPV8Ia rBgywcS9cJwrXfoN7skzBbru+xX8wWLfx0dnJIXHZUHKHzjrcfGIOfs15lw7RJ8izhaI PXgWp4kWf8GJjkSlmN+tsAXHEj2iiJmnUw1+Wmuh6mSMd30f8jieuyUvRPfRvu4yLU4m Io6Q== 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=dexYuJWfG16oZebIIhI/r5kLBI0s3raqsJXts3t9LQc=; b=tq+FzV1EzMd9LVWBD9BwU6BybNXPFDfuEZMt74/DWQFCbydapBUmD2Ictf259Y2xo6 Z4zXVjnZ/v/VV8/o6etU22AXq/NBk4cLNd93qKlsLdmWu0R+sDoifMjlCMz1HxfHUjM5 RMssNtiEXJe3gtWJaO9Keggw76ZaN/1TX8B0RnQSRiVwF419FMXnHBeXpwllFpniPKKl +RfbdEkEu2g8h4SJx3vZwXWN33AQi05U1OI7cHiI+QQECyMN6cjekWlvNVpB1Yw4TdZE eqk3CxaeZS9ZIR0o55XQGa1jUFwTOUDgPMUT/0IYaN+wIQBQO5JktKtsntF3jL0gcyTP wOAQ== 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 cr19-20020a170906d55300b006f3b8a62ff1si8329489ejc.123.2022.05.15.10.36.48; Sun, 15 May 2022 10:37:15 -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 S236214AbiEONOZ (ORCPT + 99 others); Sun, 15 May 2022 09:14:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236864AbiEONOP (ORCPT ); Sun, 15 May 2022 09:14:15 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1488613F41 for ; Sun, 15 May 2022 06:14:13 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VDAcGqu_1652620449; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VDAcGqu_1652620449) by smtp.aliyun-inc.com(127.0.0.1); Sun, 15 May 2022 21:14:09 +0800 From: Xianting Tian To: paul.walmsley@sifive.com, aou@eecs.berkeley.edu, palmer@dabbelt.com, wangkefeng.wang@huawei.com, vitaly.wool@konsulko.com, rmk+kernel@armlinux.org.uk, ebiederm@xmission.com, tongtiangen@huawei.co Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, guoren@kernel.org, mick@ics.forth.gr, Xianting Tian Subject: [PATCH] RISC-V: Add fast call path of crash_kexec() Date: Sun, 15 May 2022 21:14:07 +0800 Message-Id: <20220515131407.946832-1-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,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/virtio/virtio_mmio.c:806 806 *(int *)p = 0xdead; (gdb) (gdb) bt #0 0xffffffe00063a4e0 in test_thread (data=) at drivers/virtio/virtio_mmio.c:806 #1 0x0000000000000000 in ?? () Test code to produce NULL address dereference, +extern int panic_on_oops; +static struct task_struct *k; +static int test_thread(void *data) { + + void *p = NULL; + + while (!panic_on_oops) + msleep(2000); + + *(int *)p = 0xdead; + + return 0; +} + static int __init virtio_mmio_init(void) { + k = kthread_run(test_thread, NULL, "test_thread"); + if (IS_ERR(k)) + pr_err("Couldn't create test kthread\n"); + return platform_driver_register(&virtio_mmio_driver); } 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 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