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's code is unchanged from the last time I sent it [2], I've
simply rebased it on top of the latest commit at the time of this
writing (0e36779). I have not run it through the full test suite used
previously, but I have ensured that both PV and PVH bootloaders build
successfully and can boot an Arch Linux virtual machine on an Arch
Linux host.

Changes from the version 2 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).

[1] https://github.com/QubesOS/qubes-linux-pvgrub2/pull/16
[2] https://lists.gnu.org/archive/html/grub-devel/2025-06/msg00011.html

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

-- 
2.50.1

Attachment: pgpX3xHSMN_wg.pgp
Description: OpenPGP digital signature

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to