Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efi/loongarch: Directly position the loaded image file

The use of the 'kernel_offset' variable to position the image file that
has been loaded by UEFI or GRUB is unnecessary, because we can directly
position the loaded image file through using the image_base field of the
efi_loaded_image struct provided by UEFI.

Replace kernel_offset with image_base to position the image file that has
been loaded by UEFI or GRUB.

Signed-off-by: Wang Yao <wangyao@lemote.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

authored by

Wang Yao and committed by
Ard Biesheuvel
174a0c56 a42da7f0

+13 -11
-2
arch/loongarch/include/asm/efi.h
··· 32 32 33 33 #define EFI_KIMG_PREFERRED_ADDRESS PHYSADDR(VMLINUX_LOAD_ADDRESS) 34 34 35 - unsigned long kernel_entry_address(unsigned long kernel_addr); 36 - 37 35 #endif /* _ASM_LOONGARCH_EFI_H */
-1
arch/loongarch/kernel/head.S
··· 34 34 35 35 SYM_DATA(kernel_asize, .long _kernel_asize); 36 36 SYM_DATA(kernel_fsize, .long _kernel_fsize); 37 - SYM_DATA(kernel_offset, .long _kernel_offset); 38 37 39 38 #endif 40 39
-1
arch/loongarch/kernel/image-vars.h
··· 11 11 __efistub_kernel_entry = kernel_entry; 12 12 __efistub_kernel_asize = kernel_asize; 13 13 __efistub_kernel_fsize = kernel_fsize; 14 - __efistub_kernel_offset = kernel_offset; 15 14 #if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB) 16 15 __efistub_screen_info = screen_info; 17 16 #endif
-1
arch/loongarch/kernel/vmlinux.lds.S
··· 143 143 _kernel_fsize = _edata - _text; 144 144 _kernel_vsize = _end - __initdata_begin; 145 145 _kernel_rsize = _edata - __initdata_begin; 146 - _kernel_offset = kernel_offset - _text; 147 146 #endif 148 147 149 148 .gptab.sdata : {
+5 -4
drivers/firmware/efi/libstub/loongarch-stub.c
··· 8 8 #include <asm/efi.h> 9 9 #include <asm/addrspace.h> 10 10 #include "efistub.h" 11 + #include "loongarch-stub.h" 11 12 12 13 extern int kernel_asize; 13 14 extern int kernel_fsize; 14 - extern int kernel_offset; 15 15 extern int kernel_entry; 16 16 17 17 efi_status_t handle_kernel_image(unsigned long *image_addr, ··· 24 24 efi_status_t status; 25 25 unsigned long kernel_addr = 0; 26 26 27 - kernel_addr = (unsigned long)&kernel_offset - kernel_offset; 27 + kernel_addr = (unsigned long)image->image_base; 28 28 29 29 status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize, 30 30 EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); ··· 35 35 return status; 36 36 } 37 37 38 - unsigned long kernel_entry_address(unsigned long kernel_addr) 38 + unsigned long kernel_entry_address(unsigned long kernel_addr, 39 + efi_loaded_image_t *image) 39 40 { 40 - unsigned long base = (unsigned long)&kernel_offset - kernel_offset; 41 + unsigned long base = (unsigned long)image->image_base; 41 42 42 43 return (unsigned long)&kernel_entry - base + kernel_addr; 43 44 }
+4
drivers/firmware/efi/libstub/loongarch-stub.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + 3 + unsigned long kernel_entry_address(unsigned long kernel_addr, 4 + efi_loaded_image_t *image);
+4 -2
drivers/firmware/efi/libstub/loongarch.c
··· 8 8 #include <asm/efi.h> 9 9 #include <asm/addrspace.h> 10 10 #include "efistub.h" 11 + #include "loongarch-stub.h" 11 12 12 13 typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline, 13 14 unsigned long systab); ··· 38 37 return EFI_SUCCESS; 39 38 } 40 39 41 - unsigned long __weak kernel_entry_address(unsigned long kernel_addr) 40 + unsigned long __weak kernel_entry_address(unsigned long kernel_addr, 41 + efi_loaded_image_t *image) 42 42 { 43 43 return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS + kernel_addr; 44 44 } ··· 75 73 csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0); 76 74 csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1); 77 75 78 - real_kernel_entry = (void *)kernel_entry_address(kernel_addr); 76 + real_kernel_entry = (void *)kernel_entry_address(kernel_addr, image); 79 77 80 78 real_kernel_entry(true, (unsigned long)cmdline_ptr, 81 79 (unsigned long)efi_system_table);