Skip to contentSkip to conversation

igvm: add command line parameter support

PATCH In review Luigi Leonardi 2 participants 5 messages Oct 19 – Oct 21

lore
Share & tools
lore
#0 lore raw

v3 cover igvm: add command line parameter support

---
Changes in v3:
- Removed "kernel-style" from the property description and QAPI
doc [Stefano],
- Documented the cmdline property in qemu-options.hx [Stefano]
- New patch documenting the MADT, DEVICE_TREE and COMMAND_LINE
directives in docs/system/igvm.rst [Stefano]
- Link to v2: https://lore.kernel.org/qemu-devel/[email protected]

Changes in v2:
- Updated commit message and doc to make it clear that QEMU does not
need to parse this string [Markus]
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
Luigi Leonardi (2):
igvm: add command line parameter support
docs/system/igvm: document MADT, COMMAND_LINE and DEVICE_TREE directives

 backends/igvm-cfg.c            | 21 +++++++++++++++++++++
 backends/igvm.c                | 31 +++++++++++++++++++++++++++++++
 docs/system/igvm.rst           |  8 ++++++++
 include/system/igvm-internal.h |  5 +++++
 qapi/qom.json                  |  7 ++++++-
 qemu-options.hx                |  6 +++++-
 6 files changed, 76 insertions(+), 2 deletions(-)

---
base-commit: 9c88811b81a935a172c5c873b2ada2d9b38a5f74
change-id: 20260930-igvm_command_line-ccb5a0bddda0

Best regards,

Signature · 1 line
Luigi Leonardi <[email protected]>
#1 lore raw

PATCH v3 1/2 igvm: add command line parameter support

Add a "cmdline" property to the igvm-cfg object and a handler for the IGVM_VHT_COMMAND_LINE directive, which copies the string into the parameter area the directive points at.

The command line is passed to whatever software the IGVM file loads, such as an SVSM. For example, SVSM can use it to select the serial port it logs to.

---
 backends/igvm-cfg.c            | 21 +++++++++++++++++++++
 backends/igvm.c                | 31 +++++++++++++++++++++++++++++++
 include/system/igvm-internal.h |  5 +++++
 qapi/qom.json                  |  7 ++++++-
 qemu-options.hx                |  6 +++++-
 5 files changed, 68 insertions(+), 2 deletions(-)
backends/igvm-cfg.c +21 -0
index 935ba54f54..653f79bef5 100644
@@ -34,6 +34,19 @@ static void set_igvm(Object *obj, const char *value, Error **errp)
     igvm->filename = g_strdup(value);
 }
 
+static char *get_cmdline(Object *obj, Error **errp)
+{
+    IgvmCfg *igvm = IGVM_CFG(obj);
+    return g_strdup(igvm->cmdline);
+}
+
+static void set_cmdline(Object *obj, const char *value, Error **errp)
+{
+    IgvmCfg *igvm = IGVM_CFG(obj);
+    g_free(igvm->cmdline);
+    igvm->cmdline = g_strdup(value);
+}
+
 static ResettableState *igvm_reset_state(Object *obj)
 {
     IgvmCfg *igvm = IGVM_CFG(obj);
@@ -85,6 +98,13 @@ static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
     object_class_property_set_description(oc, "file",
                                           "Set the IGVM filename to use");
 
+    object_class_property_add_str(oc, "cmdline", get_cmdline, set_cmdline);
+    object_class_property_set_description(oc, "cmdline",
+                                          "Set the command line for the "
+                                          "software loaded from the IGVM "
+                                          "file (copied verbatim, not "
+                                          "parsed by QEMU)");
+
     igvmc->process = qigvm_process_file;
 
     rc->get_state = igvm_reset_state;
@@ -112,4 +132,5 @@ static void igvm_cfg_finalize(Object *obj)
         igvm_free(igvm->file);
     }
     g_free(igvm->filename);
+    g_free(igvm->cmdline);
 }
backends/igvm.c +31 -0
index ec7bee428b..d059fee4d2 100644
@@ -158,6 +158,8 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,
 static int qigvm_initialization_guest_policy(QIgvm *ctx,
                                        const uint8_t *header_data,
                                        Error **errp);
+static int qigvm_directive_command_line(QIgvm *ctx, const uint8_t *header_data,
+                                        Error **errp);
 #ifdef CONFIG_FDT
 static int qigvm_directive_device_tree(QIgvm *ctx, const uint8_t *header_data,
                                        Error **errp);
@@ -192,6 +194,8 @@ static struct QIGVMHandler handlers[] = {
       qigvm_initialization_guest_policy },
     { IGVM_VHT_MADT, IGVM_HEADER_SECTION_DIRECTIVE,
       qigvm_directive_madt },
+    { IGVM_VHT_COMMAND_LINE, IGVM_HEADER_SECTION_DIRECTIVE,
+      qigvm_directive_command_line },
 #ifdef CONFIG_FDT
     { IGVM_VHT_DEVICE_TREE, IGVM_HEADER_SECTION_DIRECTIVE,
       qigvm_directive_device_tree },
@@ -851,6 +855,33 @@ static int qigvm_directive_snp_id_block(QIgvm *ctx, const uint8_t *header_data,
     return 0;
 }
 
