Skip to contentSkip to conversation

igvm: rework igvm file loading + processing, fix reset

PATCH Superseded Gerd Hoffmann 4 participants 14 messages Dec 11, 2025 – Jan 12

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#7 lore raw

PATCH v2 2/5 igvm: make igvm-cfg object resettable

In reply to Gerd Hoffmann

Add TYPE_RESETTABLE_INTERFACE to interfaces. Register callbacks for the reset phases. Add trace points for logging and debugging. No functional change, that will come in followup patches.

---
 include/system/igvm-cfg.h      |  1 +
 include/system/igvm-internal.h |  1 +
 backends/igvm-cfg.c            | 35 +++++++++++++++++++++++++++++++++-
 backends/trace-events          |  5 +++++
 4 files changed, 41 insertions(+), 1 deletion(-)
include/system/igvm-cfg.h +1 -0
index 6c07f3084082..b0380133b9a0 100644
@@ -14,6 +14,7 @@
 
 #include "qemu/typedefs.h"
 #include "qom/object.h"
+#include "hw/resettable.h"
 
 typedef struct IgvmCfgClass {
     ObjectClass parent_class;
include/system/igvm-internal.h +1 -0
index 475a29bbf3d7..e0452080b127 100644
@@ -21,6 +21,7 @@ struct IgvmCfg {
      *           format.
      */
     char *filename;
+    ResettableState reset_state;
 };
 
 #endif
backends/igvm-cfg.c +34 -1
index 001c4dc93346..e0df3eaa8efd 100644
@@ -17,6 +17,8 @@
 #include "system/reset.h"
 #include "qom/object_interfaces.h"
 
+#include "trace.h"
+
 static char *get_igvm(Object *obj, Error **errp)
 {
     IgvmCfg *igvm = IGVM_CFG(obj);
@@ -30,24 +32,55 @@ static void set_igvm(Object *obj, const char *value, Error **errp)
     igvm->filename = g_strdup(value);
 }
 
+static ResettableState *igvm_reset_state(Object *obj)
+{
+    IgvmCfg *igvm = IGVM_CFG(obj);
+    return &igvm->reset_state;
+}
+
+static void igvm_reset_enter(Object *obj, ResetType type)
+{
+    trace_igvm_reset_enter(type);
+}
+
+static void igvm_reset_hold(Object *obj, ResetType type)
+{
+    trace_igvm_reset_hold(type);
+}
+
+static void igvm_reset_exit(Object *obj, ResetType type)
+{
+    trace_igvm_reset_exit(type);
+}
+
 OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT,
-                                   { TYPE_USER_CREATABLE }, { NULL })
+                                   { TYPE_USER_CREATABLE },
+                                   { TYPE_RESETTABLE_INTERFACE },
+                                   { NULL })
 
 static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
 {
     IgvmCfgClass *igvmc = IGVM_CFG_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
 
     object_class_property_add_str(oc, "file", get_igvm, set_igvm);
     object_class_property_set_description(oc, "file",
                                           "Set the IGVM filename to use");
 
     igvmc->process = qigvm_process_file;
+
+    rc->get_state = igvm_reset_state;
+    rc->phases.enter = igvm_reset_enter;
+    rc->phases.hold = igvm_reset_hold;
+    rc->phases.exit = igvm_reset_exit;
 }
 
 static void igvm_cfg_init(Object *obj)
 {
+    qemu_register_resettable(obj);
 }
 
 static void igvm_cfg_finalize(Object *obj)
 {
+    qemu_unregister_resettable(obj);
 }
backends/trace-events +5 -0
index 56132d3fd22b..45ac46dc2454 100644
@@ -21,3 +21,8 @@ iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=%d id=%d (%
 iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd=%d hwpt=%u enable=%d (%d)"
 iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t iova, uint64_t size, uint64_t page_size, int ret) " iommufd=%d hwpt=%u iova=0x%"PRIx64" size=0x%"PRIx64" page_size=0x%"PRIx64" (%d)"
 iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t data_type, uint32_t entry_len, uint32_t entry_num, uint32_t done_num, uint64_t data_ptr, int ret) " iommufd=%d id=%u data_type=%u entry_len=%u entry_num=%u done_num=%u data_ptr=0x%"PRIx64" (%d)"
+
+# igvm-cfg.c
+igvm_reset_enter(int type) "type=%u"
+igvm_reset_hold(int type) "type=%u"
+igvm_reset_exit(int type) "type=%u"
Signature · 1 line
2.52.0
#13 lore raw

PATCH v2 5/5 igvm: move igvm file processing to reset callbacks

In reply to Gerd Hoffmann

Move igvm file processing from machine init to reset callbacks. With that the igvm file is properly re-loaded on reset. Also the loading happens later in the init process now. This will simplify future support for some IGVM parameters which depend on initialization steps which happen after machine init.

---
 backends/igvm-cfg.c |  7 +++++++
 hw/i386/pc_piix.c   | 10 ----------
 hw/i386/pc_q35.c    | 10 ----------
 3 files changed, 7 insertions(+), 20 deletions(-)
backends/igvm-cfg.c +7 -0
index 4014062e0f22..8c77db8c57c6 100644
@@ -16,6 +16,8 @@
 #include "system/igvm-internal.h"
 #include "system/reset.h"
 #include "qom/object_interfaces.h"
+#include "hw/qdev-core.h"
+#include "hw/boards.h"
 
 #include "trace.h"
 
