From nobody Sat Apr 11 18:37:55 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=1775075370; cv=none; d=zohomail.com; s=zohoarc; b=QoMPYUfFLJA5C+il+mORaA7pcv++uSyLwAWWTAe9Et1xGEKtco6kXbr4Nw8SI8ADJNhF0WjaoczCeCB8vxMPJv0zHLX3XXzXhDq3Hicsfp9H1s8ePibpiC6qe24Hm1mBNUx4vZBNu0TkMHnWRhS8rF1x6leXBy710xBEP0RaL9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075370; h=Content-Type: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=kb2EMKRNvdGGvafy+iD9MxCie+cNqjcod0U6cR8fsMU=; b=FrVtJfju0DcMOoJMArytqZv2HORBQiKXOc122txkoCt67+MKaUS9a0SsNHJQyeeg9z+QOCOxA60ukC8opBoDoG8j2+cRmqIaBnzb1oCLGjzvpB0d6mRoxREHRvmNRFZbpu3kCqlTf7DsrVPzaOIqGcsBuNFEz9gf4TGq1alcDVY= 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 1775075370258401.6808767267007; Wed, 1 Apr 2026 13:29:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BM-0004Ij-SU; Wed, 01 Apr 2026 16:28: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 1w82BL-0004IF-8x for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28: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 1w82BI-00037d-SX for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:55 -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-369-r6_3a1X9MvCFWx1yetxmMQ-1; Wed, 01 Apr 2026 16:28:49 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8cfc575fa15so81095785a.2 for ; Wed, 01 Apr 2026 13:28:49 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kb2EMKRNvdGGvafy+iD9MxCie+cNqjcod0U6cR8fsMU=; b=WAXYEqfxt+fXMFD5e7Qbuy2WTbBpawK9CFixg/NP2cwYiC50y9Hc/lh0zr86C8IaHT8mFm LFKtinuonJ9KKKojYnlij3W+JiormaUJmwTibzux5Tt8LMMN5xLJwWq0+nW/Pnlu0UEkT2 mK/i+y3nQkO/9I5xpxgPPsT3Ml7OgN8= X-MC-Unique: r6_3a1X9MvCFWx1yetxmMQ-1 X-Mimecast-MFC-AGG-ID: r6_3a1X9MvCFWx1yetxmMQ_1775075329 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075328; x=1775680128; 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=kb2EMKRNvdGGvafy+iD9MxCie+cNqjcod0U6cR8fsMU=; b=LzIQOCW0SuWXVoljHadEzaXPLnn4rYYvI2VeNK9mJiB/NJ1Uru3K6iNqQ1Inn54pW1 /SBb6h+1ii/hgqTEdVSO1mJoRJGJgJEoCXsqlcAgL2YnEFuqAvnUch6oKlx0WYfOh+iE EZ3fi8pCoUDfb4+xsg2c0B5j7uE2liv2NgEYt9RQ1NVS1tVqVIPWB05536qlZAInyQ9v 1tegFsC5Z/c5VD6qWksSl3Wd0Byb5OxwrRCYfqzCTWAcu+VYNUwV7lGbw1Facz0xGcZT 28hwH3CBOZGPh8IMVCP09IZCBTcPbC9evzKIzIHUp1raBJJaaVRA44NB+HvBzskdrI9Y +l1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075328; x=1775680128; 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=kb2EMKRNvdGGvafy+iD9MxCie+cNqjcod0U6cR8fsMU=; b=igHT8pPcb+rg1KgQMCWD4CbfAMCBLFX7TJabMAO+oSFbdYNAQHrycAw9jwfBLfpie4 HCmErjJU8xe0iPXJfnQufPWLOxuGGdgD76Rd79eCVcYTYaqQgbsddxYGfa0zfJzpW/Rx 7gRN4Ks31+NWnKd2gsC8dM7f14Sx8hfrfygd49Sm5tBxYb9+8qi9bCixxHWadmaix5Xh kMYPgFWYe7uMsz6Ebtu8KCe0ifrhs8LzKqMVDHRWmURHyXfeKf6CqT2BlmfxHgYgVbvd 7PCOaPw4RmGKCzrB1pBT3TeDFQqhhmo8p3Gzb4klNBSosmP7qMqu7dWza0LcEhO8JQM3 ZvJw== X-Gm-Message-State: AOJu0YxZCVrZ8Bwbw9Ziuac0NG2QUNFxcYFcqEmIc8KSO3HfiB3Vx7S1 XXG4qq3MQ9VQivpb30crEGb3m18WbHbkcnVtZdu8po7KDvvGxpLDeZUUdlC+Lhs10ew+sPHOMi6 4iUe+b90/55vud9oHxnTXkmTkC3LzZEgtVg+tNHyX/1Cb6dHRCmxgh7bruna5kluXNVtXg4fWqY zPAI5kGemcvEVy0A+gQhB5AHViLeVYnw/I1bViRw== X-Gm-Gg: ATEYQzyby4+cbEIS2gBZfGo1KN4ExBVaKmKElm+Zjdxzsm5Z7EhJgHKr+p1fysl85x2 wMx7BKDWCqclYuBvEHeJz9hC4h9dB2TWu903729ncFuu6ckTBlodaZw2mtEPactLJHIMJSg7Nb1 xFU9/2+L9KQkcEKOADFJyLliRMM60c1QAvwR3rH1+w5O9PWubjalPcsumhUSBhygzuVe7UGtoWU N/faJX3EJ2ahsSQEmJK63h9K4sIccr7VhstFzBVfdlC3v/pijqfln1+f3MtKcE+oigxnKeRO3tb 3YoMVNyZ7MDOjcDAGy/wl9Px0izu/vhU1uibsHPDOHjNvMFE8S1v74Tw45JkfyfLfGE8v+jKW2Z m1VNtpAzCNvvPI1iVcGnZr3fYvUU2LsVcvYoiOBFRN+I= X-Received: by 2002:a05:620a:2845:b0:8cf:b7c2:fd20 with SMTP id af79cd13be357-8d1b5aac057mr736321285a.11.1775075327841; Wed, 01 Apr 2026 13:28:47 -0700 (PDT) X-Received: by 2002:a05:620a:2845:b0:8cf:b7c2:fd20 with SMTP id af79cd13be357-8d1b5aac057mr736317485a.11.1775075327295; Wed, 01 Apr 2026 13:28:47 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 01/11] vmstate: Pass in struct itself for VMSTATE_ARRAY_OF_POINTER Date: Wed, 1 Apr 2026 16:28:34 -0400 Message-ID: <20260401202844.673494-2-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075372730154100 Passing in a pointer almost never helps. Convert it to pass in struct for further refactoring on VMS_ARRAY_OF_POINTER. Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- include/migration/vmstate.h | 6 +++--- tests/unit/test-vmstate.c | 2 +- roms/seabios-hppa | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index d4a39aa794..d4880e75c2 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() } }; diff --git a/roms/seabios-hppa b/roms/seabios-hppa index cf3a472f4d..1a8ada1fb7 160000 --- a/roms/seabios-hppa +++ b/roms/seabios-hppa @@ -1 +1 @@ -Subproject commit cf3a472f4ddea30d2d483a8ba4b005505f0dabb3 +Subproject commit 1a8ada1fb70643172e251aacbac673c9ecda99e9 --=20 2.50.1 From nobody Sat Apr 11 18:37:55 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=1775075399; cv=none; d=zohomail.com; s=zohoarc; b=PQS+WuRy8vf6Vu64EtUJYpL2K0/3U8V2x0rnPZI8oBr6YsVgFfajK0iabXN06pT+A6wGJ7xPnqt6G6JmrxSrEpJQbL3LwbqwrOYVVNxdX4wv826W2y4ZGgwrtFgxCleESBP/166MtcaPAEJ11VgTV3HVbBeYQVCzL9lBFNPQXNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075399; h=Content-Type: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=eRbvL+0t6sjZnldiXjIF1mD8feBd0aVCt4GXp2N7Shk=; b=TbgW2gIEJwaXyaYb6S582/pWl6mTWB4f00USk/ubft8lmbWL3+OTmACk+IH6LzWpMBl761fvP3Y2i9hKxaP6cdDP6dGrHnT1SVvFdVhSzICB3KxKF9Axg1B7vha6XFQkZat8HtFXJNYzkuHES7OyPTNTQGWku7RX0TwGhfO+CeY= 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 177507539989019.502361701332575; Wed, 1 Apr 2026 13:29:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BR-0004Kn-RO; Wed, 01 Apr 2026 16:29:01 -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 1w82BM-0004Ik-Tm for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:58 -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 1w82BJ-00037r-J9 for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:56 -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-126-hNl_X9wDPvyqrP42-nHMbA-1; Wed, 01 Apr 2026 16:28:51 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8cd767c51efso23209185a.2 for ; Wed, 01 Apr 2026 13:28:51 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075332; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eRbvL+0t6sjZnldiXjIF1mD8feBd0aVCt4GXp2N7Shk=; b=GUC+Cy/9EtJrG9EmWG3s6PPHRpajmtgeiJmT7abHsiMmK/r4IxF0vrRwD4b7yE7eaggS1T nYMVcA3idKihxA1I9dngQaYuBlrAhb2+R5VUfouHotlgBChAESK8UWpuPGDVa5ZAzYZuYJ YCQLsEgHo/jlAeNmMS5ulPz6NofrXBc= X-MC-Unique: hNl_X9wDPvyqrP42-nHMbA-1 X-Mimecast-MFC-AGG-ID: hNl_X9wDPvyqrP42-nHMbA_1775075331 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075330; x=1775680130; 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=eRbvL+0t6sjZnldiXjIF1mD8feBd0aVCt4GXp2N7Shk=; b=BfR5clHOxv3cdlaifnv3Iv2o0L3iOb8jtBBa3tg/bQ+Mj16YdJylASIwF2qdAYIdWp s1eIGKfwqmAHHHD/Evo67No+GIOFBxs8Xh/4l9z9Q4Gl85dIByq/kuPYUfx8F8qKcxmh mmonToF63PYYBMG+C2PlbtVdd3VaN6lShX7+qP7ESx7CUczu7yVvvAU3Bs7X6X+5AcpB BrVsb9OO2oYAAVfEGF68kFYQ+0hK/otgexDctVSRZcDu8IJCZ6KF9s1E3+3wRCYompyJ 0fdEYJhEN+Ry2kBoXGHLP6WM7hcZbRhdCqFJWotxvGdQIFtlI0DUSqU2CVXciDaaL4wa O6QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075330; x=1775680130; 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=eRbvL+0t6sjZnldiXjIF1mD8feBd0aVCt4GXp2N7Shk=; b=CmtRwxx5ESEoJdR/Rg93K96fOKQ7d0lr0XEb2ArBwX6tNFL8eFA8BeTanMBKIUA7iF +32uuMRGRNpVST0uyeBG5YkYX55dF+WUUERagimHmNfn+ztAwx6su6FZWCjfF+bBiUS6 Bu1aWuoHp3RWKLenuTSyimdeI6CBVv1xCSyTNyqnAu0Fb0eegsbQgPLRYHRzwsvxDwSN 4BeLf+wqIRd4XO2+6Rv1rnUj9Oi2p5IANZQg+J/CMJfHVCiu4cnCQleug42fWZsSs9wh 1RJifyoTvbFbwUZipctYfZ58511IhfhQBsGlTfe82JIHJ+EpippkiPepy64JEInhIO+/ 5yCQ== X-Gm-Message-State: AOJu0YyYLL/JWMU4rk28G8c8sDTtC8AI4vnbIu8I/N5k357b0ozqhmAu IY/N2zz/nd8rZ8zRlzwbcWWlQTHsIHYNCekwyAiXSCk7YQPy/ZdNGX/MqLmUPxARIzwHhL+lrhX 5Q83VMIrYEXmk1WNTFIdqgaeuoF2nO2RYZ7+fCDgkkugISti/NYyvovun3NiXkQuhZ+Kyjga5zF e7zo5hXgs1DkiO2itrJhUOVmIkVJ4aCaWHYKJzUA== X-Gm-Gg: ATEYQzz+OtqNc0JlKiPeAl5oDi9czOmJZtNZYn5tfgAExz8yss5clQlf6vlUXWrZRg4 TBHOMqpb/yGJGkSxOmd66wA6eLWfrNa6aKZ19npqr7QWAI16InLM03LgSOJchnT2RWOH2Yz99/E IOX8mCfBOJQ9uBWGlyUoxZP/2BLZDyNyIOoeTHJSaDXeZ5duG8bzZLMzSxTIHetgp2iZkQLwESY oNvfyALzwBPSLIWdgUvdx5z4cnw0l12PjBQItfKBNExpCr4M46KLCRtmeL26wOw1Qi8XjyOKM2h e2o3bv+Qun5oSha9rrCGXQjc1Y/2xHwnQxRiSfuR9QY7FRNPLrB3Z0ppBqSU4K9WYCivIqCmsEc tevoRkUpMC6aPxsNgZ+ixPEdoS+7vnTdUZkNK57e2A4c= X-Received: by 2002:a05:620a:711a:b0:8cf:d2a0:d8b6 with SMTP id af79cd13be357-8d1b5a9fe41mr744037985a.10.1775075330282; Wed, 01 Apr 2026 13:28:50 -0700 (PDT) X-Received: by 2002:a05:620a:711a:b0:8cf:d2a0:d8b6 with SMTP id af79cd13be357-8d1b5a9fe41mr744030285a.10.1775075329556; Wed, 01 Apr 2026 13:28:49 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 02/11] vmstate: Pass in struct itself for VMSTATE_VARRAY_OF_POINTER_UINT32 Date: Wed, 1 Apr 2026 16:28:35 -0400 Message-ID: <20260401202844.673494-3-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075402139158500 Passing in a pointer almost never helps. Convert it to pass in struct for further refactoring on VMS_ARRAY_OF_POINTER. Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- 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 d4880e75c2..32bb8e8ebc 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 Sat Apr 11 18:37:55 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=1775075437; cv=none; d=zohomail.com; s=zohoarc; b=laA/C/dCzpMVoNaj90SQtONECro4dsIfRVazr5orFwLKnyjFLEIazhodJFOf4Z/imlP/S1fusSXYTrfENWeLs/NDkxXA3n+xEHi2xMN81A9mq1xc/3qhDqIlfYPV62l6aiq9WRxqXSwDqxqfQe47WNQZsYiL/1ytaAFd++Rdkuc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075437; h=Content-Type: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=hPQP5b/pynpHzfsBPX6i6Pduta9C+EPL3oVh5IQ70nQ=; b=Saz77ONbMgryqcSTiZBp+5KpwZ+E0NnKq6CD57iHKyc31ZVc1SAGNn4es2pqRGKlQTlwrB8t5fSONhusgfJHPx7XqdD1UXTLo7tiGi9bcjRggybIKUN5yW6wBf5Yxu5OzAqZgBc+ocicMeDYty/72yQtElV99SJb+1bj5kuWvFo= 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 177507543714275.02816168705169; Wed, 1 Apr 2026 13:30:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BT-0004MC-80; Wed, 01 Apr 2026 16:29:03 -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 1w82BM-0004Il-T2 for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:57 -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 1w82BK-000385-IY for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:56 -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-299-ID8bNQYnP5KlbrnI47Ssqg-1; Wed, 01 Apr 2026 16:28:52 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8cdae902bccso50843385a.0 for ; Wed, 01 Apr 2026 13:28:52 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hPQP5b/pynpHzfsBPX6i6Pduta9C+EPL3oVh5IQ70nQ=; b=Y1Y+1bKXw8yj01VYKp/gseaS3KwkQ5PHbXEberGM8zzDah8WgrWM+R1fxVpD5OSQesKuDl gISac504pbLWUDr1uotwRUdI2Iss61BTBy+v4vfk88JgPLTSIMutQLQ84ZxQKqf/iAyyJ1 ZSibjjjLYiuE9a4j1zzoDCgSgzMZvfk= X-MC-Unique: ID8bNQYnP5KlbrnI47Ssqg-1 X-Mimecast-MFC-AGG-ID: ID8bNQYnP5KlbrnI47Ssqg_1775075332 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075332; x=1775680132; 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=hPQP5b/pynpHzfsBPX6i6Pduta9C+EPL3oVh5IQ70nQ=; b=B+j5p3pN8IDNDH+7fSjCzNZzSOB7qAvj/D4P1mXvLsZq8OU+s27SWN0T1nIIVUMzHL vw7KOMHoG2qyVtko7bJAwpixcJz54fWoqA7H4HZRW1F5njXYZX17JbM5VrGX697eWmHv e6OV+W30Ao4+WyF6FTz4k5ipEQeOT7kZsCmCTtVwerQ2ZCqEjS07rx8WuFzoRxp19BZ4 MgmGNjChT76mlt/m3AYcXiiumwUdec86HxL7tFXX2JVZkWC0uIGFUx580oQeaIZv5WYY kEpTLJH/M1kpbYG3C28pyzMq2RRkle77Xg0hTBbCKOp57IECmb0QtrDmaxPLv87tFk1V MKvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075332; x=1775680132; 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=hPQP5b/pynpHzfsBPX6i6Pduta9C+EPL3oVh5IQ70nQ=; b=WrJ7JTn25DOOGraXukB+TkyRtuKyTq1P5NTCM4dnyqkC/0wbvaN7RJkI+KE80KCGFr th5aFA9n5nGf5w18t3q0UiPb6LogfmAExqpos5EMJA2sLvjntMpR9xwwJpYNWzyrHI2I lCZyf0QZuKqPQJKumdcASJMm3FOlB3dfzbHHbPqzV1OgnSDCgY1zdgvpbMMmWQEbmcsh vUsJ4K1sKGzGFaj5qUB7ktz62on5VYoq7b1Bgvw7bsp/9IE7KTcRj9kWTx5HJRzkDjiL dp0bBlaKmU6yJ4HjxkBxqBKLXhgI9TMhraRPKlT1Ki1ASOyk3bXwbu99Trzq7ToAiMHV j4cQ== X-Gm-Message-State: AOJu0YzfM5EgukJV4oxRPMM/V2fBkkoSkjWyPMcBzNPB2OxURDtYEKmJ bPhB6iUoqsCI/uJrciXgq9GeUYiL6Dq0MMReEaHtp4qbQVjjh+ECjYGVxeJw9L2e3TNvM4jtiTN a93mN7peTuVPKJl7NAykYNeFU7PCZZuYp06o5dr42KrELE0yyVUiPGV/Fh1TJsYBvfusgbMIewl jmWa0cmACAdbyko3ge2l0gt2vLOiWRhIYQdUHszQ== X-Gm-Gg: ATEYQzyDtpBy2t9SLQaWuhR4/tUvqin+7F5SSXF07RCn4mqtSZvyeygzmnN7ZzF7JCK mNp0tKT1j/a7HvcwwqeuwiWtHbXfm8DTv9ffqwJjp1U/ZEs5SBTo9ARbpQui8vl72sCniRZxyim t339/Zn99j4sg8UT2oLJNI6o20/GKMEcHJpBeitRzQylSw2GTws9ByfE8jJnqBRJ3sm6tSbHPZ5 1BXf2C37cb5MrSFXGAN1Dho1PtBR76XUO/V6K7bSgfjBsXNIbWJmsV4LOywX5Rv2xPSd6GHtqHw HyJi1t7Dp+cd+hR6BuiO6ubeYkjQn+BO3AJMBx85KgnkF3FqM8tXZaRzXzMx8PugU3fymarzNTt gRU2RGfEY1uefkZ5qb5/ZVan0E8htlODcg83y6IE8XIA= X-Received: by 2002:a05:620a:7001:b0:8cd:9599:b7c7 with SMTP id af79cd13be357-8d2aba26606mr169963785a.23.1775075331636; Wed, 01 Apr 2026 13:28:51 -0700 (PDT) X-Received: by 2002:a05:620a:7001:b0:8cd:9599:b7c7 with SMTP id af79cd13be357-8d2aba26606mr169956985a.23.1775075330673; Wed, 01 Apr 2026 13:28:50 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 03/11] vmstate: Do not set size for VMS_ARRAY_OF_POINTER Date: Wed, 1 Apr 2026 16:28:36 -0400 Message-ID: <20260401202844.673494-4-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075438389158500 When VMS_ARRAY_OF_POINTER is specified, it means the vmstate field is an array of pointers. The size of the element is not relevant to whatever it is stored inside: it is always the host pointer size. Let's reserve the "size" field in this case for future use, update vmstate_size() so as to make it still work for array of pointers properly. When at this, provide rich documentation on how size / size_offset works in vmstate. Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- include/migration/vmstate.h | 20 ++++++++++++++++---- migration/savevm.c | 3 +++ migration/vmstate.c | 10 +++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 32bb8e8ebc..350e62a55a 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -183,11 +183,26 @@ typedef enum { struct VMStateField { const char *name; size_t offset; + + /* + * @size or @size_offset specifies the size of the element embeded in + * the field. Only one of them should be present never both. When + * @size_offset is used together with VMS_VBUFFER, it means the size is + * dynamic calculated instead of a constant. + * + * When the field is an array of any type, this stores the size of one + * element of the array. + * + * NOTE: even if VMS_POINTER or VMS_ARRAY_OF_POINTER may be specified, + * this parameter always reflects the real size of the objects that a + * pointer point to. + */ size_t size; + size_t size_offset; + size_t start; int num; size_t num_offset; - size_t size_offset; const VMStateInfo *info; enum VMStateFlags flags; const VMStateDescription *vmsd; @@ -547,7 +562,6 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =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 Sat Apr 11 18:37:55 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=1775075399; cv=none; d=zohomail.com; s=zohoarc; b=WYeA0ly/MpU7JDO3CueEVdaIZZbrM5cB+VLlUsDwYu+JjXXDYnVsYiU1nJz5oElhNJmqnQc62PSup53LPKtyRD3YN229Lkw9uspZEE0EAD3M5hkJ4z6vlVAbCuYTwjbAv5rbLQk7uNsfvM0fsdNrNYpd/Ye8bEfQlPBKkNZZEsQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075399; 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=IOjsPMjPyjOOz0u/cqBKLuI7wgBm8OXlBH7YynEYGUs=; b=TI64IvMdl/n3nT3iwPputREJyS555YmNkZbgLEmc4Es/JNb+Ud22ZoIrjLGEjvDMyr0M0FV9dbkYA7DtDr7L2+u6xRba8tkmhEj1ORX4fb0TnjWJlrf97sAjfo90v9g92J/ivZgSPZ7adzU+S44qhfA7VvxcksQAVm66goJPBlA= 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 177507539970122.190901171789733; Wed, 1 Apr 2026 13:29:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BS-0004LW-EX; Wed, 01 Apr 2026 16:29:02 -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 1w82BN-0004Iq-7n for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:58 -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 1w82BL-00038L-L3 for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:56 -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-561-v5t523EJNPyF4FZnUh1riw-1; Wed, 01 Apr 2026 16:28:53 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8cd7c4ab845so46079685a.1 for ; Wed, 01 Apr 2026 13:28:53 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075334; 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=IOjsPMjPyjOOz0u/cqBKLuI7wgBm8OXlBH7YynEYGUs=; b=BrglIskrPlem+KXA7YI8Z5hB7vqkedFQxk4EkUViWRXTkLPRAqsjNve9s9glti0IeGDNtD r0wZGmM1ZX68KhK2X5b8KA5CNQH5QbqA9UAMYtEzM/gqESgbyCov/b0QZqkWA7Izw846dN q1VxQJfB7siL/hWXSX+NHfB67l6QEo4= X-MC-Unique: v5t523EJNPyF4FZnUh1riw-1 X-Mimecast-MFC-AGG-ID: v5t523EJNPyF4FZnUh1riw_1775075333 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075332; x=1775680132; 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=IOjsPMjPyjOOz0u/cqBKLuI7wgBm8OXlBH7YynEYGUs=; b=nVniMVfhIEW+OlLuxUfRc5GDXv8FRi6KmO51EoBibumEeAoCui2wGyokv2KLa1SGm3 IJlphZ9zbq6CrwHPETkcDfSBRGmnEjQYCxqYCTv+nh40LgpwVaR6Gj3sgweq6FFrIWyQ 2I8ENmhqHzwarrb1IT/VwxqkFDKwE0g74cHRInxNpzEN1zqjdot0ktZk5z9q1ZZ2y4d5 xOtq4MVs/RZu/8jDB48IXlZAOIxhfgqYiO23Mf5ot7eT3xlLpvEGLrIMwJ7I7T5kxPk4 f+Uf8C9L2FE29Jwe5pOrMtjZE02EZdZPcyTHm7OlOaVD6mJ4OsVdDX/ozTHswMurReCX BJmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075332; x=1775680132; 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=IOjsPMjPyjOOz0u/cqBKLuI7wgBm8OXlBH7YynEYGUs=; b=FjYChUxmePp0642ch49Fl+64r4rFfHvsyWDY0ur1EArDnlXHB7rDYH9HC4ss3wS8+L 2wzHoLaM6Woaqc5EpuTF61dZVtU5NI5M9j/NgezbYqqNZH4XHbP4eW2vL/S32n36ZjYz cQyXhQGmM/cmfDagtXKWCguppg8yxIXtv2pk2US5DvRFBc8udj/fER3yTvLWYdMLmbHc CgBI4LjRZU1iYshkLnVtU5JP7QsG3Uv7eiQHLKoOb+O1vLdkkdmeTC2QHX/KLLh1yaQW w/N34QXMX6Ts6uCYTgEYrIV3db1bHXvx+bH7AFhBVA9VnsB8OHdXA6C1rEN+pi5F91WK d3gw== X-Gm-Message-State: AOJu0YxOLWlwWTAUO5wDObADPuqI3kD4SFY8xaGb7c8VVeFoQma9oLni 8cOuucTw4OCAAgLR9iq1W4sLtBey2WUDtea296xv9kQxNVrdxkpqQvlWSxKRuKw12S7ueuOx5To 14FXmoXi7voguzvNt0GpHGGAu3dIfFGsyfRRUOycUCEFm43gfZsJdX1LrUTSzcLjco1BW3VuUjT QKfNoyAS+tRgMPVyr+ZaFSIUHl1OnouFThgLiVLw== X-Gm-Gg: ATEYQzxlv4GCemclOiRxUUAdRygDtnC0sZ0wy3JbJZ9igNH7wwou9Gu9P3dFI/0cLyk fBYlQv7ZpppLIBgZ9Fnav0GJ5Q6p577n3yamDlVGPZAdy8Ql4H7wHnshmviqLFfCivj5KTzSQLL m2MbaVQLRI7hY+kn8u3N991B+9uNEy0482tApV/qbu5g4knb7kwd3LZphjapK1P7ph2S+jPzqLL 7MX3fXayoscItalvdpQGq1yeUpBSsVhM6PINyIsECo5o0b76K61L9Oi5gGNjKsa4K4BFixfOIVx ewXOSSKORpXRAwhfiIHjJAk1sIn8AxFbk4l+NXFI5irY961sfZDUlB832sxpQ+0ctjr3bPE6SGN czpeItyCx6mXBWk5wXnYzxdEpeFHAxFzc4jYIEfdCqbw= X-Received: by 2002:a05:620a:2844:b0:8cf:e0fe:f227 with SMTP id af79cd13be357-8d2aa3b805fmr145170285a.26.1775075332419; Wed, 01 Apr 2026 13:28:52 -0700 (PDT) X-Received: by 2002:a05:620a:2844:b0:8cf:e0fe:f227 with SMTP id af79cd13be357-8d2aa3b805fmr145165085a.26.1775075331771; Wed, 01 Apr 2026 13:28:51 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn Subject: [PATCH 04/11] vmstate: Update max_elems early and check field compressable once Date: Wed, 1 Apr 2026 16:28:37 -0400 Message-ID: <20260401202844.673494-5-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075402186158500 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. Reviewed-by: Fabiano Rosas Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- 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 Sat Apr 11 18:37:55 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=1775075392; cv=none; d=zohomail.com; s=zohoarc; b=jiLkD4Z9HB5uqoA1/JP2GEHD/Xuhwei8TljS2fGOgPJkZGsSrevP8AwXVuQvkU4ejaPljNRc5BgTGhTtYbcoy1a3oJFIEsmtmWtniwGMM5YS6wb6jk+EGfmtAw5bG6uz3VoRnIlVEn0sC8bzsnSOc3ZrwpBuNKxH8fJeQ98xek8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075392; h=Content-Type: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=cqb2TTAmwxd+RL4JJIo+I7R0mtstkhAmAVuvztaMFd0=; b=nHpEv4uAEQgcpmai63oIbD7NUuPqgTcJQ2KFu5SOi2/UiIeg1fFI9Iwdt1/khaEIPC9sONRZ147axnYaCbEIDg8MYOEOJL69x4/arx/W0ep1cBtrtPpsErPT/Gz2+QjRKzreHI0yXpf/0fUu0g+LqLiQ8c4YqAFrcdJO8W9U5uQ= 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 1775075392777775.9196941097481; Wed, 1 Apr 2026 13:29:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BS-0004M9-WF; Wed, 01 Apr 2026 16:29:03 -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 1w82BP-0004Je-Hn for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:59 -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 1w82BO-00038s-3y for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:28:59 -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-616-ix3nJF6WMPmRrwySbQqqCA-1; Wed, 01 Apr 2026 16:28:55 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cfbfac0e05so34139685a.1 for ; Wed, 01 Apr 2026 13:28:55 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cqb2TTAmwxd+RL4JJIo+I7R0mtstkhAmAVuvztaMFd0=; b=CUXxlMo3FldXypWKTn+6dF8lfTzlzKHAbAq0grzJu0ALELNg9FBeh+hst94BlXxLq8SUCB K0QRVuYppJxtCjoU2Euv7Ic3nRKCnJZC1dnZnYjVflnhfuMKU8DgAqV3UbPxBEWaQ5zqU2 YR8+8Ldeyc1aEbpOi7jgJUFwgndfUr8= X-MC-Unique: ix3nJF6WMPmRrwySbQqqCA-1 X-Mimecast-MFC-AGG-ID: ix3nJF6WMPmRrwySbQqqCA_1775075335 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075334; x=1775680134; 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=cqb2TTAmwxd+RL4JJIo+I7R0mtstkhAmAVuvztaMFd0=; b=Mcvy7cnQ3zyd1MJfEnoRCY34XCZVZLY9j/8K8xTqxMQiO5QfLVXPEd0qMCZuD7TMwk 3DPFsOBp6cfhZhhY/XmWVI2zMhU277EYU0sB9/IDwcg3J3jwD9J1Akw9mXUMFcKL1Dvz eV21shIOwrnDcGjaA48Rx0szNVy8dxG6fLEKgPd6aqnlftCBJ2rI/xgYUGGh6NF2Qtyi AlCnLhMLuxn1os/pEPClbyI9AX5IX3gY7V1puIsALcHhRCDimB2nprYjVZre6eM9E0Ck 8xSlo+3uDCpGhh/oUMM6md+67c95oef+OXcGSgvNRitqxLdAeYQ6gSpIQzBVnH2GKGv4 j5Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075334; x=1775680134; 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=cqb2TTAmwxd+RL4JJIo+I7R0mtstkhAmAVuvztaMFd0=; b=EUYKvos3D+CrHsdicTiJB3zt2+O9Lws30vwsQnbTFt0TSF1biqOFkmitrSSc651P71 VowJgYF9qsoqKevCiEUyboym6i9lc6uI/4X29LwROINR/fqvk84Y2RVlW9/aXPXzzNTk Kyr+wKpTMoT82ptZ2vsORhPNBFwaAiGBx3dv9HD2c6terbfV4c79ygT66KXgaPUuGRtv IqVOtr0rFpJQPlVOIEvgeQfPBsAGyZFbjxIhOh5p+NgVsrGbWk+qXtz4IGIY5WrK0OKF HqpEvxzlAWlAav7JF9woO+QHf/eI7E6qeqRT+DRjZMkCLoNANw3UoxKVXdWcQO662ed0 ZyTg== X-Gm-Message-State: AOJu0YxzRsF6ABtlfxufgxLtx+w54Oxwv4Wi2bD3s4ujcgAseprO+Qyk 4AHNJAW0VzYGB2weOouFxbjiCWSfGVUZViiOTmOQfXR0vNsvxRc2Q+xDwrgSXvtF6jRQnMcKBma bVMf/wD16AMM3wa/9h+OLH6oozSvBuFuAGec/nYUcCWeOvy15R2Rng7+pQ6Ua6uqHaOaUHtJaaU LRl2rc9AE/1RqYAz8NVI8El+Am9okbhyAU0A1SNA== X-Gm-Gg: ATEYQzxfcvSQix+11BAFf9FqaW2OUxCUp0HxoPtwF7CQuRXQOlqlROMd8svckeKHFqP uwqsymXC5JrsWcXYHcudcHXyXceFu0w1N3TzKx7deZk077pYKIwWLQfNq/V0V00QT+6iTBLPuEl 9SJcgb3M2Bhlo7DM3mTI/PBMHiEkrazvUt57/0vgACnxrLeeBae5QX+Sl4SIQy8153L6fo8ljQK MIGI5m4SawqhIpSJpLK5+N+MjHHqHU6wjWUeHZpjVrOFiAr398dssS0GWkfi4TnXOOs4ADJCuK9 VdQAg0NYJFVFUmssD+syo6fwf3g3St6KYuR6bCIxzAfSIXdCp4P+2YApJS4l2sYafvRkKJjS/Oy Kv2GH5go5EM7lzeQoiWOU1PQpqyZc97soUou7RS5cIWA= X-Received: by 2002:a05:620a:d83:b0:8cf:d0bd:bc8c with SMTP id af79cd13be357-8d1aa3bf9admr1212628785a.12.1775075334356; Wed, 01 Apr 2026 13:28:54 -0700 (PDT) X-Received: by 2002:a05:620a:d83:b0:8cf:d0bd:bc8c with SMTP id af79cd13be357-8d1aa3bf9admr1212625185a.12.1775075333687; Wed, 01 Apr 2026 13:28:53 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 05/11] vmstate: Rename VMS_NULLPTR_MARKER to VMS_MARKER_PTR_NULL Date: Wed, 1 Apr 2026 16:28:38 -0400 Message-ID: <20260401202844.673494-6-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075394509154100 Prepare for a new MARKER for non-NULL pointer. Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- 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 350e62a55a..7396e38531 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 Sat Apr 11 18:37:55 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=1775075422; cv=none; d=zohomail.com; s=zohoarc; b=kTnr7UHEM71IuNWUD0xZL3VFVwPm/rWi4Y/U0qKML+LpRhl2/Ot6pxYJzSHTEj3vymzHJ2p+0DzFAan1+hKvWdL6e0Y2CgAAWhbUyR3EHi10I6S1itKGkM9qc+HZGx00ZhK7i/B7F2O+J5lzRMJGKvrHetEOoTO1QeKzkjjQuFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075422; 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=m4SNb/+dNBoUUecfjmeqDkL3BXGCT5Hf5mgRlSOyVOQ=; b=ZWtw2z51KIDVuSDbwdrELxQySC6LnLhdLxMzQDaB46rMVlxfitTB4fhxznRMi9RgoGXDMhb3aZELrmEeMiToJrBv8MTJKFpfqzs6hbsVJ97v7QertflPhmE34Usok8Q6XjQgr+9stq87FSUO6EjrUDftaVhrfHvSq/1WmFSaXYI= 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 1775075422937236.34393941546637; Wed, 1 Apr 2026 13:30:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BT-0004MF-CX; Wed, 01 Apr 2026 16:29:03 -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 1w82BQ-0004K5-IK for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:00 -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 1w82BO-00038x-Nm for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:00 -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-416-7Iw-8tYtO8ykW3sjTHufqw-1; Wed, 01 Apr 2026 16:28:56 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cb6291d95aso87043485a.1 for ; Wed, 01 Apr 2026 13:28:56 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075337; 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=m4SNb/+dNBoUUecfjmeqDkL3BXGCT5Hf5mgRlSOyVOQ=; b=HV20oK5Ohk+iW0gXyIZClyp0mPOfIN2k7GQY06e47cYNO3T4WS+k9UqeU2xuTh1GBCTtV8 EmSc8tQU/wCZp9XJpIHRdYQv+l9UDoZPC2yMpyuBZWGqLmapUby4Sk+mdS9UvbeIOxFXhU uNDfPLoE0dbRbS36VmlXeWwuyl4zOC4= X-MC-Unique: 7Iw-8tYtO8ykW3sjTHufqw-1 X-Mimecast-MFC-AGG-ID: 7Iw-8tYtO8ykW3sjTHufqw_1775075336 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075335; x=1775680135; 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=m4SNb/+dNBoUUecfjmeqDkL3BXGCT5Hf5mgRlSOyVOQ=; b=HLNAUBqVUGvq+cNlyCt6ffTxd+0/jFkJc00gYz5J8UaPHFk3/AfwgfKBXV1ErYjH4o NjxNOggOqtIErw8bTvfFNBMuaikT8HrrlPfYY4uFiHN+hijXlymxFswO/28Zg5y4+2PT MA5HTF4x7yuZ+tvdlBOQRzx/ZzqnJo3JWt6DHR35Aks4M0GACCIu/jg+j6hMD+RQImjg R4hem7k1m9l8I7qqx5A0hGfmgGsvLdZHpb15T1/RM4mhOvmikvw95DCUzESA68GBnYz+ aulMOklp3IHDUOnYfMTTLeh4h8JnbnWUwWjTPZMb1rah0q4hIzNjrSIK8a2V1fA/nhdb rQvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075335; x=1775680135; 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=m4SNb/+dNBoUUecfjmeqDkL3BXGCT5Hf5mgRlSOyVOQ=; b=LwFyqVQMvZtRlxLh/SeMPkgl9Fg9hca1XjalBN/UrOOmnn1fYdJwEkWqLFFNw5ZW3u 1CIi6P+vKGsxSjTNyCYftnHdsRzCK04JnnkwPJqm36EBbNa2Jp/7DD1MI2Xfmp5SiYG1 C9INZoaw/4NOXP0gEJ36vPzsEwDyfyRdrEUUdx259duXFPoKrydGGkaGgda8KFcdndsR rtOnECFCJiQZ/OCFb21JLhpFSeHORwWp7Mqn++uZO7GCD7tIzGt8R9GO7wMYd6aDKCEq Mi1z2+JAPbt3UxAYUtKQNP4fB8WD+UKFlJGnA1shCx1rvrQJkC2WNPzD1SSyTpV0kXiu WZ3Q== X-Gm-Message-State: AOJu0Yw295ha5WkkNgr+/HU026UOQ/Zerj4ipMiwcB8gsnfHmOSu+0Gu H+b1gM3mmCwYpdnGoUhZvt3uU64U8DCXgczH4oGyEHMRy0UQl5PkWmMp2BBKX1KEq+ynMGk2uwz RLv9KcjrXrgxAIXxal5LkG1SfN7nWVxC6S+WlFtW32kKdohHDh8teD7fbxuvFU9XBWtjCtw0c3Z t/wVZzazPS/6G9uCSehEJMNG2L8nLzFYPWhrQaQQ== X-Gm-Gg: ATEYQzwMR0xWnudQH0Ey054ay83cuICu35RnAiEgohipQtMs2kiqoH+BcGz+SBkP/iJ ChAJp2xhDbSJgzgaqH45Lbb1EsGQN6WpDdxZWw337OKUmmSTzHHWTEPlq6yX3I+wtn28TCrWJQg KUBavVxpLLWEuGCoFoifPocEfFImd0JgSv/cEhB/Q2UT+wa/uQsF2gTolMBkXmE+q20jzfhWHPv p99gnlcaIbN5c8NW4FL0S80Icpdni5piz14nwswC2Ut8U6tT+2w9MDrxFhACrY3+zzYYl6JNdro D2xo5wqlc5yMnU/wI4pNQrj6cRE3kWYMlkZTIMME8a/t5/D4TEBtOwqkOMgCLmlPH83qKaitVno 6A+CggwZqioWkG/7N/YauzMWRb+reppEpEyjeG4HPqrI= X-Received: by 2002:a05:620a:4441:b0:8cf:c75d:2a07 with SMTP id af79cd13be357-8d1b5ae65c1mr786478185a.16.1775075335414; Wed, 01 Apr 2026 13:28:55 -0700 (PDT) X-Received: by 2002:a05:620a:4441:b0:8cf:c75d:2a07 with SMTP id af79cd13be357-8d1b5ae65c1mr786473485a.16.1775075334738; Wed, 01 Apr 2026 13:28:54 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn Subject: [PATCH 06/11] vmstate: Introduce vmstate_save_field_with_vmdesc() Date: Wed, 1 Apr 2026 16:28:39 -0400 Message-ID: <20260401202844.673494-7-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075424306158500 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 Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- 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 Sat Apr 11 18:37:55 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=1775075421; cv=none; d=zohomail.com; s=zohoarc; b=cyh/DAbkVDZmgeTKeo4GUoKmPu2QoeLc4Lu53/rw4RvV9MLLIIKMsrdF5WO389ozJUGbkFLmcFvKKAkjWOMp4/NcYCuvxBPiz/UoMqjlvg5tjZGygEuRZ7x9ZYM+eG/7POkzVnEJq3f56Gvy7ZQgiRqtOBymQUJUwRIT3OLiXfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075421; 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=n1cYzTfIInVG4krmJT8uaa40fyNhORGhPZ9F1/mWMbo=; b=eg1sydnHWK2neFvRnqSq12SGAoyJZvS10kqsSJo50ft6moN5lpo792Zva3TzH9GtIm2+0BXZms0Vm21Vsoa9fSIlGDHKhBYUbrcm6YUv7+4MKEqQl1p0HiS2W+2c1Aho81b/I55DlJt451QxBLnBvjoQ0RBOVr+DoVogd3NvBk0= 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 1775075421826925.8272097095107; Wed, 1 Apr 2026 13:30:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BU-0004Ma-Ho; Wed, 01 Apr 2026 16:29:04 -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 1w82BR-0004Kr-TB for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:01 -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 1w82BP-000399-Ux for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:01 -0400 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-7-Qk5rW2sLOGKTXKNWN_VLxA-1; Wed, 01 Apr 2026 16:28:57 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-89ce2a7fef6so7143646d6.1 for ; Wed, 01 Apr 2026 13:28:57 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075339; 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=n1cYzTfIInVG4krmJT8uaa40fyNhORGhPZ9F1/mWMbo=; b=Za/0jEklxfZWkYP+VP6bmiVv9L/GOzGCW+soh1OkLbDKIQJ8uCvZtkTqYzlPbsxD0xY0L0 svK1rFNQ4sddz/e9LsDXQXyuOt08qihxnO7QBhCmctrjaanhglGs20FkL89AxOnVOj2C3n KWpl4r0mS+mqWs8HYUnp8u20tqcJlUQ= X-MC-Unique: Qk5rW2sLOGKTXKNWN_VLxA-1 X-Mimecast-MFC-AGG-ID: Qk5rW2sLOGKTXKNWN_VLxA_1775075337 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075336; x=1775680136; 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=n1cYzTfIInVG4krmJT8uaa40fyNhORGhPZ9F1/mWMbo=; b=SIdvczq9dFQwH1lQL4oh7ZK1pvguWDFiteDHMCS9eAxyq1q073Ak05lV43ottgbaC4 69FUeKhgADdklAJiRAuxzDPGCZ5/AyEJT7WypVeIUAncLDR0ncdJid5Fkr2bHZ+cyvl5 zfonby1f0yU5dPBTdI9DjYR1adZSx2bva9fVYkIXzegPxG2F3jHJ7KYehfP+f8Sj4ixh ChtBtG6aiD4riSA/h8myiYT7STJhr12rM3vZI3X9JaQe+06lHlMamV6jbADfpzVz/cRU vwzm5M2r37ZEEzdY7suB1ku94xUmTcx9bD8nulpGjoL3pJ8ss6rDNgWoPj4CibUWIhSt 5RRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075336; x=1775680136; 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=n1cYzTfIInVG4krmJT8uaa40fyNhORGhPZ9F1/mWMbo=; b=cY8ePseij8zxiy7THc9ovYn5L7t8AWcwwgWNbJmf9g204tiFl2exEKdNWnSwzkp89J BuThbahzzf482eRDCKXJagBiDnl640HfEUt/TqqrFsov0CXnhkp47mTa6PLDrYsKyANy aB91hvylv+T1y9pKf2vSIsbUryN5LOlepddZA9bWDMCqfsfKIxkpINGXxcTOJZu2WRVt HKq6ZbDubOBZbfvYcNDB1zhBnEj9q88FSrqbfymoy9WYcxWfui5Bqug0Nv+WFdVs5uh3 3cURItirbkv9phWT7u/P5cf1iyLb01PVaqqGSp/wFyRbadFoDI5kXVYQGbkB4ApcCOlT TgvQ== X-Gm-Message-State: AOJu0YzpT+FZYWc/hOso70hUbvbyhXm9GxmvDFEHJpF3n7Bc2Q3TyMiU WsL40d2ylMwl5Nat+is9UOgfQtceuEk0y8j/RjTirNWKKnJp0nCLtxSx5bOi513OglHwr8MZnbZ e0uhGN43YuhHeFqOX9yS+vke5Gg4is9WToJVmfrPRY/ueb6RDrkRloQV7M0SfdnrvGbOnWn3Kt+ wbrQrKwm2x/a1v3I3rvk7R5aeNxD+pgigJcSkAQQ== X-Gm-Gg: ATEYQzw6JM+I8jPTHThXTz4fFxMW1BJqpTT17QagpUrhZ3mJyL1759N0fSq6cflhihO OQfuzanC9DxNIQN+4jO9QvOZJc4I0KzXJ/QJeI/2IeZEGtqN4WwlKSdadzQeBNlJyIaCuxK3hiI /1TBwWjgUGk5mFWfs2QFL4TaN7y+3huvKNUbrTIkRG+EaPB+332PnjYuhKDcvXdtY2Z9MAcBBVw EANOMpQ6zItUaCCsbTpm2TwCSCEyDcpi1O7WZHtFgdG9Q2T9Q19P7CQLKfOFfgpKPySV49t1wxS mp76zgwfjVeJ7gLnCyLL69dmYeLQyGymla2bLzIqPuAI7H0GYd5/yAGYehFzfnaD6Sm+OotCRCo fmhHwZxSBcW+uciaj5XoxQUXBpvOoUCnWr6OJTwH1scU= X-Received: by 2002:a05:620a:404c:b0:8cb:9975:cba8 with SMTP id af79cd13be357-8d1b5c5782cmr818803185a.62.1775075336434; Wed, 01 Apr 2026 13:28:56 -0700 (PDT) X-Received: by 2002:a05:620a:404c:b0:8cb:9975:cba8 with SMTP id af79cd13be357-8d1b5c5782cmr818797985a.62.1775075335852; Wed, 01 Apr 2026 13:28:55 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn Subject: [PATCH 07/11] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers Date: Wed, 1 Apr 2026 16:28:40 -0400 Message-ID: <20260401202844.673494-8-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075422305158500 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. Reviewed-by: Fabiano Rosas Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- 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 7396e38531..492069b8d2 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 1775075420404338.58000991224856; Wed, 1 Apr 2026 13:30:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BT-0004MJ-Q7; Wed, 01 Apr 2026 16:29:03 -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 1w82BR-0004Ko-Rt for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:01 -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 1w82BQ-00039F-9R for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:01 -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-528-cSyKGx1pMtalhM0garvwuA-1; Wed, 01 Apr 2026 16:28:58 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8cb0595def4so55244785a.0 for ; Wed, 01 Apr 2026 13:28:58 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075339; 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=X3KS3isoeM2A51oCNrcxhEcDD2YvjinIbubXfJ5TPfE=; b=jHNFcQ4SAJu5D9MQT2yt7izTZi/ChmS004etXE8Y6xDpIDVN9mh3geCaLuHm1JbxhdkAVL cHUOZz5PrGf51OfD4+SkX+RH8B9v3oLCUoLFL3qFowewxTqrfdF0l2xMRfDVAm7rJR4SZh NNWysXj4PrD9uOIB1ro5Bs4IITg4R8Y= X-MC-Unique: cSyKGx1pMtalhM0garvwuA-1 X-Mimecast-MFC-AGG-ID: cSyKGx1pMtalhM0garvwuA_1775075338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075337; x=1775680137; 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=X3KS3isoeM2A51oCNrcxhEcDD2YvjinIbubXfJ5TPfE=; b=Y74KgR+3IZMuByyNBlZ9UQxAYJUxNd3oxLOm/cQENZx/JZiRPaigGCY4+LPRdOW2sn Dk2yQaE1Dwf0CheUl4eCaiHTMn9O0OhFu1yuVULcfDWeWx/In4kPe0/K6DRTFz33wuTI DLR5JJ4jy0kVEU+KPn5pG++kCnHWCdd08HsW7kTTYmLU3JUlax42GwWmxlvx++ViIf+m F+pDz4ylB0iCcciG6BXp7wW0G6eJu26fWbi8BrnzWyHc8M9kmnrHBzzFGdJRlMLqIFAK EVuQKAHwMpsdIFfP/bDO8q96PLMyC7pNIFnN+P9jPICyYm3O2SHHL/Ikn5/WYgHEbYZM 9gDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075337; x=1775680137; 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=X3KS3isoeM2A51oCNrcxhEcDD2YvjinIbubXfJ5TPfE=; b=h3KEgPw7js2pjHdgge6Q7HRNJTw7m5xl2vijDUw4HX73v+ft6EQqQFN0tMmhUBwaeL Tvot8Wnujck0gGjEPvINR40n8AZ57KBpM1LRmb9IQLHusOk2sSSaI/kvPsI8Ft6b8GJ/ mDWU7LSq1jZzo/CEs9Efr76QX0n2mKBKqh4AYgUYJzdhKLI0iCA0egHO26/WEoduTsmd 4LdSUoiH7BsFtFJbxe/WG7zGCBJhvPDITfvv10pSqoDjnZ03ZzDQQbTMQr3FtjdFcD/4 V4IkjQw6Z74cfS0PSbI8wyQ8EC69njdO++rlr9sMkuIpYsQYVsWQzZJ4FcK8v6RuXhs/ oHxQ== X-Gm-Message-State: AOJu0YzI2uZHlYB6Xz6mznWt2nBttNI87RNY71kxL3O9Ky9BdEKnqqcj tSm/xmas1zXKToJ7yugVVkI/iqYUXevxP+YMJ8GpmIjSELkrJ7RSNIazPG/ykK0I3k+Q7q9TNF/ WYJHJ0Y1MM3P8M1M13r5BBDhW0LqL0hDIue+fQbLBlz12Xn8dLuaqxM2za4FRjnVk77kw9zdhAd k+CHSKPBPpmGbIhcbZeM+gcw6Vk1RHs2tQpzd23g== X-Gm-Gg: ATEYQzx5iQ0UbTMFKe+A9rMVwpt7Ab7sue+vT/bwOUvBiVYFBZpEwUQAHhMO0hdjT+V PzAlEWxkGKLyyNi5y4i4BX0oG655NDeKI/r4RQq73r5QD2Ohu3Spw2lHUfZpaL60sr2CJOf/uVF DMRuUE4qSOq4Y0BuOaSzJKjrKTgN7svf5BksXBmiNeTQ9/C9uhIjQrYPLX4AdAu/QjPdsdDWAe8 9ns6eoFFY8xLh+XpXs4yQmRmixx/8Vm33wKjdhWbNQNMtqYXKrqD6835rIqMgsJcAZ2hVAH/DST BLBPTp3+W7Xl4+z2qytdRkND2Wv6mB9NRP0mYntanvABMpD4dLb/ruehWpW2uyFkCGQ17mv6d6I svA8k4Ag7hz/+WBi+XYPQQz4tn9/gHnO1bptb5Hiw4jM= X-Received: by 2002:a05:620a:14bc:b0:8d1:b71e:10a0 with SMTP id af79cd13be357-8d1b71e2575mr436273685a.5.1775075337387; Wed, 01 Apr 2026 13:28:57 -0700 (PDT) X-Received: by 2002:a05:620a:14bc:b0:8d1:b71e:10a0 with SMTP id af79cd13be357-8d1b71e2575mr436270185a.5.1775075336819; Wed, 01 Apr 2026 13:28:56 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn Subject: [PATCH 08/11] vmstate: Implement load of ptr marker in vmstate core Date: Wed, 1 Apr 2026 16:28:41 -0400 Message-ID: <20260401202844.673494-9-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075422234158500 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). Reviewed-by: Fabiano Rosas Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- 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 Sat Apr 11 18:37:55 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=1775075423; cv=none; d=zohomail.com; s=zohoarc; b=RxdGKrqYHyFsaA5BNNW1h2eJTCk8o8++Ej2QFNwkHurN3/8wvx6kr051qISWvjLfuwI7WUKsTeHopZ7BiNw9/0ihvBgiRYj/zTw3kUppW88S9aShOQ+yVA/qJ6xZfjvpQnFnaIpXwr6ky/yEOKSxmr8Ii0iKM8T2I2WW4E+f0Lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075423; 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=pGSlpbo7xBrzoDnclWLxzKnAf9I3/cVDvKntQi9lS54=; b=LiMyTfX8xvEmAOB/7HtP5qOWrV7/Fc0H23AFN/GuNQiqWhPaQDfAW6wq+nFaGIaj1ODJoUsas51VKSaDNz1YWwqInL2ElKMjz1wlhi58oZYniD/Vl742D4gEvBvseqk5cvPAKcNVU3txr6zPXfltHvMInXngn7PjdVr1+xQjCJE= 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 1775075423935851.4206337757279; Wed, 1 Apr 2026 13:30:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BV-0004NL-7o; Wed, 01 Apr 2026 16:29:05 -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 1w82BT-0004MH-GK for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:03 -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 1w82BR-00039Y-B6 for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:03 -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-534-wEOGjic7NR2K2eMH15XJKw-1; Wed, 01 Apr 2026 16:28:59 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8cfda078676so67456185a.2 for ; Wed, 01 Apr 2026 13:28:59 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075340; 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=pGSlpbo7xBrzoDnclWLxzKnAf9I3/cVDvKntQi9lS54=; b=QA+PXAyWZc7YYfVJZHONpolAicFVFb6VDUhLs6D7W63/M0kZoWUi7iwlLmasSrIpbK1Fh3 wGAKa9/utkWP6JhRdxyy/wkdMcXpauNWitmdf/l3gJi8XFgjXDmHot/p7S5gRV/u0GsgxN yikyXeVgD9Ci5EVr83J64igImd+00jM= X-MC-Unique: wEOGjic7NR2K2eMH15XJKw-1 X-Mimecast-MFC-AGG-ID: wEOGjic7NR2K2eMH15XJKw_1775075339 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075339; x=1775680139; 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=pGSlpbo7xBrzoDnclWLxzKnAf9I3/cVDvKntQi9lS54=; b=FmXMhq0bRBNfnM58Zd8/weV3WptDmEInzgW7etzUu5Y+6tR9fkSvcnjIWIe4cqkX28 M1GmgPocXY5tO+LRoG3iSySdwh0wn9JcVSkC4rnEWAlfiFRRKcOhrRAfbdB6eP8kSG0t giQHDvKpcIbRCzhFWTz0/Hei8SFJIqPOMb6Xm7v4EYhZlzME1OCy8Ef/bn6QXfa/LqL4 9tFJ699vumnW61P+cLA2gi8srbGqUu45JrvB5MgyWg7tCqKbryAWJh8GGaQLCLDup5T7 dVIL13BrpqWJBPLtRyONTvAh0jTAO07/NZAGd0FLSN86/UsgnrYDjGwnU+GofM2JgaV2 3YgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075339; x=1775680139; 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=pGSlpbo7xBrzoDnclWLxzKnAf9I3/cVDvKntQi9lS54=; b=QgONEfq3VN79Kg4QOqGQcKQtGutYxCjHPQutPZm16fMUK2QlOvyB60/zqPjQZuCDlG YxPlUUkpeuLqfoejJzRKcaHTv4XnGMkxU4uJNDh1bJlVgFYVtiPEozXqcLmRjgNTErKD hlEmR7+UN4qj5tL43oeiNfQkAkCORYeJl7eN7f8HseJVZ5MqW/tGD4RC76I4cJA330DR YAaRFPrQwApn31IOq45R4d3qp0C0MyrmP6bHToKDqcGkbJlPLptCVUz6aodyBsvSXKJc 1ZXr7/83ZJOewz27y/iwS9MgWZL8Cs0VqfWBajGgP0W0LuxfylKtv06NbrRckJ5C9GwQ IwDQ== X-Gm-Message-State: AOJu0YzOuHTOMFPMDDivqlRVW44rkrVTu2WqlfUjVfTpus+TMW4GR7hP LH6lqWvEQnDe08J016BzhjnHl/t4fKxn1zXPqPmrGEITczwevTCP9QPxKdpeRbIRaoPtkpxuq3+ jd+VjiTqhBlTf4nJ9yZdpTkw2lm0WD3qwdMPDM0REu4Z8ORYsKFWCvsaTrvvwxY7tDNBjCSy2bg MDatCt1Gly+SvbQ3uT7MCwtmC4mLaTfu8WcpWD4g== X-Gm-Gg: ATEYQzxcbAegkiC4MUySL/4wXbrWf7/Xbsb9VGT/Rkfg1OeAaVojg7ecCIhdxyJrHyD XByVjeaFwR+7uYO2a9qi3vtQQ4k5aWn6RljjO6Xd+lmseq0H+cX/BRtxgwkDeObVleFdzMGMaU+ A+GFn7paGSMv4cnrptJOKNcT1ykULszRF9Je9G4RNPryhtYXkkMDYIEpEPvHv2WfWpWRrVUfUm8 xj5qxdf+iaeRWlLV9QBfEWXhNShLs9Xs6bjAHLUh7QYbpwB1X6bMxM7Xwj1pL03d8CUW2fszPUp gkGI38LIorqklUP07AbSFDlqKv++61PWPs53xIp4FqGRa0NlxBiUjBad7swRCjY+GwxaOIE8YGT Q0ViIfQIpQf1ostL1y0NjXBtNEtx14RV7Hqzhtgw4PgU= X-Received: by 2002:a05:620a:3942:b0:8cd:9033:1724 with SMTP id af79cd13be357-8d2a99e6385mr148011385a.9.1775075338608; Wed, 01 Apr 2026 13:28:58 -0700 (PDT) X-Received: by 2002:a05:620a:3942:b0:8cd:9033:1724 with SMTP id af79cd13be357-8d2a99e6385mr148006985a.9.1775075337896; Wed, 01 Apr 2026 13:28:57 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn Subject: [PATCH 09/11] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Date: Wed, 1 Apr 2026 16:28:42 -0400 Message-ID: <20260401202844.673494-10-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075427125154100 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. Reviewed-by: Alexander Mikhalitsyn Tested-by: Alexander Mikhalitsyn Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- include/migration/vmstate.h | 51 ++++++++++++- migration/savevm.c | 27 ++++++- migration/vmstate.c | 145 ++++++++++++++++++++++++++++++------ 3 files changed, 199 insertions(+), 24 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 492069b8d2..28e3640e60 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..de2ad822e8 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,76 @@ 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; + + /* + * If auto_alloc is on, making sure the user provided an array of NULL + * pointers to start with + */ + assert(!auto_alloc || *pptr =3D=3D NULL); + + /* + * When pointer is null, we must expect a ptr marker first. Use cases: + * + * (1) _AUTO_ALLOC implies a ptr marker will always exist, or, + * + * (2) the element on destination is NULL, which expects the src to se= nd a + * NULL-only marker. + * + * Here, checking against a NULL pointer will work for both. + */ + if (!*pptr) { + if (!vmstate_ptr_marker_load(f, &load_field, errp)) { + trace_vmstate_load_field_error(field->name, -EINVAL); + return false; + } + + /* + * If loading is needed, do pre-allocation first (otherwise keeping + * *pptr=3D=3DNULL to imply a skip below) + */ + if (load_field) { + /* Only applies when auto_alloc=3Don on the field */ + assert(auto_alloc); + /* + * NOTE: do not use vmstate_size() here, because we need the + * object size, not entry size of the array. + */ + *pptr =3D g_malloc0(field->size); + } + } + + /* 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 +355,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 +468,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 +664,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 +690,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 +739,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 Sat Apr 11 18:37:55 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=1775075420; cv=none; d=zohomail.com; s=zohoarc; b=BoM8QpC+ChtGcYm3D0o8SIaniFh25f2dEILXrXXvq/y0CFvOADAixaPbpz7nFN/kbag+1kgykY4STkRb/W05phehHPvM08qsWRBAq1diP0vgTF9HxlrM/N8GnFAQMwR6/ImG10M1cLjAbOCH9wLq7f49v8Jj9NUqBJIxBjpKePY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075420; 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=y9nFC8fExKGiU5GjHp52oB/dVp37pPXgo7vivdw5CVw=; b=Nz410MJ4kScdsNu97wb3rSvWdc1u34dsy+ZbCNLTXtIqXczgZ/PQAtTFyhNLpUotoUWTg9srHELhjr/UvsN/Lozkwzazw2eZwgxqea8hBLK4Rr94tQMU2GxAK27FEeiL/BbPxNVTOuRLB4fT6ro+N8+66arrRFneLUufljT+rmc= 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 1775075420938872.1096938049931; Wed, 1 Apr 2026 13:30:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BU-0004Md-Hi; Wed, 01 Apr 2026 16:29:04 -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 1w82BT-0004MG-E7 for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:03 -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 1w82BS-00039h-2p for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:03 -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-125-qZij9Bx5Pm6xHJpG43NQpg-1; Wed, 01 Apr 2026 16:29:00 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cd849cd562so69954085a.0 for ; Wed, 01 Apr 2026 13:29:00 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075341; 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=y9nFC8fExKGiU5GjHp52oB/dVp37pPXgo7vivdw5CVw=; b=aJqXC1xHk2LfuF9kulirMN90aDc+4NQBFdE8NzdILo3hRBnSh0K8dXrR/OvHoICuOjPKeI 7jqTZiclCUjampUdl/Feck+s7UDx+z7Oal5NG6nv98ColgyILfI2UxbF12eki6Sw7R2fC7 XW1d4Uiomi9Pv/oDfxfAa0uBEMN8rxE= X-MC-Unique: qZij9Bx5Pm6xHJpG43NQpg-1 X-Mimecast-MFC-AGG-ID: qZij9Bx5Pm6xHJpG43NQpg_1775075340 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075340; x=1775680140; 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=y9nFC8fExKGiU5GjHp52oB/dVp37pPXgo7vivdw5CVw=; b=aDcUyit9vTfmsUQbgrzSbKUOaG39xzbt37CGir2rVQWTveJGkzfCbmtTXFWpJQwuLX CEdxosNcKCeM6y0Prxag5demdtFhi15dDSAcONJ6p8DD3qcnNwrq884jha8sh4Hjd8eD AFhrMYNORad/enPjToBmJhbOfV6SAvM/au5nfNxENepO0UsVqGmCWbrE2h1BsWOH/ndq hES1q6BAUVqJsrE+ayVS+WdZSQIxeJSUBS8NDojT7qHkMaewlLEJWbaST2zmWOLzFKsx sIKbzcqDvqodkjkn72WBy2USFg24CQu2TxauK8E+ilago8rYNuRX3HXrfCRKjisHt00J 0wOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075340; x=1775680140; 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=y9nFC8fExKGiU5GjHp52oB/dVp37pPXgo7vivdw5CVw=; b=MXg1RIsbAb4+PWOvJIFqAOZMEv/ImXggqox++5RaRxGzvFmffcOPt1grMl6aJaZpOO zz0E9NX3m5Id0eq1d/rYGun5PjAaGu2TUVFmE9l0asZiZNswTjCIKrKz02obW8bLoyao 282Llcenxjyb7pLvrEADOOkIrIvdjNKbXFZyLBLh2C4uk4sta7vRgKUTORt48hXrx6pm jjTDe7/22loKffhTIwdPLmk9fiped6dBNE7aklNaq9AenYOri6EevCWdAmsxeqC878P2 +pxYUKewgOOWgSj3N5CerwSaBPrkzgYNju5BC1CEavpEZnkfRt2nOZdny1Wk2mzqbQdg gHvg== X-Gm-Message-State: AOJu0Yxv69BZ0+PRiufzCSToWM0ZDM2kcLyKFcnvTM4b0xVu8Zrnr7JM jVRvtwN8h8sTnNnRauHECU3B9PBq0h5Vx628NvBDnEOafgQ0HARng9KJQKs0/PW5qjhe+ois8Gk R6bMyBfAEZVF5DtmjDJKjXSYQ7FqUy17P9oveF95iD6ozTH/imuFUhF0Lu6htAnmN1lYnbwltMs zq6bzyehDhsQmvNPDdsLIHQ3vrOoVyXvo+I8mRag== X-Gm-Gg: ATEYQzzA1D6wkzQAdXMWuwdXhkEyv1+h21KiW0jVtdW/k96c7yCW/EhmEG27pH5U+nS ZRekedCpAUHH4E+8APhTLthC5hmO+nrX/93RD3TTmoZsiS+U/rRFSlVQ+9NbqqfCjm6ds+wSmuP inGJk0wPn+xxFfqokpQQwV7tWQEbQIVvzVwfFfb0lvv/MyxiKeKz9km4agjQjwkJCFdGHF+DPVg Y2DKDwLTEzpN9j7/duKp1qaX1+/nKi/xXV2ucD5TV7m1ducb37QqNPXud4HafKvCFVlB+LGmkUe jZ2t7VY7Klts1Srykk8v3kPXnJD2XpsEoSt/P3u4HqJH8x/6SLyWyphNLrcCGPCT5O3mzTBcq5S mHIWG1HNJTBuVTptWzNutcQapGMIWKeVhnm/S1JuP/Wc= X-Received: by 2002:a05:620a:400f:b0:8cf:d565:fcbb with SMTP id af79cd13be357-8d1b5a994b6mr766590985a.11.1775075339442; Wed, 01 Apr 2026 13:28:59 -0700 (PDT) X-Received: by 2002:a05:620a:400f:b0:8cf:d565:fcbb with SMTP id af79cd13be357-8d1b5a994b6mr766585985a.11.1775075338860; Wed, 01 Apr 2026 13:28:58 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn Subject: [PATCH 10/11] vmstate: Stop checking size for nullptr compression Date: Wed, 1 Apr 2026 16:28:43 -0400 Message-ID: <20260401202844.673494-11-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075422203158500 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 Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Peter Xu Reviewed-by: Juraj Marcin --- migration/vmstate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index de2ad822e8..2f13b48a37 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -682,14 +682,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) { @@ -717,7 +717,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 Sat Apr 11 18:37:55 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=1775075421; cv=none; d=zohomail.com; s=zohoarc; b=gxTtXa0YWuE0zHBvfgxhTEn4IGJ677rxCYGO2v06TvdrcVU623WSGe/vR0+iWGFf6iRnD8fHrdQWC4Kef9OxE/A3SQDzgNwjag8kPE5acT1f6uLDQR8/H7a2osZrXFu2HznM4uurgHk9X8FQWVGVU7WzzPILsgkg6eGWK4KUCNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775075421; 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=adKt3s3P6L6Zgcew9ejBNGaGaJVh0/bVp0Rruo3OYXHbZVho/Gj19XsT5YfcReTY9Q3NdWabHjbf8CX82sqNgtnQ0hZILsy93GFWTEqAUxm37YRxgOgGrU9rZ64h1uW5hD30UzpWSgI9OOt/z9aPgXxJc6zulMAPc5Fh9y5N7+I= 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 1775075421133644.5077030136878; Wed, 1 Apr 2026 13:30:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w82BX-0004OC-0k; Wed, 01 Apr 2026 16:29:07 -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 1w82BV-0004NB-1v for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:05 -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 1w82BT-00039z-FA for qemu-devel@nongnu.org; Wed, 01 Apr 2026 16:29:04 -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-582-N5Uq9oryMmeXIIPKhyAFlg-1; Wed, 01 Apr 2026 16:29:01 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cd7ea0bb20so59896285a.3 for ; Wed, 01 Apr 2026 13:29:01 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a548a4efsm68194085a.8.2026.04.01.13.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 13:28:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775075342; 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=cJNdBuz3S6is0ruPjvt0Pn+XtAJ72jBZJxFTphrkxe3AnzdPsl6dWLq4qDHKK4h4aW2Ctr b+/FIbVah2bG4MTCFPE5qfMVY78Q4y4+o2Cksi9RlhGNj3p6/6MFuXXLUgZu0IYoYp/Vqa d4SFxuXdfgX1K2K73LOEc943LFLJ7SI= X-MC-Unique: N5Uq9oryMmeXIIPKhyAFlg-1 X-Mimecast-MFC-AGG-ID: N5Uq9oryMmeXIIPKhyAFlg_1775075341 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775075341; x=1775680141; 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=aUa9Rn6GgEB9uo7STWAZeliH2WTJUD4MuOu3KtoRlS5dGhz9szVwCeqOqz1U6vH0X9 4o582ZHnJtQpZqfzbn6qgXlApwbz9GvhNv8vIVGOgtYzqcdnmd6weVgnWEmYc9RVSmpj WatHwSR/iD9OPr8jh0Oc2n7OqSdryvUZPTOXoyXgOMS5evpruCV4siAM4/NL0dMQlcXC p5NA4Nu0ViCPp8YA2/MOmUJb8IUvoULZyzQLPa/TZyr5ltwnXDzwdOHSBa69OpxBSm5X dcUHulVrK1hDjPSEakDTJg4gue9PjGoqKnpL2ofIW7+Mc87fxEMtacoosKufKJLe3ZAi oXSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775075341; x=1775680141; 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=pXSfS1JYVbwADf5/5ee8pAXyReJF9CnMUQl/wBlniLz48bZWRt2tNgZ6a1IGgSU0bw 5ettbzEivDrAcNJ/pi2ft4yCxVwYQ9hUMZ1qAKWF6kGsqDd6rfeUSjM1I8aWsNaxyI/l iRH6Lh5jGpbn7rn4rksutnRAMIfdoqK3ZNml6F8I1Xonekf58gvrl9L+X96qZHS9ZxhF 1okExlfLqgQlKtrbeJ3250R8HAQTDZCn0+EElZbAdcZkDiRhPsIoKTy5Ki6cQzPV9LHt 8YHl1YcetC2tybEeCtTNq+9OUw7z1wmFr8FZpcnccLdFRLw3Oopt2tIOahbgfsh5jJhF /SkQ== X-Gm-Message-State: AOJu0Yw9emVwOb0JwYQFYiod+zJtKkMaXNe6yybF7mSgvleUI4G1cxHJ 67FRc8VxJo/56+VZxu9o/gufume5/1Wehi7GCOKGvhjBdAEhjjLH5PemP0PSQBXcif14HMGygLH Mb9Ph9Z8y48rQyBGsBV1ztr6NkdRkfQvPvvEGZDX3xNcW3u1dPpOvfTRFLYnzUAwdwspQSrFMXp QaFqM7WDG3aHlVZ1P9VteqkZ2jk4JRZPoEUBOJNQ== X-Gm-Gg: ATEYQzzL6s9dlHJBmI8YMBa4rGxWbCnOYfqhYMX/7NO9qwJNm1X/NgghPL3yAOT58q3 9S+pqNhsMy2q/yYqh2t/s+bdVsEqWfKWCCwvZb30BVNnE1aavb/kzoj9Kc4zPBdkj7cIg5Wjiba 6jPLw3+A1UP2wZiRY2ToMLshAu71mn8g/GsLNEqZV2c4/ZP30UZhCdgp+VrphtPQybmvAr2VOrV Nhc/OChdODzeULLRR5gUY7K8Ho1G55RhBJMal8omBA0mRJztbZPPpMS0VIapJYHYZ4ZpacryRZ4 AwqbD8dsw/Fhd22zHyl9Ih1uSDZ3bPzD9cE2jN0RXvuKxNtETYFlXtuCyKCAKVfrzEF5jPEKNos bqhoo3TOAFw/x39UFsObNj6iU8ndTAZVVMZJ0fMl45Uc= X-Received: by 2002:a05:620a:4103:b0:8cd:8f94:259b with SMTP id af79cd13be357-8d1b5b876f6mr760034185a.33.1775075340676; Wed, 01 Apr 2026 13:29:00 -0700 (PDT) X-Received: by 2002:a05:620a:4103:b0:8cd:8f94:259b with SMTP id af79cd13be357-8d1b5b876f6mr760027585a.33.1775075339906; Wed, 01 Apr 2026 13:28:59 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juraj Marcin , Alexander Mikhalitsyn , Fabiano Rosas , Peter Xu , Alexander Mikhalitsyn Subject: [PATCH 11/11] tests/unit/test-vmstate: add tests for VMS_ARRAY_OF_POINTER_AUTO_ALLOC Date: Wed, 1 Apr 2026 16:28:44 -0400 Message-ID: <20260401202844.673494-12-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260401202844.673494-1-peterx@redhat.com> References: <20260401202844.673494-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: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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: 1775075422246158500 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 Reviewed-by: Juraj Marcin --- 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