Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

openrisc: Fix IPIs on simple multicore systems

Commit c05671846451 ("openrisc: sleep instead of spin on secondary
wait") fixed OpenRISC SMP Linux for QEMU. However, stability was never
achieved on FPGA development boards. This is because the above patch
has a step to unmask IPIs on non-boot cpu's but on hardware without
power management, IPIs remain masked.

This meant that IPI's were never actually working on the simple SMP
systems we run on development boards. The systems booted but stability
was very suspect.

Add the ability to unmask IPI's on the non-boot cores. This is done by
making the OMPIC IRQs proper percpu IRQs. We can then use the
enabled_percpu_irq() to unmask IRQ on the non-boot cpus.

Update the or1k PIC driver to use a flow handler that can switch between
percpu and the configured level or edge flow handlers at runtime.
This mechanism is inspired by that done in the J-Core AIC driver.

Signed-off-by: Stafford Horne <shorne@gmail.com>
Acked-by: Thomas Gleixner <tglx@kernel.org>

+61 -8
+2 -1
arch/openrisc/include/asm/smp.h
··· 20 20 extern void arch_send_call_function_single_ipi(int cpu); 21 21 extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); 22 22 23 - extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int)); 23 + extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int), 24 + unsigned int irq); 24 25 extern void handle_IPI(unsigned int ipi_msg); 25 26 26 27 #endif /* __ASM_OPENRISC_SMP_H */
+21 -1
arch/openrisc/kernel/smp.c
··· 13 13 14 14 #include <linux/smp.h> 15 15 #include <linux/cpu.h> 16 + #include <linux/interrupt.h> 16 17 #include <linux/sched.h> 17 18 #include <linux/sched/mm.h> 18 19 #include <linux/irq.h> ··· 26 25 27 26 asmlinkage __init void secondary_start_kernel(void); 28 27 28 + static unsigned int ipi_irq __ro_after_init; 29 29 static void (*smp_cross_call)(const struct cpumask *, unsigned int); 30 30 31 31 unsigned long secondary_release = -1; ··· 40 38 }; 41 39 42 40 static DEFINE_SPINLOCK(boot_lock); 41 + 42 + static void or1k_ipi_enable(void) 43 + { 44 + if (WARN_ON_ONCE(!ipi_irq)) 45 + return; 46 + 47 + enable_percpu_irq(ipi_irq, 0); 48 + } 43 49 44 50 static void boot_secondary(unsigned int cpu, struct task_struct *idle) 45 51 { ··· 146 136 complete(&cpu_running); 147 137 148 138 synchronise_count_slave(cpu); 139 + or1k_ipi_enable(); 149 140 set_cpu_online(cpu, true); 150 141 151 142 local_irq_enable(); ··· 206 195 smp_call_function(stop_this_cpu, NULL, 0); 207 196 } 208 197 209 - void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int)) 198 + void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int), 199 + unsigned int irq) 210 200 { 201 + if (WARN_ON(ipi_irq)) 202 + return; 203 + 211 204 smp_cross_call = fn; 205 + 206 + ipi_irq = irq; 207 + 208 + /* Enabled IPIs for boot CPU immediately */ 209 + or1k_ipi_enable(); 212 210 } 213 211 214 212 void arch_send_call_function_single_ipi(int cpu)
+12 -5
drivers/irqchip/irq-ompic.c
··· 84 84 85 85 static void __iomem *ompic_base; 86 86 87 + static DEFINE_PER_CPU_READ_MOSTLY(int, ipi_dummy_dev); 88 + 87 89 static inline u32 ompic_readreg(void __iomem *base, loff_t offset) 88 90 { 89 91 return ioread32be(base + offset); ··· 185 183 goto out_unmap; 186 184 } 187 185 188 - ret = request_irq(irq, ompic_ipi_handler, IRQF_PERCPU, 189 - "ompic_ipi", NULL); 190 - if (ret) 191 - goto out_irq_disp; 186 + irq_set_percpu_devid(irq); 187 + ret = request_percpu_irq(irq, ompic_ipi_handler, "ompic_ipi", 188 + &ipi_dummy_dev); 192 189 193 - set_smp_cross_call(ompic_raise_softirq); 190 + if (ret) { 191 + pr_err("ompic: failed to request irq %d, error: %d", 192 + irq, ret); 193 + goto out_irq_disp; 194 + } 195 + 196 + set_smp_cross_call(ompic_raise_softirq, irq); 194 197 195 198 return 0; 196 199
+26 -1
drivers/irqchip/irq-or1k-pic.c
··· 118 118 generic_handle_domain_irq(root_domain, irq); 119 119 } 120 120 121 + /* 122 + * The OR1K PIC is a cpu-local interrupt controller and does not distinguish or 123 + * use distinct irq number ranges for per-cpu event interrupts (IPI). Since 124 + * information to determine whether a particular irq number should be treated as 125 + * per-cpu is not available at mapping time, we use a wrapper handler function 126 + * which chooses the right handler at runtime based on whether IRQF_PERCPU was 127 + * used when requesting the irq. Borrowed from J-Core AIC. 128 + */ 129 + static void or1k_irq_flow_handler(struct irq_desc *desc) 130 + { 131 + #ifdef CONFIG_SMP 132 + struct irq_data *data = irq_desc_get_irq_data(desc); 133 + struct or1k_pic_dev *pic = data->domain->host_data; 134 + 135 + if (irqd_is_per_cpu(data)) 136 + handle_percpu_devid_irq(desc); 137 + else 138 + pic->handle(desc); 139 + #endif 140 + } 141 + 121 142 static int or1k_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw) 122 143 { 123 144 struct or1k_pic_dev *pic = d->host_data; 124 145 125 - irq_set_chip_and_handler(irq, &pic->chip, pic->handle); 146 + if (IS_ENABLED(CONFIG_SMP)) 147 + irq_set_chip_and_handler(irq, &pic->chip, or1k_irq_flow_handler); 148 + else 149 + irq_set_chip_and_handler(irq, &pic->chip, pic->handle); 150 + 126 151 irq_set_status_flags(irq, pic->flags); 127 152 128 153 return 0;