Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oMDZh-0003xP-F9 for mharc-grub-devel@gnu.org; Thu, 11 Aug 2022 15:10:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMDZf-0003rk-BL for grub-devel@gnu.org; Thu, 11 Aug 2022 15:10:31 -0400 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:47288) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMDZd-0001O9-2C for grub-devel@gnu.org; Thu, 11 Aug 2022 15:10:30 -0400 Received: from mail-ua1-f71.google.com (mail-ua1-f71.google.com [209.85.222.71]) (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 BBAC33FB94 for ; Thu, 11 Aug 2022 19:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1660245025; bh=WI3WTcluaX9QeWSCytatte5fzBb19E+aqsA1DyfB5WM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=U48L5BMbBrnYlC9xdaXn19AsptvPl/DSo6K/nR7lpBIsRSFeqOpzeWX2In69ia4yb 1jmh6UyVY+oAZDGD0v/xad3P9LIc8d6zuGbRZl/9D231WRCHJn7OCSQNVcMhd7HSqt Wnbk0cO0nDzHflfPdEgq0DFSkIiCz4F5MsW5Z/3SJkTJ7T7R+qcb2uSXMYMUr6+uOI GCM5Kkv0ZBBMzizhxuRto84LnTGeCXJbW62E8pmDlNqa28RLwPmxUrgF2tTLg2YEe/ DYzeaepHLNHjyljWlVjpCkKJCPZVdzwWtCeY2nJXxy5xH6bm1e/oahRCPzKpc+aSG3 vcvQ/UhyTnwTQ== Received: by mail-ua1-f71.google.com with SMTP id u43-20020a9f35ee000000b00383589e193aso3886010uad.14 for ; Thu, 11 Aug 2022 12:10:25 -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=WI3WTcluaX9QeWSCytatte5fzBb19E+aqsA1DyfB5WM=; b=b7QBGBnAJWZ/xLJWhknSWHubyhMapGQrmtQC3Z13hThjTkMCU1hxuVYwU6jGsDzfwP /Gj61GyPK2rKWF4K93f+uRnT2ZXfZdue7Q8CL8B3rpPRpP28Q+RFdS/K4Dkmy4msC6L+ 0j2QLv3mC+J8CgIgwXGMpARyjD9ne3+/NIq+hEiF6FVzKPMS8Xr7e7TKYtgo0v78YP/E LI1YHP71jUH0OXts6N4QryI94RNeiM/sjf0qg7qhSvoKILTto/WYut+cj9AqouF/4qXF dyWlRHXu4s/fyau8C3oteeZ7C4tsEA/Wol4skGKX4BzndF+A1YQlvmGQeX4JiL0mMG3C Qgwg== X-Gm-Message-State: ACgBeo2/vyHebe8EUxHtumg9ZVeoS311GGaMHRWfaZ/v9/fzrUIpWIIz D5NMotk0V/vWi2Hn8ITr0YAlj6pV70VokOetItb4Qs6R3FYQmfiGCl7WR4PqgvYrHfloxVUymdu C9UtUGpt2yKm/XozZFGeONghec+o6 X-Received: by 2002:a05:6102:748:b0:383:f58b:e1d1 with SMTP id v8-20020a056102074800b00383f58be1d1mr232970vsg.4.1660245024092; Thu, 11 Aug 2022 12:10:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR7+3e6BBFtoN2+LChsymM31WoFtOxj+BrpCOK6WyVItXRq5dZIBaMclDO82NnKHtiZC3BBg2Q== X-Received: by 2002:a05:6102:748:b0:383:f58b:e1d1 with SMTP id v8-20020a056102074800b00383f58be1d1mr232941vsg.4.1660245023802; Thu, 11 Aug 2022 12:10:23 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:4e1:83a2:2ee9:2118:a2dc:3dd6]) by smtp.gmail.com with ESMTPSA id g7-20020a67ea07000000b00384b60a5160sm120094vso.12.2022.08.11.12.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 12:10:23 -0700 (PDT) From: Mauricio Faria de Oliveira To: xen-devel@lists.xenproject.org, grub-devel@gnu.org Cc: Daniel Kiper , =?UTF-8?q?Peter=20Gro=C3=9Fe?= Subject: [PATCH 0/2] templates/linux_xen: Properly handle multiple initrd files Date: Thu, 11 Aug 2022 16:10:12 -0300 Message-Id: <20220811191014.139882-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: Thu, 11 Aug 2022 19:10:31 -0000 Adding the xen-devel list as requested in grub-devel [0]: On Thu, Aug 11, 2022 at 1:51 PM Daniel Kiper wrote: > In general patches LGTM. However, I would prefer to hear an opinion from Xen > folks too. So, please repost the patch set and add xen-devel@lists.xenproject.org > to the list of recipients. [0] https://lists.gnu.org/archive/html/grub-devel/2022-08/msg00115.html Thanks, Mauricio ... 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