@@ -45,7 +47,12 @@ static void igvm_reset_enter(Object *obj, ResetType type)
 
 static void igvm_reset_hold(Object *obj, ResetType type)
 {
+    MachineState *ms = MACHINE(qdev_get_machine());
+    IgvmCfg *igvm = IGVM_CFG(obj);
+
     trace_igvm_reset_hold(type);
+
+    qigvm_process_file(igvm, ms->cgs, false, &error_fatal);
 }
 
 static void igvm_reset_exit(Object *obj, ResetType type)
hw/i386/pc_piix.c +0 -10
index 7b3611e973cd..b3b71df64bfc 100644
@@ -320,16 +320,6 @@ static void pc_init1(MachineState *machine, const char *pci_type)
                                x86_nvdimm_acpi_dsmio,
                                x86ms->fw_cfg, OBJECT(pcms));
     }
-
-#if defined(CONFIG_IGVM)
-    /* Apply guest state from IGVM if supplied */
-    if (x86ms->igvm) {
-        if (IGVM_CFG_GET_CLASS(x86ms->igvm)
-                ->process(x86ms->igvm, machine->cgs, false, &error_fatal) < 0) {
-            g_assert_not_reached();
-        }
-    }
-#endif
 }
 
 typedef enum PCSouthBridgeOption {
hw/i386/pc_q35.c +0 -10
index 6015e639d7bc..f2e6ebfe294c 100644
@@ -328,16 +328,6 @@ static void pc_q35_init(MachineState *machine)
                                x86_nvdimm_acpi_dsmio,
                                x86ms->fw_cfg, OBJECT(pcms));
     }
-
-#if defined(CONFIG_IGVM)
-    /* Apply guest state from IGVM if supplied */
-    if (x86ms->igvm) {
-        if (IGVM_CFG_GET_CLASS(x86ms->igvm)
-                ->process(x86ms->igvm, machine->cgs, false, &error_fatal) < 0) {
-            g_assert_not_reached();
-        }
-    }
-#endif
 }
 
 #define DEFINE_Q35_MACHINE(major, minor) \
Signature · 1 line
2.52.0
#8 lore raw

PATCH v2 3/5 igvm: move file load to complete callback

In reply to Gerd Hoffmann

Add UserCreatableClass->complete callback function for igvm-cfg object.

Move file loading and parsing of the igvm file from the process function to the new complete() callback function. Keep the igvm file loaded after processing, release it in finalize() instead, so we parse it only once.

---
 include/system/igvm-internal.h |  5 +++++
 backends/igvm-cfg.c            | 18 ++++++++++++++++++
 backends/igvm.c                |  9 ++++-----
 3 files changed, 27 insertions(+), 5 deletions(-)
include/system/igvm-internal.h +5 -0
index e0452080b127..d378d682b0fb 100644
@@ -12,6 +12,8 @@
 #include "qemu/typedefs.h"
 #include "qom/object.h"
 
+#include <igvm/igvm.h>
+
 struct IgvmCfg {
     ObjectClass parent_class;
 
@@ -21,7 +23,10 @@ struct IgvmCfg {
      *           format.
      */
     char *filename;
+    IgvmHandle file;
     ResettableState reset_state;
 };
 
+IgvmHandle qigvm_file_init(char *filename, Error **errp);
+
 #endif
backends/igvm-cfg.c +18 -0
index e0df3eaa8efd..4014062e0f22 100644
@@ -53,6 +53,13 @@ static void igvm_reset_exit(Object *obj, ResetType type)
     trace_igvm_reset_exit(type);
 }
 
+static void igvm_complete(UserCreatable *uc, Error **errp)
+{
+    IgvmCfg *igvm = IGVM_CFG(uc);
+
+    igvm->file = qigvm_file_init(igvm->filename, errp);
+}
+
 OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT,
                                    { TYPE_USER_CREATABLE },
                                    { TYPE_RESETTABLE_INTERFACE },
@@ -62,6 +69,7 @@ static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
 {
     IgvmCfgClass *igvmc = IGVM_CFG_CLASS(oc);
     ResettableClass *rc = RESETTABLE_CLASS(oc);
+    UserCreatableClass *uc = USER_CREATABLE_CLASS(oc);
 
     object_class_property_add_str(oc, "file", get_igvm, set_igvm);
     object_class_property_set_description(oc, "file",
@@ -73,14 +81,24 @@ static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
     rc->phases.enter = igvm_reset_enter;
     rc->phases.hold = igvm_reset_hold;
     rc->phases.exit = igvm_reset_exit;
+
+    uc->complete = igvm_complete;
 }
 
 static void igvm_cfg_init(Object *obj)
 {
+    IgvmCfg *igvm = IGVM_CFG(obj);
+
+    igvm->file = -1;
     qemu_register_resettable(obj);
 }
 
 static void igvm_cfg_finalize(Object *obj)
 {
+    IgvmCfg *igvm = IGVM_CFG(obj);
+
     qemu_unregister_resettable(obj);
+    if (igvm->file >= 0) {
+        igvm_free(igvm->file);
+    }
 }
backends/igvm.c +4 -5
index fbb8300b6d01..a01e01a12a60 100644
@@ -869,7 +869,7 @@ static int qigvm_handle_policy(QIgvm *ctx, Error **errp)
     return 0;
 }
 
