From: Ainux Wang <ainux.wang@gmail.com>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: wangyao@lemote.com, ardb@kernel.org, wangrui@loongson.cn,
linux-efi@vger.kernel.org
Subject: Re: [PATCH] efi/loongarch: Use relocate address to calculate kernel entry address
Date: Tue, 5 Dec 2023 09:16:26 +0800 [thread overview]
Message-ID: <CAPWE4_yLATC-Qh4STyxJ_o8DRu_+odJLDU5C6qebdmXVMaNuYA@mail.gmail.com> (raw)
In-Reply-To: <CAAhV-H4ZNsD8E=uEmtr3bgn4vfXXW0ugNHhwQHeKDKvyVAA=gA@mail.gmail.com>
Huacai Chen <chenhuacai@kernel.org> 于2023年12月4日周一 21:02写道:
>
> Hi, Yao,
>
> The title can be "Use load address ....".
>
>
> On Mon, Dec 4, 2023 at 11:19 AM <wangyao@lemote.com> wrote:
> >
> > From: Wang Yao <wangyao@lemote.com>
> >
> > The efi_relocate_kernel() may relocate the PIE kernel to anywhere, the relocated
> > address may not be equal to link address or EFI_KIMG_PREFERRED_ADDRESS.
> >
> > Signed-off-by: Wang Yao <wangyao@lemote.com>
> > ---
> > arch/loongarch/include/asm/efi.h | 2 +-
> > drivers/firmware/efi/libstub/loongarch-stub.c | 4 ++--
> > drivers/firmware/efi/libstub/loongarch.c | 6 +++---
> > 3 files changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/loongarch/include/asm/efi.h b/arch/loongarch/include/asm/efi.h
> > index 091897d40b03..91d81f9730ab 100644
> > --- a/arch/loongarch/include/asm/efi.h
> > +++ b/arch/loongarch/include/asm/efi.h
> > @@ -32,6 +32,6 @@ static inline unsigned long efi_get_kimg_min_align(void)
> >
> > #define EFI_KIMG_PREFERRED_ADDRESS PHYSADDR(VMLINUX_LOAD_ADDRESS)
> >
> > -unsigned long kernel_entry_address(void);
> > +unsigned long kernel_entry_address(unsigned long kernel_addr);
> >
> > #endif /* _ASM_LOONGARCH_EFI_H */
> > diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
> > index 72c71ae201f0..4d52f1dc5258 100644
> > --- a/drivers/firmware/efi/libstub/loongarch-stub.c
> > +++ b/drivers/firmware/efi/libstub/loongarch-stub.c
> > @@ -35,9 +35,9 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
> > return status;
> > }
> >
> > -unsigned long kernel_entry_address(void)
> > +unsigned long kernel_entry_address(unsigned long kernel_addr)
> > {
> > unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
> >
> > - return (unsigned long)&kernel_entry - base + VMLINUX_LOAD_ADDRESS;
> > + return (unsigned long)&kernel_entry - base + TO_CACHE(kernel_addr);
> > }
> > diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
> > index 807cba2693fc..d7ec9381f8ea 100644
> > --- a/drivers/firmware/efi/libstub/loongarch.c
> > +++ b/drivers/firmware/efi/libstub/loongarch.c
> > @@ -37,9 +37,9 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
> > return EFI_SUCCESS;
> > }
> >
> > -unsigned long __weak kernel_entry_address(void)
> > +unsigned long __weak kernel_entry_address(unsigned long kernel_addr)
> > {
> > - return *(unsigned long *)(PHYSADDR(VMLINUX_LOAD_ADDRESS) + 8);
> > + return *(unsigned long *)(PHYSADDR(kernel_addr) + 8);
> The address read from DOS header is link address, so you should return
> *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS +
> TO_CACHE(kernel_addr);
>
> Huacai
Ok, thanks.
Best regards,
Ainux Wang.
>
> > }
> >
> > efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
> > @@ -73,7 +73,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
> > csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
> > csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
> >
> > - real_kernel_entry = (void *)kernel_entry_address();
> > + real_kernel_entry = (void *)kernel_entry_address(kernel_addr);
> >
> > real_kernel_entry(true, (unsigned long)cmdline_ptr,
> > (unsigned long)efi_system_table);
> > --
> > 2.27.0
> >
prev parent reply other threads:[~2023-12-05 1:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 3:18 [PATCH] efi/loongarch: Use relocate address to calculate kernel entry address wangyao
2023-12-04 13:02 ` Huacai Chen
2023-12-05 1:16 ` Ainux Wang [this message]
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=CAPWE4_yLATC-Qh4STyxJ_o8DRu_+odJLDU5C6qebdmXVMaNuYA@mail.gmail.com \
--to=ainux.wang@gmail.com \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=wangrui@loongson.cn \
--cc=wangyao@lemote.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).