aboutsummaryrefslogtreecommitdiff
path: root/lib/tran_sock.c
AgeCommit message (Collapse)AuthorFilesLines
2022-04-21support AFL++ fuzzing (#623)John Levon1-299/+33
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 Makatos1-15/+15
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>
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-06-02replace max_msg_size with max_data_xfer_size (#541)John Levon1-9/+29
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-05-26remove a stale FIXME (#527)John Levon1-4/+0
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-05-26improve request header handlingJohn Levon1-4/+4
We should require a non-empty payload for every command type except VFIO_USER_DEVICE_RESET. We should also reply to the caller with such failures. Add some testing for is_valid_header(), and move the fd handling test over to it too. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-05-25more spec updates (#491)John Levon1-3/+2
update spec to v0.9.1 Changes include: - reply message includes the command number - split out message definitions into request/reply sections, and skip the repeated standard header definitions - lots of markup fixes - re-organization for clarity - further documentation of argsz - remove VFIO_USER_VM_INTERRUPT until we have a working implementation - dirty page tracking is optional - fix implementations to match the spec Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-05-11some specification updates (#465)John Levon1-6/+6
Make a few specification updates after review by Stefan Hajnoczi. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-05-04refactor message handling path (#376)John Levon1-34/+46
Capture message handling inside a new vfu_msg_t private structure and pass that around to the handlers. This provides no functional change, but greatly simplifies and cleans up that path, especially around fd and iovec handling. As part of fixing up the unit tests, start using global variables to reduce the amount of boiler-plate. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-14migration: use ERROR_INT() (#432)John Levon1-1/+1
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-13tran_sock: use ERROR_INT() (#431)John Levon1-54/+58
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-13dma: use ERROR_INT()John Levon1-0/+1
The first in a series excising the use of the "return -errno" idiom. This is a non-standard usage, and in userspace, we have "errno" for delivering side-band error values. As there have been multiple bugs from not using standard error return methods like -1+errno or NULL+errno, let's do that. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-08tran_sock: remove umask() (#435)John Levon1-6/+0
It's not our business to be setting umasks, and it's not necessary. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-04-07mark vfu_log() with format attribute (#426)John Levon1-3/+3
Fix up all resulting fallout. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-06tran_sock_send_iovec(): check for full write (#416)John Levon1-1/+7
Report -ECONNRESET to the caller if we failed to write the full expected message. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-06implement short read/write, EOF handling (#415)John Levon1-7/+7
Report any short reads to callers as ECONNRESET, which is the closest we can meaningfully get right now. This also fixes get_next_command(), which previously wasn't checking for short reads at all. When we fail to send or recv from the socket due to the client disappearing in some manner, call into vfu_reset_ctx() to clean up the connection fd, allowing a subsequent vfu_attach_ctx() to work. If we get 0 bytes from recv[msg](), this is reported by the transport as ENOMSG, and is a normal EOF condition. We can also get ECONNRESET: this can happen when we've written unacknowledged data to the socket, the client side socket is closed, and we try a subsequent read. Finally, we can get a short read or write. Our handling of these still has issues, but for now we'll presume this means the client has gone too. It may in fact be due to a client bug - if it failed to write enough data - but right now, we can't easily tell that. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-06tran_sock: fix EOF handling (#414)John Levon1-10/+16
Consistently check for EOF, returning ENOMSG as an error to consumers. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-06->get_request(): return failure if not connected (#411)John Levon1-0/+5
Previously, we'd end up doing a recvmsg(-1, ...), which would fail anyway, but it's best to be explicit. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-06use MSG_NOSIGNAL for sendmsg() (#410)John Levon1-1/+1
Get EPIPE instead instead of a signal. This isn't fixing any particular bug, but generally, we don't want unexpected signals. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-31tran_sock_recv_fds(): fix handling of get_msg() failures (#412)John Levon1-2/+2
get_msg() returns -errno not -1. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-31make some tran_sock functions static (#409)John Levon1-2/+5
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-25re-work unit test mocking (#400)John Levon1-6/+4
Instead of trying to use the linker's --wrap, which just led to more problems when we want to call the real function, we'll add two defines, MOCK_DEFINE() and MOCK_DECLARE(), that behave differently when building the unit tests, such that all wrapped functions are picked up from test/mocks.c instead, regardless of compilation unit. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-24check for double attach (#403)John Levon1-0/+7
As seen in https://github.com/spdk/spdk/issues/1854, we should explicitly check for attaching an already-attached context, instead of silently over-writing the existing socket fd. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-03-23globally define _GNU_SOURCE (#401)John Levon1-1/+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 Levon1-3/+3
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-22fix vfu_ctx_create() error path (#393)John Levon1-4/+2
The ->detach() and ->fini() transport handlers can't presume ->tran_data is set, since we cleanup a failed vfu_create_ctx() with vfu_destroy_ctx(). Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@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 sizeof() consistently (#351)John Levon1-16/+16
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-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 Levon1-72/+85
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 Levon1-30/+101
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-11move exec_command socket handling into the transport (#320)John Levon1-2/+36
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-11introduce transport reply() handler (#313)John Levon1-0/+13
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-02-09introduce transport send_msg() handler (#314)John Levon1-0/+12
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 Levon1-65/+67
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-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 Levon1-7/+20
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-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-25don't assume specific message ID when negotiating (#248)Thanos Makatos1-3/+5
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-25don't use uninitialized memory (#244)Thanos Makatos1-2/+6
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-15send file descriptors for sparse areas in get region info (#201)Thanos Makatos1-47/+82
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-07don't return invalid errnoThanos Makatos1-1/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-07Remove sock_flags from struct vfu_ctx (#163)swapnili1-5/+5
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2020-12-02use log level defines from syslogThanos Makatos1-11/+11
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-01Check for truncated response in get_request_sock() (#142)swapnili1-0/+4
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2020-12-01don't leak passed file descriptors on failureThanos Makatos1-1/+1
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-11-27rename to libvfio-user (#128)John Levon1-93/+93
The muser name no longer reflects the implementation, and will just serve to confuse. Bite the bullet now, and rename ourselves to reflect the actual implementation. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2020-11-24get_request_sock: set nr_fds always (#116)John Levon1-0/+2
2020-11-24refactor sock send/recv functions (#114)John Levon1-33/+47
Use shorter, more readable, function names, add re-jig the wrappers such that the most common operations are shortest.