-static IgvmHandle qigvm_file_init(char *filename, Error **errp)
+IgvmHandle qigvm_file_init(char *filename, Error **errp)
 {
     IgvmHandle igvm;
     g_autofree uint8_t *buf = NULL;
@@ -898,10 +898,11 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
     QIgvm ctx;
 
     memset(&ctx, 0, sizeof(ctx));
-    ctx.file = qigvm_file_init(cfg->filename, errp);
-    if (ctx.file < 0) {
+    if (cfg->file < 0) {
+        error_setg(errp, "No IGVM file loaded.");
         return -1;
     }
+    ctx.file = cfg->file;
 
     /*
      * The ConfidentialGuestSupport object is optional and allows a confidential
@@ -992,7 +993,5 @@ cleanup_parameters:
     g_free(ctx.id_auth);
 
 cleanup:
-    igvm_free(ctx.file);
-
     return retval;
 }
Signature · 1 line
2.52.0
#11 lore raw

PATCH v2 4/5 igvm: add trace points for igvm file loading and processing

In reply to Gerd Hoffmann
---
 backends/igvm.c       | 5 +++++
 backends/trace-events | 2 ++
 2 files changed, 7 insertions(+)
backends/igvm.c +5 -0
index a01e01a12a60..4cf7b572347c 100644
@@ -20,6 +20,8 @@
 #include "system/address-spaces.h"
 #include "hw/core/cpu.h"
 
+#include "trace.h"
+
 #include <igvm/igvm.h>
 #include <igvm/igvm_defs.h>
 
@@ -886,6 +888,8 @@ IgvmHandle qigvm_file_init(char *filename, Error **errp)
         error_setg(errp, "Unable to parse IGVM file %s: %d", filename, igvm);
         return -1;
     }
+
+    trace_igvm_file_loaded(filename, igvm);
     return igvm;
 }
 
@@ -903,6 +907,7 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
         return -1;
     }
     ctx.file = cfg->file;
+    trace_igvm_process_file(cfg->file, onlyVpContext);
 
     /*
      * The ConfidentialGuestSupport object is optional and allows a confidential
backends/trace-events +2 -0
index 45ac46dc2454..7a00e9bf6c16 100644
@@ -26,3 +26,5 @@ iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t data_type, u
 igvm_reset_enter(int type) "type=%u"
 igvm_reset_hold(int type) "type=%u"
 igvm_reset_exit(int type) "type=%u"
+igvm_file_loaded(const char *fn, int32_t handle) "fn=%s, handle=0x%x"
+igvm_process_file(int32_t handle, bool context_only) "handle=0x%x context-only=%d"
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 1/5 igvm: reorganize headers

In reply to Gerd Hoffmann

Add a new igvm-internal.h header file. Structs and declarations which depend on the igvm library header go into that file.

Also declare IgvmCfg in typedefs.h, so the type can be used without including igvm header files.

---
 include/qemu/typedefs.h        |  1 +
 include/system/igvm-cfg.h      | 12 +-----------
 include/system/igvm-internal.h | 26 ++++++++++++++++++++++++++
 include/system/igvm.h          |  2 +-
 backends/igvm-cfg.c            |  4 +++-
 backends/igvm.c                |  2 ++
 6 files changed, 34 insertions(+), 13 deletions(-)
 create mode 100644 include/system/igvm-internal.h
include/qemu/typedefs.h +1 -0
index 4a94af9665a5..416a8c9acead 100644
@@ -55,6 +55,7 @@ typedef struct FWCfgState FWCfgState;
 typedef struct HostMemoryBackend HostMemoryBackend;
 typedef struct I2CBus I2CBus;
 typedef struct I2SCodec I2SCodec;
+typedef struct IgvmCfg IgvmCfg;
 typedef struct IOMMUMemoryRegion IOMMUMemoryRegion;
 typedef struct ISABus ISABus;
 typedef struct ISADevice ISADevice;
include/system/igvm-cfg.h +1 -11
index 944f23a814dd..6c07f3084082 100644
@@ -12,19 +12,9 @@
 #ifndef QEMU_IGVM_CFG_H
 #define QEMU_IGVM_CFG_H
 
+#include "qemu/typedefs.h"
 #include "qom/object.h"
 
-typedef struct IgvmCfg {
-    ObjectClass parent_class;
-
-    /*
-     * filename: Filename that specifies a file that contains the configuration
-     *           of the guest in Independent Guest Virtual Machine (IGVM)
-     *           format.
-     */
-    char *filename;
-} IgvmCfg;
-
 typedef struct IgvmCfgClass {
     ObjectClass parent_class;
 
include/system/igvm-internal.h new file +26 -0
new file mode 100644
index 000000000000..475a29bbf3d7
@@ -0,0 +1,26 @@
+/*
+ * QEMU IGVM private data structures
+ *
+ * Everything which depends on igvm library headers goes here.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_IGVM_INTERNAL_H
+#define QEMU_IGVM_INTERNAL_H
+
+#include "qemu/typedefs.h"
+#include "qom/object.h"
+
+struct IgvmCfg {
+    ObjectClass parent_class;
+
+    /*
+     * filename: Filename that specifies a file that contains the configuration
+     *           of the guest in Independent Guest Virtual Machine (IGVM)
+     *           format.
+     */
+    char *filename;
+};
+
+#endif
include/system/igvm.h +1 -1
index 48ce20604259..8355e54e95fc 100644
@@ -12,8 +12,8 @@
 #ifndef BACKENDS_IGVM_H
 #define BACKENDS_IGVM_H
 
+#include "qemu/typedefs.h"
 #include "system/confidential-guest-support.h"
-#include "system/igvm-cfg.h"
 #include "qapi/error.h"
 
 int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
backends/igvm-cfg.c +3 -1
index d00acf351249..001c4dc93346 100644
@@ -11,8 +11,10 @@
 
 #include "qemu/osdep.h"
 
-#include "system/igvm-cfg.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
+#include "system/reset.h"
 #include "qom/object_interfaces.h"
 
 static char *get_igvm(Object *obj, Error **errp)
backends/igvm.c +2 -0
index 905bd8d98994..fbb8300b6d01 100644
@@ -14,6 +14,8 @@
 #include "qapi/error.h"
 #include "qemu/target-info-qapi.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
 #include "system/memory.h"
 #include "system/address-spaces.h"
 #include "hw/core/cpu.h"
Signature · 1 line
2.52.0
#0 lore raw

v2 cover igvm: rework igvm file loading + processing, fix reset

v2:
- Reorganize igvm headers (new patch #1) to fix build problems in case the igvm library is not present.
- Pick up review tags.

Gerd Hoffmann (5):
igvm: reorganize headers
igvm: make igvm-cfg object resettable
igvm: move file load to complete callback
igvm: add trace points for igvm file loading and processing
igvm: move igvm file processing to reset callbacks

 include/qemu/typedefs.h        |  1 +
 include/system/igvm-cfg.h      | 13 ++-----
 include/system/igvm-internal.h | 32 +++++++++++++++++
 include/system/igvm.h          |  2 +-
 backends/igvm-cfg.c            | 64 ++++++++++++++++++++++++++++++++--
 backends/igvm.c                | 16 ++++++---
 hw/i386/pc_piix.c              | 10 ------
 hw/i386/pc_q35.c               | 10 ------
 backends/trace-events          |  7 ++++
 9 files changed, 116 insertions(+), 39 deletions(-)
 create mode 100644 include/system/igvm-internal.h
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH v2 1/5] igvm: reorganize headers

In reply to Gerd Hoffmann

Hi Gerd,

Quoted 132 lines · Gerd Hoffmann

Add a new igvm-internal.h header file. Structs and declarations which depend on the igvm library header go into that file.

Also declare IgvmCfg in typedefs.h, so the type can be used without including igvm header files.

---

include/qemu/typedefs.h        |  1 +
include/system/igvm-cfg.h      | 12 +-----------
include/system/igvm-internal.h | 26 ++++++++++++++++++++++++++
include/system/igvm.h          |  2 +-
backends/igvm-cfg.c            |  4 +++-
backends/igvm.c                |  2 ++
6 files changed, 34 insertions(+), 13 deletions(-)

create mode 100644 include/system/igvm-internal.h

include/qemu/typedefs.h +1 -0
index 4a94af9665a5..416a8c9acead 100644
@@ -55,6 +55,7 @@ typedef struct FWCfgState FWCfgState;
 typedef struct HostMemoryBackend HostMemoryBackend;
 typedef struct I2CBus I2CBus;
 typedef struct I2SCodec I2SCodec;
+typedef struct IgvmCfg IgvmCfg;
 typedef struct IOMMUMemoryRegion IOMMUMemoryRegion;
 typedef struct ISABus ISABus;
 typedef struct ISADevice ISADevice;
include/system/igvm-cfg.h +1 -11
index 944f23a814dd..6c07f3084082 100644
@@ -12,19 +12,9 @@
 #ifndef QEMU_IGVM_CFG_H
 #define QEMU_IGVM_CFG_H
 
+#include "qemu/typedefs.h"
 #include "qom/object.h"
 
-typedef struct IgvmCfg {
-    ObjectClass parent_class;
-
-    /*
-     * filename: Filename that specifies a file that contains the configuration
-     *           of the guest in Independent Guest Virtual Machine (IGVM)
-     *           format.
-     */
-    char *filename;
-} IgvmCfg;
-
 typedef struct IgvmCfgClass {
    ObjectClass parent_class;
 
include/system/igvm-internal.h new file +26 -0
new file mode 100644
index 000000000000..475a29bbf3d7
@@ -0,0 +1,26 @@
+/*
+ * QEMU IGVM private data structures
+ *
+ * Everything which depends on igvm library headers goes here.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_IGVM_INTERNAL_H
+#define QEMU_IGVM_INTERNAL_H
+
+#include "qemu/typedefs.h"
+#include "qom/object.h"
+
+struct IgvmCfg {
+    ObjectClass parent_class;
+
+    /*
+     * filename: Filename that specifies a file that contains the configuration
+     *           of the guest in Independent Guest Virtual Machine (IGVM)
+     *           format.
+     */
+    char *filename;
+};
+
+#endif
include/system/igvm.h +1 -1
index 48ce20604259..8355e54e95fc 100644
@@ -12,8 +12,8 @@
 #ifndef BACKENDS_IGVM_H
 #define BACKENDS_IGVM_H
 
+#include "qemu/typedefs.h"
 #include "system/confidential-guest-support.h"
-#include "system/igvm-cfg.h"
 #include "qapi/error.h"
 
 int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
backends/igvm-cfg.c +3 -1
index d00acf351249..001c4dc93346 100644
@@ -11,8 +11,10 @@
 
 #include "qemu/osdep.h"
 
-#include "system/igvm-cfg.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
+#include "system/reset.h"
 #include "qom/object_interfaces.h"
 
 static char *get_igvm(Object *obj, Error **errp)
backends/igvm.c +2 -0
index 905bd8d98994..fbb8300b6d01 100644
@@ -14,6 +14,8 @@
 #include "qapi/error.h"
 #include "qemu/target-info-qapi.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
 #include "system/memory.h"
 #include "system/address-spaces.h"
 #include "hw/core/cpu.h"
Signature · 1 line
2.52.0

Should we add igvm-internal.h to the MAINTAINERS file?

Thanks,
Luigi

Reviewed-by on v2 4/5
#12 lore raw

Re: [PATCH v2 4/5] igvm: add trace points for igvm file loading and processing

In reply to Gerd Hoffmann
Quoted 47 lines · Gerd Hoffmann

---
backends/igvm.c | 5 +++++
backends/trace-events | 2 ++

2 files changed, 7 insertions(+)
backends/igvm.c +5 -0
index a01e01a12a60..4cf7b572347c 100644
@@ -20,6 +20,8 @@
 #include "system/address-spaces.h"
 #include "hw/core/cpu.h"
 
+#include "trace.h"
+
 #include <igvm/igvm.h>
 #include <igvm/igvm_defs.h>
 
@@ -886,6 +888,8 @@ IgvmHandle qigvm_file_init(char *filename, Error **errp)
        error_setg(errp, "Unable to parse IGVM file %s: %d", filename, igvm);
        return -1;
    }
