* [PATCH V1 0/3] riscv: kexec: cleanup and fixups
@ 2023-09-07 10:33 ` Song Shuai
0 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
Hi,
I had posted 2 patches [1][2] for riscv/kexec, but there was no "effective"
response to them until now, so I merged them in this series with the 3rd fixup.
Anyway, this series contains a cleanup for riscv_kexec_relocate() and two fixups
for KEXEC_FILE and had passed the basic kexec test in my 64bit Qemu-virt.
You can use this kexec-tools[3] to test the kexec-file-syscall and these patches.
riscv: kexec: Cleanup riscv_kexec_relocate (patch1)
==================================================
For readability and simplicity, cleanup the riscv_kexec_relocate code:
- Re-sort the first 4 `mv` instructions against `riscv_kexec_method()`
- Eliminate registers for debugging (s9,s10,s11) and storing const-value (s5,s6)
- Replace `jalr` with `jr` for no-link jump
riscv: kexec: Align the kexeced kernel entry (patch2)
==================================================
The current riscv boot protocol requires 2MB alignment for RV64
and 4MB alignment for RV32.
In KEXEC_FILE path, the elf_find_pbase() function should align
the kexeced kernel entry according to the requirement, otherwise
the kexeced kernel would silently BUG at the setup_vm().
riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS (patch3)
==================================================
With CONFIG_RELOCATABLE enabled, KBUILD_CFLAGS had a -fPIE option
and then the purgatory/string.o was built to reference _ctype symbol
via R_RISCV_GOT_HI20 relocations which can't be handled by purgatory.
As a consequence, the kernel failed kexec_load_file() with:
[ 880.386562] kexec_image: The entry point of kernel at 0x80200000
[ 880.388650] kexec_image: Unknown rela relocation: 20
[ 880.389173] kexec_image: Error loading purgatory ret=-8
So remove the -fPIE option for PURGATORY_CFLAGS to generate
R_RISCV_PCREL_HI20 relocations type making puragtory work as it was.
Note that:
Sorry to Andreas Schwab, I just noticed your reply about the .align
directive in patch1 when writing this e-mail. It looks good to me to
replace `.align 2` with `.balign 4`, I will fix it in the next version.
[1]: https://lore.kernel.org/linux-riscv/20230830063435.1105726-1-songshuaishuai@tinylab.org/
[2]: https://lore.kernel.org/linux-riscv/20230906095817.364390-1-songshuaishuai@tinylab.org/
[3]: https://github.com/sugarfillet/kexec-tools/tree/fix-riscv
Song Shuai (3):
riscv: kexec: Cleanup riscv_kexec_relocate
riscv: kexec: Align the kexeced kernel entry
riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
arch/riscv/kernel/elf_kexec.c | 8 ++++-
arch/riscv/kernel/kexec_relocate.S | 52 +++++++++++++-----------------
arch/riscv/purgatory/Makefile | 4 +++
3 files changed, 34 insertions(+), 30 deletions(-)
--
2.20.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH V1 0/3] riscv: kexec: cleanup and fixups
@ 2023-09-07 10:33 ` Song Shuai
0 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
Hi,
I had posted 2 patches [1][2] for riscv/kexec, but there was no "effective"
response to them until now, so I merged them in this series with the 3rd fixup.
Anyway, this series contains a cleanup for riscv_kexec_relocate() and two fixups
for KEXEC_FILE and had passed the basic kexec test in my 64bit Qemu-virt.
You can use this kexec-tools[3] to test the kexec-file-syscall and these patches.
riscv: kexec: Cleanup riscv_kexec_relocate (patch1)
==================================================
For readability and simplicity, cleanup the riscv_kexec_relocate code:
- Re-sort the first 4 `mv` instructions against `riscv_kexec_method()`
- Eliminate registers for debugging (s9,s10,s11) and storing const-value (s5,s6)
- Replace `jalr` with `jr` for no-link jump
riscv: kexec: Align the kexeced kernel entry (patch2)
==================================================
The current riscv boot protocol requires 2MB alignment for RV64
and 4MB alignment for RV32.
In KEXEC_FILE path, the elf_find_pbase() function should align
the kexeced kernel entry according to the requirement, otherwise
the kexeced kernel would silently BUG at the setup_vm().
riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS (patch3)
==================================================
With CONFIG_RELOCATABLE enabled, KBUILD_CFLAGS had a -fPIE option
and then the purgatory/string.o was built to reference _ctype symbol
via R_RISCV_GOT_HI20 relocations which can't be handled by purgatory.
As a consequence, the kernel failed kexec_load_file() with:
[ 880.386562] kexec_image: The entry point of kernel at 0x80200000
[ 880.388650] kexec_image: Unknown rela relocation: 20
[ 880.389173] kexec_image: Error loading purgatory ret=-8
So remove the -fPIE option for PURGATORY_CFLAGS to generate
R_RISCV_PCREL_HI20 relocations type making puragtory work as it was.
Note that:
Sorry to Andreas Schwab, I just noticed your reply about the .align
directive in patch1 when writing this e-mail. It looks good to me to
replace `.align 2` with `.balign 4`, I will fix it in the next version.
[1]: https://lore.kernel.org/linux-riscv/20230830063435.1105726-1-songshuaishuai@tinylab.org/
[2]: https://lore.kernel.org/linux-riscv/20230906095817.364390-1-songshuaishuai@tinylab.org/
[3]: https://github.com/sugarfillet/kexec-tools/tree/fix-riscv
Song Shuai (3):
riscv: kexec: Cleanup riscv_kexec_relocate
riscv: kexec: Align the kexeced kernel entry
riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
arch/riscv/kernel/elf_kexec.c | 8 ++++-
arch/riscv/kernel/kexec_relocate.S | 52 +++++++++++++-----------------
arch/riscv/purgatory/Makefile | 4 +++
3 files changed, 34 insertions(+), 30 deletions(-)
--
2.20.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH V1 1/3] riscv: kexec: Cleanup riscv_kexec_relocate
2023-09-07 10:33 ` Song Shuai
@ 2023-09-07 10:33 ` Song Shuai
-1 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
For readability and simplicity, cleanup the riscv_kexec_relocate code:
- Re-sort the first 4 `mv` instructions against `riscv_kexec_method()`
- Eliminate registers for debugging (s9,s10,s11) and storing const-value (s5,s6)
- Replace `jalr` with `jr` for no-link jump
I tested this on Qemu virt machine and works as it was.
Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
arch/riscv/kernel/kexec_relocate.S | 52 +++++++++++++-----------------
1 file changed, 23 insertions(+), 29 deletions(-)
diff --git a/arch/riscv/kernel/kexec_relocate.S b/arch/riscv/kernel/kexec_relocate.S
index 059c5e216ae7..de0a4b35d01e 100644
--- a/arch/riscv/kernel/kexec_relocate.S
+++ b/arch/riscv/kernel/kexec_relocate.S
@@ -17,27 +17,17 @@ SYM_CODE_START(riscv_kexec_relocate)
* s1: (const) Phys address to jump to after relocation
* s2: (const) Phys address of the FDT image
* s3: (const) The hartid of the current hart
- * s4: Pointer to the destination address for the relocation
- * s5: (const) Number of words per page
- * s6: (const) 1, used for subtraction
- * s7: (const) kernel_map.va_pa_offset, used when switching MMU off
- * s8: (const) Physical address of the main loop
- * s9: (debug) indirection page counter
- * s10: (debug) entry counter
- * s11: (debug) copied words counter
+ * s4: (const) kernel_map.va_pa_offset, used when switching MMU off
+ * s5: Pointer to the destination address for the relocation
+ * s6: (const) Physical address of the main loop
*/
mv s0, a0
mv s1, a1
mv s2, a2
mv s3, a3
- mv s4, zero
- li s5, (PAGE_SIZE / RISCV_SZPTR)
- li s6, 1
- mv s7, a4
- mv s8, zero
- mv s9, zero
- mv s10, zero
- mv s11, zero
+ mv s4, a4
+ mv s5, zero
+ mv s6, zero
/* Disable / cleanup interrupts */
csrw CSR_SIE, zero
@@ -52,21 +42,27 @@ SYM_CODE_START(riscv_kexec_relocate)
* the start of the loop below so that we jump there in
* any case.
*/
- la s8, 1f
- sub s8, s8, s7
- csrw CSR_STVEC, s8
+ la s6, 1f
+ sub s6, s6, s4
+ csrw CSR_STVEC, s6
+
+ /*
+ * With C-extension, here we get 42 Bytes and the next
+ * .align directive would pad zeros here up to 44 Bytes.
+ * So manually put a nop here to avoid zeros padding.
+ */
+ nop
/* Process entries in a loop */
.align 2
1:
- addi s10, s10, 1
REG_L t0, 0(s0) /* t0 = *image->entry */
addi s0, s0, RISCV_SZPTR /* image->entry++ */
/* IND_DESTINATION entry ? -> save destination address */
andi t1, t0, 0x1
beqz t1, 2f
- andi s4, t0, ~0x1
+ andi s5, t0, ~0x1
j 1b
2:
@@ -74,9 +70,8 @@ SYM_CODE_START(riscv_kexec_relocate)
andi t1, t0, 0x2
beqz t1, 2f
andi s0, t0, ~0x2
- addi s9, s9, 1
csrw CSR_SATP, zero
- jalr zero, s8, 0
+ jr s6
2:
/* IND_DONE entry ? -> jump to done label */
@@ -92,14 +87,13 @@ SYM_CODE_START(riscv_kexec_relocate)
andi t1, t0, 0x8
beqz t1, 1b /* Unknown entry type, ignore it */
andi t0, t0, ~0x8
- mv t3, s5 /* i = num words per page */
+ li t3, (PAGE_SIZE / RISCV_SZPTR) /* i = num words per page */
3: /* copy loop */
REG_L t1, (t0) /* t1 = *src_ptr */
- REG_S t1, (s4) /* *dst_ptr = *src_ptr */
+ REG_S t1, (s5) /* *dst_ptr = *src_ptr */
addi t0, t0, RISCV_SZPTR /* stc_ptr++ */
- addi s4, s4, RISCV_SZPTR /* dst_ptr++ */
- sub t3, t3, s6 /* i-- */
- addi s11, s11, 1 /* c++ */
+ addi s5, s5, RISCV_SZPTR /* dst_ptr++ */
+ addi t3, t3, -0x1 /* i-- */
beqz t3, 1b /* copy done ? */
j 3b
@@ -146,7 +140,7 @@ SYM_CODE_START(riscv_kexec_relocate)
*/
fence.i
- jalr zero, a2, 0
+ jr a2
SYM_CODE_END(riscv_kexec_relocate)
riscv_kexec_relocate_end:
--
2.20.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH V1 1/3] riscv: kexec: Cleanup riscv_kexec_relocate
@ 2023-09-07 10:33 ` Song Shuai
0 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
For readability and simplicity, cleanup the riscv_kexec_relocate code:
- Re-sort the first 4 `mv` instructions against `riscv_kexec_method()`
- Eliminate registers for debugging (s9,s10,s11) and storing const-value (s5,s6)
- Replace `jalr` with `jr` for no-link jump
I tested this on Qemu virt machine and works as it was.
Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
arch/riscv/kernel/kexec_relocate.S | 52 +++++++++++++-----------------
1 file changed, 23 insertions(+), 29 deletions(-)
diff --git a/arch/riscv/kernel/kexec_relocate.S b/arch/riscv/kernel/kexec_relocate.S
index 059c5e216ae7..de0a4b35d01e 100644
--- a/arch/riscv/kernel/kexec_relocate.S
+++ b/arch/riscv/kernel/kexec_relocate.S
@@ -17,27 +17,17 @@ SYM_CODE_START(riscv_kexec_relocate)
* s1: (const) Phys address to jump to after relocation
* s2: (const) Phys address of the FDT image
* s3: (const) The hartid of the current hart
- * s4: Pointer to the destination address for the relocation
- * s5: (const) Number of words per page
- * s6: (const) 1, used for subtraction
- * s7: (const) kernel_map.va_pa_offset, used when switching MMU off
- * s8: (const) Physical address of the main loop
- * s9: (debug) indirection page counter
- * s10: (debug) entry counter
- * s11: (debug) copied words counter
+ * s4: (const) kernel_map.va_pa_offset, used when switching MMU off
+ * s5: Pointer to the destination address for the relocation
+ * s6: (const) Physical address of the main loop
*/
mv s0, a0
mv s1, a1
mv s2, a2
mv s3, a3
- mv s4, zero
- li s5, (PAGE_SIZE / RISCV_SZPTR)
- li s6, 1
- mv s7, a4
- mv s8, zero
- mv s9, zero
- mv s10, zero
- mv s11, zero
+ mv s4, a4
+ mv s5, zero
+ mv s6, zero
/* Disable / cleanup interrupts */
csrw CSR_SIE, zero
@@ -52,21 +42,27 @@ SYM_CODE_START(riscv_kexec_relocate)
* the start of the loop below so that we jump there in
* any case.
*/
- la s8, 1f
- sub s8, s8, s7
- csrw CSR_STVEC, s8
+ la s6, 1f
+ sub s6, s6, s4
+ csrw CSR_STVEC, s6
+
+ /*
+ * With C-extension, here we get 42 Bytes and the next
+ * .align directive would pad zeros here up to 44 Bytes.
+ * So manually put a nop here to avoid zeros padding.
+ */
+ nop
/* Process entries in a loop */
.align 2
1:
- addi s10, s10, 1
REG_L t0, 0(s0) /* t0 = *image->entry */
addi s0, s0, RISCV_SZPTR /* image->entry++ */
/* IND_DESTINATION entry ? -> save destination address */
andi t1, t0, 0x1
beqz t1, 2f
- andi s4, t0, ~0x1
+ andi s5, t0, ~0x1
j 1b
2:
@@ -74,9 +70,8 @@ SYM_CODE_START(riscv_kexec_relocate)
andi t1, t0, 0x2
beqz t1, 2f
andi s0, t0, ~0x2
- addi s9, s9, 1
csrw CSR_SATP, zero
- jalr zero, s8, 0
+ jr s6
2:
/* IND_DONE entry ? -> jump to done label */
@@ -92,14 +87,13 @@ SYM_CODE_START(riscv_kexec_relocate)
andi t1, t0, 0x8
beqz t1, 1b /* Unknown entry type, ignore it */
andi t0, t0, ~0x8
- mv t3, s5 /* i = num words per page */
+ li t3, (PAGE_SIZE / RISCV_SZPTR) /* i = num words per page */
3: /* copy loop */
REG_L t1, (t0) /* t1 = *src_ptr */
- REG_S t1, (s4) /* *dst_ptr = *src_ptr */
+ REG_S t1, (s5) /* *dst_ptr = *src_ptr */
addi t0, t0, RISCV_SZPTR /* stc_ptr++ */
- addi s4, s4, RISCV_SZPTR /* dst_ptr++ */
- sub t3, t3, s6 /* i-- */
- addi s11, s11, 1 /* c++ */
+ addi s5, s5, RISCV_SZPTR /* dst_ptr++ */
+ addi t3, t3, -0x1 /* i-- */
beqz t3, 1b /* copy done ? */
j 3b
@@ -146,7 +140,7 @@ SYM_CODE_START(riscv_kexec_relocate)
*/
fence.i
- jalr zero, a2, 0
+ jr a2
SYM_CODE_END(riscv_kexec_relocate)
riscv_kexec_relocate_end:
--
2.20.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH V1 2/3] riscv: kexec: Align the kexeced kernel entry
2023-09-07 10:33 ` Song Shuai
@ 2023-09-07 10:33 ` Song Shuai
-1 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
The current riscv boot protocol requires 2MB alignment for RV64
and 4MB alignment for RV32.
In KEXEC_FILE path, the elf_find_pbase() function should align
the kexeced kernel entry according to the requirement, otherwise
the kexeced kernel would silently BUG at the setup_vm().
Fixes: 8acea455fafa ("RISC-V: Support for kexec_file on panic")
Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
arch/riscv/kernel/elf_kexec.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
index 38390d3bdcac..bc7a00ff5c8b 100644
--- a/arch/riscv/kernel/elf_kexec.c
+++ b/arch/riscv/kernel/elf_kexec.c
@@ -98,7 +98,13 @@ static int elf_find_pbase(struct kimage *image, unsigned long kernel_len,
kbuf.image = image;
kbuf.buf_min = lowest_paddr;
kbuf.buf_max = ULONG_MAX;
- kbuf.buf_align = PAGE_SIZE;
+
+ /*
+ * Current riscv boot protocol requires 2MB alignment for
+ * RV64 and 4MB alignment for RV32
+ *
+ */
+ kbuf.buf_align = PMD_SIZE;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
kbuf.memsz = ALIGN(kernel_len, PAGE_SIZE);
kbuf.top_down = false;
--
2.20.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH V1 2/3] riscv: kexec: Align the kexeced kernel entry
@ 2023-09-07 10:33 ` Song Shuai
0 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
The current riscv boot protocol requires 2MB alignment for RV64
and 4MB alignment for RV32.
In KEXEC_FILE path, the elf_find_pbase() function should align
the kexeced kernel entry according to the requirement, otherwise
the kexeced kernel would silently BUG at the setup_vm().
Fixes: 8acea455fafa ("RISC-V: Support for kexec_file on panic")
Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
arch/riscv/kernel/elf_kexec.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
index 38390d3bdcac..bc7a00ff5c8b 100644
--- a/arch/riscv/kernel/elf_kexec.c
+++ b/arch/riscv/kernel/elf_kexec.c
@@ -98,7 +98,13 @@ static int elf_find_pbase(struct kimage *image, unsigned long kernel_len,
kbuf.image = image;
kbuf.buf_min = lowest_paddr;
kbuf.buf_max = ULONG_MAX;
- kbuf.buf_align = PAGE_SIZE;
+
+ /*
+ * Current riscv boot protocol requires 2MB alignment for
+ * RV64 and 4MB alignment for RV32
+ *
+ */
+ kbuf.buf_align = PMD_SIZE;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
kbuf.memsz = ALIGN(kernel_len, PAGE_SIZE);
kbuf.top_down = false;
--
2.20.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH V1 3/3] riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
2023-09-07 10:33 ` Song Shuai
@ 2023-09-07 10:33 ` Song Shuai
-1 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
With CONFIG_RELOCATABLE enabled, KBUILD_CFLAGS had a -fPIE option
and then the purgatory/string.o was built to reference _ctype symbol
via R_RISCV_GOT_HI20 relocations which can't be handled by purgatory.
As a consequence, the kernel failed kexec_load_file() with:
[ 880.386562] kexec_image: The entry point of kernel at 0x80200000
[ 880.388650] kexec_image: Unknown rela relocation: 20
[ 880.389173] kexec_image: Error loading purgatory ret=-8
So remove the -fPIE option for PURGATORY_CFLAGS to generate
R_RISCV_PCREL_HI20 relocations type making puragtory work as it was.
Fixes: 39b33072941f ("riscv: Introduce CONFIG_RELOCATABLE")
Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
arch/riscv/purgatory/Makefile | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/riscv/purgatory/Makefile b/arch/riscv/purgatory/Makefile
index dc20e166983e..c2065d63945f 100644
--- a/arch/riscv/purgatory/Makefile
+++ b/arch/riscv/purgatory/Makefile
@@ -77,6 +77,10 @@ ifdef CONFIG_STACKPROTECTOR_STRONG
PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong
endif
+ifdef CONFIG_RELOCATABLE
+PURGATORY_CFLAGS_REMOVE += -fPIE
+endif
+
CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE)
CFLAGS_purgatory.o += $(PURGATORY_CFLAGS)
--
2.20.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH V1 3/3] riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
@ 2023-09-07 10:33 ` Song Shuai
0 siblings, 0 replies; 11+ messages in thread
From: Song Shuai @ 2023-09-07 10:33 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
songshuaishuai, petr.tesarik.ext, duwe, ribalda, akpm, keescook,
hi, heiko, lizhengyu3, alexghiti, schwab
Cc: linux-riscv, linux-kernel, kexec
With CONFIG_RELOCATABLE enabled, KBUILD_CFLAGS had a -fPIE option
and then the purgatory/string.o was built to reference _ctype symbol
via R_RISCV_GOT_HI20 relocations which can't be handled by purgatory.
As a consequence, the kernel failed kexec_load_file() with:
[ 880.386562] kexec_image: The entry point of kernel at 0x80200000
[ 880.388650] kexec_image: Unknown rela relocation: 20
[ 880.389173] kexec_image: Error loading purgatory ret=-8
So remove the -fPIE option for PURGATORY_CFLAGS to generate
R_RISCV_PCREL_HI20 relocations type making puragtory work as it was.
Fixes: 39b33072941f ("riscv: Introduce CONFIG_RELOCATABLE")
Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
arch/riscv/purgatory/Makefile | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/riscv/purgatory/Makefile b/arch/riscv/purgatory/Makefile
index dc20e166983e..c2065d63945f 100644
--- a/arch/riscv/purgatory/Makefile
+++ b/arch/riscv/purgatory/Makefile
@@ -77,6 +77,10 @@ ifdef CONFIG_STACKPROTECTOR_STRONG
PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong
endif
+ifdef CONFIG_RELOCATABLE
+PURGATORY_CFLAGS_REMOVE += -fPIE
+endif
+
CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE)
CFLAGS_purgatory.o += $(PURGATORY_CFLAGS)
--
2.20.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH V1 0/3] riscv: kexec: cleanup and fixups
2023-09-07 10:33 ` Song Shuai
(?)
@ 2023-09-13 0:37 ` patchwork-bot+linux-riscv
-1 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-09-13 0:37 UTC (permalink / raw)
To: Song Shuai
Cc: linux-riscv, paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
petr.tesarik.ext, duwe, ribalda, akpm, keescook, hi, heiko,
lizhengyu3, alexghiti, schwab, linux-kernel, kexec
Hello:
This series was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Thu, 7 Sep 2023 18:33:01 +0800 you wrote:
> Hi,
>
> I had posted 2 patches [1][2] for riscv/kexec, but there was no "effective"
> response to them until now, so I merged them in this series with the 3rd fixup.
>
> Anyway, this series contains a cleanup for riscv_kexec_relocate() and two fixups
> for KEXEC_FILE and had passed the basic kexec test in my 64bit Qemu-virt.
>
> [...]
Here is the summary with links:
- [V1,1/3] riscv: kexec: Cleanup riscv_kexec_relocate
(no matching commit)
- [V1,2/3] riscv: kexec: Align the kexeced kernel entry
https://git.kernel.org/riscv/c/1bfb2b618d52
- [V1,3/3] riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH V1 0/3] riscv: kexec: cleanup and fixups
@ 2023-09-13 0:37 ` patchwork-bot+linux-riscv
0 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-09-13 0:37 UTC (permalink / raw)
To: Song Shuai
Cc: linux-riscv, paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
petr.tesarik.ext, duwe, ribalda, akpm, keescook, hi, heiko,
lizhengyu3, alexghiti, schwab, linux-kernel, kexec
Hello:
This series was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Thu, 7 Sep 2023 18:33:01 +0800 you wrote:
> Hi,
>
> I had posted 2 patches [1][2] for riscv/kexec, but there was no "effective"
> response to them until now, so I merged them in this series with the 3rd fixup.
>
> Anyway, this series contains a cleanup for riscv_kexec_relocate() and two fixups
> for KEXEC_FILE and had passed the basic kexec test in my 64bit Qemu-virt.
>
> [...]
Here is the summary with links:
- [V1,1/3] riscv: kexec: Cleanup riscv_kexec_relocate
(no matching commit)
- [V1,2/3] riscv: kexec: Align the kexeced kernel entry
https://git.kernel.org/riscv/c/1bfb2b618d52
- [V1,3/3] riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH V1 0/3] riscv: kexec: cleanup and fixups
@ 2023-09-13 0:37 ` patchwork-bot+linux-riscv
0 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-09-13 0:37 UTC (permalink / raw)
To: Song Shuai
Cc: linux-riscv, paul.walmsley, palmer, aou, conor.dooley, lihuafei1,
petr.tesarik.ext, duwe, ribalda, akpm, keescook, hi, heiko,
lizhengyu3, alexghiti, schwab, linux-kernel, kexec
Hello:
This series was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Thu, 7 Sep 2023 18:33:01 +0800 you wrote:
> Hi,
>
> I had posted 2 patches [1][2] for riscv/kexec, but there was no "effective"
> response to them until now, so I merged them in this series with the 3rd fixup.
>
> Anyway, this series contains a cleanup for riscv_kexec_relocate() and two fixups
> for KEXEC_FILE and had passed the basic kexec test in my 64bit Qemu-virt.
>
> [...]
Here is the summary with links:
- [V1,1/3] riscv: kexec: Cleanup riscv_kexec_relocate
(no matching commit)
- [V1,2/3] riscv: kexec: Align the kexeced kernel entry
https://git.kernel.org/riscv/c/1bfb2b618d52
- [V1,3/3] riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-09-13 0:37 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-07 10:33 [PATCH V1 0/3] riscv: kexec: cleanup and fixups Song Shuai
2023-09-07 10:33 ` Song Shuai
2023-09-07 10:33 ` [PATCH V1 1/3] riscv: kexec: Cleanup riscv_kexec_relocate Song Shuai
2023-09-07 10:33 ` Song Shuai
2023-09-07 10:33 ` [PATCH V1 2/3] riscv: kexec: Align the kexeced kernel entry Song Shuai
2023-09-07 10:33 ` Song Shuai
2023-09-07 10:33 ` [PATCH V1 3/3] riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS Song Shuai
2023-09-07 10:33 ` Song Shuai
2023-09-13 0:37 ` [PATCH V1 0/3] riscv: kexec: cleanup and fixups patchwork-bot+linux-riscv
2023-09-13 0:37 ` patchwork-bot+linux-riscv
2023-09-13 0:37 ` patchwork-bot+linux-riscv
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.