efi/zboot: Encapsulate ELF image for arm64
Subsystems (4)
cover efi/zboot: Encapsulate ELF image for arm64
From: Ard Biesheuvel <[email protected]>
The EFI zboot image format was introduced to provide a way to distribute an EFI bootable image for architectures such as arm64, RISC-V and Loongarch supporting both compression and EFI secure boot signing.
To make this format easy to digest for other consumers than EFI firmware (e.g., qemu or kexec), the file header describes the compression type and the offset and size of the compressed image inside the file. Additional metadata of the payload is currently injected using ELF symbols (currently, the size of the executable image's code region on arm64), but this information is not accessible to other consumers unless it is exposed either via the header, or via the payload itself.
It would be better to have a structured format inside the container, so that any annotation can be added without the need to tweak the EFI zboot header layout. On x86, the legacy decompressor encapsulates an ELF image, so that ELF notes can be used for arbitrary metadata, and this is heavily used by Xen.
Let's implement something similar for the generic EFI zboot format. This removes the need for per-arch hacks to inject symbols, and makes a future alignment of EFI zboot with x86 more feasible as well.
So switch to the ELF format for the EFI zboot payload, but implement it in such a way that decompressing the entire ELF image is unnecessary. Instead, decompress the ELF file header and program headers first, and discard any file data that is not covered by a PT_LOAD program header (and therefore not part of the executable's memory image).
The latter approach permits EFI zboot to be used with unstripped ELF binaries, making EFI zboot suitable for future use as a hybrid bootable image and debug symbol library for the running kernel.
Ard Biesheuvel (4):
efi/libstub: Avoid legacy decompressor zlib/zstd wrappers efi/zboot: Add support for ELF payloads arm64/boot: Populate vmlinux ELF program headers efi/arm64: Use ELF payload for EFI zboot
arch/arm64/boot/Makefile | 4 - arch/arm64/include/asm/efi.h | 2 +- arch/arm64/kernel/image-vars.h | 4 - arch/arm64/kernel/vmlinux.lds.S | 33 ++-- drivers/firmware/efi/libstub/Makefile | 9 +- drivers/firmware/efi/libstub/Makefile.zboot | 6 + drivers/firmware/efi/libstub/arm64-stub.c | 2 +- drivers/firmware/efi/libstub/arm64.c | 20 +-- drivers/firmware/efi/libstub/efistub.h | 9 ++ drivers/firmware/efi/libstub/zboot-decompress-gzip.c | 77 ++++++++++ drivers/firmware/efi/libstub/zboot-decompress-zstd.c | 91 +++++++++++ drivers/firmware/efi/libstub/zboot-decompress.c | 161 ++++++++++++++++++++ drivers/firmware/efi/libstub/zboot.c | 58 ++----- drivers/firmware/efi/libstub/zboot.lds | 7 +- 14 files changed, 391 insertions(+), 92 deletions(-) create mode 100644 drivers/firmware/efi/libstub/zboot-decompress-gzip.c create mode 100644 drivers/firmware/efi/libstub/zboot-decompress-zstd.c create mode 100644 drivers/firmware/efi/libstub/zboot-decompress.c
base-commit: 78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
RFC PATCH 1/4 efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
From: Ard Biesheuvel <[email protected]>
Remove the dependency on the decompression wrappers used by the legacy decompressor, which do some odd things like providing a barebones malloc() implementation. Instead, implement GZIP deflate and ZSTD decompression in terms of the underlying libraries.
--- drivers/firmware/efi/libstub/Makefile | 7 +- drivers/firmware/efi/libstub/efistub.h | 3 + drivers/firmware/efi/libstub/zboot-decompress-gzip.c | 66 ++++++++++++++++ drivers/firmware/efi/libstub/zboot-decompress-zstd.c | 81 ++++++++++++++++++++ drivers/firmware/efi/libstub/zboot.c | 51 ++---------- drivers/firmware/efi/libstub/zboot.lds | 1 + 6 files changed, 163 insertions(+), 46 deletions(-)
drivers/firmware/efi/libstub/Makefile +6 -1
@@ -89,7 +89,12 @@ lib-$(CONFIG_LOONGARCH) += loongarch.o loongarch-stub.o CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) -zboot-obj-$(CONFIG_RISCV) := lib-clz_ctz.o lib-ashldi3.o +zboot-obj-y := zboot-decompress-gzip.o +CFLAGS_zboot-decompress-gzip.o += -I$(srctree)/lib/zlib_inflate +zboot-obj-$(CONFIG_KERNEL_ZSTD) := zboot-decompress-zstd.o lib-xxhash.o +CFLAGS_zboot-decompress-zstd.o += -I$(srctree)/lib/zstd + +zboot-obj-$(CONFIG_RISCV) += lib-clz_ctz.o lib-ashldi3.o lib-$(CONFIG_EFI_ZBOOT) += zboot.o $(zboot-obj-y) lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o
drivers/firmware/efi/libstub/efistub.h +3 -0
@@ -1232,4 +1232,7 @@ void process_unaccepted_memory(u64 start, u64 end);void accept_memory (phys_addr_t start,unsigned long size);void arch_accept_memory (phys_addr_t start,phys_addr_t end); +efi_status_t efi_zboot_decompress_init (unsigned long *alloc_size); +efi_status_t efi_zboot_decompress (u8 *out,unsigned long outlen); +#endif
drivers/firmware/efi/libstub/zboot-decompress-gzip.c new file +66 -0
66 lines not on this page · raw message
drivers/firmware/efi/libstub/zboot-decompress-zstd.c new file +81 -0
81 lines not on this page · raw message
drivers/firmware/efi/libstub/zboot.c +6 -45
86 lines not on this page · raw message
drivers/firmware/efi/libstub/zboot.lds +1 -0
@@ -17,6 +17,7 @@ SECTIONS .rodata : ALIGN(8) { __efistub__gzdata_start = .; *(.gzdata) + __efistub_payload_size = . - 4; __efistub__gzdata_end = .; *(.rodata* .init.rodata* .srodata*)
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Re: [RFC PATCH 1/4] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
Hi,
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Remove the dependency on the decompression wrappers used by the legacy decompressor, which do some odd things like providing a barebones
malloc()implementation. Instead, implement GZIP deflate and ZSTD decompression in terms of the underlying libraries.Signed-off-by Ard Biesheuvel <[email protected]>
With this patch in linux-next, my loongarch boot tests with qemu no longer boot. Log message is:
qemu log:
EFI stub: Decompressing Linux Kernel...
EFI stub: EFI_RNG_PROTOCOL unavailable
EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path EFI stub: Exiting boot services
... and then there is nothing until I abort the emulation.
Reverting this patch results in a build failure, so I awas not able to test it. Bisect results are atatched for reference.
Guenter
---
# bad: [37136bf5c3a6f6b686d74f41837a6406bec6b7bc] Add linux-next specific files for 20250113
# good: [9d89551994a430b50c4fffcb1e617a057fa76e20] Linux 6.13-rc6
git bisect start 'next-20250113' 'v6.13-rc6'
# good: [25dcaaf9b3bdaa117b8eb722ebde76ec9ed30038] Merge branch 'main' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
git bisect good 25dcaaf9b3bdaa117b8eb722ebde76ec9ed30038
# good: [c6ab5ee56509953c3ee6647ac9f266a7c628f082] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux.git
git bisect good c6ab5ee56509953c3ee6647ac9f266a7c628f082
# good: [37b72ff92ef30c021dca27cc5673d8c4bad49f8b] Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
git bisect good 37b72ff92ef30c021dca27cc5673d8c4bad49f8b
# good: [be5db029f3b05a02234a4b1530c0b3cdaf974718] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git
git bisect good be5db029f3b05a02234a4b1530c0b3cdaf974718
# good: [6071064d2ffec442f437277f7d411839b4898a77] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching
git bisect good 6071064d2ffec442f437277f7d411839b4898a77
# bad: [7a7dd09ee43911c0c1f4cc65bcef2aa6482f0e91] Merge branch 'rust-next' of https://github.com/Rust-for-Linux/linux.git
git bisect bad 7a7dd09ee43911c0c1f4cc65bcef2aa6482f0e91
# good: [f97b043bb40f86c715a50ba415d7fcdbed926b78] Merge branch 'zstd-next' of https://github.com/terrelln/linux.git
git bisect good f97b043bb40f86c715a50ba415d7fcdbed926b78
# bad: [dd60abee3f85689f8a6b5c817ed7f7dcc56ef822] Merge branch 'slab/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git
git bisect bad dd60abee3f85689f8a6b5c817ed7f7dcc56ef822
# bad: [6f18bb40970790b176a7aede3f1054fa7b9aa718] efi: sysfb_efi: fix W=1 warnings when EFI is not set
git bisect bad 6f18bb40970790b176a7aede3f1054fa7b9aa718
# bad: [9e45f9e16bc4d8fa963399808463d0f478e01911] efi/libstub: Simplify GOP handling code
git bisect bad 9e45f9e16bc4d8fa963399808463d0f478e01911
# bad: [7f0158f3ee12403c26e815c9df4f00d41ee3bb41] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
git bisect bad 7f0158f3ee12403c26e815c9df4f00d41ee3bb41
# good: [ec4696925da6b9baec38345184403ce9e29a2e48] efi/libstub: Bump up EFI_MMAP_NR_SLACK_SLOTS to 32
git bisect good ec4696925da6b9baec38345184403ce9e29a2e48
# first bad commit: [7f0158f3ee12403c26e815c9df4f00d41ee3bb41] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
Ard Biesheuvel
maintainerRe: [RFC PATCH 1/4] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
Quoted 22 lines · Guenter Roeck
Hi,
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Remove the dependency on the decompression wrappers used by the legacy decompressor, which do some odd things like providing a barebones
malloc()implementation. Instead, implement GZIP deflate and ZSTD decompression in terms of the underlying libraries.Signed-off-by Ard Biesheuvel <[email protected]>With this patch in linux-next, my loongarch boot tests with qemu no longer boot. Log message is:
qemu log:
EFI stub: Decompressing Linux Kernel...
EFI stub:EFI_RNG_PROTOCOLunavailable
EFI stub: Loaded initrd fromLINUX_EFI_INITRD_MEDIA_GUIDdevice path EFI stub: Exiting boot services
Quoted 5 lines
... and then there is nothing until I abort the emulation.
Reverting this patch results in a build failure, so I awas not able to test it. Bisect results are atatched for reference.
Thanks for the report - I'll drop the patch for now, and try again next cycle.
Ard Biesheuvel
maintainerRe: [RFC PATCH 1/4] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
Quoted 24 lines · Ard Biesheuvel
Quoted 22 lines · Guenter Roeck
Hi,
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Remove the dependency on the decompression wrappers used by the legacy decompressor, which do some odd things like providing a barebones
malloc()implementation. Instead, implement GZIP deflate and ZSTD decompression in terms of the underlying libraries.Signed-off-by Ard Biesheuvel <[email protected]>With this patch in linux-next, my loongarch boot tests with qemu no longer boot. Log message is:
qemu log:
EFI stub: Decompressing Linux Kernel...
EFI stub:EFI_RNG_PROTOCOLunavailable
EFI stub: Loaded initrd fromLINUX_EFI_INITRD_MEDIA_GUIDdevice path EFI stub: Exiting boot services
Quoted 7 lines
Quoted 5 lines
... and then there is nothing until I abort the emulation.
Reverting this patch results in a build failure, so I awas not able to test it. Bisect results are atatched for reference.
Thanks for the report - I'll drop the patch for now, and try again next cycle.
Mind sharing your config/firmware/command line details? I'm failing to reproduce the issue.
Re: [RFC PATCH 1/4] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
Quoted 27 lines · Ard Biesheuvel
Quoted 26 lines · Ard Biesheuvel
Quoted 24 lines · Guenter Roeck
Hi,
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Remove the dependency on the decompression wrappers used by the legacy decompressor, which do some odd things like providing a barebones
malloc()implementation. Instead, implement GZIP deflate and ZSTD decompression in terms of the underlying libraries.Signed-off-by Ard Biesheuvel <[email protected]>With this patch in linux-next, my loongarch boot tests with qemu no longer boot. Log message is:
qemu log:
EFI stub: Decompressing Linux Kernel...
EFI stub:EFI_RNG_PROTOCOLunavailable
EFI stub: Loaded initrd fromLINUX_EFI_INITRD_MEDIA_GUIDdevice path EFI stub: Exiting boot services... and then there is nothing until I abort the emulation.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Reverting this patch results in a build failure, so I awas not able to test it. Bisect results are atatched for reference.
Thanks for the report - I'll drop the patch for now, and try again next cycle.
Mind sharing your config/firmware/command line details? I'm failing to reproduce the issue.
qemu-system-loongarch64 -M virt -cpu \
la464 -kernel arch/loongarch/boot/vmlinuz.efi -smp 2 \
-no-reboot -m 4G -initrd rootfs.cpio \
-bios QEMU_EFI-loongarch64.fd \
--append "panic=-1 kunit.stats_enabled=2 kunit.filter=speed>slow rdinit=/sbin/init console=ttyS0,115200 earlycon=uart8250,mmio,0x1fe001e0,115200n8" \
-nographic -serial stdio -monitor noneqemu version is 9.1. The EFI image is at
https://github.com/groeck/linux-build-test/blob/master/rootfs/firmware/QEMU_EFI-loongarch64.fd
and the initrd is at
https://github.com/groeck/linux-build-test/blob/master/rootfs/loongarch/rootfs.cpio.gz
Configuration is defconfig with various debug options enabled.
I'll be happy to make a test directory available with all information needed if that helps. Please let me know.
Thanks,
Guenter
Ard Biesheuvel
maintainerRe: [RFC PATCH 1/4] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
Quoted 50 lines · Guenter Roeck
Quoted 27 lines · Ard Biesheuvel
Quoted 26 lines · Ard Biesheuvel
Quoted 24 lines · Guenter Roeck
Hi,
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Remove the dependency on the decompression wrappers used by the legacy decompressor, which do some odd things like providing a barebones
malloc()implementation. Instead, implement GZIP deflate and ZSTD decompression in terms of the underlying libraries.Signed-off-by Ard Biesheuvel <[email protected]>With this patch in linux-next, my loongarch boot tests with qemu no longer boot. Log message is:
qemu log:
EFI stub: Decompressing Linux Kernel...
EFI stub:EFI_RNG_PROTOCOLunavailable
EFI stub: Loaded initrd fromLINUX_EFI_INITRD_MEDIA_GUIDdevice path EFI stub: Exiting boot services... and then there is nothing until I abort the emulation.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Reverting this patch results in a build failure, so I awas not able to test it. Bisect results are atatched for reference.
Thanks for the report - I'll drop the patch for now, and try again next cycle.
Mind sharing your config/firmware/command line details? I'm failing to reproduce the issue.
qemu-system-loongarch64 -M virt -cpu \ la464 -kernel arch/loongarch/boot/vmlinuz.efi -smp 2 \ -no-reboot -m 4G -initrd rootfs.cpio \ -bios QEMU_EFI-loongarch64.fd \ --append "panic=-1 kunit.stats_enabled=2 kunit.filter=speed>slow rdinit=/sbin/init console=ttyS0,115200 earlycon=uart8250,mmio,0x1fe001e0,115200n8" \ -nographic -serial stdio -monitor noneqemu version is 9.1. The EFI image is at
https://github.com/groeck/linux-build-test/blob/master/rootfs/firmware/QEMU_EFI-loongarch64.fd
and the initrd is at
https://github.com/groeck/linux-build-test/blob/master/rootfs/loongarch/rootfs.cpio.gz
Quoted 5 lines
Configuration is defconfig with various debug options enabled.
I'll be happy to make a test directory available with all information needed if that helps. Please let me know.
Everything works fine with my distro QEMU:
$ qemu-system-loongarch64 --version QEMU emulator version 8.2.4 (Debian 1:8.2.4+ds-1+build1) Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
and it doesn't matter if I use your firmware or my own (grabbed randomly from [0])
When I build QEMU from source (stable-9.2), things still work happily if I use that same firmware. With your firmware, my QEMU 9.2 is completely dead.
Where did you find that image? I tried rebuilding it myself from a recent EDK2 base, but that doesn't work at all either.
Ard Biesheuvel
maintainerRe: [RFC PATCH 1/4] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
Quoted 67 lines · Ard Biesheuvel
Quoted 50 lines · Guenter Roeck
Quoted 27 lines · Ard Biesheuvel
Quoted 26 lines · Ard Biesheuvel
Quoted 24 lines · Guenter Roeck
Hi,
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Remove the dependency on the decompression wrappers used by the legacy decompressor, which do some odd things like providing a barebones
malloc()implementation. Instead, implement GZIP deflate and ZSTD decompression in terms of the underlying libraries.Signed-off-by Ard Biesheuvel <[email protected]>With this patch in linux-next, my loongarch boot tests with qemu no longer boot. Log message is:
qemu log:
EFI stub: Decompressing Linux Kernel...
EFI stub:EFI_RNG_PROTOCOLunavailable
EFI stub: Loaded initrd fromLINUX_EFI_INITRD_MEDIA_GUIDdevice path EFI stub: Exiting boot services... and then there is nothing until I abort the emulation.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Reverting this patch results in a build failure, so I awas not able to test it. Bisect results are atatched for reference.
Thanks for the report - I'll drop the patch for now, and try again next cycle.
Mind sharing your config/firmware/command line details? I'm failing to reproduce the issue.
qemu-system-loongarch64 -M virt -cpu \ la464 -kernel arch/loongarch/boot/vmlinuz.efi -smp 2 \ -no-reboot -m 4G -initrd rootfs.cpio \ -bios QEMU_EFI-loongarch64.fd \ --append "panic=-1 kunit.stats_enabled=2 kunit.filter=speed>slow rdinit=/sbin/init console=ttyS0,115200 earlycon=uart8250,mmio,0x1fe001e0,115200n8" \ -nographic -serial stdio -monitor noneqemu version is 9.1. The EFI image is at
https://github.com/groeck/linux-build-test/blob/master/rootfs/firmware/QEMU_EFI-loongarch64.fd
and the initrd is at
https://github.com/groeck/linux-build-test/blob/master/rootfs/loongarch/rootfs.cpio.gzQuoted 5 lines
Configuration is defconfig with various debug options enabled.
I'll be happy to make a test directory available with all information needed if that helps. Please let me know.
Everything works fine with my distro QEMU:
$ qemu-system-loongarch64 --version QEMU emulator version 8.2.4 (Debian 1:8.2.4+ds-1+build1) Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developersand it doesn't matter if I use your firmware or my own (grabbed randomly from [0])
Quoted 8 lines
When I build QEMU from source (stable-9.2), things still work happily if I use that same firmware. With your firmware, my QEMU 9.2 is completely dead.
Where did you find that image? I tried rebuilding it myself from a recent EDK2 base, but that doesn't work at all either.
... actually, turns out I built the wrong platform. If I build
OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc
from the EDK2 repository, I can boot the kernel with my change applied, using your command line.
Perhaps I should try your .config as well?
Re: [RFC PATCH 1/4] efi/libstub: Avoid legacy decompressor zlib/zstd wrappers
On 1/14/25 07:38, Ard Biesheuvel wrote:
...
Quoted 9 lines
Quoted 9 lines
Everything works fine with my distro QEMU:
$ qemu-system-loongarch64 --version QEMU emulator version 8.2.4 (Debian 1:8.2.4+ds-1+build1) Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developersand it doesn't matter if I use your firmware or my own (grabbed randomly from [0])
Quoted 7 lines
Quoted 7 lines
When I build QEMU from source (stable-9.2), things still work happily if I use that same firmware. With your firmware, my QEMU 9.2 is completely dead.
Where did you find that image? I tried rebuilding it myself from a recent EDK2 base, but that doesn't work at all either.
I built it myself sometime in 2023 (when working images were not available anywhere). It has debugging disabled and is much faster than other versions because of that.
Quoted 10 lines
Quoted 1 line
... actually, turns out I built the wrong platform. If I build
OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc
from the EDK2 repository, I can boot the kernel with my change applied, using your command line.
Perhaps I should try your .config as well?
Please see http://server.roeck-us.net/qemu/loongarch/
staging: My EFI version, the version from [0], and the version from qemu 9.2 work fine.
next: My version hangs. The version from [0] crashes:
EFI stub: EFI_RNG_PROTOCOL unavailable
EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path EFI stub: Exiting boot services
PROGRESS CODE: V03101019 I0
!!!! LoongArch64 Exception Type - 08(#ADE - Address error exception) !!!!
Zero - 0x0000000000000000, RA - 0x900000016D817264, TP - 0x900000016E3AC000, SP - 0x900000016E3AFE70 A0 - 0x9000000170430000, A1 - 0x900000016C200000, A2 - 0x0000000003CD0000, A3 - 0x9000000170430000 A4 - 0x0000000000000000, A5 - 0x0000000000000003, A6 - 0x0000026713E4D52C, A7 - 0x0000000000000001 T0 - 0x000000000000004D, T1 - 0x900000016DE0B118, T2 - 0x5453502039333A33, T3 - 0x0000000000000007 T4 - 0x0000000000000006, T5 - 0x900000016D8801CE, T6 - 0x0000000000000007, T7 - 0x0000000000000002 T8 - 0x0000000000000001, R21 - 0x0000000000000000, FP - 0x0000000000000000, S0 - 0x9000000170430000 S1 - 0x900000016C200000, S2 - 0x0000000004230000, S3 - 0x900000000E166018, S4 - 0x900000016E3EF000 S5 - 0x900000016F214448, S6 - 0x000000000A45D000, S7 - 0x000000000F467D30, S8 - 0x0000000000000000
CRMD - 0x00000000000000B0, PRMD - 0x0000000000000000, EUEN - 0x0000000000000000, MISC - 0x0000000000000000 ECFG - 0x0000000000000800, ESTAT - 0x0000000000480000, ERA - 0x900000016D7FE2F0, BADV - 0x0000000000000000 BADI - 0x000000002900008C
!!!! Can't find image information. !!!!
The efi image from qemu 9.2 crashes with:
EFI stub: Decompressing Linux Kernel...
ConvertPages: range 200000 - 3ECFFFF covers multiple entries
EFI stub: EFI_RNG_PROTOCOL unavailable
EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path
EFI stub: Exiting boot services
PROGRESS CODE: V03101019 I0
SetUefiImageMemoryAttributes - 0x000000000E2E0000 - 0x0000000000040000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000E240000 - 0x0000000000040000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000E1A0000 - 0x0000000000040000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000E0F0000 - 0x0000000000040000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000E050000 - 0x0000000000040000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000DEB0000 - 0x0000000000050000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000DD10000 - 0x0000000000040000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000DC70000 - 0x0000000000040000 (0x0000000000000008) SetUefiImageMemoryAttributes - 0x000000000DBD0000 - 0x0000000000040000 (0x0000000000000008)
!!!! LoongArch64 Exception Type - 08(#ADE - Address error exception) !!!!
Zero - 0x0000000000000000, RA - 0x900000016D817264, TP - 0x900000016E3AC000, SP - 0x900000016E3AFE70 A0 - 0x9000000170380000, A1 - 0x900000016C200000, A2 - 0x0000000003CD0000, A3 - 0x9000000170380000 A4 - 0x0000000000000000, A5 - 0x0000000000000001, A6 - 0x0000000000000053, A7 - 0x600000000000007E T0 - 0x000000000000004D, T1 - 0x900000016DE0B118, T2 - 0x5453502039333A33, T3 - 0x0000000000000007 T4 - 0x0000000000000006, T5 - 0x900000016D8801F6, T6 - 0x0000000000000007, T7 - 0x0000000000000000 T8 - 0x0000000000000000, R21 - 0x0000000000000000, FP - 0x00000000000B2298, S0 - 0x9000000170380000 S1 - 0x900000016C200000, S2 - 0x0000000004180000, S3 - 0x900000000E146018, S4 - 0x900000016E3EF000 S5 - 0x900000016F214448, S6 - 0x000000000A42D000, S7 - 0x00000000000B2950, S8 - 0x0000000000000010
CRMD - 0x00000000000000B0, PRMD - 0x0000000000000000, EUEN - 0x0000000000000000, MISC - 0x0000000000000000 ECFG - 0x0000000000000800, ESTAT - 0x0000000000480000, ERA - 0x900000016D7FE2F0, BADV - 0x0000000000000000 BADI - 0x000000002900008C
!!!! Find image based on IP(0x6D7FE2F0) (No PDB) (ImageBase=900000016C200000, EntryPoint=900000016D86E5E8) !!!!
Guenter
RFC PATCH 2/4 efi/zboot: Add support for ELF payloads
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Some architectures (such as x86) embed the ELF build of vmlinux in the decompressor, and this is relied upon by, e.g., the Xen loader, which uses the ELF notes to find the various entrypoints into the executable.
Implement support for this in EFI zboot, but avoid the need to decompress the entire ELF image, and instead, use the PT_LOAD headers to selectively decompress those slices of the the payload that are actually part of the memory image.
--- arch/arm64/include/asm/efi.h | 2 +- drivers/firmware/efi/libstub/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile.zboot | 6 + drivers/firmware/efi/libstub/arm64-stub.c | 2 +- drivers/firmware/efi/libstub/arm64.c | 16 +- drivers/firmware/efi/libstub/efistub.h | 8 +- drivers/firmware/efi/libstub/zboot-decompress-gzip.c | 25 ++- drivers/firmware/efi/libstub/zboot-decompress-zstd.c | 26 +++- drivers/firmware/efi/libstub/zboot-decompress.c | 161 ++++++++++++++++++++ drivers/firmware/efi/libstub/zboot.c | 9 +- 10 files changed, 223 insertions(+), 34 deletions(-)
arch/arm64/include/asm/efi.h +1 -1
@@ -103,7 +103,7 @@ static inline unsigned long efi_get_kimg_min_align(void)#define EFI_ALLOC_ALIGN SZ_64K#define EFI_ALLOC_LIMIT ((1UL << 48) - 1) -extern unsigned long primary_entry_offset (void ); +extern unsigned long entry_offset (void );/* * On ARM systems, virtually remapped UEFI runtime services are set up in two
drivers/firmware/efi/libstub/Makefile +1 -1
@@ -95,7 +95,7 @@ zboot-obj-$(CONFIG_KERNEL_ZSTD) := zboot-decompress-zstd.o lib-xxhash.o CFLAGS_zboot-decompress-zstd.o += -I$(srctree)/lib/zstd zboot-obj-$(CONFIG_RISCV) += lib-clz_ctz.o lib-ashldi3.o -lib-$(CONFIG_EFI_ZBOOT) += zboot.o $(zboot-obj-y) +lib-$(CONFIG_EFI_ZBOOT) += zboot.o zboot-decompress.o $(zboot-obj-y) lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o
drivers/firmware/efi/libstub/Makefile.zboot +6 -0
@@ -8,9 +8,15 @@ quiet_cmd_copy_and_pad = PAD $@ cmd_copy_and_pad = cp $< $@; \ truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@ +ifneq ($(EFI_ZBOOT_PAYLOAD),) # Pad the file to the size of the uncompressed image in memory, including BSS $(obj)/vmlinux.bin: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE $(call if_changed,copy_and_pad) +else +$(obj)/vmlinux.bin: OBJCOPYFLAGS := -R .note -R .note.gnu.build-id -R .comment -S +$(obj)/vmlinux.bin: vmlinux FORCE + $(call if_changed,objcopy) +endif # in GZIP, the appended le32 carrying the uncompressed size is part of the # format, but in other cases, we just append it at the end for convenience,
drivers/firmware/efi/libstub/arm64-stub.c +1 -1
@@ -45,7 +45,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, asmlinkage void primary_entry(void); -unsigned long primary_entry_offset (void ) +unsigned long entry_offset (void ) {/* * When built as part of the kernel, the EFI stub cannot branch to the
drivers/firmware/efi/libstub/arm64.c +2 -14
@@ -100,7 +100,7 @@ void efi_cache_sync_image(unsigned long image_base,/* only perform the cache maintenance if needed for I/D coherency */ if (!(ctr &BIT (CTR_EL0_IDC_SHIFT ))) {unsigned long base = image_base; -unsigned long size = code_size; +unsigned long size = alloc_size; do { asm("dc " DCTYPE ", %0" :: "r"(base));
@@ -116,24 +116,12 @@ void efi_cache_sync_image(unsigned long image_base,efi_remap_image (image_base, alloc_size, code_size); } -unsigned long __weak primary_entry_offset (void ) -{ -/* -* By default, we can invoke the kernel via the branch instruction in -* the image header, so offset #0. This will be overridden by the EFI -* stub build that is linked into the core kernel, as in that case, the -* image header may not have been loaded into memory, or may be mapped -* with non-executable permissions. -*/ -return 0 ; -} -void __noreturn efi_enter_kernel (unsigned long entrypoint,unsigned long fdt_addr,unsigned long fdt_size) {void (*__noreturn enter_kernel)(u64 ,u64 ,u64 ,u64 ); - enter_kernel = (void *)entrypoint +primary_entry_offset (); + enter_kernel = (void *)entrypoint +entry_offset ();enter_kernel (fdt_addr,0 ,0 ,0 ); }
drivers/firmware/efi/libstub/efistub.h +7 -1
@@ -1232,7 +1232,13 @@ void process_unaccepted_memory(u64 start, u64 end);void accept_memory (phys_addr_t start,unsigned long size);void arch_accept_memory (phys_addr_t start,phys_addr_t end); -efi_status_t efi_zboot_decompress_init (unsigned long *alloc_size); +efi_status_t efi_zboot_decompress_init (unsigned long *alloc_size, +unsigned long *entry);efi_status_t efi_zboot_decompress (u8 *out,unsigned long outlen); +bool efi_zboot_check_header (unsigned long *alloc_size, +unsigned long *entry); +bool efi_zboot_decompress_segments (u8 *out,unsigned long outlen); +bool efi_zboot_decompress_slice (u8 *out,unsigned long outlen); +#endif
drivers/firmware/efi/libstub/zboot-decompress-gzip.c +18 -7
@@ -12,11 +12,11 @@#include "inflate.c" extern unsigned char _gzdata_start[], _gzdata_end[]; -extern u32 __aligned(1) payload_size;static struct z_stream_s stream; -efi_status_t efi_zboot_decompress_init (unsigned long *alloc_size) +efi_status_t efi_zboot_decompress_init (unsigned long *alloc_size, +unsigned long *entry) {efi_status_t status;int rc;
@@ -38,14 +38,18 @@ efi_status_t efi_zboot_decompress_init(unsigned long *alloc_size) goto out; } - *alloc_size = payload_size; +if (!efi_zboot_check_header (alloc_size, entry)) { + status =EFI_LOAD_ERROR ; + goto out; + } +return EFI_SUCCESS ; out:efi_free (zlib_inflate_workspacesize (), (unsigned long )stream.workspace);return status; } -efi_status_t efi_zboot_decompress (u8 *out,unsigned long outlen) +bool efi_zboot_decompress_slice (u8 *out,unsigned long outlen) {int rc;
@@ -53,12 +57,19 @@ efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen) stream.avail_out = outlen; rc =zlib_inflate (&stream,0 ); -zlib_inflateEnd (&stream); +return rc ==Z_OK || rc ==Z_STREAM_END ; +} + +efi_status_t efi_zboot_decompress (u8 *out,unsigned long outlen) +{ +bool ret =efi_zboot_decompress_segments (out, outlen); + +zlib_inflateEnd (&stream);efi_free (zlib_inflate_workspacesize (), (unsigned long )stream.workspace); -if (rc !=Z_STREAM_END ) { -efi_err ("GZIP decompression failed with status %d\n" , rc); +if (!ret) { +efi_err ("GZIP decompression failed\n" );return EFI_LOAD_ERROR ; }
drivers/firmware/efi/libstub/zboot-decompress-zstd.c +18 -8
@@ -9,14 +9,14 @@#include "efistub.h" extern unsigned char _gzdata_start[], _gzdata_end[]; -extern u32 __aligned(1) payload_size;static ZSTD_inBuffer zstd_buf;static ZSTD_DStream *dstream;static size_t wksp_size;static void *wksp; -efi_status_t efi_zboot_decompress_init (unsigned long *alloc_size) +efi_status_t efi_zboot_decompress_init (unsigned long *alloc_size, +unsigned long *entry) {zstd_frame_header header;efi_status_t status;
@@ -51,29 +51,39 @@ efi_status_t efi_zboot_decompress_init(unsigned long *alloc_size) goto out; } - *alloc_size = payload_size; +if (!efi_zboot_check_header (alloc_size, entry)) { + status =EFI_LOAD_ERROR ; + goto out; + } +return EFI_SUCCESS ; out:efi_free (wksp_size, (unsigned long )wksp);return status; } -efi_status_t efi_zboot_decompress (u8 *out,unsigned long outlen) +bool efi_zboot_decompress_slice (u8 *out,unsigned long outlen) {ZSTD_outBuffer zstd_dec;size_t ret; -int retval; zstd_dec.dst = out; zstd_dec.pos =0 ; zstd_dec.size = outlen; ret =zstd_decompress_stream (dstream, &zstd_dec, &zstd_buf); + +return zstd_get_error_code (ret) ==0 ; +} + +efi_status_t efi_zboot_decompress (u8 *out,unsigned long outlen) +{ +bool ret =efi_zboot_decompress_segments (out, outlen); +efi_free (wksp_size, (unsigned long )wksp); - retval =zstd_get_error_code (ret); -if (retval) { -efi_err ("ZSTD-decompression failed with status %d\n" , retval); +if (!ret) { +efi_err ("ZSTD-decompression failed\n" );return EFI_LOAD_ERROR ; }
drivers/firmware/efi/libstub/zboot-decompress.c new file +161 -0
161 lines not on this page · raw message
drivers/firmware/efi/libstub/zboot.c +8 -1
@@ -31,6 +31,13 @@ struct screen_info *alloc_screen_info(void)return __alloc_screen_info (); } +static unsigned long entrypoint; + +unsigned long entry_offset (void ) +{ +return entrypoint; +} + asmlinkage efi_status_t __efiapiefi_zboot_entry (efi_handle_t handle,efi_system_table_t *systab) {
@@ -54,7 +61,7 @@ efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)efi_info ("Decompressing Linux Kernel...\n" ); - status =efi_zboot_decompress_init (&alloc_size); + status =efi_zboot_decompress_init (&alloc_size, &entrypoint);if (status !=EFI_SUCCESS )return status;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
RFC PATCH 3/4 arm64/boot: Populate vmlinux ELF program headers
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
In order to be able to use the ELF vmlinux image as the [zboot compressed] boot image, populate the program headers explicitly to describe text+rodata+inittext as R-X and initdata+data+bss as RW-.
--- arch/arm64/kernel/vmlinux.lds.S | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-)
arch/arm64/kernel/vmlinux.lds.S +22 -11
@@ -59,6 +59,7 @@ #define RO_EXCEPTION_TABLE_ALIGN 4 #define RUNTIME_DISCARD_EXIT +#define LOAD_OFFSET KIMAGE_VADDR #include <asm-generic/vmlinux.lds.h> #include <asm/cache.h>
@@ -70,7 +71,9 @@ #include "image.h" OUTPUT_ARCH(aarch64) -ENTRY(_text) +ENTRY(elf_entry) + +elf_entry = ABSOLUTE(primary_entry - KIMAGE_VADDR); jiffies = jiffies_64;
@@ -150,6 +153,11 @@ PECOFF_FILE_ALIGNMENT = 0x200; #define PECOFF_EDATA_PADDING #endif +PHDRS { + text PT_LOAD FLAGS(5); /* R_X */ + data PT_LOAD FLAGS(6); /* RW_ */ +} + SECTIONS { /*
@@ -166,10 +174,10 @@ SECTIONS . = KIMAGE_VADDR; - .head.text : { + .head.text : AT (0x0) { _text = .; HEAD_TEXT - } + } :text .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */ _stext = .; /* Text and read-only data */ IRQENTRY_TEXT
@@ -248,10 +256,6 @@ SECTIONS __inittext_end = .; __initdata_begin = .; - init_idmap_pg_dir = .; - . += INIT_IDMAP_DIR_SIZE; - init_idmap_pg_end = .; - .init.data : { INIT_DATA INIT_SETUP(16)
@@ -259,13 +263,18 @@ SECTIONS CON_INITCALL INIT_RAM_FS *(.init.altinstructions .init.bss) /* from the EFI stub */ - } + } :data .exit.data : { EXIT_DATA } RUNTIME_CONST_VARIABLES + . = ALIGN(PAGE_SIZE); + init_idmap_pg_dir = .; + . += INIT_IDMAP_DIR_SIZE; + init_idmap_pg_end = .; + PERCPU_SECTION(L1_CACHE_BYTES) HYPERVISOR_PERCPU_SECTION
@@ -325,10 +334,12 @@ SECTIONS init_pg_end = .; /* end of zero-init region */ - . += SZ_4K; /* stack for the early C runtime */ - early_init_stack = .; + .early_init_stack : { + . += SZ_4K; /* stack for the early C runtime */ + early_init_stack = .; - . = ALIGN(SEGMENT_ALIGN); + . = ALIGN(SEGMENT_ALIGN); + } __pecoff_data_size = ABSOLUTE(. - __initdata_begin); _end = .;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
RFC PATCH 4/4 efi/arm64: Use ELF payload for EFI zboot
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Instead of a raw binary executable, embed an ELF build of the core kernel into the EFI zboot image. Given that the memory layout of the kernel executable is described by ELF program headers, this removes the need to rely on symbols injected into the build to describe things like the size of the text area, which are not accessible to other consumers of the EFI zboot format, e.g., the kexec loader.
Given that the EFI zboot loader only decompresses those parts of the payload covered by PT_LOAD program headers, stripping the encapsulated ELF image is not strictly necessary, making the EFI zboot format suitable for distributing the bootable image and the debug symbols in a single compressed image.
--- arch/arm64/boot/Makefile | 4 ---- arch/arm64/kernel/image-vars.h | 4 ---- drivers/firmware/efi/libstub/arm64.c | 4 ---- drivers/firmware/efi/libstub/zboot.lds | 6 ------ 4 files changed, 18 deletions(-)
arch/arm64/boot/Makefile +0 -4
@@ -46,12 +46,8 @@ $(obj)/Image.xz: $(obj)/Image FORCE $(obj)/image.fit: $(obj)/Image $(obj)/dts/dtbs-list FORCE $(call if_changed,fit) -EFI_ZBOOT_PAYLOAD := Image EFI_ZBOOT_BFD_TARGET := elf64-littleaarch64 EFI_ZBOOT_MACH_TYPE := ARM64 EFI_ZBOOT_FORWARD_CFI := $(CONFIG_ARM64_BTI_KERNEL) -EFI_ZBOOT_OBJCOPY_FLAGS = --add-symbol zboot_code_size=0x$$( \ - $(NM) vmlinux|grep _kernel_codesize|cut -d' ' -f1) - include $(srctree)/drivers/firmware/efi/libstub/Makefile.zboot
arch/arm64/kernel/image-vars.h +0 -4
@@ -140,8 +140,4 @@ KVM_NVHE_ALIAS(kvm_protected_mode_initialized);#endif /* CONFIG_KVM */ -#ifdef CONFIG_EFI_ZBOOT -_kernel_codesize =ABSOLUTE (__inittext_end - _text); -#endif -#endif /* __ARM64_KERNEL_IMAGE_VARS_H */
drivers/firmware/efi/libstub/arm64.c +0 -4
@@ -88,8 +88,6 @@ efi_status_t check_platform_features(void)#define DCTYPE "cvau"#endif -u32 __weak code_size; -void efi_cache_sync_image (unsigned long image_base,unsigned long alloc_size) {
@@ -112,8 +110,6 @@ void efi_cache_sync_image(unsigned long image_base, asm("ic ialluis" );dsb (ish);isb (); - -efi_remap_image (image_base, alloc_size, code_size); } void __noreturn efi_enter_kernel(unsigned long entrypoint,
drivers/firmware/efi/libstub/zboot.lds +0 -6
@@ -2,8 +2,6 @@ ENTRY(__efistub_efi_zboot_header); -PROVIDE(zboot_code_size = ABSOLUTE(0)); - SECTIONS { .head : ALIGN(4096) {
@@ -21,10 +19,6 @@ SECTIONS __efistub__gzdata_end = .; *(.rodata* .init.rodata* .srodata*) - . = ALIGN(4); - __efistub_code_size = .; - LONG(zboot_code_size); - _etext = ALIGN(4096); . = _etext; }
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Hi,
So this boots in my test environments, but has the usual set of issues around various user-space utilities not recognizing it.
A couple things to think about:
Should the PE header 'zimg' type (or something else in the header) be tweaked so that the payload PE vs ELF can be detected before the image is decompressed? Right now for example, kexec-tools decompresses the image and then tosses it because the resulting decompressed image isn't understood as a loadable kernel. This is a trivial fix, but if in the future the plan is to be able to load these images directly by kexec_file_load() ideally kexec would know this before it attempts to decompress the image.
I think this needs a Kconfig entry to enable/disable it until all the userspace tools have been updated.
Thanks!
Quoted 70 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
The EFI zboot image format was introduced to provide a way to distribute an EFI bootable image for architectures such as arm64, RISC-V and Loongarch supporting both compression and EFI secure boot signing.
To make this format easy to digest for other consumers than EFI firmware (e.g., qemu or kexec), the file header describes the compression type and the offset and size of the compressed image inside the file. Additional metadata of the payload is currently injected using ELF symbols (currently, the size of the executable image's code region on arm64), but this information is not accessible to other consumers unless it is exposed either via the header, or via the payload itself.
It would be better to have a structured format inside the container, so that any annotation can be added without the need to tweak the EFI zboot header layout. On x86, the legacy decompressor encapsulates an ELF image, so that ELF notes can be used for arbitrary metadata, and this is heavily used by Xen.
Let's implement something similar for the generic EFI zboot format. This removes the need for per-arch hacks to inject symbols, and makes a future alignment of EFI zboot with x86 more feasible as well.
So switch to the ELF format for the EFI zboot payload, but implement it in such a way that decompressing the entire ELF image is unnecessary. Instead, decompress the ELF file header and program headers first, and discard any file data that is not covered by a
PT_LOADprogram header (and therefore not part of the executable's memory image).The latter approach permits EFI zboot to be used with unstripped ELF binaries, making EFI zboot suitable for future use as a hybrid bootable image and debug symbol library for the running kernel.
Cc Jeremy Linton <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Pingfan Liu <[email protected]>Cc Dave Young <[email protected]>Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Mark Rutland <[email protected]>Cc Kees Cook <[email protected]>Ard Biesheuvel (4):
efi/libstub: Avoid legacy decompressor zlib/zstd wrappers efi/zboot: Add support for ELF payloads arm64/boot: Populate vmlinux ELF program headers efi/arm64: Use ELF payload for EFI zbootarch/arm64/boot/Makefile | 4 - arch/arm64/include/asm/efi.h | 2 +- arch/arm64/kernel/image-vars.h | 4 - arch/arm64/kernel/vmlinux.lds.S | 33 ++-- drivers/firmware/efi/libstub/Makefile | 9 +- drivers/firmware/efi/libstub/Makefile.zboot | 6 + drivers/firmware/efi/libstub/arm64-stub.c | 2 +- drivers/firmware/efi/libstub/arm64.c | 20 +-- drivers/firmware/efi/libstub/efistub.h | 9 ++ drivers/firmware/efi/libstub/zboot-decompress-gzip.c | 77 ++++++++++ drivers/firmware/efi/libstub/zboot-decompress-zstd.c | 91 +++++++++++ drivers/firmware/efi/libstub/zboot-decompress.c | 161 ++++++++++++++++++++ drivers/firmware/efi/libstub/zboot.c | 58 ++----- drivers/firmware/efi/libstub/zboot.lds | 7 +- 14 files changed, 391 insertions(+), 92 deletions(-)create mode 100644
drivers/firmware/efi/libstub/zboot-decompress-gzip.ccreate mode 100644drivers/firmware/efi/libstub/zboot-decompress-zstd.ccreate mode 100644drivers/firmware/efi/libstub/zboot-decompress.cbase-commit:
78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
Hi Ard,
Sorry to reply late. A new approach sprints to my mind, but I am not sure about its feasibility.
I sent out a RFC [1]. It can stick to our original goal: keep kernel code immutable from various PE format
https://lore.kernel.org/bpf/[email protected]/T/#u
Quoted 74 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
The EFI zboot image format was introduced to provide a way to distribute an EFI bootable image for architectures such as arm64, RISC-V and Loongarch supporting both compression and EFI secure boot signing.
To make this format easy to digest for other consumers than EFI firmware (e.g., qemu or kexec), the file header describes the compression type and the offset and size of the compressed image inside the file. Additional metadata of the payload is currently injected using ELF symbols (currently, the size of the executable image's code region on arm64), but this information is not accessible to other consumers unless it is exposed either via the header, or via the payload itself.
It would be better to have a structured format inside the container, so that any annotation can be added without the need to tweak the EFI zboot header layout. On x86, the legacy decompressor encapsulates an ELF image, so that ELF notes can be used for arbitrary metadata, and this is heavily used by Xen.
Let's implement something similar for the generic EFI zboot format. This removes the need for per-arch hacks to inject symbols, and makes a future alignment of EFI zboot with x86 more feasible as well.
So switch to the ELF format for the EFI zboot payload, but implement it in such a way that decompressing the entire ELF image is unnecessary. Instead, decompress the ELF file header and program headers first, and discard any file data that is not covered by a
PT_LOADprogram header (and therefore not part of the executable's memory image).The latter approach permits EFI zboot to be used with unstripped ELF binaries, making EFI zboot suitable for future use as a hybrid bootable image and debug symbol library for the running kernel.
Cc Jeremy Linton <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Pingfan Liu <[email protected]>Cc Dave Young <[email protected]>Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Mark Rutland <[email protected]>Cc Kees Cook <[email protected]>Ard Biesheuvel (4):
efi/libstub: Avoid legacy decompressor zlib/zstd wrappers efi/zboot: Add support for ELF payloads arm64/boot: Populate vmlinux ELF program headers efi/arm64: Use ELF payload for EFI zbootarch/arm64/boot/Makefile | 4 - arch/arm64/include/asm/efi.h | 2 +- arch/arm64/kernel/image-vars.h | 4 - arch/arm64/kernel/vmlinux.lds.S | 33 ++-- drivers/firmware/efi/libstub/Makefile | 9 +- drivers/firmware/efi/libstub/Makefile.zboot | 6 + drivers/firmware/efi/libstub/arm64-stub.c | 2 +- drivers/firmware/efi/libstub/arm64.c | 20 +-- drivers/firmware/efi/libstub/efistub.h | 9 ++ drivers/firmware/efi/libstub/zboot-decompress-gzip.c | 77 ++++++++++ drivers/firmware/efi/libstub/zboot-decompress-zstd.c | 91 +++++++++++ drivers/firmware/efi/libstub/zboot-decompress.c | 161 ++++++++++++++++++++ drivers/firmware/efi/libstub/zboot.c | 58 ++----- drivers/firmware/efi/libstub/zboot.lds | 7 +- 14 files changed, 391 insertions(+), 92 deletions(-) create mode 100644 drivers/firmware/efi/libstub/zboot-decompress-gzip.c create mode 100644 drivers/firmware/efi/libstub/zboot-decompress-zstd.c create mode 100644 drivers/firmware/efi/libstub/zboot-decompress.cbase-commit:
78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8--
2.47.1.613.gc27f4b7a9f-goog