qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] igvm: rework igvm file loading + processing, fix reset
@ 2025-12-11 10:54 Gerd Hoffmann
  2025-12-11 10:54 ` [PATCH v2 1/5] igvm: reorganize headers Gerd Hoffmann
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2025-12-11 10:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ani Sinha, Marcel Apfelbaum, Gerd Hoffmann, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost, Luigi Leonardi

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

-- 
2.52.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/5] igvm: reorganize headers
  2025-12-11 10:54 [PATCH v2 0/5] igvm: rework igvm file loading + processing, fix reset Gerd Hoffmann
@ 2025-12-11 10:54 ` Gerd Hoffmann
  2025-12-11 11:13   ` Luigi Leonardi
  2025-12-11 10:54 ` [PATCH v2 2/5] igvm: make igvm-cfg object resettable Gerd Hoffmann
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Gerd Hoffmann @ 2025-12-11 10:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ani Sinha, Marcel Apfelbaum, Gerd Hoffmann, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost, Luigi Leonardi

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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 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

diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 4a94af9665a5..416a8c9acead 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -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;
diff --git a/include/system/igvm-cfg.h b/include/system/igvm-cfg.h
index 944f23a814dd..6c07f3084082 100644
--- a/include/system/igvm-cfg.h
+++ b/include/system/igvm-cfg.h
@@ -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;
 
diff --git a/include/system/igvm-internal.h b/include/system/igvm-internal.h
new file mode 100644
index 000000000000..475a29bbf3d7
--- /dev/null
+++ b/include/system/igvm-internal.h
@@ -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
diff --git a/include/system/igvm.h b/include/system/igvm.h
index 48ce20604259..8355e54e95fc 100644
--- a/include/system/igvm.h
+++ b/include/system/igvm.h
@@ -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,
diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
index d00acf351249..001c4dc93346 100644
--- a/backends/igvm-cfg.c
+++ b/backends/igvm-cfg.c
@@ -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)
diff --git a/backends/igvm.c b/backends/igvm.c
index 905bd8d98994..fbb8300b6d01 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -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"
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/5] igvm: make igvm-cfg object resettable
  2025-12-11 10:54 [PATCH v2 0/5] igvm: rework igvm file loading + processing, fix reset Gerd Hoffmann
  2025-12-11 10:54 ` [PATCH v2 1/5] igvm: reorganize headers Gerd Hoffmann
@ 2025-12-11 10:54 ` Gerd Hoffmann
  2025-12-11 10:54 ` [PATCH v2 3/5] igvm: move file load to complete callback Gerd Hoffmann
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2025-12-11 10:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ani Sinha, Marcel Apfelbaum, Gerd Hoffmann, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost, Luigi Leonardi

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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ani Sinha <anisinha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---
 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(-)

diff --git a/include/system/igvm-cfg.h b/include/system/igvm-cfg.h
index 6c07f3084082..b0380133b9a0 100644
--- a/include/system/igvm-cfg.h
+++ b/include/system/igvm-cfg.h
@@ -14,6 +14,7 @@
 
 #include "qemu/typedefs.h"
 #include "qom/object.h"
+#include "hw/resettable.h"
 
 typedef struct IgvmCfgClass {
     ObjectClass parent_class;
diff --git a/include/system/igvm-internal.h b/include/system/igvm-internal.h
index 475a29bbf3d7..e0452080b127 100644
--- a/include/system/igvm-internal.h
+++ b/include/system/igvm-internal.h
@@ -21,6 +21,7 @@ struct IgvmCfg {
      *           format.
      */
     char *filename;
+    ResettableState reset_state;
 };
 
 #endif
diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
index 001c4dc93346..e0df3eaa8efd 100644
--- a/backends/igvm-cfg.c
+++ b/backends/igvm-cfg.c
@@ -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);
 }
diff --git a/backends/trace-events b/backends/trace-events
index 56132d3fd22b..45ac46dc2454 100644
--- a/backends/trace-events
+++ b/backends/trace-events
@@ -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"
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/5] igvm: move file load to complete callback
  2025-12-11 10:54 [PATCH v2 0/5] igvm: rework igvm file loading + processing, fix reset Gerd Hoffmann
  2025-12-11 10:54 ` [PATCH v2 1/5] igvm: reorganize headers Gerd Hoffmann
  2025-12-11 10:54 ` [PATCH v2 2/5] igvm: make igvm-cfg object resettable Gerd Hoffmann
@ 2025-12-11 10:54 ` Gerd Hoffmann
  2025-12-11 11:39   ` Ani Sinha
  2025-12-11 10:54 ` [PATCH v2 4/5] igvm: add trace points for igvm file loading and processing Gerd Hoffmann
  2025-12-11 10:54 ` [PATCH v2 5/5] igvm: move igvm file processing to reset callbacks Gerd Hoffmann
  4 siblings, 1 reply; 9+ messages in thread
From: Gerd Hoffmann @ 2025-12-11 10:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ani Sinha, Marcel Apfelbaum, Gerd Hoffmann, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost, Luigi Leonardi

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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/system/igvm-internal.h |  5 +++++
 backends/igvm-cfg.c            | 18 ++++++++++++++++++
 backends/igvm.c                |  9 ++++-----
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/include/system/igvm-internal.h b/include/system/igvm-internal.h
index e0452080b127..d378d682b0fb 100644
--- a/include/system/igvm-internal.h
+++ b/include/system/igvm-internal.h
@@ -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
diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
index e0df3eaa8efd..4014062e0f22 100644
--- a/backends/igvm-cfg.c
+++ b/backends/igvm-cfg.c
@@ -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);
+    }
 }
diff --git a/backends/igvm.c b/backends/igvm.c
index fbb8300b6d01..a01e01a12a60 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -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;
 }
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/5] igvm: add trace points for igvm file loading and processing
  2025-12-11 10:54 [PATCH v2 0/5] igvm: rework igvm file loading + processing, fix reset Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2025-12-11 10:54 ` [PATCH v2 3/5] igvm: move file load to complete callback Gerd Hoffmann
