From nobody Tue Feb 10 12:42:46 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1698136946; cv=none; d=zohomail.com; s=zohoarc; b=j3tTdtgq1UKNXL48K309Mh+L9Z/pPh6ITtXkY+BIaehHVA/SPA33r1u9SYKshsxpYwY9icbVue2y+gQl7fbcQuyVWKNwts/ppi7YvkoGI92V8hw0zndHfAy0IcP1qGajj/h4Q9lQoETLwXyGC4xX7m1ZuoW4nqKnN7dMkNBDrjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698136946; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LnsG5NWQMp6ppcb6O/Y0IH9dMdUd6gQTyemwrekuS08=; b=Z3RAVUzD26fDEUkr+T7x/SgI119PWpJOUgR0keWkFfPL6f+KwarbX/f1VN4LhuxMmS+bDAf/7lFWWxIQ6+THwzI7liwA8uCD95lc5XgTGc4bHF2IGtZmnJvnxY1/B80FOcfK/LeXFt8YqJcyvn7QhvWJxPa9P3STZpRQbTneoWA= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1698136946495191.79523055591767; Tue, 24 Oct 2023 01:42:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvCyq-0004Cc-SZ; Tue, 24 Oct 2023 04:41:41 -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 1qvCyS-0003yl-Fr for qemu-devel@nongnu.org; Tue, 24 Oct 2023 04:41:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvCyP-0003LT-QN for qemu-devel@nongnu.org; Tue, 24 Oct 2023 04:41:15 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-541-1RGbMSjsMmCVGt_lZbA9OQ-1; Tue, 24 Oct 2023 04:41:09 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A25C1C051A1; Tue, 24 Oct 2023 08:41:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CE44492BD9; Tue, 24 Oct 2023 08:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698136873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LnsG5NWQMp6ppcb6O/Y0IH9dMdUd6gQTyemwrekuS08=; b=PWTockgSkXoVd5oKEn/OxwHbfOCtGtO9ZupfksWL3uR9X2znYWB0+9Ndyb31EzpC1yhHD8 s4vgjt0defySlf0IO5ZsZ6hpixwv7DoaQzxVWY59rFpnvcoAuJoAExRoAWBkrEergXrraN 8Mrsyf7vlPQz5tKxYFox2d9LzyS5dM0= X-MC-Unique: 1RGbMSjsMmCVGt_lZbA9OQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Kevin Wolf , "Michael S. Tsirkin" , Fabiano Rosas , John Snow , Hanna Reitz , Leonardo Bras , Samuel Thibault , qemu-block@nongnu.org, Peter Xu , Jason Wang , Juan Quintela , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 5/9] migration: check required subsections are loaded, once Date: Tue, 24 Oct 2023 12:40:39 +0400 Message-ID: <20231024084043.2926316-6-marcandre.lureau@redhat.com> In-Reply-To: <20231024084043.2926316-1-marcandre.lureau@redhat.com> References: <20231024084043.2926316-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 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: 1698136948524100008 From: Marc-Andr=C3=A9 Lureau Check that required subsections have been loaded. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Juan Quintela --- migration/vmstate.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 16e33a5d34..d6fe38a5e1 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -451,22 +451,51 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDe= scription *vmsd, } =20 static const VMStateDescription * -vmstate_get_subsection(const VMStateDescription **sub, char *idstr) +vmstate_get_subsection(const VMStateDescription **sub, char *idstr, bool *= visited) { + size_t i =3D 0; + while (sub && *sub) { if (strcmp(idstr, (*sub)->name) =3D=3D 0) { + if (visited[i]) { + return NULL; + } + visited[i] =3D true; return *sub; } + i++; sub++; } return NULL; } =20 +static size_t +vmstate_get_n_subsections(const VMStateDescription **sub) +{ + size_t n =3D 0; + + if (!sub) { + return 0; + } + + while (sub[n]) { + n++; + } + + return n; +} + static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *= vmsd, void *opaque) { + size_t i, n; + g_autofree bool *visited =3D NULL; + trace_vmstate_subsection_load(vmsd->name); =20 + n =3D vmstate_get_n_subsections(vmsd->subsections); + visited =3D g_new0(bool, n); + while (qemu_peek_byte(f, 0) =3D=3D QEMU_VM_SUBSECTION) { char idstr[256], *idstr_ret; int ret; @@ -492,7 +521,7 @@ static int vmstate_subsection_load(QEMUFile *f, const V= MStateDescription *vmsd, /* it doesn't have a valid subsection name */ return 0; } - sub_vmsd =3D vmstate_get_subsection(vmsd->subsections, idstr); + sub_vmsd =3D vmstate_get_subsection(vmsd->subsections, idstr, visi= ted); if (sub_vmsd =3D=3D NULL) { trace_vmstate_subsection_load_bad(vmsd->name, idstr, "(lookup)= "); return -ENOENT; @@ -509,6 +538,13 @@ static int vmstate_subsection_load(QEMUFile *f, const = VMStateDescription *vmsd, } } =20 + for (i =3D 0; i < n; i++) { + if (!visited[i] && vmstate_section_needed(vmsd->subsections[i], op= aque)) { + trace_vmstate_subsection_load_bad(vmsd->name, vmsd->subsection= s[i]->name, "(not visited)"); + return -ENOENT; + } + } + trace_vmstate_subsection_load_good(vmsd->name); return 0; } --=20 2.41.0