From nobody Mon Apr 6 21:55:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1773789908; cv=none; d=zohomail.com; s=zohoarc; b=h0H7bVvqtdSr8IuT22OLWf2zQx6D0sPqU3t2MdjVgNHCju6JZhVKPUQdQjaHknCPo7dlanl8phCxFkf0oa3beMgMYkfUSfCnQsBnmSSH2AvthgOyqV2d+ApIUWqXarJrI9acbWPpbME4AYLtiPq/WQKcmy0jBXSnz92/zCUjL1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773789908; 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=4VIfJwVvQOqSfZotFMcnTmIgI+32r03PnWffChaegzo=; b=MuUEnIMQPO64ahuaaAreXnpxaUAUkr7sROIwMvahoQhEo8g9ZRzIswsfzx5xC0BfpP0sDc4RXwHtKhAiQCWQmwoP1w96fuX6d74inItY7wWjME/yuI0a9ZnfPW+eo9NPKA7PY/P3rSa2OX+fbfm9UFEOWqYeEVNuLEkcueoCXcg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773789908985296.795178961847; Tue, 17 Mar 2026 16:25:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2dlR-0003yj-9U; Tue, 17 Mar 2026 19:23:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2dlP-0003yG-KC for qemu-devel@nongnu.org; Tue, 17 Mar 2026 19:23:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2dlO-0006TD-3C for qemu-devel@nongnu.org; Tue, 17 Mar 2026 19:23:51 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-ZMTcE3RUPkWeuGF17uVYbw-1; Tue, 17 Mar 2026 19:23:48 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-5092033798eso237515481cf.1 for ; Tue, 17 Mar 2026 16:23:48 -0700 (PDT) Received: from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89c6b9ea39asm8203806d6.37.2026.03.17.16.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 16:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773789829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4VIfJwVvQOqSfZotFMcnTmIgI+32r03PnWffChaegzo=; b=HjR4qz2WF4LHnee9t+E0fnux/CL2K83CK+OgOU8b45a0B1iUhvlHvyi9eMmLG+XqjWXgbK ajXpahQa+koN3bp4vBaLLNL8isKIFyXgYv5pAif/qFeIlxsETsaFCefv4d4zKUYEVDDul7 j9ZF1uoLRJW2yMHcBVZRFcNUiUt82PU= X-MC-Unique: ZMTcE3RUPkWeuGF17uVYbw-1 X-Mimecast-MFC-AGG-ID: ZMTcE3RUPkWeuGF17uVYbw_1773789828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773789827; x=1774394627; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4VIfJwVvQOqSfZotFMcnTmIgI+32r03PnWffChaegzo=; b=rPkuunHKf6dN8l1BlGe/TXzcqPbJ5IPv4FCsLcYigjgcqLURvxbNres6BbrkfCBYMH 20ea774Tek0mpiGZIJ6+O/PpRkJiB+oDzBZdjqZiTgwBIs8X42ecihds+F49SOWSb4Wk Bg8GK+nYgo0sSpGbFvt5fXSIPsY77QwaQZU7FrdlDoXTQAQdYfpgY7qELUmqeVzHv+nv GbxX7R3sZPrfcDFJCrIV5Zjgc/EeO6iFT20/evkRxS3Wfw1cnwk9c60hS6hV2a10mxb3 uv1IGQmKEcIlOeVrbL5T8l5Kjqdu+Z3HWYv4T377sQl4UMwdsLWd1+SDcuFmrtIpMKvR MCCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773789827; x=1774394627; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4VIfJwVvQOqSfZotFMcnTmIgI+32r03PnWffChaegzo=; b=rGJwkTdbVRfIaFKokhmRe2OafW6mPmaCcT0R/Jm+eeX20T1hrfuT6ivPc1kRkWu013 LIuIn9lJ0wSrvCxEX6d5ehfBeNQXacEDLMlXgK5pzpjNIgwS3oAxsongvLmjuD7kOxeR Eqpew7pV2ZzMvy3TBhQXOc7qHac2bnOs71Yl/hmg4Fq8FezU5HpLdre1cRjI5EhHf97t ZuID6C6O8VZeXvThhSf3rfcA5n82UAX8BJYNGpS/i+9zDxDf69zAH1wJvx3kEwsbjmYN zpTUuSTQ1rmMHNYi3Mx+pKO4D8plv42ignttKYHC4sJpjMTtphemD9LIlGlawxT+yKTZ IpnQ== X-Gm-Message-State: AOJu0Yz160zvRLZZ1EJhM1k5sMEyaBxZLCCCtEkMGMdvyGuWcorEiiZz nY7UGzU3Z+O+0RHtCqykit4z5IrUkh0sdS/nIFyta5igYVzIlgr/9hNvKYbAIQvHWxeLAoCGwmb WQelUBcu2JueBwqL4Tn0rycvZViwCJpx0/ab+7NjpDHH7gAdM3Rlu45Te96w5XrPOLKsEVmZ306 ZJUHMArVpxrIEDhLrMKoh5QaUD9Eh0l/FI0o0MaQ== X-Gm-Gg: ATEYQzwuRYWZDd9STulXPOJ6/Q+iYErNV63Jww5T4RXefb1ehmnYUkQjLtaLMRTpw+X 3tJy2hg0CM9WyLElbSmWSGyElCtsEo4lKY+K+Yvg9GyOc1WfUNERO/hkJ5hIbv+Ws+C+0srV4Pi E0IIq1O7QHlCbEvI0rFIlfW2StekCcZ/Qr2kpOl4P3UPwtXFu0W3dUbvDgnS9Yz19BbDPOckPHJ rJvj7vwFfiRu31d3LcqRXwMrwXojyHkVQ6x1xMrXFTT/CcL+lak5ky8g8jQT9tGXXFz3wfTBMbL wuzOkbHuLZ/BALG0BhBL7U07cZtY57TSC3zyYEDS1PJD85R9nv5+Q/kGqS2x1B/lt+rTl0dRDsp hvVSkpTAiYc+Zqw== X-Received: by 2002:a05:620a:4081:b0:8cd:98c1:762e with SMTP id af79cd13be357-8cfad38a797mr207316985a.63.1773789827233; Tue, 17 Mar 2026 16:23:47 -0700 (PDT) X-Received: by 2002:a05:620a:4081:b0:8cd:98c1:762e with SMTP id af79cd13be357-8cfad38a797mr207314385a.63.1773789826783; Tue, 17 Mar 2026 16:23:46 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Juraj Marcin , peterx@redhat.com, Fabiano Rosas Subject: [PATCH RFC 08/10] vmstate: Implement load of ptr marker in vmstate core Date: Tue, 17 Mar 2026 19:23:30 -0400 Message-ID: <20260317232332.15209-9-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260317232332.15209-1-peterx@redhat.com> References: <20260317232332.15209-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1773789910316158500 Content-Type: text/plain; charset="utf-8" The loader side of ptr marker is pretty straightforward, instead of playing the inner_field trick, just do the load manually assuming the marker layout is a stable ABI (which it is true already). This will remove some logic while loading VMSD, and hopefully it makes it slightly easier to read. Unfortunately, we still need to keep the sender side because of the JSON blob we're maintaining.. This paves way for future processing of non-NULL markers as well. Signed-off-by: Peter Xu Reviewed-by: Alexander Mikhalitsyn --- migration/vmstate-types.c | 12 ++++-------- migration/vmstate.c | 40 ++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index b31689fc3c..ae465c5c2c 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -363,14 +363,10 @@ static bool load_ptr_marker(QEMUFile *f, void *pv, si= ze_t size, const VMStateField *field, Error **errp) =20 { - int byte =3D qemu_get_byte(f); - - if (byte =3D=3D VMS_MARKER_PTR_NULL || byte =3D=3D VMS_MARKER_PTR_VALI= D) { - /* TODO: process PTR_VALID case */ - return true; - } - - error_setg(errp, "%s: unexpected ptr marker: %d", __func__, byte); + /* + * Load is done in vmstate core, see vmstate_ptr_marker_load(). + */ + g_assert_not_reached(); return false; } =20 diff --git a/migration/vmstate.c b/migration/vmstate.c index a3a5f25946..d65fc84dfa 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -142,6 +142,21 @@ static void vmstate_handle_alloc(void *ptr, const VMSt= ateField *field, } } =20 +static bool vmstate_ptr_marker_load(QEMUFile *f, bool *load_field, + Error **errp) +{ + int byte =3D qemu_get_byte(f); + + if (byte =3D=3D VMS_MARKER_PTR_NULL) { + /* When it's a null ptr marker, do not continue the load */ + *load_field =3D false; + return true; + } + + error_setg(errp, "Unexpected ptr marker: %d", byte); + return false; +} + static bool vmstate_pre_load(const VMStateDescription *vmsd, void *opaque, Error **errp) { @@ -264,30 +279,25 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDesc= ription *vmsd, } =20 for (i =3D 0; i < n_elems; i++) { - bool ok; + /* If we will process the load of field? */ + bool load_field =3D true; + bool ok =3D true; void *curr_elem =3D first_elem + size * i; - const VMStateField *inner_field; =20 if (field->flags & VMS_ARRAY_OF_POINTER) { curr_elem =3D *(void **)curr_elem; } =20 if (!curr_elem && size) { - /* - * If null pointer found (which should only happen in - * an array of pointers), use null placeholder and do - * not follow. - */ - inner_field =3D vmsd_create_ptr_marker_field(field); - } else { - inner_field =3D field; + /* Read the marker instead of VMSD itself */ + if (!vmstate_ptr_marker_load(f, &load_field, errp)) { + trace_vmstate_load_field_error(field->name, -EINVA= L); + return false; + } } =20 - ok =3D vmstate_load_field(f, curr_elem, size, inner_field,= errp); - - /* If we used a fake temp field.. free it now */ - if (inner_field !=3D field) { - g_clear_pointer((gpointer *)&inner_field, g_free); + if (load_field) { + ok =3D vmstate_load_field(f, curr_elem, size, field, e= rrp); } =20 if (ok) { --=20 2.50.1