+
+    trace_igvm_file_loaded(filename, igvm);
    return igvm;
 }
 
@@ -903,6 +907,7 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
        return -1;
    }
    ctx.file = cfg->file;
+    trace_igvm_process_file(cfg->file, onlyVpContext);
 
    /*
     * The ConfidentialGuestSupport object is optional and allows a confidential
backends/trace-events +0 -0
index 45ac46dc2454..7a00e9bf6c16 100644
@@ -26,3 +26,5 @@ iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t data_type, u

igvm_reset_enter(int type) "type=%u" igvm_reset_hold(int type) "type=%u" igvm_reset_exit(int type) "type=%u"

backends/trace-events iommufd_backend_invalidate_cache(int iommufd, uint32_t id, uint32_t data_type, u

Quoted 3 lines
backends/trace-events +2 -1
+igvm_file_loaded(const char *fn, int32_t handle) "fn=%s, handle=0x%x"
+igvm_process_file(int32_t handle, bool context_only) "handle=0x%x context-only=%d"
-- 2.52.0
Reviewed-by on v2 3/5
#9 lore raw

Re: [PATCH v2 3/5] igvm: move file load to complete callback

In reply to Gerd Hoffmann
Quoted 10 lines · Gerd Hoffmann

Add UserCreatableClass->complete callback function for igvm-cfg object.

Move file loading and parsing of the igvm file from the process function to the new complete() callback function. Keep the igvm file loaded after processing, release it in finalize() instead, so we parse it only once.

LGTM.

Quoted 2 lines
Quoted 119 lines

---

include/system/igvm-internal.h |  5 +++++
backends/igvm-cfg.c            | 18 ++++++++++++++++++
backends/igvm.c                |  9 ++++-----
3 files changed, 27 insertions(+), 5 deletions(-)
include/system/igvm-internal.h +5 -0
index e0452080b127..d378d682b0fb 100644
@@ -12,6 +12,8 @@
 #include "qemu/typedefs.h"
 #include "qom/object.h"
 
+#include <igvm/igvm.h>
+
 struct IgvmCfg {
    ObjectClass parent_class;
 
@@ -21,7 +23,10 @@ struct IgvmCfg {
     *           format.
     */
    char *filename;