+static int qigvm_directive_command_line(QIgvm *ctx, const uint8_t *header_data,
+                                        Error **errp)
+{
+    const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data;
+    const char *cmdline = ctx->cfg->cmdline ? ctx->cfg->cmdline : "";
+    uint8_t *param_data;
+    uint32_t param_size;
+    size_t cmdline_size = strlen(cmdline) + 1;
+
+    param_data = qigvm_get_param_data(ctx, param, &param_size, errp);
+    if (!param_data) {
+        return -1;
+    }
+
+    if (cmdline_size > param_size) {
+        error_setg(errp,
+                   "IGVM: command line size %zu exceeds the %u byte "
+                   "parameter area defined in IGVM file",
+                   cmdline_size, param_size);
+        return -1;
+    }
+
+    memcpy(param_data, cmdline, cmdline_size);
+
+    return 0;
+}
+
 #ifdef CONFIG_FDT
 static int qigvm_directive_device_tree(QIgvm *ctx, const uint8_t *header_data,
                                        Error **errp)
include/system/igvm-internal.h +5 -0
index b3b64cb584..b56a2e1254 100644
@@ -32,6 +32,11 @@ struct IgvmCfg {
      *           format.
      */
     char *filename;
+    /*
+     * cmdline: Command line for the software loaded from the IGVM file,
+     *          if it asks for one.
+     */
+    char *cmdline;
     IgvmHandle file;
     ResettableState reset_state;
     QTAILQ_HEAD(, IgvmMemoryRegion) memory_regions;
qapi/qom.json +6 -1
index 5895c97750..fe08d6d8f6 100644
@@ -1004,11 +1004,16 @@
 #
 # @file: IGVM file to use to configure guest
 #
+# @cmdline: command line for the software loaded from the IGVM file.
+#     Its format is specific to that software.  Passed verbatim: QEMU
+#     does not parse it.
+#     Ignored if the IGVM file does not ask for one.  (since 11.2)
+#
 # Since: 10.1
 ##
 { 'struct': 'IgvmCfgProperties',
   'if': 'CONFIG_IGVM',
-  'data': { 'file': 'str' } }
+  'data': { 'file': 'str', '*cmdline': 'str' } }
 
 ##
 # @SevCommonProperties:
qemu-options.hx +5 -1
index 2f6863180b..f72f30e246 100644
@@ -6496,7 +6496,7 @@ SRST
                  -machine ...,confidential-guest-support=tdx \\
                  ......
 
-    ``-object igvm-cfg,file=file``
+    ``-object igvm-cfg,file=file[,cmdline=string]``
         Create an IGVM configuration object that defines the initial state
         of the guest using a file in that conforms to the Independent Guest
         Virtual Machine (IGVM) file format.
@@ -6509,6 +6509,10 @@ SRST
         memory of the virtual machine and, depending on the platform, can
         define the initial processor state, memory map and parameters.
 
+        The optional ``cmdline`` parameter is a command line passed
+        verbatim to the software loaded from the IGVM file, if the file
+        requests one. Its format is specific to that software.
+
         The IGVM file is expected to contain the firmware for the virtual
         machine, therefore an ``igvm-cfg`` object cannot be provided along
         with other ways of specifying firmware, such as the ``-bios``
Signature · 1 line
2.56.0
Reviewed-by on v3 1/2
#2 lore raw
Quoted 10 lines · Luigi Leonardi

Add a "cmdline" property to the igvm-cfg object and a handler for the IGVM_VHT_COMMAND_LINE directive, which copies the string into the parameter area the directive points at.

The command line is passed to whatever software the IGVM file loads, such as an SVSM. For example, SVSM can use it to select the serial port it logs to.

Quoted 7 lines

---

backends/igvm-cfg.c            | 21 +++++++++++++++++++++
backends/igvm.c                | 31 +++++++++++++++++++++++++++++++
include/system/igvm-internal.h |  5 +++++
qapi/qom.json                  |  7 ++++++-
qemu-options.hx                |  6 +++++-
5 files changed, 68 insertions(+), 2 deletions(-)
#3 lore raw

PATCH v3 2/2 docs/system/igvm: document MADT, COMMAND_LINE and DEVICE_TREE directives

In reply to Luigi Leonardi

The MADT and DEVICE_TREE directives were added without updating the list of supported directives. Document them, together with the COMMAND_LINE directive added in the previous patch.

---
 docs/system/igvm.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
docs/system/igvm.rst +8 -0
index 9db8ae43d2..da1e965f54 100644
@@ -72,6 +72,14 @@ SEV-ES, SEV-SNP and non-confidential platforms.
    * - IGVM_VHT_ENVIRONMENT_INFO_PARAMETER
      - The ``memory_is_shared`` parameter is set to 1 in the guest parameter
        page.
+   * - IGVM_VHT_MADT
+     - The parameter area is populated with the ACPI MADT generated by QEMU.
+   * - IGVM_VHT_COMMAND_LINE
+     - The parameter area is populated with the ``cmdline`` property of the
+       ``igvm-cfg`` object, or an empty string if it is not set.
+   * - IGVM_VHT_DEVICE_TREE
+     - The parameter area is populated with the device tree generated by QEMU.
+       Only available when QEMU is built with FDT support.
 
 .. list-table:: Additional SEV, SEV-ES & SEV_SNP Supported Directives
    :widths: 25 75
Signature · 1 line
2.56.0
Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH v3 2/2] docs/system/igvm: document MADT, COMMAND_LINE and DEVICE_TREE directives

Quoted 9 lines · Luigi Leonardi

The MADT and DEVICE_TREE directives were added without updating the list of supported directives. Document them, together with the COMMAND_LINE directive added in the previous patch.

---
docs/system/igvm.rst | 8 ++++++++

1 file changed, 8 insertions(+)