From patchwork Wed Apr 25 15:27:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 134343 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1007049lji; Wed, 25 Apr 2018 08:28:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp6PM8XGED7KFb8Hq697V5m6PW1cMOw2m0cx7vvpy/yyRBLJIGmE3H4HbVB5y3jRE18am/V X-Received: by 10.55.197.201 with SMTP id k70mr30773732qkl.390.1524670093085; Wed, 25 Apr 2018 08:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524670093; cv=none; d=google.com; s=arc-20160816; b=PbiaGZtixP/xBZmu7Pl8OheDomF/aw1qKw66qFICuXk9NGTjUdbStuHi3DUaDv+diM R8UpzMEP0ixH7xwHndkttC0+6Qu611qBEF/NqfqkRYryFWLR8hYezz89TCyTbPq5OkTQ +vA/gISYU81+G0OvzslKw+0vVwMCQo0/SjQwSYtrNZHumaIPBH76rq4YcXtrId+uu4Nc 8sZHD1xFAx6PFF8kPp+MPZ+UZA1s4Jbn4ygdkFBF4wrnPv/3xCuL1GY/O16iikd04ATE 5qCOZp7tt1Jo8jGUMJJjWjcMjPaavw+725TrVtGO2P9bbBKAXPD0Kje91pcLfDVHE0ny W0Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=gf/5CowLf0kUhWuFGPaZfNLSbme1genL5quk7A29FGs=; b=tfTgaz4sQ5cJuP0hPfx4722HSFwR6XTVd2AJgKCPBd1REMVbnudwd2osQRquB0DIlC PaeFlsUIxAJjD4i6lrk0gGNS1BbG/R2nDKBX8Dc1bF7Z0oW12k63zSAluCGOHScQWKrs 4fO2CR1YU1ZLDuWFYFYArq0ecmkGzJsgoBWvR+E1Lnun0coMDkgKYd/TJFaE8G42mHcW l241T3XOtjCXFql7OsUk9YNM72AjFIaArqzq2yNMQrM62KJoYJBziw0zhYiPJxQE17qW 4cRMonWKQmyb3wireg1/PKZScQ6WuX34d+Xlp5I3atmevx7mrYMu2SmgQAXyAI1+2v6c DCLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ehCM4bj4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v73si7892184qkl.180.2018.04.25.08.28.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Apr 2018 08:28:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ehCM4bj4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:37649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBML6-0001uU-Ey for patch@linaro.org; Wed, 25 Apr 2018 11:28:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMKf-0001rx-HN for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBMKe-0007iG-4s for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:45 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:39902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBMKd-0007hI-SP for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:44 -0400 Received: by mail-pf0-x244.google.com with SMTP id z9so15528165pfe.6 for ; Wed, 25 Apr 2018 08:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=gf/5CowLf0kUhWuFGPaZfNLSbme1genL5quk7A29FGs=; b=ehCM4bj4nmbMjW63oY05IhJpMDSItszAPtTQWv+WxSTuEyY3SV6PSgNVsNYERaCqrJ 0XYPsU1tSvJP2mBHXfrYTzYbiLFiDakznzbCEVI2msnSq+SgqjN6DdojQniwebT5cV2X dXwe68r2w3u1dgosOWfIXQoWcVL1lO8Guew5kh7NsQZxvFt5Y8acxwsN2eeVOMMri6Jm tWkCF1l4MQNkFwi43PwS6svi5w8WxGoMtUYFi4l1uB1D9JTHNWzRhFCqMG+FDqTf4kvx KsZRnlOhcPyAoa9QL4l03hUZZHn22R6/dTI4wRR1GC/wmUO2kcm+RDG+Sdhz/2x1wqVv Ek7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=gf/5CowLf0kUhWuFGPaZfNLSbme1genL5quk7A29FGs=; b=XTjcyFSAGu84wcgvvKDjWlv4YDxsff0hHx/YE8JjnFfAZw3y/+A5l4iffz0M0xsLUc DxC67QPRbQ0Vsb9iPUPQapZZFoyEdKYnf9vA7iJKLIaSaKpCVIDI+dRQ8NJWa+U/uDtd wcQyrnyr7z7Rhz1v3a9N4vKS2cEF7LMqQP+e6EkwN+27JPFluIAovhRusuQfC2ak6IUb JFTi/lpw++QP0jK9PF3jwBgwPcYUzkPK2k1osA4F0ieW0GmxLlTPyIPBB7h/DIPgFx7O x4lMki+sdxF0gTj8oi/9gY4gNHf4fXJwsayCMBrqMPueC0/VbYGl1nQFE72XY4wYPi6p TeBg== X-Gm-Message-State: ALQs6tCb7Ah6kt4dvBFH7b9+q0MtFMlFFV0SYkhGg3IHo+sJBwL7ZVT0 Do8EhuM0U6k50QmCTjaEQoB57SY= X-Received: by 2002:a17:902:b7c8:: with SMTP id v8-v6mr4360335plz.45.1524670062887; Wed, 25 Apr 2018 08:27:42 -0700 (PDT) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id z62sm12017642pff.57.2018.04.25.08.27.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 08:27:40 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id C7340BE7; Wed, 25 Apr 2018 10:27:38 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 6C182301059; Wed, 25 Apr 2018 10:27:36 -0500 (CDT) From: minyard@acm.org To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 10:27:30 -0500 Message-Id: <1524670052-28373-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524670052-28373-1-git-send-email-minyard@acm.org> References: <1524670052-28373-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v3 1/3] vmstate: Add a VSTRUCT type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The VMS_STRUCT has no way to specify which version of a structure to use. Add a type and a new field to allow the specific version of a structure to be used. Signed-off-by: Corey Minyard --- include/migration/vmstate.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ migration/vmstate.c | 25 +++++++++++++++++++++---- 2 files changed, 66 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index df463fd..efa0a11 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -143,6 +143,11 @@ enum VMStateFlags { * to determine the number of entries in the array. Only valid in * combination with one of VMS_VARRAY*. */ VMS_MULTIPLY_ELEMENTS = 0x4000, + + /* A structure field that is like VMS_STRUCT, but uses + * VMStateField.struct_version_id to tell which version of the + * structure we are referencing to use. */ + VMS_VSTRUCT = 0x8000, }; typedef enum { @@ -167,6 +172,7 @@ struct VMStateField { enum VMStateFlags flags; const VMStateDescription *vmsd; int version_id; + int struct_version_id; bool (*field_exists)(void *opaque, int version_id); }; @@ -248,6 +254,25 @@ extern const VMStateInfo vmstate_info_qtailq; vmstate_offset_array(_state, _field, uint8_t, \ sizeof(typeof_field(_state, _field))) +/* In the macros below, if there is a _version, that means the macro's + * field will be processed only if the version being received is >= + * the _version specified. In general, if you add a new field, you + * would increment the structure's version and put that version + * number into the new field so it would only be processed with the + * new version. + * + * In particular, for VMSTATE_STRUCT() and friends the _version does + * *NOT* pick the version of the sub-structure. It works just as + * specified above. The version of the top-level structure received + * is passed down to all sub-structures. This means that the + * sub-structures must have version that are compatible with all the + * structures that use them. + * + * If you want to specify the version of the sub-structure, use + * VMSTATE_VSTRUCT(), which allows the specific sub-structure version + * to be directly specified. + */ + #define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -395,6 +420,17 @@ extern const VMStateInfo vmstate_info_qtailq; .offset = offsetof(_state, _field), \ } +#define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type, _struct_version) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .struct_version_id = (_struct_version), \ + .field_exists = (_test), \ + .vmsd = &(_vmsd), \ + .size = sizeof(_type), \ + .flags = VMS_VSTRUCT, \ + .offset = vmstate_offset_value(_state, _field, _type), \ +} + #define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \ @@ -712,6 +748,13 @@ extern const VMStateInfo vmstate_info_qtailq; #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) +#define VMSTATE_VSTRUCT(_field, _state, _vmsd, _type, _struct_version)\ + VMSTATE_VSTRUCT_TEST(_field, _state, NULL, 0, _vmsd, _type, _struct_version) + +#define VMSTATE_VSTRUCT_V(_field, _state, _version, _vmsd, _type, _struct_version) \ + VMSTATE_VSTRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type, \ + _struct_version) + #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) @@ -1000,6 +1043,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id); int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, QJSON *vmdesc); +int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, + void *opaque, QJSON *vmdesc, int version_id); bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); diff --git a/migration/vmstate.c b/migration/vmstate.c index 0b3282c..f0b07f4 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -136,6 +136,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, } else if (field->flags & VMS_STRUCT) { ret = vmstate_load_state(f, field->vmsd, curr_elem, field->vmsd->version_id); + } else if (field->flags & VMS_VSTRUCT) { + ret = vmstate_load_state(f, field->vmsd, curr_elem, + field->struct_version_id); } else { ret = field->info->get(f, curr_elem, size, field); } @@ -209,6 +212,8 @@ static const char *vmfield_get_type_name(VMStateField *field) if (field->flags & VMS_STRUCT) { type = "struct"; + } else if (field->flags & VMS_VSTRUCT) { + type = "vstruct"; } else if (field->info->name) { type = field->info->name; } @@ -309,7 +314,13 @@ bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque) int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, QJSON *vmdesc) + void *opaque, QJSON *vmdesc_id) +{ + return vmstate_save_state_v(f, vmsd, opaque, vmdesc_id, vmsd->version_id); +} + +int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, + void *opaque, QJSON *vmdesc, int version_id) { int ret = 0; VMStateField *field = vmsd->fields; @@ -327,13 +338,15 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, if (vmdesc) { json_prop_str(vmdesc, "vmsd_name", vmsd->name); - json_prop_int(vmdesc, "version", vmsd->version_id); + json_prop_int(vmdesc, "version", version_id); json_start_array(vmdesc, "fields"); } while (field->name) { - if (!field->field_exists || - field->field_exists(opaque, vmsd->version_id)) { + if ((field->field_exists && + field->field_exists(opaque, version_id)) || + (!field->field_exists && + field->version_id <= version_id)) { void *first_elem = opaque + field->offset; int i, n_elems = vmstate_n_elems(opaque, field); int size = vmstate_size(opaque, field); @@ -363,6 +376,10 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, } else if (field->flags & VMS_STRUCT) { ret = vmstate_save_state(f, field->vmsd, curr_elem, vmdesc_loop); + } else if (field->flags & VMS_VSTRUCT) { + ret = vmstate_save_state_v(f, field->vmsd, curr_elem, + vmdesc_loop, + field->struct_version_id); } else { ret = field->info->put(f, curr_elem, size, field, vmdesc_loop); From patchwork Wed Apr 25 15:27:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 134344 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1009107lji; Wed, 25 Apr 2018 08:30:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpScx500R6hsInsLEcBnx3Rc5cE/GqlUQb7YAkZhuCwIg+81datZnuJq7xttOvO1ja1i/RZ X-Received: by 10.55.203.5 with SMTP id d5mr31904778qkj.69.1524670204469; Wed, 25 Apr 2018 08:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524670204; cv=none; d=google.com; s=arc-20160816; b=ZmrB1ca0ZneVv7sAIJIM/Zv05rT0acUZgc6YL0LIRS+PtoEW0iGyFbN0Mqg10ZQCnF fSgNa4HyPkvMKQuUGeP8s6DZWVuXKCG/7J9PW6rucOTL0wt1DxXaCuXqm/z4waFmnn6r fjihuZnS1w2QhC0QYC2Sdq6AHu4PkObK2SCOKJU59csgqZsSmvsgTlrtoe5/rPvF7v4c 9d0aFoSR0ywWFibLDBTVmBKTV9S7B8p7g4tt8jNJIabVKQwnSX2QSsERKnDSBtdZ3w1/ pdKu6JuZg82GRmcd754kQJHxiL3xZhorCEzIxh3eZ2MGDHBYlR1+S3y5Rg4BZtcu6LRa prAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=qRjwqfmnz5HCJFH2ro3A8PV24E0H48sI0peirnUiF9M=; b=c5C/qWIQooviLRMSnNAjwqRRWZQ34arN9PgKZ9mMgoHjfMYy/nffxvhVDpTqG+0tfn nGM8QLCVxrE3V2FPib//NnZwwqIrnerEaSqvgKrR+nCXHmdzyC6ZB/AnOq2/mSr7cuqP qtK5/8Qh9wSwMZSeueYc+ER5xM7UCpn8D65whRqIrtYLJ7wSeb17xYKZGsbzKvfzfj9P iuHvmVw2ACX74aiPng8cbAeZEl7FcHQNz/MJuR6u2wyFd+LJnRrIAwE/fclc0fW74HZV QjclBUxfPark6pJrLMIpOy9vmnbrmta2O3VtUKcaWBqqgf0Vk5sAVSk8wFHO6GGoAV8D UxHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Bk1ADz0R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o63-v6si3859381qte.134.2018.04.25.08.30.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Apr 2018 08:30:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Bk1ADz0R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:37656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMMt-0003gG-VR for patch@linaro.org; Wed, 25 Apr 2018 11:30:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMKg-0001sM-23 for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBMKc-0007gB-QT for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:46 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:45473) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBMKc-0007f5-IU for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:42 -0400 Received: by mail-pf0-x242.google.com with SMTP id l27so15517474pfk.12 for ; Wed, 25 Apr 2018 08:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qRjwqfmnz5HCJFH2ro3A8PV24E0H48sI0peirnUiF9M=; b=Bk1ADz0RjG+Qx3pX06mSAdGXtKPJTOpL4KbExOLK0RT1kzDJzrCvIr241hmRok5E4X nIEjfFUK0nR/7lCFZ4urArIjW2TKYpYbnTLlJZx2oeIpMRzugUcsgg+yQBeVdOx4d3VF RBduMrwVMilQK62i1JBD9s+mBXoJJyDNKiNBBQ4skvFPOEv4ee0hiJIn9qTuBGan6t/f Dkckpd4hwyXFRTLu5CvT6Ju6PR47Fc3tPtIOliQaxLBd5VGoiUQiON9TybmKRQkj4Ku9 tfIZFOwwgCLqGm+oGg2Fgf+F+B5LjqClWV+Sdao9CnyS/rfgh7e5+layUgoQqEgkJOdl biAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qRjwqfmnz5HCJFH2ro3A8PV24E0H48sI0peirnUiF9M=; b=OuUWEqvD8v6Wwkh5xnDjM1e8BEFJs6SOn8F8/13Um/e4Ctg07bSh6JDj3u2/D/YPC8 VXDmfGK/06hoir96JSvW1wjrJHYb741OU5vcNMPqxPxCL2qosm5j5f3U3gFO7kzlgsE3 L/AjHEEzZNaBRmaWfqZytyaNP6Qo/Wu5zPE0w+1yWZe04yaszANPnp+8FJE1na6QXaUf E4Z9s77zuci+ThcA4ZNmDjzXq+Ao/IAm3vF77ua0oHHI0BrRj8JNZJAeviWd8HUpHgSi STK6QHE2/uhmh+CPFevK8+Vc/CWrCwOTyUV8MeOBBNjkrFv3Tuw3VwKQ+Ok26Qfhf5fD iF4A== X-Gm-Message-State: ALQs6tD93O1dpJTmke7CSupCkmcMfz/Ekp+EucAIBWj/dN6pFk7sRSJC yVCkJotT/pPoadh35VDOtQ== X-Received: by 2002:a17:902:30a3:: with SMTP id v32-v6mr29866109plb.123.1524670061126; Wed, 25 Apr 2018 08:27:41 -0700 (PDT) Received: from serve.minyard.net ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id p5sm3542911pgv.90.2018.04.25.08.27.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 08:27:40 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id BC474B99; Wed, 25 Apr 2018 10:27:38 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 5BA2430105A; Wed, 25 Apr 2018 10:27:37 -0500 (CDT) From: minyard@acm.org To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 10:27:31 -0500 Message-Id: <1524670052-28373-3-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524670052-28373-1-git-send-email-minyard@acm.org> References: <1524670052-28373-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH v3 2/3] ipmi: Use proper struct reference for KCS vmstate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The vmstate for isa_ipmi_kcs was referencing into the kcs structure, instead create a kcs structure separate and use that. There were also some issues in the state transfer. The inlen field was not being transferred, so if a transaction was in process during the transfer it would be messed up. And the use_irq field was transferred, but that should come from the configuration. To fix this, the new VMS_VSTRUCT macros are used so the exact version of the structure can be specified, depending on what version was being received. So an upgrade should work for KCS. Signed-off-by: Corey Minyard Cc: Dr. David Alan Gilbert --- hw/ipmi/isa_ipmi_kcs.c | 81 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 15 deletions(-) -- 2.7.4 diff --git a/hw/ipmi/isa_ipmi_kcs.c b/hw/ipmi/isa_ipmi_kcs.c index 689587b..a794315 100644 --- a/hw/ipmi/isa_ipmi_kcs.c +++ b/hw/ipmi/isa_ipmi_kcs.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "qapi/error.h" #include "hw/hw.h" #include "hw/ipmi/ipmi.h" @@ -422,24 +423,69 @@ static void ipmi_isa_realize(DeviceState *dev, Error **errp) isa_register_ioport(isadev, &iik->kcs.io, iik->kcs.io_base); } -const VMStateDescription vmstate_ISAIPMIKCSDevice = { +static int ipmi_kcs_vmstate_post_load(void *opaque, int version) +{ + IPMIKCS *ik = opaque; + + /* Make sure all the values are sane. */ + if (ik->outpos >= MAX_IPMI_MSG_SIZE || ik->outlen >= MAX_IPMI_MSG_SIZE || + ik->outpos >= ik->outlen) { + qemu_log_mask(LOG_GUEST_ERROR, + "ipmi:kcs: vmstate transfer received bad out values: %d %d\n", + ik->outpos, ik->outlen); + ik->outpos = 0; + ik->outlen = 0; + } + + if (ik->inlen >= MAX_IPMI_MSG_SIZE) { + qemu_log_mask(LOG_GUEST_ERROR, + "ipmi:kcs: vmstate transfer received bad in value: %d\n", + ik->inlen); + ik->inlen = 0; + } + + return 0; +} + +static bool vmstate_kcs_before_version2(void *opaque, int version) +{ + return version <= 1; +} + +static const VMStateDescription vmstate_IPMIKCS = { + .name = TYPE_IPMI_INTERFACE_PREFIX "kcs", + .version_id = 2, + .minimum_version_id = 1, + .post_load = ipmi_kcs_vmstate_post_load, + .fields = (VMStateField[]) { + VMSTATE_BOOL(obf_irq_set, IPMIKCS), + VMSTATE_BOOL(atn_irq_set, IPMIKCS), + VMSTATE_UNUSED_TEST(vmstate_kcs_before_version2, 1), /* Was use_irq */ + VMSTATE_BOOL(irqs_enabled, IPMIKCS), + VMSTATE_UINT32(outpos, IPMIKCS), + VMSTATE_UINT32_V(outlen, IPMIKCS, 2), + VMSTATE_UINT8_ARRAY(outmsg, IPMIKCS, MAX_IPMI_MSG_SIZE), + VMSTATE_UINT32_V(inlen, IPMIKCS, 2), + VMSTATE_UINT8_ARRAY(inmsg, IPMIKCS, MAX_IPMI_MSG_SIZE), + VMSTATE_BOOL(write_end, IPMIKCS), + VMSTATE_UINT8(status_reg, IPMIKCS), + VMSTATE_UINT8(data_out_reg, IPMIKCS), + VMSTATE_INT16(data_in_reg, IPMIKCS), + VMSTATE_INT16(cmd_reg, IPMIKCS), + VMSTATE_UINT8(waiting_rsp, IPMIKCS), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_ISAIPMIKCSDevice = { .name = TYPE_IPMI_INTERFACE, - .version_id = 1, + .version_id = 2, .minimum_version_id = 1, .fields = (VMStateField[]) { - VMSTATE_BOOL(kcs.obf_irq_set, ISAIPMIKCSDevice), - VMSTATE_BOOL(kcs.atn_irq_set, ISAIPMIKCSDevice), - VMSTATE_BOOL(kcs.use_irq, ISAIPMIKCSDevice), - VMSTATE_BOOL(kcs.irqs_enabled, ISAIPMIKCSDevice), - VMSTATE_UINT32(kcs.outpos, ISAIPMIKCSDevice), - VMSTATE_UINT8_ARRAY(kcs.outmsg, ISAIPMIKCSDevice, MAX_IPMI_MSG_SIZE), - VMSTATE_UINT8_ARRAY(kcs.inmsg, ISAIPMIKCSDevice, MAX_IPMI_MSG_SIZE), - VMSTATE_BOOL(kcs.write_end, ISAIPMIKCSDevice), - VMSTATE_UINT8(kcs.status_reg, ISAIPMIKCSDevice), - VMSTATE_UINT8(kcs.data_out_reg, ISAIPMIKCSDevice), - VMSTATE_INT16(kcs.data_in_reg, ISAIPMIKCSDevice), - VMSTATE_INT16(kcs.cmd_reg, ISAIPMIKCSDevice), - VMSTATE_UINT8(kcs.waiting_rsp, ISAIPMIKCSDevice), + VMSTATE_VSTRUCT_TEST(kcs, ISAIPMIKCSDevice, vmstate_kcs_before_version2, + 0, vmstate_IPMIKCS, IPMIKCS, 1), + VMSTATE_VSTRUCT_V(kcs, ISAIPMIKCSDevice, 2, vmstate_IPMIKCS, + IPMIKCS, 2), VMSTATE_END_OF_LIST() } }; @@ -450,6 +496,11 @@ static void isa_ipmi_kcs_init(Object *obj) ipmi_bmc_find_and_link(obj, (Object **) &iik->kcs.bmc); + /* + * Version 1 had an incorrect name, it clashed with the BT + * IPMI device, so receive it, but transmit a different + * version. + */ vmstate_register(NULL, 0, &vmstate_ISAIPMIKCSDevice, iik); } From patchwork Wed Apr 25 15:27:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 134345 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1012774lji; Wed, 25 Apr 2018 08:32:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqJ0gbN34nZli6WbdQTUkIGP7H0fvrlQ1AYbfpbI3XWl27pQsqT5rz6pq9HdV8Lg/thjhbA X-Received: by 2002:ac8:cc9:: with SMTP id o9-v6mr32259409qti.363.1524670366275; Wed, 25 Apr 2018 08:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524670366; cv=none; d=google.com; s=arc-20160816; b=H/WIuRM1iriUwPJwOv0bEasawtAgKNQ7a3l8SQ0N8k6gShRcDnsWMRn6oNXC2VrHcC vmQSW6VTZSWjzZIrqMO3qd/aXrkz2EQthbuqWBebZrDa70IhCetZq/JNDhGbvqHiU+Dr snn91+LPngbNgprMLrZoR7ZHSlVrD+JGiAE/Vwa13KLNJ5h1nx5ipF7ciJJ9m3NHb6+B E2aQc3oEEPB6ucNiI3M+3YwDFPevyMDce2hDu00gILV1DNuRldoH/a/R5oJ0hzhotMZJ Dz1AvEHHTZdJyMhvctbkpbq3fD8g6TsjT4/ePuCTDEAOb7L5IYyqDh/awjiL89FDxjMP /D/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=t0Yg3MxSVl5Mjb4J+J6NcyU4CPbFnTECuSysfNKM/lw=; b=JadGmRTlYLEMfFFrn5hUlQ12eg50lU1N55LJDC+3q70HzXs84XxcqTzQbcG27eqWqq VAcYViskup+5NUoVvjHTyfvACm4IbaOP+AG0O2zOpOxz65C5Esx2n43bWv7YhYddMHhB c39S6+9s8EzphyZgBNFDXfIaXGpuRD/ZCsJik44ZaW2WSMRH4NLlXRGp/yT7KvCB7nUu sxtHFXn+cSGEUiXVEXVt9KBQa7EZNkklwq6obPU5HFVVNOG4Wi8uBj/qo6SavVC++RHG zLZVdzUQojp+Am8RPNwVIxDXhQ10qV+NZDq3ajO1zKe55WHbdrEwOE6pPEwokkAHh5Q2 yVNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=u/KC1EZr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j22si10567669qkk.264.2018.04.25.08.32.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Apr 2018 08:32:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=u/KC1EZr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:37669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMPV-0005EH-Mv for patch@linaro.org; Wed, 25 Apr 2018 11:32:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMKg-0001sR-65 for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBMKe-0007jh-PU for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:46 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:34111) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBMKe-0007hw-H1 for qemu-devel@nongnu.org; Wed, 25 Apr 2018 11:27:44 -0400 Received: by mail-pg0-x244.google.com with SMTP id p10so13583366pgn.1 for ; Wed, 25 Apr 2018 08:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=t0Yg3MxSVl5Mjb4J+J6NcyU4CPbFnTECuSysfNKM/lw=; b=u/KC1EZrAc+fW/pm+CfqJo+dqrCE1Aqx4Byiewk7kkAKBR/dgET8/bnPh831QHefFX Z8dEpsvW4hYFENu/C5jN/pSFBUcYiO/dz68ICI21c6oXahDHt3jpv6zfutn93zIGeVNx m+u11CZ05Jyb42h1/sMmyfxhpTeZP2At5jsPnea43oClTDjyqX3Wvl+DvO/bakKqgYh7 TdXLfQVIguVd5dTHWdN3bsAHe6LUBbz32NNA6y/zj/dW+LArxndYh1fTmNTgMUy9KNSi YSguF0I4sc3k0cYIGyMk6yBLeGeH+IlX/1rCW5rMBtbPe6QX82gzpVMb28rPlr4817In 07lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=t0Yg3MxSVl5Mjb4J+J6NcyU4CPbFnTECuSysfNKM/lw=; b=pYJO9SAF1gx/FkYh440JjUOlJsq2s1QrjrFF/xEGgCJQ1FnfJZhxtx+oVmQUduq4PP DnD0ajmcwQhIPdj9uWsHQgCoanmXCrRQ1Zsy3GYyu7QqPyJvu4p0htcbFW3bxIOJ3G2j iMufC32PkcfK0a7jRkQf8xvwOjnHjG3Vrc4KizivF2LR6t03CkHTR2JWbZsFfF6EcJhZ c56amWJspJ+mPqJPhs10lqoiqARDkLca2aUczxpoKuRRn9TCTeRVORqG8+LKWye2CiPV iitCSP42i1Pop1N+MX2hyMB6Oq9dbFm/+KHI/NTXu4gYR8cAAelP6EIWrrYKaWYv/L0C FWfQ== X-Gm-Message-State: ALQs6tD/NlNNH2vETfbvlxEoqCvc6WkBSabGF7FPaWj0itnJYyGdOQT8 b7aN0xAYguBjrqFbhZZqSg== X-Received: by 2002:a17:902:5329:: with SMTP id b38-v6mr25290707pli.326.1524670063521; Wed, 25 Apr 2018 08:27:43 -0700 (PDT) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id k126sm38107405pfc.142.2018.04.25.08.27.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 08:27:41 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id A34EB304; Wed, 25 Apr 2018 10:27:38 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 491DE3000C0; Wed, 25 Apr 2018 10:27:37 -0500 (CDT) From: minyard@acm.org To: "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 10:27:32 -0500 Message-Id: <1524670052-28373-4-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524670052-28373-1-git-send-email-minyard@acm.org> References: <1524670052-28373-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v3 3/3] ipmi: Use proper struct reference for BT vmstate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The vmstate for isa_ipmi_bt was referencing into the bt structure, instead create a bt structure separate and use that. The version 1 of the BT transfer was fairly broken, if a migration occured during an IPMI operation, it is likely the migration would be corrupted because I misunderstood the VMSTATE_VBUFFER_UINT32() handling, I thought it handled transferring the length field, too. So I just remove support for that. I doubt anyone is using it at this point. This also removes the transfer of use_irq, since that should come from configuration. Signed-off-by: Corey Minyard Signed-off-by: Dr. David Alan Gilbert --- hw/ipmi/isa_ipmi_bt.c | 68 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/hw/ipmi/isa_ipmi_bt.c b/hw/ipmi/isa_ipmi_bt.c index e946030..8bbb1fa 100644 --- a/hw/ipmi/isa_ipmi_bt.c +++ b/hw/ipmi/isa_ipmi_bt.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "qapi/error.h" #include "hw/hw.h" #include "hw/ipmi/ipmi.h" @@ -450,22 +451,63 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp) isa_register_ioport(isadev, &iib->bt.io, iib->bt.io_base); } -static const VMStateDescription vmstate_ISAIPMIBTDevice = { - .name = TYPE_IPMI_INTERFACE, +static int ipmi_bt_vmstate_post_load(void *opaque, int version) +{ + IPMIBT *ib = opaque; + + /* Make sure all the values are sane. */ + if (ib->outpos >= MAX_IPMI_MSG_SIZE || ib->outlen >= MAX_IPMI_MSG_SIZE || + ib->outpos >= ib->outlen) { + qemu_log_mask(LOG_GUEST_ERROR, + "ipmi:bt: vmstate transfer received bad out values: %d %d\n", + ib->outpos, ib->outlen); + ib->outpos = 0; + ib->outlen = 0; + } + + if (ib->inlen >= MAX_IPMI_MSG_SIZE) { + qemu_log_mask(LOG_GUEST_ERROR, + "ipmi:bt: vmstate transfer received bad in value: %d\n", + ib->inlen); + ib->inlen = 0; + } + + return 0; +} + +const VMStateDescription vmstate_IPMIBT = { + .name = TYPE_IPMI_INTERFACE_PREFIX "bt", .version_id = 1, .minimum_version_id = 1, + .post_load = ipmi_bt_vmstate_post_load, + .fields = (VMStateField[]) { + VMSTATE_BOOL(obf_irq_set, IPMIBT), + VMSTATE_BOOL(atn_irq_set, IPMIBT), + VMSTATE_BOOL(irqs_enabled, IPMIBT), + VMSTATE_UINT32(outpos, IPMIBT), + VMSTATE_UINT32(outlen, IPMIBT), + VMSTATE_UINT8_ARRAY(outmsg, IPMIBT, MAX_IPMI_MSG_SIZE), + VMSTATE_UINT32(inlen, IPMIBT), + VMSTATE_UINT8_ARRAY(inmsg, IPMIBT, MAX_IPMI_MSG_SIZE), + VMSTATE_UINT8(control_reg, IPMIBT), + VMSTATE_UINT8(mask_reg, IPMIBT), + VMSTATE_UINT8(waiting_rsp, IPMIBT), + VMSTATE_UINT8(waiting_seq, IPMIBT), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_ISAIPMIBTDevice = { + .name = TYPE_IPMI_INTERFACE_PREFIX "isa-bt", + .version_id = 2, + .minimum_version_id = 2, + /* + * Version 1 had messed up the array transfer, it's not even usable + * because it used VMSTATE_VBUFFER_UINT32, but it did not transfer + * the buffer length, so random things would happen. + */ .fields = (VMStateField[]) { - VMSTATE_BOOL(bt.obf_irq_set, ISAIPMIBTDevice), - VMSTATE_BOOL(bt.atn_irq_set, ISAIPMIBTDevice), - VMSTATE_BOOL(bt.use_irq, ISAIPMIBTDevice), - VMSTATE_BOOL(bt.irqs_enabled, ISAIPMIBTDevice), - VMSTATE_UINT32(bt.outpos, ISAIPMIBTDevice), - VMSTATE_VBUFFER_UINT32(bt.outmsg, ISAIPMIBTDevice, 1, NULL, bt.outlen), - VMSTATE_VBUFFER_UINT32(bt.inmsg, ISAIPMIBTDevice, 1, NULL, bt.inlen), - VMSTATE_UINT8(bt.control_reg, ISAIPMIBTDevice), - VMSTATE_UINT8(bt.mask_reg, ISAIPMIBTDevice), - VMSTATE_UINT8(bt.waiting_rsp, ISAIPMIBTDevice), - VMSTATE_UINT8(bt.waiting_seq, ISAIPMIBTDevice), + VMSTATE_STRUCT(bt, ISAIPMIBTDevice, 1, vmstate_IPMIBT, IPMIBT), VMSTATE_END_OF_LIST() } };