Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F417CC5AD49 for ; Sat, 31 May 2025 00:53:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uLATV-0006R0-0z; Fri, 30 May 2025 20:53:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uLATQ-0006Qd-9O for grub-devel@gnu.org; Fri, 30 May 2025 20:53:21 -0400 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uLATO-0005cg-Fc for grub-devel@gnu.org; Fri, 30 May 2025 20:53:20 -0400 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-3dd755bc266so1675695ab.3 for ; Fri, 30 May 2025 17:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748652796; x=1749257596; darn=gnu.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=BbI37kxQG7vp7V0ecTz+o356PMVwkE8qF6C+9oXMa5E=; b=E7vWclO/bIj2tnzRdMW27uEzObzv6pyslbfmKbny9rxJuNQ2JVyB5jU/htmxWD1qL5 6qzVbs2NiJjcCA6JS2uVUeH9iPYVUD/fAwUwfaVIuoW7jTYJaY2Oc/5w2dhOhqlRWq0w fsJEgKrjWyHPRsLVATlI62OfV6xNKzzrGmqYbajdEEiYomdbqrJo6DDHo/2ByJhy/hmS 2gRqMqxVfe2brYlWDBCEuoCvVBTfICqNK2P5e+xN4UYxuOp/leI80dtr4pQyoJEOjWng XCeYAs87htO2ioVgntxd3/A2AzJStjglEthcdV7VhfJY38lQxFNIUO290RgPVoYhVhG6 8VOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748652796; x=1749257596; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=BbI37kxQG7vp7V0ecTz+o356PMVwkE8qF6C+9oXMa5E=; b=v0mE5CMU1pkvpsmixP+rs2xdp7qCjyP81WCiielbD4paZTjQOAOJ/293/RF4FfcUb3 lPcxrl3d9sRFJoyFQPaCegvAJ1Ivc6n1D2mAR7UYTWKqNqpT0FjQIdrTBkJkAQW56B9B /oAmLx88pvcujkO0FyKiq9NviWIkLy/09OR2pQk7Fgzzt3/IlA8Yrw+QRjTGn5lZyMec rl/+Pw0Zp7VKWZdIL7hRsLAkcu3F3r5gKJ9ZOysEnoRObPTNFBBabkMH61+drCy4fltl vNeSV52sVdUCvSOuzKvKtZtczBeSG8jViiZe6+qsGMcCCJ/wgdCZytbjmzw1T5qEXFbK v95w== X-Gm-Message-State: AOJu0YzCfrlZT/iiOW+BC4AtZRaSaYGBX2PX6vH+fvhHZP/W/s2MhsEl 42NVQcHOjg2GLcowuQv/Xve5UPQ6e6n/jiJrEwIUvnznqp0KJg1ggqblMHvHWA== X-Gm-Gg: ASbGncvCFQbGmC19vCFCnT+bu8uGPwBtCxSH1I5NCKO8lzEvKGBGJNFDVcbW8oUKq8T 5sd7Qnj0kmk6jJR6gha7yvAZCAnJIIyheP/eQfFWaGUuuZaXEinmkq1JA/OehTd+Cv89IEEFfnb EzlylZTh8YXAeOl1Xvmw9nqhOFt9pjq4pA0DnJvi4krilMR1Y3AYE9JunSdY5NZtrUt6spSv4h0 Q+IskHN80Zo8h3Y7VVrSGma5Vh/olTb2Kuxg5HbNHjpBdX0yWToA7IkoBLzcENgTGq3uJanAjDu 85ccmoxzVJ1TpaFp2Ezs7YWYT8JPSICnLa0JpWRFk6mmS5RIU9JuOjDoE0M= X-Google-Smtp-Source: AGHT+IFBp8jvSDh7cqJxttpiA7HS/7CdCn/3Aos/r+reLqDQMP2JD0NugBpqWmHlxR6RaVV0ItgB/A== X-Received: by 2002:a05:6e02:180a:b0:3d4:6d6f:6e1f with SMTP id e9e14a558f8ab-3dd99ca9400mr17312735ab.6.1748652796488; Fri, 30 May 2025 17:53:16 -0700 (PDT) Received: from kf-m2g5 ([2607:fb91:729:c9c7:4a01:2714:55f9:a90c]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3dd935288dbsm10137105ab.8.2025.05.30.17.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 17:53:15 -0700 (PDT) Date: Fri, 30 May 2025 19:53:06 -0500 From: Aaron Rainbolt To: grub-devel@gnu.org Cc: xen-devel@lists.xenproject.org, dkiper@net-space.pl, phcoder@gmail.com Subject: [PATCH v2 0/1] Xen: Add Xen command line parsing Message-ID: <20250530195306.41af4199@kf-m2g5> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::135; envelope-from=arraybolt3@gmail.com; helo=mail-il1-x135.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Reply-To: The development of GNU GRUB Content-Type: multipart/mixed; boundary="===============8567519050651204235==" Errors-To: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org Sender: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org --===============8567519050651204235== Content-Type: multipart/signed; boundary="Sig_/9Nfny_rgglLe_w6W9jAdx9J"; protocol="application/pgp-signature"; micalg=pgp-sha512 --Sig_/9Nfny_rgglLe_w6W9jAdx9J Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable The purpose of this patch is to allow the Xen hypervisor to pass extra data to GRUB in the form of a kernel command line, allowing the host to customize the boot process of the guest. The command line from Xen is parsed, and any variables within that start with the string `xen_grub_env_` are exposed as environment variables. The grub.cfg script can then use those environment variables as it sees fit. The main reason for doing this is to allow implementing boot modes in Qubes OS while also using in-VM kernels. For more context on Qubes boot modes, see [1]. In order for this to work with in-VM kernels, it is necessary for dom0 to pass kernel parameters to the guest without modifying the guest's grub.cfg manually. This patch allows this to be done, by allowing dom0 to pass kernel parameters to GRUB, which then provides them to grub.cfg as an environment variable. The grub.cfg script within the VM can then append those variables to the kernel command line. The patch has been tested with both PV and PVH virtual machines, using an otherwise unpatched GRUB source tree, building the patch on top of the tip of git master at the time of this writing (commit 73d1c95). My testing environment is a fully updated Arch Linux system with Xen built from the stable-4.20 branch. Changes from the previous version of the patch: * Added documentation for the future to the GRUB manual. * Fixed error checking when allocating memory. * Enhanced coding style, code efficiency, and comments based on Daniel Kiper's previous review and my own re-review. * Added an explicit null termination check on the Xen-provided kernel command line before parsing. * Fixed some memory management issues that could result in unnecessary memory consumption (one memory leak and a couple of places where an extra byte was allocated that didn't need to be). The patch has been thoroughly tested by booting a patched GRUB with various different parameters passed to it via the Xen-provided kernel command line. The effects of these parameters on the bootloader's environment were then tested, and then an Arch Linux image was booted to ensure that boot still worked. The full list of test cases and their results can be seen at [2] (pastebinned so as to not overload people's email clients with 185-character-long lines). [1] https://github.com/QubesOS/qubes-linux-pvgrub2/pull/16 [2] https://bpa.st/Z45A Aaron Rainbolt (1): kern/xen: Add Xen command line parsing docs/grub.texi | 50 +++++ grub-core/Makefile.core.def | 2 + grub-core/kern/i386/xen/pvh.c | 14 ++ grub-core/kern/main.c | 12 ++ grub-core/kern/xen/cmdline.c | 344 ++++++++++++++++++++++++++++++++++ include/grub/xen.h | 2 + 6 files changed, 424 insertions(+) create mode 100644 grub-core/kern/xen/cmdline.c --=20 2.49.0 --Sig_/9Nfny_rgglLe_w6W9jAdx9J Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEudh48PFXwyPDa0wGpwkWDXPHkQkFAmg6UvIACgkQpwkWDXPH kQkteA//ZYj9rrDDUrtS9Kt1C5YBArGy51VcG6GAZ6svAqiTdaiXpEDZYXhFC3m8 iBumFWNFxyf2o4Ngk9w3lrE2kIZFRh5ZAkpqxs1BcrAa0QojAcehW7RcVXBGd1GE CBxJeG1y3rQHZOePHzLfZEpYdlpaDkr5yd/0FsBEYdiWLODsnQxKf99I93rrXtg4 l1NxhUQyXurrSxqVZwa/KZxsx4TOVNIkIQPv6mIRwm4tGYubi+K+6a9/CwQ+l95+ K6/gi9jQyR6F92mLOGT4H4TU+z1QiBOv+p4BbbjLsxbeI4BjHp7LcE4AxZBGerS0 Vxubh+jgrnMmGmejYPK6hE6h8ElneEjfhYpI4Aye3UncSeURwAVHczhOSmwAfg/w lTBvF18NVIe0AA6chKMmhDFTB7K9a/rmLp8Onm0vDxRvsuR4Q8+CHXmiMvzAAtXZ iPD8gh9CsSWqdk78J4xUOzv9fg1fzzIx8gi4mrzKfcyaSF+KyECbO1kVxbVxF5Aw 6qw0rbNp67CoqQ2K8jql9en6OxjgGyjfgAeCFwRJ6Btn/nXAr5me3+3gEKFMdhSc pRhsPw0NeF0QMRC/rJMVPxwyK9G3ziJ/fot6ISIR2libbOAw4e57fiMJ+z6j4kTq f4RMyl8q+AwqSZH2l2hTZzNrGvM3v1ins6JYErTvK2q014lp8BY= =wxbL -----END PGP SIGNATURE----- --Sig_/9Nfny_rgglLe_w6W9jAdx9J-- --===============8567519050651204235== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============8567519050651204235==--