Skip to content

Commit 2234ae8

Browse files
avpatelMarc Zyngier
authored andcommitted
irqchip/sifive-plic: Setup cpuhp once after boot CPU handler is present
For multiple PLIC instances, the plic_init() is called once for each PLIC instance. Due to this we have two issues: 1. cpuhp_setup_state() is called multiple times 2. plic_starting_cpu() can crash for boot CPU if cpuhp_setup_state() is called before boot CPU PLIC handler is available. Address both issues by only initializing the HP notifiers when the boot CPU setup is complete. Fixes: f1ad113 ("irqchip/sifive-plic: Add support for multiple PLICs") Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 2458ed3 commit 2234ae8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/irqchip/irq-sifive-plic.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct plic_handler {
7676
void __iomem *enable_base;
7777
struct plic_priv *priv;
7878
};
79+
static bool plic_cpuhp_setup_done;
7980
static DEFINE_PER_CPU(struct plic_handler, plic_handlers);
8081

8182
static inline void plic_toggle(struct plic_handler *handler,
@@ -285,6 +286,7 @@ static int __init plic_init(struct device_node *node,
285286
int error = 0, nr_contexts, nr_handlers = 0, i;
286287
u32 nr_irqs;
287288
struct plic_priv *priv;
289+
struct plic_handler *handler;
288290

289291
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
290292
if (!priv)
@@ -313,7 +315,6 @@ static int __init plic_init(struct device_node *node,
313315

314316
for (i = 0; i < nr_contexts; i++) {
315317
struct of_phandle_args parent;
316-
struct plic_handler *handler;
317318
irq_hw_number_t hwirq;
318319
int cpu, hartid;
319320

@@ -367,9 +368,18 @@ static int __init plic_init(struct device_node *node,
367368
nr_handlers++;
368369
}
369370

370-
cpuhp_setup_state(CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING,
371+
/*
372+
* We can have multiple PLIC instances so setup cpuhp state only
373+
* when context handler for current/boot CPU is present.
374+
*/
375+
handler = this_cpu_ptr(&plic_handlers);
376+
if (handler->present && !plic_cpuhp_setup_done) {
377+
cpuhp_setup_state(CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING,
371378
"irqchip/sifive/plic:starting",
372379
plic_starting_cpu, plic_dying_cpu);
380+
plic_cpuhp_setup_done = true;
381+
}
382+
373383
pr_info("mapped %d interrupts with %d handlers for %d contexts.\n",
374384
nr_irqs, nr_handlers, nr_contexts);
375385
set_handle_irq(plic_handle_irq);

0 commit comments

Comments
 (0)