[Qemu-devel] [PATCH v8 00/13] Add migration support for VFIO device

Kirti Wankhede posted 13 patches 4 years, 8 months ago
Test docker-clang@ubuntu passed
Test FreeBSD passed
Test checkpatch failed
Test docker-mingw@fedora passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1566845753-18993-1-git-send-email-kwankhede@nvidia.com
Maintainers: Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Alex Williamson <alex.williamson@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
hw/vfio/Makefile.objs         |   2 +-
hw/vfio/common.c              |  55 +++
hw/vfio/migration.c           | 848 ++++++++++++++++++++++++++++++++++++++++++
hw/vfio/pci.c                 | 191 +++++++++-
hw/vfio/trace-events          |  19 +
include/hw/vfio/vfio-common.h |  22 ++
linux-headers/linux/vfio.h    | 148 ++++++++
7 files changed, 1278 insertions(+), 7 deletions(-)
create mode 100644 hw/vfio/migration.c
[Qemu-devel] [PATCH v8 00/13] Add migration support for VFIO device
Posted by Kirti Wankhede 4 years, 8 months ago
Add migration support for VFIO device

This Patch set include patches as below:
- Define KABI for VFIO device for migration support.
- Added save and restore functions for PCI configuration space
- Generic migration functionality for VFIO device.
  * This patch set adds functionality only for PCI devices, but can be
    extended to other VFIO devices.
  * Added all the basic functions required for pre-copy, stop-and-copy and
    resume phases of migration.
  * Added state change notifier and from that notifier function, VFIO
    device's state changed is conveyed to VFIO device driver.
  * During save setup phase and resume/load setup phase, migration region
    is queried and is used to read/write VFIO device data.
  * .save_live_pending and .save_live_iterate are implemented to use QEMU's
    functionality of iteration during pre-copy phase.
  * In .save_live_complete_precopy, that is in stop-and-copy phase,
    iteration to read data from VFIO device driver is implemented till pending
    bytes returned by driver are not zero.
  * Added function to get dirty pages bitmap for the pages which are used by
    driver.
- Add vfio_listerner_log_sync to mark dirty pages.
- Make VFIO PCI device migration capable. If migration region is not provided by
  driver, migration is blocked.

Below is the flow of state change for live migration where states in brackets
represent VM state, migration state and VFIO device state as:
    (VM state, MIGRATION_STATUS, VFIO_DEVICE_STATE)

Live migration save path:
        QEMU normal running state
        (RUNNING, _NONE, _RUNNING)
                        |
    migrate_init spawns migration_thread.
    (RUNNING, _SETUP, _RUNNING|_SAVING)
    Migration thread then calls each device's .save_setup()
                        |
    (RUNNING, _ACTIVE, _RUNNING|_SAVING)
    If device is active, get pending bytes by .save_live_pending()
    if pending bytes >= threshold_size,  call save_live_iterate()
    Data of VFIO device for pre-copy phase is copied.
    Iterate till pending bytes converge and are less than threshold
                        |
    On migration completion, vCPUs stops and calls .save_live_complete_precopy
    for each active device. VFIO device is then transitioned in
     _SAVING state.
    (FINISH_MIGRATE, _DEVICE, _SAVING)
    For VFIO device, iterate in  .save_live_complete_precopy  until
    pending data is 0.
    (FINISH_MIGRATE, _DEVICE, _STOPPED)
                        |
    (FINISH_MIGRATE, _COMPLETED, STOPPED)
    Migraton thread schedule cleanup bottom half and exit

Live migration resume path:
    Incomming migration calls .load_setup for each device
    (RESTORE_VM, _ACTIVE, STOPPED)
                        |
    For each device, .load_state is called for that device section data
                        |
    At the end, called .load_cleanup for each device and vCPUs are started.
                        |
        (RUNNING, _NONE, _RUNNING)

Note that:
- Migration post copy is not supported.

v7 -> v8:
- Updated comments for KABI
- Added BAR address validation check during PCI device's config space load as
  suggested by Dr. David Alan Gilbert.
- Changed vfio_migration_set_state() to set or clear device state flags.
- Some nit fixes.

v6 -> v7:
- Fix build failures.

v5 -> v6:
- Fix build failure.

v4 -> v5:
- Added decriptive comment about the sequence of access of members of structure
  vfio_device_migration_info to be followed based on Alex's suggestion
- Updated get dirty pages sequence.
- As per Cornelia Huck's suggestion, added callbacks to VFIODeviceOps to
  get_object, save_config and load_config.
- Fixed multiple nit picks.
- Tested live migration with multiple vfio device assigned to a VM.

v3 -> v4:
- Added one more bit for _RESUMING flag to be set explicitly.
- data_offset field is read-only for user space application.
- data_size is read for every iteration before reading data from migration, that
  is removed assumption that data will be till end of migration region.
- If vendor driver supports mappable sparsed region, map those region during
  setup state of save/load, similarly unmap those from cleanup routines.
- Handles race condition that causes data corruption in migration region during
  save device state by adding mutex and serialiaing save_buffer and
  get_dirty_pages routines.
