public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH V1 0/3] riscv: kexec: cleanup and fixups
@ 2023-09-07 10:33 Song Shuai
  2023-09-07 10:33 ` [PATCH V1 1/3] riscv: kexec: Cleanup riscv_kexec_relocate Song Shuai
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ 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] 5+ messages in thread

end of thread, other threads:[~2023-09-13  0:37 UTC | newest]

Thread overview: 5+ 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 ` [PATCH V1 1/3] riscv: kexec: Cleanup riscv_kexec_relocate 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 ` [PATCH V1 3/3] riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS Song Shuai
2023-09-13  0:37 ` [PATCH V1 0/3] riscv: kexec: cleanup and fixups patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox