aboutsummaryrefslogtreecommitdiff
path: root/lib/libvfio-user.c
AgeCommit message (Collapse)AuthorFilesLines
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 Levon1-102/+96
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 Levon1-17/+17
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 Levon1-10/+7
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 Levon1-2/+2
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)swapnili1-32/+34
* 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 Makatos1-27/+80
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 Levon1-6/+6
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-05use tran_sock_*() namespace (#308)John Levon1-9/+10
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-04close listening socket in vfu_destroy_ctx() (#299)John Levon1-3/+10
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-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-28don't leak FDs after response (#284)Thanos Makatos1-1/+1
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-21Misc fixes for DMA_MAP region prot (#233)swapnili1-1/+3
* Misc fixes for DMA_MAP region prot 1. Validate prot passed in vfu_addr_to_sg() 2. Let user know region prot via vfu_unmap_dma_cb_t Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-20support extended capabilities (#226)John Levon1-0/+1
Provide initial support for extended capabilities, and implement handlers for the Device Serial Number and Vendor-Specific capabilities. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-01-20add whole-region mmap area for vfu_setup_region() (#225)John Levon1-49/+38
If an fd is provided, automatically add a mmap area covering the entire region unless an mmap_areas array is provided. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-01-20re-work API for adding capabilities (#200)John Levon1-4/+2
Allow to add capabilities individually, including extended capabilities, and those to be handled via the region callback. As a side effect, rework config space accesses to handle reads that straddle capabilities and non-standard areas and use callbacks as needed. 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-13don't fail vfio_device_info if incoming struct has more fields (#232)Thanos Makatos1-1/+1
Such incompatibilites are expected in the VFIO protocol. That's what argsz is for. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-13make vfu_region_to_offset public (#228)Thanos Makatos1-0/+6
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-08Use prot flags sent by client to map dma regions (#227)swapnili1-3/+4
* Use prot flags sent by client to map dma regions Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-07re-work access handling (#220)John Levon1-302/+199
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-05re-work capability-locating API (#199)John Levon1-8/+0
Explicitly mimic the Linux kernel API: the searching functions return an offset into configuration space. Just like a driver, libvfio-user devices can then look into config space via vfu_pci_get_config_space() to read the capability as needed. In general, the driver itself will know exactly what the size and shape of the capability is, so this seems like a low-friction, and familiar to driver writers, API. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-04move PCI-specific code to pci.c (#219)John Levon1-168/+15
It's still pretty entangled, but move the bulk of the non-cap PCI code over to pci.c. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-04remove vestigial vfu_mmap() (#221)John Levon1-17/+0
This is no longer useful. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-04pass vfu_ctx_t to callbacks (#222)John Levon1-9/+14
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-18don't set wrong buffer size when replying to device info region (#217)Thanos Makatos1-5/+7
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-17General fixes (#213)swapnili1-24/+19
* Reorg vfu_create_ctx() * Unconditionally call dma_controller_create() in vfu_setup_device_dma_cb(). * Added UT for vfu_setup_device_dma_cb() Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-16enable ERR and REQ IRQs by default (#209)Thanos Makatos1-0/+9
enable ERR and REQ IRQs by default Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2020-12-16don't treat non-zero return value of dma_controller_add_region as failure (#206)Thanos Makatos1-0/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-15send file descriptors for sparse areas in get region info (#201)Thanos Makatos1-20/+63
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-15remove vfu_get_pci_non_std_config_space() (#195)John Levon1-11/+1
Remove this API as well as vfu_pci_non_std_config_space_t. It's at best confusing to try to represent this area as if it's not just a normal part of the overall config space, and we don't really want an additional API for the extended space past either. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-14return region capabilities a la VFIO (#187)Thanos Makatos1-19/+25
This patch returns region capabilities the same way VFIO does: if argsz is not large enough then it returns only region info and sets argsz to what it should be in order to fit the capabilities, the client then retries with a large enough argsz. The protocol specification has been updated as well. Plus unit tests. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-14add unit test for device get info (#192)Thanos Makatos1-1/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-14don't return memory allocated on the stackThanos Makatos1-16/+30
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-11minor comment fixesThanos Makatos1-0/+8
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-10Drop vfu_ctx_drive() and use vfu_ctx_poll() (#178)swapnili1-20/+9
* Drop vfu_ctx_drive() and use vfu_run_ctx() Renamed vfu_ctx_poll() to vfu_run_ctx(). Updated vfu_run_ctx() to also handle blocking ctx. Instead of having separate functions for blocking and non-blocking ctx, better to have one. This way user can call same set of functions for both cases. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-08Misc fixes for vfu_ctx_try_attach() and vfu_realize_ctx() (#175)swapnili1-37/+7
Misc changes for vfu_ctx_try_attach() * Rename to vfu_attach_ctx() * Removed call to vfu_realize_ctx(), should be called separately * Now vfu_attach_ctx() must also be called for blocking ctx. Misc changes for vfu_realize_ctx() * Made calling vfu_realize_ctx() mandatory * vfu_ctx_drive() and vfu_poll_ctx() returns EINVAL if the device is not realized. * Renamed vfu_ctx->ready to vfu_ctx->realized Added unit test for vfu_attach_ctx() and vfu_realize_ctx() Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-07rename prepare_ctx into vfio_realize_ctx and make it publicThanos Makatos1-11/+11
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-07don't ignore PCI type set by userThanos Makatos1-0/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-07convert vfu_ctx->read to boolThanos Makatos1-3/+3
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-07group PCI membersThanos Makatos1-21/+21
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-04implement VFIO_USER_FLAG_NO_REPLY (#157)John Levon1-6/+14
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-02don't spam logs when closing unexpected file descriptorThanos Makatos1-7/+3
A malicious client might take advantage of this behavior. Also, don't differentiate between failure and extraneous FD cases. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-02replace struct vfu_mmap_area with struct iovecThanos Makatos1-5/+5
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-02emit warning when receiving extraneous file descriptorsThanos Makatos1-1/+7
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-02rename VFU_REG_FLAG_* (#145)John Levon1-4/+4
We renamed other code to be "REGION" instead of "REG" so it's less ambiguous. Do the same for VFU_REG_FLAG_*. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2020-12-02use log level defines from syslogThanos Makatos1-56/+56
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-02introduce PCI typesThanos Makatos1-13/+31
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>