- Skip called get_dirty_pages routine for mapped MMIO region of device.
- Added trace events.
- Splitted into multiple functional patches.

v2 -> v3:
- Removed enum of VFIO device states. Defined VFIO device state with 2 bits.
- Re-structured vfio_device_migration_info to keep it minimal and defined action
  on read and write access on its members.

v1 -> v2:
- Defined MIGRATION region type and sub-type which should be used with region
  type capability.
- Re-structured vfio_device_migration_info. This structure will be placed at 0th
  offset of migration region.
- Replaced ioctl with read/write for trapped part of migration region.
- Added both type of access support, trapped or mmapped, for data section of the
  region.
- Moved PCI device functions to pci file.
- Added iteration to get dirty page bitmap until bitmap for all requested pages
  are copied.

Thanks,
Kirti


Kirti Wankhede (13):
  vfio: KABI for migration interface
  vfio: Add function to unmap VFIO region
  vfio: Add vfio_get_object callback to VFIODeviceOps
  vfio: Add save and load functions for VFIO PCI devices
  vfio: Add migration region initialization and finalize function
  vfio: Add VM state change handler to know state of VM
  vfio: Add migration state change notifier
  vfio: Register SaveVMHandlers for VFIO device
  vfio: Add save state functions to SaveVMHandlers
  vfio: Add load state functions to SaveVMHandlers
  vfio: Add function to get dirty page list
  vfio: Add vfio_listener_log_sync to mark dirty pages
  vfio: Make vfio-pci device migration capable.

 hw/vfio/Makefile.objs         |   2 +-
 hw/vfio/common.c              |  55 +++
 hw/vfio/migration.c           | 848 ++++++++++++++++++++++++++++++++++++++++++
 hw/vfio/pci.c                 | 191 +++++++++-
 hw/vfio/trace-events          |  19 +
 include/hw/vfio/vfio-common.h |  22 ++
 linux-headers/linux/vfio.h    | 148 ++++++++
 7 files changed, 1278 insertions(+), 7 deletions(-)
 create mode 100644 hw/vfio/migration.c

-- 
2.7.0


Re: [Qemu-devel] [PATCH v8 00/13] Add migration support for VFIO device
Posted by no-reply@patchew.org 4 years, 8 months ago
Patchew URL: https://patchew.org/QEMU/1566845753-18993-1-git-send-email-kwankhede@nvidia.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 1566845753-18993-1-git-send-email-kwankhede@nvidia.com
Subject: [Qemu-devel] [PATCH v8 00/13] Add migration support for VFIO device

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
0aeba38 vfio: Make vfio-pci device migration capable.
acc0d2b vfio: Add vfio_listener_log_sync to mark dirty pages
cb11cd6 vfio: Add function to get dirty page list
6d46042 vfio: Add load state functions to SaveVMHandlers
1f88428 vfio: Add save state functions to SaveVMHandlers
d0fbf18 vfio: Register SaveVMHandlers for VFIO device
04097e1 vfio: Add migration state change notifier
c3b9857 vfio: Add VM state change handler to know state of VM
a712a3a vfio: Add migration region initialization and finalize function
78b6920 vfio: Add save and load functions for VFIO PCI devices
032d272 vfio: Add vfio_get_object callback to VFIODeviceOps
95817ed vfio: Add function to unmap VFIO region
eaf5be5 vfio: KABI for migration interface

=== OUTPUT BEGIN ===
1/13 Checking commit eaf5be5b94f3 (vfio: KABI for migration interface)
2/13 Checking commit 95817edc42f9 (vfio: Add function to unmap VFIO region)
3/13 Checking commit 032d272ca311 (vfio: Add vfio_get_object callback to VFIODeviceOps)
4/13 Checking commit 78b692082884 (vfio: Add save and load functions for VFIO PCI devices)
5/13 Checking commit a712a3a74713 (vfio: Add migration region initialization and finalize function)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#29: 
new file mode 100644

ERROR: g_free(NULL) is safe this check is probably not required
#171: FILE: hw/vfio/migration.c:138:
+    if (vbasedev->migration) {
+        g_free(vbasedev->migration);

total: 1 errors, 1 warnings, 178 lines checked

Patch 5/13 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

6/13 Checking commit c3b98575e39b (vfio: Add VM state change handler to know state of VM)
7/13 Checking commit 04097e167c8b (vfio: Add migration state change notifier)
8/13 Checking commit d0fbf181b9db (vfio: Register SaveVMHandlers for VFIO device)
9/13 Checking commit 1f88428a8340 (vfio: Add save state functions to SaveVMHandlers)
10/13 Checking commit 6d46042143b9 (vfio: Add load state functions to SaveVMHandlers)
11/13 Checking commit cb11cd6229f8 (vfio: Add function to get dirty page list)
12/13 Checking commit acc0d2baac7d (vfio: Add vfio_listener_log_sync to mark dirty pages)
13/13 Checking commit 0aeba384447b (vfio: Make vfio-pci device migration capable.)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/1566845753-18993-1-git-send-email-kwankhede@nvidia.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com