Skip to contentSkip to conversation

riscv: Add BUG_ON() for no cpu nodes in devicetree

PATCH In review Song Shuai 3 participants 3 messages Jun 30, 2023 – Jul 11, 2023 RISC-V

lore
Share & tools
lore

Song Shuai

author
#0 lore raw

PATCH v2 1/1 riscv: Add BUG_ON() for no cpu nodes in devicetree

When only the ACPI tables are passed to kernel, the tiny devictree created by EFI Stub doesn't provide cpu nodes.

While if append the "acpi=off" to kernel cmdline to disable ACPI for kernel the BUG_ON() in of_parse_and_init_cpus() indicates there's no boot cpu found in the devicetree, not there're no cpu nodes in the devicetree.

Add BUG_ON() in the first place of of_parse_and_init_cpus() to make it clear.

---
Changes since V1:
https://lore.kernel.org/linux-riscv/[email protected]/
- revise the commit-msg and move the BUG_ON into of_parse_and_init_cpus() as Conor suggests

---
 arch/riscv/kernel/smpboot.c | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/kernel/smpboot.c +2 -0
index 6ca2b5309aab..04d33afbdf55 100644
@@ -147,6 +147,8 @@ static void __init of_parse_and_init_cpus(void)
 	int cpuid = 1;
 	int rc;
 
+	BUG_ON(!of_get_next_cpu_node(NULL));
+
 	cpu_set_ops(0);
 
 	for_each_of_cpu_node(dn) {
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 10 lines · Song Shuai

When only the ACPI tables are passed to kernel, the tiny devictree created by EFI Stub doesn't provide cpu nodes.

While if append the "acpi=off" to kernel cmdline to disable ACPI for kernel the BUG_ON() in of_parse_and_init_cpus() indicates there's no boot cpu found in the devicetree, not there're no cpu nodes in the devicetree.

Add BUG_ON() in the first place of of_parse_and_init_cpus() to make it clear.

I'm still not really convinced that this is needed - not finding the boot CPU is a strong a hint as any that your DT is completely broken. Especially if you intentionally go out of your way to disable ACPI on a system that requires it to boot.

I'll leave it up to Palmer or whoever to determine whether this is a valuable change. Code change itself much improved though, thanks - I'd give an R-b/A-b other than that I question whether there's any value in adding another BUG_ON(). You could've kept the part of the comment that explained what the error meant though, but that's not a big deal.

Thanks,
Conor.

Quoted 30 lines

---
Changes since V1:
https://lore.kernel.org/linux-riscv/[email protected]/
- revise the commit-msg and move the BUG_ON into of_parse_and_init_cpus() as Conor suggests

---
 arch/riscv/kernel/smpboot.c | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/kernel/smpboot.c +2 -0
index 6ca2b5309aab..04d33afbdf55 100644
@@ -147,6 +147,8 @@ static void __init of_parse_and_init_cpus(void)
 	int cpuid = 1;
 	int rc;
 
+	BUG_ON(!of_get_next_cpu_node(NULL));
+
 	cpu_set_ops(0);
 
 	for_each_of_cpu_node(dn) {
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#2 lore raw
Quoted 17 lines · Conor Dooley
Quoted 10 lines · Song Shuai

When only the ACPI tables are passed to kernel, the tiny devictree created by EFI Stub doesn't provide cpu nodes.

While if append the "acpi=off" to kernel cmdline to disable ACPI for kernel the BUG_ON() in of_parse_and_init_cpus() indicates there's no boot cpu found in the devicetree, not there're no cpu nodes in the devicetree.

Add BUG_ON() in the first place of of_parse_and_init_cpus() to make it clear.

I'm still not really convinced that this is needed - not finding the boot CPU is a strong a hint as any that your DT is completely broken. Especially if you intentionally go out of your way to disable ACPI on a system that requires it to boot.

Quoted 5 lines

I'll leave it up to Palmer or whoever to determine whether this is a valuable change. Code change itself much improved though, thanks - I'd give an R-b/A-b other than that I question whether there's any value in adding another BUG_ON(). You could've kept the part of the comment that explained what the error meant though, but that's not a big deal.

IIUC this is just reduntant: if the BUG_ON triggers then there's no CPUs, so we'll end up with no iterations of the loop and thus no found CPU and thus a BUG_ON. The only difference is the SBI probing, but that's just poking SBI to turn off spinwait.

So I think we already crash sufficiently on systems with an empty DT. Sorry if I'm missing something, though?

Quoted 33 lines

Thanks,
Conor.

Quoted 30 lines

---
Changes since V1:
https://lore.kernel.org/linux-riscv/[email protected]/
- revise the commit-msg and move the BUG_ON into of_parse_and_init_cpus() as Conor suggests

---
 arch/riscv/kernel/smpboot.c | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/kernel/smpboot.c +2 -0
index 6ca2b5309aab..04d33afbdf55 100644
@@ -147,6 +147,8 @@ static void __init of_parse_and_init_cpus(void)
 	int cpuid = 1;
 	int rc;
 
+	BUG_ON(!of_get_next_cpu_node(NULL));
+
 	cpu_set_ops(0);
 
 	for_each_of_cpu_node(dn) {
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv