{"id":2227467,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2227467/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260423191958.1440-31-farosas@suse.de/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260423191958.1440-31-farosas@suse.de>","list_archive_url":null,"date":"2026-04-23T19:19:44","name":"[PULL,30/43] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b6d28a6d8b6dcd972c013a526f9dde223b4da696","submitter":{"id":85343,"url":"http://patchwork.ozlabs.org/api/1.2/people/85343/?format=json","name":"Fabiano Rosas","email":"farosas@suse.de"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260423191958.1440-31-farosas@suse.de/mbox/","series":[{"id":501236,"url":"http://patchwork.ozlabs.org/api/1.2/series/501236/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=501236","date":"2026-04-23T19:19:14","name":"[PULL,01/43] checkpatch: Allow spaces after all coroutine annotations","version":1,"mbox":"http://patchwork.ozlabs.org/series/501236/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2227467/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2227467/checks/","tags":{},"related":[],"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=IGMohvtO;\n\tdkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=wMVwALrU;\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=IGMohvtO;\n\tdkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=wMVwALrU;\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=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)","smtp-out1.suse.de;\n\tnone"],"Received":["from lists1p.gnu.org (lists1p.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 4g1mH740L9z1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 05:24:03 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wFzdJ-0006AN-Es; Thu, 23 Apr 2026 15:22:41 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <farosas@suse.de>) id 1wFzcm-0004jX-5D\n for qemu-devel@nongnu.org; Thu, 23 Apr 2026 15:22:11 -0400","from smtp-out1.suse.de ([195.135.223.130])\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 1wFzcj-0002Ji-TC\n for qemu-devel@nongnu.org; Thu, 23 Apr 2026 15:22:07 -0400","from imap1.dmz-prg2.suse.org (unknown [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 465876A8AB;\n Thu, 23 Apr 2026 19:20:47 +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 097BF593A3;\n Thu, 23 Apr 2026 19:20:45 +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 mDj4MQ1x6mlJCwAAD6G6ig\n (envelope-from <farosas@suse.de>); Thu, 23 Apr 2026 19:20:45 +0000"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1776972047;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=cEY8XD3xBrJLvWZZxM6SWztn1MCt3QZRKtvPcKEo8uk=;\n b=IGMohvtOH5DUa+hN+f0aQzeMICyN7UZmmviOIUpmUNCop9aSiJRBQvpixlxsVg9RvH2dtP\n MorXgwpSr8PU7kzt06XuwQEJEYkeab8jajan9mGWzKyFDISvManHzEIoea9DOXNPNbkh5h\n Nf1ImxUPldQcw7yJ5/equz3uZO+usZQ=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1776972047;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=cEY8XD3xBrJLvWZZxM6SWztn1MCt3QZRKtvPcKEo8uk=;\n b=wMVwALrUh4v++CbqwZx6Ye7u9WydyDriXrIIua7e4uKHUJWIaxgIMIIXzqwK5k59kEBz4H\n /8a61Z98tJVgBwBA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1776972047;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=cEY8XD3xBrJLvWZZxM6SWztn1MCt3QZRKtvPcKEo8uk=;\n b=IGMohvtOH5DUa+hN+f0aQzeMICyN7UZmmviOIUpmUNCop9aSiJRBQvpixlxsVg9RvH2dtP\n MorXgwpSr8PU7kzt06XuwQEJEYkeab8jajan9mGWzKyFDISvManHzEIoea9DOXNPNbkh5h\n Nf1ImxUPldQcw7yJ5/equz3uZO+usZQ=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1776972047;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=cEY8XD3xBrJLvWZZxM6SWztn1MCt3QZRKtvPcKEo8uk=;\n b=wMVwALrUh4v++CbqwZx6Ye7u9WydyDriXrIIua7e4uKHUJWIaxgIMIIXzqwK5k59kEBz4H\n /8a61Z98tJVgBwBA=="],"From":"Fabiano Rosas <farosas@suse.de>","To":"qemu-devel@nongnu.org","Cc":"Peter Xu <peterx@redhat.com>,\n Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>,\n Juraj Marcin <jmarcin@redhat.com>","Subject":"[PULL 30/43] vmstate: Allow vmstate_info_nullptr to emit non-NULL\n markers","Date":"Thu, 23 Apr 2026 16:19:44 -0300","Message-ID":"<20260423191958.1440-31-farosas@suse.de>","X-Mailer":"git-send-email 2.51.0","In-Reply-To":"<20260423191958.1440-1-farosas@suse.de>","References":"<20260423191958.1440-1-farosas@suse.de>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Spamd-Result":"default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%];\n NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[];\n R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000];\n MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[];\n FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+];\n TO_DN_SOME(0.00)[];\n DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo];\n RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[];\n RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com];\n DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_ALL(0.00)[]","X-Spam-Score":"-2.80","Received-SPF":"pass client-ip=195.135.223.130; envelope-from=farosas@suse.de;\n helo=smtp-out1.suse.de","X-Spam_score_int":"-43","X-Spam_score":"-4.4","X-Spam_bar":"----","X-Spam_report":"(-4.4 / 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,\n RCVD_IN_DNSWL_MED=-2.3, 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"},"content":"From: Peter Xu <peterx@redhat.com>\n\nWe used to have one vmstate called \"nullptr\" which is only used to generate\none-byte hint to say one pointer is NULL.\n\nLet's extend its use so that it will generate another byte to say the\npointer is non-NULL.\n\nWith that, the name of the info struct (or functions) do not apply anymore.\nUpdate correspondingly.\n\nUpdate analyze-migration.py to work with the new layout.\n\nNo functional change intended yet.\n\nReviewed-by: Fabiano Rosas <farosas@suse.de>\nReviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>\nSigned-off-by: Peter Xu <peterx@redhat.com>\nReviewed-by: Juraj Marcin <jmarcin@redhat.com>\nLink: https://lore.kernel.org/qemu-devel/20260401202844.673494-8-peterx@redhat.com\nSigned-off-by: Fabiano Rosas <farosas@suse.de>\n---\n include/migration/vmstate.h  |  9 +++++++--\n migration/vmstate-types.c    | 34 ++++++++++++++++------------------\n migration/vmstate.c          | 25 +++++++++++++------------\n scripts/analyze-migration.py | 22 ++++++++++++----------\n 4 files changed, 48 insertions(+), 42 deletions(-)","diff":"diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h\nindex 7396e38531..492069b8d2 100644\n--- a/include/migration/vmstate.h\n+++ b/include/migration/vmstate.h\n@@ -282,9 +282,14 @@ extern const VMStateInfo vmstate_info_uint32;\n extern const VMStateInfo vmstate_info_uint64;\n extern const VMStateInfo vmstate_info_fd;\n \n-/** Put this in the stream when migrating a null pointer.*/\n+/*\n+ * Put this in the stream when migrating a pointer to reflect either a NULL\n+ * or valid pointer.\n+ */\n #define VMS_MARKER_PTR_NULL          (0x30U)   /* '0' */\n-extern const VMStateInfo vmstate_info_nullptr;\n+#define VMS_MARKER_PTR_VALID         (0x31U)   /* '1' */\n+\n+extern const VMStateInfo vmstate_info_ptr_marker;\n \n extern const VMStateInfo vmstate_info_cpudouble;\n \ndiff --git a/migration/vmstate-types.c b/migration/vmstate-types.c\nindex 7622cf8f01..b31689fc3c 100644\n--- a/migration/vmstate-types.c\n+++ b/migration/vmstate-types.c\n@@ -359,36 +359,34 @@ const VMStateInfo vmstate_info_fd = {\n     .save = save_fd,\n };\n \n-static bool load_nullptr(QEMUFile *f, void *pv, size_t size,\n-                         const VMStateField *field, Error **errp)\n+static bool load_ptr_marker(QEMUFile *f, void *pv, size_t size,\n+                            const VMStateField *field, Error **errp)\n \n {\n-    if (qemu_get_byte(f) == VMS_MARKER_PTR_NULL) {\n+    int byte = qemu_get_byte(f);\n+\n+    if (byte == VMS_MARKER_PTR_NULL || byte == VMS_MARKER_PTR_VALID) {\n+        /* TODO: process PTR_VALID case */\n         return true;\n     }\n \n-    error_setg(errp, \"vmstate: load_nullptr expected VMS_NULLPTR_MARKER\");\n+    error_setg(errp, \"%s: unexpected ptr marker: %d\", __func__, byte);\n     return false;\n }\n \n-static bool save_nullptr(QEMUFile *f, void *pv, size_t size,\n-                         const VMStateField *field, JSONWriter *vmdesc,\n-                         Error **errp)\n+static bool save_ptr_marker(QEMUFile *f, void *pv, size_t size,\n+                            const VMStateField *field, JSONWriter *vmdesc,\n+                            Error **errp)\n \n {\n-    if (pv == NULL) {\n-        qemu_put_byte(f, VMS_MARKER_PTR_NULL);\n-        return true;\n-    }\n-\n-    error_setg(errp, \"vmstate: save_nullptr must be called with pv == NULL\");\n-    return false;\n+    qemu_put_byte(f, pv ? VMS_MARKER_PTR_VALID : VMS_MARKER_PTR_NULL);\n+    return true;\n }\n \n-const VMStateInfo vmstate_info_nullptr = {\n-    .name = \"nullptr\",\n-    .load = load_nullptr,\n-    .save = save_nullptr,\n+const VMStateInfo vmstate_info_ptr_marker = {\n+    .name = \"ptr-marker\",\n+    .load = load_ptr_marker,\n+    .save = save_ptr_marker,\n };\n \n /* 64 bit unsigned int. See that the received value is the same than the one\ndiff --git a/migration/vmstate.c b/migration/vmstate.c\nindex b274204e66..b333aa1744 100644\n--- a/migration/vmstate.c\n+++ b/migration/vmstate.c\n@@ -55,12 +55,12 @@ vmstate_field_exists(const VMStateDescription *vmsd, const VMStateField *field,\n }\n \n /*\n- * Create a fake nullptr field when there's a NULL pointer detected in the\n+ * Create a ptr marker field when there's a NULL pointer detected in the\n  * array of a VMS_ARRAY_OF_POINTER VMSD field.  It's needed because we\n  * can't dereference the NULL pointer.\n  */\n static const VMStateField *\n-vmsd_create_fake_nullptr_field(const VMStateField *field)\n+vmsd_create_ptr_marker_field(const VMStateField *field)\n {\n     VMStateField *fake = g_new0(VMStateField, 1);\n \n@@ -71,12 +71,12 @@ vmsd_create_fake_nullptr_field(const VMStateField *field)\n     fake->name = field->name;\n     fake->version_id = field->version_id;\n \n-    /* Do not need \"field_exists\" check as it always exists (which is null) */\n+    /* Do not need \"field_exists\" check as it always exists */\n     fake->field_exists = NULL;\n \n-    /* See vmstate_info_nullptr - use 1 byte to represent nullptr */\n+    /* See vmstate_info_ptr_marker - use 1 byte to represent ptr status */\n     fake->size = 1;\n-    fake->info = &vmstate_info_nullptr;\n+    fake->info = &vmstate_info_ptr_marker;\n     fake->flags = VMS_SINGLE;\n \n     /* All the rest fields shouldn't matter.. */\n@@ -278,7 +278,7 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,\n                      * an array of pointers), use null placeholder and do\n                      * not follow.\n                      */\n-                    inner_field = vmsd_create_fake_nullptr_field(field);\n+                    inner_field = vmsd_create_ptr_marker_field(field);\n                 } else {\n                     inner_field = field;\n                 }\n@@ -583,26 +583,27 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,\n             for (i = 0; i < n_elems; i++) {\n                 void *curr_elem = first_elem + size * i;\n                 const VMStateField *inner_field;\n-                bool is_null;\n                 /* maximum number of elements to compress in the JSON blob */\n                 int max_elems = vmsd_can_compress(field) ? (n_elems - i) : 1;\n+                bool use_marker_field, is_null;\n \n                 if (field->flags & VMS_ARRAY_OF_POINTER) {\n                     assert(curr_elem);\n                     curr_elem = *(void **)curr_elem;\n                 }\n \n-                if (!curr_elem && size) {\n+                is_null = !curr_elem && size;\n+                use_marker_field = is_null;\n+\n+                if (use_marker_field) {\n                     /*\n                      * If null pointer found (which should only happen in\n                      * an array of pointers), use null placeholder and do\n                      * not follow.\n                      */\n-                    inner_field = vmsd_create_fake_nullptr_field(field);\n-                    is_null = true;\n+                    inner_field = vmsd_create_ptr_marker_field(field);\n                 } else {\n                     inner_field = field;\n-                    is_null = false;\n                 }\n \n                 /*\n@@ -638,7 +639,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,\n                                                     i, max_elems, errp);\n \n                 /* If we used a fake temp field.. free it now */\n-                if (is_null) {\n+                if (use_marker_field) {\n                     g_clear_pointer((gpointer *)&inner_field, g_free);\n                 }\n \ndiff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py\nindex e81deab8f9..1771ff781b 100755\n--- a/scripts/analyze-migration.py\n+++ b/scripts/analyze-migration.py\n@@ -469,26 +469,26 @@ def __init__(self, desc, file):\n         super(VMSDFieldIntLE, self).__init__(desc, file)\n         self.dtype = '<i%d' % self.size\n \n-class VMSDFieldNull(VMSDFieldGeneric):\n+class VMSDFieldPtrMarker(VMSDFieldGeneric):\n     NULL_PTR_MARKER = b'0'\n+    VALID_PTR_MARKER = b'1'\n \n     def __init__(self, desc, file):\n-        super(VMSDFieldNull, self).__init__(desc, file)\n+        super(VMSDFieldPtrMarker, self).__init__(desc, file)\n \n     def __repr__(self):\n-        # A NULL pointer is encoded in the stream as a '0' to\n-        # disambiguate from a mere 0x0 value and avoid consumers\n-        # trying to follow the NULL pointer. Displaying '0', 0x30 or\n-        # 0x0 when analyzing the JSON debug stream could become\n+        # A NULL / non-NULL pointer may be encoded in the stream as a\n+        # '0'/'1' to represent the status of the pointer.  Displaying '0',\n+        # 0x30 or 0x0 when analyzing the JSON debug stream could become\n         # confusing, so use an explicit term instead.\n-        return \"nullptr\"\n+        return \"null-ptr\" if self.data == self.NULL_PTR_MARKER else \"valid-ptr\"\n \n     def __str__(self):\n         return self.__repr__()\n \n     def read(self):\n-        super(VMSDFieldNull, self).read()\n-        assert(self.data == self.NULL_PTR_MARKER)\n+        super(VMSDFieldPtrMarker, self).read()\n+        assert(self.data in [self.NULL_PTR_MARKER, self.VALID_PTR_MARKER])\n         return self.data\n \n class VMSDFieldBool(VMSDFieldGeneric):\n@@ -642,7 +642,9 @@ def getDict(self):\n     \"bitmap\" : VMSDFieldGeneric,\n     \"struct\" : VMSDFieldStruct,\n     \"capability\": VMSDFieldCap,\n-    \"nullptr\": VMSDFieldNull,\n+    # Keep the old nullptr for old binaries\n+    \"nullptr\": VMSDFieldPtrMarker,\n+    \"ptr-marker\": VMSDFieldPtrMarker,\n     \"unknown\" : VMSDFieldGeneric,\n }\n \n","prefixes":["PULL","30/43"]}