@ 2025-12-11 10:54 ` Gerd Hoffmann
  2025-12-11 11:32   ` Luigi Leonardi
  2025-12-11 10:54 ` [PATCH v2 5/5] igvm: move igvm file processing to reset callbacks Gerd Hoffmann
  4 siblings, 1 reply; 9+ messages in thread
From: Gerd Hoffmann @ 2025-12-11 10:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ani Sinha, Marcel Apfelbaum, Gerd Hoffmann, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost, Luigi Leonardi

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ani Sinha <anisinha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---
 backends/igvm.c       | 5 +++++
 backends/trace-events | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/backends/igvm.c b/backends/igvm.c
index a01e01a12a60..4cf7b572347c 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -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
diff --git a/backends/trace-events b/backends/trace-events
index 45ac46dc2454..7a00e9bf6c16 100644
--- a/backends/trace-events
+++ b/backends/trace-events
@@ -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"
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/5] igvm: move igvm file processing to reset callbacks
  2025-12-11 10:54 [PATCH v2 0/5] igvm: rework igvm file loading + processing, fix reset Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2025-12-11 10:54 ` [PATCH v2 4/5] igvm: add trace points for igvm file loading and processing Gerd Hoffmann
@ 2025-12-11 10:54 ` Gerd Hoffmann
  4 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2025-12-11 10:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ani Sinha, Marcel Apfelbaum, Gerd Hoffmann, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost, Luigi Leonardi

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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ani Sinha <anisinha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---
 backends/igvm-cfg.c |  7 +++++++
 hw/i386/pc_piix.c   | 10 ----------
 hw/i386/pc_q35.c    | 10 ----------
 3 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
index 4014062e0f22..8c77db8c57c6 100644
--- a/backends/igvm-cfg.c
+++ b/backends/igvm-cfg.c
@@ -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)
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 7b3611e973cd..b3b71df64bfc 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -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 {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 6015e639d7bc..f2e6ebfe294c 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -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) \
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/5] igvm: reorganize headers
  2025-12-11 10:54 ` [PATCH v2 1/5] igvm: reorganize headers Gerd Hoffmann
@ 2025-12-11 11:13   ` Luigi Leonardi
  0 siblings, 0 replies; 9+ messages in thread
From: Luigi Leonardi @ 2025-12-11 11:13 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: qemu-devel, Ani Sinha, Marcel Apfelbaum, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost

Hi Gerd,

On Thu, Dec 11, 2025 at 11:54:15AM +0100, Gerd Hoffmann wrote:
>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.
>
>Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>---
> 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
>
>diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
>index 4a94af9665a5..416a8c9acead 100644
>--- a/include/qemu/typedefs.h
>+++ b/include/qemu/typedefs.h
>@@ -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;
>diff --git a/include/system/igvm-cfg.h b/include/system/igvm-cfg.h
>index 944f23a814dd..6c07f3084082 100644
>--- a/include/system/igvm-cfg.h
>+++ b/include/system/igvm-cfg.h
>@@ -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;
>
>diff --git a/include/system/igvm-internal.h b/include/system/igvm-internal.h
>new file mode 100644
>index 000000000000..475a29bbf3d7
>--- /dev/null
>+++ b/include/system/igvm-internal.h
>@@ -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
>diff --git a/include/system/igvm.h b/include/system/igvm.h
>index 48ce20604259..8355e54e95fc 100644
>--- a/include/system/igvm.h
>+++ b/include/system/igvm.h
>@@ -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,
>diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
>index d00acf351249..001c4dc93346 100644
>--- a/backends/igvm-cfg.c
>+++ b/backends/igvm-cfg.c
>@@ -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)
>diff --git a/backends/igvm.c b/backends/igvm.c
>index 905bd8d98994..fbb8300b6d01 100644
>--- a/backends/igvm.c
>+++ b/backends/igvm.c
>@@ -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"
>-- 
>2.52.0
>

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

Thanks,
Luigi



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 4/5] igvm: add trace points for igvm file loading and processing
  2025-12-11 10:54 ` [PATCH v2 4/5] igvm: add trace points for igvm file loading and processing Gerd Hoffmann
