Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit beb2800

Browse files
FlyGoatchenhuacai
authored andcommitted
LoongArch: Fix entry point in kernel image header
Currently kernel entry in head.S is in DMW address range, firmware is instructed to jump to this address after loading the kernel image. However kernel should not make any assumption on firmware's DMW setting, thus the entry point should be a physical address falls into direct translation region. Fix by converting entry address to physical and amend entry calculation logic in libstub accordingly. BTW, use ABSOLUTE() to calculate variables to make Clang/LLVM happy. Cc: stable@vger.kernel.org Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 3de9c42 commit beb2800

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

arch/loongarch/kernel/head.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_head:
2323
.word MZ_MAGIC /* "MZ", MS-DOS header */
2424
.org 0x8
25-
.dword kernel_entry /* Kernel entry point */
25+
.dword _kernel_entry /* Kernel entry point (physical address) */
2626
.dword _kernel_asize /* Kernel image effective size */
2727
.quad PHYS_LINK_KADDR /* Kernel image load offset from start of RAM */
2828
.org 0x38 /* 0x20 ~ 0x37 reserved */

arch/loongarch/kernel/vmlinux.lds.S

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#define PAGE_SIZE _PAGE_SIZE
88
#define RO_EXCEPTION_TABLE_ALIGN 4
9+
#define PHYSADDR_MASK 0xffffffffffff /* 48-bit */
910

1011
/*
1112
* Put .bss..swapper_pg_dir as the first thing in .bss. This will
@@ -142,10 +143,11 @@ SECTIONS
142143

143144
#ifdef CONFIG_EFI_STUB
144145
/* header symbols */
145-
_kernel_asize = _end - _text;
146-
_kernel_fsize = _edata - _text;
147-
_kernel_vsize = _end - __initdata_begin;
148-
_kernel_rsize = _edata - __initdata_begin;
146+
_kernel_entry = ABSOLUTE(kernel_entry & PHYSADDR_MASK);
147+
_kernel_asize = ABSOLUTE(_end - _text);
148+
_kernel_fsize = ABSOLUTE(_edata - _text);
149+
_kernel_vsize = ABSOLUTE(_end - __initdata_begin);
150+
_kernel_rsize = ABSOLUTE(_edata - __initdata_begin);
149151
#endif
150152

151153
.gptab.sdata : {

drivers/firmware/efi/libstub/loongarch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
4141
unsigned long __weak kernel_entry_address(unsigned long kernel_addr,
4242
efi_loaded_image_t *image)
4343
{
44-
return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS + kernel_addr;
44+
return *(unsigned long *)(kernel_addr + 8) - PHYSADDR(VMLINUX_LOAD_ADDRESS) + kernel_addr;
4545
}
4646

4747
efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,

0 commit comments

Comments
 (0)