From patchwork Wed Feb 14 18:23:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10219641 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 A1CBE601D7 for ; Wed, 14 Feb 2018 18:25:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82CA329049 for ; Wed, 14 Feb 2018 18:25:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75E692904A; Wed, 14 Feb 2018 18:25:18 +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 D191D29046 for ; Wed, 14 Feb 2018 18:25:17 +0000 (UTC) Received: from localhost ([::1]:46968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1em1k5-0001Vb-3A for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Feb 2018 13:25:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1em1io-0000CO-U1 for qemu-devel@nongnu.org; Wed, 14 Feb 2018 13:24:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1em1im-0003zV-Ep for qemu-devel@nongnu.org; Wed, 14 Feb 2018 13:23:58 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:34496) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1em1im-0003z0-6V for qemu-devel@nongnu.org; Wed, 14 Feb 2018 13:23:56 -0500 Received: by mail-pg0-x243.google.com with SMTP id m19so2255274pgn.1 for ; Wed, 14 Feb 2018 10:23:56 -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=sFSw0jpmcjPZqzBtPBjCfbu2BuDoa81OEZWw9pWE+cMfpjwwJrWvn9M44V/QHhdKwG fLendLkhFoYOUe8MhYnU9k9YeTKbdkCPkVLz0deFGz1MC5vzetOjyQk0cOwVTK0R2QvX IVXQHk6AKrFxd/Ph0hi0BLy+OUGz1Xt7V5jjFubSsSrntic6bpY09NLUN6cN9r8IoO07 xQ4ja07osNtwxDJj8xOEfUkYi678laT1n+QcUI/ky+7xT0xPwp0TPUbGKBNaNE0oHsqh aclp1w9Wi8wf/ZZvUhD1Cz/srLcu50CQw90sJpzt5vHuZTgaKEp4fjndK01S17GVlwDd 55kA== 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=nQzJR/JHbLiSZBZCN+Saxl1JbY3zFSKlw6MPkwNV++hLKlE4hRSulHqGq2LVGs0gsZ 6ebxFM/vJriT2ykcA+tJRKWZuSSrmS+FMuGYrljPMuQXlTRzZUBKL7dtwXz1fquYtFnU u6ehCNsqPLC3Qk+pjMYpmQRCQR9idK1izgAxce6wDGuMs1Or2m5JGPgHLA70pFWre5jT IVdw8e1+SrupjUxuQ176GMUMlw3uYDQMKjgRmvgEUtkn6YHdPnYZALTVS5Pzq9TO2OWM PuGQzq/yKSxmnkKoHwCf/nozfTXvXG9Coy/Ecuwn1GSebHujVIxnq9xRXxEx8tDBLNw/ mJNA== X-Gm-Message-State: APf1xPATe20xShzPXTL+L8dq4noNJ4IuSmS9huFT/ybF2ySUIgJDqtJ2 NDPl+ERGIQHK0mGsVn4jpUaRpb4= X-Google-Smtp-Source: AH8x225kx0vFlMYhCgae7E5jnSxgituGDs8y4h4sy9dto/MXGZRKyOw8gC2jWbW7/9XwTmzSb0r3NA== X-Received: by 10.99.107.198 with SMTP id g189mr67340pgc.299.1518632635134; Wed, 14 Feb 2018 10:23:55 -0800 (PST) Received: from serve.minyard.net ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id c16sm14739499pfe.182.2018.02.14.10.23.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Feb 2018 10:23:52 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id EE9EA8C7; Wed, 14 Feb 2018 12:23:50 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 7170B300966; Wed, 14 Feb 2018 12:23:49 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 14 Feb 2018 12:23:43 -0600 Message-Id: <1518632624-29965-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518632624-29965-1-git-send-email-minyard@acm.org> References: <1518632624-29965-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::243 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)