Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oLAre-0008Al-M4 for mharc-grub-devel@gnu.org; Mon, 08 Aug 2022 18:04:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLArX-00085m-9w for grub-devel@gnu.org; Mon, 08 Aug 2022 18:04:39 -0400 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:56570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLArV-0005aS-AZ for grub-devel@gnu.org; Mon, 08 Aug 2022 18:04:39 -0400 Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 0DFEB3F465 for ; Mon, 8 Aug 2022 22:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659996271; bh=kldukfmdYoEUCOZySTmwvjEQE3YioVAYarnXLotipdQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=OYti1/tM/NPecuITfa9d9SHC1WBeaShqedE0Ggz4E3eTPjJZL2i10e7cAw3GKSUjN zn6wm0r2agVI2u3G6cTf6+lRFMHKUgQ2PiGkG6peuQGixZOb9xkoY7FX6KoMrHv5NG aJkh0tiasZyNoYa4b4QawnplEtdbhvHaTcph66d03QQiyEXo0EGkeQRcI0Eo5nDrIQ o7cPO3zRar7qIydATLH87K3PCWviZ5t0q6UDyUUEhUZ46lmIUQE2Yp3VVP9A53ZFIw KWaWymBHDj3M0hEFaQNoPpG3seuQwdHIc/DJBRVRgHYNRNZTjI/nTawsWBuWqc90E9 ds4JrUPE16dGA== Received: by mail-vk1-f198.google.com with SMTP id d207-20020a1f1dd8000000b003790375c6b7so1265950vkd.8 for ; Mon, 08 Aug 2022 15:04:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=kldukfmdYoEUCOZySTmwvjEQE3YioVAYarnXLotipdQ=; b=HUa7g6j5rWXoWDoebsveblxIWIPzj5tNUpWgAroxF/NRGqKk6d2ge9TsN45htktkRD FLoglilvXZXCSLlDZwWdE/XLELJ4kLcgOGRdYUGTIHmyP5Yv48E7zmscJEkaHmYugU3e hE4KfgceTMGWiEGyh4vD16wUrmbjXDcBrSb740zpbf4OZuuCCDLdEROC/ZJS8BecT/n2 I4nqYKk9Bt3Y/E0OhGiTGIExnzfFKORIa1VeTHKplgJw+d7EDvjVrjv2LTYvBFPDqs2i kKsLr5xK/yee4d2Qmixi7iJQXH2XtlmwU9ibJdm10uzLAGxilFfY5SsYDjocDgg6KPlN 3Fvg== X-Gm-Message-State: ACgBeo1I4MlAFq93+1UcsejTPE7SO4n3+YenoC7iX3PEkFYSWcjFK3rV KEOoLVK42T7PtsUM9tnwOLy1pY2/mj8U26p1hnUBvcMQxy4MtxwAYhI8FFaaz/77RJV4HsZNEpE HkzXmxRhnCQOwm3XpnTZoJyWtWgMZ X-Received: by 2002:a67:1d03:0:b0:358:4217:a20d with SMTP id d3-20020a671d03000000b003584217a20dmr8901200vsd.70.1659996269447; Mon, 08 Aug 2022 15:04:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR4SALyStfN11bGbwZ6UyCSxMoOcm5sveOKHKta2oqvUc0OVnaryUB752nF8oGJUClSaTgclbg== X-Received: by 2002:a67:1d03:0:b0:358:4217:a20d with SMTP id d3-20020a671d03000000b003584217a20dmr8901191vsd.70.1659996269102; Mon, 08 Aug 2022 15:04:29 -0700 (PDT) Received: from mfo-t470.. ([2804:14c:4e1:83a2:57f5:8be0:d968:5770]) by smtp.gmail.com with ESMTPSA id a11-20020a1f980b000000b00377ada9f9f2sm9843448vke.1.2022.08.08.15.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 15:04:28 -0700 (PDT) From: Mauricio Faria de Oliveira To: grub-devel@gnu.org Cc: =?UTF-8?q?Peter=20Gro=C3=9Fe?= , Daniel Kiper Subject: [PATCH 0/2] templates/linux_xen: Properly handle multiple initrd files Date: Mon, 8 Aug 2022 19:04:23 -0300 Message-Id: <20220808220425.2544313-1-mfo@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=185.125.188.122; envelope-from=mfo@canonical.com; helo=smtp-relay-internal-0.canonical.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 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_MED=-2.3, 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: Mon, 08 Aug 2022 22:04:39 -0000 The linux_xen template seems to be broken for multiple initrd files. Linux fails to boot when it needs a real initrd but early/microcode initrd(s) are found by grub-mkconfig. Patch 1 allows initrd(s) other than the first early/microcode initrd to be loaded at all, fixing an implementation error for multiboot[2]. Patch 2 allows Linux to get the real initrd as initrd (vs. an early/ microcode-only initrd), thus being able to boot if it needs a initrd. Synthetic tests: --- # touch /boot/xen /boot/microcode.cpio Original: # grub-mkconfig 2>/dev/null | grep -P '^\t(multiboot|module)' multiboot /boot/xen ... module /boot/vmlinuz-5.4.0-122-generic ... module --nounzip /boot/microcode.cpio /boot/initrd.img-5.4.0-122-generic Patch 1: # grub-mkconfig 2>/dev/null | grep -P '^\t(multiboot|module)' multiboot /boot/xen ... module /boot/vmlinuz-5.4.0-122-generic ... module --nounzip /boot/microcode.cpio module --nounzip /boot/initrd.img-5.4.0-122-generic Patch 2: # grub-mkconfig 2>/dev/null | grep -P '^\t(multiboot|module)' multiboot /boot/xen ... module /boot/vmlinuz-5.4.0-122-generic ... module --nounzip /boot/initrd.img-5.4.0-122-generic module --nounzip /boot/microcode.cpio With fake multiboot2 header: # echo -en '\xd6\x50\x52\xe8\x00\x00\x00\x00' > /boot/xen # echo -en '\x00\x00\x00\x00\x2a\xaf\xad\x17' >> /boot/xen # echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' >> /boot/xen # echo -en '\x00\x00\x00\x00\x00\x00\x00\x00' >> /boot/xen # grub-file --is-x86-multiboot2 /boot/xen; echo $? 0 # grub-mkconfig 2>/dev/null | grep -P '^\t(multiboot|module)' multiboot2 /boot/xen ... module2 /boot/vmlinuz-5.4.0-122-generic ... module2 --nounzip /boot/initrd.img-5.4.0-122-generic module2 --nounzip /boot/microcode.cpio Regular tests: --- Debug patch: __start_xen() @ xen.git:xen/arch/x86/setup.c ... +for (i = 0; i < mbi->mods_count; i++) + printk("MODULE %d size %d string %s\n", + i, mod[i].mod_end - mod[i].mod_start, (char*)__va(mod[i].string)); + bitmap_fill(module_map, mbi->mods_count); __clear_bit(0, module_map); /* Dom0 kernel is always first */ For /boot/microcode.cpio: $ sudo apt install microcode-initrd # on Ubuntu $ du --bytes /boot/... 13660416 /boot/vmlinuz-5.4.0-122-generic 33062542 /boot/initrd.img-5.4.0-122-generic 5045248 /boot/microcode.cpio Original: (XEN) MODULE 0 size 13660416 string placeholder root=UUID=74dd579c-a377-487d-b8f7-bc7c6df13ba1 ro console=ttyS0 (XEN) MODULE 1 size 5045248 string /boot/initrd.img-5.4.0-122-generic ... [ 2.505207] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) Patch 1: (XEN) MODULE 0 size 13660416 string placeholder root=UUID=74dd579c-a377-487d-b8f7-bc7c6df13ba1 ro console=ttyS0 (XEN) MODULE 1 size 5045248 string (XEN) MODULE 2 size 33062542 string ... [ 1.890498] Freeing initrd memory: 4928K ... [ 2.710948] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) Patch 2: (XEN) MODULE 0 size 13660416 string placeholder root=UUID=74dd579c-a377-487d-b8f7-bc7c6df13ba1 ro console=ttyS0 (XEN) MODULE 1 size 33062542 string (XEN) MODULE 2 size 5045248 string ... [ 1.968578] Freeing initrd memory: 32288K ... [ 2.844889] Run /init as init process [ 2.916532] systemd-udevd[148]: Starting version 245.4-4ubuntu3.17 Xen code: --- Key code path for this patchset: @ xen.git:xen/arch/x86/setup.c: void __init noreturn __start_xen(unsigned long mbi_p) { ... unsigned int initrdidx, ... multiboot_info_t *mbi; module_t *mod; unsigned long ..., module_map[1]; ... mbi = __va(mbi_p); ... mod = __va(mbi->mods_addr); ... bitmap_fill(module_map, mbi->mods_count); __clear_bit(0, module_map); /* Dom0 kernel is always first */ ... microcode_grab_module(module_map, mbi); # ucode=number can __test_and_clear_bit(number, module_map), # ucode=scan can't. ... initrdidx = find_first_bit(module_map, mbi->mods_count); if ( bitmap_weight(module_map, mbi->mods_count) > 1 ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", initrdidx); ... /* * ... The second module, if present, is an initrd ramdisk. */ dom0 = create_dom0(mod, modules_headroom, initrdidx < mbi->mods_count ? mod + initrdidx : NULL, kextra, loader); ... Mauricio Faria de Oliveira (2): templates/linux_xen: Properly load multiple initrd files templates/linux_xen: Properly order the multiple initrd files util/grub.d/20_linux_xen.in | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) -- 2.34.1