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: 10363519 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 CFC156038F for ; Wed, 25 Apr 2018 15:32:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B417F28A7F for ; Wed, 25 Apr 2018 15:32:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A619028D92; Wed, 25 Apr 2018 15:32:23 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 1FE8128A7F for ; Wed, 25 Apr 2018 15:32:22 +0000 (UTC) Received: from localhost ([::1]:37669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBMP8-0005EH-1n for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Apr 2018 11:32:22 -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-Google-Smtp-Source: AIpwx4/+RFM5pILlr+HRkgWwavOLYOV5fqgCQlcZjgj7U3BcoAjAiODQbL0rWWsPAhslIIpAW+HflA== 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+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_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(-) 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() } };