summaryrefslogtreecommitdiff
path: root/contrib/libvhost-user/libvhost-user.c
AgeCommit message (Collapse)AuthorFilesLines
2018-03-20libvhost-user: Claim support for postcopyDr. David Alan Gilbert1-0/+33
Tell QEMU we understand the protocol features needed for postcopy. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20vhost-user: Add VHOST_USER_POSTCOPY_END messageDr. David Alan Gilbert1-0/+23
This message is sent just before the end of postcopy to get the client to stop using userfault since we wont respond to any more requests. It should close userfaultfd so that any other pages get mapped to the backing file automatically by the kernel, since at this point we know we've received everything. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20libvhost-user: mprotect & madvises for postcopyDr. David Alan Gilbert1-5/+42
Clear the area and turn off THP. PROT_NONE the area until after we've userfault advised it to catch any unexpected changes. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20vhost+postcopy: Send address back to qemuDr. David Alan Gilbert1-1/+23
We need a better way, but at the moment we need the address of the mappings sent back to qemu so it can interpret the messages on the userfaultfd it reads. This is done as a 3 stage set: QEMU -> client set_mem_table mmap stuff, get addresses client -> qemu here are the addresses qemu -> client OK - now you can use them That ensures that qemu has registered the new addresses in it's userfault code before the client starts accessing them. Note: We don't ask for the default 'ack' reply since we've got our own. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20libvhost-user+postcopy: Register new regions with the ufdDr. David Alan Gilbert1-0/+34
When new regions are sent to the client using SET_MEM_TABLE, register them with the userfaultfd. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20postcopy+vhost-user: Split set_mem_table for postcopyDr. David Alan Gilbert1-0/+53
Split the set_mem_table routines in both qemu and libvhost-user because the postcopy versions are going to be quite different once changes in the later patches are added. However, this patch doesn't produce any functional change, just the split. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20vhost+postcopy: Transmit 'listen' to slaveDr. David Alan Gilbert1-0/+19
Notify the vhost-user slave on reception of the 'postcopy-listen' event from the source. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20libvhost-user: Open userfaultfdDr. David Alan Gilbert1-2/+40
Open a userfaultfd (on a postcopy_advise) and send it back in the reply to the qemu for it to monitor. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20libvhost-user: Support sending fds back to qemuDr. David Alan Gilbert1-1/+29
Allow replies with fds (for postcopy) Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-03-20vhost-user: Add 'VHOST_USER_POSTCOPY_ADVISE' messageDr. David Alan Gilbert1-0/+11
Wire up a notifier to send a VHOST_USER_POSTCOPY_ADVISE message on an incoming advise. Later patches will fill in the behaviour/contents of the message. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2018-02-13libvhost-user: Support across-memory-boundary accessYongji Xie1-13/+120
The sg list/indirect descriptor table may be contigious in GPA but not in HVA address space. But libvhost-user wasn't aware of that. This would cause out-of-bounds access. Even a malicious guest could use it to get information from the vhost-user backend. Introduce a plen parameter in vu_gpa_to_va() so we can handle this case, returning the actual mapped length. Signed-off-by: Yongji Xie <xieyongji@baidu.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2018-02-13libvhost-user: Fix resource leakYongji Xie1-0/+14
Free the mmaped memory when we need to mmap new memory space on vu_set_mem_table_exec() and vu_set_log_base_exec() to avoid memory leak. Also close the corresponding fd after mmap() on vu_set_log_base_exec() to avoid fd leak. Signed-off-by: Yongji Xie <xieyongji@baidu.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-01-18contrib/libvhost-user: enable virtio config space messagesChangpeng Liu1-0/+42
Enable VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages in libvhost-user library, users can implement their own I/O target based on the library. This enable the virtio config space delivered between QEMU host device and the I/O target. Signed-off-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-10-12libvhost-user: Support VHOST_USER_SET_SLAVE_REQ_FDDr. David Alan Gilbert1-1/+26
Allow the qemu to pass us a slave fd. We don't do anything with it yet. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20171002191521.15748-5-dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2017-10-12libvhost-user: Update and fix feature and request listsDr. David Alan Gilbert1-5/+5
Update the ProtocolFeature and UserRequest lists to match hw/virtio/vhost-user.c. Fix the text labelling in libvhost-user.c to match the list. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20171002191521.15748-4-dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2017-10-12libvhost-user: vu_queue_startedDr. David Alan Gilbert1-0/+6
Add a vu_queue_started method to complement vu_queue_enabled. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20171002191521.15748-2-dgilbert@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
2017-10-10libvhost-user: drop dependency on glibMarc-André Lureau1-3/+26
libvhost-user is meant to be free of glib dependency. Make sure it is by droping qemu/osdep.h (which included glib.h) This fixes a bad malloc()/g_free() pair. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2017-09-08libvhost-user: support resuming vq->last_avail_idx based on used_idxMarc-André Lureau1-0/+13
This is the same workaround as commit 523b018dde3b765, which was lost with libvhost-user transition in commit e10e798c85c2331. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-08-09libvhost-user: quit when no more data receivedJens Freimann1-1/+3
End processing of messages when VHOST_USER_NONE is received. Without this we run into a vubr_panic() call and get "PANIC: Unhandled request: 0" Signed-off-by: Jens Freimann <jfreiman@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-05-10libvhost-user: fix crash when rings aren't readyMarc-André Lureau1-6/+20
Calling libvhost-user functions like vu_queue_get_avail_bytes() when the queue doesn't yet have addresses will result in the crashes like the following: Program received signal SIGSEGV, Segmentation fault. 0x000055c414112ce4 in vring_avail_idx (vq=0x55c41582fd68, vq=0x55c41582fd68) at /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:940 940 vq->shadow_avail_idx = vq->vring.avail->idx; (gdb) p vq $1 = (VuVirtq *) 0x55c41582fd68 (gdb) p vq->vring $2 = {num = 0, desc = 0x0, avail = 0x0, used = 0x0, log_guest_addr = 0, flags = 0} at /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:940 No locals. at /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:960 num_heads = <optimized out> out_bytes=out_bytes@entry=0x7fffd035d7c4, max_in_bytes=max_in_bytes@entry=0, max_out_bytes=max_out_bytes@entry=0) at /home/dgilbert/git/qemu/contrib/libvhost-user/libvhost-user.c:1034 Add a pre-condition checks on vring.avail before accessing it. Fix documentation and return type of vu_queue_empty() while at it. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Tested-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-05-05libvhost-user: replace vasprintf() to fix buildFelipe Franciosi1-1/+1
On gcc 3.4 and newer, simply using (void) in front of WUR functions is not sufficient to ignore the return value. That prevents a build when handling warnings as errors. libvhost-user had a usage of (void)vasprintf() which triggered such a condition. This fixes it by replacing this call with g_strdup_vprintf() which aborts on OOM. Signed-off-by: Felipe Franciosi <felipe@nutanix.com> Message-Id: <1488479153-21203-2-git-send-email-felipe@nutanix.com> Reviewed-by: Eric Blake <eblake@redhat.com>
2016-12-16contrib: add libvhost-userMarc-André Lureau1-0/+1499
Add a library to help implementing vhost-user backend (or slave). Dealing with vhost-user as an application developer isn't so easy: you have all the trouble with any protocol: validation, unix ancillary data, shared memory, eventfd, logging, and on top of that you need to deal with virtio queues, if possible efficiently. qemu test has a nice vhost-user testing application vhost-user-bridge, which implements most of vhost-user, and virtio.c which implements virtqueues manipulation. Based on these two, I tried to make a simple library, reusable for tests or development of new vhost-user scenarios. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> [Felipe: set used_idx copy on SET_VRING_ADDR and update shadow avail idx on SET_VRING_BASE] Signed-off-by: Felipe Franciosi <felipe@nutanix.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>