irqchip/riscv-imsic: Add kernel parameter to disable IPIs
Subsystems (4)
PATCH v4 1/1 irqchip/riscv-imsic: Add kernel parameter to disable IPIs
When injecting IPIs to a set of harts, the IMSIC IPI support will do a separate MMIO write to the SETIPNUM_LE register of each target hart. This means on a platform where IMSIC is trap-n-emulated, there will be N MMIO traps when injecting IPI to N target harts hence IMSIC IPIs will be slow on such platform compared to the SBI IPI extension.
Unfortunately, there is no DT, ACPI, or any other way of discovering whether the underlying IMSIC is trap-n-emulated. Using MMIO write to the SETIPNUM_LE register for injecting IPI is purely a software choice in the IMSIC driver hence add a kernel parameter to allow users disable IMSIC IPIs on platforms with trap-n-emulated IMSIC.
---
Changes since v3:
- Rebase upon Linux-6.16-rc4
- Make imsic_noipi as __ro_after_init
Changes since v2:
- Skip enabling/disabling IMSIC_IPI_ID in imsic_ipi_starting_cpu() and imsic_ipi_dying_cpu() when imsic_noipi is set
- Re-use the reserved IPI ID for devices when imsic_noipi is set
Changes since v1:
- Added more details to patch description
--- .../admin-guide/kernel-parameters.txt | 7 +++++++ drivers/irqchip/irq-riscv-imsic-early.c | 20 ++++++++++++++++++- drivers/irqchip/irq-riscv-imsic-state.c | 7 ++++--- drivers/irqchip/irq-riscv-imsic-state.h | 1 + 4 files changed, 31 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -2538,6 +2538,13 @@ requires the kernel to be built with CONFIG_ARM64_PSEUDO_NMI. + irqchip.riscv_imsic_noipi + [RISC-V,EARLY] + Force the kernel to not use IMSIC software injected MSIs + as IPIs. Intended for system where IMSIC is trap-n-emulated, + and thus want to reduce MMIO traps when triggering IPIs + to multiple harts. + irqfixup [HW] When an interrupt is not handled search all handlers for it. Intended to get systems with badly broken
drivers/irqchip/irq-riscv-imsic-early.c +19 -1
@@ -8,6 +8,7 @@#include <linux/acpi.h> #include <linux/cpu.h> #include <linux/interrupt.h> +#include <linux/init.h> #include <linux/io.h> #include <linux/irq.h> #include <linux/irqchip.h>
@@ -21,6 +22,14 @@#include "irq-riscv-imsic-state.h" static int imsic_parent_irq; +bool imsic_noipi__ro_after_init ; + +static int __init imsic_noipi_cfg (char *buf) +{ + imsic_noipi = true; +return 0 ; +} +early_param ("irqchip.riscv_imsic_noipi" , imsic_noipi_cfg);#ifdef CONFIG_SMP static void imsic_ipi_send (unsigned int cpu)
@@ -32,12 +41,18 @@ static void imsic_ipi_send(unsigned int cpu)static void imsic_ipi_starting_cpu (void ) { +if (imsic_noipi) +return ; +/* Enable IPIs for current CPU. */ __imsic_id_set_enable (IMSIC_IPI_ID ); }static void imsic_ipi_dying_cpu (void ) { +if (imsic_noipi) +return ; +/* Disable IPIs for current CPU. */ __imsic_id_clear_enable (IMSIC_IPI_ID ); }
@@ -46,6 +61,9 @@ static int __init imsic_ipi_domain_init(void) {int virq; +if (imsic_noipi) +return 0 ; +/* Create IMSIC IPI multiplexing */ virq =ipi_mux_create (IMSIC_NR_IPI , imsic_ipi_send);if (virq <=0 )
@@ -88,7 +106,7 @@ static void imsic_handle_irq(struct irq_desc *desc)while ((local_id =csr_swap (CSR_TOPEI ,0 ))) { local_id >>=TOPEI_ID_SHIFT ; -if (local_id ==IMSIC_IPI_ID ) { +if (!imsic_noipi && local_id ==IMSIC_IPI_ID ) {if (IS_ENABLED (CONFIG_SMP ))ipi_mux_process ();continue ;
drivers/irqchip/irq-riscv-imsic-state.c +4 -3
@@ -134,7 +134,7 @@ static bool __imsic_local_sync(struct imsic_local_priv *lpriv)lockdep_assert_held (&lpriv->lock);for_each_set_bit (i, lpriv->dirty_bitmap, imsic->global.nr_ids +1 ) { -if (!i || i ==IMSIC_IPI_ID ) +if (!i || (!imsic_noipi && i ==IMSIC_IPI_ID )) goto skip; vec = &lpriv->vectors[i];
@@ -419,7 +419,7 @@ void imsic_vector_debug_show(struct seq_file *m, struct imsic_vector *vec, int iseq_printf (m,"%*starget_cpu : %5u\n" , ind,"" , vec->cpu);seq_printf (m,"%*starget_local_id : %5u\n" , ind,"" , vec->local_id);seq_printf (m,"%*sis_reserved : %5u\n" , ind,"" , - (vec->local_id <=IMSIC_IPI_ID ) ?1 :0 ); + (!imsic_noipi && vec->local_id <=IMSIC_IPI_ID ) ?1 :0 );seq_printf (m,"%*sis_enabled : %5u\n" , ind,"" , is_enabled ?1 :0 );seq_printf (m,"%*sis_move_pending : %5u\n" , ind,"" , mvec ?1 :0 );if (mvec) {
@@ -583,7 +583,8 @@ static int __init imsic_matrix_init(void)irq_matrix_assign_system (imsic->matrix,0 , false);/* Reserve IPI ID because it is special and used internally */ -irq_matrix_assign_system (imsic->matrix,IMSIC_IPI_ID , false); +if (!imsic_noipi) +irq_matrix_assign_system (imsic->matrix,IMSIC_IPI_ID , false);return 0 ; }
drivers/irqchip/irq-riscv-imsic-state.h +1 -0
@@ -61,6 +61,7 @@ struct imsic_priv {struct irq_domain *base_domain; }; +extern bool imsic_noipi;extern struct imsic_priv *imsic;void __imsic_eix_update (unsigned long base_id,unsigned long num_id,bool pend,bool val);
Signature · 1 line
2.43.0
The following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: ea92b6046d352740c15f35e703c1b13a47dd99b0 Gitweb: https://git.kernel.org/tip/ea92b6046d352740c15f35e703c1b13a47dd99b0 Author: Anup Patel <[email protected]> AuthorDate: Wed, 16 Jul 2025 18:07:45 +05:30 Committer: Thomas Gleixner <[email protected]> CommitterDate: Fri, 18 Jul 2025 16:46:09 +02:00
irqchip/riscv-imsic: Add kernel parameter to disable IPIs
When injecting IPIs to a set of harts, the IMSIC IPI support will do a separate MMIO write to the SETIPNUM_LE register of each target hart. This means on a platform where IMSIC is trap-n-emulated, there will be N MMIO traps when injecting IPI to N target harts hence IMSIC IPIs will be slow on such platforms compared to the SBI IPI extension.
Unfortunately, there is no DT, ACPI, or any other way of discovering whether the underlying IMSIC is trap-n-emulated. Using MMIO write to the SETIPNUM_LE register for injecting IPI is purely a software choice in the IMSIC driver hence add a kernel parameter to allow users to disable IMSIC IPIs on platforms with trap-n-emulated IMSIC.
--- Documentation/admin-guide/kernel-parameters.txt | 7 ++++++- drivers/irqchip/irq-riscv-imsic-early.c | 20 +++++++++++++++- drivers/irqchip/irq-riscv-imsic-state.c | 7 +++--- drivers/irqchip/irq-riscv-imsic-state.h | 1 +- 4 files changed, 31 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -2538,6 +2538,13 @@ requires the kernel to be built with CONFIG_ARM64_PSEUDO_NMI. + irqchip.riscv_imsic_noipi + [RISC-V,EARLY] + Force the kernel to not use IMSIC software injected MSIs + as IPIs. Intended for system where IMSIC is trap-n-emulated, + and thus want to reduce MMIO traps when triggering IPIs + to multiple harts. + irqfixup [HW] When an interrupt is not handled search all handlers for it. Intended to get systems with badly broken
drivers/irqchip/irq-riscv-imsic-early.c +19 -1
@@ -8,6 +8,7 @@#include <linux/acpi.h> #include <linux/cpu.h> #include <linux/interrupt.h> +#include <linux/init.h> #include <linux/io.h> #include <linux/irq.h> #include <linux/irqchip.h>
@@ -21,6 +22,14 @@#include "irq-riscv-imsic-state.h" static int imsic_parent_irq; +bool imsic_noipi__ro_after_init ; + +static int __init imsic_noipi_cfg (char *buf) +{ + imsic_noipi = true; +return 0 ; +} +early_param ("irqchip.riscv_imsic_noipi" , imsic_noipi_cfg);#ifdef CONFIG_SMP static void imsic_ipi_send (unsigned int cpu)
@@ -32,12 +41,18 @@ static void imsic_ipi_send(unsigned int cpu)static void imsic_ipi_starting_cpu (void ) { +if (imsic_noipi) +return ; +/* Enable IPIs for current CPU. */ __imsic_id_set_enable (IMSIC_IPI_ID ); }static void imsic_ipi_dying_cpu (void ) { +if (imsic_noipi) +return ; +/* Disable IPIs for current CPU. */ __imsic_id_clear_enable (IMSIC_IPI_ID ); }
@@ -46,6 +61,9 @@ static int __init imsic_ipi_domain_init(void) {int virq; +if (imsic_noipi) +return 0 ; +/* Create IMSIC IPI multiplexing */ virq =ipi_mux_create (IMSIC_NR_IPI , imsic_ipi_send);if (virq <=0 )
@@ -88,7 +106,7 @@ static void imsic_handle_irq(struct irq_desc *desc)while ((local_id =csr_swap (CSR_TOPEI ,0 ))) { local_id >>=TOPEI_ID_SHIFT ; -if (local_id ==IMSIC_IPI_ID ) { +if (!imsic_noipi && local_id ==IMSIC_IPI_ID ) {if (IS_ENABLED (CONFIG_SMP ))ipi_mux_process ();continue ;
drivers/irqchip/irq-riscv-imsic-state.c +4 -3
@@ -134,7 +134,7 @@ static bool __imsic_local_sync(struct imsic_local_priv *lpriv)lockdep_assert_held (&lpriv->lock);for_each_set_bit (i, lpriv->dirty_bitmap, imsic->global.nr_ids +1 ) { -if (!i || i ==IMSIC_IPI_ID ) +if (!i || (!imsic_noipi && i ==IMSIC_IPI_ID )) goto skip; vec = &lpriv->vectors[i];
@@ -419,7 +419,7 @@ void imsic_vector_debug_show(struct seq_file *m, struct imsic_vector *vec, int iseq_printf (m,"%*starget_cpu : %5u\n" , ind,"" , vec->cpu);seq_printf (m,"%*starget_local_id : %5u\n" , ind,"" , vec->local_id);seq_printf (m,"%*sis_reserved : %5u\n" , ind,"" , - (vec->local_id <=IMSIC_IPI_ID ) ?1 :0 ); + (!imsic_noipi && vec->local_id <=IMSIC_IPI_ID ) ?1 :0 );seq_printf (m,"%*sis_enabled : %5u\n" , ind,"" , is_enabled ?1 :0 );seq_printf (m,"%*sis_move_pending : %5u\n" , ind,"" , mvec ?1 :0 );if (mvec) {
@@ -583,7 +583,8 @@ static int __init imsic_matrix_init(void)irq_matrix_assign_system (imsic->matrix,0 , false);/* Reserve IPI ID because it is special and used internally */ -irq_matrix_assign_system (imsic->matrix,IMSIC_IPI_ID , false); +if (!imsic_noipi) +irq_matrix_assign_system (imsic->matrix,IMSIC_IPI_ID , false);return 0 ; }
drivers/irqchip/irq-riscv-imsic-state.h +1 -0
@@ -61,6 +61,7 @@ struct imsic_priv {struct irq_domain *base_domain; }; +extern bool imsic_noipi;extern struct imsic_priv *imsic;void __imsic_eix_update (unsigned long base_id,unsigned long num_id,bool pend,bool val);
This patch was applied to riscv/linux.git (fixes) by Thomas Gleixner <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Thomas Gleixner <[email protected]>:
Quoted 6 lines · On Wed, 16 Jul 2025 18:07:45 +0530 you wrote:
When injecting IPIs to a set of harts, the IMSIC IPI support will do a separate MMIO write to the
SETIPNUM_LEregister of each target hart. This means on a platform where IMSIC is trap-n-emulated, there will be N MMIO traps when injecting IPI to N target harts hence IMSIC IPIs will be slow on such platform compared to the SBI IPI extension.
Quoted 7 lines
Unfortunately, there is no DT, ACPI, or any other way of discovering whether the underlying IMSIC is trap-n-emulated. Using MMIO write to the
SETIPNUM_LEregister for injecting IPI is purely a software choice in the IMSIC driver hence add a kernel parameter to allow users disable IMSIC IPIs on platforms with trap-n-emulated IMSIC.[...]
Here is the summary with links:
- [v4] irqchip/riscv-imsic: Add kernel parameter to disable IPIs
https://git.kernel.org/riscv/c/ea92b6046d35
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html