Message ID | 20231205060345.7742-1-wangyao@lemote.com |
---|---|
Headers | show |
Series | Use load address to calculate kernel entry | expand |
Why send a test patch? On Tue, Dec 5, 2023 at 2:04 PM <wangyao@lemote.com> wrote: > > From: Wang Yao <wangyao@lemote.com> > > This is a test patch for PIE kernel that load address is not equal to > link address. > > Signed-off-by: Wang Yao <wangyao@lemote.com> > --- > drivers/firmware/efi/libstub/loongarch-stub.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c > index d6ec5d4b8dbe..c13c022d18cf 100644 > --- a/drivers/firmware/efi/libstub/loongarch-stub.c > +++ b/drivers/firmware/efi/libstub/loongarch-stub.c > @@ -22,12 +22,22 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, > efi_handle_t image_handle) > { > efi_status_t status; > - unsigned long kernel_addr = 0; > + unsigned long kernel_addr = 0, tmp_addr = 0; > > kernel_addr = (unsigned long)&kernel_offset - kernel_offset; > > + /* > + * Allocate 2M space at 0x200000(EFI_KIMG_PREFERRED_ADDRESS) for > + * test, this will lead to the kernel be loaded at 0x4000000. > + */ > + status = efi_relocate_kernel(&tmp_addr, 0x100000, 0x200000, > + EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > + efi_info("@@@[%s] tmp_addr: 0x%lx\n", __func__, tmp_addr); > + > + /* kernel_addr == 0x400000 */ > status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize, > EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > + efi_info("@@@[%s] kernel_addr: 0x%lx\n", __func__, kernel_addr); > > *image_addr = kernel_addr; > *image_size = kernel_asize; > -- > 2.27.0 >
On Tue, Dec 5, 2023 at 2:16 PM Ainux Wang <ainux.wang@gmail.com> wrote: > > Huacai Chen <chenhuacai@kernel.org> 于2023年12月5日周二 14:09写道: > > > > Why send a test patch? > > > > Confirm the accuracy of the testing method Don't use maillist to do this. > > > On Tue, Dec 5, 2023 at 2:04 PM <wangyao@lemote.com> wrote: > > > > > > From: Wang Yao <wangyao@lemote.com> > > > > > > This is a test patch for PIE kernel that load address is not equal to > > > link address. > > > > > > Signed-off-by: Wang Yao <wangyao@lemote.com> > > > --- > > > drivers/firmware/efi/libstub/loongarch-stub.c | 12 +++++++++++- > > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c > > > index d6ec5d4b8dbe..c13c022d18cf 100644 > > > --- a/drivers/firmware/efi/libstub/loongarch-stub.c > > > +++ b/drivers/firmware/efi/libstub/loongarch-stub.c > > > @@ -22,12 +22,22 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, > > > efi_handle_t image_handle) > > > { > > > efi_status_t status; > > > - unsigned long kernel_addr = 0; > > > + unsigned long kernel_addr = 0, tmp_addr = 0; > > > > > > kernel_addr = (unsigned long)&kernel_offset - kernel_offset; > > > > > > + /* > > > + * Allocate 2M space at 0x200000(EFI_KIMG_PREFERRED_ADDRESS) for > > > + * test, this will lead to the kernel be loaded at 0x4000000. > > > + */ > > > + status = efi_relocate_kernel(&tmp_addr, 0x100000, 0x200000, > > > + EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > > > + efi_info("@@@[%s] tmp_addr: 0x%lx\n", __func__, tmp_addr); > > > + > > > + /* kernel_addr == 0x400000 */ > > > status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize, > > > EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > > > + efi_info("@@@[%s] kernel_addr: 0x%lx\n", __func__, kernel_addr); > > > > > > *image_addr = kernel_addr; > > > *image_size = kernel_asize; > > > -- > > > 2.27.0 > > >
On Tue, Dec 5, 2023 at 2:24 PM Ainux Wang <ainux.wang@gmail.com> wrote: > > Huacai Chen <chenhuacai@kernel.org> 于2023年12月5日周二 14:18写道: > > > > On Tue, Dec 5, 2023 at 2:16 PM Ainux Wang <ainux.wang@gmail.com> wrote: > > > > > > Huacai Chen <chenhuacai@kernel.org> 于2023年12月5日周二 14:09写道: > > > > > > > > Why send a test patch? > > > > > > > > > > Confirm the accuracy of the testing method > > > > Don't use maillist to do this. > > Sorry, I don't know about this :-( But from this patch, you only test the vmlinux.efi not loaded at link address, but haven't tested the vmlinuz.efi not decompressed to the link address. You should test that, but don't submit patches for that. > > > > > > > > > > On Tue, Dec 5, 2023 at 2:04 PM <wangyao@lemote.com> wrote: > > > > > > > > > > From: Wang Yao <wangyao@lemote.com> > > > > > > > > > > This is a test patch for PIE kernel that load address is not equal to > > > > > link address. > > > > > > > > > > Signed-off-by: Wang Yao <wangyao@lemote.com> > > > > > --- > > > > > drivers/firmware/efi/libstub/loongarch-stub.c | 12 +++++++++++- > > > > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c > > > > > index d6ec5d4b8dbe..c13c022d18cf 100644 > > > > > --- a/drivers/firmware/efi/libstub/loongarch-stub.c > > > > > +++ b/drivers/firmware/efi/libstub/loongarch-stub.c > > > > > @@ -22,12 +22,22 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, > > > > > efi_handle_t image_handle) > > > > > { > > > > > efi_status_t status; > > > > > - unsigned long kernel_addr = 0; > > > > > + unsigned long kernel_addr = 0, tmp_addr = 0; > > > > > > > > > > kernel_addr = (unsigned long)&kernel_offset - kernel_offset; > > > > > > > > > > + /* > > > > > + * Allocate 2M space at 0x200000(EFI_KIMG_PREFERRED_ADDRESS) for > > > > > + * test, this will lead to the kernel be loaded at 0x4000000. > > > > > + */ > > > > > + status = efi_relocate_kernel(&tmp_addr, 0x100000, 0x200000, > > > > > + EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > > > > > + efi_info("@@@[%s] tmp_addr: 0x%lx\n", __func__, tmp_addr); > > > > > + > > > > > + /* kernel_addr == 0x400000 */ > > > > > status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize, > > > > > EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > > > > > + efi_info("@@@[%s] kernel_addr: 0x%lx\n", __func__, kernel_addr); > > > > > > > > > > *image_addr = kernel_addr; > > > > > *image_size = kernel_asize; > > > > > -- > > > > > 2.27.0 > > > > >
On Tue, Dec 5, 2023 at 4:19 PM Ainux Wang <ainux.wang@gmail.com> wrote: > > Huacai Chen <chenhuacai@kernel.org> 于2023年12月5日周二 15:41写道: > > > > On Tue, Dec 5, 2023 at 2:24 PM Ainux Wang <ainux.wang@gmail.com> wrote: > > > > > > Huacai Chen <chenhuacai@kernel.org> 于2023年12月5日周二 14:18写道: > > > > > > > > On Tue, Dec 5, 2023 at 2:16 PM Ainux Wang <ainux.wang@gmail.com> wrote: > > > > > > > > > > Huacai Chen <chenhuacai@kernel.org> 于2023年12月5日周二 14:09写道: > > > > > > > > > > > > Why send a test patch? > > > > > > > > > > > > > > > > Confirm the accuracy of the testing method > > > > > > > > Don't use maillist to do this. > > > > > > Sorry, I don't know about this :-( > > But from this patch, you only test the vmlinux.efi not loaded at link > > address, but haven't tested the vmlinuz.efi not decompressed to the > > link address. You should test that, but don't submit patches for that. > > vmlinuz.efi decompress at 0x300000 is ok. Then you can resend the first patch as v4, add: Acked-by: Huacai Chen <chenhuacai@loongson.cn> Huacai > > > > > > > > > > > > > > > > > > > > > On Tue, Dec 5, 2023 at 2:04 PM <wangyao@lemote.com> wrote: > > > > > > > > > > > > > > From: Wang Yao <wangyao@lemote.com> > > > > > > > > > > > > > > This is a test patch for PIE kernel that load address is not equal to > > > > > > > link address. > > > > > > > > > > > > > > Signed-off-by: Wang Yao <wangyao@lemote.com> > > > > > > > --- > > > > > > > drivers/firmware/efi/libstub/loongarch-stub.c | 12 +++++++++++- > > > > > > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > > > > > > > > > > > diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c > > > > > > > index d6ec5d4b8dbe..c13c022d18cf 100644 > > > > > > > --- a/drivers/firmware/efi/libstub/loongarch-stub.c > > > > > > > +++ b/drivers/firmware/efi/libstub/loongarch-stub.c > > > > > > > @@ -22,12 +22,22 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, > > > > > > > efi_handle_t image_handle) > > > > > > > { > > > > > > > efi_status_t status; > > > > > > > - unsigned long kernel_addr = 0; > > > > > > > + unsigned long kernel_addr = 0, tmp_addr = 0; > > > > > > > > > > > > > > kernel_addr = (unsigned long)&kernel_offset - kernel_offset; > > > > > > > > > > > > > > + /* > > > > > > > + * Allocate 2M space at 0x200000(EFI_KIMG_PREFERRED_ADDRESS) for > > > > > > > + * test, this will lead to the kernel be loaded at 0x4000000. > > > > > > > + */ > > > > > > > + status = efi_relocate_kernel(&tmp_addr, 0x100000, 0x200000, > > > > > > > + EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > > > > > > > + efi_info("@@@[%s] tmp_addr: 0x%lx\n", __func__, tmp_addr); > > > > > > > + > > > > > > > + /* kernel_addr == 0x400000 */ > > > > > > > status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize, > > > > > > > EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0); > > > > > > > + efi_info("@@@[%s] kernel_addr: 0x%lx\n", __func__, kernel_addr); > > > > > > > > > > > > > > *image_addr = kernel_addr; > > > > > > > *image_size = kernel_asize; > > > > > > > -- > > > > > > > 2.27.0 > > > > > > >
From: Wang Yao <wangyao@lemote.com> 1, The PIE kernel will be loaded anywhere, so use load address to calculate kernel entry address. 2, Use twice efi_relocate_kernel() to make load address is not equal to link address for test. Wang Yao (2): efi/loongarch: Use load address to calculate kernel entry address efi/loongarch: load address is not equal to link address arch/loongarch/include/asm/efi.h | 2 +- drivers/firmware/efi/libstub/loongarch-stub.c | 16 +++++++++++++--- drivers/firmware/efi/libstub/loongarch.c | 6 +++--- 3 files changed, 17 insertions(+), 7 deletions(-)