Features/VirtioVsock: Difference between revisions

From QEMU
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 27: Line 27:
==Language bindings==
==Language bindings==
* C - use <linux/vm_sockets.h>
* C - use <linux/vm_sockets.h>
* Python - coming in Python 3.7 (already merged upstream)
* Python - starting from Python 3.7
* Go - [https://github.com/mdlayher/vsock Matt Layher's vsock module]
* Go - [https://github.com/mdlayher/vsock Matt Layher's vsock module]
* Rust
** [https://docs.rs/crate/libc libc crate] (libc::sockaddr_vm, libc::VMADDR_*)
** [https://docs.rs/crate/nix nix crate] (nix::sys::socket::VsockAddr)


==Projects using vsock==
==Projects using vsock==
Line 34: Line 37:
* [https://www.xpra.org/trac/wiki/Network xpra] - X11 persistent remote display server and client
* [https://www.xpra.org/trac/wiki/Network xpra] - X11 persistent remote display server and client
* [https://github.com/clownix/cloonix_vsock cloonix_vsock] - PTY over AF_VSOCK
* [https://github.com/clownix/cloonix_vsock cloonix_vsock] - PTY over AF_VSOCK
 
* [https://github.com/stefano-garzarella/iperf-vsock iperf-vsock] - iperf3 with AF_VSOCK support
==Testing==
* [http://www.dest-unreach.org/socat/ socat] - VSOCK-CONNECT and VSOCK-LISTEN addresses supported from socat 1.7.4 [2021-01-04]
The vhost-vsock-test qtest replays packets from a JSON file and verifies that the expected reply is received.
 
The JSON test file format is described in a [https://github.com/stefanha/qemu/blob/vsock/tests/vhost-vsock-test-data/README README].
 
  $ cd qemu
  $ make -j4
  $ make tests/vhost-vsock-test
  $ sudo QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 QTEST_QEMU_IMG=qemu-img MALLOC_PERTURB_=${MALLOC_PERTURB_:-$((RANDOM % 255 + 1))} gtester -k --verbose -m=quick tests/vhost-vsock-test -o /dev/stderr
 
Create and edit test cases in tests/vhost-vsock-test-data/*.json.


==Links==
==Links==
* KVM Forum 2015 presentation: [http://vmsplice.net/~stefan/stefanha-kvm-forum-2015.pdf virtio-vsock: Zero-configuration host/guest communication] (pdf)
* KVM Forum 2015 presentation: [http://vmsplice.net/~stefan/stefanha-kvm-forum-2015.pdf virtio-vsock: Zero-configuration host/guest communication] (pdf)
* Connectathon 2016 presentation: [http://vmsplice.net/~stefan/stefanha-connectathon-2016.pdf NFS over virtio-vsock: Host/guest file sharing for virtual machines] (pdf)
* Connectathon 2016 presentation: [http://vmsplice.net/~stefan/stefanha-connectathon-2016.pdf NFS over virtio-vsock: Host/guest file sharing for virtual machines] (pdf)

Latest revision as of 15:59, 11 January 2021

virtio-vsock is a host/guest communications device. It allows applications in the guest and host to communicate. This can be used to implement hypervisor services and guest agents (like qemu-guest-agent or SPICE vdagent).

  • POSIX Sockets API so existing networking applications require minimal modification (unlike virtio-serial char devices)
  • Listen sockets can accept connections from multiple clients (unlike virtio-serial char devices)
  • No address configuration required inside the guest
  • No Ethernet or TCP/IP for a reduced attack surface for hypervisor services
  • Can be used with VMs that have no network interfaces

Sockets are created with the AF_VSOCK address family. The SOCK_STREAM socket type is currently implemented for in-order, guaranteed stream semantics.

Code

Packages

Quickstart

  • Host kernel requirements: CONFIG_VHOST_VSOCK=m
  • Guest kernel requirements: CONFIG_VIRTIO_VSOCKETS=m

Launch a guest and assign it CID 3:

 (host)# qemu-system-x86_64 -device vhost-vsock-pci,guest-cid=3 ...

Language bindings

Projects using vsock

  • nc-vsock - a netcat-like utility for AF_VSOCK
  • xpra - X11 persistent remote display server and client
  • cloonix_vsock - PTY over AF_VSOCK
  • iperf-vsock - iperf3 with AF_VSOCK support
  • socat - VSOCK-CONNECT and VSOCK-LISTEN addresses supported from socat 1.7.4 [2021-01-04]

Links