Skip to contentSkip to conversation

Introducing guest driven VM launch update mechanism (BYOF interface)

PATCH Superseded Ani Sinha 3 participants 19 messages Jun 24 – Jun 26 Arm/Amlogic Meson SoC support

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

cover Introducing guest driven VM launch update mechanism (BYOF interface)

This is the resurrection of the work that was previously discussed here:
https://lists.endsoftwarepatents.org/archive/html/qemu-devel/2025-03/msg05872.html

This relates to the 'bring your own firmware' work that we are driving at Red Hat, now with IGVM support.

The patchset includes a spec doc that has more details.

This patchset implements the hypervisor interface using fw-cfg. Using this interface, the guest can pass its own IGVM file to the hypervisor. Upon reset, the hypervisor re-initializes the guest using the IGVM file the guest provided. This is useful in order to have deterministic and trustworthy launch measurements, mostly for the cloud confidential guest deployments.

This patchset has added functional and unit tests that exercize the hypervisor interface. It has been tested for both confidential guests and non-confidential guests. Gerd has also independently tested the patchset.

CC Alex Graf <[email protected]>
CC Gerd Hoffman <[email protected]>

Ani Sinha (5):
hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support docs/spec: Add a specification document for vm-launch-update device tests/qtest: Add small igvm files for testing purpose
Add functional and unit tests for the vm-launch-update device Update MAINTAINERS

Gerd Hoffmann (3):
igvm: store IgvmCfg pointer in QIgvm
igvm: track memory regions
igvm: cleanup memory regions

 MAINTAINERS                                   |  12 +
 backends/igvm-cfg.c                           |   1 +
 backends/igvm.c                               |  91 +++--
 docs/specs/index.rst                          |   1 +
 docs/specs/vmlaunchupdate.rst                 | 147 ++++++++
 hw/misc/meson.build                           |   3 +
 hw/misc/trace-events                          |   5 +
 hw/misc/vmlaunchupdate.c                      | 236 +++++++++++++
 include/hw/misc/vmlaunchupdate.h              |  85 +++++
 include/system/igvm-internal.h                |   8 +-
 include/system/igvm.h                         |   3 +
 tests/data/igvm/README                        |  24 ++
 tests/data/igvm/hello.igvm                    | Bin 0 -> 153624 bytes
 tests/data/igvm/qemuinit.igvm                 | Bin 0 -> 256856 bytes
 tests/functional/aarch64/meson.build          |   1 +
 .../aarch64/test_vm_launch_update_aarch.py    |  33 ++
 tests/functional/x86_64/meson.build           |   1 +
 .../x86_64/test_vm_launch_update.py           |  48 +++
 tests/qtest/launchupdate-test.c               | 321 ++++++++++++++++++
 tests/qtest/meson.build                       |   2 +
 20 files changed, 989 insertions(+), 33 deletions(-)
 create mode 100644 docs/specs/vmlaunchupdate.rst
 create mode 100644 hw/misc/vmlaunchupdate.c
 create mode 100644 include/hw/misc/vmlaunchupdate.h
 create mode 100644 tests/data/igvm/README
 create mode 100644 tests/data/igvm/hello.igvm
 create mode 100644 tests/data/igvm/qemuinit.igvm
 create mode 100755 tests/functional/aarch64/test_vm_launch_update_aarch.py
 create mode 100755 tests/functional/x86_64/test_vm_launch_update.py
 create mode 100644 tests/qtest/launchupdate-test.c
Signature · 1 line
2.42.0
author
#1 lore raw

PATCH 1/8 igvm: store IgvmCfg pointer in QIgvm

From: Gerd Hoffmann <[email protected]>

Store a pointer to IgvmCfg instead of only IgvmFile in QIgvm. Allows to store additional state in the (persistent) IgvmCfg struct.

---
 backends/igvm.c                | 57 ++++++++++++++++++++--------------
 include/system/igvm-internal.h |  2 +-
 2 files changed, 34 insertions(+), 25 deletions(-)
backends/igvm.c +33 -24
index 3f4b97a5d4..2995e82cee 100644
@@ -164,7 +164,8 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
         if (handlers[handler].type != type) {
             continue;
         }
-        header_handle = igvm_get_header(ctx->file, handlers[handler].section,
+        header_handle = igvm_get_header(ctx->cfg->file,
+                                        handlers[handler].section,
                                         ctx->current_header_index);
         if (header_handle < 0) {
             error_setg(
@@ -173,7 +174,7 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
                 (int)header_handle);
             return -1;
         }
-        header_data = igvm_get_buffer(ctx->file, header_handle);
+        header_data = igvm_get_buffer(ctx->cfg->file, header_handle);
         if (header_data != NULL) {
             header_data += sizeof(IGVM_VHS_VARIABLE_HEADER);
             result = handlers[handler].handler(ctx, header_data, errp);
@@ -184,7 +185,7 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
                     header_handle, type);
             result = -1;
         }
-        igvm_free_buffer(ctx->file, header_handle);
+        igvm_free_buffer(ctx->cfg->file, header_handle);
         return result;
     }
 
@@ -330,7 +331,8 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
 
     for (page_index = 0; page_index < page_count; page_index++) {
         data_handle = igvm_get_header_data(
-            ctx->file, IGVM_HEADER_SECTION_DIRECTIVE, page_index + start_index);
+            ctx->cfg->file, IGVM_HEADER_SECTION_DIRECTIVE,
+            page_index + start_index);
         if (data_handle == IGVMAPI_NO_DATA) {
             /* No data indicates a zero page */
             memset(&region[page_index * page_size], 0, page_size);
@@ -343,7 +345,7 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
             return -1;
         } else {
             zero = false;
-            data_size = igvm_get_buffer_size(ctx->file, data_handle);
+            data_size = igvm_get_buffer_size(ctx->cfg->file, data_handle);
             if (data_size < page_size) {
                 memset(&region[page_index * page_size], 0, page_size);
             } else if (data_size > page_size) {
@@ -353,14 +355,14 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
                            page_index + start_index);
                 return -1;
             }
-            data = igvm_get_buffer(ctx->file, data_handle);
+            data = igvm_get_buffer(ctx->cfg->file, data_handle);
             if (data == NULL) {
                 error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
-                igvm_free_buffer(ctx->file, data_handle);
+                igvm_free_buffer(ctx->cfg->file, data_handle);
                 return -1;
             }
             memcpy(&region[page_index * page_size], data, data_size);
-            igvm_free_buffer(ctx->file, data_handle);
+            igvm_free_buffer(ctx->cfg->file, data_handle);
         }
     }
 
