Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oMDZj-0003zo-7z for mharc-grub-devel@gnu.org; Thu, 11 Aug 2022 15:10:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMDZg-0003w2-Ib for grub-devel@gnu.org; Thu, 11 Aug 2022 15:10:32 -0400 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:47314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMDZe-0001QY-Q8 for grub-devel@gnu.org; Thu, 11 Aug 2022 15:10:32 -0400 Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) (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 7E6943FB95 for ; Thu, 11 Aug 2022 19:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1660245029; bh=Bku1QWFjoN5ugmM4WYD4XEpuzkdpLBaIxy3t9egl2dU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=veFCjXNrgHwp7PlSgIkzJ1re+NvzmQA+5bK55VyPrRJu1741Kv9qZA4nWt48kicLO xQrPFEYlXl+eblhmvpll7gZvsTjN+dUG8gELao8HH9V73nhzXtD47buRKu+O9Ww6yl otyi14ZjS5VXKq+vhPeQNJ2FVCN4Q3wVsqwV9o8zAn7c7nlZU/hdo1vEDp9e9VeY8p gi1AXSaOtPkhhO6F0e16UAXTa4THhlicoDpTnYx/NH5H/a0HI80ruPIzDLqP7qQhHO uAawwc29Q2L7FgDb/xfeSqbLxcdHX2812vvfAfAqrYgKCltXVezny8eiRbYoU97/KC zuY5JIfq7Gt0A== Received: by mail-ua1-f72.google.com with SMTP id o16-20020a9f3510000000b00384cbd2f765so3773417uao.2 for ; Thu, 11 Aug 2022 12:10:29 -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=3JrQX+bDLynRVtzi719yg0vS+TTJtMTjOGumUQNN/xNV3g08SRIjZtcll+5yPUh8aK dB2gEUEgrPHmtwWSyP63pqEKA25lXb9r0KNB46LmuIAIll5s7fhgxj6YZiJ5PbGJa99n 3KhJjQgpRJxwU8/gEvob5n3DlhCB+X5jcEn3kuOIihwEbzt3cK5S4WU+6GRxJ91VeGE/ YMrXTsFUyslmbwFI0bVUs3je3UAwYxHqCKIVLMQQodMsm4Pj8oEig0ZudozQ/yMahqkZ WVgIYOToyaA5H0RTMUrgAphQRiO3kgQCKs4ovJzI+3odmFEnvJvc+K2vrvgYUuXfT7nn lfxw== X-Gm-Message-State: ACgBeo2V8tSSqQg10KtcI4tFIR3LGwkyZIaNGcuWrVHSgkjNef4Yyo95 Yxu4TMy7JpkbPBM+RkN+5+msYTzCv434zNP5Bj8dA/dX+Bpc6Y6sARJL9zPP9T2uIXXWL5RX1WP 4gpd4nReMquoDg8TgarC7I5eZ6Luz X-Received: by 2002:a05:6102:238d:b0:388:b4aa:9f37 with SMTP id v13-20020a056102238d00b00388b4aa9f37mr343527vsr.31.1660245028264; Thu, 11 Aug 2022 12:10:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR7sJF0r7Bab4TEClDzx3QZJkVijmAqmhpwSOj/n3f6ue0JTLlUNFDAzWPlrmv2No7ACNyKt7g== X-Received: by 2002:a05:6102:238d:b0:388:b4aa:9f37 with SMTP id v13-20020a056102238d00b00388b4aa9f37mr343511vsr.31.1660245027975; Thu, 11 Aug 2022 12:10:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 12:10:27 -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 2/2] templates/linux_xen: Properly order the multiple initrd files Date: Thu, 11 Aug 2022 16:10:14 -0300 Message-Id: <20220811191014.139882-3-mfo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220811191014.139882-1-mfo@canonical.com> References: <20220811191014.139882-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: Thu, 11 Aug 2022 19:10:32 -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