From: Nathan Chancellor <nathan@kernel.org>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Huacai Chen <chenhuacai@kernel.org>,
Binbin Zhou <zhoubinbin@loongson.cn>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH v3 3/4] LoongArch: Fix entry point in image header
Date: Wed, 29 May 2024 11:28:59 -0700 [thread overview]
Message-ID: <20240529182859.GA3994034@thelio-3990X> (raw)
In-Reply-To: <20240522-loongarch-booting-fixes-v3-3-25e77a8fc86e@flygoat.com>
Hi Jiaxun,
On Wed, May 22, 2024 at 11:02:19PM +0100, Jiaxun Yang wrote:
> Currently kernel entry in head.S is in DMW address range,
> firmware is instructed to jump to this address after loading
> the 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.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
> v2: Fix efistub
> v3: Move calculation to linker script
> ---
> arch/loongarch/kernel/head.S | 2 +-
> arch/loongarch/kernel/vmlinux.lds.S | 2 ++
> drivers/firmware/efi/libstub/loongarch.c | 2 +-
> 3 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S
> index c4f7de2e2805..2cdc1ea808d9 100644
> --- a/arch/loongarch/kernel/head.S
> +++ b/arch/loongarch/kernel/head.S
> @@ -22,7 +22,7 @@
> _head:
> .word MZ_MAGIC /* "MZ", MS-DOS header */
> .org 0x8
> - .dword kernel_entry /* Kernel entry point */
> + .dword _kernel_entry_phys /* Kernel entry point (physical address) */
> .dword _kernel_asize /* Kernel image effective size */
> .quad PHYS_LINK_KADDR /* Kernel image load offset from start of RAM */
> .org 0x38 /* 0x20 ~ 0x37 reserved */
> diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S
> index e8e97dbf9ca4..c6f89e51257a 100644
> --- a/arch/loongarch/kernel/vmlinux.lds.S
> +++ b/arch/loongarch/kernel/vmlinux.lds.S
> @@ -6,6 +6,7 @@
>
> #define PAGE_SIZE _PAGE_SIZE
> #define RO_EXCEPTION_TABLE_ALIGN 4
> +#define TO_PHYS_MASK 0x000fffffffffffff /* 48-bit */
>
> /*
> * Put .bss..swapper_pg_dir as the first thing in .bss. This will
> @@ -142,6 +143,7 @@ SECTIONS
>
> #ifdef CONFIG_EFI_STUB
> /* header symbols */
> + _kernel_entry_phys = kernel_entry & TO_PHYS_MASK;
> _kernel_asize = _end - _text;
> _kernel_fsize = _edata - _text;
> _kernel_vsize = _end - __initdata_begin;
> diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
> index 684c9354637c..60c145121393 100644
> --- a/drivers/firmware/efi/libstub/loongarch.c
> +++ b/drivers/firmware/efi/libstub/loongarch.c
> @@ -41,7 +41,7 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
> unsigned long __weak kernel_entry_address(unsigned long kernel_addr,
> efi_loaded_image_t *image)
> {
> - return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS + kernel_addr;
> + return *(unsigned long *)(kernel_addr + 8) - TO_PHYS(VMLINUX_LOAD_ADDRESS) + kernel_addr;
> }
>
> efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
>
> --
> 2.43.0
>
This patch is now in -next as commit 75461304ee4e ("LoongArch: Fix entry
point in kernel image header"). I just bisected a build failure that I
see when building with LLVM (either 18 or 19) to this change.
$ make -skj"$(nproc)" ARCH=loongarch LLVM=1 defconfig vmlinux
...
kallsyms failure: relative symbol value 0x9000000000200000 out of range in relative mode
make[4]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1
...
Does kallsyms need some adjustment for this?
Cheers,
Nathan
# bad: [9d99040b1bc8dbf385a8aa535e9efcdf94466e19] Add linux-next specific files for 20240529
# good: [e0cce98fe279b64f4a7d81b7f5c3a23d80b92fbc] Merge tag 'tpmdd-next-6.10-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
git bisect start '9d99040b1bc8dbf385a8aa535e9efcdf94466e19' 'e0cce98fe279b64f4a7d81b7f5c3a23d80b92fbc'
# bad: [270c6bb9d5e8448b74950f23ff2a192faaf10428] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git
git bisect bad 270c6bb9d5e8448b74950f23ff2a192faaf10428
# good: [c38b067bf2ab58d93590a50cbc06c992fe00447e] Merge branch 'ti-next' of git://git.kernel.org/pub/scm/linux/kernel/git/ti/linux.git
git bisect good c38b067bf2ab58d93590a50cbc06c992fe00447e
# bad: [6bcfb2dcf8b00c0b4cef68ac026c71dae3c25070] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git
git bisect bad 6bcfb2dcf8b00c0b4cef68ac026c71dae3c25070
# good: [2ca0cd490407a728a9aa57b9538f3ca8b287a089] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git
git bisect good 2ca0cd490407a728a9aa57b9538f3ca8b287a089
# good: [f3760c80d06a838495185c0fe341c043e6495142] Merge branch 'rework/write-atomic' into for-next
git bisect good f3760c80d06a838495185c0fe341c043e6495142
# good: [b9fc9904efcaea8470f0d4cd0691f1295add9381] Merge branch 'vfs.module.description' into vfs.all
git bisect good b9fc9904efcaea8470f0d4cd0691f1295add9381
# good: [88dbb5f3c068ba8944e97235ccfdc5fbd6c7d577] Merge branch '9p-next' of git://github.com/martinetd/linux
git bisect good 88dbb5f3c068ba8944e97235ccfdc5fbd6c7d577
# bad: [b4660cd50cb1e5821532e34dbc7f47cb155ba57b] Merge branch 'next' of git://git.monstr.eu/linux-2.6-microblaze.git
git bisect bad b4660cd50cb1e5821532e34dbc7f47cb155ba57b
# bad: [c768fc96978cd0f74dd297d58720cb984a7f6341] LoongArch: Override higher address bits in JUMP_VIRT_ADDR
git bisect bad c768fc96978cd0f74dd297d58720cb984a7f6341
# good: [2624e739c2e9abe5f6cc9acc37f9752f0055fb5f] LoongArch: Add all CPUs enabled by fdt to NUMA node 0
git bisect good 2624e739c2e9abe5f6cc9acc37f9752f0055fb5f
# bad: [75461304ee4e7e2cb282265a6a89c35b81282d19] LoongArch: Fix entry point in kernel image header
git bisect bad 75461304ee4e7e2cb282265a6a89c35b81282d19
# first bad commit: [75461304ee4e7e2cb282265a6a89c35b81282d19] LoongArch: Fix entry point in kernel image header
next prev parent reply other threads:[~2024-05-29 18:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-22 22:02 [PATCH v3 0/4] LoongArch: Bootloader interface fixes Jiaxun Yang
2024-05-22 22:02 ` [PATCH v3 1/4] LoongArch: Fix built-in DTB detection Jiaxun Yang
2024-05-30 10:06 ` Thomas Weißschuh
2024-05-30 14:49 ` Huacai Chen
2024-05-22 22:02 ` [PATCH v3 2/4] LoongArch: smp: Add all CPUs enabled by fdt to NUMA node 0 Jiaxun Yang
2024-05-22 22:02 ` [PATCH v3 3/4] LoongArch: Fix entry point in image header Jiaxun Yang
2024-05-29 18:28 ` Nathan Chancellor [this message]
2024-05-30 5:01 ` WANG Rui
2024-05-30 9:50 ` Jiaxun Yang
2024-05-30 10:41 ` Huacai Chen
2024-05-22 22:02 ` [PATCH v3 4/4] LoongArch: Override higher address bits in JUMP_VIRT_ADDR Jiaxun Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240529182859.GA3994034@thelio-3990X \
--to=nathan@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=jiaxun.yang@flygoat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=loongarch@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zhoubinbin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox