From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: minyard@acm.org
Cc: qemu-devel@nongnu.org, Corey Minyard <cminyard@mvista.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] ipmi: Use proper struct reference for KCS vmstate
Date: Mon, 5 Feb 2018 16:06:53 +0000 [thread overview]
Message-ID: <20180205160652.GB2317@work-vm> (raw)
In-Reply-To: <1517511547-10147-2-git-send-email-minyard@acm.org>
* minyard@acm.org (minyard@acm.org) wrote:
> From: Corey Minyard <cminyard@mvista.com>
Hi Corey,
> The vmstate for isa_ipmi_kcs was referencing into the kcs structure,
> instead create a kcs structure separate and use that.
>
> There was 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. This
> also fixes those issues and is tested under heavy load.
>
> Signed-off-by: Corey Minyard <cminyard@mvista.com>
> ---
> hw/ipmi/isa_ipmi_kcs.c | 75 ++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 60 insertions(+), 15 deletions(-)
>
> diff --git a/hw/ipmi/isa_ipmi_kcs.c b/hw/ipmi/isa_ipmi_kcs.c
> index 689587b..3c942d6 100644
> --- a/hw/ipmi/isa_ipmi_kcs.c
> +++ b/hw/ipmi/isa_ipmi_kcs.c
> @@ -422,24 +422,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 = {
> - .name = TYPE_IPMI_INTERFACE,
> +static const VMStateDescription vmstate_IPMIKCS = {
> + .name = TYPE_IPMI_INTERFACE_PREFIX "kcs",
> .version_id = 1,
> .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_BOOL(obf_irq_set, IPMIKCS),
> + VMSTATE_BOOL(atn_irq_set, IPMIKCS),
> + VMSTATE_BOOL(use_irq, IPMIKCS),
> + VMSTATE_BOOL(irqs_enabled, IPMIKCS),
> + VMSTATE_UINT32(outpos, IPMIKCS),
> + VMSTATE_UINT8_ARRAY(outmsg, IPMIKCS, MAX_IPMI_MSG_SIZE),
> + VMSTATE_UINT32(inlen, IPMIKCS),
> + VMSTATE_UINT8_ARRAY(inmsg, IPMIKCS, MAX_IPMI_MSG_SIZE),
There's an easier way to do this, which means that you don't need the
load_old hook; you can do:
VMSTATE_UINT32_V(inlen, IPMIKCS, 2);
and that field will only be loaded when loading a v2.
Now, the other thing you could do, if it's rare then inlen is none-0,
is you could add it as a subsection that only gets sent when it's
none-0; that way migration to an old qemu would work in most cases.
Dave
> + 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 int isa_ipmi_kcs_load_old(QEMUFile *f, void *opaque, int version_id)
> +{
> + ISAIPMIKCSDevice *iik = opaque;
> + IPMIKCS *k = &iik->kcs;
> + unsigned int i;
> +
> + if (version_id != 1) {
> + return -EINVAL;
> + }
> +
> + k->obf_irq_set = qemu_get_byte(f);
> + k->atn_irq_set = qemu_get_byte(f);
> + qemu_get_byte(f); /* Used to be use_irq, but that's not a good idea. */
> + k->irqs_enabled = qemu_get_byte(f);
> + k->outpos = qemu_get_be32(f);
> + for (i = 0; i < MAX_IPMI_MSG_SIZE; i++) {
> + k->outmsg[i] = qemu_get_byte(f);
> + }
> + k->inlen = 0; /* This was forgotten on version 1, just reset it. */
> + for (i = 0; i < MAX_IPMI_MSG_SIZE; i++) {
> + k->inmsg[i] = qemu_get_byte(f);
> + }
> + k->write_end = qemu_get_byte(f);
> + k->status_reg = qemu_get_byte(f);
> + k->data_out_reg = qemu_get_byte(f);
> + k->data_in_reg = qemu_get_be16(f);
> + k->cmd_reg = qemu_get_be16(f);
> + k->waiting_rsp = qemu_get_byte(f);
> +
> + return 0;
> +}
> +
> +static const VMStateDescription vmstate_ISAIPMIKCSDevice = {
> + .name = TYPE_IPMI_INTERFACE_PREFIX "isa-kcs",
> + .version_id = 2,
> + .minimum_version_id = 2,
> + .minimum_version_id_old = 1,
> + .load_state_old = isa_ipmi_kcs_load_old,
> + .fields = (VMStateField[]) {
> + VMSTATE_STRUCT(kcs, ISAIPMIKCSDevice, 1, vmstate_IPMIKCS, IPMIKCS),
> VMSTATE_END_OF_LIST()
> }
> };
> --
> 2.7.4
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2018-02-05 16:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-01 18:59 [Qemu-devel] [PATCH 0/2] Fix vmstate for IPMI devices minyard
2018-02-01 18:59 ` [Qemu-devel] [PATCH 1/2] ipmi: Use proper struct reference for KCS vmstate minyard
2018-02-05 16:06 ` Dr. David Alan Gilbert [this message]
2018-02-01 18:59 ` [Qemu-devel] [PATCH 2/2] ipmi: Use proper struct reference for BT vmstate minyard
2018-02-05 16:28 ` Dr. David Alan Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180205160652.GB2317@work-vm \
--to=dgilbert@redhat.com \
--cc=cminyard@mvista.com \
--cc=minyard@acm.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).