aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2022-05-23libvfio-user.h: sync VFIO_DEVICE_STATE_XXXX definitions with upstream (#690)Jag Raman3-40/+40
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-05-12run scan-build in CI (#680)John Levon2-1/+5
Yet another static analyzer pass, this one is used by SPDK, and as it did detect some minor issues, it's worth running. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2022-05-09build: delete CMake build rulesDaniel P. Berrangé1-89/+0
Now that Meson is functional, support for building with CMake is removed so that there is only one build system to maintain. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-05-09build: introduce Meson build file rulesDaniel P. Berrangé1-0/+47
The Meson build system used by many other virt projects (QEMU, libvirt and others) is easier to understand & maintain rules for than cmake, guiding towards best practice. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-04-28lib: export dma_sg_size symbol in library (#664)Daniel Berrangé1-1/+1
The dma_sg_size() method is listed in libvfio-user.h but the symbol is marked private in the ELF library. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2022-04-21fix a small coverity complaint (#663)John Levon1-6/+0
The complaint was: 259 if (ret != 0) { >>> CID 392380: Possible Control flow issues (DEADCODE) >>> Execution cannot reach this statement: "free(tp);". 260 free(tp); 261 return ERROR_INT(ret); 262 } Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2022-04-21support AFL++ fuzzing (#623)John Levon9-340/+1002
To support fuzzing with AFL++, add a "pipe" transport that reads from stdin and outputs to stdout: this is the most convenient way of doing fuzzing. Add some docs on how to run a fuzzing session. 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-04-19use struct iovec for grouping buffer and length (#658)Thanos Makatos4-124/+118
This make it tidier and easier to pass to function the buffer and length, instead of passing the whole msg. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-03-07check for allowed operations in quiesce state (#647)Thanos Makatos4-0/+60
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-03-02improve region access debugging (#653)John Levon3-60/+49
Many region accesses of interest are of normal register sizes; sniff the region access size, and report the read/written value if possible. Clean up dump_buffer() now, as it's not of much use. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@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>
2022-02-24additional logging around dirty pages (#650)Thanos Makatos2-0/+30
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-02-04ignore writes to RO MSI-X registers (#642)Thanos Makatos1-32/+19
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2022-01-17small get_request_header() cleanup (#637)John Levon1-9/+2
LGTM.com reports "Comparison is always true because ret <= -1.", and it's indeed correct (but harmless). Clean this up. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-12-22fix coverity issues (#636)John Levon1-0/+1
Fix three remaining low priority coverity issues; they do not represent bugs. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-12-09allow DMA funcs to be called in quiesced state (#635)Thanos Makatos1-2/+0
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-12-01refactor process_request() (#633)John Levon2-177/+200
Instead of process_request() having a dual role, split into get_request() and handle_request(). Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-11-30introduce device quiesce callback (#609)Thanos Makatos8-100/+256
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Leon <john.levon@nutanix.com>
2021-11-24verify region is mapped before acquiring dirty bitmap (#627)John Levon1-0/+12
DMA regions not mapped by the server are not dirty tracked (the client must track changes via handling VFIO_USER_DMA_WRITE), but we weren't correctly enforcing this, which could segfault when ->dirty_bitmap was NULL. Found via AFL++. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-11-24check ->argsz for VFIO_USER_DIRTY_PAGES (#628)John Levon1-5/+12
We weren't checking for a too-large ->argsz for this command. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-11-24fix dma unmap validation (#626)John Levon1-40/+57
There were two issues with unmap request validation when the dirty bitmap flag was set: - we weren't checking ->argsz against the maximum transfer size, allowing a client to trigger unbounded allocations - we needed to check for overflow when calculating the requested message out size Found via AFL++. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-11-24is_valid_region_access(): account for wrap-around (#624)John Levon2-2/+9
AFL++ found this, though we already knew about it, so fix it by comparing against a saturating addition. This was the only instance of client-controlled potential overflow I noticed. 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-11-12don't assert in dev_get_caps() (#621)John Levon1-5/+6
As clients control ->client_max_fds, we should return an error, not assert, if we can't represent a region's mmap_areas. Found via AFL++. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-11-11Fix reply of VFIO_USER_DEVICE_GET_REGION_INFO (#619)Swapnil Ingle1-4/+8
* Fix reply of VFIO_USER_DEVICE_GET_REGION_INFO Set VFIO_REGION_INFO_FLAG_CAPS flag only if caps are part of the reply. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-10-20fix coverity warnings (#611)John Levon1-1/+2
Fix a few coverity-identified issues. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-10-05make migration state callback optionally asynchronous (#608)Thanos Makatos3-14/+69
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-09-28disable VFIO_USER_DEVICE_GET_REGION_IO_FDS on invalid region (#607)John Levon1-0/+5
If a region is not set up, asking for its iofds should fail with EINVAL. Co-authored-by: John Levon <john.levon@nutanix.com> Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-09-28fix issue with get_region_io_fds when fd = -1 (#606)John Levon1-5/+1
An unmappable region should still allow io fds, as they are orthogonal. Co-authored-by: John Levon <john.levon@nutanix.com> Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-09-08initial ioeventfd support (#601)JAKelly102-1/+193
Provide initial support for handling VFIO_USER_DEVICE_GET_REGION_IO_FDS, along with a new vfu_create_ioeventfd() API. Reviewed-by: John Levon <john.levon@nutanix.com>
2021-08-27Add support for VFIO_DMA_UNMAP_FLAG_ALL flag (#600)Swapnil Ingle1-1/+24
* Add support for VFIO_DMA_UNMAP_FLAG_ALL flag Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-08-26Fix err path of handle_dma_unmap() (#597)Swapnil Ingle1-5/+5
* initial dma_unmap test Signed-off-by: John Levon <john.levon@nutanix.com> Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> * Fix err path of handle_dma_unmap() Set msg->out_size before successful return. Otherwise in case of error reply path we may endup setting iovecs[1].iov_len with invalid iovecs[1].iov_base in tran_sock_reply() Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-08-19dma: cleanup dma_{map,unmap}_sg (#591)Swapnil Ingle1-20/+28
* dma: cleanup dma_{map,unmap}_sg Instead of using index to traverse sg and iovec, better to use it as pointers. It's more readable and less prone from coding mistakes. Also adding unit tests for the same. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-08-17fix dma_{map,unmap}_sg() array handling (#586)John Levon1-6/+6
Multiple places in dma_map_sg() and dma_unmap_sg() were dereferencing sg[0] instead of the correct index. Take the opportunity to improve the doc comments at the same time. Reported-by: Changpeng Liu <changpeng.liu@intel.com> Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-07-29change verbosity of some PCI config space accesses (#584)Thanos Makatos1-18/+18
There's nothing special about most of these accesses so we shouldn't create unnecessary noise in the logs. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-07-14check for valid vfu_setup_region() flags (#579)John Levon1-5/+11
Complain about a region that isn't readable *or* writable, or any unknown flags. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-07-13add VFU_REGION_FLAG_ALWAYS_CB to receive callback always (#583)Jag Raman1-2/+9
2021-07-12basic write support for PXLC, PXSC, PXRS, and PXSC2 (#575)Thanos Makatos1-0/+32
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-07-12ignore writes to some RO registers in PCI config space (#576)Thanos Makatos1-4/+12
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-30return process request count in vfu_run_ctx() (#574)John Levon2-9/+14
Consumers such as SPDK would like to know if any actual work was done. Modify the API to support this. Also, clean up some stale mocking we no longer use. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-06-22disable EROM (#572)Thanos Makatos1-0/+2
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-22PCI: handle cache line register (#573)Thanos Makatos1-0/+5
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-22split writes to PCI header (#569)Thanos Makatos1-20/+61
Multiple registers can be written in one go so we need to split the write. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-18superficially handle Device Control 2 and Link Control 2 (#568)Thanos Makatos1-0/+32
* superficially handle Device Control 2 and Link Control 2 Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-18fix print (#567)Thanos Makatos1-2/+2
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-10dma: Fix returned sg array (#564)Swapnil Ingle1-1/+1
_dma_addr_sg_split() is supposed to return back sg's if the requested dma addr spans across regions. Also adding unit tests to cover these case. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-06-09clear dirty pages bitmap after getting dirty pages but keep mapped segments ↵Thanos Makatos3-71/+126
dirty (#551) Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-09drop mappable flag from DMA map (#553)Thanos Makatos1-6/+7
The flags field belongs to VFIO and it's not a good idea to reuse as new VFIO flags can break things. Instead, we derive whether or not a region is mappable if a file descriptor is passed. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-02replace max_msg_size with max_data_xfer_size (#541)John Levon4-67/+129
The previously specified max_msg_size had one major issue: it implied a (way too small) limit on the size of dirty bitmaps that could be requested by a client, and as a result a hard limit on memory region size. It seemed awkward to attempt to split up an unmap request instead. Instead, let most requests and replies be limited by their "natural" limits; for example, the number of booleans in VFIO_USER_SET_IRQS is limited by MSI-X count. For the requests that solicit or provide data - that is, VFIO_USER_DMA_READ/WRITE and VFIO_USER_REGION_READ/WRITE - we negotiate a new max_data_xfer_size value. These are much easier to split up into separate requests at the client side so should not present an implementation problem. For our server, chunking is implemented in vfu_dma_read/vfu_dma_write(). 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-06-02clean up migration register definitions (#550)John Levon2-8/+8
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-06-01limit max DMA region size (#545)John Levon5-8/+24
Since the dirty bitmap in message replies is allocated based upon the maximum size of an individual region, add a limit (somewhat arbitrarily 8TiB, which is a bitmap size of 256MiB). Add a couple of basic tests on the two DMA limits. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>