From: Stefan Hajnoczi <stefanha@redhat.com>
To: <qemu-devel@nongnu.org>
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [RFC v3 1/3] virtio: add vdc->vmchange_state() callback
Date: Fri, 24 May 2019 19:36:36 +0100 [thread overview]
Message-ID: <20190524183638.20745-2-stefanha@redhat.com> (raw)
In-Reply-To: <20190524183638.20745-1-stefanha@redhat.com>
The core virtio code invokes ->set_status() followed by
->ioeventfd_start() when the guest resumes execution. Both of these
functions are also called in other cases unrelated to vm change state.
This patch introduces ->vmstate_change() so that devices can act on
guest pause/resume. The existing qemu_add_vm_change_state_handler() API
isn't usable by virtio devices since the ordering between vm change
state handlers is undefined. The new ->vmstate_change() callback is
always invoked after ->set_status() and ->ioeventfd_start() when
resuming a guest.
A later patch makes use of this new callback.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/hw/virtio/virtio.h | 7 +++++++
hw/virtio/virtio.c | 9 +++++++++
2 files changed, 16 insertions(+)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 27c0efc3d0..5742efa1d7 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -158,6 +158,13 @@ typedef struct VirtioDeviceClass {
void (*save)(VirtIODevice *vdev, QEMUFile *f);
int (*load)(VirtIODevice *vdev, QEMUFile *f, int version_id);
const VMStateDescription *vmsd;
+
+ /* Called when the device should start/stop running because the guest was
+ * resumed/paused. Note that this takes VIRTIO_CONFIG_S_DRIVER_OK into
+ * account so running is true iff the guest is resumed and the guest driver
+ * has already indicated it is ready.
+ */
+ void (*vmstate_change)(VirtIODevice *vdev, bool running);
} VirtioDeviceClass;
void virtio_instance_init_common(Object *proxy_obj, void *data,
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 4805727b53..cdf869456b 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2291,6 +2291,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
VirtIODevice *vdev = opaque;
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
bool backend_run = running && vdev->started;
vdev->vm_running = running;
@@ -2298,10 +2299,18 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
virtio_set_status(vdev, vdev->status);
}
+ if (!backend_run && vdc->vmstate_change) {
+ vdc->vmstate_change(vdev, backend_run);
+ }
+
if (k->vmstate_change) {
k->vmstate_change(qbus->parent, backend_run);
}
+ if (backend_run && vdc->vmstate_change) {
+ vdc->vmstate_change(vdev, backend_run);
+ }
+
if (!backend_run) {
virtio_set_status(vdev, vdev->status);
}
--
2.21.0
next prev parent reply other threads:[~2019-05-24 18:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 18:36 [Qemu-devel] [RFC v3 0/3] scsi: restart dma after vm change state handlers Stefan Hajnoczi
2019-05-24 18:36 ` Stefan Hajnoczi [this message]
2019-05-24 18:36 ` [Qemu-devel] [RFC v3 2/3] scsi: add scsi_bus_dma_restart() Stefan Hajnoczi
2019-05-24 18:36 ` [Qemu-devel] [RFC v3 3/3] virtio-scsi: fix iothread deadlock on 'cont' Stefan Hajnoczi
2019-05-24 18:47 ` [Qemu-devel] [RFC v3 0/3] scsi: restart dma after vm change state handlers Paolo Bonzini
2019-05-24 19:08 ` Michael S. Tsirkin
2019-05-29 22:10 ` Kevin Wolf
2019-05-30 8:27 ` Paolo Bonzini
2019-05-30 8:52 ` Kevin Wolf
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=20190524183638.20745-2-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--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).