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 87A85C5B543 for ; Thu, 5 Jun 2025 05:26:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uN37K-0000Pb-IE; Thu, 05 Jun 2025 01:26:18 -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 1uN37H-0000PF-Vt for grub-devel@gnu.org; Thu, 05 Jun 2025 01:26:16 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uN37G-0007HK-58 for grub-devel@gnu.org; Thu, 05 Jun 2025 01:26:15 -0400 Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-3ddc090d881so325815ab.3 for ; Wed, 04 Jun 2025 22:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749101171; x=1749705971; darn=gnu.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=T53+ijlXu/Jb/YRepw4rfUkWAWCFRGwzmhGhfqmrkf0=; b=jS0rsv1+qD5XghhDrgMBOLEW+d8F52QzFcs10f3TkwXevQXjB1RFDKhhB/m2aBjWHj gLnupwhqdjO3u+9bmrWwPjpfKtm604lYZvggQix2xq/CJ08E0Efp7ZUbJ7qEAHVb9ao5 mcKWwjBul1YC7thZ+/nEddicN3sFfqHu6NN1ZR3HJnKwMP3QW+8uwoSQSX+NPjWfMw9/ VhuxA3MSvAZcUlxNu8c+BmXFCsE7R57qjT5ShmEAGIaQE/OykfTz+KogE/seQtGd9yf2 B7FzrFzYF2geCjTeBTuo+qftnkeGU1qDJXKZNx40twX/SZW81lqp1i8N/86UETCfQAT9 aSYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749101171; x=1749705971; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=T53+ijlXu/Jb/YRepw4rfUkWAWCFRGwzmhGhfqmrkf0=; b=I9BwPIdTKY/EfVia9Wmo+UvjDJ2pLDYs2werCZOIWCM+A2DUF/HEmphNQHLiThobeM pImaodi9heDChL4umQdcWUKOlLs+FyB0k48+AUKeW2U6v30jnAHLZwelXMgZtS/xEuyL Ck2boJJ4eoC3v5IM1MZk6CnkV39U4p56nNKze12v1QqFRN4GAMA08BVZs3kwzvZ5Mt56 C9iFYyuZKxP9sKn4TP+8kinKZ126gfgTaFkC1qUd2GdCWxvQFACBnFp9Cc1oWrJvvyX5 ZUuWijSMnk1YQptnycoT9kAdNo/59MORfbUvO6vQO7W615Skx2Cz4JC5FEMIRq5Eu5NT 02YA== X-Gm-Message-State: AOJu0Yyb5I8rhvHuPgpPyojH/NrQYmPM1Lo86hz32ufH8N6RQK4IWJCG UCn1ah9axUfBPPd/fmy05bAdUiU0bf9I5/8JtEkSQRQHXqKN0QtLLE4njZFzDQ== X-Gm-Gg: ASbGncv5q7M436w9vIhut+OHs8w7Sl39RwGgA/MKv7h4DwIlwmN+15GA1uwTOandoh9 V0XF+BBgOuVNIuFBJWOc8OQl1LXLv4PDVgkPyB9UmKPc8Bz9zZoAeWNfhOjhnYNGVW9EyIjIVuR v28eRBcHdD4+fjP6bsu0XmGDNnnymSR8OAwc8Wolc4yi9bzErY2LRb60S58rWdrPkBwFWoMvQ6C sfZrp0CJiL/twU6D46SoNqTKz8Rm3V9Y7OdqcjL5t3NtrBeHqZ6rmK2vj2rKmC5iApLzd8/Yc4y 6Boh1FwRd168v1Z9fVN7TR0fcsw8+TloUvWUFPqpbVNkL1mlEOXCX3ycA5g= X-Google-Smtp-Source: AGHT+IEIEssQyYpJAI3uaYnFE/r+RIy7mtvyJO2hCXZ7dYai+czsg/AJDEmrM6oh2w1ZHJoQU/jxZQ== X-Received: by 2002:a05:6e02:12cc:b0:3dd:b7da:5254 with SMTP id e9e14a558f8ab-3ddbedae965mr16824255ab.7.1749101171227; Wed, 04 Jun 2025 22:26:11 -0700 (PDT) Received: from kf-m2g5 ([2607:fb91:729:c9c7:c3e2:180e:e54f:7b49]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ff1e5aee18sm2684590173.101.2025.06.04.22.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 22:26:10 -0700 (PDT) Date: Thu, 5 Jun 2025 00:26:01 -0500 From: Aaron Rainbolt To: grub-devel@gnu.org Cc: xen-devel@lists.xenproject.org, daniel.kiper@oracle.com, phcoder@gmail.com, marmarek@invisiblethingslab.com Subject: [PATCH v3 0/1] kern/xen: Add Xen command line parsing Message-ID: <20250605002601.73a34f9b@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::12d; envelope-from=arraybolt3@gmail.com; helo=mail-il1-x12d.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="===============8364478712660852992==" Errors-To: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org Sender: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org --===============8364478712660852992== Content-Type: multipart/signed; boundary="Sig_/ZF=r=FsOwGehNJsxTrAMV2o"; protocol="application/pgp-signature"; micalg=pgp-sha512 --Sig_/ZF=r=FsOwGehNJsxTrAMV2o 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 438f055). 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: * Implemented changes suggested by Marek from Invisible Things Lab, who reviewed an earlier version of the patch. Specifically: * Added minor optimizations (avoided needlessly calling grub_strlen in a loop, got rid of an unneeded variable, removed a redundant string length check) * Made a couple of bit setting and unsetting operations in the parser more readable * Removed a superfluous extra NUL terminator from a string literal 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). This is the same test suite used for version 2 of the patch. [1] https://github.com/QubesOS/qubes-linux-pvgrub2/pull/16 [2] https://bpa.st/5C7A 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 | 343 ++++++++++++++++++++++++++++++++++ include/grub/xen.h | 2 + 6 files changed, 423 insertions(+) create mode 100644 grub-core/kern/xen/cmdline.c --=20 2.49.0 --Sig_/ZF=r=FsOwGehNJsxTrAMV2o Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEudh48PFXwyPDa0wGpwkWDXPHkQkFAmhBKmkACgkQpwkWDXPH kQnGvQ//SdvF1dnEEjK7Y9/lSyC91a1q7JWPyHSodauHeEmHBz8X5JcvAhJB3eRz 7QVGnAa4cLeXAZtumPcxlFbHyBFVgRvSdoOMYNu02GB7kTWg/71tHVGZKgDDgjSi t7CNevsaKDy6BymJlMq8bLjbodxgE5qZ14kQ3SwPdQcSVRIpzSggTOOe1sIvYoWr B0/8mc67e3Lk4U7MtvcuG0PeBVRR64hxzjY/rxvqfyUUs9sYIVVNHiab2FWmvsmP sF3uTyYW4kuQjK3rpgmuQf2n8jGB8rD4TMoa6TkW5j+zw6a87ZeoeoxNcKW1HYzY QNEuQglgIK2lVX0ozWEqpUKK4EliSP1sylZFxfZETvvZZf3FkRddgpQ+O07l9V/j piMH5qjIslEK99uOQ3ZrqFfqhG7zLPekO1H8B5YhOcyjIw2p50HNMzaP5UkUyQJ1 Fx1p1n3JxRP/000gUfizisWZSxLNlYYuKok/dLgpWqudp3BqLjkixhFpDioADVgR KAqzo9Iync/AzIgP/A+Wy8Y+3vx2mDEMGgvTJsS8Q1+XP6FMQVACuF8lx/8TBBAb QyIep0+a3YkNbhfTMsKvnNY9gHFh+JOuMO+88z1VRlUkZAA9sSsj+qq60Eno6Zlo t5LVgs06I7VHhTdmhXdz1mhBgaOSSEt4QT3+VAuCVSecBhB3q0g= =lgoW -----END PGP SIGNATURE----- --Sig_/ZF=r=FsOwGehNJsxTrAMV2o-- --===============8364478712660852992== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============8364478712660852992==--