From nobody Fri May 3 07:04:33 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=1669641000; cv=none; d=zohomail.com; s=zohoarc; b=nzyKU6ijNz4e4FSFnQdvsV9xm2UeN+X3to08ogdsXvpFIdIZw9r7cOE7IstE78pmJQsMN6zV3iKNURLloRINxgQ1hmvgN3S+aJCD90hgHcm3AehDAsGpG7zVj8Nv10C0JT4j/kdFYuOBIccGVPswL0HJjtmna2YA4DE5N4/x4+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669641000; 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=a2yPSFHfWL2F/7ZG8gYyYFjHrLJX9UaDd0kr3K5wFrERhnXzMSv204H5Ho/1HCGLpXeXPwMIVcUa+qQLrwozV/RepuROrpVzMQBDIVk8YSFdReEjYO3DGYSb23TtXrp8WRNpIGeGiovKfA0Jtlbut0CWZSQrY5bKI5aTfJp/UW4= 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 1669641000791178.72087434300067; Mon, 28 Nov 2022 05:10:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozdsq-00079Z-WE; Mon, 28 Nov 2022 08:09:17 -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 1ozdsc-00074j-Cw for qemu-devel@nongnu.org; Mon, 28 Nov 2022 08:09:02 -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 1ozdsa-0000td-Rt for qemu-devel@nongnu.org; Mon, 28 Nov 2022 08:09:02 -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-182-WzosiOs4PWuXciCJidu0hg-1; Mon, 28 Nov 2022 08:08:56 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78E3E185A78F; Mon, 28 Nov 2022 13:08:56 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7527F492B05; Mon, 28 Nov 2022 13:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669640940; 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=S6t+jLVOCFyHfvVLOyF1TJxiT3KeGA9DQv6+dJBF0JG8pK7j7l22GfCGETAiGtOgYwN3Gw Iz6biQTW04+K4AYY9abP7b3hNwAXDt8duoQQv7GV5HRLsEdtElcYlIvvZY84deGgt16wnJ ddaX1EdCICpukz/Au3wIQJ3ZfijRMhY= X-MC-Unique: WzosiOs4PWuXciCJidu0hg-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 1/2] migration: Add canary to VMSTATE_END_OF_LIST Date: Mon, 28 Nov 2022 14:08:50 +0100 Message-Id: <20221128130851.14362-2-quintela@redhat.com> In-Reply-To: <20221128130851.14362-1-quintela@redhat.com> References: <20221128130851.14362-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.10 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: 1669641041011100001 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 Fri May 3 07:04:33 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=1669640976; cv=none; d=zohomail.com; s=zohoarc; b=LEWWRYonx5nHTVO2XlQW+NTsyWqFKohzd+LlJ1tiBVjWEkXBKA2076o7xnxN8SZvB7C4AITSmjCHDWHpCsqKHL+9BkyRaIr+G6EXppMsyVfIbm3dPJF8Un0tk3So1Qp3DE/nAh6iJlt6yjqVLAaAoI4s7oSzfbrvyZVqaS0SpsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669640976; 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=duJofwq2YQ9LlAcHBVk0zocyia/nPUQ8k1CUjCqbhWg=; b=nsljGaXKpIhhYd45FlIia2XA3WctTyNOtdEm75j5blTKcoOjCZ82Z0DWIhfkxhwW/YYeHgiKyipVzYfV6snXt9oEiNQ2NQWVY2gNIVn4eQKKKzTlk56wWPK+MxeWFYw1jDlde3H7PXdH3iq0aGC9k49nPlJ53YrFUSSPJ5DAHdM= 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 1669640976751607.4901986818729; Mon, 28 Nov 2022 05:09:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozdsp-00076M-2k; Mon, 28 Nov 2022 08:09:15 -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 1ozdsb-00074f-UC for qemu-devel@nongnu.org; Mon, 28 Nov 2022 08:09:02 -0500 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 1ozdsa-0000tW-7J for qemu-devel@nongnu.org; Mon, 28 Nov 2022 08:09:01 -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-479-vy-zTHwtMJmlCRPNU8dbFw-1; Mon, 28 Nov 2022 08:08:57 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7876A811E67; Mon, 28 Nov 2022 13:08:57 +0000 (UTC) Received: from secure.mitica (unknown [10.39.193.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB6CC492B05; Mon, 28 Nov 2022 13:08:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669640939; 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=duJofwq2YQ9LlAcHBVk0zocyia/nPUQ8k1CUjCqbhWg=; b=K7tahLq+NGyj1pwcmefM3a4wkyq6HNBqJrZJxBovF3AmkcIJJr+Mb8hIffkFsuKJrAgN3p joPImdioE2BIENvY3FhRD60d5m549zpHwJ4PDL0rRJI30XLosd4ohI961tCpI0o6v/Jzq2 +JoOhLUD82364VEK7cwCZDCYH2DGay0= X-MC-Unique: vy-zTHwtMJmlCRPNU8dbFw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , Peter Maydell Subject: [PATCH 2/2] migration: Perform vmsd structure check during tests Date: Mon, 28 Nov 2022 14:08:51 +0100 Message-Id: <20221128130851.14362-3-quintela@redhat.com> In-Reply-To: <20221128130851.14362-1-quintela@redhat.com> References: <20221128130851.14362-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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: 1669641032722100001 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..653087f0bb 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= ); + exit(-1); + } + } + + 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