Skip to contentSkip to conversation

igvm: add support for igvm memory map parameter in native mode

PATCH In review Gerd Hoffmann 2 participants 7 messages Oct 29, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v5 cover igvm: add support for igvm memory map parameter in native mode

v5:
- pick up review tags + Fixes: tag.
- update MAINTAINERS entry to list /me + Stefano as maintainers.

v4:
- misc minor fixes as suggested by Stefano
- pick up review tags
- add Ani as reviewer

v3:
- Oh crap, no MAINTAINERS entry, so v1 + v2 probably went largely unnoticed. Added a patch adding an entry, comments welcome. Also added some people to Cc.
- code is mostly unchanged.
v2:
- add support for loading the initial register state

Gerd Hoffmann (5):
igvm: move igvm.h file to include/system
igvm: fix off by one bug in memmap entry count checking
igvm: add support for igvm memory map parameter in native mode
igvm: add support for initial register state load in native mode
igvm: add MAINTAINERS entry

 {backends => include/system}/igvm.h |   7 ++
 target/i386/cpu.h                   |   3 +
 backends/igvm-cfg.c                 |   2 +-
 backends/igvm.c                     |  50 ++++----
 stubs/igvm.c                        |  26 ++++
 target/i386/cpu.c                   |   6 +
 target/i386/igvm.c                  | 180 ++++++++++++++++++++++++++++
 MAINTAINERS                         |  10 ++
 stubs/meson.build                   |   1 +
 target/i386/meson.build             |   3 +
 10 files changed, 266 insertions(+), 22 deletions(-)
 rename {backends => include/system}/igvm.h (64%)
 create mode 100644 stubs/igvm.c
 create mode 100644 target/i386/igvm.c
Signature · 1 line
2.51.0
#1 lore raw

PATCH v5 1/5 igvm: move igvm.h file to include/system

Prepare for arch-specific igvm code being added to the code base.

---
 {backends => include/system}/igvm.h | 0
 backends/igvm-cfg.c                 | 2 +-
 backends/igvm.c                     | 2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename {backends => include/system}/igvm.h (100%)
include/system/igvm.h renamed from backends/igvm.h +0 -0
similarity index 100%
rename from backends/igvm.h
rename to include/system/igvm.h
backends/igvm-cfg.c +1 -1
index 45df63e06c1a..d00acf351249 100644
@@ -12,7 +12,7 @@
 #include "qemu/osdep.h"
 
 #include "system/igvm-cfg.h"
-#include "igvm.h"
+#include "system/igvm.h"
 #include "qom/object_interfaces.h"
 
 static char *get_igvm(Object *obj, Error **errp)
backends/igvm.c +1 -1
index 9ad41582ee5e..723d45b755a0 100644
@@ -11,8 +11,8 @@
 
 #include "qemu/osdep.h"
 
-#include "igvm.h"
 #include "qapi/error.h"
+#include "system/igvm.h"
 #include "system/memory.h"
 #include "system/address-spaces.h"
 #include "hw/core/cpu.h"
Signature · 1 line
2.51.0
#2 lore raw

PATCH v5 2/5 igvm: fix off by one bug in memmap entry count checking

In reply to Gerd Hoffmann
Fixes c1d466d267 ("backends/igvm: Add IGVM loader and configuration")
---
 backends/igvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
