From: Ani Sinha <anisinha@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Ani Sinha <anisinha@redhat.com>
Cc: ani@anisinha.ca, agraf@csgraf.de, graf@amazon.com, qemu-devel@nongnu.org
Subject: [PATCH v6 03/11] igvm: cleanup memory regions
Date: Mon, 17 Aug 2026 19:49:58 +0530 [thread overview]
Message-ID: <20260817142010.80693-4-anisinha@redhat.com> (raw)
In-Reply-To: <20260817142010.80693-1-anisinha@redhat.com>
From: Gerd Hoffmann <kraxel@redhat.com>
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.
Reviewed-by: Alexander Graf <graf@amazon.com>
Tested-by: Ani Sinha <anisinha@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
backends/igvm-cfg.c | 2 ++
backends/igvm.c | 19 +++++++++++++++++++
include/system/igvm.h | 1 +
3 files changed, 22 insertions(+)
diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
index 38438a7b1e..935ba54f54 100644
--- a/backends/igvm-cfg.c
+++ b/backends/igvm-cfg.c
@@ -52,6 +52,8 @@ static void igvm_reset_hold(Object *obj, ResetType type)
trace_igvm_reset_hold(type);
+ /* cleanup existing memory regions first */
+ qigvm_cleanup_memory(igvm);
qigvm_process_file(igvm, ms, false, &error_fatal);
}
diff --git a/backends/igvm.c b/backends/igvm.c
index 9e7c90d386..9b101c8182 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -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"
@@ -1109,3 +1110,21 @@ 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);
+ /* this triggers MemoryRegion cleanup */
+ object_unparent(OBJECT(imr->mr));
+ g_free(imr);
+ }
+}
diff --git a/include/system/igvm.h b/include/system/igvm.h
index 64d3542311..e219f1a4ed 100644
--- a/include/system/igvm.h
+++ b/include/system/igvm.h
@@ -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,
--
2.42.0
next prev parent reply other threads:[~2026-08-17 14:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 14:19 [PATCH v6 00/11] Introducing guest driven VM launch update mechanism (BYOF interface) Ani Sinha
2026-08-17 14:19 ` [PATCH v6 01/11] igvm: store IgvmCfg pointer in QIgvm Ani Sinha
2026-08-17 14:19 ` [PATCH v6 02/11] igvm: track memory regions Ani Sinha
2026-08-17 14:19 ` Ani Sinha [this message]
2026-08-17 14:19 ` [PATCH v6 04/11] system/memory: add a tracepoint for memory_region_finalize Ani Sinha
2026-08-17 14:20 ` [PATCH v6 05/11] backends/igvm: add a tracepoint for qigvm_cleanup_memory Ani Sinha
2026-08-17 14:20 ` [PATCH v6 06/11] hw/misc/vmlaunchupdate: add api header Ani Sinha
2026-08-18 9:22 ` Gerd Hoffman
2026-08-19 4:31 ` Ani Sinha
2026-08-17 14:20 ` [PATCH v6 07/11] hw/misc/vmlaunchupdate: Introduce hypervisor fw-cfg interface support Ani Sinha
2026-08-17 14:20 ` [PATCH v6 08/11] docs/spec: Add a specification document for vm-launch-update device Ani Sinha
2026-08-17 14:20 ` [PATCH v6 09/11] tests/qtest: Add small igvm files for testing purpose Ani Sinha
2026-08-17 14:20 ` [PATCH v6 10/11] Add functional and unit tests for the vm-launch-update device Ani Sinha
2026-08-17 14:20 ` [PATCH v6 11/11] Update MAINTAINERS Ani Sinha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260817142010.80693-4-anisinha@redhat.com \
--to=anisinha@redhat.com \
--cc=agraf@csgraf.de \
--cc=ani@anisinha.ca \
--cc=graf@amazon.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.