From nobody Thu May 2 08:35:11 2024 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=1669723505; cv=none; d=zohomail.com; s=zohoarc; b=hvTs2n99monVVCLgSK3kuQ6AiHnSTopdDcB8IDyqc9ECNwQdESKalxJfiManOwjHG3YBSRMgL2F6wLe9IRki/I4Bmc0FirWp2Ids6msTnBbHHcbKvLB/2y0hUm8IIVQIh0Sn9rKXcjJjR62ylbpW+cd9rZT/IFXb8J3gfZChNuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669723505; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vJC6rD1rMTbnmUdrTWSBJ+RfNQMIjV7oilTjYfhpvkw=; b=kIFy+B4s2k1sEiEpzgI/vgkiCFs5ec7SKovu6EIBXs1cfo7iAwc5SS5uJatE0wwjStOKIykjj4CQVp3eh6bHcP+5iYsu4tXVjbw5Wrnn/TKJEPGuJNMADRq/mFQeCQVJNM4gD/MhU0z++yIIy8I4GgrlhvlqzqLf0LI8xetTwmI= 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 1669723505605525.3510238307457; Tue, 29 Nov 2022 04:05:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozzLY-00081l-Vr; Tue, 29 Nov 2022 07:04:21 -0500 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 1ozzLM-0007x2-3k for qemu-devel@nongnu.org; Tue, 29 Nov 2022 07:04:17 -0500 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 1ozzLK-0002FC-Er for qemu-devel@nongnu.org; Tue, 29 Nov 2022 07:04:07 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-ulmwP2RwPqmFYd31FG08vA-1; Tue, 29 Nov 2022 07:04:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D6DBE88646B; Tue, 29 Nov 2022 12:04:02 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id F12D62166B2D; Tue, 29 Nov 2022 12:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669723444; 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=vJC6rD1rMTbnmUdrTWSBJ+RfNQMIjV7oilTjYfhpvkw=; b=BBuoejw/Pvaf7rKWjudZBqgOLkg5gOfAW3DUNAIZ/ulKCd2IPClft4lkWJ1giSjOXOMvrO 4c+VoaQQjt8zek8kswTIPX7PByvFk/5Oxi9AFE5uWW8G2KROAyQ2038lBDlkHFFHNTeZtc ouXsOdOKDB5n4NHENQ7vYzazOrlf78U= X-MC-Unique: ulmwP2RwPqmFYd31FG08vA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/2] migration: Add canary to VMSTATE_END_OF_LIST Date: Tue, 29 Nov 2022 13:03:57 +0100 Message-Id: <20221129120358.16452-2-quintela@redhat.com> In-Reply-To: <20221129120358.16452-1-quintela@redhat.com> References: <20221129120358.16452-1-quintela@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=quintela@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_H2=-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: 1669723507371100001 From: "Dr. David Alan Gilbert" We fairly regularly forget VMSTATE_END_OF_LIST markers off descriptions; given that the current check is only for ->name being NULL, sometimes we get unlucky and the code apparently works and no one spots the error. Explicitly add a flag, VMS_END that should be set, and assert it is set during the traversal. Note: This can't go in until we update the copy of vmstate.h in slirp. Suggested-by: Peter Maydell Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- include/migration/vmstate.h | 7 ++++++- migration/savevm.c | 1 + migration/vmstate.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index ad24aa1934..527ead2831 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -147,6 +147,9 @@ enum VMStateFlags { * VMStateField.struct_version_id to tell which version of the * structure we are referencing to use. */ VMS_VSTRUCT =3D 0x8000, + + /* Marker for end of list */ + VMS_END =3D 0x10000 }; =20 typedef enum { @@ -1161,7 +1164,9 @@ extern const VMStateInfo vmstate_info_qlist; VMSTATE_UNUSED_BUFFER(_test, 0, _size) =20 #define VMSTATE_END_OF_LIST() \ - {} + { \ + .flags =3D VMS_END, \ + } =20 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id); diff --git a/migration/savevm.c b/migration/savevm.c index a0cdb714f7..3ad81359ab 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -585,6 +585,7 @@ static void dump_vmstate_vmsd(FILE *out_file, field++; first =3D false; } + assert(field->flags =3D=3D VMS_END); fprintf(out_file, "\n%*s]", indent, ""); } if (vmsd->subsections !=3D NULL) { diff --git a/migration/vmstate.c b/migration/vmstate.c index 924494bda3..83ca4c7d3e 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -154,6 +154,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescri= ption *vmsd, } field++; } + assert(field->flags =3D=3D VMS_END); ret =3D vmstate_subsection_load(f, vmsd, opaque); if (ret !=3D 0) { return ret; @@ -408,6 +409,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, } field++; } + assert(field->flags =3D=3D VMS_END); =20 if (vmdesc) { json_writer_end_array(vmdesc); --=20 2.38.1 From nobody Thu May 2 08:35:11 2024 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=1669723494; cv=none; d=zohomail.com; s=zohoarc; b=E0pwrXaSvdGcdYpQRraST3T0HkAHz68gVz3PwoJnpGwT3J9D2NXxbAASQFV2+sHu58I0OcqSMB1VMF02nbRXKynyqglrQx70oVtBa1XeFfwZ4QzCYhB12xDb2xFiUnwUYrNzhAcUZ+NVj2uECHQLAULl+b9y4bG13svMZrhEaLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669723494; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CAdle4g5CCMNqOqQR86hoGfyErhNQCAtfZJ1Q4Djxzs=; b=Zwfyk4WpLmUMjjfqGxHwotnzDBiUlOTKt8tNQysK3tIGyJREOYRelLI+HAi//YMqvzWBY7JqYvd5hQIQCywFgDlHGXtAOkd4txAtEqc/DOpRshbflBcH8fdR8nCfOgCobqNpIWkoofC60B64r/XM84MldbJg0H+iF7H6/xCjO0c= 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 1669723494149567.8348136849896; Tue, 29 Nov 2022 04:04:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozzLX-000806-Rf; Tue, 29 Nov 2022 07:04:19 -0500 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 1ozzLP-0007xE-Ty for qemu-devel@nongnu.org; Tue, 29 Nov 2022 07:04:17 -0500 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 1ozzLM-0002FQ-W9 for qemu-devel@nongnu.org; Tue, 29 Nov 2022 07:04:11 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-448-RlPWdFWgM_Wjcm51fwrNWw-1; Tue, 29 Nov 2022 07:04:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D7275185A7A8; Tue, 29 Nov 2022 12:04:03 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2622F2166B2D; Tue, 29 Nov 2022 12:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669723447; 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=CAdle4g5CCMNqOqQR86hoGfyErhNQCAtfZJ1Q4Djxzs=; b=KKxg8i1xdR1nxLnEdIBDxN2gzi4xFmtLd8J14xel9SlEaP7I/H9Y0XPS2gp1DPWzM3wW32 YysVDERE11F4Mc8dT7BUbDbXrXak4eziOIZypq7iqbFWG/P6vwI0wlnAQUmWM6ePEg1Uyh i3yER3GDdZccVEVeB42hW+WnRgbQcDY= X-MC-Unique: RlPWdFWgM_Wjcm51fwrNWw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , Peter Maydell Subject: [PATCH v2 2/2] migration: Perform vmsd structure check during tests Date: Tue, 29 Nov 2022 13:03:58 +0100 Message-Id: <20221129120358.16452-3-quintela@redhat.com> In-Reply-To: <20221129120358.16452-1-quintela@redhat.com> References: <20221129120358.16452-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=quintela@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_H2=-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: 1669723495280100002 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Perform a check on vmsd structures during test runs in the hope of catching any missing terminators and other simple screwups. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Maydell Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/savevm.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 3ad81359ab..e6c3fc6614 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -66,6 +66,7 @@ #include "net/announce.h" #include "qemu/yank.h" #include "yank_functions.h" +#include "sysemu/qtest.h" =20 const unsigned int postcopy_ram_discard_version; =20 @@ -804,6 +805,42 @@ void unregister_savevm(VMStateIf *obj, const char *ids= tr, void *opaque) } } =20 +/* + * Perform some basic checks on vmsd's at registration + * time. + */ +static void vmstate_check(const VMStateDescription *vmsd) +{ + const VMStateField *field =3D vmsd->fields; + const VMStateDescription **subsection =3D vmsd->subsections; + + if (field) { + while (field->name) { + if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) { + /* Recurse to sub structures */ + vmstate_check(field->vmsd); + } + /* Carry on */ + field++; + } + /* Check for the end of field list canary */ + if (field->flags !=3D VMS_END) { + error_report("VMSTATE not ending with VMS_END: %s", vmsd->name= ); + g_assert_not_reached(); + } + } + + while (subsection && *subsection) { + /* + * The name of a subsection should start with the name of the + * current object. + */ + assert(!strncmp(vmsd->name, (*subsection)->name, strlen(vmsd->name= ))); + vmstate_check(*subsection); + subsection++; + } +} + int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, @@ -849,6 +886,11 @@ int vmstate_register_with_alias_id(VMStateIf *obj, uin= t32_t instance_id, } else { se->instance_id =3D instance_id; } + + /* Perform a recursive sanity check during the test runs */ + if (qtest_enabled()) { + vmstate_check(vmsd); + } assert(!se->compat || se->instance_id =3D=3D 0); savevm_state_handler_insert(se); return 0; --=20 2.38.1