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); }