[focal:linux-azure-cvm][PATCH 1/1] efi/x86: Only copy the compressed kernel image in efi_relocate_kernel()

Marcelo Henrique Cerri marcelo.cerri at canonical.com
Mon Jun 27 23:38:37 UTC 2022

From: Arvind Sankar <nivedita at alum.mit.edu>

BugLink: https://bugs.launchpad.net/bugs/1980023

The image_size argument to efi_relocate_kernel() is currently specified
as init_size, but this is unnecessarily large. The compressed kernel is
much smaller, in fact, its image only extends up to the start of _bss,
since at this point, the .bss section is still uninitialized.

Depending on compression level, this can reduce the amount of data
copied by 4-5x.

Signed-off-by: Arvind Sankar <nivedita at alum.mit.edu>
Link: https://lore.kernel.org/r/20201011142012.96493-1-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
(back ported from commit 688eb28211abdf82a3f51e8997f1c8137947227d)
[marcelo.cerri: replicate the same change in eboot.c instead because
 it was merged into libstub in 5.7 by c2d0b470154c]
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri at canonical.com>
 arch/x86/boot/compressed/eboot.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 82bc60c8acb2..59a5ea4f64f9 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -810,9 +810,11 @@ efi_main(struct efi_config *c, struct boot_params *boot_params)
 	 * address, relocate it.
 	if (hdr->pref_address != hdr->code32_start) {
+		extern char _bss[];
 		unsigned long bzimage_addr = hdr->code32_start;
 		status = efi_relocate_kernel(sys_table, &bzimage_addr,
-					     hdr->init_size, hdr->init_size,
+					     (unsigned long)_bss - bzimage_addr,
+					     hdr->init_size,

More information about the kernel-team mailing list