]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
irqchip/sifive-plic: Setup cpuhp once after boot CPU handler is present
authorAnup Patel <anup.patel@wdc.com>
Mon, 18 May 2020 09:14:40 +0000 (14:44 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 22 Jun 2020 07:33:00 +0000 (09:33 +0200)
commit 2234ae846ccb9ebdf4c391824cb79e73674dceda upstream.

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: f1ad1133b18f ("irqchip/sifive-plic: Add support for multiple PLICs")
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200518091441.94843-3-anup.patel@wdc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/irqchip/irq-sifive-plic.c

index 6955890a01f79e169983bad9532816bfad674121..eb44816b8fada4e385a394557574f09810cc21f0 100644 (file)
@@ -76,6 +76,7 @@ struct plic_handler {
        void __iomem            *enable_base;
        struct plic_priv        *priv;
 };
+static bool plic_cpuhp_setup_done;
 static DEFINE_PER_CPU(struct plic_handler, plic_handlers);
 
 static inline void plic_toggle(struct plic_handler *handler,
@@ -285,6 +286,7 @@ static int __init plic_init(struct device_node *node,
        int error = 0, nr_contexts, nr_handlers = 0, i;
        u32 nr_irqs;
        struct plic_priv *priv;
+       struct plic_handler *handler;
 
        priv = kzalloc(sizeof(*priv), GFP_KERNEL);
        if (!priv)
@@ -315,7 +317,6 @@ static int __init plic_init(struct device_node *node,
 
        for (i = 0; i < nr_contexts; i++) {
                struct of_phandle_args parent;
-               struct plic_handler *handler;
                irq_hw_number_t hwirq;
                int cpu, hartid;
 
@@ -369,9 +370,18 @@ done:
                nr_handlers++;
        }
 
-       cpuhp_setup_state(CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING,
+       /*
+        * We can have multiple PLIC instances so setup cpuhp state only
+        * when context handler for current/boot CPU is present.
+        */
+       handler = this_cpu_ptr(&plic_handlers);
+       if (handler->present && !plic_cpuhp_setup_done) {
+               cpuhp_setup_state(CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING,
                                  "irqchip/sifive/plic:starting",
                                  plic_starting_cpu, plic_dying_cpu);
+               plic_cpuhp_setup_done = true;
+       }
+
        pr_info("mapped %d interrupts with %d handlers for %d contexts.\n",
                nr_irqs, nr_handlers, nr_contexts);
        set_handle_irq(plic_handle_irq);