aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-09-18test_negotiate: add migration testing (#781)HEADmasterJohn Levon1-8/+6
Add migration support to the test setup, and complete some additional testing for the migration JSON capability. Signed-off-by: John Levon <john.levon@nutanix.com>
2023-09-18fix: minor memory bugs #784 William Henderson2-10/+4
Fixes the following Coverity reports: ________________________________________________________________________________________________________ *** CID 417161: Memory - corruptions (ARRAY_VS_SINGLETON) /samples/server.c: 438 in migration_write_data() 432 } 433 434 /* write to bar0, if any */ 435 if (write_end > server_data->bar1_size) { 436 length_in_bar0 = write_end - write_start; 437 write_start -= server_data->bar1_size; CID 417161: Memory - corruptions (ARRAY_VS_SINGLETON) Using "&server_data->bar0" as an array. This might corrupt or misinterpret adjacent memory locations. 438 memcpy(&server_data->bar0 + write_start, buf + length_in_bar1, 439 length_in_bar0); 440 } 441 442 server_data->migration.bytes_transferred += bytes_written; 443 ________________________________________________________________________________________________________ *** CID 417160: Memory - corruptions (ARRAY_VS_SINGLETON) /samples/server.c: 394 in migration_read_data() 388 } 389 390 /* read bar0, if any */ 391 if (read_end > server_data->bar1_size) { 392 length_in_bar0 = read_end - read_start; 393 read_start -= server_data->bar1_size; CID 417160: Memory - corruptions (ARRAY_VS_SINGLETON) Using "&server_data->bar0" as an array. This might corrupt or misinterpret adjacent memory locations. 394 memcpy(buf + length_in_bar1, &server_data->bar0 + read_start, 395 length_in_bar0); 396 } 397 398 server_data->migration.bytes_transferred += bytes_read; 399 ________________________________________________________________________________________________________ *** CID 417159: Possible Control flow issues (DEADCODE) /lib/libvfio-user.c: 121 in dev_get_caps() 115 116 header = (struct vfio_info_cap_header*)(vfio_reg + 1); 117 118 if (vfu_reg->mmap_areas != NULL) { 119 int i, nr_mmap_areas = vfu_reg->nr_mmap_areas; 120 if (type != NULL) { CID 417159: Possible Control flow issues (DEADCODE) Execution cannot reach this statement: "type->header.next = vfio_re...". 121 type->header.next = vfio_reg->cap_offset + sizeof(struct vfio_region_info_cap_type); 122 sparse = (struct vfio_region_info_cap_sparse_mmap*)(type + 1); 123 } else { 124 vfio_reg->cap_offset = sizeof(struct vfio_region_info); 125 sparse = (struct vfio_region_info_cap_sparse_mmap*)header; 126 } Signed-off-by: William Henderson <william.henderson@nutanix.com>
2023-09-18Add some notes on live migration version and SPDK usage. (#783)John Levon2-0/+14
Signed-off-by: John Levon <john.levon@nutanix.com>
2023-09-15adapt to VFIO live migration v2 (#782)William Henderson25-2357/+2497
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>
2023-09-15Pass server->client command over a separate socket pair (#762)Mattias Nissler9-23/+373
Use separate socket for server->client commands This change adds support for a separate socket to carry commands in the server-to-client direction. It has proven problematic to send commands in both directions over a single socket, since matching replies to commands can become non-trivial when both sides send commands at the same time and adds significant complexity. See issue #279 for details. To set up the reverse communication channel, the client indicates support for it via a new capability flag in the version message. The server will then create a fresh pair of sockets and pass one end to the client in its version reply. When the server wishes to send commands to the client at a later point, it now uses its end of the new socket pair rather than the main socket. Corresponding replies are also passed back over the new socket pair. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com>
2023-09-15Describe the twin-socket feature in the spec (#775)Mattias Nissler1-8/+83
Signed-off-by: Mattias Nissler <mnissler@rivosinc.com>
2023-08-31update SDPK version spdk.md (#769)Thanos Makatos1-5/+5
The SPDK and QEMU versions were too old. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2023-08-31Introduce client object in python tests (#772)Mattias Nissler21-351/+365
Thus far, the client end of the socket is the only piece of client state tracked in tests, for which a global `socket` variable has been used. In preparation to add more state, replace the `socket` global with a `client` global object that groups all client state. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-08-31Prepare python test helpers for receiving commands (#774)Mattias Nissler1-21/+56
Thus far, the python test code has only ever sent messages of type commands to the server and processed the corresponding replies. For the twin-socket feature, the tests will exercise flows where DMA access commands must be received, processed, and replied to by the client. This change refactors the message handling python test code to provide functions to handle server-to-client commands, reusing existing code as appropriate. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-08-31Construct server capabilities using json-c (#771)Mattias Nissler1-25/+106
String formatting is hitting its limits: Adding another field is difficult given that we already branch on whether migration is enabled. This change constructs a JSON-C object instead so we can add what we need and serialize to a string afterwards. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-08-30Replace protocol header flags bit field with mask (#773)Mattias Nissler5-23/+21
It turns out that the bit field will not yield the desired / specified bit layout on big-endian systems, see issue #768 for details. Thus, replace the bit field with constants for the individual fields and use bit masking when accessing the flags field. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-08-23fix: incorrect number of dirty pages printed (#766)William Henderson1-1/+1
The `log_dirty_bitmap` function in `dma.c` would output the wrong number of dirty pages due to the `char` of the bitmap being sign-extended when implicitly being converted to `unsigned int` for `__builtin_popcount`. By adding an intermediate cast to `uint8_t` we avoid this incorrect behaviour. See https://github.com/nutanix/libvfio-user/pull/746#discussion_r1297173318. Signed-off-by: William Henderson <william.henderson@nutanix.com>
2023-08-15Make debian-11, debian-12 and arch-202307 required pull request jobsSandro-Alessio Gierens1-0/+3
Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
2023-08-15Revise iovec_t.__eq__ and vfu_dma_info_t.__eq__ to fix flake8 E721Sandro-Alessio Gierens1-2/+2
The newer flake8 version in the arch linux job of the pull request workflow fails due to: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` Both `__eq__` functions now use `is not` instead of `!=` for the type initial check. Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
2023-08-15Add debian 11, 12 and arch linux jobs to pull_request workflowSandro-Alessio Gierens1-0/+41
This adds jobs to `.github/workflows/pull_request.yml` for Debian 11 bullseye, Debian 12 bookworm and Arch Linux base 20230723.0.166908. Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
2023-08-15Bump Github Actions version to v3Sandro-Alessio Gierens2-6/+6
Node12 and as a result Github Actions v2 will apparently soon be deprecated, see: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/ Thus this changes all workflow jobs to use `actions/checkout@v3`. Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
2023-08-15Introduce close_safely helper function (#763)Mattias Nissler6-63/+49
The helper function centralizes some extra checks and diligence desired by many/most current code paths but currently inconsistently applied. This includes bypassing the close call when the file descriptor is -1 already, resetting the file descriptor variable to -1 after closing, and preserving errno. All calls to close are replaced by close_safely. Some warning log output is lost over this, but it doesn't seem like this was very useful anyways given that Linux always closes the file descriptor anyways. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com>
2023-08-15Allow adding MSI capability via vfu_pci_add_capability (#758)Florian Freudiger5-14/+152
Signed-off-by: Florian Freudiger <25648113+FlorianFreudiger@users.noreply.github.com>
2023-08-15Add another lspci test output variant (#761)Sandro-Alessio Gierens2-1/+31
This adds the expected output to the lspci test I get on my Arch with kernel version 6.1.44-lts and pciutils version 3.10.0. Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
2023-08-08Fix MSI-X capability write logging opposite status (#759)Florian Freudiger1-3/+3
Signed-off-by: Florian Freudiger <25648113+FlorianFreudiger@users.noreply.github.com>
2023-08-02fix: server sample not marking dirty pages (#748)William Henderson2-66/+173
The server sample is supposed to demonstrate dirty page logging, but it was not marking dirty pages. This commit both adds client-side dirty page tracking for pages dirtied with `vfu_sgl_write` and server-side dirty page tracking for pages directly dirtied by the server using `vfu_sgl_get/put`. Signed-off-by: William Henderson <william.henderson@nutanix.com>
2023-08-02docs: document test debugging with GDB (#756)William Henderson1-0/+12
Signed-off-by: William Henderson <william.henderson@nutanix.com>
2023-07-31docs: document DMA message dirty handling (#755)John Levon2-2/+9
Document that on vfu_sgl_write(), it's the client's responsibility to track any dirty pages. Signed-off-by: John Levon <john.levon@nutanix.com>
2023-07-31fix: CRC calculation in client sample (#750)William Henderson1-5/+1
Signed-off-by: William Henderson <william.henderson@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-07-24refactor: remove private includes from server.c (#752)William Henderson1-2/+0
Signed-off-by: William Henderson <william.henderson@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-07-03Fix address calculation for message-based DMA (#740)Mattias Nissler2-25/+39
The correct DMA address is formed by adding base and offset - the latter was accidentally missing. Change the server example to read and write blocks at non-zero offsets, such that `test-client-server.sh` exercises offset handling. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com>
2023-06-22fix build instructions for samples (#739)William Henderson1-5/+5
Signed-off-by: William Henderson <william.henderson@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-06-21Fix some python tests (#737)Axel PASCON3-6/+6
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-06-08fix err/req irq fd issue (#731)limiao-intel2-17/+64
When handle_device_set_irqs set err irq/req irq, fd will be filled in vfu_ctx->irqs->efds[] rather than vfu_ctx->irqs->err_efd or vfu_ctx->irqs->req_efd. This patch adds irq index judgment before filling in fd to make sure fd is filled in the correct place. Signed-off-by: Miao Li <miao.li@intel.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-05-24test: don't leave global pointing to stack memory (#735)Jim Harris1-0/+1
test_device_is_stopped_and_copying points the global vfu_ctx structure to a local stack-allocated data structure. This is fine while the function is executing, but newer gcc complains that the pointer is left there after it returns. So clear the pointer to NULL before returning. Fixes issue #734. Reported-by: Kamil Godzwon <kamilx.godzwon@intel.com> Signed-off-by: Jim Harris <james.r.harris@intel.com>
2023-01-04allow -1 file descriptor for ioregionfd (#727)Thanos Makatos3-1/+111
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2023-01-03fix FLR reset callback (#729)John Levon6-33/+64
A reset callback is allowed to call functions disallowed in quiescent state. However, the FLR reset path neglected to account for this properly, causing an incorrect assert to be triggered if, for example, vfu_sgl_put() is called. To fix this, make sure all reset paths go through call_reset_cb(). Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2023-01-01test: use `grep -E` instead of `egrep` (#728)Ville Skyttä1-1/+1
`egrep` has been deprecated in GNU grep since 2007, and since 3.8 it emits obsolescence warnings: https://git.savannah.gnu.org/cgit/grep.git/commit/?id=a9515624709865d480e3142fd959bccd1c9372d1 Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2022-11-22shadow ioeventfd: add demo (#722)Thanos Makatos5-0/+329
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-11-22vfu_pci_init: initialize PCI config space flags (#724)Thanos Makatos2-0/+74
vfu_pci_init() sets the size of the PCI config space but not the flags; vfu_realize_ctx() won't initialize the flags since the size if already set. vfu_pci_init() must initialize flags as well. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-11-22add debugging to handle_device_get_region_io_fds (#723)Thanos Makatos1-0/+4
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-11-22fix shadow ioeventfd unit test (#726)Thanos Makatos2-3/+3
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-11-22allow shadow memory offset per shadow ioeventfd (#703)Thanos Makatos7-28/+34
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-11-16check spelling (#720)John Levon6-3/+22
Use misspell-fixer if available, and correct the small number of errors it found. Rather than trying to install into the CI, run it directly from a github action. 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>
2022-10-05add some unlikely (#717)Thanos Makatos1-13/+16
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-10-05only call debug_region_access if in debug mode (#716)Thanos Makatos1-1/+9
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-10-05don't duplicate FD in get region info (#715)Thanos Makatos2-22/+5
This is out of spec. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-10-04fix compilation for i386 and ppc64 (#709)Thanos Makatos23-204/+319
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-10-03document how to run individual Python unit tests (#712)Thanos Makatos1-0/+7
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-08-18make SGL error-checking DEBUG-only (#706)John Levon1-3/+11
As vfu_addr_to_sgl() and co are on the hot path, compile out these sanity checks for non-DEBUG builds. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2022-08-18avoid vfu_log() in SGL hot path (#705)John Levon4-1/+18
Even though in non-debug, we don't actually log anything here, even assembling the arguments to vfu_log() has a performance impact. Hide them behind a DEBUG_SGL define - even in a DEBUG build, they are particularly noisy and low-value. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2022-08-08delete socket on vfu_ctx_destroy (#702)Thanos Makatos4-5/+13
fixes #660 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>
2022-07-21disable client-server test by default (#700)John Levon2-12/+16
This test is flaky: there is some kind of race that causes the test to hang. Now we are run as part of qemu CI, we need to disable this by default, until we can find time to fix the test. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2022-07-04support for shadow ioeventfd (#698)Thanos Makatos12-13/+184
When an ioeventfd is written to, KVM discards the value since it has no memory to write it to, and simply kicks the eventfd. This a problem for devices such a NVMe controllers that need the value (e.g. doorbells on BAR0). This patch allows the vfio-user server to pass a file descriptor that can be mmap'ed and KVM can write the ioeventfd value to this _shadow_ memory instead of discarding it. This shadow memory is not exposed to the guest. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com> Change-Id: Iad849c94076ffa5988e034c8bf7ec312d01f095f
2022-06-16improve README.md (#696)John Levon1-114/+100
Re-organize the README so it flows better, and make several fixes/improvements. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>