[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V2 2/4] vfio: Add vm status change callback to stop/re
From: |
Yulei Zhang |
Subject: |
[Qemu-devel] [RFC V2 2/4] vfio: Add vm status change callback to stop/restart the mdev device |
Date: |
Mon, 31 Jul 2017 06:26:11 -0000 |
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 <address@hidden>
---
hw/vfio/pci.c | 19 +++++++++++++++++++
include/hw/vfio/vfio-common.h | 1 +
linux-headers/linux/vfio.h | 3 +++
3 files changed, 23 insertions(+)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 21a5cef..753da80 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 VMStateDescription vfio_pci_vmstate;
+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
@@ -2858,6 +2859,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;
@@ -2940,6 +2942,23 @@ 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\n", 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 c582de1..c4bab97 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -123,6 +123,7 @@ typedef struct VFIODevice {
unsigned int num_irqs;
unsigned int num_regions;
unsigned int flags;
+ bool device_state;
} VFIODevice;
struct VFIODeviceOps {
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index e2c53bf..ae1b953 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -299,6 +299,9 @@ struct vfio_region_info_cap_type {
#define VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG (3)
#define VFIO_REGION_SUBTYPE_INTEL_IGD_DEVICE_STATE (4)
+#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)
--
2.7.4
- [Qemu-devel] [RFC V2 0/4] vfio: Introduce Live migration capability to vfio_mdev device, Yulei Zhang, 2017/07/31
- [Qemu-devel] [RFC V2 1/4] vfio: introduce a new VFIO sub region for mdev device migration support, Yulei Zhang, 2017/07/31
- [Qemu-devel] [RFC V2 2/4] vfio: Add vm status change callback to stop/restart the mdev device,
Yulei Zhang <=
- [Qemu-devel] [RFC V2 4/4] vifo: introduce new VFIO ioctl VFIO_IOMMU_GET_DIRTY_BITMAP, Yulei Zhang, 2017/07/31
- [Qemu-devel] [RFC V2 3/4] vfio: Add struct vfio_vmstate_info to introduce put/get callback funtion for vfio device status save/restore, Yulei Zhang, 2017/07/31
- Re: [Qemu-devel] [RFC V2 0/4] vfio: Introduce Live migration capability to vfio_mdev device, Tian, Kevin, 2017/07/31
- Re: [Qemu-devel] [RFC V2 0/4] vfio: Introduce Live migration capability to vfio_mdev device, no-reply, 2017/07/31