irqchip/sifive-plic: Disable S-mode IRQs if running in M-mode
authorNiklas Cassel <niklas.cassel@wdc.com>
Wed, 2 Mar 2022 13:15:53 +0000 (13:15 +0000)
committerMarc Zyngier <maz@kernel.org>
Wed, 2 Mar 2022 13:30:50 +0000 (13:30 +0000)
commit098fdbc3531f06aae2426b3a6f9bd730e7691258
treef1a22ad2d8f3cc142994117555ed98e52557714c
parent0d3616bbd03cdfaa8a5fdf38e0fec2b1ef6ec0a0
irqchip/sifive-plic: Disable S-mode IRQs if running in M-mode

When detecting a context for a privilege mode different from the current
running privilege mode, we simply skip to the next context register.

This means that we never clear the S-mode enable bits when running in
M-mode.

On canaan k210, a bunch of S-mode interrupts are enabled by the bootrom.
These S-mode specific interrupts should never trigger, since we never set
the mie.SEIE bit in the parent interrupt controller (riscv-intc).

However, we will be able to see the mip.SEIE bit set as pending.

This isn't a good default when CONFIG_RISCV_M_MODE is set, since in that
case we will never enter a lower privilege mode (e.g. S-mode).

Let's clear the S-mode enable bits when running the kernel in M-mode, such
that we won't have a interrupt pending bit set, which we will never clear.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220302131544.3166154-3-Niklas.Cassel@wdc.com
drivers/irqchip/irq-sifive-plic.c