From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11D7C342518 for ; Wed, 17 Dec 2025 08:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765958951; cv=none; b=rjMgt2TT3FgYyppWxbrMyJuNHZV6sTZW2sRs5d5aLLtYBSk8/GODeZItpHvFPsd7YYrDORjVVGG9S6m+t46l4IFqd6JcR+S6qyHzYWuz5xFoW30mKHmkO5YYDM9YizDjJxUpvTw0IdA/OcwZN+Tv+dBWZD7KaYsBKY6KaLq89Us= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765958951; c=relaxed/simple; bh=Upo/KeJ1tydzhEX3FEnB2Lq6CdSMUiNT1LlycW0K1NM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I6n2TvUmlHa4Zz8kqswm1Wgx2wLYUdnMHyofpuv8GBo88eWVWWJMhbsF2+FEdjRajwN3qmJYPpiXQKSrkZS4+ycc7rjP3T4zJ7HRlKPR8rdzv38PvtLKNVAi3EQm7vGtTKOBKhuWdIE63tYd2M4MyG4aLeHtBezKMjIEFu5+3no= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nPayYxL2; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nPayYxL2" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4779a4fc95aso1602785e9.1 for ; Wed, 17 Dec 2025 00:09:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765958948; x=1766563748; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VFXHMGeoomdbZOLp3ce3D0yDHo0q4hSajO4R4fHl4CQ=; b=nPayYxL2f6oP7HUVKxICogu72BNfjl5QmcC4GmE+RiKQalXJaNg0DzKf6UFXB+ZGsu vxYwUwRjGzs86Y/yz/KgXIP67jHetvG3h1nLuRk2s7SCVf26guPMUlpvWuEDeH2y3KBC twYKwLiV7jPjdlrJIKwFILKPt+jcVLrMV8UhPZ+1TxmyxqiviI1ftbFjmD+fHX4H/kLz XnWDP9mhsVj0WYSgGa/P0/dSExPN3S5aDsYIs3vJcCGvuZgU0u38VR8uTONEY3XrIY2/ 3k1xJOJHmUhqsxQhuiz9thZfF7up2Zn/bnQRUx/zxiARX7CJVSde8Bne8EMoiHKmZs7k 3D2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765958948; x=1766563748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VFXHMGeoomdbZOLp3ce3D0yDHo0q4hSajO4R4fHl4CQ=; b=ea74LBz0nnIwWfjHf/xSKHyrTCwr9dyZiEPJBc5f7+CHpEKul2Y5dOs1tSWTFNpnWz dEboJd7IGfbxHCxtEymScSgJeNGgguBx6JqcWp70ceCY0v58lcawfZFKKarGyUOBTqX6 Lo6Rj/EsjNe02oPmFbZsftXkYWuqxoGHRXzSye5vd83hS8YF55NOag9Mj4aByCM45whM D0+33bzD5UtIxoKymoeg7MtKJSXDcGURX7Gu4D+aiw4seSTFTi7EsN5Y2UitGgwJJDYa l4kowCYlaT3QvzGEqj1SuGVY5nQHMoUlzHM2incy2qAgkQ/145OK9dJZdF6tvX8QXHqD xQrA== X-Gm-Message-State: AOJu0YzctATD83GTefjUOzhV8GZkwlOAZIiRlVj4a3dKEh2zD98L5Jmj zHclzrj/lCGZ8uIjBH4+Kb/JW3d9CaKutWNvk3CM0drb2EpWyE6eql5b X-Gm-Gg: AY/fxX7LUbKIxl9jNaGFpT4Av73NgxA397nYWbAgldXOIMTu7ouBc3qvx9VUSvra3E/ F89YWnQ7ptIPd2eNCZYjVemmFZ3/mehEBNKRReSV170GwBv1MOEblE1fUgK2l7Y9bfjOJatRxGW tND0us9afJi3vxN+wX1NqrQbh3KpRJIzzBS3iX9KLybElhMdo/oCU3IrOX9JtfrDbp7SiFRJMWV hT8j4tIWAatQkcM23IITqI1knzYtsVZ8VRt4+eJMtI3SOW72UQcnzLuXEfSXjRKN+aEeDKaNtV9 mT7csLMQf3YuN4uQODTsAowqKXFBgJDKnH6vTGL9eMc9QiPkG2guI8eOsxv/SUtGDNCgNzjKUN7 tFd8oLku3AeYqVN2ub4cEcDjsNXSs4PTSoaJ9FQL36POgTKplIj/vUm2Mnph9sOQpIJOBpqifk+ z1rTLpf5z7HPmhDfyDK9T8V9kYBKh0J1WZYl5YPtOlW2vBWscY8ozwTZzAMPlmrFql X-Google-Smtp-Source: AGHT+IFdA/DhWhc0fvmsOUqd7FLcG+OG0v2ccGRkQHL3gBaAO1Q1UrtDjoq1SDubt5kPWl7UFxdxGA== X-Received: by 2002:a05:600c:444a:b0:46e:59bd:f7e2 with SMTP id 5b1f17b1804b1-47a8f1c20e1mr166323265e9.11.1765958947878; Wed, 17 Dec 2025 00:09:07 -0800 (PST) Received: from localhost (brnt-04-b2-v4wan-170138-cust2432.vm7.cable.virginm.net. [94.175.9.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47bdc14b421sm25574375e9.0.2025.12.17.00.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 00:09:06 -0800 (PST) From: Stafford Horne To: LKML Cc: Linux OpenRISC , Stafford Horne , Jonas Bonn , Stefan Kristiansson , Thomas Gleixner Subject: [PATCH v2 3/5] openrisc: Fix IPIs on simple multicore systems Date: Wed, 17 Dec 2025 08:08:29 +0000 Message-ID: <20251217080843.70621-4-shorne@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251217080843.70621-1-shorne@gmail.com> References: <20251217080843.70621-1-shorne@gmail.com> Precedence: bulk X-Mailing-List: linux-openrisc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- arch/openrisc/include/asm/smp.h | 3 ++- arch/openrisc/kernel/smp.c | 22 +++++++++++++++++++++- drivers/irqchip/irq-ompic.c | 15 +++++++++++---- drivers/irqchip/irq-or1k-pic.c | 27 ++++++++++++++++++++++++++- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/arch/openrisc/include/asm/smp.h b/arch/openrisc/include/asm/smp.h index e21d2f12b5b6..007296f160ef 100644 --- a/arch/openrisc/include/asm/smp.h +++ b/arch/openrisc/include/asm/smp.h @@ -20,7 +20,8 @@ extern void smp_init_cpus(void); extern void arch_send_call_function_single_ipi(int cpu); extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); -extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int)); +extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int), + unsigned int irq); extern void handle_IPI(unsigned int ipi_msg); #endif /* __ASM_OPENRISC_SMP_H */ diff --git a/arch/openrisc/kernel/smp.c b/arch/openrisc/kernel/smp.c index 86da4bc5ee0b..040ca201b692 100644 --- a/arch/openrisc/kernel/smp.c +++ b/arch/openrisc/kernel/smp.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,7 @@ asmlinkage __init void secondary_start_kernel(void); +static unsigned int ipi_irq __ro_after_init; static void (*smp_cross_call)(const struct cpumask *, unsigned int); unsigned long secondary_release = -1; @@ -39,6 +41,14 @@ enum ipi_msg_type { static DEFINE_SPINLOCK(boot_lock); +static void or1k_ipi_enable(void) +{ + if (WARN_ON_ONCE(!ipi_irq)) + return; + + enable_percpu_irq(ipi_irq, 0); +} + static void boot_secondary(unsigned int cpu, struct task_struct *idle) { /* @@ -136,6 +146,7 @@ asmlinkage __init void secondary_start_kernel(void) complete(&cpu_running); synchronise_count_slave(cpu); + or1k_ipi_enable(); set_cpu_online(cpu, true); local_irq_enable(); @@ -195,9 +206,18 @@ void smp_send_stop(void) smp_call_function(stop_this_cpu, NULL, 0); } -void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int)) +void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int), + unsigned int irq) { + if (WARN_ON(ipi_irq)) + return; + smp_cross_call = fn; + + ipi_irq = irq; + + /* Enabled IPIs for boot CPU immediately */ + or1k_ipi_enable(); } void arch_send_call_function_single_ipi(int cpu) diff --git a/drivers/irqchip/irq-ompic.c b/drivers/irqchip/irq-ompic.c index e66ef4373b1e..f0e0b435bb1d 100644 --- a/drivers/irqchip/irq-ompic.c +++ b/drivers/irqchip/irq-ompic.c @@ -84,6 +84,8 @@ DEFINE_PER_CPU(unsigned long, ops); static void __iomem *ompic_base; +static DEFINE_PER_CPU_READ_MOSTLY(int, ipi_dummy_dev); + static inline u32 ompic_readreg(void __iomem *base, loff_t offset) { return ioread32be(base + offset); @@ -183,12 +185,17 @@ static int __init ompic_of_init(struct device_node *node, goto out_unmap; } - ret = request_irq(irq, ompic_ipi_handler, IRQF_PERCPU, - "ompic_ipi", NULL); - if (ret) + irq_set_percpu_devid(irq); + ret = request_percpu_irq(irq, ompic_ipi_handler, "ompic_ipi", + &ipi_dummy_dev); + + if (ret) { + pr_err("ompic: failed to request irq %d, error: %d", + irq, ret); goto out_irq_disp; + } - set_smp_cross_call(ompic_raise_softirq); + set_smp_cross_call(ompic_raise_softirq, irq); return 0; diff --git a/drivers/irqchip/irq-or1k-pic.c b/drivers/irqchip/irq-or1k-pic.c index 48126067c54b..73dc99c71d40 100644 --- a/drivers/irqchip/irq-or1k-pic.c +++ b/drivers/irqchip/irq-or1k-pic.c @@ -118,11 +118,36 @@ static void or1k_pic_handle_irq(struct pt_regs *regs) generic_handle_domain_irq(root_domain, irq); } +/* + * The OR1K PIC is a cpu-local interrupt controller and does not distinguish or + * use distinct irq number ranges for per-cpu event interrupts (IPI). Since + * information to determine whether a particular irq number should be treated as + * per-cpu is not available at mapping time, we use a wrapper handler function + * which chooses the right handler at runtime based on whether IRQF_PERCPU was + * used when requesting the irq. Borrowed from J-Core AIC. + */ +static void or1k_irq_flow_handler(struct irq_desc *desc) +{ +#ifdef CONFIG_SMP + struct irq_data *data = irq_desc_get_irq_data(desc); + struct or1k_pic_dev *pic = data->domain->host_data; + + if (irqd_is_per_cpu(data)) + handle_percpu_devid_irq(desc); + else + pic->handle(desc); +#endif +} + static int or1k_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw) { struct or1k_pic_dev *pic = d->host_data; - irq_set_chip_and_handler(irq, &pic->chip, pic->handle); + if (IS_ENABLED(CONFIG_SMP)) + irq_set_chip_and_handler(irq, &pic->chip, or1k_irq_flow_handler); + else + irq_set_chip_and_handler(irq, &pic->chip, pic->handle); + irq_set_status_flags(irq, pic->flags); return 0; -- 2.51.0