+    IgvmHandle file;
    ResettableState reset_state;
 };
 
+IgvmHandle qigvm_file_init(char *filename, Error **errp);
+
 #endif
backends/igvm-cfg.c +18 -0
index e0df3eaa8efd..4014062e0f22 100644
@@ -53,6 +53,13 @@ static void igvm_reset_exit(Object *obj, ResetType type)
    trace_igvm_reset_exit(type);
 }
 
+static void igvm_complete(UserCreatable *uc, Error **errp)
+{
+    IgvmCfg *igvm = IGVM_CFG(uc);
+
+    igvm->file = qigvm_file_init(igvm->filename, errp);
+}
+
 OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT,
                                   { TYPE_USER_CREATABLE },
                                   { TYPE_RESETTABLE_INTERFACE },
@@ -62,6 +69,7 @@ static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
 {
    IgvmCfgClass *igvmc = IGVM_CFG_CLASS(oc);
    ResettableClass *rc = RESETTABLE_CLASS(oc);
+    UserCreatableClass *uc = USER_CREATABLE_CLASS(oc);
 
    object_class_property_add_str(oc, "file", get_igvm, set_igvm);
    object_class_property_set_description(oc, "file",
@@ -73,14 +81,24 @@ static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
    rc->phases.enter = igvm_reset_enter;
    rc->phases.hold = igvm_reset_hold;
    rc->phases.exit = igvm_reset_exit;
+
+    uc->complete = igvm_complete;
 }
 
 static void igvm_cfg_init(Object *obj)
 {
+    IgvmCfg *igvm = IGVM_CFG(obj);
+
+    igvm->file = -1;
    qemu_register_resettable(obj);
 }
 
 static void igvm_cfg_finalize(Object *obj)
 {
+    IgvmCfg *igvm = IGVM_CFG(obj);
+
    qemu_unregister_resettable(obj);
+    if (igvm->file >= 0) {
+        igvm_free(igvm->file);
+    }
 }
backends/igvm.c +4 -3
index fbb8300b6d01..a01e01a12a60 100644
@@ -869,7 +869,7 @@ static int qigvm_handle_policy(QIgvm *ctx, Error **errp)
    return 0;
 }
 
