[{"id":3669752,"web_url":"http://patchwork.ozlabs.org/comment/3669752/","msgid":"<acVARwOjj5gJlmhr@x1.local>","list_archive_url":null,"date":"2026-03-26T14:18:47","subject":"Re: [RFC PATCH v1 12/17] vmstate: Introduce vmstate_next","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/people/67717/","name":"Peter Xu","email":"peterx@redhat.com"},"content":"On Tue, Mar 24, 2026 at 04:43:27PM -0300, Fabiano Rosas wrote:\n> Similarly to vmstate_first(), introduce a vmstate_next(), which does\n> the necessary dereferencing of pointers to get to the leaf element. On\n> the load side, allow the caller to pass a flag indicating whether\n> allocation is expected and call the allocation function if so.\n> \n> Signed-off-by: Fabiano Rosas <farosas@suse.de>\n> ---\n>  migration/vmstate.c | 84 +++++++++++++++++++++------------------------\n>  1 file changed, 39 insertions(+), 45 deletions(-)\n> \n> diff --git a/migration/vmstate.c b/migration/vmstate.c\n> index ab7c6fa4ab..c1ad0ef9a5 100644\n> --- a/migration/vmstate.c\n> +++ b/migration/vmstate.c\n> @@ -127,24 +127,51 @@ static void *vmstate_first(void *opaque, const VMStateField *field,\n>      return first;\n>  }\n>  \n> -static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field,\n> -                                    Error **errp)\n> +static void *vmstate_next(void **first, const VMStateField *field,\n> +                          int size, int i, bool alloc)\n>  {\n> -    int byte = qemu_get_byte(f);\n> +    void **array_elem;\n> +    void *next;\n> +\n> +    if (!(field->flags & VMS_ARRAY_OF_POINTER)) {\n> +        next = (void *)first + size * i;\n> +        return next;\n> +    }\n> +\n> +    array_elem = first + i;\n> +    next = *array_elem;\n> +\n> +    if (alloc) {\n> +        if (!next || field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC) {\n> +            /*\n> +             * NOTE: do not use vmstate_size() here, because we\n> +             * need the object size, not entry size of the\n> +             * array.\n> +             */\n> +            next = vmstate_handle_alloc(array_elem, field->size, 1);\n> +        }\n> +    }\n> +    return next;\n> +}\n> +\n> +static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field)\n> +{\n> +    int byte = qemu_peek_byte(f, 0);\n\nHere, peeking the marker for ...\n\n>  \n>      if (byte == VMS_MARKER_PTR_NULL) {\n>          /* When it's a null ptr marker, do not continue the load */\n>          *load_field = false;\n> +        qemu_file_skip(f, 1);\n>          return true;\n>      }\n>  \n>      if (byte == VMS_MARKER_PTR_VALID) {\n>          /* We need to load this field right after the marker */\n>          *load_field = true;\n> +        qemu_file_skip(f, 1);\n>          return true;\n>      }\n>  \n> -    error_setg(errp, \"Unexpected ptr marker: %d\", byte);\n>      return false;\n>  }\n>  \n> @@ -273,41 +300,13 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,\n>                  void *curr_elem;\n>  \n>                  if (field->flags & VMS_ARRAY_OF_POINTER) {\n\n... every VMS_ARRAY_OF_POINTER case makes me feel uneasy.\n\nNote that we only have two use cases that both of them are certain on the\nupcoming byte to come:\n\n(1) for the null-only pointer, which is before this series introduced, both\nsrc/dst qemu knows 100% which ptr is NULL, so dest QEMU expects that 0x30\nfor each null pointer.\n\n(2) for the new _AUTO_ALLOC introduced here, we also know exactly either\n0x30 or 0x31 will come, and one of them must come before the real field\ndump.\n\nI think we may shoot us in the foot if we see 0x30 but in reality it's just\nthe 1st byte of some array field's binary stream.\n\n> -                    void **array_elem = (void **)head + i;\n> -                    bool use_dynamic_array =\n> -                        field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC;\n> -                    bool use_marker_field;\n> -\n> -                    curr_elem = *array_elem;\n> -                    use_marker_field = use_dynamic_array || !curr_elem;\n> -\n> -                    if (use_marker_field) {\n> -                        /* Read the marker instead of VMSD first */\n> -                        if (!vmstate_ptr_marker_load(f, &load_field, errp)) {\n> -                            trace_vmstate_load_field_error(field->name,\n> -                                                           -EINVAL);\n> -                            return false;\n> -                        }\n> -\n> -                        if (load_field) {\n> -                            /*\n> -                             * When reaching here, it means we received a\n> -                             * non-NULL ptr marker, so we need to populate the\n> -                             * field before loading it.\n> -                             *\n> -                             * NOTE: do not use vmstate_size() here, because we\n> -                             * need the object size, not entry size of the\n> -                             * array.\n> -                             */\n> -                            assert(!curr_elem);\n> -                            curr_elem = vmstate_handle_alloc(array_elem,\n> -                                                             field->size, 1);\n> -                        }\n> -                    }\n> -                } else {\n> -                    curr_elem = head + size * i;\n> +                    /* Peek a possible pointer marker instead of VMSD first */\n> +                    ok = vmstate_ptr_marker_load(f, &load_field);\n>                  }\n>  \n> +                curr_elem = vmstate_next(head, field, size, i,\n> +                                         load_field && ok);\n> +\n>                  if (load_field) {\n>                      ok = vmstate_load_field(f, curr_elem, size, field, errp);\n>                  }\n> @@ -647,15 +646,11 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,\n>  \n>              for (i = 0; i < n_elems; i++) {\n>                  bool save_field = true;\n> -                void *curr_elem;\n> +                void *curr_elem = vmstate_next(head, field, size, i, false);\n>                  int max_elems = n_elems - i;\n>  \n>                  if (field->flags & VMS_ARRAY_OF_POINTER) {\n>                      bool use_marker_field, is_null, use_dynamic_array;\n> -                    void **array_elem = (void **)head + i;\n> -\n> -                    assert(array_elem);\n> -                    curr_elem = *array_elem;\n>  \n>                      is_null = !curr_elem;\n>  \n> @@ -688,7 +683,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,\n>                              use_vmdesc = true;\n>  \n>                              for (int j = i + 1; j < n_elems; j++) {\n> -                                void *elem = *(void **)(head + size * j);\n> +                                void *elem = vmstate_next(head, field, size, j,\n> +                                                          false);\n>                                  bool elem_is_null = !elem;\n>  \n>                                  if (is_null != elem_is_null) {\n> @@ -713,8 +709,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,\n>  \n>                          save_field = !!curr_elem;\n>                      }\n> -                } else {\n> -                    curr_elem = head + size * i;\n>                  }\n>  \n>                  if (save_field) {\n> -- \n> 2.51.0\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=NxGo14US;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=uOunKCTh;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fhQrj2HfVz1y1G\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 27 Mar 2026 01:19:33 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w5lY1-0000ey-Te; Thu, 26 Mar 2026 10:18:57 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1w5lXz-0000em-Gp\n for qemu-devel@nongnu.org; Thu, 26 Mar 2026 10:18:56 -0400","from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1w5lXx-0005Dm-Ok\n for qemu-devel@nongnu.org; Thu, 26 Mar 2026 10:18:55 -0400","from mail-qv1-f72.google.com (mail-qv1-f72.google.com\n [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-681-jEqqTRfnP3GAlMh--O1FsQ-1; Thu, 26 Mar 2026 10:18:50 -0400","by mail-qv1-f72.google.com with SMTP id\n 6a1803df08f44-89c3e0be5ccso7093396d6.1\n for <qemu-devel@nongnu.org>; Thu, 26 Mar 2026 07:18:50 -0700 (PDT)","from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-89cd5a22711sm29366716d6.27.2026.03.26.07.18.48\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 26 Mar 2026 07:18:48 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1774534732;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=4bk6t0SUecjr7baFP4UJcCSBeTGMo9yq6NxAlD5WMgE=;\n b=NxGo14US1Goh9Sb4dOUzyrnOpX4yditu0fcuRisnXd2pPG68gNPms3fpz4VyHBjwgpsgNP\n c/4yF171C/QsfNjyYLdI1/1qJOI2mk0RetP9Y2HdRSFv6AJGaBT+K6wUF9/JhNn+6NGSyb\n A1GYPRZngo8oC/CfzfJSxTHe9NZL3qo=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1774534730; x=1775139530; darn=nongnu.org;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;\n bh=4bk6t0SUecjr7baFP4UJcCSBeTGMo9yq6NxAlD5WMgE=;\n b=uOunKCThETYJ0S91d9rGPisDXpj1r5845HLKdmopEJ3rzJ520sa2YpztcR9s3GgUtM\n SDebR7f5eBF5brsxPnFML1nXWpgciUdjX6XGwTf7FtZ7Fpzch673jwFqMdC5j54BoYuc\n BvNP5jHDSLChgfz34Ba63kk67xsntY5rFSuw9oTa3Ef3HhdB64LdgU0owNSbdarVfx/U\n AhB361knNWCbvK1oUW2+5YFRvHvG+TjZpLDkXn+X5Roh6x5C+uxi/xSYAhUmSAMjKYoU\n 0DX50ylQvlE+SijtEgI5blS6da8+40IktWAWguBQZhxHWAuwMpz9BE16Vmfrn0+W2WnE\n D76Q=="],"X-MC-Unique":"jEqqTRfnP3GAlMh--O1FsQ-1","X-Mimecast-MFC-AGG-ID":"jEqqTRfnP3GAlMh--O1FsQ_1774534730","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774534730; x=1775139530;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=4bk6t0SUecjr7baFP4UJcCSBeTGMo9yq6NxAlD5WMgE=;\n b=huX4gure6JAGE162mQkp3jet4blODb+DjxNG4lfYEZIFjbVEgqzsh8RTUyqVtCNbVB\n gY6oMYSFNv02DZRLWSL3yWp4GQ0T2rlXmnmWPQozf/WE/JaeVlBtvRYAhfPLSaFLiyH0\n TYlOglJfgzxhK/FcKlQM4KUdkE4BnULwWoy7620ad4mvqfzJeXQlXyQtbMqZsCiBpUXI\n FdTAQrf/X8C2+QbzT6ZiJpapUOioK3oqo1gtoR7pUcz88DBwlXUyQKdlFpAABQ2hho6B\n OA5C0u37KKI5doQ+SMNKGIaKNg1wecp/ksfNPVJbdN2PFNRdK1sUUxjKrvCUxHMhYSPb\n z3XQ==","X-Gm-Message-State":"AOJu0Yyakx+eLwgDty33ToFxD7USE3HJ2XBNhV3w+rp7NyJwyFEpZZ0l\n QZoOcTj7EfXi8qcuX1jRk0ANKb5vux5KbDF9bf0huZKSseepqGuYpPAacIo3xbRKc5uIfRc2VnN\n M9GQHKn5B6DpcPsBDS5LfbdH5EWpOF6Jw5B0lfASPTYvdXwo7TI6BWAb/","X-Gm-Gg":"ATEYQzx5W047gY4Tu7nj3xJLlVi0KVHs4KACzVOaPob/9aLf/rrikj0Zhcgh4IVJadu\n Zt4odZWlNDEmHO92mslwwT+Gk1coTVEmHW6VDrRVfS207ciWrCwEbiZPZ9MuPIzlptzBH2cYA5Y\n DWrOmn1RT+f1dyDPsACgFT5GKrKdUDUB8mHbwtY6aKGBd8cqT56MK8k7LTkRc0RTKk8PmWiaIU6\n u5eeXaNwzg8uds5GNP4NXlYH62nKoOZrckcK/FgMpNOcO0DYNnqGcr38AtfS9zI+7eb5UPsQLCw\n +/CHKdD35tmlI+jBLGtwfkdx44Aa7Cy6kZGL0bGidCbuqsf2HgWB5BxeFJWW1jLFvtgd7usFpQk\n cUAbWM/CzKpC2Bg==","X-Received":["by 2002:a05:6214:2503:b0:899:f570:3167 with SMTP id\n 6a1803df08f44-89cc4a9b8ffmr117094806d6.46.1774534729962;\n Thu, 26 Mar 2026 07:18:49 -0700 (PDT)","by 2002:a05:6214:2503:b0:899:f570:3167 with SMTP id\n 6a1803df08f44-89cc4a9b8ffmr117094216d6.46.1774534729243;\n Thu, 26 Mar 2026 07:18:49 -0700 (PDT)"],"Date":"Thu, 26 Mar 2026 10:18:47 -0400","From":"Peter Xu <peterx@redhat.com>","To":"Fabiano Rosas <farosas@suse.de>","Cc":"qemu-devel@nongnu.org, Alexander Mikhalitsyn <alexander@mihalicyn.com>,\n Juraj Marcin <jmarcin@redhat.com>","Subject":"Re: [RFC PATCH v1 12/17] vmstate: Introduce vmstate_next","Message-ID":"<acVARwOjj5gJlmhr@x1.local>","References":"<20260324194333.30004-1-farosas@suse.de>\n <20260324194333.30004-13-farosas@suse.de>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20260324194333.30004-13-farosas@suse.de>","Received-SPF":"pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}},{"id":3669972,"web_url":"http://patchwork.ozlabs.org/comment/3669972/","msgid":"<871ph6jmd1.fsf@suse.de>","list_archive_url":null,"date":"2026-03-26T21:45:46","subject":"Re: [RFC PATCH v1 12/17] vmstate: Introduce vmstate_next","submitter":{"id":85343,"url":"http://patchwork.ozlabs.org/api/people/85343/","name":"Fabiano Rosas","email":"farosas@suse.de"},"content":"Peter Xu <peterx@redhat.com> writes:\n\n> On Tue, Mar 24, 2026 at 04:43:27PM -0300, Fabiano Rosas wrote:\n>> Similarly to vmstate_first(), introduce a vmstate_next(), which does\n>> the necessary dereferencing of pointers to get to the leaf element. On\n>> the load side, allow the caller to pass a flag indicating whether\n>> allocation is expected and call the allocation function if so.\n>> \n>> Signed-off-by: Fabiano Rosas <farosas@suse.de>\n>> ---\n>>  migration/vmstate.c | 84 +++++++++++++++++++++------------------------\n>>  1 file changed, 39 insertions(+), 45 deletions(-)\n>> \n>> diff --git a/migration/vmstate.c b/migration/vmstate.c\n>> index ab7c6fa4ab..c1ad0ef9a5 100644\n>> --- a/migration/vmstate.c\n>> +++ b/migration/vmstate.c\n>> @@ -127,24 +127,51 @@ static void *vmstate_first(void *opaque, const VMStateField *field,\n>>      return first;\n>>  }\n>>  \n>> -static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field,\n>> -                                    Error **errp)\n>> +static void *vmstate_next(void **first, const VMStateField *field,\n>> +                          int size, int i, bool alloc)\n>>  {\n>> -    int byte = qemu_get_byte(f);\n>> +    void **array_elem;\n>> +    void *next;\n>> +\n>> +    if (!(field->flags & VMS_ARRAY_OF_POINTER)) {\n>> +        next = (void *)first + size * i;\n>> +        return next;\n>> +    }\n>> +\n>> +    array_elem = first + i;\n>> +    next = *array_elem;\n>> +\n>> +    if (alloc) {\n>> +        if (!next || field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC) {\n>> +            /*\n>> +             * NOTE: do not use vmstate_size() here, because we\n>> +             * need the object size, not entry size of the\n>> +             * array.\n>> +             */\n>> +            next = vmstate_handle_alloc(array_elem, field->size, 1);\n>> +        }\n>> +    }\n>> +    return next;\n>> +}\n>> +\n>> +static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field)\n>> +{\n>> +    int byte = qemu_peek_byte(f, 0);\n>\n> Here, peeking the marker for ...\n>\n>>  \n>>      if (byte == VMS_MARKER_PTR_NULL) {\n>>          /* When it's a null ptr marker, do not continue the load */\n>>          *load_field = false;\n>> +        qemu_file_skip(f, 1);\n>>          return true;\n>>      }\n>>  \n>>      if (byte == VMS_MARKER_PTR_VALID) {\n>>          /* We need to load this field right after the marker */\n>>          *load_field = true;\n>> +        qemu_file_skip(f, 1);\n>>          return true;\n>>      }\n>>  \n>> -    error_setg(errp, \"Unexpected ptr marker: %d\", byte);\n>>      return false;\n>>  }\n>>  \n>> @@ -273,41 +300,13 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,\n>>                  void *curr_elem;\n>>  \n>>                  if (field->flags & VMS_ARRAY_OF_POINTER) {\n>\n> ... every VMS_ARRAY_OF_POINTER case makes me feel uneasy.\n>\n\nThere's 32k bytes in the buffer, this is likely to be just a\ndereference. But fair enough.\n\n> Note that we only have two use cases that both of them are certain on the\n> upcoming byte to come:\n>\n> (1) for the null-only pointer, which is before this series introduced, both\n> src/dst qemu knows 100% which ptr is NULL, so dest QEMU expects that 0x30\n> for each null pointer.\n>\n> (2) for the new _AUTO_ALLOC introduced here, we also know exactly either\n> 0x30 or 0x31 will come, and one of them must come before the real field\n> dump.\n>\n> I think we may shoot us in the foot if we see 0x30 but in reality it's just\n> the 1st byte of some array field's binary stream.\n>\n\nYeah, that's a good point...\n\nIf you can put up with passing QEMUFile into vmstate_next(), we could\nget the byte only when we're expecting it. Something like:\n\ndiff --git a/migration/vmstate.c b/migration/vmstate.c\nindex 25fd9e52bc..16d9c1753f 100644\n--- a/migration/vmstate.c\n+++ b/migration/vmstate.c\n@@ -137,7 +137,7 @@ static void *vmstate_first(void *opaque, const VMStateField *field,\n }\n \n static void *vmstate_next(void **first, const VMStateField *field,\n-                          int size, int i, bool alloc)\n+                          int size, int i, QEMUFile *f)\n {\n     void **array_elem;\n     void *next;\n@@ -150,8 +150,11 @@ static void *vmstate_next(void **first, const VMStateField *field,\n     array_elem = first + i;\n     next = *array_elem;\n \n-    if (alloc) {\n-        if (!next || field->flags & VMS_ALLOC) {\n+    if (f && (!next || field->flags & VMS_ALLOC)) {\n+        bool alloc, ok;\n+\n+        ok = vmstate_ptr_marker_load(f, &alloc);\n+        if (ok & alloc) {\n             /*\n              * NOTE: do not use vmstate_size() here, because we\n              * need the object size, not entry size of the\n@@ -315,18 +318,11 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,\n                              !(field->flags & VMS_ARRAY_OF_POINTER));\n \n         for (i = 0; i < n_elems; i++) {\n-            /* If we will process the load of field? */\n-            bool load_field = true;\n             void *curr_elem;\n \n-            if (field->flags & VMS_ARRAY_OF_POINTER) {\n-                /* Peek a possible pointer marker instead of VMSD first */\n-                ok = vmstate_ptr_marker_load(f, &load_field);\n-            }\n-\n-            curr_elem = vmstate_next(head, field, size, i, load_field && ok);\n+            curr_elem = vmstate_next(head, field, size, i, f);\n \n-            if (load_field) {\n+            if (curr_elem) {\n                 ok = vmstate_load_field(f, curr_elem, size, field, errp);\n             }\n \n@@ -673,7 +669,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,\n \n         for (i = 0; i < n_elems; i++) {\n             bool save_field = true;\n-            void *curr_elem = vmstate_next(head, field, size, i, false);\n+            void *curr_elem = vmstate_next(head, field, size, i, NULL);\n             int max_elems = n_elems - i;\n \n             if (field->flags & VMS_ARRAY_OF_POINTER) {\n@@ -711,8 +707,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,\n                         use_vmdesc = true;\n \n                         for (int j = i + 1; j < n_elems; j++) {\n-                            void *elem = vmstate_next(head, field, size, j,\n-                                                      false);\n+                            void *elem = vmstate_next(head, field, size, j, NULL);\n                             bool elem_is_null = !elem;\n \n                             if (is_null != elem_is_null) {","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256\n header.s=susede2_rsa header.b=JdnBQaPW;\n\tdkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=l92uuPw4;\n\tdkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.a=rsa-sha256 header.s=susede2_rsa header.b=qISt25N6;\n\tdkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=SXOtTtDp;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)","smtp-out1.suse.de;\n dkim=pass header.d=suse.de header.s=susede2_rsa header.b=qISt25N6;\n dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=SXOtTtDp"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fhcm71SVSz1yFp\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 27 Mar 2026 08:46:15 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w5sWY-0006T9-0G; Thu, 26 Mar 2026 17:45:54 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <farosas@suse.de>) id 1w5sWW-0006Sw-O0\n for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:45:52 -0400","from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <farosas@suse.de>) id 1w5sWU-0005xI-J7\n for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:45:52 -0400","from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org\n [IPv6:2a07:de40:b281:104:10:150:64:97])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by smtp-out1.suse.de (Postfix) with ESMTPS id D711221132;\n Thu, 26 Mar 2026 21:45:48 +0000 (UTC)","from imap1.dmz-prg2.suse.org (localhost [127.0.0.1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 757A44A0A3;\n Thu, 26 Mar 2026 21:45:48 +0000 (UTC)","from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167])\n by imap1.dmz-prg2.suse.org with ESMTPSA id IFNwEQypxWnJZgAAD6G6ig\n (envelope-from <farosas@suse.de>); Thu, 26 Mar 2026 21:45:48 +0000"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1774561549;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=3PY49rqrb3gZsoCVQ26efIKByZsntJlPggvKJ/pYdtU=;\n b=JdnBQaPWKe0rUXosPDFNP/QipJLr7QTsvneU05AHiFoC6Yvs1jEfMtPJBNwiQhoYUU3AzQ\n jUGJgF4qV6XolE8VsHWeiZcQ1ZLFYDkKBfKGyJzRvqyjG/ECOCRMqKIoBNyr7N33uUy97M\n o4UrlGUaBLv2amlzpTlM8xlSOsMNTkc=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1774561549;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=3PY49rqrb3gZsoCVQ26efIKByZsntJlPggvKJ/pYdtU=;\n b=l92uuPw4+3kBw6fKdR/E1jWjEhKjQ0A+i26jSNGLEe/si9f6fpciCqnoppwu08PT42vZCy\n gSj74P99Wscjp8Ag==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1774561548;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=3PY49rqrb3gZsoCVQ26efIKByZsntJlPggvKJ/pYdtU=;\n b=qISt25N6WkJ+g5EdEod5UAlN57l60qnSIdIaNslWjakprDLJkqe/ZIti0Vb0Ups5dZaj1i\n 2rnIPclyKC+U0Z8d3bKvuzWpfdiZwO570nsRo2uVPPpv4DIXTsgFablgrnJa/cyvv16K+i\n XDlEbz1Lcoc6qfQTNPe3PwIffBd2zBU=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1774561548;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=3PY49rqrb3gZsoCVQ26efIKByZsntJlPggvKJ/pYdtU=;\n b=SXOtTtDpQx4Vg7eB4xuC8nzkb3hACV8C7+MrA+78a/gRrYh1vTE9BvLRONhPAWxOQYoSfh\n Bp7Vil+5RjcartDA=="],"From":"Fabiano Rosas <farosas@suse.de>","To":"Peter Xu <peterx@redhat.com>","Cc":"qemu-devel@nongnu.org, Alexander Mikhalitsyn <alexander@mihalicyn.com>,\n Juraj Marcin <jmarcin@redhat.com>","Subject":"Re: [RFC PATCH v1 12/17] vmstate: Introduce vmstate_next","In-Reply-To":"<acVARwOjj5gJlmhr@x1.local>","References":"<20260324194333.30004-1-farosas@suse.de>\n <20260324194333.30004-13-farosas@suse.de> <acVARwOjj5gJlmhr@x1.local>","Date":"Thu, 26 Mar 2026 18:45:46 -0300","Message-ID":"<871ph6jmd1.fsf@suse.de>","MIME-Version":"1.0","Content-Type":"text/plain","X-Rspamd-Action":"no action","X-Rspamd-Server":"rspamd2.dmz-prg2.suse.org","X-Spamd-Result":"default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%];\n NEURAL_HAM_LONG(-1.00)[-1.000];\n R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain];\n MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[];\n RCVD_TLS_ALL(0.00)[]; MISSING_XM_UA(0.00)[];\n TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+];\n SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n FUZZY_RATELIMITED(0.00)[rspamd.com];\n MID_RHS_MATCH_FROM(0.00)[];\n DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[];\n RCPT_COUNT_THREE(0.00)[4]; RCVD_COUNT_TWO(0.00)[2];\n TO_MATCH_ENVRCPT_ALL(0.00)[];\n DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns];\n DKIM_TRACE(0.00)[suse.de:+]","X-Rspamd-Queue-Id":"D711221132","X-Spam-Score":"-4.51","Received-SPF":"pass client-ip=2a07:de40:b251:101:10:150:64:1;\n envelope-from=farosas@suse.de; helo=smtp-out1.suse.de","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]