aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2021-03-10fix IRQ disable path (#386)John Levon3-178/+138
Properly fix IRQ disabling: Allow count == 0 to mean "disable all IRQS of the given type". On our side, disabling an IRQ means forgetting about the eventfd that was previously passed over the socket. Allow individual IRQs to be disabled, by means of a VFIO_IRQ_SET_DATA_EVENTFD message with no file descriptors passed. In vfio, this is done via setting "-1" in the fd slots; which isn't possible via auxiliary data. Thus, only one IRQ can be disabled a a time in vfio-user. Clean up "->type": this is never set, so wasn't having any effect. Follow up changes will likely re-introduce this in some form. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-09remove vfu_irq_message() (#389)John Levon1-22/+0
This sends a message to a vfio-user client to trigger an IRQ, instead of writing to an eventfd. However, this isn't necessary on the cases we care about, where eventfds *are* available. Furthermore, this isn't something an API user should need to know about: if we ever care, the better way to do this is to make vfu_irq_trigger() automatically use a message if an eventfd isn't available. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-04don't munmap(2) unmapped DMA region (#384)Thanos Makatos1-21/+22
Plus always notify user when DMA region is removed. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-03-01don't call user's unmap_dma callback when removing DMA region (#370)Thanos Makatos1-8/+5
Plus unit tests. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reported-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-24ignore VFIO_IRQ_SET_DATA_NONE (#364)Thanos Makatos1-0/+10
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-22don't use wrong buf offset for responding with PCI caps (#355)Thanos Makatos1-0/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Signed-off-by: John Levon <john.levon@nutanix.com>
2021-02-22tran_sock: don't leave errno unset when failing to attach (#352)Thanos Makatos1-2/+3
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-18use UNUSED consistently (#350)John Levon1-3/+0
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-18use sizeof() consistently (#351)John Levon6-52/+52
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 Makatos4-95/+160
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-17add unit tests for handle dirty pages w/o DMA (#348)Thanos Makatos1-1/+3
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-16exec_command: free out structs on failure (#345)John Levon1-0/+4
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-16fix DEVICE_GET_INFO specification and handling (#344)John Levon2-12/+18
The specification for DEVICE_GET_INFO differed from the implementation. After some discussion, fix the spec such that the struct should be passed in with ->argsz set. As it happened, the implementation was also wrong: we weren't actually checking the incoming ->argsz for validation, but we should. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-15implement server-side max_msg_size (#323)John Levon1-4/+15
Pick an arbitrary limit of 65536, and report it back. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-15add vfu_get_poll_fd() (#322)John Levon3-81/+106
Library users can use this to sleep on either a newly-attached socket client, or a new message. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-15make file descriptors private to the transport (#321)John Levon3-35/+103
General code has no business knowing about the socket file descriptors. vfu_attach_ctx() is changed to not return the file descriptor; we'll re-expose a suitable file descriptor in a follow-up Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-15handle VFIO_USER_DIRTY_PAGES in stopped and stop-and-copy states (#335)Thanos Makatos1-5/+9
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-15ack dirty page commands w/o DMA controller (#334)Thanos Makatos1-2/+7
need unit tests Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-11move exec_command socket handling into the transport (#320)John Levon3-104/+135
Also clean up some code surrounding this. In particular, don't play games with modifying the message header. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-11tiny rename of vfu_ctx_t::trans -> tran (#315)John Levon3-22/+22
This matches the tran_* namespace better. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-11introduce transport reply() handler (#313)John Levon3-10/+24
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-10don't expose -errno in public API (#327)John Levon2-2/+8
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-10API error return converged to one func (#325)swapnili5-67/+66
* API error return converged to one func Use ERROR_INT() or ERROR_PTR() to return errors from API's. This way if we want to change the behaviour later, we will just need to update these funcitons. Also fixed some error return cases and comments. Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-10set VFIO_REGION_INFO_FLAG_CAPS for migration region (#319)Thanos Makatos1-3/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-10expose migration region (#305)Thanos Makatos4-37/+121
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-02-09introduce transport send_msg() handler (#314)John Levon4-10/+28
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-09remove recv_blocking() (#316)John Levon1-22/+3
It has the incorrect implication that other socket I/O is necessarily non-blocking. Replace with an explicit recv(..., MSG_WAITALL). Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-05use tran_sock_*() namespace (#308)John Levon4-120/+122
Rename (again!) all internal tran_sock APIs so it's very clear which cases are directly using them, perhaps when they shouldn't. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-04fix vfio_irq_idx_to_str() (#309)John Levon1-10/+11
This debug helper wasn't handling all the valid IRQ indexes. Found via ASAN. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-04open_sock(): remove stale comment (#307)John Levon1-4/+0
We fixed it so we don't accept() when we create the context, but only when we attach. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-04close listening socket in vfu_destroy_ctx() (#299)John Levon3-14/+37
We were forgetting to close vfu_ctx->fd, add a tran callback for this. While we're there, clean up the tran callbacks somewhat. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-02define full PCI Express capability struct (#289)John Levon1-1/+1
Define the full-size capability as defined in the specification. Previously, we were defining the structure as in the form used by PCI Express Integrated Endpoints. It's reasonable to assume, however, that a vfio-user device is a normal PCI Express Endpoint connected over a Link. We'll go further, and define the whole structure, including the slot registers at the end that are usually only used for Ports. The presumption here is that it can't hurt to use the larger size: the only way a client could care is if it presumed the next capability was at a particular offset from this one, and we must hope nothing is that silly. This also corrects a buffer overflow: cap_size() in fact disagreed with the original size of our struct pxcap (found via clang's address sanitizer). Signed-off-by: John Levon <john.levon@nutanix.com Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-01remove stale FIXME (#290)John Levon1-1/+0
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28install static library (#267)John Levon1-0/+3
SPDK would like to statically link in libvfio-user, and it builds against a staged installation directory, so always install the static library too. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28use unique errno when recv msg ID doesn't match (#280)Thanos Makatos1-1/+1
This is simply to make debugging easier. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28don't leak FDs after response (#284)Thanos Makatos1-1/+1
Signed-off-by: Thanos Makatos <thanos.makatos@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 Makatos2-26/+58
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-25don't assume specific message ID when negotiating (#248)Thanos Makatos1-3/+5
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25print errno string instead of errno value (#251)Thanos Makatos1-2/+2
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>