riscv: avoid kernel hangs when trapped in BUG()
authorVincent Chen <vincent.chen@sifive.com>
Mon, 23 Sep 2019 00:45:14 +0000 (08:45 +0800)
committerPaul Walmsley <paul.walmsley@sifive.com>
Mon, 7 Oct 2019 19:59:40 +0000 (12:59 -0700)
When the CONFIG_GENERIC_BUG is disabled by disabling CONFIG_BUG, if a
kernel thread is trapped by BUG(), the whole system will be in the
loop that infinitely handles the ebreak exception instead of entering the
die function. To fix this problem, the do_trap_break() will always call
the die() to deal with the break exception as the type of break is
BUG_TRAP_TYPE_BUG.

Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Paul Walmsley <paul.walmsley@sifive.com>
arch/riscv/kernel/traps.c

index 424eb72d56b10c51120cf02a6618a504f37d41f9..055a937aca70a770b4147df54efecfa2d621c0c4 100644 (file)
@@ -124,23 +124,23 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
 
 asmlinkage void do_trap_break(struct pt_regs *regs)
 {
-#ifdef CONFIG_GENERIC_BUG
        if (!user_mode(regs)) {
                enum bug_trap_type type;
 
                type = report_bug(regs->sepc, regs);
                switch (type) {
+#ifdef CONFIG_GENERIC_BUG
                case BUG_TRAP_TYPE_NONE:
                        break;
                case BUG_TRAP_TYPE_WARN:
                        regs->sepc += get_break_insn_length(regs->sepc);
                        break;
                case BUG_TRAP_TYPE_BUG:
+#endif /* CONFIG_GENERIC_BUG */
+               default:
                        die(regs, "Kernel BUG");
                }
        }
-#endif /* CONFIG_GENERIC_BUG */
-
        force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc));
 }