From: Yulei Zhang <yulei.zhang@intel.com>
To: qemu-devel@nongnu.org
Cc: kevin.tian@intel.com, joonas.lahtinen@linux.intel.com,
zhenyuw@linux.intel.com, kwankhede@nvidia.com,
zhi.a.wang@intel.com, alex.williamson@redhat.com,
dgilbert@redhat.com, quintela@redhat.com,
Yulei Zhang <yulei.zhang@intel.com>
Subject: [Qemu-devel] [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev device
Date: Tue, 10 Apr 2018 14:02:57 +0800 [thread overview]
Message-ID: <1523340177-8975-1-git-send-email-yulei.zhang@intel.com> (raw)
VM status change handler is added to change the vfio pci device
status during the migration, write the demanded device status
to the DEVICE STATUS subregion to stop the device on the source side
before fetch its status and start the deivce on the target side
after restore its status.
Signed-off-by: Yulei Zhang <yulei.zhang@intel.com>
---
hw/vfio/pci.c | 20 ++++++++++++++++++++
include/hw/vfio/vfio-common.h | 1 +
| 6 ++++++
roms/seabios | 2 +-
4 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index f98a9dd..13d8c73 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -38,6 +38,7 @@
static void vfio_disable_interrupts(VFIOPCIDevice *vdev);
static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled);
+static void vfio_vm_change_state_handler(void *pv, int running, RunState state);
/*
* Disabling BAR mmaping can be slow, but toggling it around INTx can
@@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vfio_register_err_notifier(vdev);
vfio_register_req_notifier(vdev);
vfio_setup_resetfn_quirk(vdev);
+ qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);
return;
@@ -2982,6 +2984,24 @@ post_reset:
vfio_pci_post_reset(vdev);
}
+static void vfio_vm_change_state_handler(void *pv, int running, RunState state)
+{
+ VFIOPCIDevice *vdev = pv;
+ VFIODevice *vbasedev = &vdev->vbasedev;
+ uint8_t dev_state;
+ uint8_t sz = 1;
+
+ dev_state = running ? VFIO_DEVICE_START : VFIO_DEVICE_STOP;
+
+ if (pwrite(vdev->vbasedev.fd, &dev_state,
+ sz, vdev->device_state.offset) != sz) {
+ error_report("vfio: Failed to %s device", running ? "start" : "stop");
+ return;
+ }
+
+ vbasedev->device_state = dev_state;
+}
+
static void vfio_instance_init(Object *obj)
{
PCIDevice *pci_dev = PCI_DEVICE(obj);
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index f3a2ac9..9c14a8f 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -125,6 +125,7 @@ typedef struct VFIODevice {
unsigned int num_irqs;
unsigned int num_regions;
unsigned int flags;
+ bool device_state;
} VFIODevice;
struct VFIODeviceOps {
--git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index e3380ad..8f02f2f 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -304,6 +304,12 @@ struct vfio_region_info_cap_type {
/* Mdev sub-type for device state save and restore */
#define VFIO_REGION_SUBTYPE_DEVICE_STATE (4)
+/* Offset in region to save device state */
+#define VFIO_DEVICE_STATE_OFFSET 1
+
+#define VFIO_DEVICE_START 0
+#define VFIO_DEVICE_STOP 1
+
/**
* VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9,
* struct vfio_irq_info)
diff --git a/roms/seabios b/roms/seabios
index 63451fc..5f4c7b1 160000
--- a/roms/seabios
+++ b/roms/seabios
@@ -1 +1 @@
-Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc
+Subproject commit 5f4c7b13cdf9c450eb55645f4362ea58fa61b79b
--
2.7.4
next reply other threads:[~2018-04-10 5:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-10 6:02 Yulei Zhang [this message]
2018-04-16 14:44 ` [Qemu-devel] [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev device Kirti Wankhede
2018-04-16 20:23 ` Alex Williamson
2018-04-17 13:40 ` Zhang, Yulei
2018-04-17 14:43 ` Alex Williamson
2018-04-17 19:14 ` Kirti Wankhede
2018-04-17 20:09 ` Alex Williamson
2018-04-17 21:11 ` Kirti Wankhede
2018-04-17 21:36 ` Alex Williamson
2018-04-18 6:56 ` Kirti Wankhede
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=1523340177-8975-1-git-send-email-yulei.zhang@intel.com \
--to=yulei.zhang@intel.com \
--cc=alex.williamson@redhat.com \
--cc=dgilbert@redhat.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kevin.tian@intel.com \
--cc=kwankhede@nvidia.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@intel.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).