Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp398582iof; Mon, 6 Jun 2022 05:43:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHY+tIgFmQQH/qc75c2K38EVrjgAfSiUKk//s3etsHxfpeoHGbjF1re+k4FirsHQEvMudx X-Received: by 2002:a63:d30e:0:b0:3fd:e23d:f7d2 with SMTP id b14-20020a63d30e000000b003fde23df7d2mr1998519pgg.277.1654519437686; Mon, 06 Jun 2022 05:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654519437; cv=none; d=google.com; s=arc-20160816; b=nyUAuVWqrrbfFSQWQKuVe7Q/5UffgSe9BmBaKsPPZRmUTQHNhPxFQHrpkPvTEahLPX Rwkj6pim+BV0VujQGM+RJxcn9bLg7iNzRrh4kLXeS0SVqWlKmWBG3oSRDpK6hTOnRM0Z 4/bwez1K/So7WaqRTbfvu7tkJdeasF9KTmYXadxO+5tKsgkg7zRZKE78UkatNN12s/m0 PBlrGlZjQ9rw0MCqZeboYS25Jnszy8Mai2HIuBtDmu84uCxGODA3Ou9wc4e9IFhEwP/G r/tCY86804nCEwEFY4eFQGTcA1b9SAfyA5+CbvmVAHA9IEXMiGm5Ff0DAFMo3OGxAN20 EPLQ== 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=qaReDSM0pqgLIysjIasvgHAVuTOmhcv6xcuzhZLzhV8=; b=RTJG35Y1hVmiOcrHJpAQf/mkCsminXNF6BboNmMgDG94IMJ92rFEdnJO2AHJYwSUAJ 7HbcFcnTmJqK9fpET42uD8njj53U4LjCfiNuYHwTMQqPF+I2+e0cTWZH3iJOzu4gyu2u JT1sxl8UI9HRory4QdB651qHj0rqmmkIJKZvOAQAz1tbH8W9OxVXKoRcnagecgBJBvuE RuoHAvsW0m+fpKKtzlsTn7Qpke82JuQq1VCqjEJnuhFgNjMQdzri1oDt0NWpArNX4Xrz HUxzcDCMKbCjBnM+ZAHS3/U0g5fqzVucrw2HDr1RSPW/or4cuiWe3G8XNfWhuSE+XsbG sHYw== 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 k15-20020aa788cf000000b0050dfc3c58fbsi11611318pff.5.2022.06.06.05.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 05:43:57 -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 8FEFD9D4D4; Mon, 6 Jun 2022 05:38:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237307AbiFFMh7 (ORCPT + 99 others); Mon, 6 Jun 2022 08:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237300AbiFFMh6 (ORCPT ); Mon, 6 Jun 2022 08:37:58 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5DA299687 for ; Mon, 6 Jun 2022 05:37:55 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VFYRvQg_1654519072; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VFYRvQg_1654519072) by smtp.aliyun-inc.com(127.0.0.1); Mon, 06 Jun 2022 20:37:53 +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: [PATCH v3] RISC-V: Add fixup to support fast call of crash_kexec() Date: Mon, 6 Jun 2022 20:37:50 +0800 Message-Id: <20220606123750.2884245-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; Fixes: 76d2a0493a17 ("RISC-V: Init and Halt Code") Reviewed-by: Guo Ren Signed-off-by: Xianting Tian --- Changes from v1: - simplify the commit message Changes from v2: - add fixup in title --- 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