diff mbox series

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

Message ID 20230630105938.1377262-1-suagrfillet@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series [V2] riscv: Add BUG_ON() for no cpu nodes in devicetree | expand

Checks

Context Check Description
conchuod/cover_letter success Single patches do not need cover letters
conchuod/tree_selection success Guessed tree name to be for-next at HEAD 488833ccdcac
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 6 and now 6
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 8 this patch: 8
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 8 this patch: 8
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 20 this patch: 20
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch warning WARNING: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Song Shuai June 30, 2023, 10:59 a.m. UTC
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.

Signed-off-by: Song Shuai <suagrfillet@gmail.com>
---
Changes since V1:
https://lore.kernel.org/linux-riscv/20230629105839.1160895-1-suagrfillet@gmail.com/
- 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(+)

Comments

Conor Dooley June 30, 2023, 6:39 p.m. UTC | #1
On Fri, Jun 30, 2023 at 06:59:38PM +0800, Song Shuai wrote:
> 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.
> 
> Signed-off-by: Song Shuai <suagrfillet@gmail.com>

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.

> ---
> Changes since V1:
> https://lore.kernel.org/linux-riscv/20230629105839.1160895-1-suagrfillet@gmail.com/
> - 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(+)
> 
> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> index 6ca2b5309aab..04d33afbdf55 100644
> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c
> @@ -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) {
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt July 11, 2023, 10:58 p.m. UTC | #2
On Fri, 30 Jun 2023 11:39:24 PDT (-0700), Conor Dooley wrote:
> On Fri, Jun 30, 2023 at 06:59:38PM +0800, Song Shuai wrote:
>> 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.
>> 
>> Signed-off-by: Song Shuai <suagrfillet@gmail.com>
>
> 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.

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?

> Thanks,
> Conor.
>
>> ---
>> Changes since V1:
>> https://lore.kernel.org/linux-riscv/20230629105839.1160895-1-suagrfillet@gmail.com/
>> - 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(+)
>> 
>> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
>> index 6ca2b5309aab..04d33afbdf55 100644
>> --- a/arch/riscv/kernel/smpboot.c
>> +++ b/arch/riscv/kernel/smpboot.c
>> @@ -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) {
>> -- 
>> 2.20.1
>> 
>> 
>> _______________________________________________
>> linux-riscv mailing list
>> linux-riscv@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv
diff mbox series

Patch

diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index 6ca2b5309aab..04d33afbdf55 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -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) {