backends/igvm.c +1 -1
index 723d45b755a0..055bbba745ad 100644
@@ -567,7 +567,7 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
 
             retval = ctx->cgsc->get_mem_map_entry(entry, &cgmm_entry, errp);
             while (retval == 0) {
-                if (entry > max_entry_count) {
+                if (entry >= max_entry_count) {
                     error_setg(
                         errp,
                         "IGVM: guest memory map size exceeds parameter area defined in IGVM file");
Signature · 1 line
2.51.0
#3 lore raw

PATCH v5 3/5 igvm: add support for igvm memory map parameter in native mode

In reply to Gerd Hoffmann

Add and wire up qigvm_x86_get_mem_map_entry function which converts the e820 table into an igvm memory map parameter. This makes igvm files for the native (non-confidential) platform with memory map parameter work.

---
 include/system/igvm.h   |  5 +++++
 backends/igvm.c         | 16 ++++++++++----
 stubs/igvm.c            | 21 +++++++++++++++++++
 target/i386/igvm.c      | 46 +++++++++++++++++++++++++++++++++++++++++
 stubs/meson.build       |  1 +
 target/i386/meson.build |  3 +++
 6 files changed, 88 insertions(+), 4 deletions(-)
 create mode 100644 stubs/igvm.c
 create mode 100644 target/i386/igvm.c
include/system/igvm.h +5 -0
index a4abab043a1f..3f72a40b8897 100644
@@ -19,4 +19,9 @@
 int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
                       bool onlyVpContext, Error **errp);
 
+/* x86 native */
+int qigvm_x86_get_mem_map_entry(int index,
+                                ConfidentialGuestMemoryMapEntry *entry,
+                                Error **errp);
+
 #endif
backends/igvm.c +12 -4
index 055bbba745ad..2ab7a9d96565 100644
@@ -12,6 +12,7 @@
 #include "qemu/osdep.h"
 
 #include "qapi/error.h"
+#include "qemu/target-info-qapi.h"
 #include "system/igvm.h"
 #include "system/memory.h"
 #include "system/address-spaces.h"
@@ -543,6 +544,8 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
                                       Error **errp)
 {
     const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data;
+    int (*get_mem_map_entry)(int index, ConfidentialGuestMemoryMapEntry *entry,
+                             Error **errp) = NULL;
     QIgvmParameterData *param_entry;
     int max_entry_count;
     int entry = 0;
@@ -550,7 +553,13 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
     ConfidentialGuestMemoryMapEntry cgmm_entry;
     int retval = 0;
 
-    if (!ctx->cgs) {
+    if (ctx->cgs && ctx->cgsc->get_mem_map_entry) {
+        get_mem_map_entry = ctx->cgsc->get_mem_map_entry;
+
+    } else if (target_arch() == SYS_EMU_TARGET_X86_64) {
+        get_mem_map_entry = qigvm_x86_get_mem_map_entry;
+
+    } else {
         error_setg(errp,
                    "IGVM file contains a memory map but this is not supported "
                    "by the current system.");
@@ -565,7 +574,7 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
                 param_entry->size / sizeof(IGVM_VHS_MEMORY_MAP_ENTRY);
             mm_entry = (IGVM_VHS_MEMORY_MAP_ENTRY *)param_entry->data;
 
-            retval = ctx->cgsc->get_mem_map_entry(entry, &cgmm_entry, errp);
+            retval = get_mem_map_entry(entry, &cgmm_entry, errp);
             while (retval == 0) {
                 if (entry >= max_entry_count) {
                     error_setg(
@@ -598,8 +607,7 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
                         IGVM_MEMORY_MAP_ENTRY_TYPE_PLATFORM_RESERVED;
                     break;
                 }
-                retval =
-                    ctx->cgsc->get_mem_map_entry(++entry, &cgmm_entry, errp);
+                retval = get_mem_map_entry(++entry, &cgmm_entry, errp);
             }
             if (retval < 0) {
                 return retval;
stubs/igvm.c new file +21 -0
new file mode 100644
index 000000000000..c32058eb2a6e
@@ -0,0 +1,21 @@
+/*
+ * QEMU IGVM, stubs
+ *
+ * Copyright (C) 2026 Red Hat
+ *
+ * Authors:
+ *  Gerd Hoffmann <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+
+#include "system/igvm.h"
+
+int qigvm_x86_get_mem_map_entry(int index,
+                                ConfidentialGuestMemoryMapEntry *entry,
+                                Error **errp)
+{
+    return -1;
+}
target/i386/igvm.c new file +46 -0

46 lines not on this page · raw message

stubs/meson.build +1 -0
index 5d577467bfdd..27be2dec9f9e 100644
@@ -74,6 +74,7 @@ if have_system
   stub_ss.add(files('dump.c'))
   stub_ss.add(files('cmos.c'))
   stub_ss.add(files('fw_cfg.c'))
+  stub_ss.add(files('igvm.c'))
   stub_ss.add(files('target-get-monitor-def.c'))
   stub_ss.add(files('target-monitor-defs.c'))
   stub_ss.add(files('win32-kbd-hook.c'))
target/i386/meson.build +3 -0
index 89ba4912aaeb..d385eafdf7e1 100644
@@ -26,6 +26,9 @@ i386_system_ss.add(files(
 ))
 i386_system_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'),
                                        if_false: files('sev-system-stub.c'))
+if igvm.found()
+  i386_system_ss.add(files('igvm.c'))
+endif
 
 i386_user_ss = ss.source_set()
 
Signature · 1 line
2.51.0
#4 lore raw

PATCH v5 4/5 igvm: add support for initial register state load in native mode

In reply to Gerd Hoffmann

Add IgvmNativeVpContextX64 struct holding the register state (see igvm spec), and the qigvm_x86_load_context() function to load the register state.

Wire up using two new functions: qigvm_x86_set_vp_context() is called from igvm file handling code and stores the boot processor context. qigvm_x86_bsp_reset() is called from i386 target cpu reset code and loads the context into the cpu registers.

---
 include/system/igvm.h |   2 +
 target/i386/cpu.h     |   3 +
 backends/igvm.c       |  30 +++++-----
 stubs/igvm.c          |   5 ++
 target/i386/cpu.c     |   6 ++
 target/i386/igvm.c    | 134 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 165 insertions(+), 15 deletions(-)
include/system/igvm.h +2 -0
index 3f72a40b8897..48ce20604259 100644
@@ -23,5 +23,7 @@ int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
 int qigvm_x86_get_mem_map_entry(int index,
                                 ConfidentialGuestMemoryMapEntry *entry,
                                 Error **errp);
+int qigvm_x86_set_vp_context(void *data, int index,
+                             Error **errp);
 
 #endif
target/i386/cpu.h +3 -0
index d0da9bfe58ce..cee1f692a1c3 100644
@@ -2868,6 +2868,9 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);
 
 #endif
 
+/* igvm.c */
+void qigvm_x86_bsp_reset(CPUX86State *env);
+
 /* cpu.c */
 bool cpu_is_bsp(X86CPU *cpu);
 
backends/igvm.c +15 -15
index 2ab7a9d96565..905bd8d98994 100644
@@ -432,18 +432,6 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
         return 0;
     }
 
-    /*
-     * A confidential guest support object must be provided for setting
-     * a VP context.
-     */
-    if (!ctx->cgs) {
-        error_setg(
-            errp,
-            "A VP context is present in the IGVM file but is not supported "
-            "by the current system.");
-        return -1;
-    }
-
     data_handle = igvm_get_header_data(ctx->file, IGVM_HEADER_SECTION_DIRECTIVE,
                                        ctx->current_header_index);
     if (data_handle < 0) {
@@ -453,9 +441,21 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
     }
 
     data = (uint8_t *)igvm_get_buffer(ctx->file, data_handle);
-    result = ctx->cgsc->set_guest_state(
-        vp_context->gpa, data, igvm_get_buffer_size(ctx->file, data_handle),
-        CGS_PAGE_TYPE_VMSA, vp_context->vp_index, errp);
+
+    if (ctx->cgs) {
+        result = ctx->cgsc->set_guest_state(
+            vp_context->gpa, data, igvm_get_buffer_size(ctx->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);
+    } else {
+        error_setg(
+            errp,
+            "A VP context is present in the IGVM file but is not supported "
+            "by the current system.");
+        result = -1;
+    }
+
     igvm_free_buffer(ctx->file, data_handle);
     if (result < 0) {
         return result;
stubs/igvm.c +5 -0
index c32058eb2a6e..17cd1e903e35 100644
@@ -19,3 +19,8 @@ int qigvm_x86_get_mem_map_entry(int index,
 {
     return -1;
 }
+
+int qigvm_x86_set_vp_context(void *data, int index, Error **errp)
+{
+    return -1;
+}
target/i386/cpu.c +6 -0
index 0a66e1fec939..641777578637 100644
@@ -8770,6 +8770,12 @@ static void x86_cpu_reset_hold(Object *obj, ResetType type)
 
     cs->halted = !cpu_is_bsp(cpu);
 
+#if defined(CONFIG_IGVM)
+    if (cpu_is_bsp(cpu)) {
+        qigvm_x86_bsp_reset(env);
+    }
+#endif
+
     if (kvm_enabled()) {
         kvm_arch_reset_vcpu(cpu);
     }
target/i386/igvm.c +134 -0

146 lines not on this page · raw message

Signature · 1 line
2.51.0
#5 lore raw

PATCH v5 5/5 igvm: add MAINTAINERS entry

In reply to Gerd Hoffmann

Roy Hopkins (the original author) does not respond, so the new plan going forward is that I will maintain this together with Stefano. Also add Ani as reviewer.

---
 MAINTAINERS | 10 ++++++++++
 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
index 64491c800c2c..a79eb495d047 100644
@@ -3906,6 +3906,16 @@ F: roms/edk2-*
 F: tests/data/uefi-boot-images/
 F: tests/uefi-test-tools/
 
+IGVM Firmware
+M: Gerd Hoffmann <[email protected]>
+M: Stefano Garzarella <[email protected]>
+R: Ani Sinha <[email protected]>
+S: Maintained
+F: backends/igvm*.c
+F: include/system/igvm*.h
+F: stubs/igvm.c
+F: target/i386/igvm.c
+
 VT-d Emulation
 M: Michael S. Tsirkin <[email protected]>
 R: Jason Wang <[email protected]>
Signature · 1 line
2.51.0
Reviewed-by on v5 5/5
#6 lore raw

Re: [PATCH v5 5/5] igvm: add MAINTAINERS entry

Quoted 2 lines · Gerd Hoffmann

Roy Hopkins (the original author) does not respond, so the new plan going forward is that I will maintain this together with Stefano. Also

I confirm my availability :-)

Quoted 15 lines

add Ani as reviewer.

---
MAINTAINERS | 10 ++++++++++

1 file changed, 10 insertions(+)
MAINTAINERS +0 -0
index 64491c800c2c..a79eb495d047 100644
@@ -3906,6 +3906,16 @@ F: roms/edk2-*

F: tests/data/uefi-boot-images/
F: tests/uefi-test-tools/

MAINTAINERS F: roms/edk2-* · line 3917

Quoted 9 lines
MAINTAINERS +9 -0
+IGVM Firmware
+M: Gerd Hoffmann <[email protected]>
+M: Stefano Garzarella <[email protected]>
+R: Ani Sinha <[email protected]>
+S: Maintained
+F: backends/igvm*.c
+F: include/system/igvm*.h
+F: stubs/igvm.c
+F: target/i386/igvm.c

Should we also add docs/system/igvm.rst ?

Thanks,
Stefano

Quoted 7 lines

+
VT-d Emulation
M: Michael S. Tsirkin <[email protected]>
R: Jason Wang <[email protected]>

Signature · 1 line
2.51.0