Commit 8b04825e authored by Vincent Chen's avatar Vincent Chen Committed by Paul Walmsley
Browse files

riscv: avoid kernel hangs when trapped in BUG()



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: default avatarVincent Chen <vincent.chen@sifive.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarPaul Walmsley <paul.walmsley@sifive.com>
parent da0c9ea1
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -124,23 +124,23 @@ static inline unsigned long get_break_insn_length(unsigned long pc)


asmlinkage void do_trap_break(struct pt_regs *regs)
asmlinkage void do_trap_break(struct pt_regs *regs)
{
{
#ifdef CONFIG_GENERIC_BUG
	if (!user_mode(regs)) {
	if (!user_mode(regs)) {
		enum bug_trap_type type;
		enum bug_trap_type type;


		type = report_bug(regs->sepc, regs);
		type = report_bug(regs->sepc, regs);
		switch (type) {
		switch (type) {
#ifdef CONFIG_GENERIC_BUG
		case BUG_TRAP_TYPE_NONE:
		case BUG_TRAP_TYPE_NONE:
			break;
			break;
		case BUG_TRAP_TYPE_WARN:
		case BUG_TRAP_TYPE_WARN:
			regs->sepc += get_break_insn_length(regs->sepc);
			regs->sepc += get_break_insn_length(regs->sepc);
			break;
			break;
		case BUG_TRAP_TYPE_BUG:
		case BUG_TRAP_TYPE_BUG:
#endif /* CONFIG_GENERIC_BUG */
		default:
			die(regs, "Kernel BUG");
			die(regs, "Kernel BUG");
		}
		}
	}
	}
#endif /* CONFIG_GENERIC_BUG */

	force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc));
	force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)(regs->sepc));
}
}