aboutsummaryrefslogtreecommitdiff
path: root/lib/migration.c
AgeCommit message (Collapse)AuthorFilesLines
2023-09-15adapt to VFIO live migration v2 (#782)William Henderson1-353/+219
This commit adapts the vfio-user protocol specification and the libvfio-user implementation to v2 of the VFIO live migration interface, as used in the kernel and QEMU. The differences between v1 and v2 are discussed in this email thread [1], and we slightly differ from upstream VFIO v2 in that instead of transferring data over a new FD, we use the existing UNIX socket with new commands VFIO_USER_MIG_DATA_READ/WRITE. We also don't yet use P2P states. The updated spec was submitted to qemu-devel [2]. [1] https://lore.kernel.org/all/20220130160826.32449-9-yishaih@nvidia.com/ [2] https://lore.kernel.org/all/20230718094150.110183-1-william.henderson@nutanix.com/ Signed-off-by: William Henderson <william.henderson@nutanix.com>
2022-10-04fix compilation for i386 and ppc64 (#709)Thanos Makatos1-8/+10
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reported-by: Eduardo Lima <eblima@gmail.com>
2022-05-23libvfio-user.h: sync VFIO_DEVICE_STATE_XXXX definitions with upstream (#690)Jag Raman1-14/+14
Rename VFIO_DEVICE_STATE_XXXX defines as VFIO_DEVICE_STATE_V1_XXXX. Upstream renamed these variable to be of the XXXX_V1_XXXX format and switched an enum for VFIO_DEVICE_STATE_XXXX. Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2022-03-07check for allowed operations in quiesce state (#647)Thanos Makatos1-0/+4
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-02-25clarify when logging when device changes migration state (#649)Thanos Makatos1-1/+6
This makes reading logs easier. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-11-30introduce device quiesce callback (#609)Thanos Makatos1-7/+17
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Leon <john.levon@nutanix.com>
2021-10-05make migration state callback optionally asynchronous (#608)Thanos Makatos1-0/+5
Some devices need the migration state callback to be asynchronous. The simplest way to implement this is to require from the callback to return -1 and set errno to EBUSY, not process any other new messages (vfu_ctx_run returns -1 and sets errno to EBUSY), and provide a way to the user to complete migration (vfu_migr_done). Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-06-02clean up migration register definitions (#550)John Levon1-7/+7
We should explicitly define the expected migration register contents for API users who aren't using the callbacks. Clean up some related lint. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-05-28hide non-ABI symbols (#538)John Levon1-1/+1
Default to hidden visibility to remove non-public symbols from API users (and improve performance a little). Every public function gets an EXPORT annotation. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-05-20migration: various dirty page tracking fixes (#457)Thanos Makatos1-58/+112
- document how to use a vfio-user device with libvirt - document how to use SPDK's nvmf/vfio-user target with libvirt - replace vfio_bitmap with vfio_user_bitmap and vfio_iommu_type1_dirty_bitmap_get with vfio_user_bitmap_range - fix bug for calculating number of pages needed for dirty page bitmap - align number of bytes for dirty page bitmap to QWORD - add debug messages around dirty page tracking - only support flags=0 when doing DMA unmap - set device state to running after reset - allow region read/write even if device is in stopped state - allow transitioning from stopped/stop-and-copy state to running state - fix unit tests Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-04-15remove stale comment (#443)John Levon1-2/+0
Missed this FIXME when removing use of __u* types previously. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-04-14migration: use ERROR_INT() (#432)John Levon1-29/+26
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-13drop use of __u* types (#438)John Levon1-13/+10
As we are now pure userspace, there is no need for us to use non-standard integer types. This leaves the copied defines from Linux's vfio.h alone, however. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-25re-work unit test mocking (#400)John Levon1-2/+2
Instead of trying to use the linker's --wrap, which just led to more problems when we want to call the real function, we'll add two defines, MOCK_DEFINE() and MOCK_DECLARE(), that behave differently when building the unit tests, such that all wrapped functions are picked up from test/mocks.c instead, regardless of compilation unit. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-18use sizeof() consistently (#351)John Levon1-1/+1
The most common way we have written this is as "sizeof()"; use this form consistently. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-18unit test exec_command and friends w.r.t. migration device state (#346)Thanos Makatos1-78/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-10don't expose -errno in public API (#327)John Levon1-0/+6
Regardless of what we do internally, most of our API uses standard mechanisms for reporting errors. Fix vfu_run_ctx() to do so properly as well, and fix a couple of other references for user-provided callbacks. This will require a small fix to SPDK. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-10expose migration region (#305)Thanos Makatos1-9/+38
This patch exposes the fact that live migration is implemented as a special device region. Hiding this from the user doesn't offer much benefit since it only takes just a little bit of extra code for the user to handle it as a region. We do keep the migration callback functionality since this feature substantially simplifies supporting live migration from the device implementation's perspective. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Co-authored-by: John Levon <john.levon@nutanix.com>
2021-01-27allow device to specify data_offset when resuming (#272)Thanos Makatos1-24/+17
Handling data_offset and data_size internally is wrong: we can't simply assume that the migration data should be appending to the migration region, devices might have their own requirements. This also requires a way for the device to return the data_offset, we do this by making the prepare_data callback applicable in resume state. Also, allow migration read/write callabcks to return errors. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26cache pending_bytes (#246)Thanos Makatos1-6/+7
In VFIO, pending_bytes can be re-read and each time it's read the device can return a new value (even higher than the previous one). Rather than exposing the vfio-user device implementation to such complicated semantics, we cache pending_bytes and handle repeated calls to it ourselves. Even if pending_bytes does change in the device, the client will either way read it as a part of the current migration iteration. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26don't return wrong data_offset in resuming state (#253)Thanos Makatos1-16/+12
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26reset migration iteration state whenever VFIO device migration state changes ↵Thanos Makatos1-0/+1
(#254) Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26use names for migration states when logging (#250)Thanos Makatos1-26/+55
Plus migration states array fixes and unit tests. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26don't remain in wrong migration iteration state after data have been ↵Thanos Makatos1-0/+8
prepared (#257) Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26introduce function for transitioning vfio-user migration iteration states (#263)Thanos Makatos1-2/+10
This makes it easier to tell where we change the migration iteration state. In the future we might also perform additional validations.
2021-01-25add pre-copy phase in live migration example (#247)Thanos Makatos1-0/+6
This patch adds a simplistic pre-copy phase in the live migration sample. The end goal is have a separate thread in the client to modify device state while the device is in the pre-copy phase. This will be done in later patches. BAR1 is saved during the pre-copy phase and BAR0 is saved during the stop-and-copy phase. This is purely for convenience. There are quite a few assumptions and FIXMEs, even in the client code. We plan to address them in future patches. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25minor comments (#249)Thanos Makatos1-1/+9
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25rename _migr_state_transition_is_valid to ↵Thanos Makatos1-2/+2
vfio_migr_state_transition_is_valid for clarity (#260) Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25minor comments (#262)Thanos Makatos1-1/+9
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25don't swallow errors when writing data_size (#261)Thanos Makatos1-3/+5
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-07re-work access handling (#220)John Levon1-9/+10
Various cleanups and fixes to handling of region accesses, including: - there should be no reason for us to split accesses into 1/2/4/8 byte accesses: in general, the client will have already be doing that, and if not, there's no particular reason we should be the ones to split up such larger accesses. - use a callback for PCI config space reads and writes if one is provided (needs more work for capabilities) Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-04pass vfu_ctx_t to callbacks (#222)John Levon1-30/+29
It's easy (with the new vfu_get_private()) to go from a vfu_ctx to the private pointer, but not the reverse; pass the ctx into all the callbacks. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-02use log level defines from syslogThanos Makatos1-15/+15
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-11-27rename to libvfio-user (#128)John Levon1-45/+56
The muser name no longer reflects the implementation, and will just serve to confuse. Bite the bullet now, and rename ourselves to reflect the actual implementation. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2020-11-24Api refactoring (#115)swapnili1-5/+7
API refactoring
2020-11-24parse VFIO_USER_VERSION JSON stanzaJohn Levon1-2/+16
2020-11-23fix printf argsThanos Makatos1-4/+4
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-11-20don't expose migration as regionThanos Makatos1-3/+3
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-11-20move migration into separate fileThanos Makatos1-0/+468
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>