]> Git Repo - linux.git/commitdiff
Merge patch series "riscv: kexec: cleanup and fixups"
authorPalmer Dabbelt <[email protected]>
Wed, 1 Nov 2023 02:15:41 +0000 (19:15 -0700)
committerPalmer Dabbelt <[email protected]>
Wed, 1 Nov 2023 02:15:41 +0000 (19:15 -0700)
Song Shuai <[email protected]> says:

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.

 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(-)

* b4-shazam-merge:
  riscv: kexec: Remove -fPIE for PURGATORY_CFLAGS
  riscv: kexec: Align the kexeced kernel entry
  riscv: kexec: Cleanup riscv_kexec_relocate

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Palmer Dabbelt <[email protected]>
1  2 
arch/riscv/kernel/elf_kexec.c
arch/riscv/purgatory/Makefile

index f4099059ed8f2507913ecfbb3713249feda33373,9a81d6926ac614fedfbe2fc1fa6afdc7e919e917..e60fbd8660c4a531c6deef3938c45afe2e158839
@@@ -98,7 -98,13 +98,13 @@@ static int elf_find_pbase(struct kimag
        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;
@@@ -260,7 -266,7 +266,7 @@@ static void *elf_kexec_load(struct kima
                cmdline = modified_cmdline;
        }
  
 -#ifdef CONFIG_ARCH_HAS_KEXEC_PURGATORY
 +#ifdef CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY
        /* Add purgatory to the image */
        kbuf.top_down = true;
        kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
                                             sizeof(kernel_start), 0);
        if (ret)
                pr_err("Error update purgatory ret=%d\n", ret);
 -#endif /* CONFIG_ARCH_HAS_KEXEC_PURGATORY */
 +#endif /* CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY */
  
        /* Add the initrd to the image */
        if (initrd != NULL) {
                kbuf.buffer = initrd;
                kbuf.bufsz = kbuf.memsz = initrd_len;
                kbuf.buf_align = PAGE_SIZE;
 -              kbuf.top_down = false;
 +              kbuf.top_down = true;
                kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
                ret = kexec_add_buffer(&kbuf);
                if (ret)
@@@ -425,7 -431,6 +431,7 @@@ int arch_kexec_apply_relocations_add(st
                 * sym, instead of searching the whole relsec.
                 */
                case R_RISCV_PCREL_HI20:
 +              case R_RISCV_CALL_PLT:
                case R_RISCV_CALL:
                        *(u64 *)loc = CLEAN_IMM(UITYPE, *(u64 *)loc) |
                                 ENCODE_UJTYPE_IMM(val - addr);
index 9e6476719abbbb4e9206cd89292be7f25261a5b6,c2065d63945f3e8348167cb666a146b1d74cca80..982fc8e771085edc6ba91f40855ec8edca525c13
@@@ -77,10 -77,10 +77,14 @@@ ifdef CONFIG_STACKPROTECTOR_STRON
  PURGATORY_CFLAGS_REMOVE               += -fstack-protector-strong
  endif
  
 +ifdef CONFIG_CFI_CLANG
 +PURGATORY_CFLAGS_REMOVE               += $(CC_FLAGS_CFI)
 +endif
 +
+ ifdef CONFIG_RELOCATABLE
+ PURGATORY_CFLAGS_REMOVE               += -fPIE
+ endif
  CFLAGS_REMOVE_purgatory.o     += $(PURGATORY_CFLAGS_REMOVE)
  CFLAGS_purgatory.o            += $(PURGATORY_CFLAGS)
  
This page took 0.06661 seconds and 4 git commands to generate.