aboutsummaryrefslogtreecommitdiff
path: root/samples
AgeCommit message (Collapse)AuthorFilesLines
2021-04-06samples client/server: log more consistently (#420)John Levon2-25/+30
Prefix logs with client/server; run the tests verbosely. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-31rework DMA callbacks (#396)John Levon2-37/+30
This fixes a number of issues with how DMA is handled, based on some changes by Thanos Makatos: - rename callbacks to register/unregister, as there is not necessarily any mapping - provide the (large) page-aligned mapped start and size, the page size used, as well as the protection flags: some API users need these - for convenience, provide the virtual address separately that corresponds to the mapped region - we should only require a DMA controller to use vfu_addr_to_sg(), not an unregister callback - the callbacks should return errno not -errno - region removal was incorrectly updating the region array - various other cleanups and clarifications Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-23globally define _GNU_SOURCE (#401)John Levon2-2/+0
This avoids any issues with multiple definitions when passing CFLAGS in. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-03-23add -Wmissing-declarations (#399)John Levon2-8/+11
This is used by SPDK, and it's generally useful. This also uncovered some issues in the test mocking. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-03-09remove vfu_irq_message() (#389)John Levon2-52/+17
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-02gpio-pci-idio-16: fix library dependency (#382)John Levon1-1/+1
Link gpio sample against "vfio-user-shared" to correct CMake dependencies. This was breaking "make -j" builds. Reported-by: Karol Latecki <karol.latecki@intel.com> Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-03-01use shared libvfio-user object for gpio sample (#372)Thanos Makatos1-1/+2
This makes it easier to test that libvfio-user is correctly installed. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-03-01optionally enable DMA controller in GPIO sample (#375)Thanos Makatos1-2/+25
This helps debugging. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-18use sizeof() consistently (#351)John Levon2-40/+40
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-16support live migration in GPIO sample (#324)Thanos Makatos1-3/+84
* gpio: support live migration Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-02-10don't expose -errno in public API (#327)John Levon2-16/+15
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 Makatos2-36/+75
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-09samples/client: fix confusion over region_info argsz (#318)John Levon1-2/+2
get_device_region_info() was accidentally using the region size as the region info argsz. 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-53/+55
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-04client/server: print number of FDs per region (#302)Thanos Makatos1-2/+4
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-04client/server: misc comments (#304)Thanos Makatos1-1/+12
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-04client/server: move mapping sparse areas to separate function (#301)Thanos Makatos1-14/+36
And print file path when it fails to mmap. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-01samples/lspci: free vfu context (#293)John Levon1-0/+2
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-01-28client/server: don't sleep before migrating (#281)Thanos Makatos1-8/+0
Migration now takes a non-trivial amount of time, plus running the sample through Valgrind will inherently be slower. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28client/server: arm timer for a little longer (#283)Thanos Makatos1-3/+3
The interrupt might be delivered too soon, when e.g. the client is waiting for a response for a message it previously sent. This isn't 100% bulletproof. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28client/server: don't leak memory in client (#285)Thanos Makatos1-0/+6
Not that useful, apart from running it through Valgrind in CI. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28client/server: make number of migration iterations deterministic (#277)Thanos Makatos1-10/+3
The number of migration iterations would depend on whether or how many times the fake guest thread would touch BAR1. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28client/server: disarm timer when device is stopped (#276)Thanos Makatos1-0/+5
When the device is set to stop-and-copy state it must stop operating, which means that if it has been previously programmed to triggers it should refrain from doing so. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28client/server: don't sleep for fake guest thread (#275)Thanos Makatos1-3/+0
The fake guest thread unconditionally performs the first iteration, so there's no need to give it time to do stuff. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-28simplify client/server pre-copy phase by always copying entire BAR1 (#273)Thanos Makatos2-110/+53
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-27allow device to specify data_offset when resuming (#272)Thanos Makatos1-10/+4
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-27implement fake guest thread in client/server live migration sample (#264)Thanos Makatos3-21/+130
* add fake guest thread in migration sample This patch adds a thread that pretends to be the guest VM (while the client itself is the VMM) in the live migration sample. Our goal is to have the fake guest modifying device state while live migration is ongoing and when live migration has finished the device state should be correct in the destination server. Currently this doesn't work because the server blindly applies device state when resuming, which is wrong because some device state must be applied to specific offsets. To fix this we have to include the offset and length (along with BAR1 data) in the migration stream. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26store BAR1 in pre-copy and BAR0 in stop-and-copy (#256)Thanos Makatos1-6/+17
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26drop data_size and migr_data (#245)Thanos Makatos1-20/+14
We don't need data_size, it only complicates things. We don't use migr_data at all. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-26minor comments and assertions (#258)Thanos Makatos1-1/+3
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25add pre-copy phase in live migration example (#247)Thanos Makatos2-112/+248
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-5/+2
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25use unique message IDs in client sample (#255)Thanos Makatos1-10/+11
This makes debugging a little bit easier. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25don't use uninitialized memory (#244)Thanos Makatos1-4/+7
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-2/+34
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-20re-work API for adding capabilities (#200)John Levon1-9/+19
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-04re-work PCI config setup API (#198)John Levon5-29/+23
Split up vfu_pci_setup_config_hdr(): individual "helpers" like vfu_pci_set_id() are much simpler to use than making the user specify the values in header-formatted structs; and this way if we want to add additional helpers, we won't need to modify the existing functions. 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 Levon4-45/+44
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>
2021-01-04remove Python bindings (#223)John Levon1-37/+0
They haven't kept pace with recent changes, and at this point are of no real use (and besides, options like CFFI are likely better than hand-rolled bindings). Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-17Fix passing of recv_data (#214)swapnili1-1/+1
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-16fix clang build (#210)John Levon1-12/+19
Also add clang to pull request build checks. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-15send file descriptors for sparse areas in get region info (#201)Thanos Makatos3-28/+48
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-14return region capabilities a la VFIO (#187)Thanos Makatos2-48/+69
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-14don't leak memory in server sampleThanos Makatos1-0/+1
Make valgrind happy. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-11add support PCI vendor-specific capabilityThanos Makatos1-3/+6
The PCI vendor-specific capability is blindly read/written by the library. It is possible that the user might want to intercept accesses to it, in which case we'll have to add callback. The best way to do this to introduce a new function that configures callbacks for the PCI capabilities, e.g. typedef ssize_t (vfu_cap_access_t) (void *pvt, uint8_t id, char *buf, size_t count, loff_t offset, bool is_write); vfu_pci_cap_set_cb(vfu_ctx-T *vfu_ctx, uint8_t cap_id, vfu_cap_access_t *cb); This way the existing API won't have to change. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-10Drop vfu_ctx_drive() and use vfu_ctx_poll() (#178)swapnili3-3/+3
* 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)swapnili3-0/+30
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-08build a static libvfio-user (#173)John Levon1-6/+6
Note that we intentionally don't install it: this is really for use when building as a sub-module. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-07lspci: fix build with gcc 4 (#172)John Levon1-4/+4
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>