From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7191109C040 for ; Wed, 25 Mar 2026 18:12:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5Shf-00051I-5J; Wed, 25 Mar 2026 14:11:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5ShZ-00050r-OY for qemu-devel@nongnu.org; Wed, 25 Mar 2026 14:11:34 -0400 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w5ShX-0000qX-Eb for qemu-devel@nongnu.org; Wed, 25 Mar 2026 14:11:33 -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 799885BCF8; Wed, 25 Mar 2026 18:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774462288; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6Jh3rtxKgzb5uF3D05rl3H5rlxtEEvLJmEe702E6cW0=; b=0zKnyFkeLOHNnFnEMSyz1xaKh6ZsSc4REVprZ234zd74422tP7Me/TocYCKVF6rzK9b5vP GmjPsKYAZaUMTD/G8xEdRWALWvj2CcmSaUljo/96Kt3BRBFQ3njMsUe14cqyoZGn0V7xY5 o82pn77Lz6EXyWoRCRBPoABf3GYlG0o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774462288; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6Jh3rtxKgzb5uF3D05rl3H5rlxtEEvLJmEe702E6cW0=; b=ALcP77MghL7Btq0O/4pSrcXIGqukjxPndiSXQHsVCb1Ax5n7LWwjyMDGzpNXzMSvTGlM1w Ckcp0uJeSqgieQDw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0zKnyFke; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ALcP77Mg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774462288; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6Jh3rtxKgzb5uF3D05rl3H5rlxtEEvLJmEe702E6cW0=; b=0zKnyFkeLOHNnFnEMSyz1xaKh6ZsSc4REVprZ234zd74422tP7Me/TocYCKVF6rzK9b5vP GmjPsKYAZaUMTD/G8xEdRWALWvj2CcmSaUljo/96Kt3BRBFQ3njMsUe14cqyoZGn0V7xY5 o82pn77Lz6EXyWoRCRBPoABf3GYlG0o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774462288; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6Jh3rtxKgzb5uF3D05rl3H5rlxtEEvLJmEe702E6cW0=; b=ALcP77MghL7Btq0O/4pSrcXIGqukjxPndiSXQHsVCb1Ax5n7LWwjyMDGzpNXzMSvTGlM1w Ckcp0uJeSqgieQDw== 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 04D7644526; Wed, 25 Mar 2026 18:11:27 +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 zyNJME8lxGmlLwAAD6G6ig (envelope-from ); Wed, 25 Mar 2026 18:11:27 +0000 From: Fabiano Rosas To: Peter Xu Cc: qemu-devel@nongnu.org, Alexander Mikhalitsyn , Juraj Marcin Subject: Re: [RFC PATCH v1 05/17] vmstate: Remove vmdesc_loop In-Reply-To: References: <20260324194333.30004-1-farosas@suse.de> <20260324194333.30004-6-farosas@suse.de> Date: Wed, 25 Mar 2026 15:11:25 -0300 Message-ID: <87pl4rkcdu.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:mid,suse.de:dkim,suse.de:email]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 799885BCF8 Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Peter Xu writes: > On Tue, Mar 24, 2026 at 04:43:20PM -0300, Fabiano Rosas wrote: >> The vmdesc_loop variable is being used as a hacky way of writing the >> JSON description only for the first element of a compressed >> array. There are also a few implicit uses, such as writing the JSON >> for the first non-compressed element after a compressed portion. >> >> Future work will have trouble with this. Use a simple boolean to be >> explicit now. >> >> Signed-off-by: Fabiano Rosas >> --- >> migration/vmstate.c | 25 ++++++++++++++----------- >> 1 file changed, 14 insertions(+), 11 deletions(-) >> >> diff --git a/migration/vmstate.c b/migration/vmstate.c >> index dec9cf920b..7a12245d36 100644 >> --- a/migration/vmstate.c >> +++ b/migration/vmstate.c >> @@ -622,8 +622,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd, >> void *first_elem = opaque + field->offset; >> int i, n_elems = vmstate_n_elems(opaque, field); >> int size = vmstate_size(opaque, field); >> - JSONWriter *vmdesc_loop = vmdesc; >> bool is_null_prev = false; >> + bool use_vmdesc = true; >> + >> /* >> * When this is enabled, it means we will always push a ptr >> * marker first for each element saying if it's populated. >> @@ -673,7 +674,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd, >> is_null != is_null_prev) { >> >> is_null_prev = is_null; >> - vmdesc_loop = vmdesc; >> + use_vmdesc = true; >> >> for (int j = i + 1; j < n_elems; j++) { >> void *elem = *(void **)(first_elem + size * j); >> @@ -686,8 +687,13 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd, >> } >> } >> >> + if (use_dynamic_array) { >> + use_vmdesc = true; >> + } > > [1] > >> + >> ok = vmstate_save_field_with_vmdesc(f, curr_elem, size, vmsd, >> - inner_field, vmdesc_loop, >> + inner_field, >> + use_vmdesc ? vmdesc : NULL, >> i, max_elems, errp); >> >> /* If we used a fake temp field.. free it now */ >> @@ -708,19 +714,16 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd, >> * NOTE: do not use vmstate_size() here because we want >> * to dump the real VMSD object now. >> */ >> - ok = vmstate_save_field_with_vmdesc(f, curr_elem, >> - field->size, vmsd, >> - field, vmdesc_loop, >> - i, max_elems, errp); >> + ok = vmstate_save_field_with_vmdesc( >> + f, curr_elem, field->size, vmsd, field, >> + use_vmdesc ? vmdesc : NULL, i, max_elems, errp); >> + >> if (!ok) { >> goto out; >> } >> } >> >> - /* Compressed arrays only care about the first element */ >> - if (vmdesc_loop && vmsd_can_compress(field)) { >> - vmdesc_loop = NULL; >> - } >> + use_vmdesc = false; > > Hmm... > > vmsd_can_compress() can return arbitrary things depending on the field > itself, now we always do the dedup almost for everything. > > The patch did add above [1] to make AUTO_ALLOC be ok, by enforce setting > TRUE for it for every loop, but what about other cases where > vmsd_can_compress() may return false (where the field does not support > compression)? > Hmm, I think you're right. But what I'm doing by setting use_vmdesc=false here is just clearing it for the next iteration, where it should be set according to necessity. So I'd leave this down here, but up there change to: if (vmdesc && vmsd_can_compress(field)) { if (is_null != is_null_prev) { use_vmdesc = true; ... } - } - - if (use_dynamic_array) { + } else { use_vmdesc = true; } In words: all fields should appear in the JSON, unless its part of the NULL portion of a compressed array. For compressed arrays only the first element appears in the JSON. If a stream of NULLs is followed by a non-NULL member, then that member should appear in the JSON after the compressed entry. These two catch all these corner-cases I think: PYTHON=$(pwd)/pyvenv/bin/python3.11 QTEST_QEMU_BINARY=./qemu-system-s390x ./tests/qtest/migration-test -p /s390x/migration/analyze-script PYTHON=$(pwd)/pyvenv/bin/python3.11 QTEST_QEMU_BINARY=./qemu-system-ppc64 ./tests/qtest/migration-test-p /ppc64/migration/analyze-script >> } >> } else { >> if (field->flags & VMS_MUST_EXIST) { >> -- >> 2.51.0 >>