public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org,
	Alexander Mikhalitsyn <alexander@mihalicyn.com>,
	Juraj Marcin <jmarcin@redhat.com>
Subject: Re: [RFC PATCH v1 05/17] vmstate: Remove vmdesc_loop
Date: Wed, 25 Mar 2026 15:11:25 -0300	[thread overview]
Message-ID: <87pl4rkcdu.fsf@suse.de> (raw)
In-Reply-To: <acQWXMP1VjSeXUvL@x1.local>

Peter Xu <peterx@redhat.com> writes:

> On Tue, Mar 24, 2026 at 04:43:20PM -0300, Fabiano Rosas wrote:
>> The vmdesc_loop variable is being used as a hacky way of writing the
>> JSON description only for the first element of a compressed
>> array. There are also a few implicit uses, such as writing the JSON
>> for the first non-compressed element after a compressed portion.
>> 
>> Future work will have trouble with this. Use a simple boolean to be
>> explicit now.
>> 
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>> ---
>>  migration/vmstate.c | 25 ++++++++++++++-----------
>>  1 file changed, 14 insertions(+), 11 deletions(-)
>> 
>> diff --git a/migration/vmstate.c b/migration/vmstate.c
>> index dec9cf920b..7a12245d36 100644
>> --- a/migration/vmstate.c
>> +++ b/migration/vmstate.c
>> @@ -622,8 +622,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>>              void *first_elem = opaque + field->offset;
>>              int i, n_elems = vmstate_n_elems(opaque, field);
>>              int size = vmstate_size(opaque, field);
>> -            JSONWriter *vmdesc_loop = vmdesc;
>>              bool is_null_prev = false;
>> +            bool use_vmdesc = true;
>> +
>>              /*
>>               * When this is enabled, it means we will always push a ptr
>>               * marker first for each element saying if it's populated.
>> @@ -673,7 +674,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>>                      is_null != is_null_prev) {
>>  
>>                      is_null_prev = is_null;
>> -                    vmdesc_loop = vmdesc;
>> +                    use_vmdesc = true;
>>  
>>                      for (int j = i + 1; j < n_elems; j++) {
>>                          void *elem = *(void **)(first_elem + size * j);
>> @@ -686,8 +687,13 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>>                      }
>>                  }
>>  
>> +                if (use_dynamic_array) {
>> +                    use_vmdesc = true;
>> +                }
>
> [1]
>
>> +
>>                  ok = vmstate_save_field_with_vmdesc(f, curr_elem, size, vmsd,
>> -                                                    inner_field, vmdesc_loop,
>> +                                                    inner_field,
>> +                                                    use_vmdesc ? vmdesc : NULL,
>>                                                      i, max_elems, errp);
>>  
>>                  /* If we used a fake temp field.. free it now */
>> @@ -708,19 +714,16 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>>                       * NOTE: do not use vmstate_size() here because we want
>>                       * to dump the real VMSD object now.
>>                       */
>> -                    ok = vmstate_save_field_with_vmdesc(f, curr_elem,
>> -                                                        field->size, vmsd,
>> -                                                        field, vmdesc_loop,
>> -                                                        i, max_elems, errp);
>> +                    ok = vmstate_save_field_with_vmdesc(
>> +                        f, curr_elem, field->size, vmsd, field,
>> +                        use_vmdesc ? vmdesc : NULL, i, max_elems, errp);
>> +
>>                      if (!ok) {
>>                          goto out;
>>                      }
>>                  }
>>  
>> -                /* Compressed arrays only care about the first element */
>> -                if (vmdesc_loop && vmsd_can_compress(field)) {
>> -                    vmdesc_loop = NULL;
>> -                }
>> +                use_vmdesc = false;
>
> Hmm...
>
> vmsd_can_compress() can return arbitrary things depending on the field
> itself, now we always do the dedup almost for everything.
>
> The patch did add above [1] to make AUTO_ALLOC be ok, by enforce setting
> TRUE for it for every loop, but what about other cases where
> vmsd_can_compress() may return false (where the field does not support
> compression)?
>

