Skip to contentSkip to conversation

riscv: make sure the cores stay looping in .Lsecondary_park

PATCH Superseded Greentime Hu 2 participants 6 messages Jan 9, 2020 – Jan 15, 2020 RISC-V

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 riscv: make sure the cores stay looping in .Lsecondary_park

The code in secondary_park is currently placed in the .init section. The kernel reclaims and clears this code when it finishes booting. That causes the cores parked in it to go to somewhere unpredictable, so we move this function out of init to make sure the cores stay looping there.

---
 arch/riscv/kernel/head.S | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
arch/riscv/kernel/head.S +7 -5
index f8f996916c5b..276b98f9d0bd 100644
@@ -217,11 +217,6 @@ relocate:
 	tail smp_callin
 #endif
 
-.align 2
-.Lsecondary_park:
-	/* We lack SMP support or have too many harts, so park this hart */
-	wfi
-	j .Lsecondary_park
 END(_start)
 
 #ifdef CONFIG_RISCV_M_MODE
@@ -303,6 +298,13 @@ ENTRY(reset_regs)
 END(reset_regs)
 #endif /* CONFIG_RISCV_M_MODE */
 
+.section ".text", "ax",@progbits
+.align 2
+.Lsecondary_park:
+	/* We lack SMP support or have too many harts, so park this hart */
+	wfi
+	j .Lsecondary_park
+
 __PAGE_ALIGNED_BSS
 	/* Empty zero page */
 	.balign PAGE_SIZE
Signature · 1 line
2.17.1
Reviewed-by Anup Patel on v3 1/1
#1 lore raw
Quoted 7 lines · Greentime Hu

The code in secondary_park is currently placed in the .init section. The kernel reclaims and clears this code when it finishes booting. That causes the cores parked in it to go to somewhere unpredictable, so we move this function out of init to make sure the cores stay looping there.

Thanks, the following is what's been queued for v5.5-rc.

- Paul

From: Greentime Hu <[email protected]>
Date: Thu, 9 Jan 2020 11:15:16 +0800
Subject: [PATCH] riscv: make sure the cores stay looping in .Lsecondary_park

The code in secondary_park is currently placed in the .init section. The kernel reclaims and clears this code when it finishes booting. That causes the cores parked in it to go to somewhere unpredictable, so we move this function out of init to make sure the cores stay looping there.

Cc Andreas Schwab <[email protected]>
Fixes 76d2a0493a17d ("RISC-V: Init and Halt Code")
---
 arch/riscv/kernel/head.S | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
arch/riscv/kernel/head.S +7 -5
index 797802c73dee..c9cc44ef7184 100644
@@ -209,11 +209,6 @@ relocate:
 	tail smp_callin
 #endif
 
-.align 2
-.Lsecondary_park:
-	/* We lack SMP support or have too many harts, so park this hart */
-	wfi
-	j .Lsecondary_park
 END(_start)
 
 #ifdef CONFIG_RISCV_M_MODE
@@ -295,6 +290,13 @@ ENTRY(reset_regs)
 END(reset_regs)
 #endif /* CONFIG_RISCV_M_MODE */
 
+.section ".text", "ax",@progbits
+.align 2
+.Lsecondary_park:
+	/* We lack SMP support or have too many harts, so park this hart */
+	wfi
+	j .Lsecondary_park
+
 __PAGE_ALIGNED_BSS
 	/* Empty zero page */
 	.balign PAGE_SIZE
Signature · 1 line
2.25.0.rc2
#2 lore raw

Hi Greentime,

Quoted 11 lines · Paul Walmsley
Quoted 7 lines · Greentime Hu

The code in secondary_park is currently placed in the .init section. The kernel reclaims and clears this code when it finishes booting. That causes the cores parked in it to go to somewhere unpredictable, so we move this function out of init to make sure the cores stay looping there.

Thanks, the following is what's been queued for v5.5-rc.

During final testing, when building the kernel with an initramfs, I hit the following linker error:

LD .tmp_vmlinux1
arch/riscv/kernel/head.o: in function .L0 ':(.init.text+0x5c): relocation truncated to fit: R_RISCV_JAL against .Lsecondary_park' make[1]: *** [Makefile:1079: vmlinux] Error 1
make: *** [Makefile:326: __build_one_by_one] Error 2

Could you take a look at this?

thanks,

- Paul

#3 lore raw

Hi Paul,

Quoted 20 lines · Paul Walmsley

Hi Greentime,

Quoted 11 lines · Paul Walmsley
Quoted 7 lines · Greentime Hu

The code in secondary_park is currently placed in the .init section. The kernel reclaims and clears this code when it finishes booting. That causes the cores parked in it to go to somewhere unpredictable, so we move this function out of init to make sure the cores stay looping there.

Thanks, the following is what's been queued for v5.5-rc.

During final testing, when building the kernel with an initramfs, I hit the following linker error:

Quoted 6 lines

LD .tmp_vmlinux1
arch/riscv/kernel/head.o: in function .L0 ':(.init.text+0x5c): relocation truncated to fit: R_RISCV_JAL against .Lsecondary_park' make[1]: *** [Makefile:1079: vmlinux] Error 1
make: *** [Makefile:326: __build_one_by_one] Error 2

Could you take a look at this?

I think it is because the sections are too far for bqeu to jump and the config I used just small enough for it to jump so I didn't see this bug. Sorry about that.
I tried this fix to boot in Unleashed board.

#ifdef CONFIG_SMP
li t0, CONFIG_NR_CPUS

-       bgeu a0, t0, .Lsecondary_park
+       blt a0, t0, .Lgood_cores
+       tail .Lsecondary_park

+.Lgood_cores:
#endif

#4 lore raw

Hi Greentime,

Quoted 3 lines · Greentime Hu

I think it is because the sections are too far for bqeu to jump and the config I used just small enough for it to jump so I didn't see this bug. Sorry about that.

No problem.

Review

Quoted 9 lines

I tried this fix to boot in Unleashed board.

#ifdef CONFIG_SMP
li t0, CONFIG_NR_CPUS

(quoted diff) +3 -1
-       bgeu a0, t0, .Lsecondary_park
+       blt a0, t0, .Lgood_cores
+       tail .Lsecondary_park
+.Lgood_cores:
 #endif

Looks reasonable to me. Care to update and repost the patch?

- Paul

#5 lore raw
Quoted 21 lines · Paul Walmsley

Hi Greentime,

Quoted 3 lines · Greentime Hu

I think it is because the sections are too far for bqeu to jump and the config I used just small enough for it to jump so I didn't see this bug. Sorry about that.

No problem.

Review

Quoted 9 lines

I tried this fix to boot in Unleashed board.

#ifdef CONFIG_SMP
li t0, CONFIG_NR_CPUS

(quoted diff) +3 -1
-       bgeu a0, t0, .Lsecondary_park
+       blt a0, t0, .Lgood_cores
+       tail .Lsecondary_park
+.Lgood_cores:
 #endif
Quoted 1 line

Looks reasonable to me. Care to update and repost the patch?

Yes, Paul. I have sent the v4 patch.
It is tested in Unleashed board.