From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>,
Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>,
Juraj Marcin <jmarcin@redhat.com>
Subject: [PULL 30/43] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers
Date: Thu, 23 Apr 2026 16:19:44 -0300 [thread overview]
Message-ID: <20260423191958.1440-31-farosas@suse.de> (raw)
In-Reply-To: <20260423191958.1440-1-farosas@suse.de>
From: Peter Xu <peterx@redhat.com>
We used to have one vmstate called "nullptr" which is only used to generate
one-byte hint to say one pointer is NULL.
Let's extend its use so that it will generate another byte to say the
pointer is non-NULL.
With that, the name of the info struct (or functions) do not apply anymore.
Update correspondingly.
Update analyze-migration.py to work with the new layout.
No functional change intended yet.
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Juraj Marcin <jmarcin@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260401202844.673494-8-peterx@redhat.com
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
include/migration/vmstate.h | 9 +++++++--
migration/vmstate-types.c | 34 ++++++++++++++++------------------
migration/vmstate.c | 25 +++++++++++++------------
scripts/analyze-migration.py | 22 ++++++++++++----------
4 files changed, 48 insertions(+), 42 deletions(-)
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 7396e38531..492069b8d2 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -282,9 +282,14 @@ extern const VMStateInfo vmstate_info_uint32;
extern const VMStateInfo vmstate_info_uint64;
extern const VMStateInfo vmstate_info_fd;
-/** Put this in the stream when migrating a null pointer.*/
+/*
+ * Put this in the stream when migrating a pointer to reflect either a NULL
+ * or valid pointer.
+ */
#define VMS_MARKER_PTR_NULL (0x30U) /* '0' */
-extern const VMStateInfo vmstate_info_nullptr;
+#define VMS_MARKER_PTR_VALID (0x31U) /* '1' */
+
+extern const VMStateInfo vmstate_info_ptr_marker;
extern const VMStateInfo vmstate_info_cpudouble;
diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c
index 7622cf8f01..b31689fc3c 100644
--- a/migration/vmstate-types.c
+++ b/migration/vmstate-types.c
@@ -359,36 +359,34 @@ const VMStateInfo vmstate_info_fd = {
.save = save_fd,
};
-static bool load_nullptr(QEMUFile *f, void *pv, size_t size,
- const VMStateField *field, Error **errp)
+static bool load_ptr_marker(QEMUFile *f, void *pv, size_t size,
+ const VMStateField *field, Error **errp)
{
- if (qemu_get_byte(f) == VMS_MARKER_PTR_NULL) {
+ int byte = qemu_get_byte(f);
+
+ if (byte == VMS_MARKER_PTR_NULL || byte == VMS_MARKER_PTR_VALID) {
+ /* TODO: process PTR_VALID case */
return true;
}
- error_setg(errp, "vmstate: load_nullptr expected VMS_NULLPTR_MARKER");
+ error_setg(errp, "%s: unexpected ptr marker: %d", __func__, byte);
return false;
}
-static bool save_nullptr(QEMUFile *f, void *pv, size_t size,
- const VMStateField *field, JSONWriter *vmdesc,
- Error **errp)
+static bool save_ptr_marker(QEMUFile *f, void *pv, size_t size,
+ const VMStateField *field, JSONWriter *vmdesc,
+ Error **errp)
{
- if (pv == NULL) {
- qemu_put_byte(f, VMS_MARKER_PTR_NULL);
- return true;
- }
-
- error_setg(errp, "vmstate: save_nullptr must be called with pv == NULL");
- return false;
+ qemu_put_byte(f, pv ? VMS_MARKER_PTR_VALID : VMS_MARKER_PTR_NULL);
+ return true;
}
-const VMStateInfo vmstate_info_nullptr = {
- .name = "nullptr",
- .load = load_nullptr,
- .save = save_nullptr,
+const VMStateInfo vmstate_info_ptr_marker = {
+ .name = "ptr-marker",
+ .load = load_ptr_marker,
+ .save = save_ptr_marker,
};
/* 64 bit unsigned int. See that the received value is the same than the one
diff --git a/migration/vmstate.c b/migration/vmstate.c
index b274204e66..b333aa1744 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -55,12 +55,12 @@ vmstate_field_exists(const VMStateDescription *vmsd, const VMStateField *field,
}
/*
- * Create a fake nullptr field when there's a NULL pointer detected in the
+ * Create a ptr marker field when there's a NULL pointer detected in the
* array of a VMS_ARRAY_OF_POINTER VMSD field. It's needed because we
* can't dereference the NULL pointer.
*/
static const VMStateField *
-vmsd_create_fake_nullptr_field(const VMStateField *field)
+vmsd_create_ptr_marker_field(const VMStateField *field)
{
VMStateField *fake = g_new0(VMStateField, 1);
@@ -71,12 +71,12 @@ vmsd_create_fake_nullptr_field(const VMStateField *field)
fake->name = field->name;
fake->version_id = field->version_id;
- /* Do not need "field_exists" check as it always exists (which is null) */
+ /* Do not need "field_exists" check as it always exists */
fake->field_exists = NULL;
- /* See vmstate_info_nullptr - use 1 byte to represent nullptr */
+ /* See vmstate_info_ptr_marker - use 1 byte to represent ptr status */
fake->size = 1;
- fake->info = &vmstate_info_nullptr;
+ fake->info = &vmstate_info_ptr_marker;
fake->flags = VMS_SINGLE;
/* All the rest fields shouldn't matter.. */
@@ -278,7 +278,7 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,
* an array of pointers), use null placeholder and do
* not follow.
*/
- inner_field = vmsd_create_fake_nullptr_field(field);
+ inner_field = vmsd_create_ptr_marker_field(field);
} else {
inner_field = field;
}
@@ -583,26 +583,27 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
for (i = 0; i < n_elems; i++) {
void *curr_elem = first_elem + size * i;
const VMStateField *inner_field;
- bool is_null;
/* maximum number of elements to compress in the JSON blob */
int max_elems = vmsd_can_compress(field) ? (n_elems - i) : 1;
+ bool use_marker_field, is_null;
if (field->flags & VMS_ARRAY_OF_POINTER) {
assert(curr_elem);
curr_elem = *(void **)curr_elem;
}
- if (!curr_elem && size) {
+ is_null = !curr_elem && size;
+ use_marker_field = is_null;
+
+ if (use_marker_field) {
/*
* If null pointer found (which should only happen in
* an array of pointers), use null placeholder and do
* not follow.
*/
- inner_field = vmsd_create_fake_nullptr_field(field);
- is_null = true;
+ inner_field = vmsd_create_ptr_marker_field(field);
} else {
inner_field = field;
- is_null = false;
}
/*
@@ -638,7 +639,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
i, max_elems, errp);
/* If we used a fake temp field.. free it now */
- if (is_null) {
+ if (use_marker_field) {
g_clear_pointer((gpointer *)&inner_field, g_free);
}
diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
index e81deab8f9..1771ff781b 100755
--- a/scripts/analyze-migration.py
+++ b/scripts/analyze-migration.py
@@ -469,26 +469,26 @@ def __init__(self, desc, file):
super(VMSDFieldIntLE, self).__init__(desc, file)
self.dtype = '<i%d' % self.size
-class VMSDFieldNull(VMSDFieldGeneric):
+class VMSDFieldPtrMarker(VMSDFieldGeneric):
NULL_PTR_MARKER = b'0'
+ VALID_PTR_MARKER = b'1'
def __init__(self, desc, file):
- super(VMSDFieldNull, self).__init__(desc, file)
+ super(VMSDFieldPtrMarker, self).__init__(desc, file)
def __repr__(self):
- # A NULL pointer is encoded in the stream as a '0' to
- # disambiguate from a mere 0x0 value and avoid consumers
- # trying to follow the NULL pointer. Displaying '0', 0x30 or
- # 0x0 when analyzing the JSON debug stream could become
+ # A NULL / non-NULL pointer may be encoded in the stream as a
+ # '0'/'1' to represent the status of the pointer. Displaying '0',
+ # 0x30 or 0x0 when analyzing the JSON debug stream could become
# confusing, so use an explicit term instead.
- return "nullptr"
+ return "null-ptr" if self.data == self.NULL_PTR_MARKER else "valid-ptr"
def __str__(self):
return self.__repr__()
def read(self):
- super(VMSDFieldNull, self).read()
- assert(self.data == self.NULL_PTR_MARKER)
+ super(VMSDFieldPtrMarker, self).read()
+ assert(self.data in [self.NULL_PTR_MARKER, self.VALID_PTR_MARKER])
return self.data
class VMSDFieldBool(VMSDFieldGeneric):
@@ -642,7 +642,9 @@ def getDict(self):
"bitmap" : VMSDFieldGeneric,
"struct" : VMSDFieldStruct,
"capability": VMSDFieldCap,
- "nullptr": VMSDFieldNull,
+ # Keep the old nullptr for old binaries
+ "nullptr": VMSDFieldPtrMarker,
+ "ptr-marker": VMSDFieldPtrMarker,
"unknown" : VMSDFieldGeneric,
}
--
2.51.0
next prev parent reply other threads:[~2026-04-23 19:24 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 19:19 [PULL 00/43] Migration patches for 2026-04-23 Fabiano Rosas
2026-04-23 19:19 ` [PULL 01/43] checkpatch: Allow spaces after all coroutine annotations Fabiano Rosas
2026-04-23 19:19 ` [PULL 02/43] tests/functional: Make socat wait longer in migration exec test Fabiano Rosas
2026-04-23 19:19 ` [PULL 03/43] migration: vmstate_save_state_v: fix double error_setg Fabiano Rosas
2026-04-23 19:19 ` [PULL 04/43] migration: make vmstate_save_state_v() static Fabiano Rosas
2026-04-23 19:19 ` [PULL 05/43] migration: make .post_save() a void function Fabiano Rosas
2026-04-23 19:19 ` [PULL 06/43] migration: vmstate_load_state(): add some newlines Fabiano Rosas
2026-04-23 19:19 ` [PULL 07/43] migration: vmstate_save/load_state(): refactor tracing errors Fabiano Rosas
2026-04-23 19:19 ` [PULL 08/43] migration: factor out vmstate_pre_save() from vmstate_save_state() Fabiano Rosas
2026-04-23 19:19 ` [PULL 09/43] migration: factor out vmstate_save_field() " Fabiano Rosas
2026-04-23 19:19 ` [PULL 10/43] migration: factor out vmstate_pre_load() from vmstate_load_state() Fabiano Rosas
2026-04-23 19:19 ` [PULL 11/43] migration: factor out vmstate_load_field() " Fabiano Rosas
2026-04-23 19:19 ` [PULL 12/43] migration: factor out vmstate_post_load() " Fabiano Rosas
2026-04-23 19:19 ` [PULL 13/43] migration: convert vmstate_subsection_save/load functions to bool Fabiano Rosas
2026-04-23 19:19 ` [PULL 14/43] migration: VMStateInfo: introduce new handlers with errp Fabiano Rosas
2026-04-23 19:19 ` [PULL 15/43] migration: introduce vmstate_load_vmsd() and vmstate_save_vmsd() Fabiano Rosas
2026-04-23 19:19 ` [PULL 16/43] migration/cpr: move to new migration APIs Fabiano Rosas
2026-04-23 19:19 ` [PULL 17/43] migration/savevm: " Fabiano Rosas
2026-04-23 19:19 ` [PULL 18/43] hw/s390x/css: drop use of .err_hint for vmstate Fabiano Rosas
2026-04-23 19:19 ` [PULL 19/43] migration: drop VMStateField.err_hint Fabiano Rosas
2026-04-23 19:19 ` [PULL 20/43] migration/vmstate-types: move to new migration APIs Fabiano Rosas
2026-04-23 19:19 ` [PULL 21/43] migration: Tweak description of migration property multifd-compression Fabiano Rosas
2026-04-23 19:19 ` [PULL 22/43] tests/qtest/migration: Add mapped-ram/postcopy validation test Fabiano Rosas
2026-04-23 19:19 ` [PULL 23/43] migration: fix QIOChannelFile leak on error in file_connect_outgoing Fabiano Rosas
2026-04-23 19:19 ` [PULL 24/43] vmstate: Pass in struct itself for VMSTATE_ARRAY_OF_POINTER Fabiano Rosas
2026-04-23 19:19 ` [PULL 25/43] vmstate: Pass in struct itself for VMSTATE_VARRAY_OF_POINTER_UINT32 Fabiano Rosas
2026-04-23 19:19 ` [PULL 26/43] vmstate: Do not set size for VMS_ARRAY_OF_POINTER Fabiano Rosas
2026-04-23 19:19 ` [PULL 27/43] vmstate: Update max_elems early and check field compressable once Fabiano Rosas
2026-04-23 19:19 ` [PULL 28/43] vmstate: Rename VMS_NULLPTR_MARKER to VMS_MARKER_PTR_NULL Fabiano Rosas
2026-04-23 19:19 ` [PULL 29/43] vmstate: Introduce vmstate_save_field_with_vmdesc() Fabiano Rosas
2026-04-23 19:19 ` Fabiano Rosas [this message]
2026-04-23 19:19 ` [PULL 31/43] vmstate: Implement load of ptr marker in vmstate core Fabiano Rosas
2026-04-23 19:19 ` [PULL 32/43] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Fabiano Rosas
2026-04-23 19:19 ` [PULL 33/43] vmstate: Stop checking size for nullptr compression Fabiano Rosas
2026-04-23 19:19 ` [PULL 34/43] tests/unit/test-vmstate: add tests for VMS_ARRAY_OF_POINTER_AUTO_ALLOC Fabiano Rosas
2026-04-23 19:19 ` [PULL 35/43] migration: validate page_size in mapped-ram header before use Fabiano Rosas
2026-04-23 19:19 ` [PULL 36/43] io/channel: introduce qio_channel_pread{v, }_all{, _eof}() Fabiano Rosas
2026-04-23 19:19 ` [PULL 37/43] io/channel: introduce qio_channel_pwrite{v,}_all() Fabiano Rosas
2026-04-23 19:19 ` [PULL 38/43] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data Fabiano Rosas
2026-04-23 19:19 ` [PULL 39/43] tests/unit: add pread/pwrite _all tests for io channel file Fabiano Rosas
2026-04-23 19:19 ` [PULL 40/43] tests/qtest/migration: fix fd leak in ufd_version_check Fabiano Rosas
2026-04-23 19:19 ` [PULL 41/43] migration/qemu-file: switch buffer_at functions to positioned I/O _all helpers Fabiano Rosas
2026-04-23 19:19 ` [PULL 42/43] migration/file: switch file_write_ramblock_iov to pwritev_all Fabiano Rosas
2026-04-23 19:19 ` [PULL 43/43] migration/qemu-file: drop incorrect const from qemu_get_buffer_at buf Fabiano Rosas
2026-04-25 16:58 ` [PULL 00/43] Migration patches for 2026-04-23 Stefan Hajnoczi
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=20260423191958.1440-31-farosas@suse.de \
--to=farosas@suse.de \
--cc=aleksandr.mikhalitsyn@futurfusion.io \
--cc=jmarcin@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.