Skip to content

Commit 098fdbc

Browse files
Niklas CasselMarc Zyngier
authored andcommitted
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
1 parent 0d3616b commit 098fdbc

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

drivers/irqchip/irq-sifive-plic.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,21 @@ static int plic_parent_irq __ro_after_init;
8181
static bool plic_cpuhp_setup_done __ro_after_init;
8282
static DEFINE_PER_CPU(struct plic_handler, plic_handlers);
8383

84-
static inline void plic_toggle(struct plic_handler *handler,
85-
int hwirq, int enable)
84+
static void __plic_toggle(void __iomem *enable_base, int hwirq, int enable)
8685
{
87-
u32 __iomem *reg = handler->enable_base + (hwirq / 32) * sizeof(u32);
86+
u32 __iomem *reg = enable_base + (hwirq / 32) * sizeof(u32);
8887
u32 hwirq_mask = 1 << (hwirq % 32);
8988

90-
raw_spin_lock(&handler->enable_lock);
9189
if (enable)
9290
writel(readl(reg) | hwirq_mask, reg);
9391
else
9492
writel(readl(reg) & ~hwirq_mask, reg);
93+
}
94+
95+
static void plic_toggle(struct plic_handler *handler, int hwirq, int enable)
96+
{
97+
raw_spin_lock(&handler->enable_lock);
98+
__plic_toggle(handler->enable_base, hwirq, enable);
9599
raw_spin_unlock(&handler->enable_lock);
96100
}
97101

@@ -324,8 +328,18 @@ static int __init plic_init(struct device_node *node,
324328
* Skip contexts other than external interrupts for our
325329
* privilege level.
326330
*/
327-
if (parent.args[0] != RV_IRQ_EXT)
331+
if (parent.args[0] != RV_IRQ_EXT) {
332+
/* Disable S-mode enable bits if running in M-mode. */
333+
if (IS_ENABLED(CONFIG_RISCV_M_MODE)) {
334+
void __iomem *enable_base = priv->regs +
335+
CONTEXT_ENABLE_BASE +
336+
i * CONTEXT_ENABLE_SIZE;
337+
338+
for (hwirq = 1; hwirq <= nr_irqs; hwirq++)
339+
__plic_toggle(enable_base, hwirq, 0);
340+
}
328341
continue;
342+
}
329343

330344
hartid = riscv_of_parent_hartid(parent.np);
331345
if (hartid < 0) {

0 commit comments

Comments
 (0)