Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oOgtq-0004hU-8I for mharc-grub-devel@gnu.org; Thu, 18 Aug 2022 10:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOgto-0004hD-ND for grub-devel@gnu.org; Thu, 18 Aug 2022 10:53:32 -0400 Received: from ams.source.kernel.org ([145.40.68.75]:57916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOgti-0001Bi-GF for grub-devel@gnu.org; Thu, 18 Aug 2022 10:53:28 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AF60AB821C8; Thu, 18 Aug 2022 14:53:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E39CC433D7; Thu, 18 Aug 2022 14:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660834402; bh=k8vyF2FBdOXl9Ni7aJ6ddq2+1AEu7XG7n19BHIldGGk=; h=From:To:Cc:Subject:Date:From; b=rDcAdmQMCiZfCs/9gA3aiTEbbI5YcoNqzwqpn92CApUTSMv2GD494EsEfkrKnOiA8 h5Ny1FXzjJPQnuyJiCjdGKvktqbi/m7fFR7/Zy9ctK1Wl3hk9FAv6qka0lX0YYTDb+ ldGpavcOQkrxAfRE3Us+jfh/Qh+TI0Y3oacBf5de3yw5wRwrHaFa0FqM8SYtCO8oVA p+Cp5hxU4WFdRPmOiafPIHrQ5wFS8IiCQlENbeBbkRAcXR6g1osLf8+L4vd6gmqlnx JXdiOFNIYoRw5c+9qblgiov1JzAAjfeNOSP0CEpMne05SvyuW6vUYxfElNADnZTve5 d+tb3W9K+HPcw== From: Ard Biesheuvel To: grub-devel@gnu.org Cc: Ard Biesheuvel , Daniel Kiper , Leif Lindholm , Nikita Ermakov , Atish Patra , Huacai Chen , Heinrich Schuchardt , dann frazier , Julian Andres Klode Subject: [PATCH v3 0/8] linux: implement LoadFile2 initrd loading Date: Thu, 18 Aug 2022 16:51:27 +0200 Message-Id: <20220818145135.2208251-1-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4621; i=ardb@kernel.org; h=from:subject; bh=k8vyF2FBdOXl9Ni7aJ6ddq2+1AEu7XG7n19BHIldGGk=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBi/lHjksrus+TCOdA243cWO5FedfS5eKGkUyF3F4EZ aT4WqGiJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYv5R4wAKCRDDTyI5ktmPJERyDA CX8st5wfbuh6KGHiJf5piZmY43FaTw8/u0RXfOKnazuRm906RNy8BxENe9S8nsVk8Mtybpyy5KFqBu TOuk22tnlDWb2e7YqS86h0jivLFa3Odej96Qb1OGfNACnvME8LeNcEx72WeQ5WX2LRKHNsVwqg2sq7 ZnVraCJsYNAyO5CLi84yAgAQT++qrCM+tN4P+q+Cu4ha9JGrg8lpN9xrguwz9cw8JHOYIHIBCGf6mp LBklEQWY1JfWcBohyW7atzkmVU4CKRkbjKE6KMv6VDy/0gwizNDye9cjA0J+WNBvbduWLHl0tBB9td o3BKoU6RNeQ13nGCVY8NyezUfplvTHRlsxVTNb4PfzZM3cO+wVDN0gbAjiZGeQsGRZpdeh7z1ZJsnO SKhZIDu0wKIQbeZSgPP6aI304fXksVZdxVIJVz+ivnnxmUAloBzNXlaZzlHpU5+U+UnekQ0FEnjS29 BgcAjL+jrz0QeX4zDum2+eovRWwnQ8/l1C2WaA/P44Fcc= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=145.40.68.75; envelope-from=ardb@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -71 X-Spam_score: -7.2 X-Spam_bar: ------- X-Spam_report: (-7.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2022 14:53:32 -0000 This implements the LoadFile2 initrd loading protocol, which is essentially a callback interface into the bootloader to load the initrd data into a caller provided buffer. This means the bootloader no longer has to contain any policy regarding where to load the initrd (which differs between architectures and kernel versions) and no longer has to manipulate arch specific data structures such as DT or struct bootparams to inform the OS where the initrd resides in memory. This is especially relevant for the upcoming LoongArch support, which does not use either DT or struct bootparams, and would have to rely on the initrd= command line interface, which is deprecated and of limited utility [0]. Sample output from booting a recent Linux/arm64 kernel: grub> insmod part_msdos grub> linux (hd0,msdos1)/Image grub> initrd (hd0,msdos1)/initrd.img grub> boot EFI stub: Booting Linux Kernel... EFI stub: EFI_RNG_PROTOCOL unavailable, KASLR will be disabled EFI stub: Generating empty DTB EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path EFI stub: Exiting boot services and installing virtual address map... [ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070] This is mostly a resend of my original v2 [1], although I did cherry-pick Nikita's version of the first patch, which incorporates Heinrich's suggestion to simply drop the argv[] argument from grub_initrd_load(). I also included the patch I sent out the other day to remove the pointless header magic number check, and included a fix for the PXE boot issue reported by dann [2]. Changes since v2: - incorporate some ancient feedback from Daniel that I never saw until today. (this is why I am sending two versions of the same series on the same day - apologies for the spam) [0] The initrd= command line loader can only access files that reside on the same volume as the loaded image, which means GRUB would have to present this volume abstraction in order to serve the initrd file. Another reason why this method is problematic is generic EFI zboot, which is being added to Linux, and which calls loadimage on another, embedded PE/COFF image which would also need to expose this volume abstraction. [1] https://lists.gnu.org/archive/html/grub-devel/2020-10/msg00124.html [2] https://lists.gnu.org/archive/html/grub-devel/2022-04/msg00055.html Cc: Daniel Kiper Cc: Leif Lindholm Cc: Nikita Ermakov Cc: Atish Patra Cc: Huacai Chen Cc: Heinrich Schuchardt Cc: dann frazier Cc: Julian Andres Klode Ard Biesheuvel (7): efi: move MS-DOS stub out of generic PE header definition arm64/linux: Remove magic number header field check linux/arm: unify ARM/arm64 vs Xen PE/COFF header handling linux/arm: account for COFF headers appearing at unexpected offsets efi/efinet: Don't close connections at fini_hw() time efi: implement LoadFile2 initrd loading protocol for Linux linux: ignore FDT unless we need to modify it Nikita Ermakov (1): loader: drop argv[] argument in grub_initrd_load() grub-core/commands/efi/lsefi.c | 1 + grub-core/kern/efi/efi.c | 5 +- grub-core/loader/arm/linux.c | 2 +- grub-core/loader/arm64/linux.c | 175 +++++++++++++++++--- grub-core/loader/arm64/xen_boot.c | 23 +-- grub-core/loader/efi/fdt.c | 7 +- grub-core/loader/i386/linux.c | 2 +- grub-core/loader/i386/pc/linux.c | 2 +- grub-core/loader/i386/xen.c | 3 +- grub-core/loader/ia64/efi/linux.c | 2 +- grub-core/loader/linux.c | 4 +- grub-core/loader/mips/linux.c | 2 +- grub-core/loader/powerpc/ieee1275/linux.c | 2 +- grub-core/loader/sparc64/ieee1275/linux.c | 2 +- grub-core/net/drivers/efi/efinet.c | 10 +- grub-core/net/net.c | 2 +- include/grub/arm/linux.h | 7 +- include/grub/arm64/linux.h | 5 +- include/grub/efi/api.h | 40 +++++ include/grub/efi/efi.h | 4 +- include/grub/efi/pe32.h | 5 +- include/grub/linux.h | 2 +- include/grub/net.h | 3 +- 23 files changed, 245 insertions(+), 65 deletions(-) -- 2.35.1