From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Xu" <peterx@redhat.com>,
"Alexander Mikhalitsyn" <aleksandr.mikhalitsyn@futurfusion.io>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Juraj Marcin" <jmarcin@redhat.com>
Subject: [PULL 26/43] vmstate: Do not set size for VMS_ARRAY_OF_POINTER
Date: Thu, 23 Apr 2026 16:19:40 -0300 [thread overview]
Message-ID: <20260423191958.1440-27-farosas@suse.de> (raw)
In-Reply-To: <20260423191958.1440-1-farosas@suse.de>
From: Peter Xu <peterx@redhat.com>
When VMS_ARRAY_OF_POINTER is specified, it means the vmstate field is an
array of pointers.
The size of the element is not relevant to whatever it is stored inside: it
is always the host pointer size.
Let's reserve the "size" field in this case for future use, update
vmstate_size() so as to make it still work for array of pointers properly.
When at this, provide rich documentation on how size / size_offset works in
vmstate.
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Juraj Marcin <jmarcin@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260401202844.673494-4-peterx@redhat.com
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
include/migration/vmstate.h | 20 ++++++++++++++++----
migration/savevm.c | 3 +++
migration/vmstate.c | 10 +++++++++-
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 32bb8e8ebc..350e62a55a 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -183,11 +183,26 @@ typedef enum {
struct VMStateField {
const char *name;
size_t offset;
+
+ /*
+ * @size or @size_offset specifies the size of the element embeded in
+ * the field. Only one of them should be present never both. When
+ * @size_offset is used together with VMS_VBUFFER, it means the size is
+ * dynamic calculated instead of a constant.
+ *
+ * When the field is an array of any type, this stores the size of one
+ * element of the array.
+ *
+ * NOTE: even if VMS_POINTER or VMS_ARRAY_OF_POINTER may be specified,
+ * this parameter always reflects the real size of the objects that a
+ * pointer point to.
+ */
size_t size;
+ size_t size_offset;
+
size_t start;
int num;
size_t num_offset;
- size_t size_offset;
const VMStateInfo *info;
enum VMStateFlags flags;
const VMStateDescription *vmsd;
@@ -547,7 +562,6 @@ extern const VMStateInfo vmstate_info_qlist;
.version_id = (_version), \
.num = (_num), \
.info = &(_info), \
- .size = sizeof(_type *), \
.flags = VMS_ARRAY|VMS_ARRAY_OF_POINTER, \
.offset = vmstate_offset_array(_state, _field, _type *, _num), \
}
@@ -557,7 +571,6 @@ extern const VMStateInfo vmstate_info_qlist;
.version_id = (_v), \
.num = (_n), \
.vmsd = &(_vmsd), \
- .size = sizeof(_type *), \
.flags = VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \
.offset = vmstate_offset_array(_s, _f, _type*, _n), \
}
@@ -567,7 +580,6 @@ extern const VMStateInfo vmstate_info_qlist;
.version_id = (_version), \
.num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \
.info = &(_info), \
- .size = sizeof(_type *), \
.flags = VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER, \
.offset = vmstate_offset_pointer(_state, _field, _type *), \
}
diff --git a/migration/savevm.c b/migration/savevm.c
index 8115203b51..f5a6fd0c66 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -868,6 +868,9 @@ static void vmstate_check(const VMStateDescription *vmsd)
if (field) {
while (field->name) {
+ if (field->flags & VMS_ARRAY_OF_POINTER) {
+ assert(field->size == 0);
+ }
if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) {
/* Recurse to sub structures */
vmstate_check(field->vmsd);
diff --git a/migration/vmstate.c b/migration/vmstate.c
index e98b5f5346..e29a8c3f49 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -110,13 +110,21 @@ static int vmstate_n_elems(void *opaque, const VMStateField *field)
static int vmstate_size(void *opaque, const VMStateField *field)
{
- int size = field->size;
+ int size;
if (field->flags & VMS_VBUFFER) {
size = *(int32_t *)(opaque + field->size_offset);
if (field->flags & VMS_MULTIPLY) {
size *= field->size;
}
+ } else if (field->flags & VMS_ARRAY_OF_POINTER) {
+ /*
+ * For an array of pointer, the each element is always size of a
+ * host pointer.
+ */
+ size = sizeof(void *);
+ } else {
+ size = field->size;
}
return size;
--
2.51.0
next prev parent reply other threads:[~2026-04-23 19:22 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 ` Fabiano Rosas [this message]
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 ` [PULL 30/43] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers Fabiano Rosas
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-27-farosas@suse.de \
--to=farosas@suse.de \
--cc=aleksandr.mikhalitsyn@futurfusion.io \
--cc=jmarcin@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--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.