From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Fam Zheng" <fam@euphon.net>,
"Collin Walling" <walling@linux.ibm.com>,
"Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Edgar Iglesias" <edgar.iglesias@xilinx.com>,
"Hannes Reinecke" <hare@suse.com>,
Qemu-block <qemu-block@nongnu.org>,
quintela@redhat.com, "David Hildenbrand" <david@redhat.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@de.ibm.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Richard Henderson" <rth@twiddle.net>,
"Thomas Huth" <thuth@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Alistair Francis" <alistair@alistair23.me>,
qemu-s390x <qemu-s390x@nongnu.org>,
qemu-arm <qemu-arm@nongnu.org>, "Cédric Le Goater" <clg@kaod.org>,
"John Snow" <jsnow@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Damien Hedde" <damien.hedde@greensocs.com>,
"Daniel P. Berrange" <berrange@redhat.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Mark Burton" <mark.burton@greensocs.com>,
qemu-ppc <qemu-ppc@nongnu.org>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 07/33] automatically add vmstate for reset support in devices
Date: Thu, 8 Aug 2019 16:42:19 +0100 [thread overview]
Message-ID: <20190808154219.GK2852@work-vm> (raw)
In-Reply-To: <CAFEAcA-W0SaaGbUnGZ0b61ngxKY8R9xjwGXeN+=MaUi4bMDgNg@mail.gmail.com>
* Peter Maydell (peter.maydell@linaro.org) wrote:
> On Mon, 29 Jul 2019 at 15:59, Damien Hedde <damien.hedde@greensocs.com> wrote:
> >
> > This add the reset related sections for every QOM
> > device.
>
> A bit more detail in the commit message would help, I think --
> this is adding extra machinery which has to copy and modify
> the VMStateDescription passed in by the device in order to
> add the subsection that handles reset.
>
> I've added Dave Gilbert to the already long cc list since this
> is migration related.
I don't like dynamically modifying all the vmsds.
Aren't you going to have to understand each devices reset behaviour
and make sure it does something sane? e.g. it might have a postload
that registers a timer or something that you wouldn't want to do if it's
in reset.
The easiest way is to write a macro that you can easily add to devices
you've checked subsection list (like the way we have a
VMSTATE_USB_DEVICE).
Dave
>
> > Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
> > ---
> > hw/core/qdev-vmstate.c | 41 +++++++++++++++++++++++++++++++++++++++++
> > hw/core/qdev.c | 12 +++++++++++-
> > include/hw/qdev-core.h | 3 +++
> > stubs/Makefile.objs | 1 +
> > stubs/device.c | 7 +++++++
> > 5 files changed, 63 insertions(+), 1 deletion(-)
> > create mode 100644 stubs/device.c
> >
> > diff --git a/hw/core/qdev-vmstate.c b/hw/core/qdev-vmstate.c
> > index 07b010811f..24f8465c61 100644
> > --- a/hw/core/qdev-vmstate.c
> > +++ b/hw/core/qdev-vmstate.c
> > @@ -43,3 +43,44 @@ const struct VMStateDescription device_vmstate_reset = {
> > VMSTATE_END_OF_LIST()
> > },
> > };
> > +
> > +static VMStateDescription *vmsd_duplicate_and_append(
> > + const VMStateDescription *old_vmsd,
> > + const VMStateDescription *new_subsection)
> > +{
> > + VMStateDescription *vmsd;
> > + int n = 0;
> > +
> > + assert(old_vmsd && new_subsection);
> > +
> > + vmsd = (VMStateDescription *) g_memdup(old_vmsd, sizeof(*vmsd));
> > +
> > + if (old_vmsd->subsections) {
> > + while (old_vmsd->subsections[n]) {
> > + n += 1;
> > + }
> > + }
> > + vmsd->subsections = g_new(const VMStateDescription *, n + 2);
> > +
> > + if (old_vmsd->subsections) {
> > + memcpy(vmsd->subsections, old_vmsd->subsections,
> > + sizeof(VMStateDescription *) * n);
> > + }
> > + vmsd->subsections[n] = new_subsection;
> > + vmsd->subsections[n + 1] = NULL;
> > +
> > + return vmsd;
> > +}
> > +
> > +void device_class_build_extended_vmsd(DeviceClass *dc)
> > +{
> > + assert(dc->vmsd);
> > + assert(!dc->vmsd_ext);
> > +
> > + /* forge a subsection with proper name */
> > + VMStateDescription *reset;
> > + reset = g_memdup(&device_vmstate_reset, sizeof(*reset));
> > + reset->name = g_strdup_printf("%s/device_reset", dc->vmsd->name);
> > +
> > + dc->vmsd_ext = vmsd_duplicate_and_append(dc->vmsd, reset);
> > +}
>
> This will allocate memory, but there is no corresponding
> code which frees it. This means you'll have a memory leak
> across device realize->unrealize for hotplug devices.
>
> > diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> > index e9e5f2d5f9..88387d3743 100644
> > --- a/hw/core/qdev.c
> > +++ b/hw/core/qdev.c
> > @@ -45,7 +45,17 @@ bool qdev_hot_removed = false;
> > const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
> > {
> > DeviceClass *dc = DEVICE_GET_CLASS(dev);
> > - return dc->vmsd;
> > +
> > + if (!dc->vmsd) {
> > + return NULL;
> > + }
> > +
> > + if (!dc->vmsd_ext) {
> > + /* build it first time we need it */
> > + device_class_build_extended_vmsd(dc);
> > + }
> > +
> > + return dc->vmsd_ext;
> > }
>
> Unfortunately not everything that wants the VMSD calls
> this function. migration/savevm.c:dump_vmstate_json_to_file()
> does a direct access to dc->vmsd, so we need to fix that first.
>
> Devices which don't use dc->vmsd won't get this and so
> their reset state won't be migrated. That's OK for anything
> that's still not yet a QOM device, I guess -- it's not possible
> for them to be in a 'held in reset' state anyway, so the
> extra subsection would never be needed.
>
> The one I'm less sure about is the 'virtio' devices, which
> have to do something odd with migration state for backwards
> compat reasons. At the moment they can't be in a situation
> where they're being held in reset when we do a migration,
> but since they're PCI devices they might in future be possible
> to put into new boards/pci controllers that would let them
> be in that situation.
>
> > static void bus_remove_child(BusState *bus, DeviceState *child)
> > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> > index 1670ae41bb..926d4bbcb1 100644
> > --- a/include/hw/qdev-core.h
> > +++ b/include/hw/qdev-core.h
> > @@ -120,6 +120,7 @@ typedef struct DeviceClass {
> >
> > /* device state */
> > const struct VMStateDescription *vmsd;
> > + const struct VMStateDescription *vmsd_ext;
> >
> > /* Private to qdev / bus. */
> > const char *bus_type;
> > @@ -520,6 +521,8 @@ void device_class_set_parent_unrealize(DeviceClass *dc,
> >
> > const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
> >
> > +void device_class_build_extended_vmsd(DeviceClass *dc);
> > +
> > const char *qdev_fw_name(DeviceState *dev);
> >
> > Object *qdev_get_machine(void);
> > diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> > index 9c7393b08c..432b56f290 100644
> > --- a/stubs/Makefile.objs
> > +++ b/stubs/Makefile.objs
> > @@ -40,4 +40,5 @@ stub-obj-y += pci-host-piix.o
> > stub-obj-y += ram-block.o
> > stub-obj-y += ramfb.o
> > stub-obj-y += fw_cfg.o
> > +stub-obj-y += device.o
> > stub-obj-$(CONFIG_SOFTMMU) += semihost.o
> > diff --git a/stubs/device.c b/stubs/device.c
> > new file mode 100644
> > index 0000000000..e9b4f57e5f
> > --- /dev/null
> > +++ b/stubs/device.c
> > @@ -0,0 +1,7 @@
> > +#include "qemu/osdep.h"
> > +#include "hw/qdev-core.h"
> > +
> > +void device_class_build_extended_vmsd(DeviceClass *dc)
> > +{
> > + return;
> > +}
> > --
> > 2.22.0
>
>
> thanks
> -- PMM
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2019-08-08 15:43 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-29 14:56 [Qemu-devel] [PATCH v3 00/33] Multi-phase reset mechanism Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 01/33] Create Resettable QOM interface Damien Hedde
2019-07-30 13:42 ` Cornelia Huck
2019-07-30 13:44 ` Peter Maydell
2019-07-30 13:55 ` Cornelia Huck
2019-07-30 13:59 ` Peter Maydell
2019-07-30 14:08 ` Damien Hedde
2019-07-30 15:47 ` Cornelia Huck
2019-07-31 5:46 ` David Gibson
2019-08-01 9:35 ` Damien Hedde
2019-08-12 10:27 ` David Gibson
2019-07-31 10:17 ` Christophe de Dinechin
2019-08-01 9:19 ` Damien Hedde
2019-08-01 9:30 ` Christophe de Dinechin
2019-08-07 14:20 ` Peter Maydell
2019-08-07 15:03 ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 02/33] add temporary device_legacy_reset function to replace device_reset Damien Hedde
2019-08-07 14:27 ` Peter Maydell
2019-08-09 9:20 ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 03/33] Replace all call to device_reset by call to device_legacy_reset Damien Hedde
2019-07-31 5:52 ` David Gibson
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 04/33] make Device and Bus Resettable Damien Hedde
2019-07-31 5:56 ` David Gibson
2019-07-31 9:09 ` Damien Hedde
2019-08-06 0:35 ` David Gibson
2019-08-07 7:55 ` Damien Hedde
2019-08-12 10:28 ` David Gibson
2019-08-07 14:41 ` Peter Maydell
2019-08-07 15:23 ` Damien Hedde
2019-08-07 15:28 ` Peter Maydell
2019-08-12 9:08 ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 05/33] Switch to new api in qdev/bus Damien Hedde
2019-07-31 6:05 ` David Gibson
2019-07-31 9:29 ` Damien Hedde
2019-07-31 11:31 ` Philippe Mathieu-Daudé
2019-08-08 6:47 ` David Gibson
2019-08-09 11:08 ` Peter Maydell
2019-08-12 10:34 ` David Gibson
2019-08-08 6:48 ` David Gibson
2019-08-09 11:39 ` Cédric Le Goater
2019-08-12 10:36 ` David Gibson
2019-08-07 14:48 ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 06/33] add the vmstate description for device reset state Damien Hedde
2019-07-31 6:08 ` David Gibson
2019-07-31 11:04 ` Damien Hedde
2019-08-07 14:53 ` Peter Maydell
2019-08-07 14:54 ` Peter Maydell
2019-08-07 15:27 ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 07/33] automatically add vmstate for reset support in devices Damien Hedde
2019-08-07 15:07 ` Peter Maydell
2019-08-07 17:22 ` Damien Hedde
2019-08-08 15:42 ` Dr. David Alan Gilbert [this message]
2019-08-09 10:07 ` Peter Maydell
2019-08-09 10:29 ` Damien Hedde
2019-08-09 10:32 ` Peter Maydell
2019-08-09 10:46 ` Damien Hedde
2019-08-09 13:02 ` Juan Quintela
2019-08-09 13:01 ` Juan Quintela
2019-08-09 13:50 ` Dr. David Alan Gilbert
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 08/33] Add function to control reset with gpio inputs Damien Hedde
2019-07-31 6:11 ` David Gibson
2019-07-31 10:09 ` Damien Hedde
2019-08-07 10:37 ` Peter Maydell
2019-08-09 5:51 ` David Gibson
2019-08-09 8:45 ` Damien Hedde
2019-08-12 10:29 ` David Gibson
2019-08-07 15:18 ` Peter Maydell
2019-08-07 16:56 ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 09/33] add doc about Resettable interface Damien Hedde
2019-07-31 6:30 ` David Gibson
2019-07-31 10:05 ` Damien Hedde
2019-08-07 10:34 ` Peter Maydell
2019-08-08 6:49 ` David Gibson
2019-08-07 16:01 ` Peter Maydell
2019-08-12 10:15 ` David Gibson
2019-08-07 15:58 ` Peter Maydell
2019-08-07 16:02 ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 10/33] vl.c: remove qbus_reset_all registration Damien Hedde
2019-08-07 15:20 ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 11/33] hw/s390x/ipl.c: " Damien Hedde
2019-08-07 15:24 ` Peter Maydell
2019-08-08 10:25 ` Cornelia Huck
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 12/33] hw/pci/: remove qdev/qbus_reset_all call Damien Hedde
2019-08-07 15:31 ` Peter Maydell
2019-08-09 9:47 ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 13/33] hw/scsi/: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 14/33] hw/s390x/s390-virtio-ccw.c: remove qdev_reset_all call Damien Hedde
2019-08-08 10:50 ` Cornelia Huck
2019-08-09 8:31 ` Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 15/33] hw/ide/piix.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 16/33] hw/input/adb.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 17/33] hw/usb/dev-uas.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 18/33] hw/audio/intel-hda.c: remove device_legacy_reset call Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 19/33] hw/sd/pl181.c & omap_mmc.c: " Damien Hedde
2019-07-31 15:48 ` Philippe Mathieu-Daudé
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 20/33] hw/hyperv/hyperv.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 21/33] hw/intc/spapr_xive.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 22/33] hw/ppc/pnv_psi.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 23/33] hw/scsi/vmw_pvscsi.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 24/33] hw/ppc/spapr: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 25/33] hw/i386/pc.c: " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 26/33] hw/s390x/s390-pci-inst.c: " Damien Hedde
2019-08-08 10:52 ` Cornelia Huck
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 27/33] hw/ide/microdrive.c: remove device_legacy_reset calls Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 28/33] qdev: Remove unused deprecated reset functions Damien Hedde
2019-08-07 15:29 ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 29/33] hw/misc/zynq_slcr: use standard register definition Damien Hedde
2019-08-07 15:33 ` Peter Maydell
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 30/33] convert cadence_uart to 3-phases reset Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 31/33] Convert zynq's slcr " Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 32/33] Add uart reset support in zynq_slcr Damien Hedde
2019-07-29 14:56 ` [Qemu-devel] [PATCH v3 33/33] Connect the uart reset gpios in the zynq platform Damien Hedde
2019-07-30 10:14 ` [Qemu-devel] [PATCH v3 00/33] Multi-phase reset mechanism Cornelia Huck
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=20190808154219.GK2852@work-vm \
--to=dgilbert@redhat.com \
--cc=alistair@alistair23.me \
--cc=berrange@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=clg@kaod.org \
--cc=cohuck@redhat.com \
--cc=damien.hedde@greensocs.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=dmitry.fleytman@gmail.com \
--cc=edgar.iglesias@xilinx.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=hare@suse.com \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.burton@greensocs.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@twiddle.net \
--cc=thuth@redhat.com \
--cc=walling@linux.ibm.com \
/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).