From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077573; cv=none; d=zohomail.com; s=zohoarc; b=aYCErJumoY5CE0t9QXmU5ls0dhC+OxEL7CXh1WnJivpIqKOy/xPxWXbWTOiooG8LZMXSHy1NF8iYAYeOu+cvl1Dt0BKks7GN3HH08aQzYNT6c1F5BvEUyxdwgkXa6hewXq7CFiEAi8Up7lIfZ3msl+9xWWj1Z0ovEIKsj7ErmZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077573; 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=+3V/PR/3rZ16t+TPz1hsj/IbhHxe06d9rOuvrnFpHuk=; b=WI8ZGrh7GYW8LCRes40Gr0Ko3qRjrzY46RqhQFW9wGB9HbUSn+sp3gUv8Cjg4/kpdBTdicn2Bmh6lyZhp8RWOsBM6NxNYZA4pKMMQeNesRzGPOQXmZcjR/vpJE0jFP8+ajVEW8EE3Az3EZEKAcJHTbyThsRTfV7UsvvZkhQiZXI= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787077573741803.2347948915799; Tue, 18 Aug 2026 11:26:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUh-0007yN-RF; Tue, 18 Aug 2026 14:25:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUg-0007xv-I4 for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:02 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUe-0002yy-Pf for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:02 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 33880846B9; Tue, 18 Aug 2026 18:24:51 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D7E6D362E; Tue, 18 Aug 2026 18:24:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id iCi8KXGjhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:24:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077495; h=from:from:reply-to: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=+3V/PR/3rZ16t+TPz1hsj/IbhHxe06d9rOuvrnFpHuk=; b=O0inj6KFNOcUgq9C/aCX/qtBYmldRyyf6USO3i/xs0ZPy01Afd5axdJ7rUl5l1GkmI6CAT kV38uThCwDQBG9rgcz8W3eGk9Jl2CF7+/YaAuyqqhr2ZIwqPgK5LZ0EwwsPWzcOsOoq6O/ 8Ae/4FuS9KtcpA9Q3tRv92heiqWwPew= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077495; h=from:from:reply-to: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=+3V/PR/3rZ16t+TPz1hsj/IbhHxe06d9rOuvrnFpHuk=; b=GEUXkjE6yZzjSlf84Puu9wiZWTnfgdHra5C2+GfycXdIUZWYQdqR30pRf/Yt0nyrfSQcws fNRkni9+jk6+WTCA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=bhLeGBhJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="6cf/oYya" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077491; h=from:from:reply-to: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=+3V/PR/3rZ16t+TPz1hsj/IbhHxe06d9rOuvrnFpHuk=; b=bhLeGBhJBqOeo/FjujGa0rKvY+87h+zpC/CHyauvkC0EzhlxPMTEQ8g9YeIZ0XpBQc1V8o Tmx2y52AQ91OhD3nw77EgTzDQQr1bZwU27IRUQMg+vT64uKYeDCZW+YAXIs1h5BWjfWBGe L7ttUXX1asw6vJoDTmMpk5ZN0TyLaIA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077491; h=from:from:reply-to: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=+3V/PR/3rZ16t+TPz1hsj/IbhHxe06d9rOuvrnFpHuk=; b=6cf/oYyavGGu41eubXZ/6i6noppyHGbqiz4G9utyhI8Rp5gVpEv/oQjlIs4DqNpfiFz8Hl 6nIdJv/iOfOS5cBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" Subject: [PATCH v2 1/8] migration: Remove unused vmstate macros Date: Tue, 18 Aug 2026 15:24:34 -0300 Message-ID: <20260818182441.404790-2-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: 33880846B9 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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=lists1p.gnu.org; Received-SPF: pass client-ip=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077574036158500 Content-Type: text/plain; charset="utf-8" Remove the several vmstate macros that don't have any users. Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- include/migration/vmstate.h | 45 ------------------------------------- 1 file changed, 45 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 1b7f295417e..214a2131350 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -451,15 +451,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_sub_array(_state, _field, _type, _start= ), \ } =20 -#define VMSTATE_ARRAY_INT32_UNSAFE(_field, _state, _field_num, _info, _typ= e) {\ - .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_INT32, \ - .offset =3D vmstate_offset_varray(_state, _field, _type), \ -} - #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, = _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -710,16 +701,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 -#define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, = _vmsd, _type) { \ - .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ - .version_id =3D (_version), \ - .vmsd =3D &(_vmsd), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_INT32, \ - .offset =3D vmstate_offset_varray(_state, _field, _type), \ -} - #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version,= _vmsd, _type) { \ .name =3D (stringify(_field)), \ .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), \ @@ -1069,8 +1050,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; =20 #ifdef CONFIG_LINUX =20 -#define VMSTATE_U8(_f, _s) \ - VMSTATE_U8_V(_f, _s, 0) #define VMSTATE_U16(_f, _s) \ VMSTATE_U16_V(_f, _s, 0) #define VMSTATE_U32(_f, _s) \ @@ -1116,15 +1095,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_BOOL_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool) =20 -#define VMSTATE_INT8_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t) - -#define VMSTATE_INT16_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t) - -#define VMSTATE_INT32_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t) - #define VMSTATE_INT64_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t) =20 @@ -1140,12 +1110,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_UINT64_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t) =20 -#define VMSTATE_FD_TEST(_f, _s, _t) = \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_fd, int32_t) - -#define VMSTATE_TIMER_PTR_TEST(_f, _s, _test) \ - VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *) - #define VMSTATE_TIMER_PTR_V(_f, _s, _v) \ VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *) =20 @@ -1155,9 +1119,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_TIMER_PTR_ARRAY(_f, _s, _n) \ 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) - #define VMSTATE_TIMER_V(_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_timer, QEMUTimer) =20 @@ -1275,12 +1236,6 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \ VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0) =20 -#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ - VMSTATE_VBUFFER(_f, _s, 0, NULL, _size) - -#define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) = \ - VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size) - #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)= )) =20 --=20 2.53.0 From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077594; cv=none; d=zohomail.com; s=zohoarc; b=QZuYahrsvtPCrpdLj+GVqmIr0wyDkfVnh4tQ07b1clfPUbSNGvvXgIJh4a3RB/YZNCT7Og0FdPbsInfW1ejl4wK0UP97h03D8KbvWHAVnkdfSa7hgRTxO2vucSwhz0kb5glsRNPkhUrR+gtfLzZp3quxKAuhwqIukYq60GYtrgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077594; 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=jYy26PXxKizQVID78SWYPZeYQFKEXBhX80lFvKgUAtI=; b=kZUE48ZBtI8x0hhw6sGm6oaOjxqluEQP41SP8c5NB4YTzcPO6TH/+18eJBytCta2kd1hKzDFP6WgRmsKKtSt/sQPPGXndOIFQH3ESKZ9YVryo1dR4fjGpIujklU/8rWoexz+lIZTUlKlnK0+M3ya1fdwvzkcWmLCfVb7C6UIMgo= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178707759473245.0096323828127; Tue, 18 Aug 2026 11:26:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUn-00082B-7o; Tue, 18 Aug 2026 14:25:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUl-00081T-CB for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:07 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUh-0002zf-3h for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:07 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 80C993E39; Tue, 18 Aug 2026 18:24:53 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9B2E922BA; Tue, 18 Aug 2026 18:24:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id eCHnGnOjhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:24:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077497; h=from:from:reply-to: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=jYy26PXxKizQVID78SWYPZeYQFKEXBhX80lFvKgUAtI=; b=c0cSk/hs7oqkgfN3iSIqo3YaipeNrCbsqPskBQHgFu4mI5IsgQ6m7/TPhqWWsRj1vuFqpX 2+ps0oFfUcLXh4RPfMoL7J3K8lOpMxp9r1XIfZYaUItOW8OJfsdWM+kzx5xzsigAZWC2qz I9czW0jZmXQQOP4okYmUCJgNHLzZb1A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077497; h=from:from:reply-to: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=jYy26PXxKizQVID78SWYPZeYQFKEXBhX80lFvKgUAtI=; b=KDtcSGtbjK01OOdYpZaSyudi21/caHbinUTr09Qzi7W1ZloXY6LZywv884nFX3UK9ou/RT oCA7y8OxlsNIg6DQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077493; h=from:from:reply-to: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=jYy26PXxKizQVID78SWYPZeYQFKEXBhX80lFvKgUAtI=; b=kdrUy08VyHpTo01xFjmmDHszp6LX7immWdrp2y11QoN8x8krU9tALiBa32k8E8wLwvRQBb +YrupODTCr0aaw6/hfGY1AxWFS+WNRvngS6XHjM7FTxFlWYhirTEpkL02qQaM+HCiCyic8 BwZA/QH6T2TMge8UEQH8Uhvh84Wo2oE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077493; h=from:from:reply-to: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=jYy26PXxKizQVID78SWYPZeYQFKEXBhX80lFvKgUAtI=; b=IplBal8YJOaFiw38Ki8/+dxFVXkeUaG2CWvQ/PIhL5SggEgPM267L8HwqRbNzOWfi3Woj6 K3OBEoHsiX+0DKCQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" , Seungjung Kim , Manos Pitsidianakis Subject: [PATCH v2 2/8] migration: Introduce VMStateStructMember Date: Tue, 18 Aug 2026 15:24:35 -0300 Message-ID: <20260818182441.404790-3-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,yandex-team.ru,gmail.com,linaro.org]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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=lists1p.gnu.org; Received-SPF: pass client-ip=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077596249158500 Content-Type: text/plain; charset="utf-8" When migrating a buffer or array, the vmstate code needs to know the size of the buffer and the number of elements of the array. Today a vmstate writer can choose from a number of macros that take as last input the name of a struct member from where the size/num will be read. At load time, the code will access those values via an opaque pointer to the migrated data and therefore it needs to also know the size of the struct member at that offset. Currently that information is communicated by means of the VMS_VARRAY_* and VMS_VBUFFER_* flags, where each possible type is represented by a flag. So far, that's all fine, but since the vmstate code makes heavy use of macros, handling several types individually (i.e. by name: int, int32_t, etc) requires several versions of a same macro, one for each type. E.g: VMSTATE_VBUFFER_ALLOC_UINT32 ^ This creates a pattern where the vmstate writer has to match the macro name to the data type and has resulted in the code having a tendency of having one macro version for each type, for each type of vmstate. There is also some cognitive load to deal with, e.g. VMSTATE_VARRAY_INT32 doesn't hold an array of int32, it holds an array of something else and the number of elements for the array is stored in a variable of type int32. We're now dealing with the scenario where the code has been expecting int32_t at some places, but a uint64_t macro variant has been added without the code being updated. To address all these situations, introduce a new struct that will hold the offset of the struct members, but also their size, so the various extra macros can all be removed and the person writing the vmstate doesn't need to care about type-checking. Still, keep a minimum check that those fields are at least integers and fit into 64 bits. What changes: 1) type checking changes from individual types to a single check for all integers; 2) there are new ways to access the offsets; num_offset -> num_indirect.offset size_offset -> size_indirect.offset [new] num_indirect.size [new] size_indirect.size 2) reading the offsets goes from checking the VMS_VARRAY_* flags in an if/elseif block to comparing offset.size against the hardcoded sizes in bytes; 3) the VMS_VARRAY_* and VMS_VBUFFER_* flags become obsolete. Removed in the next patch; 4) memory usage increases +1 byte per vmstate; Reported-by: Seungjung Kim Fixes: CVE-2026-6426 Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3675 Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- include/migration/vmstate.h | 163 +++++++++++++++++++++-------- migration/savevm.c | 4 +- migration/vmstate.c | 50 +++++---- rust/bindings/migration-sys/lib.rs | 10 ++ rust/migration/src/vmstate.rs | 24 ++++- rust/tests/tests/vmstate_tests.rs | 26 ++--- 6 files changed, 197 insertions(+), 80 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 214a2131350..12bfa64fb92 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -31,6 +31,7 @@ =20 typedef struct VMStateInfo VMStateInfo; typedef struct VMStateField VMStateField; +typedef struct VMStateStructMember VMStateStructMember; =20 /* * VMStateInfo allows customized migration of objects that don't fit in @@ -67,15 +68,15 @@ enum VMStateFlags { * to the actual field (e.g. struct a { uint8_t *b; * }). Dereference the pointer before using it as basis for * further pointer arithmetic (see e.g. VMS_ARRAY). Does not - * affect the meaning of VMStateField.num_offset or - * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for + * affect the meaning of VMStateField.num_indirect or + * VMStateField.size_indirect; see VMS_VARRAY* and VMS_VBUFFER for * those. */ VMS_POINTER =3D 0x002, =20 /* The field is an array of fixed size. VMStateField.num contains * the number of entries in the array. The size of each entry is * given by VMStateField.size and / or opaque + - * VMStateField.size_offset; see VMS_VBUFFER and + * VMStateField.size_indirect; see VMS_VBUFFER and * VMS_MULTIPLY. Each array entry will be processed individually * (VMStateField.info.get()/put() if VMS_STRUCT is not set, * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not @@ -88,8 +89,9 @@ enum VMStateFlags { * array entry. */ VMS_STRUCT =3D 0x008, =20 - /* The field is an array of variable size. The int32_t at opaque + - * VMStateField.num_offset contains the number of entries in the + /* + * The field is an array of variable size. The integer at opaque + + * VMStateField.num_indirect contains the number of entries in the * array. See the VMS_ARRAY description regarding array handling * in general. May not be combined with VMS_ARRAY or any other * VMS_VARRAY*. */ @@ -105,7 +107,7 @@ enum VMStateFlags { VMS_ARRAY_OF_POINTER =3D 0x040, =20 /* The field is an array of variable size. The uint16_t at opaque - * + VMStateField.num_offset + * + VMStateField.num_indirect * contains the number of entries in the array. See the VMS_ARRAY * description regarding array handling in general. May not be * combined with VMS_ARRAY or any other VMS_VARRAY*. */ @@ -114,26 +116,27 @@ enum VMStateFlags { /* The size of the individual entries (a single array entry if * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if * neither is set) is variable (i.e. not known at compile-time), - * but the same for all entries. Use the int32_t at opaque + - * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine + * but the same for all entries. Use the integer at opaque + + * VMStateField.size_indirect (subject to VMS_MULTIPLY) to determine * the size of each (and every) entry. */ VMS_VBUFFER =3D 0x100, =20 - /* Multiply the entry size given by the int32_t at opaque + - * VMStateField.size_offset (see VMS_VBUFFER description) with + /* + * Multiply the entry size given by the integer at opaque + + * VMStateField.size_indirect (see VMS_VBUFFER description) with * VMStateField.size to determine the number of bytes to be * allocated. Only valid in combination with VMS_VBUFFER. */ VMS_MULTIPLY =3D 0x200, =20 /* The field is an array of variable size. The uint8_t at opaque + - * VMStateField.num_offset + * VMStateField.num_indirect * contains the number of entries in the array. See the VMS_ARRAY * description regarding array handling in general. May not be * combined with VMS_ARRAY or any other VMS_VARRAY*. */ VMS_VARRAY_UINT8 =3D 0x400, =20 /* The field is an array of variable size. The uint32_t at opaque - * + VMStateField.num_offset + * + VMStateField.num_indirect * contains the number of entries in the array. See the VMS_ARRAY * description regarding array handling in general. May not be * combined with VMS_ARRAY or any other VMS_VARRAY*. */ @@ -187,29 +190,88 @@ typedef enum { MIG_PRI_MAX, } MigrationPriority; =20 + +/* + * VMStateStructMember: Metadata about a single member of the struct + * being migrated by the vmstate. This is kept separate from + * VMStateField because a single VMStateField can reference other + * members of the struct aside from the main struct member that's + * being migrated. + * + * One situation where extra fields are referenced is the common case + * of a struct containing an array or buffer, the size of which is + * stored in another member of the same struct. + * + * Example 1: + * struct IDEState { + * ... + * uint8_t *io_buffer; + * int32_t io_buffer_total_len; + * ... + * } + * VMSTATE_VARRAY_INT32(io_buffer, IDEState, io_buffer_total_len, 1, + * vmstate_info_uint8, uint8_t) + * + * In the above, io_buffer is the main field being migrated by the + * VMSTATE_VARRAY while io_buffer_total_len is the meta field that + * provides the size of the io_buffer. In this particular case, + * io_buffer_total_len is never migrated. + * + * Example 2: + * struct SpaprMachineState { + * ... + * uint32_t fdt_size; + * void *fdt_blob; + * ... + * } + * VMSTATE_UINT32(fdt_size, SpaprMachineState), + * VMSTATE_VBUFFER_ALLOC_UINT32(fdt_blob, SpaprMachineState, 0, NULL, fdt_= size), + * + * Here, fdt_blob is the field being migrated by VMSTATE_VBUFFER_ALLOC + * and fdt_size is the meta field providing the size. In this case, + * the extra field is also independently migrated by the + * VMSTATE_UINT32 above. + */ +struct VMStateStructMember { + /* offsetof the field inside the migrated struct */ + uint32_t offset; + /* size of field itself */ + uint8_t size; +}; + struct VMStateField { const char *name; size_t offset; =20 /* - * @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. + * @size directly specifies the size of the element being + * migrated. * - * When the field is an array of any type, this stores the size of one - * element of the array. + * @size_indirect specifies the offset inside a struct where the + * size of the element is stored. * - * 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. + * Only one of the above should be present (except for + * VMSTATE_MULTIPLY which uses .size as a multiplier). When + * @size_indirect 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, these refer to the size + * of one element of the array. + * + * NOTE: even if VMS_POINTER or VMS_ARRAY_OF_POINTER may be + * specified, these parameters always reflect the real size of the + * objects that a pointer point to. + * + * @num_indirect specifies the offset inside a struct where the + * number of elements of an array is stored. */ size_t size; - size_t size_offset; + VMStateStructMember size_indirect; + VMStateStructMember num_indirect; =20 size_t start; int num; - size_t num_offset; + const VMStateInfo *info; enum VMStateFlags flags; const VMStateDescription *vmsd; @@ -328,6 +390,17 @@ extern const VMStateInfo vmstate_info_g_byte_array; (type_check(t1, typeof_elt_of_field(t2, f)) \ + QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(((t2 *)0)->f))) =20 +#define type_check_int64(t) \ + (~((t)0) * sizeof(struct { \ + QEMU_BUILD_BUG_ON(sizeof(t) > sizeof(uint64_t)); \ + })) + +#define vmstate_field_offset(_state, _field) { \ + .offset =3D (offsetof(_state, _field) + \ + type_check_int64(typeof_field(_state, _field))), \ + .size =3D sizeof(typeof_field(_state, _field)), \ +} + #define vmstate_offset_value(_state, _field, _type) \ (offsetof(_state, _field) + \ type_check(_type, typeof_field(_state, _field))) @@ -454,7 +527,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, = _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_INT32|VMS_POINTER, \ @@ -464,7 +537,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info,= _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT32|VMS_POINTER, \ @@ -474,7 +547,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_INT32_ALLOC(_field, _state, _field_num, _version, _= info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_INT32 | VMS_POINTER | VMS_ALLOC, \ @@ -484,7 +557,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \ @@ -494,7 +567,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT16_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint16_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT16 | VMS_POINTER | VMS_ALLOC, \ @@ -504,7 +577,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version,= _info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint16_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ .flags =3D VMS_VARRAY_UINT16, \ @@ -583,7 +656,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; _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), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ .flags =3D VMS_POINTER | VMS_VARRAY_UINT8 | \ @@ -596,7 +669,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; _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), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ .flags =3D VMS_POINTER | VMS_VARRAY_UINT32 | \ @@ -608,7 +681,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VARRAY_OF_POINTER_UINT32(_field, _state, _field_num, _vers= ion, _info, _type) { \ .name =3D (stringify(_field)), = \ .version_id =3D (_version), = \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), = \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), = \ .info =3D &(_info), = \ .flags =3D VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER= , \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ @@ -650,7 +723,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; =20 #define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, = _vmsd, _type) { \ .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint8_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ @@ -674,7 +747,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _v= msd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ @@ -684,7 +757,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _= vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ @@ -694,7 +767,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _= vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint16_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ .flags =3D VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ @@ -703,7 +776,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; =20 #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version,= _vmsd, _type) { \ .name =3D (stringify(_field)), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ @@ -715,7 +788,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, int32_t), \ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .flags =3D VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ @@ -736,7 +809,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .size =3D (_multiply), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ @@ -747,7 +820,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, int32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ @@ -757,7 +830,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ @@ -767,7 +840,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint64_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER | VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ @@ -778,7 +851,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, uint32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ .offset =3D offsetof(_state, _field), \ @@ -838,7 +911,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, = _size) {\ .name =3D "unused", \ .field_exists =3D (_test), \ - .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ .size =3D (_size), \ .info =3D &vmstate_info_unused_buffer, \ @@ -852,7 +925,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .name =3D (stringify(_field)), \ .field_exists =3D (_test), \ .version_id =3D (_version), \ - .size_offset =3D vmstate_offset_value(_state, _field_size, int32_t),\ + .size_indirect =3D vmstate_field_offset(_state, _field_size), \ .info =3D &vmstate_info_bitmap, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ diff --git a/migration/savevm.c b/migration/savevm.c index 34dd06f9f73..e1b707dda63 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -873,14 +873,14 @@ static void vmstate_check(const VMStateDescription *v= msd) * Size must be provided because dest QEMU needs that * info to know what to allocate */ - assert(field->size || field->size_offset); + assert(field->size !=3D 0 || field->size_indirect.size= !=3D 0); } 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); + assert(field->size =3D=3D 0 && field->size_indirect.si= ze =3D=3D 0); } /* * VMS_ARRAY_OF_POINTER must be used only together with one diff --git a/migration/vmstate.c b/migration/vmstate.c index 50ebe378452..372aed258f1 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -78,32 +78,44 @@ vmsd_init_ptr_marker_field(VMStateField *fake, const VM= StateField *field) }; } =20 -static int vmstate_n_elems(void *opaque, const VMStateField *field) +static uint64_t vmstate_read_from_offset(const VMStateStructMember *member, + void *opaque) { - int n_elems =3D 1; + uint8_t *ptr =3D (uint8_t *)opaque + member->offset; + uint64_t v =3D 0; + + switch (member->size) { + case 1: + case 2: + case 4: + case 8: + memcpy(&v, ptr, member->size); + return v; + } + g_assert_not_reached(); +} + +static uint64_t vmstate_n_elems(void *opaque, const VMStateField *field) +{ + uint64_t n_elems =3D 1; =20 if (field->flags & VMS_ARRAY) { n_elems =3D field->num; - } else if (field->flags & VMS_VARRAY_INT32) { - n_elems =3D *(int32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT32) { - n_elems =3D *(uint32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT16) { - n_elems =3D *(uint16_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT8) { - n_elems =3D *(uint8_t *)(opaque + field->num_offset); + } else if (field->flags & (VMS_VARRAY_INT32 | VMS_VARRAY_UINT32 + | VMS_VARRAY_UINT16 | VMS_VARRAY_UINT8)) { + n_elems =3D vmstate_read_from_offset(&field->num_indirect, opaque); } =20 trace_vmstate_n_elems(field->name, n_elems); return n_elems; } =20 -static int vmstate_size(void *opaque, const VMStateField *field) +static uint64_t vmstate_size(void *opaque, const VMStateField *field) { - int size; + uint64_t size; =20 if (field->flags & VMS_VBUFFER) { - size =3D *(int32_t *)(opaque + field->size_offset); + size =3D vmstate_read_from_offset(&field->size_indirect, opaque); if (field->flags & VMS_MULTIPLY) { size *=3D field->size; } @@ -124,7 +136,7 @@ static void vmstate_handle_alloc(void *ptr, const VMSta= teField *field, void *opaque) { if (field->flags & VMS_POINTER && field->flags & VMS_ALLOC) { - gsize size =3D vmstate_size(opaque, field); + uint64_t size =3D vmstate_size(opaque, field); size *=3D vmstate_n_elems(opaque, field); if (size) { *(void **)ptr =3D g_malloc(size); @@ -335,8 +347,9 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescri= ption *vmsd, =20 if (exists) { void *first_elem =3D opaque + field->offset; - int i, n_elems =3D vmstate_n_elems(opaque, field); - int size =3D vmstate_size(opaque, field); + int i; + uint64_t n_elems =3D vmstate_n_elems(opaque, field); + uint64_t size =3D vmstate_size(opaque, field); =20 vmstate_handle_alloc(first_elem, field, opaque); if (field->flags & VMS_POINTER) { @@ -650,8 +663,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, while (field->name) { if (vmstate_field_exists(vmsd, field, opaque, version_id)) { void *first_elem =3D opaque + field->offset; - int i, n_elems =3D vmstate_n_elems(opaque, field); - int size =3D vmstate_size(opaque, field); + int i; + uint64_t n_elems =3D vmstate_n_elems(opaque, field); + uint64_t size =3D vmstate_size(opaque, field); JSONWriter *vmdesc_loop =3D vmdesc; bool is_prev_null =3D false; /* diff --git a/rust/bindings/migration-sys/lib.rs b/rust/bindings/migration-s= ys/lib.rs index 9581481e421..baa2730ca9d 100644 --- a/rust/bindings/migration-sys/lib.rs +++ b/rust/bindings/migration-sys/lib.rs @@ -47,6 +47,7 @@ fn default() -> Self { unsafe impl Zeroable for VMStateFlags {} unsafe impl Zeroable for VMStateField {} unsafe impl Zeroable for VMStateDescription {} +unsafe impl Zeroable for VMStateStructMember {} =20 // The following higher-level helpers could be in "migration" // crate when Rust has const trait impl. @@ -115,3 +116,12 @@ pub const fn with_varray_flag(mut self, flag: VMStateF= lags) -> Self { self.with_varray_flag_unchecked(flag) } } + +impl VMStateStructMember { + pub const fn new(off: usize, size: usize) -> Self { + Self { + offset: off as u32, + size: size as u8, + } + } +} diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index 63d78b4f275..e60c0860cc5 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -42,7 +42,7 @@ }; =20 use crate::bindings::{self, VMStateFlags}; -pub use crate::bindings::{MigrationPriority, VMStateField}; +pub use crate::bindings::{MigrationPriority, VMStateField, VMStateStructMe= mber}; =20 /// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a @@ -120,6 +120,23 @@ pub const fn vmstate_varray_flag(_: Phanto= mData) -> VMStateFlags T::VARRAY_FLAG } =20 +pub const OPAQUE: &[u8; 1048576] =3D &[0; 1048576]; + +pub const fn size_of_ptr_type(_: *const T) -> usize { + ::core::mem::size_of::() +} + +#[macro_export] +macro_rules! size_of_field_type { + ($struct_name:ty, $($field_name:ident).+) =3D> { + $crate::vmstate::size_of_ptr_type(unsafe { + ::core::ptr::addr_of!( + (*$crate::vmstate::OPAQUE.as_ptr().cast::<$struct_name>())= .$($field_name).+ + ) + }) + }; +} + /// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. /// @@ -148,7 +165,10 @@ macro_rules! vmstate_of { .as_bytes() .as_ptr().cast::<::std::os::raw::c_char>(), offset: ::std::mem::offset_of!($struct_name, $($field_name).+), - $(num_offset: ::std::mem::offset_of!($struct_name, $($num).+),= )? + $(num_indirect: $crate::vmstate::VMStateStructMember { + offset: ::std::mem::offset_of!($struct_name, $($num).+) as= u32, + size: $crate::size_of_field_type!($struct_name, $($num).+) as u8, + },)? $(field_exists: $crate::vmstate_exist_fn!($struct_name, $test_= fn),)? // The calls to `call_func_with_field!` are the magic that // computes most of the VMStateField from the type of the fiel= d. diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_t= ests.rs index c2c12cfab52..c002ffb2bc4 100644 --- a/rust/tests/tests/vmstate_tests.rs +++ b/rust/tests/tests/vmstate_tests.rs @@ -65,7 +65,7 @@ fn test_vmstate_uint16() { b"elem\0" ); assert_eq!(foo_fields[0].offset, 16); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_int8 }); assert_eq!(foo_fields[0].version_id, 0); assert_eq!(foo_fields[0].size, 1); @@ -86,7 +86,7 @@ fn test_vmstate_unused() { b"unused\0" ); assert_eq!(foo_fields[1].offset, 0); - assert_eq!(foo_fields[1].num_offset, 0); + assert_eq!(foo_fields[1].num_indirect.size, 0); assert_eq!(foo_fields[1].info, unsafe { &vmstate_info_unused_buffer }); assert_eq!(foo_fields[1].version_id, 0); assert_eq!(foo_fields[1].size, 8); @@ -108,7 +108,7 @@ fn test_vmstate_varray_uint16_unsafe() { b"arr\0" ); assert_eq!(foo_fields[2].offset, 0); - assert_eq!(foo_fields[2].num_offset, 4); + assert_eq!(foo_fields[2].num_indirect.offset, 4); assert_eq!(foo_fields[2].info, unsafe { &vmstate_info_uint8 }); assert_eq!(foo_fields[2].version_id, 0); assert_eq!(foo_fields[2].size, 1); @@ -172,7 +172,7 @@ fn test_vmstate_bool_v() { b"val\0" ); assert_eq!(foo_fields[0].offset, 136); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_bool }); assert_eq!(foo_fields[0].version_id, 2); assert_eq!(foo_fields[0].size, 1); @@ -193,7 +193,7 @@ fn test_vmstate_uint64() { b"wrap\0" ); assert_eq!(foo_fields[1].offset, 128); - assert_eq!(foo_fields[1].num_offset, 0); + assert_eq!(foo_fields[1].num_indirect.size, 0); assert_eq!(foo_fields[1].info, unsafe { &vmstate_info_uint64 }); assert_eq!(foo_fields[1].version_id, 0); assert_eq!(foo_fields[1].size, 8); @@ -215,7 +215,7 @@ fn test_vmstate_struct_varray_uint8() { b"arr_a\0" ); assert_eq!(foo_fields[2].offset, 0); - assert_eq!(foo_fields[2].num_offset, 60); + assert_eq!(foo_fields[2].num_indirect.offset, 60); assert!(foo_fields[2].info.is_null()); // VMSTATE_STRUCT_VARRAY_UINT8 = doesn't set info field. assert_eq!(foo_fields[2].version_id, 1); assert_eq!(foo_fields[2].size, 20); @@ -240,7 +240,7 @@ fn test_vmstate_macro_array() { b"arr_i64\0" ); assert_eq!(foo_fields[4].offset, 144); - assert_eq!(foo_fields[4].num_offset, 0); + assert_eq!(foo_fields[4].num_indirect.size, 0); assert_eq!(foo_fields[4].info, unsafe { &vmstate_info_int64 }); assert_eq!(foo_fields[4].version_id, 0); assert_eq!(foo_fields[4].size, 8); @@ -264,7 +264,7 @@ fn test_vmstate_struct_varray_uint8_wrapper() { unsafe { CStr::from_ptr(foo_fields[5].name) }.to_bytes_with_nul(), b"arr_a_wrap\0" ); - assert_eq!(foo_fields[5].num_offset, 228); + assert_eq!(foo_fields[5].num_indirect.offset, 228); assert!(unsafe { foo_fields[5].field_exists.unwrap()(foo_b_p, 0) }); =20 // The last VMStateField in VMSTATE_FOOB. @@ -316,7 +316,7 @@ fn test_vmstate_pointer() { b"ptr\0" ); assert_eq!(foo_fields[0].offset, 0); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_int32 }); assert_eq!(foo_fields[0].version_id, 2); assert_eq!(foo_fields[0].size, 4); @@ -341,7 +341,7 @@ fn test_vmstate_struct_pointer() { b"ptr_a\0" ); assert_eq!(foo_fields[1].offset, PTR_SIZE); - assert_eq!(foo_fields[1].num_offset, 0); + assert_eq!(foo_fields[1].num_indirect.size, 0); assert_eq!(foo_fields[1].vmsd, VMSTATE_FOOA.as_ref()); assert_eq!(foo_fields[1].version_id, 0); assert_eq!(foo_fields[1].size, size_of::()); @@ -366,7 +366,7 @@ fn test_vmstate_macro_array_of_pointer() { b"arr_ptr\0" ); assert_eq!(foo_fields[2].offset, 2 * PTR_SIZE); - assert_eq!(foo_fields[2].num_offset, 0); + assert_eq!(foo_fields[2].num_indirect.size, 0); assert_eq!(foo_fields[2].info, unsafe { &vmstate_info_uint8 }); assert_eq!(foo_fields[2].version_id, 0); assert_eq!(foo_fields[2].size, PTR_SIZE); @@ -391,7 +391,7 @@ fn test_vmstate_macro_array_of_pointer_wrapped() { b"arr_ptr_wrap\0" ); assert_eq!(foo_fields[3].offset, (FOO_ARRAY_MAX + 2) * PTR_SIZE); - assert_eq!(foo_fields[3].num_offset, 0); + assert_eq!(foo_fields[3].num_indirect.size, 0); assert_eq!(foo_fields[3].info, unsafe { &vmstate_info_uint8 }); assert_eq!(foo_fields[3].version_id, 0); assert_eq!(foo_fields[3].size, PTR_SIZE); @@ -454,7 +454,7 @@ fn test_vmstate_validate() { b"foo_d_0\0" ); assert_eq!(foo_fields[0].offset, 0); - assert_eq!(foo_fields[0].num_offset, 0); + assert_eq!(foo_fields[0].num_indirect.size, 0); assert!(foo_fields[0].info.is_null()); assert_eq!(foo_fields[0].version_id, 0); assert_eq!(foo_fields[0].size, 0); --=20 2.53.0 From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077554; cv=none; d=zohomail.com; s=zohoarc; b=V8qfRawuDaPjv6emfw0uE1gXE7qd0PBk+UAR30mtajf1OSJDR369VeRTPIbWLmK7q3peMIKl8Dx2WYPicjvJZhGmZ2PocL0PnXOzC5BuS1hTEHlWglUrojwcP0dfRXzAyn9+rVYxpfkpKv+X+GHvyADCAnCASsz25rTMEXRcvL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077554; 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=OApujg6O6m3Dquv+V7qQF2oVVDehESoVxw0de8YzCaA=; b=SplKz2vpU4hTGE6dEloynaYYCheT4Qv89yjfmr9W2vuXOgelJIUmmuN8PjrMBFRF31hpiJaAfn9KJNviVsnZM5YDJyhYCxvrQlmXoFZKDmnj2U7WaaY7bcL5Y6hEZ9VXB6vxFTCIB29QFKJ4mcckiH6gcmzQ3r8aSM+5D+37tHA= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787077554258720.8588554691033; Tue, 18 Aug 2026 11:25:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUo-00082X-8p; Tue, 18 Aug 2026 14:25:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUm-00081d-3j for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:08 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUj-00039i-6Y for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:07 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6FD573E8C; Tue, 18 Aug 2026 18:24:55 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E484F364F; Tue, 18 Aug 2026 18:24:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AH7XLHWjhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:24:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077499; h=from:from:reply-to: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=OApujg6O6m3Dquv+V7qQF2oVVDehESoVxw0de8YzCaA=; b=X3EWLj7rGRu6iTk1GkQlhaSfRdZPVNUYJOFiM0RQr7gM/3CrjBOP8JmRUfQEWLSU6FPx8o khc6NHws93v8T/NGUDjOfkVHQOGsrbRmTmBu2OKCN2KBYJPXpKsfOKAkGj2kf0/7WjSBMp bLK+KEo2bWEFpr5VgTT4xwWHCu6HO2M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077499; h=from:from:reply-to: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=OApujg6O6m3Dquv+V7qQF2oVVDehESoVxw0de8YzCaA=; b=Jf+Up4cAAUZL9Im6hE3JQw8BqBzDC5gkk1k7EoM+CjKnnItAHlnGGk7qSJC+iL7m7UNwmm 4mPmPuJ8jTXzMIBA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077495; h=from:from:reply-to: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=OApujg6O6m3Dquv+V7qQF2oVVDehESoVxw0de8YzCaA=; b=xRk4IdxWDIyafxbER2WyoAPS1fzvx3Pa3sUizjU8pq/IpyBjvzFnMmN7k+/M6adXXiXFTf coOdMX6xdqI2NY2nZnUoVsAp1YK3T8bFhfP8Pf9+2s0dOj5W7lySAFfLrWoQ272AN87Vu2 K2QT4vycS59Jg1ZQ9/Y3v02YZqURyto= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077495; h=from:from:reply-to: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=OApujg6O6m3Dquv+V7qQF2oVVDehESoVxw0de8YzCaA=; b=uOSfBirXA/umEQ0h7VUYleCC2veSMGTzREfYOZOHNXFtE1swuWfgmQvw0Mewb6qfkmOmt+ WDG3GArB6TaJz6Bg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" , Manos Pitsidianakis Subject: [PATCH v2 3/8] migration: Remove redundant flags Date: Tue, 18 Aug 2026 15:24:36 -0300 Message-ID: <20260818182441.404790-4-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.986]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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=lists1p.gnu.org; Received-SPF: pass client-ip=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077556355158500 Content-Type: text/plain; charset="utf-8" Remove the VMS_VARRAY and VMS_VBUFFER flags that became redundant due to the previous commit which stores the size of the vmstate offset variables along with the offset itself. Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- include/migration/vmstate.h | 74 +++++++++++------------------- migration/savevm.c | 6 +-- migration/vmstate.c | 3 +- rust/bindings/migration-sys/lib.rs | 7 +-- rust/migration/src/vmstate.rs | 6 +-- rust/tests/tests/vmstate_tests.rs | 4 +- 6 files changed, 37 insertions(+), 63 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 12bfa64fb92..a168651a062 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -69,8 +69,9 @@ enum VMStateFlags { * }). Dereference the pointer before using it as basis for * further pointer arithmetic (see e.g. VMS_ARRAY). Does not * affect the meaning of VMStateField.num_indirect or - * VMStateField.size_indirect; see VMS_VARRAY* and VMS_VBUFFER for - * those. */ + * VMStateField.size_indirect; see VMS_VARRAY and VMS_VBUFFER for + * those. + */ VMS_POINTER =3D 0x002, =20 /* The field is an array of fixed size. VMStateField.num contains @@ -80,12 +81,13 @@ enum VMStateFlags { * VMS_MULTIPLY. Each array entry will be processed individually * (VMStateField.info.get()/put() if VMS_STRUCT is not set, * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not - * be combined with VMS_VARRAY*. */ + * be combined with VMS_VARRAY. + */ VMS_ARRAY =3D 0x004, =20 /* The field is itself a struct, containing one or more * fields. Recurse into VMStateField.vmsd. Most useful in - * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each + * combination with VMS_ARRAY / VMS_VARRAY, recursing into each * array entry. */ VMS_STRUCT =3D 0x008, =20 @@ -93,9 +95,9 @@ enum VMStateFlags { * The field is an array of variable size. The integer at opaque + * VMStateField.num_indirect contains the number of entries in the * array. See the VMS_ARRAY description regarding array handling - * in general. May not be combined with VMS_ARRAY or any other - * VMS_VARRAY*. */ - VMS_VARRAY_INT32 =3D 0x010, + * in general. May not be combined with VMS_ARRAY. + */ + VMS_VARRAY =3D 0x010, =20 /* Ignored */ VMS_BUFFER =3D 0x020, @@ -103,18 +105,12 @@ enum VMStateFlags { /* The field is a (fixed-size or variable-size) array of pointers * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry * before using it. Note: Does not imply any one of VMS_ARRAY / - * VMS_VARRAY*; these need to be set explicitly. */ + * VMS_VARRAY; these need to be set explicitly. + */ VMS_ARRAY_OF_POINTER =3D 0x040, =20 - /* The field is an array of variable size. The uint16_t at opaque - * + VMStateField.num_indirect - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT16 =3D 0x080, - /* The size of the individual entries (a single array entry if - * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if + * VMS_ARRAY or VMS_VARRAY are set, or the field itself if * neither is set) is variable (i.e. not known at compile-time), * but the same for all entries. Use the integer at opaque + * VMStateField.size_indirect (subject to VMS_MULTIPLY) to determine @@ -128,20 +124,6 @@ enum VMStateFlags { * allocated. Only valid in combination with VMS_VBUFFER. */ VMS_MULTIPLY =3D 0x200, =20 - /* The field is an array of variable size. The uint8_t at opaque + - * VMStateField.num_indirect - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT8 =3D 0x400, - - /* The field is an array of variable size. The uint32_t at opaque - * + VMStateField.num_indirect - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT32 =3D 0x800, - /* Fail loading the serialised VM state if this field is missing * from the input. */ VMS_MUST_EXIST =3D 0x1000, @@ -530,7 +512,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_INT32|VMS_POINTER, \ + .flags =3D VMS_VARRAY | VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -540,7 +522,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT32|VMS_POINTER, \ + .flags =3D VMS_VARRAY | VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -550,7 +532,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_INT32 | VMS_POINTER | VMS_ALLOC, \ + .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -560,7 +542,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT32|VMS_POINTER|VMS_ALLOC, \ + .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -570,7 +552,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT16 | VMS_POINTER | VMS_ALLOC, \ + .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -580,7 +562,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .info =3D &(_info), \ .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY_UINT16, \ + .flags =3D VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 @@ -659,7 +641,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_POINTER | VMS_VARRAY_UINT8 | \ + .flags =3D VMS_POINTER | VMS_VARRAY | \ VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ @@ -672,7 +654,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_POINTER | VMS_VARRAY_UINT32 | \ + .flags =3D VMS_POINTER | VMS_VARRAY | \ VMS_ARRAY_OF_POINTER | VMS_STRUCT | \ VMS_ARRAY_OF_POINTER_AUTO_ALLOC, \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ @@ -683,7 +665,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), = \ .num_indirect =3D vmstate_field_offset(_state, _field_num), = \ .info =3D &(_info), = \ - .flags =3D VMS_VARRAY_UINT32 | VMS_ARRAY_OF_POINTER | VMS_POINTER= , \ + .flags =3D VMS_VARRAY | VMS_ARRAY_OF_POINTER | VMS_POINTER, = \ .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ } =20 @@ -727,7 +709,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_UINT8, \ + .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 @@ -750,7 +732,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ + .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -760,7 +742,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ + .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -770,7 +752,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT, \ + .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -780,7 +762,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_UINT32, \ + .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 @@ -790,7 +772,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .vmsd =3D &(_vmsd), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .size =3D sizeof(_type), \ - .flags =3D VMS_STRUCT|VMS_VARRAY_INT32|VMS_ALLOC|VMS_POINTER, \ + .flags =3D VMS_STRUCT | VMS_VARRAY | VMS_ALLOC | VMS_POINTER, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 @@ -915,7 +897,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .version_id =3D (_version), \ .size =3D (_size), \ .info =3D &vmstate_info_unused_buffer, \ - .flags =3D VMS_VARRAY_UINT32 | VMS_BUFFER, \ + .flags =3D VMS_VARRAY | VMS_BUFFER, \ } =20 /* _field_size should be a int32_t field in the _state struct giving the diff --git a/migration/savevm.c b/migration/savevm.c index e1b707dda63..3e5cce6520d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -884,11 +884,9 @@ static void vmstate_check(const VMStateDescription *vm= sd) } /* * VMS_ARRAY_OF_POINTER must be used only together with one - * of VMS_(V)ARRAY* flags. + * of VMS_(V)ARRAY flags. */ - assert(field->flags & (VMS_ARRAY | VMS_VARRAY_INT32 | - VMS_VARRAY_UINT16 | VMS_VARRAY_UINT= 8 | - VMS_VARRAY_UINT32)); + assert(field->flags & (VMS_ARRAY | VMS_VARRAY)); } =20 if (field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC) { diff --git a/migration/vmstate.c b/migration/vmstate.c index 372aed258f1..bc5285bcea2 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -101,8 +101,7 @@ static uint64_t vmstate_n_elems(void *opaque, const VMS= tateField *field) =20 if (field->flags & VMS_ARRAY) { n_elems =3D field->num; - } else if (field->flags & (VMS_VARRAY_INT32 | VMS_VARRAY_UINT32 - | VMS_VARRAY_UINT16 | VMS_VARRAY_UINT8)) { + } else if (field->flags & VMS_VARRAY) { n_elems =3D vmstate_read_from_offset(&field->num_indirect, opaque); } =20 diff --git a/rust/bindings/migration-sys/lib.rs b/rust/bindings/migration-s= ys/lib.rs index baa2730ca9d..c8397dc8974 100644 --- a/rust/bindings/migration-sys/lib.rs +++ b/rust/bindings/migration-sys/lib.rs @@ -57,12 +57,7 @@ pub trait VMStateFlagsExt { } =20 impl VMStateFlagsExt for VMStateFlags { - const VMS_VARRAY_FLAGS: VMStateFlags =3D VMStateFlags( - VMStateFlags::VMS_VARRAY_INT32.0 - | VMStateFlags::VMS_VARRAY_UINT8.0 - | VMStateFlags::VMS_VARRAY_UINT16.0 - | VMStateFlags::VMS_VARRAY_UINT32.0, - ); + const VMS_VARRAY_FLAGS: VMStateFlags =3D VMStateFlags(VMStateFlags::VM= S_VARRAY.0); } =20 // Add a couple builder-style methods to VMStateField, allowing diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index e60c0860cc5..4ec54097148 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -287,9 +287,9 @@ unsafe impl $crate::vmstate::VMState for $type { impl_vmstate_scalar!(vmstate_info_int16, i16); impl_vmstate_scalar!(vmstate_info_int32, i32); impl_vmstate_scalar!(vmstate_info_int64, i64); -impl_vmstate_scalar!(vmstate_info_uint8, u8, VMS_VARRAY_UINT8); -impl_vmstate_scalar!(vmstate_info_uint16, u16, VMS_VARRAY_UINT16); -impl_vmstate_scalar!(vmstate_info_uint32, u32, VMS_VARRAY_UINT32); +impl_vmstate_scalar!(vmstate_info_uint8, u8, VMS_VARRAY); +impl_vmstate_scalar!(vmstate_info_uint16, u16, VMS_VARRAY); +impl_vmstate_scalar!(vmstate_info_uint32, u32, VMS_VARRAY); impl_vmstate_scalar!(vmstate_info_uint64, u64); impl_vmstate_scalar!(vmstate_info_timer, util::timer::Timer); =20 diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_t= ests.rs index c002ffb2bc4..5f6dd8ae7f1 100644 --- a/rust/tests/tests/vmstate_tests.rs +++ b/rust/tests/tests/vmstate_tests.rs @@ -113,7 +113,7 @@ fn test_vmstate_varray_uint16_unsafe() { assert_eq!(foo_fields[2].version_id, 0); assert_eq!(foo_fields[2].size, 1); assert_eq!(foo_fields[2].num, 0); - assert_eq!(foo_fields[2].flags, VMStateFlags::VMS_VARRAY_UINT16); + assert_eq!(foo_fields[2].flags, VMStateFlags::VMS_VARRAY); assert!(foo_fields[2].vmsd.is_null()); assert!(foo_fields[2].field_exists.is_none()); } @@ -222,7 +222,7 @@ fn test_vmstate_struct_varray_uint8() { assert_eq!(foo_fields[2].num, 0); assert_eq!( foo_fields[2].flags.0, - VMStateFlags::VMS_STRUCT.0 | VMStateFlags::VMS_VARRAY_UINT8.0 + VMStateFlags::VMS_STRUCT.0 | VMStateFlags::VMS_VARRAY.0 ); assert_eq!(foo_fields[2].vmsd, VMSTATE_FOOA.as_ref()); assert!(foo_fields[2].field_exists.is_none()); --=20 2.53.0 From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077593; cv=none; d=zohomail.com; s=zohoarc; b=ntvdyyKhPgJ2G0APtF4uglpSvPLSRIBnG0PLtQgh26utRIWNDAq4g8CthKaKCfdn+x2FQwSKpaRJ7nY3+UTkeFWEiiC7iHJ/O3psAsBAhUXTym22otfq5pe9nbjz+TZoLLbus9m2iPiBeKi/7mu/R2++2yL0+JI69l2tjYlghfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077593; 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=0sHt0NatwhLlnSWyxTBxDTi3HoA48Mx9LVOofzGh7Cc=; b=D2WpochgW6D1nFsrf8SopSsUG3HeGGeedTDlsjJI/SHt8qzkgUJaAFMrZkDEc25bIkXeg+T9fxbP/vAa8ZEBKBSGbJ3vqE9ZwajFZ2qSCxcfByWneeg9F5FYuJySnmI4PHLv+UrOV9Cpg/dmAu4KSOSLCFs4QNe5IEcHjNcSjSM= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787077593503210.90045610844209; Tue, 18 Aug 2026 11:26:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUs-00087b-O5; Tue, 18 Aug 2026 14:25:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUp-00083e-0n for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:11 -0400 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUm-0003B2-IB for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:10 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2807B846BB; Tue, 18 Aug 2026 18:24:57 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C900C367A; Tue, 18 Aug 2026 18:24:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id KNUiJnejhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:24:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077501; h=from:from:reply-to: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=0sHt0NatwhLlnSWyxTBxDTi3HoA48Mx9LVOofzGh7Cc=; b=pd7UsquuaxrLN9liqaNj2UCmpDrV3UFjNMNlc03IfsN5GmY95TSHyLRZmkdqYGJszAJ/fc ponQovPOdujN8ynZslOPTEhfRp/XlLmUqBT0Adl7uP0Kkg1K4zaGGCaOof7bXkxHE+GIpJ Ba1b/K6gcX2mlBw1bYutqKKwYkTGnGg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077501; h=from:from:reply-to: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=0sHt0NatwhLlnSWyxTBxDTi3HoA48Mx9LVOofzGh7Cc=; b=4rsGO8v3y5rpy8CKn8kGUCFT/XDg7zxNYnb72VOywyhQQR/pICMsUttR7UoGH31gg3xZKI 460aTRpSKUt/YnDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hVsJItC2; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qLRoC1pe DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077497; h=from:from:reply-to: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=0sHt0NatwhLlnSWyxTBxDTi3HoA48Mx9LVOofzGh7Cc=; b=hVsJItC2Au8BScLRXswzt4hZU20T/8MV0crr9D71fnY3Tv+YmLhAdYT+EGAquIxTjFVDIE aouAHPpEnQG43HgMbenjq7yREdKC8xlPizkEoAXf7A8gwJ2Rd1car7IoYn5xmSTd8Kvt45 ojniThb23f8wcxfDatcutoksRRbrKTk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077497; h=from:from:reply-to: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=0sHt0NatwhLlnSWyxTBxDTi3HoA48Mx9LVOofzGh7Cc=; b=qLRoC1pe3a2Ea7TdyTVbqSEAMGLuRXzE7khwnG9KkkulzgAHW3IspsPVHjoW647IlYDEkT Okd2iyf3EvQstJAA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" Subject: [PATCH v2 4/8] migration: Remove duplicate vmstate macros Date: Tue, 18 Aug 2026 15:24:37 -0300 Message-ID: <20260818182441.404790-5-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: 2807B846BB X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:mid,suse.de:email,suse.de:dkim]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077594434158500 Content-Type: text/plain; charset="utf-8" Now that type-checking is not being done per integer size anymore, various macros have duplicated bodies. Remove them. The original names are left the same so the device code can be altered per-subsystem in the next patches. Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- include/migration/vmstate.h | 135 ++++++++++++------------------------ 1 file changed, 44 insertions(+), 91 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index a168651a062..4b6d52955ff 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -506,7 +506,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_sub_array(_state, _field, _type, _start= ), \ } =20 -#define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, = _type) {\ +#define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type)= {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -516,17 +516,11 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 -#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info,= _type) {\ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY | VMS_POINTER, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} +#define VMSTATE_VARRAY_INT32 VMSTATE_VARRAY +#define VMSTATE_VARRAY_UINT32 VMSTATE_VARRAY =20 -#define VMSTATE_VARRAY_INT32_ALLOC(_field, _state, _field_num, _version, _= info, _type) {\ +#define VMSTATE_VARRAY_ALLOC(_field, _state, _field_num, _version, _info, \ + _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -536,27 +530,12 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 -#define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} - -#define VMSTATE_VARRAY_UINT16_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .info =3D &(_info), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_VARRAY | VMS_POINTER | VMS_ALLOC, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} +#define VMSTATE_VARRAY_INT32_ALLOC VMSTATE_VARRAY_ALLOC +#define VMSTATE_VARRAY_UINT32_ALLOC VMSTATE_VARRAY_ALLOC +#define VMSTATE_VARRAY_UINT16_ALLOC VMSTATE_VARRAY_ALLOC =20 -#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version,= _info, _type) {\ +#define VMSTATE_VARRAY_UNSAFE(_field, _state, _field_num, _version, _info,= \ + _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -566,6 +545,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_varray(_state, _field, _type), \ } =20 +#define VMSTATE_VARRAY_UINT16_UNSAFE VMSTATE_VARRAY_UNSAFE + #define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type= , _struct_version) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -634,7 +615,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; * _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(\ +#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC( \ _field, _state, _field_num, _version, _vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -647,20 +628,13 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type *), \ } =20 -#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_indirect =3D vmstate_field_offset(_state, _field_num), \ - .vmsd =3D &(_vmsd), \ - .size =3D sizeof(_type), \ - .flags =3D VMS_POINTER | VMS_VARRAY | \ - 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_UINT8_ALLOC \ + VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC +#define VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_UINT32_ALLOC \ + VMSTATE_VARRAY_OF_POINTER_TO_STRUCT_ALLOC =20 -#define VMSTATE_VARRAY_OF_POINTER_UINT32(_field, _state, _field_num, _vers= ion, _info, _type) { \ +#define VMSTATE_VARRAY_OF_POINTER(_field, _state, _field_num, _version, _i= nfo, \ + _type) { \ .name =3D (stringify(_field)), = \ .version_id =3D (_version), = \ .num_indirect =3D vmstate_field_offset(_state, _field_num), = \ @@ -669,6 +643,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D vmstate_offset_pointer(_state, _field, _type *), = \ } =20 +#define VMSTATE_VARRAY_OF_POINTER_UINT32 VMSTATE_VARRAY_OF_POINTER + #define VMSTATE_STRUCT_SUB_ARRAY(_field, _state, _start, _num, _version, _= vmsd, _type) { \ .name =3D (stringify(_field)), = \ .version_id =3D (_version), = \ @@ -703,7 +679,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; _n1, _n2), \ } =20 -#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, = _vmsd, _type) { \ +#define VMSTATE_STRUCT_VARRAY(_field, _state, _field_num, _version, _vmsd,= \ + _type) { \ .name =3D (stringify(_field)), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ @@ -712,6 +689,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_UINT8 VMSTATE_STRUCT_VARRAY =20 /* a variable length array (i.e. _type *_field) but we know the * length @@ -726,7 +704,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D offsetof(_state, _field), \ } =20 -#define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _v= msd, _type) { \ +#define VMSTATE_STRUCT_VARRAY_POINTER(_field, _state, _field_num, _vmsd, \ + _type) { \ .name =3D (stringify(_field)), \ .version_id =3D 0, \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -735,28 +714,12 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ .offset =3D vmstate_offset_pointer(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_POINTER_INT32 VMSTATE_STRUCT_VARRAY_POINTER +#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32 VMSTATE_STRUCT_VARRAY_POINTER +#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16 VMSTATE_STRUCT_VARRAY_POINTER =20 -#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _= vmsd, _type) { \ - .name =3D (stringify(_field)), \ - .version_id =3D 0, \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .size =3D sizeof(_type), \ - .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} - -#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _= vmsd, _type) { \ - .name =3D (stringify(_field)), \ - .version_id =3D 0, \ - .num_indirect =3D vmstate_field_offset(_state, _field_num), \ - .size =3D sizeof(_type), \ - .vmsd =3D &(_vmsd), \ - .flags =3D VMS_POINTER | VMS_VARRAY | VMS_STRUCT, \ - .offset =3D vmstate_offset_pointer(_state, _field, _type), \ -} - -#define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version,= _vmsd, _type) { \ +#define VMSTATE_STRUCT_VARRAY(_field, _state, _field_num, _version, _vmsd,= \ + _type) { \ .name =3D (stringify(_field)), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ .version_id =3D (_version), \ @@ -765,8 +728,11 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_STRUCT | VMS_VARRAY, \ .offset =3D vmstate_offset_varray(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_INT32 VMSTATE_STRUCT_VARRAY +#define VMSTATE_STRUCT_VARRAY_UINT32 VMSTATE_STRUCT_VARRAY =20 -#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, = _vmsd, _type) {\ +#define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, \ + _vmsd, _type) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .vmsd =3D &(_vmsd), \ @@ -808,28 +774,11 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D offsetof(_state, _field), \ } =20 -#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_siz= e) { \ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .field_exists =3D (_test), \ - .size_indirect =3D vmstate_field_offset(_state, _field_size), \ - .info =3D &vmstate_info_buffer, \ - .flags =3D VMS_VBUFFER|VMS_POINTER, \ - .offset =3D offsetof(_state, _field), \ -} +#define VMSTATE_VBUFFER_UINT32 VMSTATE_VBUFFER +#define VMSTATE_VBUFFER_UINT64 VMSTATE_VBUFFER =20 -#define VMSTATE_VBUFFER_UINT64(_field, _state, _version, _test, _field_siz= e) { \ - .name =3D (stringify(_field)), \ - .version_id =3D (_version), \ - .field_exists =3D (_test), \ - .size_indirect =3D vmstate_field_offset(_state, _field_size), \ - .info =3D &vmstate_info_buffer, \ - .flags =3D VMS_VBUFFER | VMS_POINTER, \ - .offset =3D offsetof(_state, _field), \ -} - -#define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \ - _test, _field_size) { \ +#define VMSTATE_VBUFFER_ALLOC(_field, _state, _version, \ + _test, _field_size) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ @@ -839,6 +788,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .offset =3D offsetof(_state, _field), \ } =20 +#define VMSTATE_VBUFFER_ALLOC_UINT32 VMSTATE_VBUFFER_ALLOC + #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _= info, _size) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ @@ -890,7 +841,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; } =20 /* Discard size * field_num bytes, where field_num is a uint32 member */ -#define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, = _size) {\ +#define VMSTATE_UNUSED_VARRAY(_state, _test, _version, _field_num, _size) = {\ .name =3D "unused", \ .field_exists =3D (_test), \ .num_indirect =3D vmstate_field_offset(_state, _field_num), \ @@ -900,6 +851,8 @@ extern const VMStateInfo vmstate_info_g_byte_array; .flags =3D VMS_VARRAY | VMS_BUFFER, \ } =20 +#define VMSTATE_UNUSED_VARRAY_UINT32 VMSTATE_UNUSED_VARRAY + /* _field_size should be a int32_t field in the _state struct giving the * size of the bitmap _field in bits. */ --=20 2.53.0 From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077565; cv=none; d=zohomail.com; s=zohoarc; b=BKrDk6NkzmI98lREMoC+MGBviB7nY8UAqIMeC43Zb670vsN21ciN4Y/9IWhDQLaco8l1w3Igd0wr+QikqeZJTVxmz3jbZuk6rhb9QRrZ+qbPqyP+616KX8r/3S5sLVbJk39fwhToY0nBDMKapqOTpyVYuL7BVtwI9dxgJCfY64o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077565; 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=bhZ0Jaa2LTaWO+2UdkFJyZ/kFzMlnQ9CTe18Ey4xy/A=; b=Sc57xiP4P7j4s3nqcl6fsFccxnfjGXcoBEv9cP1X+U2bMLLhxf51SZfsYTMp9rgqr3F7nkvpifYzm7G14aDUPDhO9YfpuyTU/9RvihuoTOfgKt1IAPy/ELyRgWdKpwYdU1Uq4se0pnwXcW4Ql62vdPdOn1550PZczFHFHti9o9I= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787077565927509.8559866530321; Tue, 18 Aug 2026 11:26:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUt-00087e-6h; Tue, 18 Aug 2026 14:25:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUp-00083p-Lz for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:11 -0400 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUm-0003Bv-Rr for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:11 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 69704846C1; Tue, 18 Aug 2026 18:24:59 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8BA6A367B; Tue, 18 Aug 2026 18:24:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IDQhF3mjhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:24:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077503; h=from:from:reply-to: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=bhZ0Jaa2LTaWO+2UdkFJyZ/kFzMlnQ9CTe18Ey4xy/A=; b=woA9YSiISCKjedoHYgAg8IWEem66a/kgIAs2PCEOP7sKrCO3s1ZEQ5ZhIToWUEgXKvp0e/ OOdOJ3py7FVIhE5Q4URgtST9PcA1pqdLPo+r1JvGpvjkZOcNE5RO+Ofxj/6gvkrogZ9/xV 7njbvh/v7s9OyQy0rfUhfPYqNvM7vCI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077503; h=from:from:reply-to: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=bhZ0Jaa2LTaWO+2UdkFJyZ/kFzMlnQ9CTe18Ey4xy/A=; b=lBUU8hTWz4b0e2jwhqTtqnEHbX/kwaoWVx5vvYRduF+vzCNEr9e7tBBWb+/jyqmkJcnd9Z O2d6xfteNHj3gbAg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vEn97KIv; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Utw71iRd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077499; h=from:from:reply-to: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=bhZ0Jaa2LTaWO+2UdkFJyZ/kFzMlnQ9CTe18Ey4xy/A=; b=vEn97KIvYEeQuhDv0Y9Yf8mXpr65CqDCdYP4kiSM3fDBMQdFbTYv2H95Q5ueaLosMV2lxz ma0sqaMkqY5CnMPwTFJKxSoOMnzA8z9nnNYlByfu02kErEKZWd6R2//MWkJbhUahJKpPlP YeOKVJT3iix0Jocctrv3LoSKIgmwaHA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077499; h=from:from:reply-to: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=bhZ0Jaa2LTaWO+2UdkFJyZ/kFzMlnQ9CTe18Ey4xy/A=; b=Utw71iRdz4o5E/GaF6TEPoy0VQc0drkMOT7bW30URc5p3WW1A2nWgnJFPFz+oJ+dAgV5r5 msOa+VtSbT78yXCw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" , Paolo Bonzini , Fam Zheng , Manos Pitsidianakis Subject: [PATCH v2 5/8] migration: Add VMS_NO_STATE flag Date: Tue, 18 Aug 2026 15:24:38 -0300 Message-ID: <20260818182441.404790-6-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid,suse.de:dkim]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_SEVEN(0.00)[8]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -3.01 X-Rspamd-Queue-Id: 69704846C1 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077568295158500 Content-Type: text/plain; charset="utf-8" There are a few special cases of vmstate usage: The vmstate_msix and vmstate_scsi_device have fields that contain no data, only a vmstate_info structure. The VMSTATE_VALIDATE macro serves only to invoke the .field_exists routine for validation. Regardless whether these scenarios are valid, add a separate flag to identify them so we can enforce common constraints for the normal vmstates such as having a size greater than zero. Note that n_elems is hardcoded to 1 for all vmstates, except VMS_[V]ARRAY, so VMSTATE_VALIDATE needed to set VMS_ARRAY to be able to force n_elems to 0. This patch now checks the flag at vmstate_n_elems(). Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- hw/pci/msix.c | 6 +----- hw/scsi/scsi-bus.c | 6 +----- include/migration/vmstate.h | 9 +++++++-- migration/vmstate.c | 6 +++++- rust/migration/src/vmstate.rs | 2 +- rust/tests/tests/vmstate_tests.rs | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 1b23eaf1007..adf76b5bccc 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -711,12 +711,8 @@ const VMStateDescription vmstate_msix =3D { .fields =3D (const VMStateField[]) { { .name =3D "msix", - .version_id =3D 0, - .field_exists =3D NULL, - .size =3D 0, /* ouch */ .info =3D &vmstate_info_msix, - .flags =3D VMS_SINGLE, - .offset =3D 0, + .flags =3D VMS_SINGLE | VMS_NO_STATE, }, VMSTATE_END_OF_LIST() } diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index deb43d5560e..aa02ff631b7 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1980,12 +1980,8 @@ const VMStateDescription vmstate_scsi_device =3D { VMSTATE_UINT32(sense_len, SCSIDevice), { .name =3D "requests", - .version_id =3D 0, - .field_exists =3D NULL, - .size =3D 0, /* ouch */ .info =3D &vmstate_info_scsi_requests, - .flags =3D VMS_SINGLE, - .offset =3D 0, + .flags =3D VMS_SINGLE | VMS_NO_STATE, }, VMSTATE_END_OF_LIST() }, diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 4b6d52955ff..e72c3fae9a6 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -109,6 +109,12 @@ enum VMStateFlags { */ VMS_ARRAY_OF_POINTER =3D 0x040, =20 + /* + * The field contains no data. Used for special cases such as + * invoking a custom VMStateInfo. + */ + VMS_NO_STATE =3D 0x080, + /* The size of the individual entries (a single array entry if * VMS_ARRAY or VMS_VARRAY are set, or the field itself if * neither is set) is variable (i.e. not known at compile-time), @@ -454,8 +460,7 @@ extern const VMStateInfo vmstate_info_g_byte_array; #define VMSTATE_VALIDATE(_name, _test) { \ .name =3D (_name), \ .field_exists =3D (_test), \ - .flags =3D VMS_ARRAY | VMS_MUST_EXIST, \ - .num =3D 0, /* 0 elements: no data, only run _test */ \ + .flags =3D VMS_MUST_EXIST | VMS_NO_STATE, \ } =20 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ diff --git a/migration/vmstate.c b/migration/vmstate.c index bc5285bcea2..51d02b87e7e 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -97,12 +97,16 @@ static uint64_t vmstate_read_from_offset(const VMStateS= tructMember *member, =20 static uint64_t vmstate_n_elems(void *opaque, const VMStateField *field) { - uint64_t n_elems =3D 1; + uint64_t n_elems; =20 if (field->flags & VMS_ARRAY) { n_elems =3D field->num; } else if (field->flags & VMS_VARRAY) { n_elems =3D vmstate_read_from_offset(&field->num_indirect, opaque); + } else if (field->flags & VMS_MUST_EXIST && field->flags & VMS_NO_STAT= E) { + n_elems =3D 0; + } else { + n_elems =3D 1; } =20 trace_vmstate_n_elems(field->name, n_elems); diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index 4ec54097148..a3a710ab3ac 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -418,7 +418,7 @@ macro_rules! vmstate_validate { field_exists: $crate::vmstate_exist_fn!($struct_name, $test_fn= ), flags: $crate::bindings::VMStateFlags( $crate::bindings::VMStateFlags::VMS_MUST_EXIST.0 - | $crate::bindings::VMStateFlags::VMS_ARRAY.0, + | $crate::bindings::VMStateFlags::VMS_NO_STATE.0, ), num: 0, // 0 elements: no data, only run test_fn callback ..::common::zeroable::Zeroable::ZERO diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_t= ests.rs index 5f6dd8ae7f1..6578d54b37d 100644 --- a/rust/tests/tests/vmstate_tests.rs +++ b/rust/tests/tests/vmstate_tests.rs @@ -461,7 +461,7 @@ fn test_vmstate_validate() { assert_eq!(foo_fields[0].num, 0); assert_eq!( foo_fields[0].flags.0, - VMStateFlags::VMS_ARRAY.0 | VMStateFlags::VMS_MUST_EXIST.0 + VMStateFlags::VMS_NO_STATE.0 | VMStateFlags::VMS_MUST_EXIST.0 ); assert!(foo_fields[0].vmsd.is_null()); assert!(unsafe { foo_fields[0].field_exists.unwrap()(foo_d_p, 0) }); --=20 2.53.0 From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077566; cv=none; d=zohomail.com; s=zohoarc; b=Jz4kGSrGolAAOagxZzWlYobdwnZcMAsFebRE5pOdH4of2xu2I3ynvvImQafoiS3kfTROxmIG5Xi3/ztsl32h7/8Wab3aBOrf+IsQasSTSnG264UnamUarAtZ38l46qesS5cRj8zZY5qG/7raJK5nZCERJYT6U3GUCmDW5bJq50E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077566; 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=G2peLC6JzEpMik1srp1Ibgub0BcuGgBGnMWyYc7s5n4=; b=IteuuYGO7miilH3NpNIqdD19jR4mMuH+YgDjrqw11xnyV8W88tbrAJwskKZ2NU9dZIqtdyZkL2hq1lcYwkOcFaLqSdn1Lc5wgmTTd/CtMgnr69dSlUvfgk6fFRpv+f+r25hRYaWZwk9EiSjihastMD/HU38qvLNJNVP4TNH2Lso= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787077565987792.422910026931; Tue, 18 Aug 2026 11:26:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUr-00085H-FY; Tue, 18 Aug 2026 14:25:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUq-00084F-5P for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:12 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUo-0003CF-LI for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:11 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1F4C03E7D; Tue, 18 Aug 2026 18:25:01 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C7E41339C; Tue, 18 Aug 2026 18:24:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id CHPSJXujhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:24:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077505; h=from:from:reply-to: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=G2peLC6JzEpMik1srp1Ibgub0BcuGgBGnMWyYc7s5n4=; b=xvaLYsxm/sJ7BaVqNgzZAV6qWBt+VT98HrxxRbLhDNX7Y1AllI8GJreNPIVZ1IK8czT2Yx 7GNQJx85TkghJitSfpNGKqPPQAcPJx27zbJb/6zxXYyFigQsgtkj+LX4txeQSJW2sFVq4K JpQj5NC4Cn54ofN8C+XkPTemFvM0duw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077505; h=from:from:reply-to: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=G2peLC6JzEpMik1srp1Ibgub0BcuGgBGnMWyYc7s5n4=; b=Nlt/bEh7tUV/ha+u1LG3cxQT0wyW9PycSt0MtkMyGR8K1atafpkxOdog7yH2ZurjLhBmWg Qw8fQ8WdOMFKoBBQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=rqRCqEtk; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=zK1ulCrp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077501; h=from:from:reply-to: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=G2peLC6JzEpMik1srp1Ibgub0BcuGgBGnMWyYc7s5n4=; b=rqRCqEtkmg+f3boESKLQR/qLWRRKUF/HCZcj2js9O1AqZcevgfpGGboDX+ZamsHEbyq6L/ DWrg7oknSiQcsvLduLrSnxHCddIGmSH4EiwVcw7BajUDM1yHEckdI2HM3dDkW5qV8n+zzG ViYv3SapJKO5x8GKdOF0I5dowII9DDo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077501; h=from:from:reply-to: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=G2peLC6JzEpMik1srp1Ibgub0BcuGgBGnMWyYc7s5n4=; b=zK1ulCrprHK9y7VQRbXIY9kFVDOb3TRQKbU/IydRxaXqQsV4HZAKSCqcq3NnDM7dIxPQqO B+4qFb0euL6O1ACw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" Subject: [PATCH v2 6/8] migration: Check more vmstate flags Date: Tue, 18 Aug 2026 15:24:39 -0300 Message-ID: <20260818182441.404790-7-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: 1F4C03E7D X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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=lists1p.gnu.org; Received-SPF: pass client-ip=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077568114158501 Content-Type: text/plain; charset="utf-8" Add more checks for vmstate flags constraints. Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- migration/savevm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 3e5cce6520d..c44df365cc8 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -893,6 +893,25 @@ static void vmstate_check(const VMStateDescription *vm= sd) assert(field->flags & VMS_ARRAY_OF_POINTER); } =20 + /* + * The VMS*ARRAY flags and VMS_VBUFFER affect allocation, + * they must have the proper fields set and no other + * vmstate types can set those fields, otherwise it won't + * be picked-up due to the missing flag. + */ + + if (field->flags & (VMS_ARRAY | VMS_VARRAY)) { + assert(field->num > 0 || field->num_indirect.size !=3D 0); + } else { + assert(field->num =3D=3D 0 && field->num_indirect.size =3D= =3D 0); + } + + if (field->flags & VMS_VBUFFER) { + assert(field->size_indirect.size !=3D 0); + } else { + assert(field->size_indirect.size =3D=3D 0); + } + if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) { /* Recurse to sub structures */ vmstate_check(field->vmsd); --=20 2.53.0 From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077544; cv=none; d=zohomail.com; s=zohoarc; b=Znu1PGIUzjvvjTse4K7ChfCW4XFN0kPrs0vvIvc5lu2enTH9Nfpj+KzpIKXYsl/WsO1Yf3mhx2dRN2zTjBd2nb+UyGeyqXwE6No+tlgy9CnF6ZIPFkhDPLeeMOlcCFs+D0Ds7KsHv4SWYLBWnR8zZfjPQXDUexJi79nkwKmavUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077544; 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=9wD3CVIRX8903SHtXpBw3TNTneDODNtlzxFonZCIu80=; b=Gj0hsHY0PzcWM/SPxjr2funqYnQxtT/+lTLoxZhb2Ak+FuwbCOXMLqnMiscdGyiot0Td61wLsT0slQ6zakhosYDIYw1t6w3N2uKuepVg8vcRquJYUR76x/opmina1OndEJbI2TPE4dWTVwSy29xJPuseHaU8f40Vbsr2msro9vE= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787077544921376.9063292057333; Tue, 18 Aug 2026 11:25:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUt-000887-Us; Tue, 18 Aug 2026 14:25:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUr-00086e-W7 for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:14 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUq-0003Ca-EH for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:13 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C8E8A846C2; Tue, 18 Aug 2026 18:25:02 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7DBC7362E; Tue, 18 Aug 2026 18:25:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4CC0E32jhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:25:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077506; h=from:from:reply-to: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=9wD3CVIRX8903SHtXpBw3TNTneDODNtlzxFonZCIu80=; b=FXx800ruGgZu/cFcZOOhLU0eMXcZfzsyP5JuRUkOrMPkw0yIEIFpS6N64zHn+3vWWd9v8P 2dMMGHhdE3LSwzvRKO/rhHSddFmlgqMU9we+QwWGTZAl5GV3rk8vwedvTNAfDH5++2QzpI d6oCt2K3Csa+5zrr2QQJcX2YIn2lEZQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077506; h=from:from:reply-to: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=9wD3CVIRX8903SHtXpBw3TNTneDODNtlzxFonZCIu80=; b=d1v0CeEP+G1bYJa8PtTMN5+F2Tormggsiy/sZvJ/taiWLT1iSPjFqHXamSguVgb4CDGgcS wPZK6AA3sHjvgrBQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="sCInR/s8"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9T+rCui6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077502; h=from:from:reply-to: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=9wD3CVIRX8903SHtXpBw3TNTneDODNtlzxFonZCIu80=; b=sCInR/s8AN9mPEcLeV9fAcDAT7G35X3YzzhG9UQjcEcuAbUhvpWK3NXozamOnsEdkuWl7c t5tjvOdQFDlXgIYNXXUI7ihsYA5M/ljAilWLeWXXEiDo8Ck0nguMhcnYT6KAkcZBBOejTv C5D7AdznweDaYRvkwC7aydABUjx5bRw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077502; h=from:from:reply-to: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=9wD3CVIRX8903SHtXpBw3TNTneDODNtlzxFonZCIu80=; b=9T+rCui6/5SPhehcSLJ4CrQcU/VTmL+z4KLLf59The6huuWUP2q3zYygDNqO+VOus2zoaZ S6PgEmcWiESeKDAQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" Subject: [PATCH v2 7/8] migration: Harden vmstate_handle_alloc Date: Tue, 18 Aug 2026 15:24:40 -0300 Message-ID: <20260818182441.404790-8-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: C8E8A846C2 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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=lists1p.gnu.org; Received-SPF: pass client-ip=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077547126158500 Content-Type: text/plain; charset="utf-8" Harden the vmstate_handle_alloc function against overflow of the 64bit integers it consumes and failure to allocate due to an exceedingly large request. Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- migration/vmstate.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 51d02b87e7e..1d028bfe009 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -135,16 +135,28 @@ static uint64_t vmstate_size(void *opaque, const VMSt= ateField *field) return size; } =20 -static void vmstate_handle_alloc(void *ptr, const VMStateField *field, - void *opaque) +static bool vmstate_handle_alloc(void *ptr, const VMStateField *field, + uint64_t n, uint64_t size, Error **errp) { + void *p; + if (field->flags & VMS_POINTER && field->flags & VMS_ALLOC) { - uint64_t size =3D vmstate_size(opaque, field); - size *=3D vmstate_n_elems(opaque, field); - if (size) { - *(void **)ptr =3D g_malloc(size); - } + if (size && n) { + if (umul64_overflow(size, n, &size)) { + error_setg(errp, "%s: field '%s' multiply overflow", + __func__, field->name); + return false; + } + p =3D g_try_malloc(size); + if (!p) { + error_setg(errp, "%s: Could not allocate memory for field = '%s'", + __func__, field->name); + return false; + } + *(void **)ptr =3D p; + } } + return true; } =20 static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field, @@ -354,7 +366,9 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescri= ption *vmsd, uint64_t n_elems =3D vmstate_n_elems(opaque, field); uint64_t size =3D vmstate_size(opaque, field); =20 - vmstate_handle_alloc(first_elem, field, opaque); + if (!vmstate_handle_alloc(first_elem, field, n_elems, size, er= rp)) { + return false; + } if (field->flags & VMS_POINTER) { first_elem =3D *(void **)first_elem; assert(first_elem || !n_elems || !size); --=20 2.53.0 From nobody Sat Sep 26 23:03: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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1787077566; cv=none; d=zohomail.com; s=zohoarc; b=l/YTgzN+0es0cn0sm+Pgf9F+CV7+GEzttHavciGm5QfkY7PYiw5TDxnoE/5PuNP+fd/qa0mu1NsSHsWST9UvhmWzZLLZ9zzORFfsk1tlSk3VT073UQTHHVuLpCRxSHMkqEUjC3uKQplgvXuSMs6Psq+iVEBkAz+6yBaw2SVMH90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787077566; 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=SX866xtZPR2zRAuCpGL4s+/Ehk+85xy98jnqPxXOvz0=; b=X7CQ+lQMCfHAUFLhb1tdJnkmD4tFo3FX7Vvvra9NphXe4a4ZbDBW2q96kYoBT0AMjuy6a3lquJWLh3Mxb4v9e+MMg000yTM3F+Z3CtrEYSXVXtNIpPRwXHJDD1C23Uo/brR9k6lWwFQjGw4gI47Vr3qjiUMxol9udGKA3tJe2sQ= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787077566461460.66581509979187; Tue, 18 Aug 2026 11:26:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwOUv-00089r-B5; Tue, 18 Aug 2026 14:25:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwOUt-00087r-Mr for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:15 -0400 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wwOUr-0003D8-VU for qemu-devel@nongnu.org; Tue, 18 Aug 2026 14:25:15 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7F004846B9; Tue, 18 Aug 2026 18:25:04 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3342A22BA; Tue, 18 Aug 2026 18:25:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id CG+HAX+jhGpYYQAAD6G6ig (envelope-from ); Tue, 18 Aug 2026 18:25:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077508; h=from:from:reply-to: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=SX866xtZPR2zRAuCpGL4s+/Ehk+85xy98jnqPxXOvz0=; b=CpN1+FYL5ScQ3VZQB3t623R2rCA68QBM630lLC1XQpS4g91LWkz5XdAscRXuiDb6dyWGgN Nb2mg/7mo3amiS7cyiM4tx86t5SGl0uvsVRkjnG+EjtXacaQVGYqmk4UfMi/BM8GwoFiHG qWr6U2EeTGxm0R5JL9AtiulmuKl35EA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077508; h=from:from:reply-to: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=SX866xtZPR2zRAuCpGL4s+/Ehk+85xy98jnqPxXOvz0=; b=GSdL8i0wrVcpE+fRynU+hgbEjA+YdyYU5pGa+QdxyP/uaq87U8W4iNB2pH4UWGPa+cSRQF KaMzmlaIKcW2AMCg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Iitygxvd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=9DZmdN9s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787077504; h=from:from:reply-to: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=SX866xtZPR2zRAuCpGL4s+/Ehk+85xy98jnqPxXOvz0=; b=IitygxvdYHeeEC9pu/u6fEAG1ojQqH7JFkL49JSQUn1/rBvGUziwAQU5kNxJAxJrUw0I++ fCqMi+dX9c7K2x9sy1NSpo0L8HXhQyPFI1HeM1r1yrkfPxQjBDHJ9P9AXFMJgEGYTi194g EWsm9oE4v0/o3FZhpKEiDv0EYFPf+QM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787077504; h=from:from:reply-to: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=SX866xtZPR2zRAuCpGL4s+/Ehk+85xy98jnqPxXOvz0=; b=9DZmdN9s9pJae8Ww7LZySVnnqfIEOF7Dd0Ntdm8irBvab6BSoKodsvWs0vPeUBOxJImYRM VxvDUREpRGNoYxBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Vladimir Sementsov-Ogievskiy , Alexandr Moshkov , "Michael S . Tsirkin" Subject: [PATCH v2 8/8] migration: Harden vmstate_size Date: Tue, 18 Aug 2026 15:24:41 -0300 Message-ID: <20260818182441.404790-9-farosas@suse.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260818182441.404790-1-farosas@suse.de> References: <20260818182441.404790-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,suse.de:dkim,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -3.01 X-Rspamd-Queue-Id: 7F004846B9 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1787077568167158500 Content-Type: text/plain; charset="utf-8" Protect vmstate_size against overflow of the on-stack 64bit integer during multiplication. The data at size_indirect.offset comes from the migration stream. Signed-off-by: Fabiano Rosas Acked-by: Peter Xu --- migration/vmstate.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 1d028bfe009..08548ae7a1f 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -113,14 +113,20 @@ static uint64_t vmstate_n_elems(void *opaque, const V= MStateField *field) return n_elems; } =20 -static uint64_t vmstate_size(void *opaque, const VMStateField *field) +static bool vmstate_size(void *opaque, const VMStateField *field, + uint64_t *sz, Error **errp) { uint64_t size; =20 + *sz =3D 0; + if (field->flags & VMS_VBUFFER) { size =3D vmstate_read_from_offset(&field->size_indirect, opaque); - if (field->flags & VMS_MULTIPLY) { - size *=3D field->size; + if ((field->flags & VMS_MULTIPLY) && + umul64_overflow(size, field->size, &size)) { + error_setg(errp, "%s: VMState field '%s' multiply overflow", + __func__, field->name); + return false; } } else if (field->flags & VMS_ARRAY_OF_POINTER) { /* @@ -132,7 +138,8 @@ static uint64_t vmstate_size(void *opaque, const VMStat= eField *field) size =3D field->size; } =20 - return size; + *sz =3D size; + return true; } =20 static bool vmstate_handle_alloc(void *ptr, const VMStateField *field, @@ -364,7 +371,11 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescr= iption *vmsd, void *first_elem =3D opaque + field->offset; int i; uint64_t n_elems =3D vmstate_n_elems(opaque, field); - uint64_t size =3D vmstate_size(opaque, field); + uint64_t size; + + if (!vmstate_size(opaque, field, &size, errp)) { + return false; + } =20 if (!vmstate_handle_alloc(first_elem, field, n_elems, size, er= rp)) { return false; @@ -682,9 +693,10 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, void *first_elem =3D opaque + field->offset; int i; uint64_t n_elems =3D vmstate_n_elems(opaque, field); - uint64_t size =3D vmstate_size(opaque, field); + uint64_t size; 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. @@ -692,6 +704,10 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, bool use_dynamic_array =3D field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC; =20 + if (!vmstate_size(opaque, field, &size, errp)) { + return false; + } + trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems= ); if (field->flags & VMS_POINTER) { first_elem =3D *(void **)first_elem; --=20 2.53.0