From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oWHcU-000808-4y for mharc-grub-devel@gnu.org; Thu, 08 Sep 2022 09:31:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oWHcG-0007tI-KI for grub-devel@gnu.org; Thu, 08 Sep 2022 09:30:48 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]:59806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oWHcE-00036a-HN for grub-devel@gnu.org; Thu, 08 Sep 2022 09:30:48 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8342461B51; Thu, 8 Sep 2022 13:30:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A73BAC433D6; Thu, 8 Sep 2022 13:30:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662643842; bh=2BzjO+dzcv5F215+93mf1Xff2OVO8e7VmTPhThJLlcQ=; h=From:To:Cc:Subject:Date:From; b=dZ4kJ2pekmnKCYGlRY9BqRYmzvGizz2Vv8Qe/NeJMAUySiZIKL2vDgHjfVwA0F+xh jZIjjeO9LgMEA7pu6ohxQwoeRbIeXsv99Lmc4YyioDyfVtVHWQh8lAfuv7y3mjMRv5 gJgoXLLApItPXwfBCUujTM37fWa2C7DXUaYjlvs791nJRMUm4kvcKI+OwfFckHtGvD SA/wXVdEyBUf93BDEUPyXZXLYKHc5q0mET4AtlB2oD4B+2609vvzLZ4G2MOqpI21AA bfXjBExc93dgoN03Esy4ZlZj4A9iMQeXb0CGQllNu9+BctJWT50M6GFId5njK4Ctzk 0MsC+RMH4LjPw== 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 , Ilias Apalodimas Subject: [PATCH v4 0/6] linux: implement LoadFile2 initrd loading Date: Thu, 8 Sep 2022 15:30:11 +0200 Message-Id: <20220908133017.1464494-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=3632; i=ardb@kernel.org; h=from:subject; bh=2BzjO+dzcv5F215+93mf1Xff2OVO8e7VmTPhThJLlcQ=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjGe5e1mY7gEBDGsoi90J7vbc7v3Zi2Ivn3rYJnx/Z LNv8d2qJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYxnuXgAKCRDDTyI5ktmPJBj4DA CJ4BAwPvNwEUk909mIKtOssMpsPe21MP2S9s+RNQ1jQSjYh+nv1OitrCwkpcg7estwgl633lzq4v+r fmP61Sdc0hnp7jDwzF93i/YhByzp7pUoyUEjnZDAL8fS5Tf88F8T1pK9vG8S5UQO5wIkkzjNfRQUe6 fo94XlWbXaaWxZZlX+JsohHhbrjeH43kYV+p4rki6exnXWYnpu1VmdWjny8M49qUueWdYN6t0Wy+4j 8moA+HU7H/MbGX3l0SD5sQ9mXkvNXGlbUmz/xY25mJkoyvahlJaiEyuA8sOm+1CPnKMsLMMFfuWA3y 2v1iUL3Wz8AgkOOh85zCn2yzIjrqBP0vKQztHpDfufJx+4TVuhN0a5DI6aTWmrYt8/eZiYtdz9cLzM cx5Fb0OsJMOxklQs48XEHH/NG31oWcc3j1+1tYjVsp28+6GC4OgT6oTSjrh/C0EmnPFRP0iO2baXJI AvyPvs5wRiNmt3nKK2exvnMcwO1ZQedYleZrPn+RYV+gA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=139.178.84.217; envelope-from=ardb@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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, 08 Sep 2022 13:30:48 -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] Changes since v3: - drop a couple of patches that have been merged independently in the meantime - update patch #1 to read the PE image header offset from the file instead of using the harcoded offset - add acks from Heinrich and Ilias 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. 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 Cc: Ilias Apalodimas Ard Biesheuvel (6): efi: move MS-DOS stub out of generic PE header definition 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 grub-core/commands/efi/lsefi.c | 1 + grub-core/kern/efi/efi.c | 8 +- grub-core/loader/arm64/linux.c | 172 ++++++++++++++++++-- grub-core/loader/arm64/xen_boot.c | 23 +-- grub-core/loader/efi/fdt.c | 7 +- grub-core/net/drivers/efi/efinet.c | 10 +- grub-core/net/net.c | 2 +- include/grub/arm/linux.h | 6 + include/grub/arm64/linux.h | 4 + include/grub/efi/api.h | 40 +++++ include/grub/efi/efi.h | 4 +- include/grub/efi/pe32.h | 16 +- include/grub/net.h | 3 +- 13 files changed, 248 insertions(+), 48 deletions(-) -- 2.35.1