@@ -397,7 +399,8 @@ static int qigvm_process_mem_page(QIgvm *ctx,
             ctx->region_start = page_data->gpa;
             ctx->region_start_index = ctx->current_header_index;
         } else {
-            if (!qigvm_page_attrs_equal(ctx->file, ctx->current_header_index,
+            if (!qigvm_page_attrs_equal(ctx->cfg->file,
+                                        ctx->current_header_index,
                                         page_data,
                                         &ctx->region_prev_page_data) ||
                 ((ctx->region_prev_page_data.gpa +
@@ -460,7 +463,8 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
         return 0;
     }
 
-    data_handle = igvm_get_header_data(ctx->file, IGVM_HEADER_SECTION_DIRECTIVE,
+    data_handle = igvm_get_header_data(ctx->cfg->file,
+                                       IGVM_HEADER_SECTION_DIRECTIVE,
                                        ctx->current_header_index);
     if (data_handle < 0) {
         error_setg(errp, "Invalid VP context in IGVM file. Error code: %X",
@@ -468,7 +472,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
         return -1;
     }
 
-    data = (uint8_t *)igvm_get_buffer(ctx->file, data_handle);
+    data = (uint8_t *)igvm_get_buffer(ctx->cfg->file, data_handle);
     if (data == NULL) {
         error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
         result = -1;
@@ -477,7 +481,8 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
 
     if (ctx->machine_state->cgs) {
         result = ctx->cgsc->set_guest_state(
-            vp_context->gpa, data, igvm_get_buffer_size(ctx->file, data_handle),
+            vp_context->gpa, data,
+            igvm_get_buffer_size(ctx->cfg->file, data_handle),
             CGS_PAGE_TYPE_VMSA, vp_context->vp_index, errp);
     } else if (target_arch() == SYS_EMU_TARGET_X86_64) {
         result = qigvm_x86_set_vp_context(data, vp_context->vp_index, errp);
@@ -490,7 +495,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
     }
 
 exit:
-    igvm_free_buffer(ctx->file, data_handle);
+    igvm_free_buffer(ctx->cfg->file, data_handle);
     if (result < 0) {
         return result;
     }
@@ -803,7 +808,8 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
     uint32_t compatibility_mask_sev_snp = 0;
     uint32_t compatibility_mask = 0;
 
-    header_count = igvm_header_count(ctx->file, IGVM_HEADER_SECTION_PLATFORM);
+    header_count = igvm_header_count(ctx->cfg->file,
+                                     IGVM_HEADER_SECTION_PLATFORM);
     if (header_count < 0) {
         error_setg(errp,
                    "Invalid platform header count in IGVM file. Error code: %X",
@@ -814,11 +820,11 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
     for (header_index = 0; header_index < (unsigned)header_count;
          header_index++) {
         IgvmVariableHeaderType typ = igvm_get_header_type(
-            ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
+            ctx->cfg->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
         typ = igvm_vht_type(typ);
         if (typ == IGVM_VHT_SUPPORTED_PLATFORM) {
             header_handle = igvm_get_header(
-                ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
+                ctx->cfg->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
             if (header_handle < 0) {
                 error_setg(errp,
                            "Invalid platform header in IGVM file. "
@@ -827,11 +833,11 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
                 return -1;
             }
             platform =
-                (IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->file,
+                (IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->cfg->file,
                                                                 header_handle));
             if (platform == NULL) {
                 error_setg(errp, "IGVM: No buffer for handle %d", header_handle);
-                igvm_free_buffer(ctx->file, header_handle);
+                igvm_free_buffer(ctx->cfg->file, header_handle);
                 return -1;
             }
 
@@ -862,7 +868,7 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
             } else if (platform->platform_type == IGVM_PLATFORM_TYPE_NATIVE) {
                 compatibility_mask = platform->compatibility_mask;
             }
-            igvm_free_buffer(ctx->file, header_handle);
+            igvm_free_buffer(ctx->cfg->file, header_handle);
         }
     }
     /* Choose the strongest supported isolation technology */
@@ -939,7 +945,7 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
         error_setg(errp, "No IGVM file loaded.");
         return -1;
     }
-    ctx.file = cfg->file;
+    ctx.cfg = cfg;
     trace_igvm_process_file(cfg->file, onlyVpContext);
 
     ctx.machine_state = machine_state;
@@ -961,7 +967,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
         goto cleanup;
     }
 
-    header_count = igvm_header_count(ctx.file, IGVM_HEADER_SECTION_DIRECTIVE);
+    header_count = igvm_header_count(ctx.cfg->file,
+                                     IGVM_HEADER_SECTION_DIRECTIVE);
     if (header_count <= 0) {
         error_setg(
             errp, "Invalid directive header count in IGVM file. Error code: %X",
@@ -975,7 +982,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
          ctx.current_header_index < (unsigned)header_count;
          ctx.current_header_index++) {
         IgvmVariableHeaderType raw_type = igvm_get_header_type(
-            ctx.file, IGVM_HEADER_SECTION_DIRECTIVE, ctx.current_header_index);
+            ctx.cfg->file, IGVM_HEADER_SECTION_DIRECTIVE,
+            ctx.current_header_index);
         if (!onlyVpContext || igvm_vht_type(raw_type) == IGVM_VHT_VP_CONTEXT) {
             if (qigvm_handler(&ctx, raw_type, errp) < 0) {
                 goto cleanup_parameters;
@@ -993,7 +1001,7 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
     }
 
     header_count =
-        igvm_header_count(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION);
+        igvm_header_count(ctx.cfg->file, IGVM_HEADER_SECTION_INITIALIZATION);
     if (header_count < 0) {
         error_setg(
             errp,
@@ -1006,7 +1014,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
          ctx.current_header_index < (unsigned)header_count;
          ctx.current_header_index++) {
         IgvmVariableHeaderType type =
-            igvm_get_header_type(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION,
+            igvm_get_header_type(ctx.cfg->file,
+                                 IGVM_HEADER_SECTION_INITIALIZATION,
                                  ctx.current_header_index);
         if (qigvm_handler(&ctx, type, errp) < 0) {
             goto cleanup_parameters;
include/system/igvm-internal.h +1 -1
index 7f131c4d03..b55b35328a 100644
@@ -43,7 +43,7 @@ typedef struct QIgvmParameterData {
  * file.
  */
 struct QIgvm {
-    IgvmHandle file;
+    IgvmCfg *cfg;
     MachineState *machine_state;
     ConfidentialGuestSupportClass *cgsc;
     uint32_t compatibility_mask;
Signature · 1 line
2.42.0
author Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH v1 1/8] igvm: store IgvmCfg pointer in QIgvm

Quoted 10 lines · Ani Sinha

From: Gerd Hoffmann <[email protected]>

Store a pointer to IgvmCfg instead of only IgvmFile in QIgvm. Allows to store additional state in the (persistent) IgvmCfg struct.

Quoted 233 lines

---
backends/igvm.c | 57 ++++++++++++++++++++--------------
include/system/igvm-internal.h | 2 +-

2 files changed, 34 insertions(+), 25 deletions(-)
backends/igvm.c +17 -12
index 3f4b97a5d4..2995e82cee 100644
@@ -164,7 +164,8 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
        if (handlers[handler].type != type) {
            continue;
        }
-        header_handle = igvm_get_header(ctx->file, handlers[handler].section,
+        header_handle = igvm_get_header(ctx->cfg->file,
+                                        handlers[handler].section,
                                        ctx->current_header_index);
        if (header_handle < 0) {
            error_setg(
@@ -173,7 +174,7 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
                (int)header_handle);
            return -1;
        }
-        header_data = igvm_get_buffer(ctx->file, header_handle);
+        header_data = igvm_get_buffer(ctx->cfg->file, header_handle);
        if (header_data != NULL) {
            header_data += sizeof(IGVM_VHS_VARIABLE_HEADER);
            result = handlers[handler].handler(ctx, header_data, errp);
@@ -184,7 +185,7 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
                    header_handle, type);
            result = -1;
        }
-        igvm_free_buffer(ctx->file, header_handle);
+        igvm_free_buffer(ctx->cfg->file, header_handle);
        return result;
    }
 
@@ -330,7 +331,8 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
 
    for (page_index = 0; page_index < page_count; page_index++) {
        data_handle = igvm_get_header_data(
-            ctx->file, IGVM_HEADER_SECTION_DIRECTIVE, page_index + start_index);
+            ctx->cfg->file, IGVM_HEADER_SECTION_DIRECTIVE,
+            page_index + start_index);
        if (data_handle == IGVMAPI_NO_DATA) {
            /* No data indicates a zero page */
            memset(&region[page_index * page_size], 0, page_size);
@@ -343,7 +345,7 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
            return -1;
        } else {
            zero = false;
-            data_size = igvm_get_buffer_size(ctx->file, data_handle);
+            data_size = igvm_get_buffer_size(ctx->cfg->file, data_handle);
            if (data_size < page_size) {
                memset(&region[page_index * page_size], 0, page_size);
            } else if (data_size > page_size) {
@@ -353,14 +355,14 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
                           page_index + start_index);
                return -1;
            }
-            data = igvm_get_buffer(ctx->file, data_handle);
+            data = igvm_get_buffer(ctx->cfg->file, data_handle);
            if (data == NULL) {
                error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
-                igvm_free_buffer(ctx->file, data_handle);
+                igvm_free_buffer(ctx->cfg->file, data_handle);
                return -1;
            }
            memcpy(&region[page_index * page_size], data, data_size);
-            igvm_free_buffer(ctx->file, data_handle);
+            igvm_free_buffer(ctx->cfg->file, data_handle);
        }
    }
 
@@ -397,7 +399,8 @@ static int qigvm_process_mem_page(QIgvm *ctx,
            ctx->region_start = page_data->gpa;
            ctx->region_start_index = ctx->current_header_index;
        } else {
-            if (!qigvm_page_attrs_equal(ctx->file, ctx->current_header_index,
+            if (!qigvm_page_attrs_equal(ctx->cfg->file,
+                                        ctx->current_header_index,
                                        page_data,
                                        &ctx->region_prev_page_data) ||
                ((ctx->region_prev_page_data.gpa +
@@ -460,7 +463,8 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
        return 0;
    }
 
-    data_handle = igvm_get_header_data(ctx->file, IGVM_HEADER_SECTION_DIRECTIVE,
+    data_handle = igvm_get_header_data(ctx->cfg->file,
+                                       IGVM_HEADER_SECTION_DIRECTIVE,
                                       ctx->current_header_index);
    if (data_handle < 0) {
        error_setg(errp, "Invalid VP context in IGVM file. Error code: %X",
@@ -468,7 +472,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
        return -1;
    }
 
-    data = (uint8_t *)igvm_get_buffer(ctx->file, data_handle);
+    data = (uint8_t *)igvm_get_buffer(ctx->cfg->file, data_handle);
    if (data == NULL) {
        error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
        result = -1;
@@ -477,7 +481,8 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
 
    if (ctx->machine_state->cgs) {
        result = ctx->cgsc->set_guest_state(
-            vp_context->gpa, data, igvm_get_buffer_size(ctx->file, data_handle),
+            vp_context->gpa, data,
+            igvm_get_buffer_size(ctx->cfg->file, data_handle),
            CGS_PAGE_TYPE_VMSA, vp_context->vp_index, errp);
    } else if (target_arch() == SYS_EMU_TARGET_X86_64) {
        result = qigvm_x86_set_vp_context(data, vp_context->vp_index, errp);
@@ -490,7 +495,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
    }
 

exit:

backends/igvm.c +16 -12
-    igvm_free_buffer(ctx->file, data_handle);
+    igvm_free_buffer(ctx->cfg->file, data_handle);
    if (result < 0) {
        return result;
    }
@@ -803,7 +808,8 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
    uint32_t compatibility_mask_sev_snp = 0;
    uint32_t compatibility_mask = 0;
 
-    header_count = igvm_header_count(ctx->file, IGVM_HEADER_SECTION_PLATFORM);
+    header_count = igvm_header_count(ctx->cfg->file,
+                                     IGVM_HEADER_SECTION_PLATFORM);
    if (header_count < 0) {
        error_setg(errp,
                   "Invalid platform header count in IGVM file. Error code: %X",
@@ -814,11 +820,11 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
    for (header_index = 0; header_index < (unsigned)header_count;
         header_index++) {
        IgvmVariableHeaderType typ = igvm_get_header_type(
-            ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
+            ctx->cfg->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
        typ = igvm_vht_type(typ);
        if (typ == IGVM_VHT_SUPPORTED_PLATFORM) {
            header_handle = igvm_get_header(
-                ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
+                ctx->cfg->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
            if (header_handle < 0) {
                error_setg(errp,
                           "Invalid platform header in IGVM file. "
@@ -827,11 +833,11 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
                return -1;
            }
            platform =
-                (IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->file,
+                (IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->cfg->file,
                                                                header_handle));
            if (platform == NULL) {
                error_setg(errp, "IGVM: No buffer for handle %d", header_handle);
-                igvm_free_buffer(ctx->file, header_handle);
+                igvm_free_buffer(ctx->cfg->file, header_handle);
                return -1;
            }
 
@@ -862,7 +868,7 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
            } else if (platform->platform_type == IGVM_PLATFORM_TYPE_NATIVE) {
                compatibility_mask = platform->compatibility_mask;
            }
-            igvm_free_buffer(ctx->file, header_handle);
+            igvm_free_buffer(ctx->cfg->file, header_handle);
        }
    }
    /* Choose the strongest supported isolation technology */
@@ -939,7 +945,7 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
        error_setg(errp, "No IGVM file loaded.");
        return -1;
    }
-    ctx.file = cfg->file;
+    ctx.cfg = cfg;
    trace_igvm_process_file(cfg->file, onlyVpContext);
 
    ctx.machine_state = machine_state;
@@ -961,7 +967,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
        goto cleanup;
    }
 
-    header_count = igvm_header_count(ctx.file, IGVM_HEADER_SECTION_DIRECTIVE);
+    header_count = igvm_header_count(ctx.cfg->file,
+                                     IGVM_HEADER_SECTION_DIRECTIVE);
    if (header_count <= 0) {
        error_setg(
            errp, "Invalid directive header count in IGVM file. Error code: %X",
@@ -975,7 +982,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
         ctx.current_header_index < (unsigned)header_count;
         ctx.current_header_index++) {
        IgvmVariableHeaderType raw_type = igvm_get_header_type(
-            ctx.file, IGVM_HEADER_SECTION_DIRECTIVE, ctx.current_header_index);
+            ctx.cfg->file, IGVM_HEADER_SECTION_DIRECTIVE,
+            ctx.current_header_index);
        if (!onlyVpContext || igvm_vht_type(raw_type) == IGVM_VHT_VP_CONTEXT) {
            if (qigvm_handler(&ctx, raw_type, errp) < 0) {
                goto cleanup_parameters;
@@ -993,7 +1001,7 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
    }
 
    header_count =
-        igvm_header_count(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION);
+        igvm_header_count(ctx.cfg->file, IGVM_HEADER_SECTION_INITIALIZATION);
    if (header_count < 0) {
        error_setg(
            errp,
@@ -1006,7 +1014,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
         ctx.current_header_index < (unsigned)header_count;
         ctx.current_header_index++) {
        IgvmVariableHeaderType type =
-            igvm_get_header_type(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION,
+            igvm_get_header_type(ctx.cfg->file,
+                                 IGVM_HEADER_SECTION_INITIALIZATION,
                                 ctx.current_header_index);
        if (qigvm_handler(&ctx, type, errp) < 0) {
            goto cleanup_parameters;
include/system/igvm-internal.h +1 -1
index 7f131c4d03..b55b35328a 100644
@@ -43,7 +43,7 @@ typedef struct QIgvmParameterData {
 * file.
 */
 struct QIgvm {
-    IgvmHandle file;
+    IgvmCfg *cfg;
    MachineState *machine_state;
    ConfidentialGuestSupportClass *cgsc;
    uint32_t compatibility_mask;
Signature · 1 line
2.42.0
author
#3 lore raw

PATCH 2/8 igvm: track memory regions

In reply to Ani Sinha

From: Gerd Hoffmann <[email protected]>

Memory regions added by the current IGVM needs to be tracked so that they can be freed when a new IGVM is loaded.

---
 backends/igvm-cfg.c            |  1 +
 backends/igvm.c                | 17 +++++++++--------
 include/system/igvm-internal.h |  6 ++++++
 3 files changed, 16 insertions(+), 8 deletions(-)
backends/igvm-cfg.c +1 -0
index e1f09855f6..38438a7b1e 100644
@@ -65,6 +65,7 @@ static void igvm_complete(UserCreatable *uc, Error **errp)
     IgvmCfg *igvm = IGVM_CFG(uc);
 
     igvm->file = qigvm_file_init(igvm->filename, errp);
+    QTAILQ_INIT(&igvm->memory_regions);
 }
 
 OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT,
backends/igvm.c +9 -8
index 2995e82cee..1c9751812d 100644
@@ -206,7 +206,7 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,
                                   int region_identifier, Error **errp)
 {
     ERRP_GUARD();
-    MemoryRegion *igvm_pages = NULL;
+    IgvmMemoryRegion *imr = NULL;
     Int128 gpa_region_size;
     MemoryRegionSection mrs =
         memory_region_find(get_system_memory(), addr, size);
@@ -240,23 +240,24 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,
          */
         g_autofree char *region_name =
             g_strdup_printf("igvm.%X", region_identifier);
-        igvm_pages = g_new0(MemoryRegion, 1);
+        imr = g_new0(IgvmMemoryRegion, 1);
         if (ctx->machine_state->cgs &&
             ctx->machine_state->cgs->require_guest_memfd) {
-            if (!memory_region_init_ram_guest_memfd(igvm_pages, NULL,
+            if (!memory_region_init_ram_guest_memfd(&imr->mr, NULL,
                                                     region_name, size, errp)) {
-                g_free(igvm_pages);
+                g_free(imr);
                 return NULL;
             }
         } else {
-            if (!memory_region_init_ram(igvm_pages, NULL, region_name, size,
+            if (!memory_region_init_ram(&imr->mr, NULL, region_name, size,
                                         errp)) {
-                g_free(igvm_pages);
+                g_free(imr);
                 return NULL;
             }
         }
-        memory_region_add_subregion(get_system_memory(), addr, igvm_pages);
-        return memory_region_get_ram_ptr(igvm_pages);
+        memory_region_add_subregion(get_system_memory(), addr, &imr->mr);
+        QTAILQ_INSERT_TAIL(&ctx->cfg->memory_regions, imr, next);
+        return memory_region_get_ram_ptr(&imr->mr);
     }
 }
 
include/system/igvm-internal.h +6 -0
index b55b35328a..cab74cfd1d 100644
@@ -18,6 +18,11 @@
 #include "system/confidential-guest-support.h"
 #include <igvm/igvm.h>
 
+typedef struct IgvmMemoryRegion {
+    QTAILQ_ENTRY(IgvmMemoryRegion) next;
+    MemoryRegion mr;
+} IgvmMemoryRegion;
+
 struct IgvmCfg {
     Object parent_obj;
 
@@ -29,6 +34,7 @@ struct IgvmCfg {
     char *filename;
     IgvmHandle file;
     ResettableState reset_state;
+    QTAILQ_HEAD(, IgvmMemoryRegion) memory_regions;
 };
 
 typedef struct QIgvmParameterData {
Signature · 1 line
2.42.0
author Reviewed-by on v1 2/8
#4 lore raw

Re: [PATCH v1 2/8] igvm: track memory regions

Quoted 10 lines · Ani Sinha

From: Gerd Hoffmann <[email protected]>

Memory regions added by the current IGVM needs to be tracked so that they can be freed when a new IGVM is loaded.

Quoted 90 lines

---

backends/igvm-cfg.c            |  1 +
backends/igvm.c                | 17 +++++++++--------
include/system/igvm-internal.h |  6 ++++++
3 files changed, 16 insertions(+), 8 deletions(-)
backends/igvm-cfg.c +1 -0
index e1f09855f6..38438a7b1e 100644
@@ -65,6 +65,7 @@ static void igvm_complete(UserCreatable *uc, Error **errp)
    IgvmCfg *igvm = IGVM_CFG(uc);
 
    igvm->file = qigvm_file_init(igvm->filename, errp);
+    QTAILQ_INIT(&igvm->memory_regions);
 }
 
 OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT,
backends/igvm.c +9 -8
index 2995e82cee..1c9751812d 100644
@@ -206,7 +206,7 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,
                                  int region_identifier, Error **errp)
 {
    ERRP_GUARD();
-    MemoryRegion *igvm_pages = NULL;
+    IgvmMemoryRegion *imr = NULL;
    Int128 gpa_region_size;
    MemoryRegionSection mrs =
        memory_region_find(get_system_memory(), addr, size);
@@ -240,23 +240,24 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,
         */
        g_autofree char *region_name =
            g_strdup_printf("igvm.%X", region_identifier);
-        igvm_pages = g_new0(MemoryRegion, 1);
+        imr = g_new0(IgvmMemoryRegion, 1);
        if (ctx->machine_state->cgs &&
            ctx->machine_state->cgs->require_guest_memfd) {
-            if (!memory_region_init_ram_guest_memfd(igvm_pages, NULL,
+            if (!memory_region_init_ram_guest_memfd(&imr->mr, NULL,
                                                    region_name, size, errp)) {
-                g_free(igvm_pages);
+                g_free(imr);
                return NULL;
            }
        } else {
-            if (!memory_region_init_ram(igvm_pages, NULL, region_name, size,
+            if (!memory_region_init_ram(&imr->mr, NULL, region_name, size,
                                        errp)) {
-                g_free(igvm_pages);
+                g_free(imr);
                return NULL;
            }
        }
-        memory_region_add_subregion(get_system_memory(), addr, igvm_pages);
-        return memory_region_get_ram_ptr(igvm_pages);
+        memory_region_add_subregion(get_system_memory(), addr, &imr->mr);
+        QTAILQ_INSERT_TAIL(&ctx->cfg->memory_regions, imr, next);
+        return memory_region_get_ram_ptr(&imr->mr);
    }
 }
 
include/system/igvm-internal.h +6 -0
index b55b35328a..cab74cfd1d 100644
@@ -18,6 +18,11 @@
 #include "system/confidential-guest-support.h"
 #include <igvm/igvm.h>
 
+typedef struct IgvmMemoryRegion {
+    QTAILQ_ENTRY(IgvmMemoryRegion) next;
+    MemoryRegion mr;
+} IgvmMemoryRegion;
+
 struct IgvmCfg {
    Object parent_obj;
 
@@ -29,6 +34,7 @@ struct IgvmCfg {
    char *filename;
    IgvmHandle file;
    ResettableState reset_state;
+    QTAILQ_HEAD(, IgvmMemoryRegion) memory_regions;
 };
 
 typedef struct QIgvmParameterData {
Signature · 1 line
2.42.0
author
#5 lore raw

PATCH 3/8 igvm: cleanup memory regions

In reply to Ani Sinha

From: Gerd Hoffmann <[email protected]>

This change cleans up existing memory regions that were created by the current IGVM. The cleanup would be necessary when a new IGVM is loaded. This cleanup function is called in a subsequent patch.

---
 backends/igvm.c       | 17 +++++++++++++++++
 include/system/igvm.h |  1 +
 2 files changed, 18 insertions(+)
backends/igvm.c +17 -0
index 1c9751812d..61040d1be2 100644
@@ -14,6 +14,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/target-info-qapi.h"
+#include "migration/vmstate.h"
 #include "system/igvm.h"
 #include "system/igvm-cfg.h"
 #include "system/igvm-internal.h"
@@ -1046,3 +1047,19 @@ cleanup_parameters:
 cleanup:
     return retval;
 }
+
+/*
+ * cleanup any memory regions created by qigvm_prepare_memory()
+ */
+void qigvm_cleanup_memory(IgvmCfg *cfg)
+{
+    IgvmMemoryRegion *imr, *tmp;
+
+    QTAILQ_FOREACH_SAFE(imr, &cfg->memory_regions, next, tmp)
+    {
+        memory_region_del_subregion(get_system_memory(), &imr->mr);
+        vmstate_unregister_ram(&imr->mr, NULL);
+        QTAILQ_REMOVE(&cfg->memory_regions, imr, next);
+        g_free(imr);
+    }
+}
include/system/igvm.h +1 -0
index 64d3542311..e219f1a4ed 100644
@@ -20,6 +20,7 @@ typedef struct QIgvm QIgvm;
 
 int qigvm_process_file(IgvmCfg *igvm, MachineState *machine_state,
                        bool onlyVpContext, Error **errp);
+void qigvm_cleanup_memory(IgvmCfg *igvm);
 
 /* x86 native */
 int qigvm_x86_get_mem_map_entry(int index,
Signature · 1 line
2.42.0
author
#6 lore raw

PATCH 4/8 hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

In reply to Ani Sinha

VM launch update is a mechanism where the virtual machines can use IGVM file bundle to boot into a trusted execution environment without having to depend on a untrusted party to provide the IGVM bundle or firmware image. This is particularly useful for confidential virtual machines that are deployed in the cloud where the tenant and the cloud provider are two different entities. In this scenario, virtual machines can bring their own trusted IGVM file containing a trusted firmware image
bundled as a part of their filesystem and then use this hypervisor interface to update to a trusted and deterministic boot state.
This also allows the guests to have a consistent measurements on the firmware image.

Currently, this mechanism only works if the VM was started with IGVM in the first place.

This change introduces support for the fw-cfg based hypervisor interface and the corresponding device.The change also includes the specification document for this interface. The interface is made generic enough so that guests are free to use their own ABI to pass required information between initial and trusted execution contexts (where they are running their own trusted boot state) without the hypervisor getting involved in between.

Currently, this device is only supported for x86 machines. Presence of IGVM host libraries is also required for parsing IGVM files. Hence, the device cannot be initialized for other machine types or hosts where IGVM support is not present. Trying to initialize it for arm for example will lead to failure:

$ ./qemu-system-arm -device vm-launch-update -machine virt
qemu-system-arm: -device vmfwupdate: This machine does not support vm-launch-update device

Functional and qtests will be added in a subsequent patch.

CC Alex Graf <[email protected]>
CC Gerd Hoffman <[email protected]>
---
 hw/misc/meson.build              |   3 +
 hw/misc/trace-events             |   5 +
 hw/misc/vmlaunchupdate.c         | 236 +++++++++++++++++++++++++++++++
 include/hw/misc/vmlaunchupdate.h |  85 +++++++++++
 include/system/igvm.h            |   2 +
 5 files changed, 331 insertions(+)
 create mode 100644 hw/misc/vmlaunchupdate.c
 create mode 100644 include/hw/misc/vmlaunchupdate.h
hw/misc/meson.build +3 -0
index 23265f6035..b8c7de295e 100644
@@ -163,6 +163,9 @@ specific_ss.add(when: 'CONFIG_MIPS_ITU', if_true: files('mips_itu.c'))
 
 specific_ss.add(when: 'CONFIG_RISCV_MIPS_CMGCR', if_true: files('riscv_cmgcr.c'))
 specific_ss.add(when: 'CONFIG_RISCV_MIPS_CPC', if_true: files('riscv_cpc.c'))
+if igvm.found()
+   specific_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('vmlaunchupdate.c'))
+endif
 
 system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c'))
 
hw/misc/trace-events +5 -0
index b88accc437..f440987501 100644
@@ -417,3 +417,8 @@ iommu_testdev_dma_read(uint64_t gva, uint32_t len) "gva=0x%" PRIx64 " len=%u"
 iommu_testdev_dma_verify(uint32_t expected, uint32_t actual) "expected=0x%x actual=0x%x"
 iommu_testdev_dma_result(uint32_t result) "DMA completed result=0x%x"
 iommu_testdev_dma_armed(bool armed) "armed=%d"
+
+# vmlaunchupdate.c
+launch_update_write(void) ""
+vmlaunch_reset(void) ""
+vm_launchupdate_finalize(void) ""
hw/misc/vmlaunchupdate.c new file +236 -0

236 lines not on this page · raw message

include/hw/misc/vmlaunchupdate.h new file +85 -0

85 lines not on this page · raw message

include/system/igvm.h +2 -0
index e219f1a4ed..e6879550b1 100644
@@ -22,6 +22,8 @@ int qigvm_process_file(IgvmCfg *igvm, MachineState *machine_state,
                        bool onlyVpContext, Error **errp);
 void qigvm_cleanup_memory(IgvmCfg *igvm);
 
+void qigvm_free_memory_regions(void);
+
 /* x86 native */
 int qigvm_x86_get_mem_map_entry(int index,
                                 ConfidentialGuestMemoryMapEntry *entry,
Signature · 1 line
2.42.0
#7 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

Hi,

Quoted 1 line

+static bool disabled;

Why is this global? Should be in VMLaunchUpdateState I think.

hw/misc/vmlaunchupdate.c line 96

Quoted 7 lines
hw/misc/vmlaunchupdate.c new file +7 -0
+    /* free previous file context */
+    if (igvmc->file >= 0) {
+        igvm_free(igvmc->file);
+    }
+    g_free(igvmc->filename);
+    /* set new context */
+    igvmc->file = igvm;

I'm wondering whenever we should better keep the original file, so we have the option to switch back.

With a boot workflow like this ...

(1) boot qemu firmware
(2) some efi app loads igvm with guest firmware + kernel
(3) reset
(4) boot guest-supplied firmware
(5) guest-supplied firmware boots into the bundled kernel (without even looking at the ESP).

... you are now in a situation where the guest can't load a different IGVM file (say with an updated kernel) using the same workflow. The next reset will go straight to (4) instead of restarting at (1).

Quoted 1 line

+++ b/include/hw/misc/vmlaunchupdate.h

I think it makes sense to have two include files, one for the API and one for the qemu internals.

include/hw/misc/vmlaunchupdate.h line 40

Quoted 3 lines
include/hw/misc/vmlaunchupdate.h new file +3 -0
+typedef struct {
+    /* api version */
+    uint16_t version;

uint8_t padding[6];

include/hw/misc/vmlaunchupdate.h line 50

Quoted 10 lines
include/hw/misc/vmlaunchupdate.h new file +10 -0
+
+    /* VMM capabilities, read-only. */
+    uint64_t capabilities;
+    /* control bits, see VMFWUPDATE_CTL_* */
+    uint64_t control;
+
+    /*
+     * address and size of the IGVM image.  Will be cleared when
+     * the write completes successfully and IGVM file is correctly parsed.
+     */

I think we should better have an explicit status field, something along the lines of ...

enum VMLaunchUpdateStatus {
STATUS_UNDEFINED = 0,
STATUS_DISABLED = 1,
STATUS_NO_IMAGE = 2,
STATUS_IMAGE_LOAD_OK = 3,
STATUS_IMAGE_LOAD_FAIL = 4,
}

.. instead of signaling success indirectly by clearing fields. There is room anyway right after the version field.

include/hw/misc/vmlaunchupdate.h line 52

Quoted 2 lines
include/hw/misc/vmlaunchupdate.h new file +2 -0
+    uint64_t fw_image_addr;
+    uint32_t fw_image_size;

uint64_t?

take care,
Gerd

author
#8 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

Quoted 30 lines · Gerd Hoffman

Hi,

Quoted 1 line

+static bool disabled;

Why is this global? Should be in VMLaunchUpdateState I think.

hw/misc/vmlaunchupdate.c line 96

Quoted 7 lines
hw/misc/vmlaunchupdate.c new file +7 -0
+    /* free previous file context */
+    if (igvmc->file >= 0) {
+        igvm_free(igvmc->file);
+    }
+    g_free(igvmc->filename);
+    /* set new context */
+    igvmc->file = igvm;

I'm wondering whenever we should better keep the original file, so we have the option to switch back.

With a boot workflow like this ...

(1) boot qemu firmware
(2) some efi app loads igvm with guest firmware + kernel
(3) reset
(4) boot guest-supplied firmware
(5) guest-supplied firmware boots into the bundled kernel (without even looking at the ESP).

Quoted 2 lines

... you are now in a situation where the guest can't load a different IGVM file (say with an updated kernel) using the same workflow.

Why? Why would the fw-cfg interface not be used again to reset to a new IGVM that loads a new kernel?

Quoted 7 lines

The
next reset will go straight to (4) instead of restarting at (1).

Quoted 1 line

+++ b/include/hw/misc/vmlaunchupdate.h

I think it makes sense to have two include files, one for the API and one for the qemu internals.

Where would you put the api header file?

Quoted 29 lines

include/hw/misc/vmlaunchupdate.h line 40

Quoted 4 lines
include/hw/misc/vmlaunchupdate.h new file +3 -0
+typedef struct {
+    /* api version */
+    uint16_t version;

uint8_t padding[6];

include/hw/misc/vmlaunchupdate.h line 50

Quoted 10 lines
include/hw/misc/vmlaunchupdate.h new file +10 -0
+
+    /* VMM capabilities, read-only. */
+    uint64_t capabilities;
+    /* control bits, see VMFWUPDATE_CTL_* */
+    uint64_t control;
+
+    /*
+     * address and size of the IGVM image.  Will be cleared when
+     * the write completes successfully and IGVM file is correctly parsed.
+     */

I think we should better have an explicit status field, something along the lines of ...

enum VMLaunchUpdateStatus {
STATUS_UNDEFINED = 0,
STATUS_DISABLED = 1,
STATUS_NO_IMAGE = 2,
STATUS_IMAGE_LOAD_OK = 3,
STATUS_IMAGE_LOAD_FAIL = 4,
}

Quoted 7 lines

.. instead of signaling success indirectly by clearing fields. There is room anyway right after the version field.

include/hw/misc/vmlaunchupdate.h line 52

Quoted 2 lines
include/hw/misc/vmlaunchupdate.h new file +2 -0
+    uint64_t fw_image_addr;
+    uint32_t fw_image_size;

uint64_t?

I would leave this as 32 bits. 64 bit idvm file size is too big, no?

#9 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

Hi,

Quoted 12 lines
Quoted 12 lines

I'm wondering whenever we should better keep the original file, so we have the option to switch back.

With a boot workflow like this ...

(1) boot qemu firmware
(2) some efi app loads igvm with guest firmware + kernel
(3) reset
(4) boot guest-supplied firmware
(5) guest-supplied firmware boots into the bundled kernel (without even looking at the ESP).

Quoted 4 lines
Quoted 2 lines

... you are now in a situation where the guest can't load a different IGVM file (say with an updated kernel) using the same workflow.

Why? Why would the fw-cfg interface not be used again to reset to a new IGVM that loads a new kernel?

The guest has no access to the qemu firmware so resetting to that (to get the process start at (1) again) is not so easy. Certainly harder for the guest that for qemu doing it (or offer the option to do it via some control bit).

The other option would be to have some linux driver for this allowing linux tools (instead of an efi app or bootloader) loading a new igvm file on kernel package updates. Implies we'll need two different ways to load IGVM files. I'd much prefer not doing that.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+++ b/include/hw/misc/vmlaunchupdate.h

I think it makes sense to have two include files, one for the API and one for the qemu internals.

Where would you put the api header file?

standard-headers/misc/ looks good to me.

Quoted 9 lines
Quoted 7 lines

.. instead of signaling success indirectly by clearing fields. There is room anyway right after the version field.

include/hw/misc/vmlaunchupdate.h line 52

Quoted 2 lines
include/hw/misc/vmlaunchupdate.h new file +2 -0
+    uint64_t fw_image_addr;
+    uint32_t fw_image_size;

uint64_t?

I would leave this as 32 bits. 64 bit idvm file size is too big, no?

With u32 we'll get 4 bytes padding, so we do not safe any space in the struct. Also initrds can be quite big, the standard anaconda install initrd for fedora 44 is 252M, this is not *that* far away from 32bit max. Also you never know what people do once they have the opportunity. It certainly is possible to build igvm files loading your complete multi-gigabyte workload into memory, verified by launch measurement, then run it without ever accessing disk storage.

take care,
Gerd

author
#10 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

Quoted 33 lines · Gerd Hoffman

Hi,

Quoted 12 lines
Quoted 12 lines

I'm wondering whenever we should better keep the original file, so we have the option to switch back.

With a boot workflow like this ...

(1) boot qemu firmware
(2) some efi app loads igvm with guest firmware + kernel
(3) reset
(4) boot guest-supplied firmware
(5) guest-supplied firmware boots into the bundled kernel (without even looking at the ESP).

Quoted 4 lines
Quoted 2 lines

... you are now in a situation where the guest can't load a different IGVM file (say with an updated kernel) using the same workflow.

Why? Why would the fw-cfg interface not be used again to reset to a new IGVM that loads a new kernel?

The guest has no access to the qemu firmware so resetting to that (to get the process start at (1) again) is not so easy. Certainly harder for the guest that for qemu doing it (or offer the option to do it via some control bit).

The other option would be to have some linux driver for this allowing linux tools (instead of an efi app or bootloader) loading a new igvm file on kernel package updates. Implies we'll need two different ways to load IGVM files. I'd much prefer not doing that.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+++ b/include/hw/misc/vmlaunchupdate.h

I think it makes sense to have two include files, one for the API and one for the qemu internals.

Where would you put the api header file?

standard-headers/misc/ looks good to me.

Hmm, checkpatch is not happy

ERROR: headers imported from Linux should be self-contained in a patch with no other changes #89: FILE: include/standard-headers/misc/vmlaunchupdate.h:1:
+/*

Quoted 21 lines
Quoted 10 lines
Quoted 8 lines

.. instead of signaling success indirectly by clearing fields. There is room anyway right after the version field.

include/hw/misc/vmlaunchupdate.h line 52

Quoted 2 lines
include/hw/misc/vmlaunchupdate.h new file +2 -0
+    uint64_t fw_image_addr;
+    uint32_t fw_image_size;

uint64_t?

I would leave this as 32 bits. 64 bit idvm file size is too big, no?

With u32 we'll get 4 bytes padding, so we do not safe any space in the struct. Also initrds can be quite big, the standard anaconda install initrd for fedora 44 is 252M, this is not *that* far away from 32bit max. Also you never know what people do once they have the opportunity. It certainly is possible to build igvm files loading your complete multi-gigabyte workload into memory, verified by launch measurement, then run it without ever accessing disk storage.

take care,
Gerd

#11 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

Where would you put the api header file?

standard-headers/misc/ looks good to me.

Hmm, checkpatch is not happy

ERROR: headers imported from Linux should be self-contained in a patch with no other changes #89: FILE: include/standard-headers/misc/vmlaunchupdate.h:1:
+/*

Make adding include/standard-headers/misc/vmlaunchupdate.h a separate patch then?

checkpatch doesn't complain about the location but about the patch doing other stuff too.

take care,
Gerd

#12 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

In reply to Ani Sinha
Quoted 127 lines · Ani Sinha

VM launch update is a mechanism where the virtual machines can use IGVM file bundle to boot into a trusted execution environment without having to depend on a untrusted party to provide the IGVM bundle or firmware image. This is particularly useful for confidential virtual machines that are deployed in the cloud where the tenant and the cloud provider are two different entities. In this scenario, virtual machines can bring their own trusted IGVM file containing a trusted firmware image
bundled as a part of their filesystem and then use this hypervisor interface to update to a trusted and deterministic boot state.
This also allows the guests to have a consistent measurements on the firmware image.

Currently, this mechanism only works if the VM was started with IGVM in the first place.

This change introduces support for the fw-cfg based hypervisor interface and the corresponding device.The change also includes the specification document for this interface. The interface is made generic enough so that guests are free to use their own ABI to pass required information between initial and trusted execution contexts (where they are running their own trusted boot state) without the hypervisor getting involved in between.

Currently, this device is only supported for x86 machines. Presence of IGVM host libraries is also required for parsing IGVM files. Hence, the device cannot be initialized for other machine types or hosts where IGVM support is not present. Trying to initialize it for arm for example will lead to failure:

$ ./qemu-system-arm -device vm-launch-update -machine virt
qemu-system-arm: -device vmfwupdate: This machine does not support vm-launch-update device

Functional and qtests will be added in a subsequent patch.

CC Alex Graf <[email protected]>
CC Gerd Hoffman <[email protected]>
---
  hw/misc/meson.build              |   3 +
  hw/misc/trace-events             |   5 +
  hw/misc/vmlaunchupdate.c         | 236 +++++++++++++++++++++++++++++++
  include/hw/misc/vmlaunchupdate.h |  85 +++++++++++
  include/system/igvm.h            |   2 +
  5 files changed, 331 insertions(+)

create mode 100644 hw/misc/vmlaunchupdate.c create mode 100644 include/hw/misc/vmlaunchupdate.h

include/hw/misc/vmlaunchupdate.h new file +73 -0
new file mode 100644
index 0000000000..1d13f4b176
@@ -0,0 +1,85 @@
+/*
+ * Guest driven VM launch state update device via IGVM.
+ * For details and specification, please look at docs/specs/vmlaunchupdate.rst.
+ *
+ * Copyright (C) 2026 Red Hat, Inc.
+ *
+ * Authors: Ani Sinha <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ */
+#ifndef VMLAUNCHUPDATE_H
+#define VMLAUNCHUPDATE_H
+
+#include "hw/core/qdev.h"
+#include "qom/object.h"
+#include "qemu/units.h"
+#include "system/igvm-cfg.h"
+
+#define TYPE_VMLAUNCHUPDATE "vm-launch-update"
+
+/* fw-cfg file definition */
+#define FILE_VMLAUNCHUPDATE "etc/vmlaunchupdate"
+
+/* version */
+#define VM_LAUNCHUPDATE_VERSION 0x01
+
+/* format bits, used by both 'capabilities' and 'control'  */
+
+/* igvm */
+#define VM_LAUNCHUPDATE_FORMAT_IGVM           (1ULL << 32)
+
+/* 'control' field bits  */
+
+/* disable vmlaunchupdate interface */
+#define VM_LAUNCHUPDATE_CTL_DISABLE            (1 << 0)
+
+typedef struct {
+    /* api version */
+    uint16_t version;
+
+    /* VMM capabilities, read-only. */
+    uint64_t capabilities;
+    /* control bits, see VMFWUPDATE_CTL_* */
+    uint64_t control;
+
+    /*
+     * address and size of the IGVM image.  Will be cleared when
+     * the write completes successfully and IGVM file is correctly parsed.
+     */
+    uint64_t fw_image_addr;
+    uint32_t fw_image_size;
+
+    /*
+     * address + size of opaque blob.  The guest can use this to pass on
+     * information, for example which memory region the linux kernel has been
+     * loaded to.  writable, will be kept intact on firmware update.
+     */
+    uint64_t opaque_addr;
+    uint64_t opaque_size;
+
+} VMLaunchUpdate;
+
+typedef struct VMLaunchUpdateState {
+    DeviceState parent_obj;
+    VMLaunchUpdate launch_update;
+    ResettableState reset_state;
+} VMLaunchUpdateState;
+
+
+typedef struct VMLaunchUpdateStateClass {
+    ObjectClass parent_class;
+} VMLaunchUpdateStateClass;

include/hw/misc/vmlaunchupdate.h line 83

Quoted 10 lines
include/hw/misc/vmlaunchupdate.h new file +10 -0
+
+OBJECT_DECLARE_SIMPLE_TYPE(VMLaunchUpdateState, VMLAUNCHUPDATE);
+
+/* returns NULL unless there is exactly one device */
+static inline VMLaunchUpdateState *vm_launchupdate_find(void)
+{
+    Object *o = object_resolve_path_type("", TYPE_VMLAUNCHUPDATE, NULL);
+
+    return o ? VMLAUNCHUPDATE(o) : NULL;
+}

Is this inline really justified?

Quoted 2 lines
include/hw/misc/vmlaunchupdate.h new file +2 -0
+
+#endif
author
#13 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

Quoted 18 lines · Philippe Mathieu-Daudé

include/hw/misc/vmlaunchupdate.h line 83

Quoted 11 lines · Ani Sinha
include/hw/misc/vmlaunchupdate.h new file +10 -0
+
+OBJECT_DECLARE_SIMPLE_TYPE(VMLaunchUpdateState, VMLAUNCHUPDATE);
+
+/* returns NULL unless there is exactly one device */
+static inline VMLaunchUpdateState *vm_launchupdate_find(void)
+{
+    Object *o = object_resolve_path_type("", TYPE_VMLAUNCHUPDATE, NULL);
+
+    return o ? VMLAUNCHUPDATE(o) : NULL;
+}

Is this inline really justified?

Will fix in next spin up.

author
#14 lore raw

Re: [PATCH v1 4/8] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support

In reply to Ani Sinha
Quoted 8 lines
include/system/igvm.h +0 -0
index e219f1a4ed..e6879550b1 100644

include/system/igvm.h int qigvm_process_file(IgvmCfg *igvm, MachineState *machine_state, · line 29

Quoted 8 lines
include/system/igvm.h +2 -0
@@ -22,6 +22,8 @@ int qigvm_process_file(IgvmCfg *igvm, MachineState *machine_state,
                       bool onlyVpContext, Error **errp);
 void qigvm_cleanup_memory(IgvmCfg *igvm);
 
+void qigvm_free_memory_regions(void);
+
 /* x86 native */
 int qigvm_x86_get_mem_map_entry(int index,
                                ConfidentialGuestMemoryMapEntry *entry,

This hunk is completely not needed and is bogus. Will remove in next spinup.

author
#15 lore raw

PATCH 5/8 docs/spec: Add a specification document for vm-launch-update device

In reply to Ani Sinha

This change adds a specification document and expanation for the vm-launch-update device.

CC Alex Graf <[email protected]>
CC Gerd Hoffman <[email protected]>
---
 docs/specs/index.rst          |   1 +
 docs/specs/vmlaunchupdate.rst | 147 ++++++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+)
 create mode 100644 docs/specs/vmlaunchupdate.rst
docs/specs/index.rst +1 -0
index b7909a108a..3cdf242661 100644
@@ -34,6 +34,7 @@ guest hardware that is specific to QEMU.
    virt-ctlr
    vmcoreinfo
    vmgenid
+   vmlaunchupdate
    rapl-msr
    rocker
    riscv-iommu
docs/specs/vmlaunchupdate.rst new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.42.0
author
#16 lore raw

PATCH 6/8 tests/qtest: Add small igvm files for testing purpose

In reply to Ani Sinha

Needed by launchupdate-test.c. README file is added with explanation on how to build these IGVM files.

CC Alex Graf <[email protected]>
CC Gerd Hoffman <[email protected]>
---
 tests/data/igvm/README        |  24 ++++++++++++++++++++++++
 tests/data/igvm/hello.igvm    | Bin 0 -> 153624 bytes
 tests/data/igvm/qemuinit.igvm | Bin 0 -> 256856 bytes
 3 files changed, 24 insertions(+)
 create mode 100644 tests/data/igvm/README
 create mode 100644 tests/data/igvm/hello.igvm
 create mode 100644 tests/data/igvm/qemuinit.igvm
tests/data/igvm/README new file +24 -0
new file mode 100644
index 0000000000..e785099579
@@ -0,0 +1,24 @@
+Small IGVM file bundles required for tesing vm-launch-update device
+===================================================================
+
+This directory contains IGVM files required for launchupdate-test.c.
+These IGVM bundles can be built from the following repository:
+https://gitlab.com/anisinha/virt-firmware-rs
+
+Just type "make" in the top of the repository. The built IGVM files
+can be found in the target/x86_64-unknown-none/debug directory.
+
+$ ls -l ./target/x86_64-unknown-none/debug/*.igvm
+-rw-r--r--. 1 anisinha anisinha 153624 Jun  8 10:05 ./target/x86_64-unknown-none/debug/hello.igvm
+-rw-r--r--. 1 anisinha anisinha 157848 Jun  8 10:05 ./target/x86_64-unknown-none/debug/igvmtest.igvm
+-rw-r--r--. 1 anisinha anisinha 987384 Jun  8 10:05 ./target/x86_64-unknown-none/debug/mefisto.igvm
+-rw-r--r--. 1 anisinha anisinha 368312 Jun  8 10:05 ./target/x86_64-unknown-none/debug/qemuinit.igvm
+-rw-r--r--. 1 anisinha anisinha 223944 Jun  8 10:05 ./target/x86_64-unknown-none/debug/snptest.igvm
+
+
+Following files are used by the tests/qtest/launchupdate-test.c:
+
+hello.igvm
+qemuinit.igvm
+
+
tests/data/igvm/hello.igvm new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..62196ba40a1bd63a7fb68cdb3eb26ac93fed40db
GIT binary patch
tests/data/igvm/qemuinit.igvm new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8923f6282e4899d217d9032de87eb3f1e8eb030a
GIT binary patch
Signature · 1 line
2.42.0
author
#17 lore raw

PATCH 7/8 Add functional and unit tests for the vm-launch-update device

In reply to Ani Sinha

This patchset adds functional and unit tests that exercize various functions and behaviors of vm-launch-update device. It uses the IGVM files that were introduced in the previous patch for exercizing the hypervisor interface.

CC Alex Graf <[email protected]>
CC Gerd Hoffman <[email protected]>
---
 tests/functional/aarch64/meson.build          |   1 +
 .../aarch64/test_vm_launch_update_aarch.py    |  33 ++
 tests/functional/x86_64/meson.build           |   1 +
 .../x86_64/test_vm_launch_update.py           |  48 +++
 tests/qtest/launchupdate-test.c               | 321 ++++++++++++++++++
 tests/qtest/meson.build                       |   2 +
 6 files changed, 406 insertions(+)
 create mode 100755 tests/functional/aarch64/test_vm_launch_update_aarch.py
 create mode 100755 tests/functional/x86_64/test_vm_launch_update.py
 create mode 100644 tests/qtest/launchupdate-test.c
tests/functional/aarch64/meson.build +1 -0
index e81afd6c39..b07373189e 100644
@@ -23,6 +23,7 @@ test_aarch64_timeouts = {
 tests_aarch64_system_quick = [
   'migration',
   'vmstate',
+  'vm_launch_update_aarch',
 ]
 
 tests_aarch64_system_thorough = [
tests/functional/aarch64/test_vm_launch_update_aarch.py new file +33 -0
new file mode 100755
index 0000000000..2b3d7cf4a3
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+#
+# Check for vm-launch-update device.
+#
+# Copyright (c) 2026 Red Hat, Inc.
+#
+# Author:
+#  Ani Sinha <[email protected]>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import QemuSystemTest
+
+class VmLaunchUpdateDeviceCheck(QemuSystemTest):
+
+    def aarch64_fail_test(self):
+        """
+        Currently the device is only supported for pc platforms.
+        """
+        self.vm.add_args('-machine', 'virt', '-device',
+                         'vm-launch-update,id=fwupd1')
+        self.vm.set_qmp_monitor(enabled=False)
+        self.vm.launch()
+        self.vm.wait()
+        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
+        self.assertRegex(self.vm.get_log(),
+                    r'This machine does not support vm-launch-update device')
+
+    def test_vm_launch_update(self):
+        self.aarch64_fail_test()
+
+if __name__ == '__main__':
+    QemuSystemTest.main()
tests/functional/x86_64/meson.build +1 -0
index 1ed10ad6c2..9b98e61e63 100644
@@ -18,6 +18,7 @@ tests_x86_64_system_quick = [
   'pc_cpu_hotplug_props',
   'virtio_version',
   'vmstate',
+  'vm_launch_update',
 ]
 
 # The address-sanitizer makes mlock() a no-op because it
tests/functional/x86_64/test_vm_launch_update.py new file +48 -0

48 lines not on this page · raw message

tests/qtest/launchupdate-test.c new file +321 -0

321 lines not on this page · raw message

tests/qtest/meson.build +2 -0
index 4897325d84..d23c76963e 100644
@@ -59,6 +59,8 @@ qtests_i386 = \
   (config_all_devices.has_key('CONFIG_FDC_ISA') ? ['fdc-test'] : []) +                      \
   (config_all_devices.has_key('CONFIG_I440FX') ? ['fw_cfg-test'] : []) +                    \
   (config_all_devices.has_key('CONFIG_FW_CFG_DMA') ? ['vmcoreinfo-test'] : []) +            \
+  (igvm.found() and
+   config_all_devices.has_key('CONFIG_FW_CFG_DMA') ? ['launchupdate-test'] : []) +          \
   (config_all_devices.has_key('CONFIG_I440FX') ? ['i440fx-test'] : []) +                    \
   (config_all_devices.has_key('CONFIG_I440FX') ? ['ide-test'] : []) +                       \
   (config_all_devices.has_key('CONFIG_I440FX') ? ['numa-test'] : []) +                      \
Signature · 1 line
2.42.0
author
#18 lore raw

PATCH 8/8 Update MAINTAINERS

In reply to Ani Sinha

Add maintainers for vm-launch-update device and associated documentation and test code.

---
 MAINTAINERS | 12 ++++++++++++
 1 file changed, 12 insertions(+)
MAINTAINERS +12 -0
index 93df53d87f..98b63b40d4 100644
@@ -2773,6 +2773,18 @@ F: include/hw/acpi/vmgenid.h
 F: docs/specs/vmgenid.rst
 F: tests/qtest/vmgenid-test.c
 
+VM Launch Update
+M: Ani Sinha <[email protected]>
+M: Gerd Hoffman <[email protected]>
+S: Maintained
+F: hw/misc/vmlaunchupdate.c
+F: include/hw/misc/vmlaunchupdate.h
+F: docs/specs/vmlaunchupdate.rst
+F: tests/functional/aarch64/test_vm_launch_update_aarch.py
+F: tests/functional/x86_64/test_vm_launch_update.py
+F: tests/qtest/launchupdate-test.c
+F: tests/data/igvm/*
+
 LED
 M: Philippe Mathieu-Daudé <[email protected]>
 S: Maintained
Signature · 1 line
2.42.0