Skip to content

Commit

Permalink
sbi-con: do not panic on keypresses during boot (and remove useless l…
Browse files Browse the repository at this point in the history
…ock)

If you hit a key during boot before the line "console [sbi_console0] enabled", enjoy:

[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018
[    0.000000] Oops [#1]
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.6.2-g2afb779-dirty riscvarchive#9
[    0.000000] task: ffffffff80624410 ti: ffffffff80620000 task.ti: ffffffff80620000
[    0.000000] sepc: ffffffff802837f0 ra : ffffffff802837dc sp : ffffffff80621ca8
[    0.000000]  gp : ffffffff80646ec0 tp : ffffffff80624410 t0 : ffffffff8064bff0
[    0.000000]  t1 : 000000000000001e t2 : 0000000000008000 s0 : ffffffff80621cd8
[    0.000000]  s1 : 000000000000006a a0 : 0000000000000008 a1 : ffffffff8064b3b8
[    0.000000]  a2 : 000000000000001e a3 : 0000000000000017 a4 : 0000000000000000
[    0.000000]  a5 : ffffffff8064a000 a6 : 0000000000000001 a7 : 0000000000000000
[    0.000000]  s2 : ffffffff8064a000 s3 : 0000000000000000 s4 : 8000000000000001
[    0.000000]  s5 : 00000000024000c0 s6 : 00000000024000c0 s7 : 0000000000000020
[    0.000000]  s8 : 0000000000000010 s9 : 00000000000000c0 s10: ffffffff8f499c80
[    0.000000]  s11: ffffffff8f003300 t3 : 0000000000000001 t4 : 0000000000000002
[    0.000000]  t5 : 000000000000001e t6 : ffffffff8064b3cf
[    0.000000] sstatus: 0000000000040100 sbadaddr: 0000000000000018 scause: 0000000000000005
[    0.010000] ---[ end trace cb88537fdc8fa200 ]---
[    0.010000] Kernel panic - not syncing: Fatal exception in interrupt
[    0.010000] ---[ end Kernel panic - not syncing: Fatal exception in interrupt

We cannot just turn off software interrupts; we still want timer events.
So, while booting, simply discard keypresses until the tty is initialized.

The lock was removed since it guards against nothing.
It is safe to put characters into an initialized tty from any thread.
  • Loading branch information
terpstra committed Jul 10, 2016
1 parent 2afb779 commit a9474b8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions arch/riscv/kernel/sbi-con.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include <linux/interrupt.h>

#include <asm/sbi.h>
#include <asm/atomic.h>

static DEFINE_SPINLOCK(sbi_tty_port_lock);
static atomic_t tty_ready = ATOMIC_INIT(0);
static struct tty_port sbi_tty_port;
static struct tty_driver *sbi_tty_driver;

Expand All @@ -18,10 +19,11 @@ irqreturn_t sbi_console_isr(void)
if (ch < 0)
return IRQ_NONE;

spin_lock(&sbi_tty_port_lock);
tty_insert_flip_char(&sbi_tty_port, ch, TTY_NORMAL);
tty_flip_buffer_push(&sbi_tty_port);
spin_unlock(&sbi_tty_port_lock);
/* Do not deliver characters until tty subsystem has been started */
if (atomic_read(&tty_ready)) {
tty_insert_flip_char(&sbi_tty_port, ch, TTY_NORMAL);
tty_flip_buffer_push(&sbi_tty_port);
}

return IRQ_HANDLED;
}
Expand Down Expand Up @@ -110,6 +112,9 @@ static int __init sbi_console_init(void)
if (unlikely(ret))
goto out_tty_put;

/* Enable the console ISR */
atomic_set(&tty_ready, 1);

/* Poll the console once, which will trigger future interrupts */
sbi_console_isr();

Expand Down

0 comments on commit a9474b8

Please sign in to comment.