Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oLArb-00088H-C8 for mharc-grub-devel@gnu.org; Mon, 08 Aug 2022 18:04:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLArZ-00086u-FX for grub-devel@gnu.org; Mon, 08 Aug 2022 18:04:41 -0400 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:56584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLArV-0005ac-BH for grub-devel@gnu.org; Mon, 08 Aug 2022 18:04:41 -0400 Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.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 B7D8F3F468 for ; Mon, 8 Aug 2022 22:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659996274; bh=Bku1QWFjoN5ugmM4WYD4XEpuzkdpLBaIxy3t9egl2dU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BcUT0nuUPrrA2ys9x42+aiAFV6TsU9pWz9CemvduCALbGO7XhwaSK749WWdO2xQuV JkkeugCPh74DiSbvzYJXrcgADycxPQx66tSDhWtH4VwKzkH86Kh9MXENnJgQx413ER M0z+xMhG9asZl3aAgmbJnhxTi1xN9YWBMOKhpk08INSUyDeIsLsOu75geG2D2+dNTt mxNMlV4oLYCgsl3FQAaQWdyaYBsMimP6T0Kg/fbtxpPV4CHP5d91A/9t7Zx7xOD/jM FS1JEgKwKzxeoZ22JoRtiDJfBgMiKS5m+rjX465dkKToVgv/kR87NhmRxYIE9cnhjH m4F++v0EK1j9A== Received: by mail-vs1-f71.google.com with SMTP id v67-20020a676146000000b0038899813921so1036073vsb.4 for ; Mon, 08 Aug 2022 15:04:34 -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:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Bku1QWFjoN5ugmM4WYD4XEpuzkdpLBaIxy3t9egl2dU=; b=CufzIFzavU3NoVyuRbaBfgSBHRc3U8iOahVteXK30Wwt4gcZQPcRDfFXx5xv+MX8Uw bSoHdBeSTmKNGRXLJ67JZoKkCT3gmevUmYEZdRBpEcW2WdeTnHQalyNKE1sww0z+8UIe UP33vDxvGwv4xHyH7/QEak0XJ+aVWubslWFlyvyhNmR/ZFeq3Bo9K4Vy6RbdaqX9yXsP wvx5JG4n7osaX6zeTjmgWJgIGp9MvStHHHEDqxOQHLgw5jOTIzP3hCgFjhP1iYQ0oGWu ecHNP8BuzbUVd1ficZa7EuyimV4pMM5t4R18mOS65juFZL9syp1vUf4DAsYjtguaReOS T/3A== X-Gm-Message-State: ACgBeo0gvCJWsbjJeMr+vNG1F0006KZnh7Z+fPiqabXd0JrOG2PTdGif SgPy4J/cqHd6IdJziUrF5izIypQN8MS/AEot7al6gJ+vIPdRBrhO16QgoMi5INoWLSEUBaeBqLq I8oOpv9xQva4rNtutQjEajtZhtP7p X-Received: by 2002:a67:ab4d:0:b0:357:8ef7:f421 with SMTP id k13-20020a67ab4d000000b003578ef7f421mr8681558vsh.6.1659996273375; Mon, 08 Aug 2022 15:04:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR6lSvYdqJvbRKYeMfYcns+HRWfwPFP5ayE0VS00Gt/MFXMm9R9HeHBaG0gsFvsGme7/XE47uA== X-Received: by 2002:a67:ab4d:0:b0:357:8ef7:f421 with SMTP id k13-20020a67ab4d000000b003578ef7f421mr8681547vsh.6.1659996273121; Mon, 08 Aug 2022 15:04:33 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 15:04:32 -0700 (PDT) From: Mauricio Faria de Oliveira To: grub-devel@gnu.org Cc: =?UTF-8?q?Peter=20Gro=C3=9Fe?= , Daniel Kiper Subject: [PATCH 2/2] templates/linux_xen: Properly order the multiple initrd files Date: Mon, 8 Aug 2022 19:04:25 -0300 Message-Id: <20220808220425.2544313-3-mfo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220808220425.2544313-1-mfo@canonical.com> References: <20220808220425.2544313-1-mfo@canonical.com> MIME-Version: 1.0 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:41 -0000 The linux_xen template orders the "early" initrd file(s) _first_ (i.e., before the "real" initrd files) and that seems reasonable, as microcode updates usually come first. However, this usually breaks Linux boot with initrd under Xen because Xen assumes the real initrd is the first multiboot[2] module after the kernel, passing its address over to Linux in Xen's start_info struct. So, if a microcode-only initrd (i.e., without init/userspace) is found by grub-mkconfig, it ends up considered as a normal initrd by the Linux kernel, which cannot do anything with it (as it has no other files) and panic()s unable to mount root if it depends on a initrd to do that (e.g., root=UUID=...). ... Well, since Xen doesn't actually use the provided microcode by default / unless the 'ucode=' option is enabled, this isn't used in the general case (and breaks). Additionally, if an user enables the 'ucode=' option, that either specifies which module is to be used for microcode, or scans all modules (regardless of being first) for that. Thus, for Xen: - it is *not required* to have microcode first, - but it is *required* to have real initrd first So, fix it by ordering the real initrd before early initrd(s). After: # touch /boot/xen /boot/microcode.cpio # 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 ... Corner case specific to Xen implementation details: It is actually _possible_ to have a microcode initrd first, but that requires a non-default option (so can't rely on it), and it turns out to be inconsistent with its counterpart (really shouldn't rely on it, as it may get confusing; below). 'ucode=1' does manually specify the first module is microcode _AND_ clears its bit in the module bitmap. The next module is now the 'new first', and gets passed to Linux as initrd. Good. 'ucode=scan' checks all modules for microcode, but does _NOT_ clear a bit if it finds one (reasonable, as it can find that prepended in a "real" initrd anyway, which needs to be used). The first module still gets passed to Linux as initrd. Bad. Fixes: e86f6aafb8de ("grub-mkconfig/20_linux_xen: Support multiple early initrd images") Signed-off-by: Mauricio Faria de Oliveira --- util/grub.d/20_linux_xen.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 50c62562b730..626aed40cbfd 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -307,7 +307,10 @@ for current_xen in ${reverse_sorted_xen_list}; do initrd= if test -n "${initrd_early}" || test -n "${initrd_real}"; then - initrd="${initrd_early} ${initrd_real}" + # Xen assumes the real initrd is the first module after the kernel. + # Additional (later) initrds can also be used for microcode update, + # with Xen option 'ucode= (non-default anyway). + initrd="${initrd_real} ${initrd_early}" initrd_display= for i in ${initrd}; do -- 2.34.1