Hmm, I think you're right. But what I'm doing by setting
use_vmdesc=false here is just clearing it for the next iteration, where
it should be set according to necessity. So I'd leave this down here,
but up there change to:

         if (vmdesc && vmsd_can_compress(field)) {
             if (is_null != is_null_prev) {
                 use_vmdesc = true;
                 ...
             }
-        }
-
-        if (use_dynamic_array) {
+        } else {
             use_vmdesc = true;
         }

In words: all fields should appear in the JSON, unless its part of the
NULL portion of a compressed array. For compressed arrays only the first
element appears in the JSON. If a stream of NULLs is followed by a
non-NULL member, then that member should appear in the JSON after the
compressed entry.

These two catch all these corner-cases I think:

PYTHON=$(pwd)/pyvenv/bin/python3.11
QTEST_QEMU_BINARY=./qemu-system-s390x ./tests/qtest/migration-test -p
/s390x/migration/analyze-script

PYTHON=$(pwd)/pyvenv/bin/python3.11
QTEST_QEMU_BINARY=./qemu-system-ppc64 ./tests/qtest/migration-test-p
/ppc64/migration/analyze-script

>>              }
>>          } else {
>>              if (field->flags & VMS_MUST_EXIST) {
>> -- 
>> 2.51.0
>> 


  reply	other threads:[~2026-03-25 18:12 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 19:43 [RFC PATCH v1 00/17] migration: vmstate_save|load changes for peterx Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 01/17] vmstate: fixup the use of AUTO_ALLOC flag Fabiano Rosas
2026-03-25 16:18   ` Peter Xu
2026-03-24 19:43 ` [RFC PATCH v1 02/17] vmstate: Remove vmstate_use_marker_field Fabiano Rosas
2026-03-25 16:37   ` Peter Xu
2026-03-25 17:51     ` Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 03/17] vmstate: Stop checking size for nullptr compression Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 04/17] vmstate: Set error inside of vmstate_save_field_with_vmdesc Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 05/17] vmstate: Remove vmdesc_loop Fabiano Rosas
2026-03-25 17:07   ` Peter Xu
2026-03-25 18:11     ` Fabiano Rosas [this message]
2026-03-25 21:43       ` Peter Xu
2026-03-24 19:43 ` [RFC PATCH v1 06/17] vmstate: Put array of pointers code together Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 07/17] vmstate: Create and save ptr marker in same function Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 08/17] vmstate: Don't recompute size and n_elems in vmstate_size Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 09/17] vmstate: Increase scope of vmstate_handle_alloc Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 10/17] vmstate: Remove curr_elem_p Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 11/17] vmstate: Introduce vmstate_first Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 12/17] vmstate: Introduce vmstate_next Fabiano Rosas
2026-03-26 14:18   ` Peter Xu
2026-03-24 19:43 ` [RFC PATCH v1 13/17] vmstate: Drop VMS_ARRAY_OF_POINTER_AUTO_ALLOC Fabiano Rosas
2026-03-25 19:29   ` Peter Xu
2026-03-25 21:49     ` Peter Xu
2026-03-25 21:57   ` Peter Xu
2026-03-24 19:43 ` [RFC PATCH v1 14/17] vmstate: Move VMS_MUST_EXIST check Fabiano Rosas
2026-03-25 19:38   ` Peter Xu
2026-03-24 19:43 ` [RFC PATCH v1 15/17] vmstate: Invert exists check Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 16/17] vmstate: Declare variables at the top Fabiano Rosas
2026-03-24 19:43 ` [RFC PATCH v1 17/17] vmstate: Reduce indentation levels Fabiano Rosas
2026-03-25 19:43 ` [RFC PATCH v1 00/17] migration: vmstate_save|load changes for peterx Peter Xu
2026-03-25 20:10   ` Fabiano Rosas

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=87pl4rkcdu.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=alexander@mihalicyn.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox