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: 10255003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 596106037F for ; Fri, 2 Mar 2018 15:27:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 482A2288CD for ; Fri, 2 Mar 2018 15:27:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CFC0288FC; Fri, 2 Mar 2018 15:27:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 85EED288CD for ; Fri, 2 Mar 2018 15:27:58 +0000 (UTC) Received: from localhost ([::1]:35915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ermbF-0005wO-O5 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 02 Mar 2018 10:27:57 -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-Google-Smtp-Source: AG47ELt/MrVjsyVYt9bXPkXwzhfzlbmtolJLoR26b04KsCU2twNOBSvDYqkkGKbXIp+CYyYXtGr/vw== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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)