From nobody Mon Apr 6 21:55:02 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=1773789899; cv=none; d=zohomail.com; s=zohoarc; b=i6Va+zfqUZFmQofDJy1nJKh2W+P56JKSULYdo2gpJ3rZh2zmSb3uKQjqqkPi+Qnzl0KHTwSF2BnQ7mlxoWqpZniXgwVfqtWi561gGJ8DjwRxhfdHmVpoTDZdh7qiZKoQhTrgg+xhXAeMTjDtRIMK5JQmpG9tqheO7ATLrvbo4Uk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773789899; 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=PN63kHSkiGklfAkICvLJCg4I6fSHLpVorWEfRkM9FZU=; b=RNhXv4xOYw/mqbtud2Jlr6yU248xMg+9sXHBofX11tlPBLmSdcLpXz9pejzjeDyq6XnaxdYaqQm94eo4/gzqGZcYPuLX/3UZ/oB+B+2rooG66/bq0OID7WqaJ1cPFsBuC0Lq5f3Uds+HeRbowZto0EHWSn3PJ2py5SZ2XAK42C4= 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 1773789899182792.6020584691139; Tue, 17 Mar 2026 16:24:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2dlK-0003wV-38; Tue, 17 Mar 2026 19:23:46 -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 1w2dlI-0003vv-Pl for qemu-devel@nongnu.org; Tue, 17 Mar 2026 19:23:44 -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 1w2dlH-0006Rw-7k for qemu-devel@nongnu.org; Tue, 17 Mar 2026 19:23:44 -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-685-PEJrET97P7anVQf27T9HNA-1; Tue, 17 Mar 2026 19:23:41 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-89c56300e64so106186636d6.3 for ; Tue, 17 Mar 2026 16:23:40 -0700 (PDT) Received: from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89c6b9ea39asm8203806d6.37.2026.03.17.16.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 16:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773789822; 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=PN63kHSkiGklfAkICvLJCg4I6fSHLpVorWEfRkM9FZU=; b=iUelgLXHp6nXM+6upe2nwk7xSBshRn5RO32fxhns0xRnp0FbYUMyedOG8RfODeRZsXun4p MNjXg+iogtEAaVoJ+sAbh1+6/V8OU9i6vbNwGYMX9IQGTX1/Ph5SZCuAuxBcxsbs0sGAxv GNjzZ3klGghZofZjzfoumgJltD+rCX8= X-MC-Unique: PEJrET97P7anVQf27T9HNA-1 X-Mimecast-MFC-AGG-ID: PEJrET97P7anVQf27T9HNA_1773789820 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773789820; x=1774394620; 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=PN63kHSkiGklfAkICvLJCg4I6fSHLpVorWEfRkM9FZU=; b=BtVm1dVSp2KLgKosQd70/dsJPBR8sE1TOwvDdwwOYtsn++rM14sGYPTv+zJP7A4raR q5c+ALbWsC/VCTxolHXxEhyUY2eRW51QTXChep7w0Ulu51Zq5GSe5iTX27zHVtOFXx1j 9cNU78SPr+TFlozfR9v1jH/Up/Cr2+THc09YoCT6OEUcOax1fTSpAt67R5FWOFlGW57n oEtFfReqy7juq5A4tu1Dc2CWCaWsfeRZbt0Q8ZoziXFv/CU2+8I3Bow8U1X7YEnInnBS NDttbhvsPU0u22LZIRy+MM9QGfU6I6CjfugTY8aihXs0r+M7dUA0v8g1SBxK0Agyfs5x JoDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773789820; x=1774394620; 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=PN63kHSkiGklfAkICvLJCg4I6fSHLpVorWEfRkM9FZU=; b=DrfsJ24tKDna4aImP8TSac3dAQkr3scRYwN99ZjREW1STubkE6s60WRmzwY/eMzyJB Pis2BYxzXAru6qWUVBhAzEFKjyZbJ8Zy1luzdte+gWccoehc+5ydgkmLyyZb972+wIIb IvRQ9vSmicZZduxJQPpAKzmahwNfbwrW7sdDL4dXr+uFF4adCzW7X3odgpl3/INMMlsk 0uq7q5vuchPXdElEtivXFytfRMIJkr2otLLeo3H9iADCFiONmLt9aiNtcpHV8UDflt+x 0InCXOR1qGqNao8m3rM0SOuRW4gY9OmIyjpwSAjFx6CHeyQNPeoMM3V7vXtuCOblbjrB NVLQ== X-Gm-Message-State: AOJu0Yz0UoDVd4WPDggLwp5G+1a25lQT57CqdIwsRuu/DoQss3D0Mk84 sS2skhH2FJs96g53QugONcr4MV3aSB3C43PLAzWio+CQYHgE06vVgBtJU7fx6w2w5HLYZHIxTJy uf0fmcmWlcGVOWXckQOWu5KN58b3MveV7qQeWAIkSHB8ULFJFZA6Zy+J6OM5c2i9HYwCoqKlXQW E/I7qsA1q2TCMT9jZ+j+/8lyJutxKdScKJVQx0Dg== X-Gm-Gg: ATEYQzy9mPsHwYurtDMQb1uQ7BdvThwgY/Q6m5Xm9dCJKGk9jQ7Hj7KlBo1M+hRz9ry s1EDiu19QMVgYfEP0RbtWaei/ua8CCUFMAJuXGb1OGkdSD22fFXoLFWsWcYADY/m0Qp7K3JOcy3 H/VnoFbqDlWZjwDQMEfefnmNpHS2+ml9vvCU3H2ldPg1CM94076+psiz1ahH/KFSUnQp+uX+jZZ 25l1UMjTPdpxIZ943HLASCrdvPm4KTUA+ez2AesqIrG77LNLDgmbN/0XHdXtWHZvHB7gmunkYDr Qn+/9pKUTbcHm9wBMl9bWeKq/deqMZcYzlKbys3Xie3OVmYguzTxMtdcR11wacWbtWSOrk6SWjl yjXIvU9ZE6pez7w== X-Received: by 2002:a05:6214:5d0f:b0:89c:5557:88b9 with SMTP id 6a1803df08f44-89c6b58d971mr21984206d6.48.1773789820023; Tue, 17 Mar 2026 16:23:40 -0700 (PDT) X-Received: by 2002:a05:6214:5d0f:b0:89c:5557:88b9 with SMTP id 6a1803df08f44-89c6b58d971mr21983916d6.48.1773789819542; Tue, 17 Mar 2026 16:23:39 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Juraj Marcin , peterx@redhat.com, Fabiano Rosas Subject: [PATCH RFC 03/10] vmstate: Do not set size for VMS_ARRAY_OF_POINTER Date: Tue, 17 Mar 2026 19:23:25 -0400 Message-ID: <20260317232332.15209-4-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260317232332.15209-1-peterx@redhat.com> References: <20260317232332.15209-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: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, 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: 1773789901802154100 Content-Type: text/plain; charset="utf-8" When VMS_ARRAY_OF_POINTER is specified, it means the vmstate field is an array of pointers. The size of the element is not relevant to whatever it is stored inside: it is always the host pointer size. Let's reserve the "size" field in this case for future use, update vmstate_size() so as to make it still work for array of pointers properly. When at this, provide rich documentation on how size / size_offset works in vmstate. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn --- include/migration/vmstate.h | 20 ++++++++++++++++---- migration/savevm.c | 3 +++ migration/vmstate.c | 10 +++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 68fd954411..b4bc69486d 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -183,11 +183,26 @@ typedef enum { struct VMStateField { const char *name; size_t offset; + + /* + * @size or @size_offset specifies the size of the element embeded in + * the field. Only one of them should be present never both. When + * @size_offset is used together with VMS_VBUFFER, it means the size is + * dynamic calculated instead of a constant. + * + * When the field is an array of any type, this stores the size of one + * element of the array. + * + * NOTE: even if VMS_POINTER or VMS_ARRAY_OF_POINTER may be specified, + * this parameter always reflects the real size of the objects that a + * pointer point to. + */ size_t size; + size_t size_offset; + size_t start; int num; size_t num_offset; - size_t size_offset; const VMStateInfo *info; enum VMStateFlags flags; const VMStateDescription *vmsd; @@ -547,7 +562,6 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =3D (_version), \ .num =3D (_num), \ .info =3D &(_info), \ - .size =3D sizeof(_type *), \ .flags =3D VMS_ARRAY|VMS_ARRAY_OF_POINTER, \ .offset =3D vmstate_offset_array(_state, _field, _type*, _num), \ } @@ -557,7 +571,6 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =3D (_v), \ .num =3D (_n), \ .vmsd =3D &(_vmsd), \ - .size =3D sizeof(_type *), \ .flags =3D VMS_ARRAY|VMS_STRUCT|VMS_ARRAY_OF_POINTER, \ .offset =3D vmstate_offset_array(_s, _f, _type*, _n), \ } @@ -567,7 +580,6 @@ extern const VMStateInfo vmstate_info_qlist; .version_id =3D (_version), = \ .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), = \ .info =3D &(_info), = \ - .size =3D sizeof(_type *), = \ .flags =3D VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER= , \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ } diff --git a/migration/savevm.c b/migration/savevm.c index 8115203b51..f5a6fd0c66 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -868,6 +868,9 @@ static void vmstate_check(const VMStateDescription *vms= d) =20 if (field) { while (field->name) { + if (field->flags & VMS_ARRAY_OF_POINTER) { + assert(field->size =3D=3D 0); + } if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) { /* Recurse to sub structures */ vmstate_check(field->vmsd); diff --git a/migration/vmstate.c b/migration/vmstate.c index e98b5f5346..e29a8c3f49 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -110,13 +110,21 @@ static int vmstate_n_elems(void *opaque, const VMStat= eField *field) =20 static int vmstate_size(void *opaque, const VMStateField *field) { - int size =3D field->size; + int size; =20 if (field->flags & VMS_VBUFFER) { size =3D *(int32_t *)(opaque + field->size_offset); if (field->flags & VMS_MULTIPLY) { size *=3D field->size; } + } else if (field->flags & VMS_ARRAY_OF_POINTER) { + /* + * For an array of pointer, the each element is always size of a + * host pointer. + */ + size =3D sizeof(void *); + } else { + size =3D field->size; } =20 return size; --=20 2.50.1