irqchip/sifive-plic: use hartid as context_id in OF to fix AMP conflicts
Subsystems (3)
PATCH 1/1 irqchip/sifive-plic: use hartid as context_id in OF to fix AMP conflicts
In asymmetric multi-processing (AMP) scenarios, the original PLIC driver used the context loop index 'i' as context_id for OF (device tree) platforms. This caused multiple contexts from different harts (e.g., core0 and core4) to share the same enable_base, leading to conflicts when initializing the PLIC.
This patch resolves enable_base conflicts on AMP platforms while maintaining SMP/UP behavior.
--- drivers/irqchip/irq-sifive-plic.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/irqchip/irq-sifive-plic.c +12 -11
@@ -487,18 +487,18 @@ static int plic_parse_nr_irqs_and_contexts(struct fwnode_handle *fwnode, }static int plic_parse_context_parent (struct fwnode_handle *fwnode,u32 context, -u32 *parent_hwirq,int *parent_cpu,u32 id) +u32 *parent_hwirq,int *parent_cpu,u32 id, +unsigned long *hartid) {struct of_phandle_args parent; -unsigned long hartid;int rc;if (!is_of_node (fwnode)) { - hartid =acpi_rintc_ext_parent_to_hartid (id, context); -if (hartid ==INVALID_HARTID ) + *hartid =acpi_rintc_ext_parent_to_hartid (id, context); +if (*hartid ==INVALID_HARTID )return -EINVAL ; - *parent_cpu =riscv_hartid_to_cpuid (hartid); + *parent_cpu =riscv_hartid_to_cpuid (*hartid); *parent_hwirq =RV_IRQ_EXT ;return 0 ; }
@@ -507,19 +507,19 @@ static int plic_parse_context_parent(struct fwnode_handle *fwnode, u32 context,if (rc)return rc; - rc =riscv_of_parent_hartid (parent.np, &hartid); + rc =riscv_of_parent_hartid (parent.np, hartid);if (rc)return rc; *parent_hwirq = parent.args[0 ]; - *parent_cpu =riscv_hartid_to_cpuid (hartid); + *parent_cpu =riscv_hartid_to_cpuid (*hartid);return 0 ; }static int plic_probe (struct fwnode_handle *fwnode) {int error =0 , nr_contexts, nr_handlers =0 , cpu, i; -unsigned long plic_quirks =0 ; +unsigned long plic_quirks =0 , hartid;struct plic_handler *handler;u32 nr_irqs, parent_hwirq;struct plic_priv *priv;
@@ -569,14 +569,14 @@ static int plic_probe(struct fwnode_handle *fwnode)for (i =0 ; i < nr_contexts; i++) { error =plic_parse_context_parent (fwnode, i, &parent_hwirq, &cpu, - priv->acpi_plic_id); + priv->acpi_plic_id, &hartid);if (error) {pr_warn ("%pfwP: hwirq for context%d not found\n" , fwnode, i);continue ; }if (is_of_node (fwnode)) { - context_id = i; + context_id = hartid *2 + i %2 ; }else { context_id =acpi_rintc_get_plic_context (priv->acpi_plic_id, i);if (context_id ==INVALID_CONTEXT ) {
@@ -694,7 +694,8 @@ static int plic_probe(struct fwnode_handle *fwnode) fail_cleanup_contexts:for (i =0 ; i < nr_contexts; i++) { -if (plic_parse_context_parent (fwnode, i, &parent_hwirq, &cpu, priv->acpi_plic_id)) +if (plic_parse_context_parent (fwnode, i, &parent_hwirq, &cpu, + priv->acpi_plic_id, &hartid))continue ;if (parent_hwirq !=RV_IRQ_EXT || cpu <0 )continue ;
---
base-commit: fdbc36b17e9f2fa24c940959e39df90f53ccce2b
change-id: 20251020-fix-plic-amp-72bd94969ca4
Best regards,
Signature · 7 lines
Troy Mitchell <[email protected]> _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 2 lines · Troy Mitchell
In asymmetric multi-processing (AMP) scenarios, the original PLIC driver used the context loop index 'i' as
context_idfor OF (device
Which original driver and when did it stop to use the context loop index?
Quoted 3 lines
tree) platforms. This caused multiple contexts from different harts (e.g., core0 and core4) to share the same
enable_base, leading to conflicts when initializing the PLIC.
When did it stop to cause the issues? And if the issues have been already resolved, what is this patch about?
Quoted 1 line
This patch resolves
enable_baseconflicts on AMP platforms while
# git grep 'This patch' Documentation/process/
Quoted 1 line
maintaining SMP/UP behavior.
There is zero explanation what this patch does to resolve the issue.
See also:
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#changelog
drivers/irqchip/irq-sifive-plic.c static int plic_probe(struct fwnode_handle *fwnode) · line 579
Quoted 4 lines
drivers/irqchip/irq-sifive-plic.c +1
-1if (is_of_node (fwnode)) { - context_id = i; + context_id = hartid *2 + i %2 ;
This is incomprehensible and will cause head scratching 6 weeks down the road. This needs a proper comment with an explanation what this is about and why it is correct under all circumstances.
Thanks,
tglx
Quoted 4 lines · Thomas Gleixner
Quoted 2 lines · Troy Mitchell
In asymmetric multi-processing (AMP) scenarios, the original PLIC driver used the context loop index 'i' as
context_idfor OF (device
Quoted 8 lines
Which original driver and when did it stop to use the context loop index?
Quoted 3 lines
tree) platforms. This caused multiple contexts from different harts (e.g., core0 and core4) to share the same
enable_base, leading to conflicts when initializing the PLIC.When did it stop to cause the issues? And if the issues have been already resolved, what is this patch about?
The issue still exists in the current driver.
The PLIC driver for OF-based platforms assigns context_id = i inside the context loop, which assumes that all harts are numbered contiguously starting from 0.
In AMP systems (e.g., when Linux boots from hart4 while hart0 runs another OS), this assumption breaks — multiple contexts from different clusters share the same enable_base(e.g., core4's enable_base = core0's enable_base), causing conflicts.
This patch fixes the problem by assigning context_id based on the actual hartid, ensuring that each hart context maps to a unique enable region, while preserving behavior on SMP and UP systems.
Does it make sense? I'll update my commit message in the next version.
Quoted 5 lines
Quoted 2 lines
This patch resolves
enable_baseconflicts on AMP platforms while# git grep 'This patch' Documentation/process/
Quoted 7 lines
Quoted 1 line
maintaining SMP/UP behavior.
There is zero explanation what this patch does to resolve the issue.
See also:
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#changelog
Thanks for your link!
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static int plic_probe(struct fwnode_handle *fwnode) · line 579
Quoted 5 lines
drivers/irqchip/irq-sifive-plic.c +1
-1if (is_of_node (fwnode)) { - context_id = i; + context_id = hartid *2 + i %2 ;This is incomprehensible and will cause head scratching 6 weeks down the road. This needs a proper comment with an explanation what this is about and why it is correct under all circumstances.
I will add comments here. Thanks!
- Troy
Quoted 4 lines
Thanks,
tglx
Quoted 22 lines · Troy Mitchell
Quoted 4 lines · Thomas Gleixner
Quoted 2 lines · Troy Mitchell
In asymmetric multi-processing (AMP) scenarios, the original PLIC driver used the context loop index 'i' as
context_idfor OF (deviceQuoted 8 lines
Which original driver and when did it stop to use the context loop index?
Quoted 3 lines
tree) platforms. This caused multiple contexts from different harts (e.g., core0 and core4) to share the same
enable_base, leading to conflicts when initializing the PLIC.When did it stop to cause the issues? And if the issues have been already resolved, what is this patch about?
The issue still exists in the current driver.
The PLIC driver for OF-based platforms assignscontext_id= i inside the context loop, which assumes that all harts are numbered contiguously starting from 0.In AMP systems (e.g., when Linux boots from hart4 while hart0 runs another OS), this assumption breaks — multiple contexts from different clusters share the same
enable_base(e.g., core4's enable_base = core0's enable_base), causing conflicts.
Quoted 5 lines
This patch fixes the problem by assigning
context_idbased on the actual hartid, ensuring that each hart context maps to a unique enable region, while preserving behavior on SMP and UP systems.Does it make sense? I'll update my commit message in the next version.
Yes. Though this still applies:
Quoted 1 line
Quoted 1 line
# git grep 'This patch' Documentation/process/
Thanks,
tglx
Quoted 23 lines · Thomas Gleixner
Quoted 22 lines · Troy Mitchell
Quoted 4 lines · Thomas Gleixner
Quoted 2 lines · Troy Mitchell
In asymmetric multi-processing (AMP) scenarios, the original PLIC driver used the context loop index 'i' as
context_idfor OF (deviceQuoted 8 lines
Which original driver and when did it stop to use the context loop index?
Quoted 3 lines
tree) platforms. This caused multiple contexts from different harts (e.g., core0 and core4) to share the same
enable_base, leading to conflicts when initializing the PLIC.When did it stop to cause the issues? And if the issues have been already resolved, what is this patch about?
The issue still exists in the current driver.
The PLIC driver for OF-based platforms assignscontext_id= i inside the context loop, which assumes that all harts are numbered contiguously starting from 0.In AMP systems (e.g., when Linux boots from hart4 while hart0 runs another OS), this assumption breaks — multiple contexts from different clusters share the same
enable_base(e.g., core4's enable_base = core0's enable_base), causing conflicts.
Quoted 7 lines
Quoted 5 lines
This patch fixes the problem by assigning
context_idbased on the actual hartid, ensuring that each hart context maps to a unique enable region, while preserving behavior on SMP and UP systems.Does it make sense? I'll update my commit message in the next version.
Yes. Though this still applies:
Thank you for your reminder again.
- Troy
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
# git grep 'This patch' Documentation/process/Thanks,
tglx