From patchwork Fri Mar 2 15:26:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 130559 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1396830lja; Fri, 2 Mar 2018 07:28:59 -0800 (PST) X-Google-Smtp-Source: AG47ELunYyKop+q11ygSv6pBTjIsQG71zehNYqZ4m4DcKh/Y0/p8dLmmgMzOpeGJ1pCj8h0tywI+ X-Received: by 2002:a25:c6d3:: with SMTP id k202-v6mr1103683ybf.269.1520004539270; Fri, 02 Mar 2018 07:28:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520004539; cv=none; d=google.com; s=arc-20160816; b=DMWk8I8aX0PnX/6br4DdJQ87s2mHD/FzNq+69SUCOXKR78beOplLxrQj0EeTSbr6AN pa0xR/q7wNTWG7BGYlZ4EaYbZwZ6nSIdwt+0DlvsoTFbUierGFPyxAKJ3dZufxmboKU/ q2xyWW4CDYaZop2xdPp5WFUcVtH7ba9s0IZ80alV15wDfRECUsMQPrlpuXBS4F6gzB/h IqOsZ+/5V+WTxbqeyvHx5Lel6JXJjAxg95XsBG6KdxSwDol/gb8XcQ2RVUC1n5wYfPmH YyqrJvwpBEbAwbokNkRRcKKJGU76I8BWeCzK2t3eANG4bY8yNes/0oe5BLy78BwF9fji qiCA== 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=M5d+tyFIlbfw72o2CoRuK3fqwH2wjZqt4/GUEETwgYg=; b=o4iGUpsaDM89QSeoixviMGjWjQCwkFMyRhTV4tglI65Cgg9TZBLIS0VsaDBh6j6H4I /WfC9eibSCCSB1qbD0sRDEBwMDl8ARYAQdWOk369ToqmeG3f0//iRSNXy1eJPogGla4u 6xDLDOvjwqWFXiBGjMlR/dTqSUhagqXD7Daw43rY8WTXEbT3v2ioDqTiaSruSdCe/yjv 7h1DbsJeAfSV8R3lubBfY+BdFeRkz6RNFWFWRcUlpmIGQRKtuqcbN8ui/khK47HJZIkQ nWagk4eBf0Oj1Sa0MJO568jIL5zdlusGer1zg+lhJBVfUMqjjcm/PZ78I+zRTcyilLPT zSrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TNAd29W9; 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 p4-v6si318122ybg.586.2018.03.02.07.28.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Mar 2018 07:28:59 -0800 (PST) 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=TNAd29W9; 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]:35915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ermcE-0005wO-LA for patch@linaro.org; Fri, 02 Mar 2018 10:28:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erma8-00050G-8F for qemu-devel@nongnu.org; Fri, 02 Mar 2018 10:26:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erma6-0005Ku-TJ for qemu-devel@nongnu.org; Fri, 02 Mar 2018 10:26:48 -0500 Received: from mail-ot0-x241.google.com ([2607:f8b0:4003:c0f::241]:42614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1erma6-0005Jo-MX for qemu-devel@nongnu.org; Fri, 02 Mar 2018 10:26:46 -0500 Received: by mail-ot0-x241.google.com with SMTP id l5so9007452otf.9 for ; Fri, 02 Mar 2018 07:26:46 -0800 (PST) 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=M5d+tyFIlbfw72o2CoRuK3fqwH2wjZqt4/GUEETwgYg=; b=TNAd29W9mvgYi1+k6VY4xSrG0nMywo68+hXeQ0xtzR/cpWwX9hgxv+aKGhs3P9Lngv oDeGgiCK2RtXEOVwhMDBaZrNROZo4vqRgopm4bWeui0O8jiHJLaulperV56rDhtDrlkW icGufalI8iY6FQ5JdWC5+lXJllu/0qsGH6Xg8B8iuqu9EJ6nep4hrdXjVMlKPtXwt2tk BQ+7rWJTIyFdjQXoNFlfIaUiZj6sckItYmvV/kiuUWExa7VuFJZm7U3mus10oKFgVg0a 7l+vpXGp7zpDykI3xdYVExDYcnoYyqzzo9H6vzhgNAkEZuKU27LghUhXGhn/OE9oS5up WQ3Q== 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=M5d+tyFIlbfw72o2CoRuK3fqwH2wjZqt4/GUEETwgYg=; b=bYAOoiJUu6BGxWVOgn/BUPFXtkt5o4cB+RIWrYL2TbPSqqH0qnRpm/z90r0n3DVf6A NkmpjUCiRALVZ08h18VBUVhFTo9y0w6IutAr+ztNtmnMaBskZuuMY0Ld9bA0YGz9Tlpa 6QGGLTAGIIOXk65dN3DHH6w2IuO89jYplKYfGnFQti8Fx7Gh50iIVrdlHZHsxzOnzclf FkRFrwm04j/l2U/MXccmCD5lvv+U4jsv1ISR6xdKKhKm2A3ljTM7Gri/PDgAi6WrUaOL CzkDH5WnMO7/Ai5U8nf5MredwjFk5QfsbjFgzhKHNTJ2VgRRkdaw4flM6yiujREIvn/B c/Vg== X-Gm-Message-State: APf1xPDKKzDsIjbdU0743HvmUA+a0m6ZNtsVU1WTavWzZjZPuP4wczVQ i29BPApXcIySBy6sFOwokg== X-Received: by 10.157.71.149 with SMTP id b21mr4096084otf.130.1520004405454; Fri, 02 Mar 2018 07:26:45 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id y23sm3387843otj.29.2018.03.02.07.26.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 07:26:43 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 187F8781; Fri, 2 Mar 2018 09:26:43 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 6331B300060; Fri, 2 Mar 2018 09:26:42 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, Peter Maydell Date: Fri, 2 Mar 2018 09:26:36 -0600 Message-Id: <1520004397-28521-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520004397-28521-1-git-send-email-minyard@acm.org> References: <1520004397-28521-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:4003:c0f::241 Subject: [Qemu-devel] [PATCH v2 1/2] 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 , "Dr . David Alan Gilbert" 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. And the name on the man VMStateDescription was incorrect, it needed to be differentiated from the BT one. To fix this, a new VMStateDescription is added that is hopefully correct, and the old one is kept (modified to remove use_irq) in a way that it can be received from the remote but will not be sent. So an upgrade should work for KCS. Signed-off-by: Corey Minyard Cc: Dr. David Alan Gilbert --- hw/ipmi/isa_ipmi_kcs.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/hw/ipmi/isa_ipmi_kcs.c b/hw/ipmi/isa_ipmi_kcs.c index 689587b..2a2784d 100644 --- a/hw/ipmi/isa_ipmi_kcs.c +++ b/hw/ipmi/isa_ipmi_kcs.c @@ -422,14 +422,86 @@ 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) { + ik->outpos = 0; + ik->outlen = 0; + } + + if (ik->inlen >= MAX_IPMI_MSG_SIZE) { + ik->inlen = 0; + } + + return 0; +} + +static const VMStateDescription vmstate_IPMIKCS = { + .name = TYPE_IPMI_INTERFACE_PREFIX "kcs", + .version_id = 1, + .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_BOOL(irqs_enabled, IPMIKCS), + VMSTATE_UINT32(outpos, IPMIKCS), + VMSTATE_UINT32(outlen, IPMIKCS), + VMSTATE_UINT8_ARRAY(outmsg, IPMIKCS, MAX_IPMI_MSG_SIZE), + VMSTATE_UINT32(inlen, IPMIKCS), + 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_PREFIX "isa-kcs", + .version_id = 2, + .minimum_version_id = 2, + .fields = (VMStateField[]) { + VMSTATE_STRUCT(kcs, ISAIPMIKCSDevice, 1, vmstate_IPMIKCS, IPMIKCS), + VMSTATE_END_OF_LIST() + } +}; + +/* + * Old version of the vmstate transfer that has a number of issues. + * We changed the vm state description name, so we need a separate + * structure and need to register it separately. + */ +static int ipmi_kcs_v1_vmstate_post_load(void *opaque, int version) +{ + ISAIPMIKCSDevice *iik = opaque; + + return ipmi_kcs_vmstate_post_load(&iik->kcs, version); +} + +static bool ipmi_kcs_v1_vmstate_needed(void *opaque) +{ + /* Never transmit this, it is just for receiving old versions. */ + return false; +} + +const VMStateDescription vmstate_v1_ISAIPMIKCSDevice = { .name = TYPE_IPMI_INTERFACE, .version_id = 1, .minimum_version_id = 1, + .post_load = ipmi_kcs_v1_vmstate_post_load, + .needed = ipmi_kcs_v1_vmstate_needed, .fields = (VMStateField[]) { VMSTATE_BOOL(kcs.obf_irq_set, ISAIPMIKCSDevice), VMSTATE_BOOL(kcs.atn_irq_set, ISAIPMIKCSDevice), - VMSTATE_BOOL(kcs.use_irq, ISAIPMIKCSDevice), + VMSTATE_UNUSED(1), /* Was use_irq */ VMSTATE_BOOL(kcs.irqs_enabled, ISAIPMIKCSDevice), VMSTATE_UINT32(kcs.outpos, ISAIPMIKCSDevice), VMSTATE_UINT8_ARRAY(kcs.outmsg, ISAIPMIKCSDevice, MAX_IPMI_MSG_SIZE), @@ -451,6 +523,7 @@ static void isa_ipmi_kcs_init(Object *obj) ipmi_bmc_find_and_link(obj, (Object **) &iik->kcs.bmc); vmstate_register(NULL, 0, &vmstate_ISAIPMIKCSDevice, iik); + vmstate_register(NULL, 0, &vmstate_v1_ISAIPMIKCSDevice, iik); } static void *isa_ipmi_kcs_get_backend_data(IPMIInterface *ii) From patchwork Fri Mar 2 15:26:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 130560 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1396846lja; Fri, 2 Mar 2018 07:29:00 -0800 (PST) X-Google-Smtp-Source: AG47ELvJ22dxzECiXDgAg38VVWVU4sWBuseKDUWYuKBxLGQldDq7lYPwpJ4eUXNJF2H/TNM5ILvb X-Received: by 10.13.226.67 with SMTP id l64mr4008472ywe.502.1520004540218; Fri, 02 Mar 2018 07:29:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520004540; cv=none; d=google.com; s=arc-20160816; b=e6hE/X/8jC2C+sy3UMctgy6tPl1XdTrjZXKXUAF9VaOeLSvUWmuQTgrHgQ9IU6vu8s hvwvMAxtSHiO7B62Y98Rs1WQovtaNoL0w5HoPv1Ik+x8hxezFaB35ZtQS1RA+zdYy3uO c801yqK5T2NJEeciTIYkNb9WEPu1Mz17J3vJuxRep0rI34R5pwrnmWYg/loO5qq7IYcA GxmiEajCQuLxYAQCwSCUZ58Gi/iibxCVd1qP+wDiJs2sF9DooXOyiiDgbogldY672rAl LzqhyuOxf5RvitRkbKCTEnDNqtt6hpekLPzj5rQdy3JZXh4GSM3Pbv5me/uMPfluRB3S FSww== 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=xW43wuybE/Gh5PTxm4i4/rWSx+RsfVayvLsI/2XKrvQ=; b=Nk6B++JJxSoLzcOS4TB70trdO634l5C1RvRgJ5iUyc9+slHIH7A+2JTdRc1Um1nF2n fuwyQxTX7y+oAq2+zDcf3L52PHtE4DHGAFg4w4SoUyryYyET7oCVpanSQY7xP3FFEdWU 4mzexYzW8qj5ZLTeZHfpbKT2tXpd8cmRzWJXZgdPyL0ZglnhQUEv0liyioLBFqRSDTbx vrApGVsLB49A3dRqF8HLy9e6z4A01BIyX7CcFtyug3rVJcPhFJI/UClsPRVGA8KrOORl MTu7GR7IeJKJeDFPGT+cnI/0pYFX/w7oOYareTJ88um290M75+XWZsfGSjR5lEBRyU5r lkSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Rvy94dPy; 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 u189si1109475ywc.558.2018.03.02.07.28.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Mar 2018 07:29:00 -0800 (PST) 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=Rvy94dPy; 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]:35916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ermcF-0005yB-Gp for patch@linaro.org; Fri, 02 Mar 2018 10:28:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ermaB-00051f-G6 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 10:26:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erma8-0005Lt-AI for qemu-devel@nongnu.org; Fri, 02 Mar 2018 10:26:51 -0500 Received: from mail-oi0-x241.google.com ([2607:f8b0:4003:c06::241]:33857) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1erma8-0005Lg-4W for qemu-devel@nongnu.org; Fri, 02 Mar 2018 10:26:48 -0500 Received: by mail-oi0-x241.google.com with SMTP id c83so7288615oib.1 for ; Fri, 02 Mar 2018 07:26:48 -0800 (PST) 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=xW43wuybE/Gh5PTxm4i4/rWSx+RsfVayvLsI/2XKrvQ=; b=Rvy94dPybDhsFHxYMRJ/HGCuU2VgYHKdT2NP0F2REUH1f7ZsLOxCvo3hlE4WFbz4dl ecI+KMrlRQmG5KGg/4O4Ww2WahmkiL/a0FXVbl2CwKS8t9pr6tO7BaJ63s22iI4HPniG wiwfbZxxfr4jhNkypMe+8M2ojE+Xh/GZhEdXPc+anIG2+rryNR6ETp6aFN9YANueFitC die8+NZaHsXUrr27y3OeHIDuL0SDz1GUmJkWgGrQS/zvQcV4//GRafoZZV/SSDTlUkh/ XGWlnfVbm/KX12aqrp3hLuW8/XuSbF1ykccRvSlYXYQARTT0/hv37PaMFucjI+H911eW vgBg== 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=xW43wuybE/Gh5PTxm4i4/rWSx+RsfVayvLsI/2XKrvQ=; b=Np6bHjSALXLFsFml582F85OJ57F06njdM+6Vps7kzqHvRnPXEiag+VCfY6b19hQyvP UWn9lnWkRY85wKqHXKi9x5duhla/NRlSs9fFIivnqxzhvS4O03lkrNyPSoIy8FmrM2Ei j/myLeQM23xe7VV0+tV9P2PcVINH92WH+TiADYBNVsbpv9ceOq4p2/dgVMArr4lafJKv JwjAsLDFFlp830cLqU3wpH2iF41uXIn0h9GxShIbFLTBCl0fuVMJHJJstljNYG/VvDpx g9s6SHCDYq7KAGDYxTqonGJwYWH2L4R92w5i47mDJGUlqI/tweyJNYBKPjyZOfMabbx5 mUnQ== X-Gm-Message-State: AElRT7GJaR2k5OlPoDAFHxVEV0aDxa2/KbEMSIX4uVINTK1HdBf9Co2m OirK1kc9NrUZiFSqKqiiMQ== X-Received: by 10.202.208.92 with SMTP id h89mr3777371oig.126.1520004407301; Fri, 02 Mar 2018 07:26:47 -0800 (PST) Received: from serve.minyard.net ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id d143sm3357101oih.46.2018.03.02.07.26.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 07:26:44 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 31115966; Fri, 2 Mar 2018 09:26:43 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 6E1773000A9; Fri, 2 Mar 2018 09:26:42 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, Peter Maydell Date: Fri, 2 Mar 2018 09:26:37 -0600 Message-Id: <1520004397-28521-3-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520004397-28521-1-git-send-email-minyard@acm.org> References: <1520004397-28521-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:4003:c06::241 Subject: [Qemu-devel] [PATCH v2 2/2] 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 , "Dr . David Alan Gilbert" 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 Cc: Dr. David Alan Gilbert --- hw/ipmi/isa_ipmi_bt.c | 61 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 13 deletions(-) -- 2.7.4 Reviewed-by: Dr. David Alan Gilbert diff --git a/hw/ipmi/isa_ipmi_bt.c b/hw/ipmi/isa_ipmi_bt.c index e946030..b64dce2 100644 --- a/hw/ipmi/isa_ipmi_bt.c +++ b/hw/ipmi/isa_ipmi_bt.c @@ -450,22 +450,57 @@ 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) { + ib->outpos = 0; + ib->outlen = 0; + } + + if (ib->inlen >= MAX_IPMI_MSG_SIZE) { + 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() } };