-static IgvmHandle qigvm_file_init(char *filename, Error **errp)
+IgvmHandle qigvm_file_init(char *filename, Error **errp)
 {
    IgvmHandle igvm;
    g_autofree uint8_t *buf = NULL;
@@ -898,10 +898,11 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
    QIgvm ctx;
 
    memset(&ctx, 0, sizeof(ctx));
-    ctx.file = qigvm_file_init(cfg->filename, errp);
-    if (ctx.file < 0) {
+    if (cfg->file < 0) {
+        error_setg(errp, "No IGVM file loaded.");
        return -1;
    }
+    ctx.file = cfg->file;
 
    /*
     * The ConfidentialGuestSupport object is optional and allows a confidential
@@ -992,7 +993,5 @@ cleanup_parameters:
    g_free(ctx.id_auth);
 

cleanup:

backends/igvm.c +0 -2
-    igvm_free(ctx.file);
-
    return retval;

}

Signature · 1 line
2.52.0
#3 lore raw

Re: [PATCH v2 1/5] igvm: reorganize headers

In reply to Luigi Leonardi
Quoted 20 lines · Luigi Leonardi

Hi Gerd,

Quoted 17 lines · Gerd Hoffmann

Add a new igvm-internal.h header file. Structs and declarations which depend on the igvm library header go into that file.

Also declare IgvmCfg in typedefs.h, so the type can be used without including igvm header files.

---

include/qemu/typedefs.h        |  1 +
include/system/igvm-cfg.h      | 12 +-----------
include/system/igvm-internal.h | 26 ++++++++++++++++++++++++++
include/system/igvm.h          |  2 +-
backends/igvm-cfg.c            |  4 +++-
backends/igvm.c                |  2 ++
6 files changed, 34 insertions(+), 13 deletions(-)

create mode 100644 include/system/igvm-internal.h

[...]

Quoted 2 lines

Should we add igvm-internal.h to the MAINTAINERS file?

There is this entry in the MAINTAINERS file:

F: include/system/igvm*.h

It should already cover also the new igvm-internal.h, no?

Thanks,
Stefano

#4 lore raw

Re: [PATCH v2 1/5] igvm: reorganize headers

In reply to Gerd Hoffmann
Quoted 105 lines · Gerd Hoffmann

Add a new igvm-internal.h header file. Structs and declarations which depend on the igvm library header go into that file.

Also declare IgvmCfg in typedefs.h, so the type can be used without including igvm header files.

---

include/qemu/typedefs.h        |  1 +
include/system/igvm-cfg.h      | 12 +-----------
include/system/igvm-internal.h | 26 ++++++++++++++++++++++++++
include/system/igvm.h          |  2 +-
backends/igvm-cfg.c            |  4 +++-
backends/igvm.c                |  2 ++
6 files changed, 34 insertions(+), 13 deletions(-)

create mode 100644 include/system/igvm-internal.h

include/qemu/typedefs.h +1 -0
index 4a94af9665a5..416a8c9acead 100644
@@ -55,6 +55,7 @@ typedef struct FWCfgState FWCfgState;
 typedef struct HostMemoryBackend HostMemoryBackend;
 typedef struct I2CBus I2CBus;
 typedef struct I2SCodec I2SCodec;
+typedef struct IgvmCfg IgvmCfg;
 typedef struct IOMMUMemoryRegion IOMMUMemoryRegion;
 typedef struct ISABus ISABus;
 typedef struct ISADevice ISADevice;
include/system/igvm-cfg.h +1 -11
index 944f23a814dd..6c07f3084082 100644
@@ -12,19 +12,9 @@
 #ifndef QEMU_IGVM_CFG_H
 #define QEMU_IGVM_CFG_H
 
+#include "qemu/typedefs.h"
 #include "qom/object.h"
 
-typedef struct IgvmCfg {
-    ObjectClass parent_class;
-
-    /*
-     * filename: Filename that specifies a file that contains the configuration
-     *           of the guest in Independent Guest Virtual Machine (IGVM)
-     *           format.
-     */
-    char *filename;
-} IgvmCfg;
-
 typedef struct IgvmCfgClass {
    ObjectClass parent_class;
 
include/system/igvm-internal.h new file +26 -0
new file mode 100644
index 000000000000..475a29bbf3d7
@@ -0,0 +1,26 @@
+/*
+ * QEMU IGVM private data structures
+ *
+ * Everything which depends on igvm library headers goes here.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_IGVM_INTERNAL_H
+#define QEMU_IGVM_INTERNAL_H
+
+#include "qemu/typedefs.h"
+#include "qom/object.h"
+
+struct IgvmCfg {
+    ObjectClass parent_class;
+
+    /*
+     * filename: Filename that specifies a file that contains the configuration
+     *           of the guest in Independent Guest Virtual Machine (IGVM)
+     *           format.
+     */
+    char *filename;
+};
+
+#endif
include/system/igvm.h +1 -1
index 48ce20604259..8355e54e95fc 100644
@@ -12,8 +12,8 @@
 #ifndef BACKENDS_IGVM_H
 #define BACKENDS_IGVM_H
 
+#include "qemu/typedefs.h"
 #include "system/confidential-guest-support.h"
-#include "system/igvm-cfg.h"
 #include "qapi/error.h"
 
 int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
backends/igvm-cfg.c +0 -0
index d00acf351249..001c4dc93346 100644

backends/igvm-cfg.c line 17

Quoted 8 lines
backends/igvm-cfg.c +3 -1
@@ -11,8 +11,10 @@
 
 #include "qemu/osdep.h"
 
-#include "system/igvm-cfg.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
+#include "system/reset.h"

Why we need to include "system/reset.h" ?

The rest LGTM.
Stefano

Quoted 19 lines
backends/igvm-cfg.c +0 -0
 #include "qom/object_interfaces.h"
 
 static char *get_igvm(Object *obj, Error **errp)
backends/igvm.c +2 -0
index 905bd8d98994..fbb8300b6d01 100644
@@ -14,6 +14,8 @@
 #include "qapi/error.h"
 #include "qemu/target-info-qapi.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
 #include "system/memory.h"
 #include "system/address-spaces.h"
 #include "hw/core/cpu.h"
Signature · 1 line
2.52.0
Reviewed-by on v2 3/5
#10 lore raw

Re: [PATCH v2 3/5] igvm: move file load to complete callback

In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann

Add UserCreatableClass->complete callback function for igvm-cfg object.

Move file loading and parsing of the igvm file from the process function to the new complete() callback function. Keep the igvm file loaded after processing, release it in finalize() instead, so we parse it only once.

Quoted 6 lines

---

include/system/igvm-internal.h |  5 +++++
backends/igvm-cfg.c            | 18 ++++++++++++++++++
backends/igvm.c                |  9 ++++-----
3 files changed, 27 insertions(+), 5 deletions(-)
Quoted 114 lines
include/system/igvm-internal.h +5 -0
index e0452080b127..d378d682b0fb 100644
@@ -12,6 +12,8 @@
 #include "qemu/typedefs.h"
 #include "qom/object.h"
 
+#include <igvm/igvm.h>
+
 struct IgvmCfg {
    ObjectClass parent_class;
 
@@ -21,7 +23,10 @@ struct IgvmCfg {
     *           format.
     */
    char *filename;
+    IgvmHandle file;
    ResettableState reset_state;
 };
 
+IgvmHandle qigvm_file_init(char *filename, Error **errp);
+
 #endif
backends/igvm-cfg.c +18 -0
index e0df3eaa8efd..4014062e0f22 100644
@@ -53,6 +53,13 @@ static void igvm_reset_exit(Object *obj, ResetType type)
    trace_igvm_reset_exit(type);
 }
 
+static void igvm_complete(UserCreatable *uc, Error **errp)
+{
+    IgvmCfg *igvm = IGVM_CFG(uc);
+
+    igvm->file = qigvm_file_init(igvm->filename, errp);
+}
+
 OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT,
                                   { TYPE_USER_CREATABLE },
                                   { TYPE_RESETTABLE_INTERFACE },
@@ -62,6 +69,7 @@ static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
 {
    IgvmCfgClass *igvmc = IGVM_CFG_CLASS(oc);
    ResettableClass *rc = RESETTABLE_CLASS(oc);
+    UserCreatableClass *uc = USER_CREATABLE_CLASS(oc);
 
    object_class_property_add_str(oc, "file", get_igvm, set_igvm);
    object_class_property_set_description(oc, "file",
@@ -73,14 +81,24 @@ static void igvm_cfg_class_init(ObjectClass *oc, const void *data)
    rc->phases.enter = igvm_reset_enter;
    rc->phases.hold = igvm_reset_hold;
    rc->phases.exit = igvm_reset_exit;
+
+    uc->complete = igvm_complete;
 }
 
 static void igvm_cfg_init(Object *obj)
 {
+    IgvmCfg *igvm = IGVM_CFG(obj);
+
+    igvm->file = -1;
    qemu_register_resettable(obj);
 }
 
 static void igvm_cfg_finalize(Object *obj)
 {
+    IgvmCfg *igvm = IGVM_CFG(obj);
+
    qemu_unregister_resettable(obj);
+    if (igvm->file >= 0) {
+        igvm_free(igvm->file);
+    }
 }
backends/igvm.c +4 -3
index fbb8300b6d01..a01e01a12a60 100644
@@ -869,7 +869,7 @@ static int qigvm_handle_policy(QIgvm *ctx, Error **errp)
    return 0;
 }
 
-static IgvmHandle qigvm_file_init(char *filename, Error **errp)
+IgvmHandle qigvm_file_init(char *filename, Error **errp)
 {
    IgvmHandle igvm;
    g_autofree uint8_t *buf = NULL;
@@ -898,10 +898,11 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
    QIgvm ctx;
 
    memset(&ctx, 0, sizeof(ctx));
-    ctx.file = qigvm_file_init(cfg->filename, errp);
-    if (ctx.file < 0) {
+    if (cfg->file < 0) {
+        error_setg(errp, "No IGVM file loaded.");
        return -1;
    }
+    ctx.file = cfg->file;
 
    /*
     * The ConfidentialGuestSupport object is optional and allows a confidential
@@ -992,7 +993,5 @@ cleanup_parameters:
    g_free(ctx.id_auth);
 

cleanup:

backends/igvm.c +0 -2
-    igvm_free(ctx.file);
-
    return retval;

}

Signature · 1 line
2.52.0
Reviewed-by
#5 lore raw

Re: [PATCH v2 1/5] igvm: reorganize headers

In reply to Stefano Garzarella
Quoted 109 lines · Stefano Garzarella
Quoted 108 lines · Gerd Hoffmann

Add a new igvm-internal.h header file. Structs and declarations which depend on the igvm library header go into that file.

Also declare IgvmCfg in typedefs.h, so the type can be used without including igvm header files.

---

include/qemu/typedefs.h        |  1 +
include/system/igvm-cfg.h      | 12 +-----------
include/system/igvm-internal.h | 26 ++++++++++++++++++++++++++
include/system/igvm.h          |  2 +-
backends/igvm-cfg.c            |  4 +++-
backends/igvm.c                |  2 ++
6 files changed, 34 insertions(+), 13 deletions(-)

create mode 100644 include/system/igvm-internal.h

include/qemu/typedefs.h +1 -0
index 4a94af9665a5..416a8c9acead 100644
@@ -55,6 +55,7 @@ typedef struct FWCfgState FWCfgState;
 typedef struct HostMemoryBackend HostMemoryBackend;
 typedef struct I2CBus I2CBus;
 typedef struct I2SCodec I2SCodec;
+typedef struct IgvmCfg IgvmCfg;
 typedef struct IOMMUMemoryRegion IOMMUMemoryRegion;
 typedef struct ISABus ISABus;
 typedef struct ISADevice ISADevice;
include/system/igvm-cfg.h +1 -11
index 944f23a814dd..6c07f3084082 100644
@@ -12,19 +12,9 @@
 #ifndef QEMU_IGVM_CFG_H
 #define QEMU_IGVM_CFG_H
 
+#include "qemu/typedefs.h"
 #include "qom/object.h"
 
-typedef struct IgvmCfg {
-    ObjectClass parent_class;
-
-    /*
-     * filename: Filename that specifies a file that contains the configuration
-     *           of the guest in Independent Guest Virtual Machine (IGVM)
-     *           format.
-     */
-    char *filename;
-} IgvmCfg;
-
 typedef struct IgvmCfgClass {
   ObjectClass parent_class;
 
include/system/igvm-internal.h new file +26 -0
new file mode 100644
index 000000000000..475a29bbf3d7
@@ -0,0 +1,26 @@
+/*
+ * QEMU IGVM private data structures
+ *
+ * Everything which depends on igvm library headers goes here.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_IGVM_INTERNAL_H
+#define QEMU_IGVM_INTERNAL_H
+
+#include "qemu/typedefs.h"
+#include "qom/object.h"
+
+struct IgvmCfg {
+    ObjectClass parent_class;
+
+    /*
+     * filename: Filename that specifies a file that contains the configuration
+     *           of the guest in Independent Guest Virtual Machine (IGVM)
+     *           format.
+     */
+    char *filename;
+};
+
+#endif
include/system/igvm.h +1 -1
index 48ce20604259..8355e54e95fc 100644
@@ -12,8 +12,8 @@
 #ifndef BACKENDS_IGVM_H
 #define BACKENDS_IGVM_H
 
+#include "qemu/typedefs.h"
 #include "system/confidential-guest-support.h"
-#include "system/igvm-cfg.h"
 #include "qapi/error.h"
 
 int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
backends/igvm-cfg.c +0 -0
index d00acf351249..001c4dc93346 100644
@@ -11,8 +11,10 @@
 
 #include "qemu/osdep.h"
 
Quoted 7 lines

backends/igvm-cfg.c line 17

Quoted 5 lines
backends/igvm-cfg.c +3 -1
-#include "system/igvm-cfg.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
+#include "system/reset.h"

Why we need to include "system/reset.h" ?

BTW it's a minor thing:

Quoted 23 lines

The rest LGTM.
Stefano

Quoted 19 lines
backends/igvm-cfg.c +0 -0
 #include "qom/object_interfaces.h"
 
 static char *get_igvm(Object *obj, Error **errp)
backends/igvm.c +2 -0
index 905bd8d98994..fbb8300b6d01 100644
@@ -14,6 +14,8 @@
 #include "qapi/error.h"
 #include "qemu/target-info-qapi.h"
 #include "system/igvm.h"
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
 #include "system/memory.h"
 #include "system/address-spaces.h"
 #include "hw/core/cpu.h"
Signature · 1 line
2.52.0
#6 lore raw

Re: [PATCH v2 1/5] igvm: reorganize headers

Hi,

Quoted 11 lines
Quoted 7 lines

backends/igvm-cfg.c line 17

Quoted 5 lines

-#include "system/igvm-cfg.h"
#include "system/igvm.h"

backends/igvm-cfg.c +3 -0
+#include "system/igvm-cfg.h"
+#include "system/igvm-internal.h"
+#include "system/reset.h"

Why we need to include "system/reset.h" ?

BTW it's a minor thing:

Landed in 1/5 due to patch reordering, the more correct place would be 2/5 where it'll be actually needed.

take care,
Gerd