@ 2025-12-11 11:32   ` Luigi Leonardi
  0 siblings, 0 replies; 9+ messages in thread
From: Luigi Leonardi @ 2025-12-11 11:32 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: qemu-devel, Ani Sinha, Marcel Apfelbaum, Michael S. Tsirkin,
	Stefano Garzarella, Paolo Bonzini, Oliver Steffen,
	Richard Henderson, Eduardo Habkost

On Thu, Dec 11, 2025 at 11:54:18AM +0100, Gerd Hoffmann wrote:
>Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>Reviewed-by: Ani Sinha <anisinha@redhat.com>
>Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
>---
> backends/igvm.c       | 5 +++++
> backends/trace-events | 2 ++
> 2 files changed, 7 insertions(+)
>
>diff --git a/backends/igvm.c b/backends/igvm.c
>index a01e01a12a60..4cf7b572347c 100644
>--- a/backends/igvm.c
>+++ b/backends/igvm.c
>@@ -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
>diff --git a/backends/trace-events b/backends/trace-events
>index 45ac46dc2454..7a00e9bf6c16 100644
>--- a/backends/trace-events
>+++ b/backends/trace-events
>@@ -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"
>-- 2.52.0
>

Reviewed-by: Luigi Leonardi <leonardi@redhat.com>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/5] igvm: move file load to complete callback
  2025-12-11 10:54 ` [PATCH v2 3/5] igvm: move file load to complete callback Gerd Hoffmann
@ 2025-12-11 11:39   ` Ani Sinha
  0 siblings, 0 replies; 9+ messages in thread
From: Ani Sinha @ 2025-12-11 11:39 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: qemu-devel, Marcel Apfelbaum, Michael Tsirkin, Stefano Garzarella,
	Paolo Bonzini, Oliver Steffen, Richard Henderson, Eduardo Habkost,
	Luigi Leonardi



> On 11 Dec 2025, at 4:24 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> 
> 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.

> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Reviewed-by: Ani Sinha <anisinha@redhat.com>

> ---
> include/system/igvm-internal.h |  5 +++++
> backends/igvm-cfg.c            | 18 ++++++++++++++++++
> backends/igvm.c                |  9 ++++-----
> 3 files changed, 27 insertions(+), 5 deletions(-)
> 
> diff --git a/include/system/igvm-internal.h b/include/system/igvm-internal.h
> index e0452080b127..d378d682b0fb 100644
> --- a/include/system/igvm-internal.h
> +++ b/include/system/igvm-internal.h
> @@ -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
> diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
> index e0df3eaa8efd..4014062e0f22 100644
> --- a/backends/igvm-cfg.c
> +++ b/backends/igvm-cfg.c
> @@ -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);
> +    }
> }
> diff --git a/backends/igvm.c b/backends/igvm.c
> index fbb8300b6d01..a01e01a12a60 100644
> --- a/backends/igvm.c
> +++ b/backends/igvm.c
> @@ -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;
> }
> -- 
> 2.52.0
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-12-11 11:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11 10:54 [PATCH v2 0/5] igvm: rework igvm file loading + processing, fix reset Gerd Hoffmann
2025-12-11 10:54 ` [PATCH v2 1/5] igvm: reorganize headers Gerd Hoffmann
2025-12-11 11:13   ` Luigi Leonardi
2025-12-11 10:54 ` [PATCH v2 2/5] igvm: make igvm-cfg object resettable Gerd Hoffmann
2025-12-11 10:54 ` [PATCH v2 3/5] igvm: move file load to complete callback Gerd Hoffmann
2025-12-11 11:39   ` Ani Sinha
2025-12-11 10:54 ` [PATCH v2 4/5] igvm: add trace points for igvm file loading and processing Gerd Hoffmann
2025-12-11 11:32   ` Luigi Leonardi
2025-12-11 10:54 ` [PATCH v2 5/5] igvm: move igvm file processing to reset callbacks Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).