diff mbox series

[v5,5/8] RISC-V: Compare cpuid with NR_CPUS before mapping.

Message ID 1550089092-28783-6-git-send-email-atish.patra@wdc.com (mailing list archive)
State New, archived
Headers show
Series Various SMP related fixes | expand

Commit Message

Atish Patra Feb. 13, 2019, 8:18 p.m. UTC
We should never have a cpuid greater that NR_CPUS. Compare with NR_CPUS
before creating the mapping between logical and physical CPU ids. This
is also mandatory as NR_CPUS check is removed from
riscv_of_processor_hartid.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 arch/riscv/kernel/smpboot.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Christoph Lameter (Ampere) Feb. 14, 2019, 5:59 p.m. UTC | #1
On Wed, 13 Feb 2019, Atish Patra wrote:

> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c
> @@ -66,6 +66,11 @@ void __init setup_smp(void)
>  			found_boot_cpu = 1;
>  			continue;
>  		}
> +		if (cpuid >= NR_CPUS) {

Use nr_cpu_ids instead? Its initialized to NR_CPUS but can be restricted
if we can determine on boot how many processor we truly have.
Atish Patra Feb. 14, 2019, 11:33 p.m. UTC | #2
On 2/14/19 9:59 AM, Christopher Lameter wrote:
> On Wed, 13 Feb 2019, Atish Patra wrote:
> 
>> --- a/arch/riscv/kernel/smpboot.c
>> +++ b/arch/riscv/kernel/smpboot.c
>> @@ -66,6 +66,11 @@ void __init setup_smp(void)
>>   			found_boot_cpu = 1;
>>   			continue;
>>   		}
>> +		if (cpuid >= NR_CPUS) {
> 
> Use nr_cpu_ids instead? Its initialized to NR_CPUS but can be restricted
> if we can determine on boot how many processor we truly have.
> 
nr_cpu_ids can be modified by nr_cpus in boot command line. If nr_cpus 
is set to a value less than number of cpus described in the DT, kernel 
may not boot depending on the boot hartid. This happens because we break 
out of the while loop and BUG_ON(!found_boot_cpu).

As the required fix will be different from the current fix, I would like 
to do this in a follow up patch if that's ok.

Btw, thanks for bringing this up.

Regards,
Atish
diff mbox series

Patch

diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index d369b669..eb533b5c 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -66,6 +66,11 @@  void __init setup_smp(void)
 			found_boot_cpu = 1;
 			continue;
 		}
+		if (cpuid >= NR_CPUS) {
+			pr_warn("Invalid cpuid [%d] for hartid [%d]\n",
+				cpuid, hart);
+			break;
+		}
 
 		cpuid_to_hartid_map(cpuid) = hart;
 		set_cpu_possible(cpuid, true);