From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559177; cv=none; d=zohomail.com; s=zohoarc; b=OloEy34onCujGksYfRaZwr3/bYTlLKVI4uQvYvNBY3Okq2+YtibBZJTdWZOamRxC3K7ifxREqO76lUNljF21jJADp6rSxOPKo+z5CvZ5fAYZUh4/++Czf8GDcfCnilJ3bQfUPNwn+YDXjMdq+WEHQoiYZN0AHDru04vYVOwhMC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559177; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=erx+743xHQZ4m+Ex6FitH4YpobL1zwjNzywosqKc3PM=; b=JBVFYu6zKYuAjJIAXNYkFTZn98m+yPkRKM1dLw/PxFSc1p3PpruIHJOXhjy50igimT7kREz762HrAk8AsqscQqn6/TwTjDa99KOECDTqSo4W/xVCIIv4X15JGbXY9NPVs6NFsHb6hmJ8dF7qae2bZ3uwCo0E1pi3i1o9AxPVwDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774559177892401.9772878559537; Thu, 26 Mar 2026 14:06:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtg-00046f-7m; Thu, 26 Mar 2026 17:05:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rte-00046H-K2 for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtd-00035E-3A for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:42 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-ZQXLhpZzPtGgt_zmGGRwYA-1; Thu, 26 Mar 2026 17:05:38 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cd77e5e187so394853385a.1 for ; Thu, 26 Mar 2026 14:05:38 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=erx+743xHQZ4m+Ex6FitH4YpobL1zwjNzywosqKc3PM=; b=EhrwonwbIv6kHn/oUI+vPPJJTl5fB8vPlEpk7XsoS2UbCQ+UBhPGbPSVVJYH7atyzl7nPI QMTVia6rTR9tAnKHgpJ4q56pP9cAEoEXNK7/O7ZYB38OmJ5xbdJ33lnOATsppS8mcd8rVe pyW5pr3JS14nlNfeDF38UZmlUKwgliA= X-MC-Unique: ZQXLhpZzPtGgt_zmGGRwYA-1 X-Mimecast-MFC-AGG-ID: ZQXLhpZzPtGgt_zmGGRwYA_1774559138 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559138; x=1775163938; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=erx+743xHQZ4m+Ex6FitH4YpobL1zwjNzywosqKc3PM=; b=sXwO0MWQKYPooa0ztTsQNMoLa3d6JodeNuI+Wtq1tVd6YuUrmYLQ5nTmQd5p6oaJCx BLK0swO0XAOeLfnbmc3wGK/q25Zs8rI0ksggnFAhwbsNBggBUVl2eEtZqaEcYyUIWJnC vojfine+4yIVA1NZcCI/ZPofu+VgqjagdD43RrW8HF8o06StztfhIc2lpwu1Ao7P9BPC Np6PkS6a7rS97NjFCboo7O2FfrKmSOy9mASfcjXK23oh5G/4oEYZ1rjsDt03soNDvz/E KbMbvZe3oGQpcP4ZckCVoD0OKh0F/QJ7I1RMZavGFfYEO1mZI18ax4YXtaTPp+nbRS7H 1ohw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559138; x=1775163938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=erx+743xHQZ4m+Ex6FitH4YpobL1zwjNzywosqKc3PM=; b=j7ZISRzRE1Im+mrNMZjuBKZQnRZqMxMTI/rduQFgQI3cSCip39EH9sGq0PrRcr6/Sl ylMjDwRz8YiGeVXcizprbktgUlDU2SrqOQffr8nTGyLGv5UwWmtNYXFtp4YXxHcc1pX+ UBlFrRRKKCkfs8nXejfrd+9SFy5wOG0jVLfcabnQUOCFxtSI8o/C0mpiLABDFuYrErD8 mASqpk0FWt6fJAJo4UbdLiN3oiO+k+WkyEQ1ffp04TcWNOhooDYroEFGr6T9+Jb+MOu5 dTZYmQDshc004Gpaz18Sviy+VhcKvleuZToLCnHxNFgtt4hmuoUjQzi+BizxWBe3XdR7 Rxqw== X-Gm-Message-State: AOJu0YwVbFyTW4ecmMsbikQkqyvb+FQA1MElymZ+PKxl/XEZQTz54H7E B1thCf645bdZFcc4l+q/Sm1lKQEp0vWF+qNk/2c7wAM/hkq0RfbnndYYi1CJKGT2juQtsvjvDJY pBWUkXZNqLzzTo+KAbf32aGRoxA5pm1YpJW9N0IGqbvSgefK4PmGXOzLV2bxiC4Kn60uMT+cWWC FFZ2firdeUpCjM5viQlFY8UVKMjhfanLc/HVnazQ== X-Gm-Gg: ATEYQzwF9OgFNZQzUNZfI8+SSvaCqz1fLBU5IJ278DHlPc8Pi4HHRSOdDZfJZyyh9vt IgI4YAADZUaiPb9vOc+vIJxn3GSNvmfpIliBdK7D1EsUxN7lkbLOiPmxEiJ7jMCiR7xbNi4mInZ pAn2Pgw3GKS69R8kS3zVD6dhrTGqB9aZeC8tPNK3RcmQEEkHC1JJ5Rca/TLMoFnfjzO/N+fR8Ul u6kyhXghV/fviIFYoAlBDuutilTM8NXjsaQd76PADPpAgFcCFQ525wdzOUHBi71rXqZfO+qt/iU 3W1n4kcsry5I7Fr5mOj3DGxh+616GXb0ZNiE9zfk5dCEivcOFsMuNMucsN7oVq5nGJp4DyFz0lM aicdAQVnfxSg= X-Received: by 2002:a05:620a:c4a:b0:8ca:123e:819c with SMTP id af79cd13be357-8d00100420cmr1207553585a.35.1774559137584; Thu, 26 Mar 2026 14:05:37 -0700 (PDT) X-Received: by 2002:a05:620a:c4a:b0:8ca:123e:819c with SMTP id af79cd13be357-8d00100420cmr1207547985a.35.1774559136993; Thu, 26 Mar 2026 14:05:36 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin , Alexander Mikhalitsyn Subject: [PATCH RFC v2 01/11] vmstate: Pass in struct itself for VMSTATE_ARRAY_OF_POINTER Date: Thu, 26 Mar 2026 17:05:22 -0400 Message-ID: <20260326210532.379027-2-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559181837154100 Content-Type: text/plain; charset="utf-8" Passing in a pointer almost never helps. Convert it to pass in struct for further refactoring on VMS_ARRAY_OF_POINTER. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/migration/vmstate.h | 6 +++--- tests/unit/test-vmstate.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index d4a39aa794..8992fba57d 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -547,9 +547,9 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =3D (_version), \ .num =3D (_num), \ .info =3D &(_info), \ - .size =3D sizeof(_type), \ + .size =3D sizeof(_type *), \ .flags =3D VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ - .offset =3D vmstate_offset_array(_state, _field, _type, _num), \ + .offset =3D vmstate_offset_array(_state, _field, _type*, _num), \ } =20 #define VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, _v, _vmsd, _type) {= \ @@ -1093,7 +1093,7 @@ extern const VMStateInfo vmstate_info_qlist; VMSTATE_TIMER_PTR_V(_f, _s, 0) =20 #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \ - VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer = *) + VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer) =20 #define VMSTATE_TIMER_TEST(_f, _s, _test) \ VMSTATE_SINGLE_TEST(_f, _s, _test, 0, vmstate_info_timer, QEMUTimer) diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index cadbab3c5e..6a42cc1a4e 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -668,7 +668,7 @@ const VMStateDescription vmsd_arpp =3D { .minimum_version_id =3D 1, .fields =3D (const VMStateField[]) { VMSTATE_ARRAY_OF_POINTER(ar, TestArrayOfPtrToInt, - AR_SIZE, 0, vmstate_info_int32, int32_t*), + AR_SIZE, 0, vmstate_info_int32, int32_t), VMSTATE_END_OF_LIST() } }; --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559227; cv=none; d=zohomail.com; s=zohoarc; b=Eb7GkzjrlmeyP2SIzUOdCVx9ykDdls4iME5eH7Y+d03EzXlgPgwnxt2ReDntOlpwCM33bjWeDKRraFyetGYbG678jlB4IWKYpFepzE+oDFD/ENkQPpWgYn707cjLVLz2mKe+c+uSUOw7qD70triACJbm0Zr/M32ZfN9jaEqLsjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559227; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yAsrRY7tNnPZNv7QX95Jwwlg0RE4QfNAnLAWQ9HKoeI=; b=XnlUDoJhZvWtYja4zUFzCpG8+i7Xb4KafHiJQSSJj6wyX+/TRBZkeXQY3MLoZCJ1k0CcHChtONxrWzArtXkiXSeQbYYmGInp2ahOryw1nDaxXNzP1bmcQhXwC0SATeb415kpCOpiyqR3pn3kG/pwsX7PSH4H1TXh+tTBzOrCH9o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177455922703554.398495441198065; Thu, 26 Mar 2026 14:07:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtl-00048H-6I; Thu, 26 Mar 2026 17:05:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtj-00047e-Ve for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rti-00036I-Hr for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:47 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-i4Sc2zJeOca-m3b6YFoF8g-1; Thu, 26 Mar 2026 17:05:40 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cfdc479f5bso350116985a.2 for ; Thu, 26 Mar 2026 14:05:40 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yAsrRY7tNnPZNv7QX95Jwwlg0RE4QfNAnLAWQ9HKoeI=; b=PnR5viagpp76e/w2kFcESHagAJ3K0ZfXVU1NFrPLhwhre3B9AFO5BXhPR4c46G3dSM0FRk tw4cWJgbQ/DBg4ki/Et6mrozc24zGqSj032kAldgXGVW/kgNHk7LswnxcFLtdam6eZKnEB PBMrhPad4J0npzDNRXA4XhUNsqSc2Lc= X-MC-Unique: i4Sc2zJeOca-m3b6YFoF8g-1 X-Mimecast-MFC-AGG-ID: i4Sc2zJeOca-m3b6YFoF8g_1774559140 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559139; x=1775163939; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yAsrRY7tNnPZNv7QX95Jwwlg0RE4QfNAnLAWQ9HKoeI=; b=BFBtj1gBOBsmK/HUhmWQQnvN2qZsrC9LZhol/4vJ5JCYxVQQ2NZr5UT0ri15RWzOHK r5pzPmqNTzvYsTtJjR+NRt4eQgI/73TAwpbkoSmL6xgWRBQ1IdeabbVvH3L+b0nW06ov UpCNCTTuwpQIeYU/05ZGoLfcdVFL72AxtYNjnqkoTww+y1y7m23s4Pbg51g0vgHcp+yG oas79yAcN2sHtu1dQ3S3OWkICYmf1HDA8Uu80LJfKu4Ln7yUyJWQ+zTPLtgz12Cxc1I4 ol73yLxno8Olee9PBSNA75Nvkuj07qq9Wjl2EWxKxWSTSKOIfTy4FSrDBh4UH+jRwmus 8lSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559139; x=1775163939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yAsrRY7tNnPZNv7QX95Jwwlg0RE4QfNAnLAWQ9HKoeI=; b=IAsl3qxlcFPciomj/gwNwtz394a7kvZrH7bcVuKog682tvI1cmx2T3Kp+z3XZZg12R k/7RccJkqY3s/TJO5CTfALsWP9iBPUPZ29IO2GTrcK9jbONsC78L/2xheIMSDNMJ810V 82ex4vzC6X7oXpnG1y/WLo5HAutoTrJ2ytcsFVfEBCa3xeziyXb2hs5fQc89o5XT855x G+dWPALb8NJCYE7SJ1C8g5qc+k3u43RJhxTH2vN8zzfNx8KsM3y1DNM5E6+j5NReeg9k yXrvqGJSUtQ7zs4/iDyJskVTIEGBQtNO57NT9IsbybdxDUXIxEcdqHH6L/fP6rYYB+ap FmrA== X-Gm-Message-State: AOJu0YwiSLw6pFGBFn6QNzBgJQXRhDt6slFJiXEsDrf5Ffk8A02bOlSI nQFtYlpwSXbuInMxNk9Ys33xvo2qInaUSzfyWwxcl3liS0xYbN6zzW2P/I9j+Y95JtE6QbRDZm5 mqsK4WLeirD0ALvqkBBPDo9lY7YfpG/2uYloHU5/Dm0fuMRKB+u8eeen/TLn0E+vzWVfPAeFoCK f/qPWICEW1JkZaTddFYtCuWDMavJJJNVdR4Ww4Cg== X-Gm-Gg: ATEYQzy93RmZgHtWJbVo8/p7/4DqvcA1USbfc2BZZNgGRqAk70v7zKN5393uGBgSOQS Gpxg3CqOFXXDCFCLc07bjtg3kDGrQclVcvkYy09t0ockREa8bCaXwLxe6DNamn3elWIXrVAJGCt gpSQJiBQIn+eGPkBldxBylNomcV2Y1fiT+yXetpA4adtOFKhHFTpE3YD7iE6iCDu4k7s6R/mOKB MXaDfukVWcpIDrb4qltwAbMlW+mC8Cr6PdzUd86iP7+9QdAtZ6cfVg/MTCVA7/UhHponqhUl8aY jWjFNebL/NjXMiTXGKtPg+PjnwU33OOScqCibpE54XXKquYTRizO66rMp7K7IxlGO1imbu18IKS Pai3ovn/QvBQ= X-Received: by 2002:a05:620a:2805:b0:8cf:e946:b2d4 with SMTP id af79cd13be357-8d00105203fmr1191627685a.69.1774559139188; Thu, 26 Mar 2026 14:05:39 -0700 (PDT) X-Received: by 2002:a05:620a:2805:b0:8cf:e946:b2d4 with SMTP id af79cd13be357-8d00105203fmr1191620185a.69.1774559138515; Thu, 26 Mar 2026 14:05:38 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin , Alexander Mikhalitsyn Subject: [PATCH RFC v2 02/11] vmstate: Pass in struct itself for VMSTATE_VARRAY_OF_POINTER_UINT32 Date: Thu, 26 Mar 2026 17:05:23 -0400 Message-ID: <20260326210532.379027-3-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559228158158500 Content-Type: text/plain; charset="utf-8" Passing in a pointer almost never helps. Convert it to pass in struct for further refactoring on VMS_ARRAY_OF_POINTER. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/intc/riscv_aclint.h | 6 +++--- include/migration/vmstate.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/hw/intc/riscv_aclint.h b/include/hw/intc/riscv_aclint.h index 5310615cbf..0e0b98acb0 100644 --- a/include/hw/intc/riscv_aclint.h +++ b/include/hw/intc/riscv_aclint.h @@ -80,8 +80,8 @@ enum { RISCV_ACLINT_SWI_SIZE =3D 0x4000 }; =20 -#define VMSTATE_TIMER_PTR_VARRAY(_f, _s, _f_n) \ -VMSTATE_VARRAY_OF_POINTER_UINT32(_f, _s, _f_n, 0, vmstate_info_timer, \ - QEMUTimer *) +#define VMSTATE_TIMER_PTR_VARRAY(_f, _s, _f_n) \ + VMSTATE_VARRAY_OF_POINTER_UINT32(_f, _s, _f_n, 0, vmstate_info_timer, \ + QEMUTimer) =20 #endif diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 8992fba57d..68fd954411 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -567,9 +567,9 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =3D (_version), = \ .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), = \ .info =3D &(_info), = \ - .size =3D sizeof(_type), = \ + .size =3D sizeof(_type *), = \ .flags =3D VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER= , \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), = \ + .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ } =20 #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _= vmsd, _type) { \ --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559223; cv=none; d=zohomail.com; s=zohoarc; b=lwd2wGBHvyi1BXz76kbEVaOzlf0hnp2E4NIs2QbVqtAT+dD4QQH5a33sT4oSV7UcR4Nc59X4o7Qfgopo9fr41glB7qk148amIn2/t+3zHB9O4bpaF3xKFAp/CkPqLpoFI3S4Fr3H4J7vtEcZO6OtTc1CWa4BR9bL+Ko00+ZvmBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559223; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ubb/xNXuD8MO8IRZHm3DHAIE1nzess2O6rBQSwmPzBQ=; b=h0+gfv9+4V64t+tdWUlTGQD7+vTvs1YmrW+XfwKCivyXL/VNxumgOcPGd7yvpWLo1aBwEOgF2CKWLP7BTxQO+dqPPghU1GD/tAwbF8a68DvS8ijQTcwEIo/Ffn6z/AebD0BQ2oXFg2euUwXJCaoSf327WOj2on1R4nm0ce9bhto= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774559223863624.244861358224; Thu, 26 Mar 2026 14:07:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtj-00047Y-RX; Thu, 26 Mar 2026 17:05:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rti-00047H-4K for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtg-00035s-H9 for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:45 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-jq_vj9EcP_K1SOr8RUe7aA-1; Thu, 26 Mar 2026 17:05:42 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cfcf23c0e1so377141785a.2 for ; Thu, 26 Mar 2026 14:05:42 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ubb/xNXuD8MO8IRZHm3DHAIE1nzess2O6rBQSwmPzBQ=; b=CpBEGPcLh9mf58XEnnrxAK0itfroDBDXzQIW9w91dn4/pjfdu1jU/EJMGr7R8wUOl2Goss 0XIXov9k/j+5++SlIeb8WjT0UUtkjMvaE5FywR6cuMVw8yZFVR+4tazHtg3K96PL5qhAmO AaCQxje7Sj74RfosMttA6VAAX+N3vTY= X-MC-Unique: jq_vj9EcP_K1SOr8RUe7aA-1 X-Mimecast-MFC-AGG-ID: jq_vj9EcP_K1SOr8RUe7aA_1774559141 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559141; x=1775163941; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ubb/xNXuD8MO8IRZHm3DHAIE1nzess2O6rBQSwmPzBQ=; b=o/vx4a9z4M/cmeED2hz6EaX5+RrhGDmxFqRL5WpLeh7wLw6LYr5uwGc5m+nff524/r GVCehSGLMQhLrhokFwwbo/NEexwEqienkJGk0qQAAWBy1Zlool/xkngy+gEssACOpYqJ SbYtpSQGynZA8cYilY+nE0uUZKgxXKQN/uo89V6tXucd55eD6zorLSOO78C5uvlGJlAR OBBRe3nrRZh1CWqpApde45ivuqcuquf0VmKpihXHaA/lpd9kdbcOv43EU1Z+9WujDpC4 ndtcxyfnq78Gr3ZyKdfb/DjyN78j1ZPVzDWT1K/0np+UQAd5Tt5hbzcaPIRUaB1QvBt2 0wYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559141; x=1775163941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Ubb/xNXuD8MO8IRZHm3DHAIE1nzess2O6rBQSwmPzBQ=; b=IbMPjMzJEiLrEuU7KBuIFBCmvLRnuAUSDZwmZ/BNEKvXv+NboXfYnYEvYNaBwK9aaL R/JGR9BWxFT0tCu9KTa1Y7H+lu6ZOQHd0kYbSl25V60DybZAnV9SYMBvsDPc1/bxyZFB 4xzZVydzcJg1SHTrf18Pbbl4xAqVRKvbFffQhlz3YnOBAlz3gSsvVDEIT85DQInZ6vLA RXGYzHxoFh2awqhkABi19zEcHbwxoJHWDQ7h6mrFlc8muIUH07bxsNwPLbW8325M+b9U qTxr3juJSEDbC2Xe71uUkABbk4t1drASBygXoBRceXxuN7n6mLQseN03YlEQpZ9qBxBl y5jg== X-Gm-Message-State: AOJu0YzehAa2U1cJ/uZlDLVZIYPlTxkEutk4B1jhcOEAeKK2S0PY3B79 bCdG0o8H0nq6LzsyPGbGe3SmjMBZp3X6Xz90H8k3LMSSRQEyMtV1IygfDQwYpc+wV/tDqX4x4iJ HPjo8HZALHJ6MtXAIaGfMPjidP62SWlZO44LmGBbi/V0yE2O6wooi8zTVHI3rFl8vwwOX3V7ahC KIN2IaLjGhwrV6DBo9YcaTCoolHI/oAmuKfXqXog== X-Gm-Gg: ATEYQzxYUh28Aqp+2zpbfzTN7FPhngWwK2GIyD/zS38essBn/TfOKofz0BWjW+7vqVx lieaW7UA+ucEtSWIQbNnujPsgLzA5J7VgBCPxsS25yJfoMZ8Uv+dZr4pSwCk3ZCGEEqSC/K/Pzf AJSCq45VGeQM0wOFiJG8YUXNJkIMH0yy20FT57m/gM94T4AO2p8zvT0ijFzhCJUK8f3L6qjkGWm mL9hJLjjlAGn4APS0PTzx/IugDjTsjYJnT4kHs056gi1j/eeXW0OoyRaUfvExls4oleJRArpfno GbQLzxSN46fjVV+MsMu26sr/LBDJVhFFH43rLvluBNPJX9sE6mWRnxw62HUNAQWeWcKQsBo6daP WZWNQDygBvRA= X-Received: by 2002:a05:620a:7014:b0:8cd:982d:4122 with SMTP id af79cd13be357-8d0010074b7mr1097938085a.39.1774559140969; Thu, 26 Mar 2026 14:05:40 -0700 (PDT) X-Received: by 2002:a05:620a:7014:b0:8cd:982d:4122 with SMTP id af79cd13be357-8d0010074b7mr1097931585a.39.1774559140226; Thu, 26 Mar 2026 14:05:40 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin , Alexander Mikhalitsyn Subject: [PATCH RFC v2 03/11] vmstate: Do not set size for VMS_ARRAY_OF_POINTER Date: Thu, 26 Mar 2026 17:05:24 -0400 Message-ID: <20260326210532.379027-4-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559226064154100 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 68fd954411..b4bc69486d 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 =3D (_version), \ .num =3D (_num), \ .info =3D &(_info), \ - .size =3D sizeof(_type *), \ .flags =3D VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ .offset =3D vmstate_offset_array(_state, _field, _type*, _num), \ } @@ -557,7 +571,6 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =3D (_v), \ .num =3D (_n), \ .vmsd =3D &(_vmsd), \ - .size =3D sizeof(_type *), \ .flags =3D VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \ .offset =3D vmstate_offset_array(_s, _f, _type*, _n), \ } @@ -567,7 +580,6 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =3D (_version), = \ .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), = \ .info =3D &(_info), = \ - .size =3D sizeof(_type *), = \ .flags =3D VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER= , \ .offset =3D 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 *vms= d) =20 if (field) { while (field->name) { + if (field->flags & VMS_ARRAY_OF_POINTER) { + assert(field->size =3D=3D 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 VMStat= eField *field) =20 static int vmstate_size(void *opaque, const VMStateField *field) { - int size =3D field->size; + int size; =20 if (field->flags & VMS_VBUFFER) { size =3D *(int32_t *)(opaque + field->size_offset); if (field->flags & VMS_MULTIPLY) { size *=3D 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 =3D sizeof(void *); + } else { + size =3D field->size; } =20 return size; --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559213; cv=none; d=zohomail.com; s=zohoarc; b=Y00CW96CeSHLDwPTRUFvCq1BAxQ/laaauW6suMMZG3npJ2n0GQ+SMPtWmpUzhDbSaqzDzQGPyojyNRPVIS90XDJY1IeCEmWClb/3T06PKau1A4i9KSfaRwS3MjEk9N81Ub+09DjKVkNuifjZkArSHBgWGgVs3S3gYbXPMVQyAGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559213; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NhAUULl4qMWtcriJZslSelYi7+LKHXIebTcjt2KeKTg=; b=n1T5RKfNDeVQGQmBEk0+w4MxIfEVUI7NPciidf7HuWhMmgxPtd58ewHxB8chhR+mET99L1NxELzBZYHv0fzLJ84U1jAwrRdx9N832PRqrLjgAFldOs5rLw2ol4b35GLpBTGhz4SoEDeRL7WwoHlIf0Epxr3lAN7Vgku9gBCsnR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17745592139052.574141018067394; Thu, 26 Mar 2026 14:06:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtl-00048F-2B; Thu, 26 Mar 2026 17:05:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rti-00047S-O4 for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rth-00035w-75 for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:46 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-240-wpuKSBOTOGWt_Faie53Rag-1; Thu, 26 Mar 2026 17:05:42 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cd827a356aso353776785a.3 for ; Thu, 26 Mar 2026 14:05:42 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NhAUULl4qMWtcriJZslSelYi7+LKHXIebTcjt2KeKTg=; b=XFci+OH38VjnIzycQlYKsNGN89ZHEVLCf570AsevZHR+H43Ql/asJXx4vFSk9ySnEVOXIt cjJjUytNSLbSpOBzjQ/3YlPVNNn+JKlUREeh3h6Ih4OPG5p/BFe+8X9pW3fJ5DCTKNIVEb ObeUSFwhPafwx8IX4choMJ/E3amb9FI= X-MC-Unique: wpuKSBOTOGWt_Faie53Rag-1 X-Mimecast-MFC-AGG-ID: wpuKSBOTOGWt_Faie53Rag_1774559142 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559142; x=1775163942; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NhAUULl4qMWtcriJZslSelYi7+LKHXIebTcjt2KeKTg=; b=pjGdl4yfSRUU5G6GDqSS++c0vpezSFiyENIBpWV/0UCqEu3+JWw5hauy0jvZ8qwkxj olI1L4xgHT2XOGiUFvr5PdsL/hPjV2pawuaL3cSCpy17moXPwMNsJkOiOagA0NOQV0Iq yIbdmdfkLJvodwU6uGwGOoWhzpfj7UE/Dsnne+XdxHd1jJM5aDEQb/vycdpTgIAf2CLB srO3lktIv53X6wJ/bhoS4c19hYpR2DdXS/yWTaa3+1ogpH/ro5mRvYvIdW95noqT4Nrh UJdR8UcXmzOzmatyK4j7PPGzndzU69ri3aHhU/zR9riYwzW8ZRpYf6ixvgH7BnRFw1f7 dFQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559142; x=1775163942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NhAUULl4qMWtcriJZslSelYi7+LKHXIebTcjt2KeKTg=; b=O2Se81z2mDYKX4/6BrG030BvVSr0hqAxisWhPSfApLJmhLAml76UFlGTRj2OgHUT1f sgjls+dhqocdpVJKMgq73Jd6UzdbfAn1E35H5yNWyPORFZQKN86vNTi4Dx+qqF/7L6Ug wdS1bCQGCWJvtsi3vYk30ir+DWPa0Eff6jXzWTbZ2TI6dWsKlT6yqobrfqamSWVlZpT1 aEYCyLv/yQodghAuYeTg0Zezesvuavj9k1pgB8B16sdFkH1fhgjFXvAq8U4u373r8hEA 8JqeT75yf0kFuZn3AIAFp2l8LVeoALiPNtPaMjqXy8v362G2QR1O8hqA4hP3mqSn1xT5 wSvA== X-Gm-Message-State: AOJu0YyR2CDSCQ9AkW5LJnLK/XUojI33Xqv5wknTP85zx31SjXSbg18L g5dxhQL7kDGgeZfC+Psi4t4c85vcMGOni6wRhVuuEsqncUMMkxZNUz/eiVtgnXZcBvAG5H0n1M0 dvbUhieGXh1/cmBftKGgevH6yNQQyZfDY2KU/OXmuIxgaFQiNaxiN36UbeO2VzM/y9taj893dy5 qZ5vESbCrv4zybrd/h60MLYGgiHccMThEFPvH2YA== X-Gm-Gg: ATEYQzygKDLhzRUteUrmyRzh1xldSfZv3QrAP0+RR0H7CKHUokFNy/pKgFb6uPV1lri Xnc2/DR3/BLx9JtuEzhyRWgzBaXSPaDzgL9ah806EEMymOUtwKtXqQXIxN8JozwuE4dadkRbiJj wFzhQWdvtC13PBnTl5NN9pbEoleLsXUAJxow5l78BnG1byrtATZUhPP4MrF4l3HL0cBt77+fCuD N1yWKAlCj3GssbkJiharx1oN/fpMZHRkeJP7mO+1dA+1LSitxQANnU0jg9YcIXeDJ3ayhuNHIlr Q0ULMC9WyYEwDrIWGnnxhHlc+aMl2R5aLidRN6PcaYC640+lR8Uu8owYChJNZrKK6e+DkE1pHDi 873YJXDaZK7Q= X-Received: by 2002:a05:620a:4591:b0:8cf:de7b:42c8 with SMTP id af79cd13be357-8d000f1dbabmr1302952485a.24.1774559141748; Thu, 26 Mar 2026 14:05:41 -0700 (PDT) X-Received: by 2002:a05:620a:4591:b0:8cf:de7b:42c8 with SMTP id af79cd13be357-8d000f1dbabmr1302946085a.24.1774559141193; Thu, 26 Mar 2026 14:05:41 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin Subject: [PATCH RFC v2 04/11] vmstate: Update max_elems early and check field compressable once Date: Thu, 26 Mar 2026 17:05:25 -0400 Message-ID: <20260326210532.379027-5-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559215831154100 Content-Type: text/plain; charset="utf-8" QEMU has a trick in vmstate_save_vmsd_v(), where it will try to compress multiple JSON entries into one with a count to avoid duplicated entries. That only applies to the cases where vmsd_can_compress() should return true. For example, vmsd_desc_field_start() later (who will take the updated max_elems as the last parameter) will ignore the value passed in when vmsd_can_compress() returns false. Do that check once at the start of loop, and use it to update max_elems, so that max_elems keeps 1 for uncompressable VMSD fields, which is more straightforward. This also paves way to make this counter work for ptr marker VMSD fields too. No functional change intended in this patch alone. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas --- migration/vmstate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index e29a8c3f49..05badef42f 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -556,7 +556,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, void *curr_elem =3D first_elem + size * i; const VMStateField *inner_field; bool is_null; - int max_elems =3D n_elems - i; + /* maximum number of elements to compress in the JSON blob= */ + int max_elems =3D vmsd_can_compress(field) ? (n_elems - i)= : 1; =20 old_offset =3D qemu_file_transferred(f); if (field->flags & VMS_ARRAY_OF_POINTER) { @@ -587,7 +588,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, * vs. nullptr). Search ahead for the next null/non-null e= lement * and start a new compressed array if found. */ - if (vmdesc && (field->flags & VMS_ARRAY_OF_POINTER) && + if (vmdesc && max_elems > 1 && + (field->flags & VMS_ARRAY_OF_POINTER) && is_null !=3D is_prev_null) { =20 is_prev_null =3D is_null; @@ -626,7 +628,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, } =20 /* Compressed arrays only care about the first element */ - if (vmdesc_loop && vmsd_can_compress(field)) { + if (vmdesc_loop && max_elems > 1) { vmdesc_loop =3D NULL; } } --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559228; cv=none; d=zohomail.com; s=zohoarc; b=QAJR9g9SQ54uTgMtS2e7XnkJ9PgZDdl6SXSFKlSp06s71IGTv8f9es/eIFZBx79fLotwskA8+s8Ix37JMVMAA/ewG5TWpimJVyTc7WTUbzRLniW9TXlOpHvTd4SrgM3904OLqDoWPNbzD68gWG0Nh/JnFY9AFVEsPQFpYk+NUrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559228; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=V+2bKn7od5XGyVQRVijnjbeo3YuBsl9Tu9Y2/7dq7ZE=; b=TV6hU4hW0chRWy8gNmfCNa8X/Q7JaoGb5ojF/JwoUYHymiwZaD6yM0pSVnisnTLltoX11w7QwvPxPsTZ6JxXoFXeEqaRUUjJMJERLgASJ3p+bqqK6hWKqi9obZk/hnMFJIOdPhOnjdk/n0eW50KA8J+nDO3AV9a2bbDNVBRRX+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774559228601943.3034591366662; Thu, 26 Mar 2026 14:07:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtp-00049j-9i; Thu, 26 Mar 2026 17:05:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtm-00048X-4I for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtk-00037H-Kl for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:49 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-258-VcdlYRRYOdeOgc31V-LK1w-1; Thu, 26 Mar 2026 17:05:44 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8cfc5294894so464496585a.1 for ; Thu, 26 Mar 2026 14:05:44 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V+2bKn7od5XGyVQRVijnjbeo3YuBsl9Tu9Y2/7dq7ZE=; b=VV2+cRloVC3gjMYTw+OwStDWxGNVjM0FMS0gCcFEy/NfpaKDOFaA0FaXIPvTACfMHfQLBH L8dXr5TEX2jdmLcu61A6C9QfiPi8t7Fctm9SnjbAnA40E6/YhYi7FkhdBI8VepTn4qP06T E1QEV+3b/IUWweigrCvDnu6engVjCTc= X-MC-Unique: VcdlYRRYOdeOgc31V-LK1w-1 X-Mimecast-MFC-AGG-ID: VcdlYRRYOdeOgc31V-LK1w_1774559144 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559143; x=1775163943; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V+2bKn7od5XGyVQRVijnjbeo3YuBsl9Tu9Y2/7dq7ZE=; b=sh9mx+v1hi5VzL21gP7Bq6qz+Ahk2NLbX69r61D/xxyQ8TzwTZe+RBTneCehlESfhU POEFIteCiXwWDl602m2e/7H/jHYB6Y1SJ6I7HGRbme7q5WJHGZ5U2uM3iNB07bfl/W0o xdUvZiTddrtIaSB3D61FwyLAZ0ubWaQjl/VI5dDXZY66sdUdZyhwzM8e/zEibBO5Zaeg 5z5L6t8pNMBnIstTTECQcUJMFdBkjG0mvbb1xy4/FiZJaAouvRQuI90LqUnoW7rB1TDE GOlfUpob+pzHeoC7U6HeLa4cBqfOyG0Z5D9aHVBBplqH/2R9VR7Jh0zMHJWixD1jYfjC jcfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559143; x=1775163943; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=V+2bKn7od5XGyVQRVijnjbeo3YuBsl9Tu9Y2/7dq7ZE=; b=HgTJkWymrysocXEuThpIPIuJPtbfqtiyAXXhUJnwIudhZqawczxhNYS9QLARgSd4rM T+zcG6SR32fh3JmEqaD1wHrnyrLEYy3R6YGIr0OEEewe4ytkR/gxLp0uUZEbZCgZjeHL JPcoHiSFLXJUti/aep1sDBC6hDeLASZ/LSvjw34UVah4xRV0LKNFi/Vl9KAVR06g/wL5 Zhvan6aJtChKhDuta43WF4AvQrYEt7o3Y5C/W144q6PY3QLXqcWaeQmwYGimRKEL86v4 EkFCRHj+3w3l4Uc689IsSLue2iZT9/5ni3+tg2EI5yLFPJCsHem/GJI8BhJiuCNnRLAh 3A1Q== X-Gm-Message-State: AOJu0Yy4v4UUDCv1Ff3onkpuQBFLpvXbUA+VD9JUQU9caN1LcwGhzKul UAFh388hyS7x4ln/Pj3dGRv0SL+qXKIdKQgQpfrcztrbOv/YUXk2EAGqCu9U05H191zdtSLfzP6 hGAq9SloeuGpkqv2dSBAWVFq0SIsqGtakprEHfL4ESc2Qx0JOUeo0w3NieUiqO+KjqL+fHSn0kv GIg3XfXxSRi+82+KeL3sigAGHgR3xQiQH2qe399g== X-Gm-Gg: ATEYQzyOuSva5yUAyyItDjgyBZh/WsSt4Ju/N4ebHFii1zYkXoy1qkrl/ZHyAwRFUyF bk3AsHSEvOKCXSgUQtMCm/WalyGmYj2weD7n9dpbjjzvBbam1oJmnm2aP2oOowLUSIJoxGqUzdX URSW3gmbCWlEn/DjI0q60x1LWtZTJx4WwK95CDoNPYC5lUZkfGH/vQJsjvmOl+KtjIj4Nf4nZU2 Yy5371bQXPybl4QMXE1k9DnMTQGvocYp8ta2Yk0InhZdDK4Jr35Isf64xB+xxx4WcUf054JuKyO CxY+CXCJ7ntE9np9pU8FEcSWQl5bgUaJOHfgd+rMnuKeA/jN1pm7yWfqGammgRjpjx0iPUntTV3 csADd+aUHUn8= X-Received: by 2002:a05:620a:46a5:b0:8cf:d441:c7c3 with SMTP id af79cd13be357-8d001012bbbmr1230781885a.39.1774559143525; Thu, 26 Mar 2026 14:05:43 -0700 (PDT) X-Received: by 2002:a05:620a:46a5:b0:8cf:d441:c7c3 with SMTP id af79cd13be357-8d001012bbbmr1230775485a.39.1774559142905; Thu, 26 Mar 2026 14:05:42 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin , Alexander Mikhalitsyn Subject: [PATCH RFC v2 05/11] vmstate: Rename VMS_NULLPTR_MARKER to VMS_MARKER_PTR_NULL Date: Thu, 26 Mar 2026 17:05:26 -0400 Message-ID: <20260326210532.379027-6-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559229912154100 Content-Type: text/plain; charset="utf-8" Prepare for a new MARKER for non-NULL pointer. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/migration/vmstate.h | 2 +- migration/vmstate-types.c | 4 ++-- tests/unit/test-vmstate.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index b4bc69486d..092e8f7e9a 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -283,7 +283,7 @@ extern const VMStateInfo vmstate_info_uint64; extern const VMStateInfo vmstate_info_fd; =20 /** Put this in the stream when migrating a null pointer.*/ -#define VMS_NULLPTR_MARKER (0x30U) /* '0' */ +#define VMS_MARKER_PTR_NULL (0x30U) /* '0' */ extern const VMStateInfo vmstate_info_nullptr; =20 extern const VMStateInfo vmstate_info_cpudouble; diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index 23f3433696..7622cf8f01 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -363,7 +363,7 @@ static bool load_nullptr(QEMUFile *f, void *pv, size_t = size, const VMStateField *field, Error **errp) =20 { - if (qemu_get_byte(f) =3D=3D VMS_NULLPTR_MARKER) { + if (qemu_get_byte(f) =3D=3D VMS_MARKER_PTR_NULL) { return true; } =20 @@ -377,7 +377,7 @@ static bool save_nullptr(QEMUFile *f, void *pv, size_t = size, =20 { if (pv =3D=3D NULL) { - qemu_put_byte(f, VMS_NULLPTR_MARKER); + qemu_put_byte(f, VMS_MARKER_PTR_NULL); return true; } =20 diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index 6a42cc1a4e..dae15786aa 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -620,7 +620,7 @@ static void test_arr_ptr_str_no0_load(void) =20 static uint8_t wire_arr_ptr_0[] =3D { 0x00, 0x00, 0x00, 0x00, - VMS_NULLPTR_MARKER, + VMS_MARKER_PTR_NULL, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, QEMU_VM_EOF --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559228; cv=none; d=zohomail.com; s=zohoarc; b=QgAVXaHXC1bXlVckbTZ8vdmnegTSFGqpnfUEXGrdRNx4DUhDEzpsMx4/NnttmGtmadx9tr9qxBWSt7TZLxCKgJ8/96LIT9dTSr7r4LG5n3u81kLygXCsxv9XgFo3/wgncuXlmpQEU7UrCNt7EQvqw3Ac698BThUslmArM1NV37w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559228; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5OGxsDPDL98ip8EJwQP/tMCYj51Rwd5fV8vt/33jK2E=; b=nuuGCokTkGvSXt/lmEOhNRt5YyYQ5YJxKxlvUF2ySnEJBXgkjBrjBzVM3npzfSpYAtUIqgWB6cuta75NwCwIKDcRySfh2PbodkygSDzQc6BLH3XxLU208ms1VUR0dBHGhRqEICHlNMcLYpgRSCzdtxPTrIFYN66GgH4n4GFrl7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177455922857767.64352500747634; Thu, 26 Mar 2026 14:07:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rto-00049d-LW; Thu, 26 Mar 2026 17:05:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtl-00048P-Dp for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtj-00036m-Kw for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:49 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-WffzlzDkOZiRrVMkbTbjsA-1; Thu, 26 Mar 2026 17:05:45 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cfcebeb1f3so121921485a.0 for ; Thu, 26 Mar 2026 14:05:45 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5OGxsDPDL98ip8EJwQP/tMCYj51Rwd5fV8vt/33jK2E=; b=RgPdVtFLTEa9C/mH4eo7ExHHYUWeETnQRwSm921degXGhB2FF+meTQTxetL1Bi2T5Xt4SX r8HKgSE/lboNWQoK7uH4zYYXpyVM18si0pLxazcg/dG9/G8QtxZUyLYlDmiceyv6ZxkUqF vhCKCd71ZBc2ZIFju0pXXnAfWfE0vzw= X-MC-Unique: WffzlzDkOZiRrVMkbTbjsA-1 X-Mimecast-MFC-AGG-ID: WffzlzDkOZiRrVMkbTbjsA_1774559145 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559145; x=1775163945; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5OGxsDPDL98ip8EJwQP/tMCYj51Rwd5fV8vt/33jK2E=; b=dtLMV5R73wqbA7LIAIyKEs6DoLVUbsAwVaFe1V1VohNrTY/bzH8pTbehHV4DDH/YIZ LP+B3GKkZ75VXEsaf7G3Ov2/2w6Iz+UGkKNySU8jwa3+oOeK8U4hMY8uuoXFqj1lq/Ow YvlPhVU0/6k0Mdp2nr12DVbuvduRiXAbHAT24U4BccXRSy+hnxJj+3fBVb1jbtGkNAO3 yzFzdj5fMcjODpVUqmJYGoi9vAG+cqFJisrEPFshl1TGY4hAGwusDzdSf8CYg1csQpRa H01noR7dZ6w2CP/3BzX/sUDRY+X+tSQO9zZE2mGLRWKXLqIg9la0og+GvW6q0826i3WS uUjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559145; x=1775163945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5OGxsDPDL98ip8EJwQP/tMCYj51Rwd5fV8vt/33jK2E=; b=aojBiP3jVwqVCh9HpRJrdW66ubdZ8Rl4dHiCiwz9uZPlBKuPF74wCuQwcCK55pa62u TOUFwpkgiOcJKXpW7/x+T6Pe85RzyBqhzaR1DZwfdsevy8C0TSsbNvEFnraesU72iClk 0jQeTSBcFVN5DReUcffFek8XInA1llwgiIbWlAaRVWsmmGpqiFBLeDWXlNTDjfADgLlN zvbSv6Mza8YScDt7XBX565pHlqYuXoOqFjg9XyrEXYMJ7IDLi/lYZEaYp45YrxrVnK1W kpbqmvz1E0CCwwlC9dXQrkhAyvkb+EbSzCNs4uclHJZiV61D24Ja/n6ibHJAkwT49o6u Rc3Q== X-Gm-Message-State: AOJu0YxDsZ3zqB5rTijPxOChG0AwZ8QQW5g53IYt4q7h72q7R6PN9YQc Rj3CHoiaryG8cy5cjVq+XL0LAEa1oWmHTGpusSWciFNNw3slv2zzyQBbrv+vqVC4SbqNhdq2QLX TTMacH9YmgbEbZVIrjaOrBs/5UrTIplnGm5y/wKzJsrBOIV2ADpd7yJb6YsMOV8pYp9XjT7b11N BxeLrGV/1QhOMVoeckV6yGJJPOZ6fpxB/Q0BDteA== X-Gm-Gg: ATEYQzwCcO5I4NAkeWoPRRPo657U36qIaVvSY+dOyQYM4LdU81YIWW2mUNkzGPCIE6X KVPbtzGqDfPAj2oSIUkUeRIuFza7HJcsiUg8ssevM8OQpKYvbizzCMG48R2h1r4ccv0A/DIxno8 cqcTG8w4Ov8HgpvKYymbkKDhFamY6I9HIR+IlQuKWO+970A7m5djbRx0tAoyMy9sLyUMq0pcqKk zRHO52PBjMNnL8NeJ+0ya/6Xml9GwhlJGidyEZ/b/4kQaPvridc8YWuvGjqs9USUJXAWKkRtgWX E4sMaFiE1gvotJ1Q64AJN4aRL5/3kOXLT8obVx2feYJy3PNnc2/+GA6/qXC+1ALrIqhm5+yKmcF imqijNJoOncE= X-Received: by 2002:a05:620a:1a25:b0:8cd:8eb7:2c02 with SMTP id af79cd13be357-8d00107e6d6mr1258732385a.58.1774559144565; Thu, 26 Mar 2026 14:05:44 -0700 (PDT) X-Received: by 2002:a05:620a:1a25:b0:8cd:8eb7:2c02 with SMTP id af79cd13be357-8d00107e6d6mr1258726285a.58.1774559143895; Thu, 26 Mar 2026 14:05:43 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin , Alexander Mikhalitsyn Subject: [PATCH RFC v2 06/11] vmstate: Introduce vmstate_save_field_with_vmdesc() Date: Thu, 26 Mar 2026 17:05:27 -0400 Message-ID: <20260326210532.379027-7-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559230061158500 Content-Type: text/plain; charset="utf-8" Introduce a helper to do both the JSON blob generations and save vmstate. This further shrinks the function a bit. More importantly, we'll need to save two fields in one loop very soon in the future with the JSON blob. Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/vmstate.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 05badef42f..b274204e66 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -514,6 +514,35 @@ static bool vmstate_save_field(QEMUFile *f, void *pv, = size_t size, return true; } =20 +/* + * Save a whole VMSD field, including its JSON blob separately when @vmdesc + * is specified. + */ +static inline bool +vmstate_save_field_with_vmdesc(QEMUFile *f, void *pv, size_t size, + const VMStateDescription *vmsd, + const VMStateField *field, JSONWriter *vmde= sc, + int i, int max, Error **errp) +{ + uint64_t old_offset, written_bytes; + bool ok; + + vmsd_desc_field_start(vmsd, vmdesc, field, i, max); + + old_offset =3D qemu_file_transferred(f); + ok =3D vmstate_save_field(f, pv, size, field, vmdesc, errp); + written_bytes =3D qemu_file_transferred(f) - old_offset; + + vmsd_desc_field_end(vmsd, vmdesc, field, written_bytes); + + if (!ok) { + error_prepend(errp, "Save of field %s/%s failed: ", + vmsd->name, field->name); + } + + return ok; +} + static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vms= d, void *opaque, JSONWriter *vmdesc, int version_id, Error **errp) @@ -542,7 +571,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, void *first_elem =3D opaque + field->offset; int i, n_elems =3D vmstate_n_elems(opaque, field); int size =3D vmstate_size(opaque, field); - uint64_t old_offset, written_bytes; JSONWriter *vmdesc_loop =3D vmdesc; bool is_prev_null =3D false; =20 @@ -559,7 +587,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, /* maximum number of elements to compress in the JSON blob= */ int max_elems =3D vmsd_can_compress(field) ? (n_elems - i)= : 1; =20 - old_offset =3D qemu_file_transferred(f); if (field->flags & VMS_ARRAY_OF_POINTER) { assert(curr_elem); curr_elem =3D *(void **)curr_elem; @@ -606,15 +633,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, } } =20 - vmsd_desc_field_start(vmsd, vmdesc_loop, inner_field, - i, max_elems); - - ok =3D vmstate_save_field(f, curr_elem, size, inner_field, - vmdesc_loop, errp); - - written_bytes =3D qemu_file_transferred(f) - old_offset; - vmsd_desc_field_end(vmsd, vmdesc_loop, inner_field, - written_bytes); + ok =3D vmstate_save_field_with_vmdesc(f, curr_elem, size, = vmsd, + inner_field, vmdesc_lo= op, + i, max_elems, errp); =20 /* If we used a fake temp field.. free it now */ if (is_null) { @@ -622,8 +643,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, } =20 if (!ok) { - error_prepend(errp, "Save of field %s/%s failed: ", - vmsd->name, field->name); goto out; } =20 --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559240; cv=none; d=zohomail.com; s=zohoarc; b=KznVRlS395WYAHqV4mxMzN+TPmNf9Z1nnZVgPcLzjhT9INOo44hFpvbvJiCqOfWKEXmBNEk5RqEXd+z5G2mIS9Vz+l2MyAxtzr5LJaX2i4yY+u8T8zUmVQvS0cI4Jgis6/FGLgmK96v46hj8DUP8AaTB9Ln+CqOyAe/0Pya9LDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559240; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=drzSSQlOSjoFXZvAA8C13NBR1l8WjpxMK8cEocL7tFk=; b=BcWGWtkoVHOqqab1m7SPTPqjdM3ELyhkiUQsTfPip1VOgCc47RDxFmDXfmxhU80Bo/QXbqJQD7kBPHVpSngt0uVORLd9V70otD5e1WSmJlqaaq25v5ykPhfnUUF48WY6bzrIPBsMFkcjgY7CUFPkPZVFwAa/SrJYp7YE1JZ+JQ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774559240216124.66662944875634; Thu, 26 Mar 2026 14:07:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtr-0004AM-Nt; Thu, 26 Mar 2026 17:05:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtm-00048d-TU for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtk-00037M-Ky for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:50 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-3vcvptPhM3iQ_7TlSJOigA-1; Thu, 26 Mar 2026 17:05:46 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cfc61fc9b8so392397385a.1 for ; Thu, 26 Mar 2026 14:05:46 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=drzSSQlOSjoFXZvAA8C13NBR1l8WjpxMK8cEocL7tFk=; b=gCshdkB7ghR2AhJ+umAT8Pnart6ak7znr5w37awV6yY4TYK0UjlxNNG4Wc9jOQObh5cr67 XM1qSBd20bUFLTJEd5Tw6Lq+OisfTQaveedIUFSx+pkNKdLH/+xHDuP3ffe59Jihut9jQf nvux7i4qGsGoYDOfCyXt/wK3thyE/w0= X-MC-Unique: 3vcvptPhM3iQ_7TlSJOigA-1 X-Mimecast-MFC-AGG-ID: 3vcvptPhM3iQ_7TlSJOigA_1774559146 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559146; x=1775163946; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=drzSSQlOSjoFXZvAA8C13NBR1l8WjpxMK8cEocL7tFk=; b=bmD0M9zm67szEcrqC5BBWxcb4YipPB0z9bxfNzo/FWopx2oFPHaJJAmNmSPWP1Mzws K+m4vpKbotd4RCaYaKUkQlRcxUpOaN35ZEHQNCtEGq8lfaB0026lXRkiXy870RAlyaAy EcrSs7B004KAAuCZ69tlWu0n9z5eC/CuMt808BXgQMVm96NORHDymGgsLMOyalQB2unh qDk+ZuF+CAXtJ1N6KbA6NSkYTpw7p3k6OftCVMgQ9PttD/nuIa8Az5miuaFrv1bvSJ8L yEF2QurBzCEcEe/OKc531/yBmjiTPRnTE8SE8vf7tN6mZGl9sLV37oNQEAJNDnwRYTHc QzkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559146; x=1775163946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=drzSSQlOSjoFXZvAA8C13NBR1l8WjpxMK8cEocL7tFk=; b=I8lreW0MooP+niLBP+cElV8GdwX4J57KSgYVQbTZN3c0OYMJY1amS658iHgqxYN02L 3grOl5Zrr18PhoS3vy+SUK0SzDvbVmZrfO7TyjK5qXqLoSVj/7zx1Jg08W+Bf45FMfXv zcipUl8qNF/EksGLqvxbUwuQdVq/W3jtvfO4T9Rg3o6UlAJhrmalfTepgevr/djcFOol c7oe2nFzzoOMAVYl+pJbkmLdEwIp6wmHtlWdtt48QWxNUQ2hxKpWNy0ViKik4M0oC/Bq AGF/0I5x5tJrpy/bHFpqLe28YS2JPbTrKXecPwoi4w9PDvc549x1HF+1EuRp/uW2DPKo Tllg== X-Gm-Message-State: AOJu0Yzd1f8Te6bySNvFfc+syhL9BvyKygASXUhuSHaQj7RPsj6FON2H HW1No2QW895W3Gd2Npv41hc577J4CNNRS6rijI0qPTX3bJvHEi/prAJUsRMZzI2cijZHzdIksmq HcGEVtMI1W4EPmO4uTQtRf1Xdl0JxHgZfTxexma45MPNKMPVp6AyhY902Cy8kIc9hM7iqN3smll aS4F2Hju5HmJfFmDFFnS/YkiRZZBxx7TldKOGCKg== X-Gm-Gg: ATEYQzyvJgfN/8jQfmf0nzhFHGYCDMXkjGTCnm/gXLdQqFYryWkfKRBgV8+DOdEy302 74Jyjb9skkRfxgIppMwhJ0Gxdp/oizBuIv8B9tYHwEDKenqhuf01KkU0IzwFx2dtmrdH2RUEStx /lC+MHLT4hg2Sdr7/xThIrAIz0rPothfP+npQm3EQ/PcqMdSx3TaaskYyp3tLJEr3TshAuAXESP KN5+MPeeSpPQLqSyZDuQWWIr1rWjVeD6ghuV/wBGXizKE59qU+tTPhVJxKFOD96cGdBIzhwPOeV 0wH8t0T+UQLv4iuAJakxnQqa9PWVl66rLixCymtvDfrIY1nqbxYZOv1fFi6pD+ZA274xj1aDhTv Afo5Fobwztfk= X-Received: by 2002:a05:620a:46aa:b0:8cf:ed8d:20a3 with SMTP id af79cd13be357-8d0010f03a6mr1401551885a.42.1774559145591; Thu, 26 Mar 2026 14:05:45 -0700 (PDT) X-Received: by 2002:a05:620a:46aa:b0:8cf:ed8d:20a3 with SMTP id af79cd13be357-8d0010f03a6mr1401544585a.42.1774559144888; Thu, 26 Mar 2026 14:05:44 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin Subject: [PATCH RFC v2 07/11] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers Date: Thu, 26 Mar 2026 17:05:28 -0400 Message-ID: <20260326210532.379027-8-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559242343158500 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas --- 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 092e8f7e9a..2e51b5ea04 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; =20 -/** 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; =20 extern const VMStateInfo vmstate_info_cpudouble; =20 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 =3D { .save =3D save_fd, }; =20 -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) =20 { - if (qemu_get_byte(f) =3D=3D VMS_MARKER_PTR_NULL) { + int byte =3D qemu_get_byte(f); + + if (byte =3D=3D VMS_MARKER_PTR_NULL || byte =3D=3D VMS_MARKER_PTR_VALI= D) { + /* TODO: process PTR_VALID case */ return true; } =20 - error_setg(errp, "vmstate: load_nullptr expected VMS_NULLPTR_MARKER"); + error_setg(errp, "%s: unexpected ptr marker: %d", __func__, byte); return false; } =20 -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) =20 { - if (pv =3D=3D NULL) { - qemu_put_byte(f, VMS_MARKER_PTR_NULL); - return true; - } - - error_setg(errp, "vmstate: save_nullptr must be called with pv =3D=3D = NULL"); - return false; + qemu_put_byte(f, pv ? VMS_MARKER_PTR_VALID : VMS_MARKER_PTR_NULL); + return true; } =20 -const VMStateInfo vmstate_info_nullptr =3D { - .name =3D "nullptr", - .load =3D load_nullptr, - .save =3D save_nullptr, +const VMStateInfo vmstate_info_ptr_marker =3D { + .name =3D "ptr-marker", + .load =3D load_ptr_marker, + .save =3D save_ptr_marker, }; =20 /* 64 bit unsigned int. See that the received value is the same than the o= ne 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, co= nst VMStateField *field, } =20 /* - * 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 =3D g_new0(VMStateField, 1); =20 @@ -71,12 +71,12 @@ vmsd_create_fake_nullptr_field(const VMStateField *fiel= d) fake->name =3D field->name; fake->version_id =3D field->version_id; =20 - /* 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 =3D NULL; =20 - /* See vmstate_info_nullptr - use 1 byte to represent nullptr */ + /* See vmstate_info_ptr_marker - use 1 byte to represent ptr status */ fake->size =3D 1; - fake->info =3D &vmstate_info_nullptr; + fake->info =3D &vmstate_info_ptr_marker; fake->flags =3D VMS_SINGLE; =20 /* All the rest fields shouldn't matter.. */ @@ -278,7 +278,7 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescri= ption *vmsd, * an array of pointers), use null placeholder and do * not follow. */ - inner_field =3D vmsd_create_fake_nullptr_field(field); + inner_field =3D vmsd_create_ptr_marker_field(field); } else { inner_field =3D field; } @@ -583,26 +583,27 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VM= StateDescription *vmsd, for (i =3D 0; i < n_elems; i++) { void *curr_elem =3D first_elem + size * i; const VMStateField *inner_field; - bool is_null; /* maximum number of elements to compress in the JSON blob= */ int max_elems =3D vmsd_can_compress(field) ? (n_elems - i)= : 1; + bool use_marker_field, is_null; =20 if (field->flags & VMS_ARRAY_OF_POINTER) { assert(curr_elem); curr_elem =3D *(void **)curr_elem; } =20 - if (!curr_elem && size) { + is_null =3D !curr_elem && size; + use_marker_field =3D 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 =3D vmsd_create_fake_nullptr_field(field); - is_null =3D true; + inner_field =3D vmsd_create_ptr_marker_field(field); } else { inner_field =3D field; - is_null =3D false; } =20 /* @@ -638,7 +639,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, i, max_elems, errp); =20 /* 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); } =20 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 =3D ' (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774559243408301.8196726247836; Thu, 26 Mar 2026 14:07:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rts-0004Aa-BR; Thu, 26 Mar 2026 17:05:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtn-000490-11 for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtl-00037d-CP for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:50 -0400 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-KLeZFTGQP2CF_jLzXtMaSQ-1; Thu, 26 Mar 2026 17:05:47 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8cfc5294894so464506285a.1 for ; Thu, 26 Mar 2026 14:05:47 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1lTxzlXPcIkLTIzQtm5snIna0fiWyl7m583Ny0gqjgk=; b=LyFyV8KqgbbbUPTTq0Pgd6Ui4K1RD6JtqOGRY5UE0HQgilq+W9V9DIEzTXQaGRV1WdFcPA QJchM2bzR398MbzmFDMhiFA/aGetFC/cQR7fPawkA8oVg/tpFyUoLFLnuyOfpERHLYoJxm anUisCAtyzUnSnax0KiHe1SbMsKWlRU= X-MC-Unique: KLeZFTGQP2CF_jLzXtMaSQ-1 X-Mimecast-MFC-AGG-ID: KLeZFTGQP2CF_jLzXtMaSQ_1774559147 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559146; x=1775163946; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1lTxzlXPcIkLTIzQtm5snIna0fiWyl7m583Ny0gqjgk=; b=I9hgHL0QdibFZn5aR9wt0C6CI0J2vsSzVx10RNVMNMNE70bI4G44qKdp/HSiOQJ+mV f/g/PEWpvBxPB/aUnfzCvm30JXEZ8EQgQ13YocjaGcdvqOXumf0CTbIOIbmGJKfoU6Qi jAmu/2ECtefXrRo7dwEBXyUaq2D95QVfkt4NEomgpVhju0iFVIVLGGeIRoPdMmbxw5pG nPQl6QN/0GEAn4FLeOfzdRVyezzLWmC6Cnt/KleWI2Tfhok5ZY4AjKSRzjsykmU2Kgtm b6qf3i5puE4BLOMlRku2zjcGEdMNuW2Kn45yECny40NKP3lR1dFQD9mqjO/gRxFDxzO9 icZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559146; x=1775163946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1lTxzlXPcIkLTIzQtm5snIna0fiWyl7m583Ny0gqjgk=; b=gFAPduvGlMcZ87agwbtJnbEMMjg/sEjlVo+MRF3v54arTHei3gXMj/7TDSf5AksWpW /JFUCec6vlsuxV318EO1fctF7HtD2NZOSsXwHmEVo3YrDmR+PTYszF1kistE6zALP2Cx RrdhYoUu61ylbn8FgaW/mFCtZFcVFX5RkqE04D8Ct1ToZJGg+Fu6LV1mY8fPqcg06bGx efo/mcoVmNP2cIpspvzvcx1O6a+w04S7ll7FvPN3s7Q2A9natW5WUfJ2ztmY9XkwXYrV XMhhQFpfrfgdmQmFkeAhwBubTDOnWpWdSOmd5UML4/JjLJP80amOPV+GT0eWH5dyBjmJ pHkg== X-Gm-Message-State: AOJu0YwDfJEbHaFWTCdAfc8iH8LgFr9/jRQpayam4MqKpKMvCw6UHBwH 9RSs6GG2WvFsTyZdhRW/jMvPbyvZbicsaYSC0SFTGI2hXQn4xjuGqFqL+k/Lwe9LzaxrwkxFXYP 9KcnjOESt2cSGFok8uhiPewNkTbjYX8VkxtTImqtDd/1Cz0hcd+Kna0YdEdh9sf17FgsdkC7b5H Z0mWep/QR57+FCplQEOEHWsrJnlgDbfcgGagSCKw== X-Gm-Gg: ATEYQzw6Hrw9i0ftephe5WPgaCgxfFMeWkljOWhSR6YnltANsDtXFPeODN6TGD7YSbm YzXGdAtINFyX03e/X1sPdl4laUL1vLNIC5L0q4xR52eHf0Ss/7KSD1Ik2bqMQz2wSgAYncyWrvH HAEIHCKgHe54vfnYO5RJbsi435LUJezFscIw6fxjbx2+JO2+YnGMWNrh3+W5rVsRcBQ6W+ge0d5 o6GyvQhcGxlcseCFfdUOTyLmXDP5mhTJdHAFOaCzNfVCGSwRxnW3t++FEalFKKgLbWeJpeFNP37 KvWJyd7KVktLXTovnF1bWNSuhHaom6oKLmRoUglfnKmDxwMy9BZbF0eV55rJEDdmvzfkz1LvehA Mn/tsTPjAUfE= X-Received: by 2002:a05:620a:1a22:b0:8cd:8ddd:2699 with SMTP id af79cd13be357-8d000f5cd3amr1239516885a.24.1774559146311; Thu, 26 Mar 2026 14:05:46 -0700 (PDT) X-Received: by 2002:a05:620a:1a22:b0:8cd:8ddd:2699 with SMTP id af79cd13be357-8d000f5cd3amr1239511985a.24.1774559145805; Thu, 26 Mar 2026 14:05:45 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin Subject: [PATCH RFC v2 08/11] vmstate: Implement load of ptr marker in vmstate core Date: Thu, 26 Mar 2026 17:05:29 -0400 Message-ID: <20260326210532.379027-9-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559244171154100 Content-Type: text/plain; charset="utf-8" The loader side of ptr marker is pretty straightforward, instead of playing the inner_field trick, just do the load manually assuming the marker layout is a stable ABI (which it is true already). This will remove some logic while loading VMSD, and hopefully it makes it slightly easier to read. Unfortunately, we still need to keep the sender side because of the JSON blob we're maintaining.. This paves way for future processing of non-NULL markers as well. When at it, not check "size" anymore for existing NULL markers, and move it under the same VMS_ARRAY_OF_POINTER section because that's the only place that NULL marker can happen (which guarantess size=3D=3Dhost ptr size, whic= h is non-zero). Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas --- migration/vmstate-types.c | 12 ++++------ migration/vmstate.c | 46 ++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index b31689fc3c..ae465c5c2c 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -363,14 +363,10 @@ static bool load_ptr_marker(QEMUFile *f, void *pv, si= ze_t size, const VMStateField *field, Error **errp) =20 { - int byte =3D qemu_get_byte(f); - - if (byte =3D=3D VMS_MARKER_PTR_NULL || byte =3D=3D VMS_MARKER_PTR_VALI= D) { - /* TODO: process PTR_VALID case */ - return true; - } - - error_setg(errp, "%s: unexpected ptr marker: %d", __func__, byte); + /* + * Load is done in vmstate core, see vmstate_ptr_marker_load(). + */ + g_assert_not_reached(); return false; } =20 diff --git a/migration/vmstate.c b/migration/vmstate.c index b333aa1744..47812eb882 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -142,6 +142,21 @@ static void vmstate_handle_alloc(void *ptr, const VMSt= ateField *field, } } =20 +static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field, + Error **errp) +{ + int byte =3D qemu_get_byte(f); + + if (byte =3D=3D VMS_MARKER_PTR_NULL) { + /* When it's a null ptr marker, do not continue the load */ + *load_field =3D false; + return true; + } + + error_setg(errp, "Unexpected ptr marker: %d", byte); + return false; +} + static bool vmstate_pre_load(const VMStateDescription *vmsd, void *opaque, Error **errp) { @@ -264,30 +279,25 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDesc= ription *vmsd, } =20 for (i =3D 0; i < n_elems; i++) { - bool ok; + /* If we will process the load of field? */ + bool load_field =3D true; + bool ok =3D true; void *curr_elem =3D first_elem + size * i; - const VMStateField *inner_field; =20 if (field->flags & VMS_ARRAY_OF_POINTER) { curr_elem =3D *(void **)curr_elem; + if (!curr_elem) { + /* Read the marker instead of VMSD itself */ + if (!vmstate_ptr_marker_load(f, &load_field, errp)= ) { + trace_vmstate_load_field_error(field->name, + -EINVAL); + return false; + } + } } =20 - if (!curr_elem && size) { - /* - * If null pointer found (which should only happen in - * an array of pointers), use null placeholder and do - * not follow. - */ - inner_field =3D vmsd_create_ptr_marker_field(field); - } else { - inner_field =3D field; - } - - ok =3D vmstate_load_field(f, curr_elem, size, inner_field,= errp); - - /* If we used a fake temp field.. free it now */ - if (inner_field !=3D field) { - g_clear_pointer((gpointer *)&inner_field, g_free); + if (load_field) { + ok =3D vmstate_load_field(f, curr_elem, size, field, e= rrp); } =20 if (ok) { --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559243; cv=none; d=zohomail.com; s=zohoarc; b=hWggnx3kWxkN7GFyEPn5gO8qwbKiHa8xQHMIwniJ8JwJj7JLSwW81MTBI6YnmHHBS8vT8HDBgwDWLxVIXDzkj7n1uL+gatHh8B+ydduRuAjStipWYFcfLdZX1YwdpoJJbgcj16ii14odT8FxoxHwqyJlz/PEBiLYCqKFD/1aqhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559243; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+9bH3nFltdiRFFH0om8Ts5SFlEEyrXqfBGminAjx0uw=; b=hZyJ+C82lRbzQSyumbBi5CR7r89jb+9ThsrspMf7w4y/MFWrt+K6i9E+4vNUOF3f+dYoMqW7zhT25Rb2PUmlOklsFeXtqkAuXQ06LO99rua9R0K6Hi3DRhVFa/8B9RLnkqPpfPwtsG8jgB4KTHaORujIvvyQC8op5dOUx+7dCfg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177455924322912.573658528524447; Thu, 26 Mar 2026 14:07:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtt-0004Ad-09; Thu, 26 Mar 2026 17:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtp-00049h-2J for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtm-00038F-QQ for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:52 -0400 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-_u04Y0w7ObS0pQFhMdkYbw-1; Thu, 26 Mar 2026 17:05:48 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8cd7fc27cf7so412667985a.1 for ; Thu, 26 Mar 2026 14:05:48 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+9bH3nFltdiRFFH0om8Ts5SFlEEyrXqfBGminAjx0uw=; b=jMlGAQqrlGmDVmw5LOxRGl7aFgIjT8zqwoOkBhZN5WyD1w5gS/JW0V2a2qdcImqoJ32GBe 9gRM1BQI+vo380FglAtU4glqI8UtX0hkSEdr0p1IAwH6h5Zo4faAEylDN6WlE/MCor/AWx vKHL+HxFxzLJIu94zfO/Ljd42LmHQ6E= X-MC-Unique: _u04Y0w7ObS0pQFhMdkYbw-1 X-Mimecast-MFC-AGG-ID: _u04Y0w7ObS0pQFhMdkYbw_1774559148 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559148; x=1775163948; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+9bH3nFltdiRFFH0om8Ts5SFlEEyrXqfBGminAjx0uw=; b=BN0zb81DIElbCFFCX+91I1ARkwJEl0p/JUkM7zulPqrwNopS/IJj/DFOK4ilUDDSD5 Brg8gyhx4gJKHiISkLQKovokseJCU8/305DsFkZLxidxDlbyMD4sUfemefBqB/sTKr13 cR6T2bVOr8j2Iso/KNiNRpcRrKYfvvvbUYHzySShloB0+sN00eWnw2SQMmsEG/4zoPnb 8BjYOunQCM3EL4MfkOoxw5M4Ed0EX2+y/ABCqu9Rk9WfE8cIbJqmkYaov62A93Np0YBa Qg1CJ6tjvJ9mgOIFnUwTmx3hEXxuIcyhkWVwXSk/3Se03jvrPoPvMuLKV4dgr+excFL/ qHpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559148; x=1775163948; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+9bH3nFltdiRFFH0om8Ts5SFlEEyrXqfBGminAjx0uw=; b=shvtI0hte9elT9jGrQNkp83T5waXPAdV0zS0JL/hGXpSq7IEXSHU7XJ6PjTv9B4Um4 IG7aC0lKoLagSyE3WTLJunGJaIdFMD1waA6AX57wApwrsxAkjtJCPZCc5hXKDIEWjDT8 p7JrdzMxxFbFscskiNFeyI2mAIdk312eEvlGJnkHGzs+HL10RuDx3b0ScIt+MY/nml8F p/bdoFqc+N/o+pYzoZXxtVcbXBL1vHhjAMCCmrgc99RX51QbZd8u7nKwAMCJWzx1ZOFy lpuwz+1T9L6L8bPrGOJ8Cw+rGVj+4jnObhIOa2XhbMWLXZiez2uqsr29yc1g1To+5+Ag OqeQ== X-Gm-Message-State: AOJu0YxTaTAfHXy5jnzBgKyhzwOTDkvFqliKipKqXngM2pIMV6Tibjd+ tIsR+cKiOFvu9pJ8oUD8fz2fZc2VZc9Vw+7nWoCZCiug4UNt8e5ER+MipzsIToYL4YlfC/QcpGu bkz2U4YTHfGt70KeKiQYQiKxB96UD3r66kfRW9vTv7Ih/7gZ3PiYgoVB8dinAsxpDBW7uzacoUt WRS3U7vBEE4LA6fmNawwgpmo/4Wyd3MUWwN1vjKQ== X-Gm-Gg: ATEYQzyhSl9TyuMCJqPlqRqT4pwk7vUV6bnlZ7aHHrz9uLGxhpIuKEFOpOT0MMe9oXL GDJFFzahzVcrN91rOLBfLcWVrH894swk47nizBPEsop8ywgfyc5jj28bW+Rb9as0zzW0bccrdPa 1qdH3zVxhJWzVOI7p55CNOwTOo1tb1qmDxhFFxG7MkRel3MMrdTU+Qvme3cRcrMB/8QtxBy6XvX pUn5RTiy42+x6DDeXie0Gkrtp209xEfiYNZxCTvNVnVmnjxjZmBiZNEChV7XbiyidEvfyfoziXQ MYbwQqawDb2rMpFSHkmgMG/13a1ret1Cki3exnDly1J97RwgQpkoflNwLr+xGN1YMC+VmaN2SIB 3RXh/Wh4lS/o= X-Received: by 2002:a05:620a:3947:b0:8cf:db04:8a31 with SMTP id af79cd13be357-8d00100ea0fmr1306692185a.55.1774559147418; Thu, 26 Mar 2026 14:05:47 -0700 (PDT) X-Received: by 2002:a05:620a:3947:b0:8cf:db04:8a31 with SMTP id af79cd13be357-8d00100ea0fmr1306685385a.55.1774559146751; Thu, 26 Mar 2026 14:05:46 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin Subject: [PATCH RFC v2 09/11] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Date: Thu, 26 Mar 2026 17:05:30 -0400 Message-ID: <20260326210532.379027-10-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559244330158501 Content-Type: text/plain; charset="utf-8" Introduce a new flag, VMS_ARRAY_OF_POINTER_AUTO_ALLOC, for VMSD field. It must be used together with VMS_ARRAY_OF_POINTER. It can be used to allow migration of an array of pointers where the pointers may point to NULLs. Note that we used to allow migration of a NULL pointer within an array that is being migrated. That corresponds to the code around vmstate_info_nullptr where we may get/put one byte showing that the element of an array is NULL. That usage is fine but very limited, it's because even if it will migrate a NULL pointer with a marker, it still works in a way that both src and dest QEMUs must know exactly which elements of the array are non-NULL, so instead of dynamically loading an array (which can have NULL pointers), it actually only verifies the known NULL pointers are still NULL pointers after migration. Also, in that case since dest QEMU knows exactly which element is NULL, which is not NULL, dest QEMU's device code will manage all allocations for the elements before invoking vmstate_load_vmsd(). That's not enough per evolving needs of new device states that may want to provide real dynamic array of pointers, like what Alexander proposed here with the NVMe device migration: https://lore.kernel.org/r/20260317102708.126725-1-alexander@mihalicyn.com This patch is an alternative approach to address the problem. Along with the flag, introduce two new macros: VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT{8|32}_ALLOC() Which will be used very soon in the NVMe series. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn Tested-by: Alexander Mikhalitsyn --- include/migration/vmstate.h | 51 +++++++++++++- migration/savevm.c | 27 ++++++- migration/vmstate.c | 136 ++++++++++++++++++++++++++++++------ 3 files changed, 190 insertions(+), 24 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 2e51b5ea04..d844b46e63 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -161,8 +161,21 @@ enum VMStateFlags { * structure we are referencing to use. */ VMS_VSTRUCT =3D 0x8000, =20 + /* + * This is a sub-flag for VMS_ARRAY_OF_POINTER. When this flag is set, + * VMS_ARRAY_OF_POINTER must also be set. When set, it means array + * elements can contain either valid or NULL pointers, vmstate core + * will be responsible for synchronizing the pointer status, providing + * proper memory allocations on the pointer when it is populated on the + * source QEMU. It also means the user of the field must make sure all + * the elements in the array are NULL pointers before loading. This + * should also work with VMS_ALLOC when the array itself also needs to + * be allocated. + */ + VMS_ARRAY_OF_POINTER_AUTO_ALLOC =3D 0x10000, + /* Marker for end of list */ - VMS_END =3D 0x10000 + VMS_END =3D 0x20000, }; =20 typedef enum { @@ -580,6 +593,42 @@ extern const VMStateInfo vmstate_info_qlist; .offset =3D vmstate_offset_array(_s, _f, _type*, _n), \ } =20 +/* + * For migrating a dynamically allocated uint{8,32}-indexed array of + * pointers to structures (with NULL entries and with auto memory + * allocation). + * + * _type: type of structure pointed to + * _vmsd: VMSD for structure _type (when VMS_STRUCT is set) + * _info: VMStateInfo for _type (when VMS_STRUCT is not set) + * start: size of (_type) pointed to (for auto memory allocation) + */ +#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT8_ALLOC(\ + _field, _state, _field_num, _version, _vmsd, _type) { \ + .name =3D (stringify(_field)), \ + .version_id =3D (_version), \ + .num_offset =3D vmstate_offset_value(_state, _field_num, uint8_t), \ + .vmsd =3D &(_vmsd), \ + .size =3D sizeof(_type), \ + .flags =3D VMS_POINTER | VMS_VARRAY_UINT8 | \ + VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ + VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ + .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ +} + +#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT32_ALLOC(\ + _field, _state, _field_num, _version, _vmsd, _type) { \ + .name =3D (stringify(_field)), \ + .version_id =3D (_version), \ + .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), \ + .vmsd =3D &(_vmsd), \ + .size =3D sizeof(_type), \ + .flags =3D VMS_POINTER | VMS_VARRAY_UINT32 | \ + VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ + VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ + .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ +} + #define VMSTATE_VARRAY_OF_POINTER_UINT32(_field, _state, _field_num, _vers= ion, _info, _type) { \ .name =3D (stringify(_field)), = \ .version_id =3D (_version), = \ diff --git a/migration/savevm.c b/migration/savevm.c index f5a6fd0c66..765df8ce2d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -869,8 +869,33 @@ static void vmstate_check(const VMStateDescription *vm= sd) if (field) { while (field->name) { if (field->flags & VMS_ARRAY_OF_POINTER) { - assert(field->size =3D=3D 0); + if (field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC) { + /* + * Size must be provided because dest QEMU needs that + * info to know what to allocate + */ + assert(field->size || field->size_offset); + } else { + /* + * Otherwise size info isn't useful (because it's + * always the size of host pointer), detect accidental + * setup of sizes in this case. + */ + assert(field->size =3D=3D 0 && field->size_offset =3D= =3D 0); + } + /* + * VMS_ARRAY_OF_POINTER must be used only together with one + * of VMS_(V)ARRAY* flags. + */ + assert(field->flags & (VMS_ARRAY | VMS_VARRAY_INT32 | + VMS_VARRAY_UINT16 | VMS_VARRAY_UINT= 8 | + VMS_VARRAY_UINT32)); } + + if (field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC) { + assert(field->flags & VMS_ARRAY_OF_POINTER); + } + 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 47812eb882..9cd0a88ce9 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -153,6 +153,12 @@ static bool vmstate_ptr_marker_load(QEMUFile *f, bool = *load_field, return true; } =20 + if (byte =3D=3D VMS_MARKER_PTR_VALID) { + /* We need to load the field right after the marker */ + *load_field =3D true; + return true; + } + error_setg(errp, "Unexpected ptr marker: %d", byte); return false; } @@ -234,6 +240,67 @@ static bool vmstate_post_load(const VMStateDescription= *vmsd, return true; } =20 +/* + * Try to prepare loading the next element, the object pointer to be put + * into @next_elem. When @next_elem is NULL, it means we should skip + * loading this element. + * + * Returns false for errors, in which case *errp will be set, migration + * must be aborted. + */ +static bool vmstate_load_next(QEMUFile *f, const VMStateField *field, + void *first_elem, void **next_elem, + int size, int i, Error **errp) +{ + bool auto_alloc =3D field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC; + void *ptr =3D first_elem + size * i, **pptr; + bool load_field; + + if (!(field->flags & VMS_ARRAY_OF_POINTER)) { + /* Simplest case, no pointer involved */ + *next_elem =3D ptr; + return true; + } + + /* + * We're loading an array of pointers, switch to use pptr to make it + * easier to read later + */ + pptr =3D (void **)ptr; + + /* + * Some special cases use pointer markers: (1) _AUTO_ALLOC implies a + * ptr marker will always exist, or (2) the element on destination is + * NULL, which expects the src to send a NULL-only marker. + */ + if (auto_alloc || !*pptr) { + if (!vmstate_ptr_marker_load(f, &load_field, errp)) { + trace_vmstate_load_field_error(field->name, -EINVAL); + return false; + } + + if (load_field) { + /* + * When reaching here, it means we received a non-NULL ptr + * marker, so we need to populate the field before loading it. + * + * NOTE: do not use vmstate_size() here, because we need the + * object size, not entry size of the array. + */ + assert(auto_alloc); + *pptr =3D g_malloc0(field->size); + } else { + /* Clear the pointer to imply a skip */ + *next_elem =3D NULL; + return true; + } + } + + /* Move the cursor to the next element for loading */ + *next_elem =3D *pptr; + return true; +} + bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id, Error **errp) { @@ -279,27 +346,22 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDesc= ription *vmsd, } =20 for (i =3D 0; i < n_elems; i++) { - /* If we will process the load of field? */ - bool load_field =3D true; - bool ok =3D true; - void *curr_elem =3D first_elem + size * i; + void *curr_elem; + bool ok; =20 - if (field->flags & VMS_ARRAY_OF_POINTER) { - curr_elem =3D *(void **)curr_elem; - if (!curr_elem) { - /* Read the marker instead of VMSD itself */ - if (!vmstate_ptr_marker_load(f, &load_field, errp)= ) { - trace_vmstate_load_field_error(field->name, - -EINVAL); - return false; - } - } + ok =3D vmstate_load_next(f, field, first_elem, &curr_elem, + size, i, errp); + if (!ok) { + return false; } =20 - if (load_field) { - ok =3D vmstate_load_field(f, curr_elem, size, field, e= rrp); + if (!curr_elem) { + /* Implies a skip */ + continue; } =20 + ok =3D vmstate_load_field(f, curr_elem, size, field, errp); + if (ok) { int ret =3D qemu_file_get_error(f); if (ret < 0) { @@ -397,6 +459,16 @@ static bool vmsd_can_compress(const VMStateField *fiel= d) return false; } =20 + if (field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC) { + /* + * This may involve two VMSD fields to be saved, one for the + * marker to show if the pointer is NULL, followed by the real + * vmstate object. To make it simple at least for now, skip + * compression for this one. + */ + return false; + } + if (field->flags & VMS_STRUCT) { const VMStateField *sfield =3D field->vmsd->fields; while (sfield->name) { @@ -583,6 +655,12 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, int size =3D vmstate_size(opaque, field); JSONWriter *vmdesc_loop =3D vmdesc; bool is_prev_null =3D false; + /* + * When this is enabled, it means we will always push a ptr + * marker first for each element saying if it's populated. + */ + bool use_dynamic_array =3D + field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC; =20 trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems= ); if (field->flags & VMS_POINTER) { @@ -603,14 +681,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, } =20 is_null =3D !curr_elem && size; - use_marker_field =3D is_null; + use_marker_field =3D use_dynamic_array || is_null; =20 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 =3D vmsd_create_ptr_marker_field(field); } else { inner_field =3D field; @@ -657,6 +730,25 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, goto out; } =20 + /* + * If we're using dynamic array and the element is + * populated, save the real object right after the marker. + */ + if (use_dynamic_array && curr_elem) { + /* + * NOTE: do not use vmstate_size() here because we want + * to save the real VMSD object now. + */ + ok =3D vmstate_save_field_with_vmdesc(f, curr_elem, + field->size, vmsd, + field, vmdesc_loop, + i, max_elems, errp= ); + + if (!ok) { + goto out; + } + } + /* Compressed arrays only care about the first element */ if (vmdesc_loop && max_elems > 1) { vmdesc_loop =3D NULL; --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559249; cv=none; d=zohomail.com; s=zohoarc; b=R764s/f96v5oi8/uplmbhMxZOWV92uabP0ocO0qPUP19ScKiJq5sQtZlIvG6gDlB0CO7cJRTWWV1y5cZ2l+M8ycIvIOqqP7M6z/iJogxqeRYrZehjhl+nmy/OsA5X/JBghDNCpl+wHavfDHtrFMBXxY/nbPf/UkXMpoX5VKMt2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559249; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Xl4BeA9TjT4adRjjwuVr5ck8x18mt6Jrccqdq1Pqh9U=; b=H5OitvutskxMZ+9puiaPGMkmy7yzIORxBOBECiw9C/IyTJOFNl9ZAaPOKeWX/DWEx9BxUYiiBd+4j9W54bbTzh8OQQARgurSq8TStqVi95VqgsG0DEnVZomtl3zOfWpjT6IXsLyy14iidtR7Dqb+vjdP4VsNvfkgiP8ERYWQ6Vc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774559249689236.0813841011544; Thu, 26 Mar 2026 14:07:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtt-0004Ap-JA; Thu, 26 Mar 2026 17:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rto-00049J-Bi for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtn-00038N-0k for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:52 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-5L501rjRPY-PKxq6YZvyHg-1; Thu, 26 Mar 2026 17:05:49 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cb706313beso250159285a.3 for ; Thu, 26 Mar 2026 14:05:49 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xl4BeA9TjT4adRjjwuVr5ck8x18mt6Jrccqdq1Pqh9U=; b=Dsv0NW9VMPdkxo9LcUYol7hlaBUiBN+UJfoO8QgMe/tjVqymEueu2HFLiI+TxY5wPqGiqn 0krT6JhFs1i0XZPJ2G/S4AAwdZMV3t0rBsIRLKV2FJpib9jxYxuANQ17DgduOSsR28Nz/X y6+eNVOvxSCcptJglzikAGtUQLX+2fI= X-MC-Unique: 5L501rjRPY-PKxq6YZvyHg-1 X-Mimecast-MFC-AGG-ID: 5L501rjRPY-PKxq6YZvyHg_1774559149 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559148; x=1775163948; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xl4BeA9TjT4adRjjwuVr5ck8x18mt6Jrccqdq1Pqh9U=; b=RLknSWMGyC/CqluCmFJ2jn/cghqwN4Cxtl7UNIo3tKqt+KlYcOqL+1Y7J/ywFUpEPT NrYx72f17Qq+N5bBkPlZGagmZ/dJaKqdwGSYq5FTjWnqz5EwTguDTvE8xWxvO7Cr/KQO hhnR2P06Lxt9SeIKstgVAU3Lm6GUBmh6JuNgUYBZrwzxpkrJMN64OubAOVwniTQEPVF7 WnVleLDyuFVAGqf3OpX6U9r2Ox4ZEX8sUL6HKw+1LxnXMfeJkJqjBReSZun2fQQ6c6To jEAuNqVjmVNXG1lYGJyyzrwPClQANV42+DxCCD6/MuOL6HOgwXKbNrXna3j28zlSjwP3 fK0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559148; x=1775163948; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Xl4BeA9TjT4adRjjwuVr5ck8x18mt6Jrccqdq1Pqh9U=; b=L1hBtHDQD82VKVanfdQsLdVUtQOzHHrGtOa/7a9APe/S7xOtmifUtlRkWnFvEa3jsc EiIu2pLv7nr9L3mjmYoASY2l6dlMx0WuurcO1lgM1ZmDwTloFel5o0EqPA1W/rB8xHyr 29VP26MIkSNJm6Bt03pJGh5h8ampL68yDalSeuqwg7bfwu3jyfU+mNmRsCkO2Didt17g pUdAwhU2/v0XksjzQ+jf2jleQMupUV3x6jkJmGifaYlxmiu6BbLDxt56IL/Gof2t+qtD AzMsJyKY/2BMld7nVMDHdpGdS1HZRxZ0EiMWSY7c0+2Z/qyUYJhKTLokYkFW2Ivi6zgK /McQ== X-Gm-Message-State: AOJu0YzQwKdYM2DASQROQYJFfpbxdkZfnngIouvqEF12+feU59cXqxCC 6HV5DaOY9JgVf5hlp6ErGaohYhrUec6y784UqB7XQUpQ92H+RXipqwEDO/4Wl4hoEZt2NtT+gjx Rdo3Z3O6eJe0BoEtathdu0EfCDOrBO5wqdHtjw343HAjqsz03Scrf2Ykaxg3HCZGSbuY6W6bucs SFZgMZPtFUFSIKZYdv/GxaPvJU9hFRlbztIMQ/5A== X-Gm-Gg: ATEYQzzvJGi1BqOYL0P7DU30QyZaVzKEwjejNq/N/Fr9Zm9fnLl2vFXJkAWZYKYMGNC EVwUNEPvBdWAU5VevRKVRev/95kxm0QrFLzSfall6pDCj8RtwyV3O0qH+IifiTZVjONwuoL8vxF aLboWfunh0/J/kqifuQj1irZ85FGDGZ/uo3djWQ507boU2C8NVJd3k5FawX7YX+wYFhR/CFGQbe eV+2ujBCY2smm9yNUo8dN6i38q+m8z/qLTElKUKfeSg2djH3vgazI+ELYmA3xVOOoKbGYCNAAy/ TmZwO3Ei9YnvIaps4mvWvxf7BVs4NRYJFejEZlb66ZpRsfl+8ndY6qkwtGvYyhlro+n5f/GkxJm oPfKRA9k+IwQ= X-Received: by 2002:a05:620a:400b:b0:8cd:b61f:2f48 with SMTP id af79cd13be357-8d00100bc68mr1252415785a.42.1774559148325; Thu, 26 Mar 2026 14:05:48 -0700 (PDT) X-Received: by 2002:a05:620a:400b:b0:8cd:b61f:2f48 with SMTP id af79cd13be357-8d00100bc68mr1252410185a.42.1774559147640; Thu, 26 Mar 2026 14:05:47 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin Subject: [PATCH RFC v2 10/11] vmstate: Stop checking size for nullptr compression Date: Thu, 26 Mar 2026 17:05:31 -0400 Message-ID: <20260326210532.379027-11-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559252292154100 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas The NULL pointer marker code applies only to VMS_ARRAY_OF_POINTER, where the size is never NULL. Move the setting of is_null under VMS_ARRAY_OF_POINTER, so we can stop checking the size. Signed-off-by: Fabiano Rosas Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn --- migration/vmstate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 9cd0a88ce9..1923602f3b 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -673,14 +673,14 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VM= StateDescription *vmsd, const VMStateField *inner_field; /* maximum number of elements to compress in the JSON blob= */ int max_elems =3D vmsd_can_compress(field) ? (n_elems - i)= : 1; - bool use_marker_field, is_null; + bool use_marker_field, is_null =3D false; =20 if (field->flags & VMS_ARRAY_OF_POINTER) { assert(curr_elem); curr_elem =3D *(void **)curr_elem; + is_null =3D !curr_elem; } =20 - is_null =3D !curr_elem && size; use_marker_field =3D use_dynamic_array || is_null; =20 if (use_marker_field) { @@ -708,7 +708,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, =20 for (int j =3D i + 1; j < n_elems; j++) { void *elem =3D *(void **)(first_elem + size * j); - bool elem_is_null =3D !elem && size; + bool elem_is_null =3D !elem; =20 if (is_null !=3D elem_is_null) { max_elems =3D j - i; --=20 2.50.1 From nobody Thu Apr 2 18:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774559239; cv=none; d=zohomail.com; s=zohoarc; b=DS7RCywBVWaVVRtC/sRVBkWQXhms5k9j9fFz+ivM8xN2VRwPrZvjE2NhYIbhXAZkOA3fcZ7HLk/5JV2BjGReKjHmf9uf2OE88q7/nV4TbXv7Fmgdwk0HPYs/WM6EL3xHh9JUyDC703wqW96Bu83F2AHlOiPDUpeOIfte/Spfxg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774559239; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BTcRRki4RVI+IH0q3dAynZQWyxZQTTE18znN3ItjLD4=; b=BA7V4HNCJ2LdkCvYKKGPIL3vTpCdhfcV4JxNTaacwzNtC3hUxngE/OsIyHdTnBLeam9Mqv74+ZxzZXQhN5cTGskhWIb7uqhhAVFaEJUUGblwwloiBIijzwg8wredraZA077+j3oWURVQ/WYsmhNO3IRCMrOdTRf4DaU89J4lTaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17745592398200.332846938023863; Thu, 26 Mar 2026 14:07:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5rtt-0004B5-TF; Thu, 26 Mar 2026 17:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtq-0004A0-SL for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5rtp-00039Y-6K for qemu-devel@nongnu.org; Thu, 26 Mar 2026 17:05:54 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-Aiqq05axPSWobj6hgbuy8A-1; Thu, 26 Mar 2026 17:05:50 -0400 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-89c4ec516e5so62601016d6.0 for ; Thu, 26 Mar 2026 14:05:50 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e4fa7d9sm353479785a.32.2026.03.26.14.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 14:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774559152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BTcRRki4RVI+IH0q3dAynZQWyxZQTTE18znN3ItjLD4=; b=EBmXSVH3I9o/i6OYM80KziZ+6GuoCR3ItrDzblS2vIHBMhgdDhNfhszFUhMcMl7twxVFa6 aEhdm1fyfJPC2ZRTaLM9ep0Yjm8RT59sS/zs7zxpAkhl7p1kRp98azti1Iub+QGen4wnPV s/pFmz5Ia7HRtIOBJftebREyrg75tqM= X-MC-Unique: Aiqq05axPSWobj6hgbuy8A-1 X-Mimecast-MFC-AGG-ID: Aiqq05axPSWobj6hgbuy8A_1774559150 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774559150; x=1775163950; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BTcRRki4RVI+IH0q3dAynZQWyxZQTTE18znN3ItjLD4=; b=ATCQ2GNE5zCX9ltgtp8JrzwulO2Nmq5wvAbnqD2F2GMEkTA89M6j8+lFWFOFJW8HTV TyiBhjhwjzFoy9VMNwKm62vYww8D2ukuTjHsloumiONBfnbHrfOQMj6U0qna6CYaZvSz F/VHw97bn9/eRDI0ns0OA/lCh8pt/IOWHT/mezskwEeQBB0/LRZLq7AfUKiwdQG0jf7R 9LMGWXq9MZitf31yU190kq+e++KqYHrOXZBckbQ0nb0YqI1vwz5Iuq9JZpRURDRI88zF YwTVWVfEKaClKNE54zNEXEdMiOlfi3PSI/yB7Y4YPxORihf2ktSIGSxmmsXmzaMdZttr oORA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774559150; x=1775163950; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BTcRRki4RVI+IH0q3dAynZQWyxZQTTE18znN3ItjLD4=; b=rjZSp81mc8L3AraJ7oTv1Shp//7kpVZotI0UA8aXQ9an8Di1ZJxpFd/sxvk4CFXMuf dKlb9VBl1IQpaWxMQkOE3FnNNUXD2EXiBBAJKJNOVuOzEAwpr0LIr+GOh+VjkxmXJI1K qY3F5izN0ayFuNhw+vfYo0DUWo+WtC3+ntG58M5dqB45WQuyc2qrmEgMFORQzz8oS7zc xn2+aTTbahHCYhXOGLJdkVApBTInhrlX76tmFhE4ZoTYvMREZg910NPX2BRCwz5VWCbO clL3WXBT9rD9J2uevlAw0Ey3EFsEVjZCyBMHYZzxToE67heR283cxc+HUvOBhiipCqL4 muMg== X-Gm-Message-State: AOJu0Yx2ZLww8YYcEeE4uAzYDqWfa6ZyGqmydvScuc0PEPoz610poNEP zqePeYFptNLIC92gB9P+h++zEdOUeIp/vjafgaAjQO0gE5p6tzjVT0lObY935F329TGbz23RPyQ QBY1uWjs/SaHUQEeYxneZKPfq1GLr3vagplxii7Pso8HHD5QjjWwP+9uhUkL4g5AIFlNVoa7ZPr Rev8CapoRFqp5pCF6tCjn6F0h3+Kp5rbkQL2pKmA== X-Gm-Gg: ATEYQzyqAxwNQzx1zMIaLzF/gbC4ydSn7tk0LTauxIFjV0yMzYCGf3ojkk/Gx89254a 0VFXnUbGK83MPUvUJNQL4DQcoZK8ysSf0g4r+Hm22BcwYOQoNGmsemMxF1ggVvMpUp8g9QVzJp3 NwfIihR4u+lofgQ5rrYLv06QUgW2mY6yVOqsiAZXjmAZGY4ue/OwS1jcJDwQMdOzbXPMQ6YL/iu BPKdJO9DH00fXkgsjTxBq+oV+d1qAXqDqQgjWf9LtDc8DLAzSCaRrcM3OJob0UixRD+djpNBt93 ywSA32xLXNYETWtnd+CS3PNdcgdmPXK7l84HJVwMNkWVnhQs1wl0ogpSlxmUMs76/BpxwYvrScC OjrOBkcXfCP4= X-Received: by 2002:a05:620a:4449:b0:8cf:d469:8456 with SMTP id af79cd13be357-8d000f85e87mr1224703785a.4.1774559149547; Thu, 26 Mar 2026 14:05:49 -0700 (PDT) X-Received: by 2002:a05:620a:4449:b0:8cf:d469:8456 with SMTP id af79cd13be357-8d000f85e87mr1224696785a.4.1774559148749; Thu, 26 Mar 2026 14:05:48 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , peterx@redhat.com, Fabiano Rosas , Juraj Marcin , Alexander Mikhalitsyn Subject: [PATCH RFC v2 11/11] tests/unit/test-vmstate: add tests for VMS_ARRAY_OF_POINTER_AUTO_ALLOC Date: Thu, 26 Mar 2026 17:05:32 -0400 Message-ID: <20260326210532.379027-12-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260326210532.379027-1-peterx@redhat.com> References: <20260326210532.379027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774559242260158500 Content-Type: text/plain; charset="utf-8" From: Alexander Mikhalitsyn Add tests for VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT32_ALLOC. Signed-off-by: Alexander Mikhalitsyn [peterx: Removed two tests due to macro not used, rebase, fix warning] Signed-off-by: Peter Xu --- tests/unit/test-vmstate.c | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index dae15786aa..df1fb4c778 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -702,6 +702,88 @@ static void test_arr_ptr_prim_0_load(void) } } =20 +static uint8_t wire_arr_ptr_with_nulls[] =3D { + VMS_MARKER_PTR_VALID, + 0x00, 0x00, 0x00, 0x00, + VMS_MARKER_PTR_NULL, + VMS_MARKER_PTR_VALID, + 0x00, 0x00, 0x00, 0x02, + VMS_MARKER_PTR_VALID, + 0x00, 0x00, 0x00, 0x03, + QEMU_VM_EOF +}; + +typedef struct { + uint32_t ar_items_num; + TestStructTriv **ar; +} TestVArrayOfPtrToStuctWithNULLs; + +const VMStateDescription vmsd_arps_with_nulls =3D { + .name =3D "test/arps_with_nulls", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT32_ALLOC( + ar, TestVArrayOfPtrToStuctWithNULLs, ar_items_num, + 0, vmsd_tst, TestStructTriv), + VMSTATE_END_OF_LIST() + } +}; + +static void test_arr_ptr_nulls_str_save(void) +{ + TestStructTriv ar[AR_SIZE] =3D { {.i =3D 0}, {.i =3D 1}, {.i =3D 2}, {= .i =3D 3} }; + TestVArrayOfPtrToStuctWithNULLs sample =3D {}; + int idx; + + sample.ar_items_num =3D AR_SIZE; + sample.ar =3D g_new0(TestStructTriv*, sample.ar_items_num); + sample.ar[0] =3D g_new0(TestStructTriv, 1); + *sample.ar[0] =3D ar[0]; + /* note, sample.ar[1] remains NULL */ + sample.ar[2] =3D g_new0(TestStructTriv, 1); + *sample.ar[2] =3D ar[2]; + sample.ar[3] =3D g_new0(TestStructTriv, 1); + *sample.ar[3] =3D ar[3]; + + save_vmstate(&vmsd_arps_with_nulls, &sample); + compare_vmstate(wire_arr_ptr_with_nulls, sizeof(wire_arr_ptr_with_null= s)); + + for (idx =3D 0; idx < AR_SIZE; ++idx) { + g_free(sample.ar[idx]); + } + g_free(sample.ar); +} + +static void test_arr_ptr_nulls_str_load(void) +{ + TestStructTriv ar_gt[AR_SIZE] =3D {{.i =3D 0}, {.i =3D 0}, {.i =3D 2},= {.i =3D 3} }; + TestVArrayOfPtrToStuctWithNULLs obj =3D {}; + int idx; + + obj.ar_items_num =3D AR_SIZE; + obj.ar =3D g_new0(TestStructTriv*, obj.ar_items_num); + + save_buffer(wire_arr_ptr_with_nulls, sizeof(wire_arr_ptr_with_nulls)); + SUCCESS(load_vmstate_one( + &vmsd_arps_with_nulls, &obj, 1, + wire_arr_ptr_with_nulls, sizeof(wire_arr_ptr_with_nulls))); + + for (idx =3D 0; idx < AR_SIZE; ++idx) { + if (idx =3D=3D 1) { + g_assert_cmpint((uintptr_t)(obj.ar[idx]), =3D=3D, 0); + } else { + /* compare the target array ar with the ground truth array ar_= gt */ + g_assert_cmpint(ar_gt[idx].i, =3D=3D, obj.ar[idx]->i); + } + } + + for (idx =3D 0; idx < AR_SIZE; ++idx) { + g_free(obj.ar[idx]); + } + g_free(obj.ar); +} + /* test QTAILQ migration */ typedef struct TestQtailqElement TestQtailqElement; =20 @@ -1568,6 +1650,10 @@ int main(int argc, char **argv) test_arr_ptr_prim_0_save); g_test_add_func("/vmstate/array/ptr/prim/0/load", test_arr_ptr_prim_0_load); + g_test_add_func("/vmstate/array/ptr-nulls/str/save", + test_arr_ptr_nulls_str_save); + g_test_add_func("/vmstate/array/ptr-nulls/str/load", + test_arr_ptr_nulls_str_load); g_test_add_func("/vmstate/qtailq/save/saveq", test_save_q); g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q); g_test_add_func("/vmstate/gtree/save/savedomain", test_gtree_save_doma= in); --=20 2.50.1