Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AF_VSOCK support #983

Closed
totaam opened this issue Sep 17, 2015 · 15 comments
Closed

AF_VSOCK support #983

totaam opened this issue Sep 17, 2015 · 15 comments

Comments

@totaam
Copy link
Collaborator

totaam commented Sep 17, 2015

When using the ProxyServer, or just when connecting to/from a virtual machine in general, it would be very nice to support VSOCK.
One could also envisage running virtual machines without any networking whatsoever (or even the host, and let the VM have the NIC instead), only the VSOCK would be used for display forwarding.

Links:

Usage:

qemu ... -device vhost-vsock-pci,id=vhost-vsock-pci0
.svm_family = AF_VSOCK,
.svm_cid = VMADDR_CID_HOST,
.svm_port = 1234,

Not sure about the kernel + python support.

/usr/include/bits/socket.h:#define PF_VSOCK	40	/* vSockets.  */
/usr/include/bits/socket.h:#define AF_VSOCK	PF_VSOCK

This may require cythonizing:

>>> s=socket.socket(40)
>>> s.bind((1234, ))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: getsockaddrarg: bad family
>>> 
@totaam
Copy link
Collaborator Author

totaam commented Apr 2, 2016

Links:

@totaam
Copy link
Collaborator Author

totaam commented Apr 2, 2016

2016-04-02 17:48:08: antoine uploaded file vsock.patch (8.1 KiB)

patch attempting to force AF_VSOCK into the python socket class

@totaam
Copy link
Collaborator Author

totaam commented Apr 3, 2016

The vsock bits have been reverted in December 2015: VSOCK: revert virtio-vsock until device spec is finalized, which makes it very hard to test. And it's not immediately obvious because you get this unhelpful error:

qemu-system-x86_64: -device vhost-vsock-pci,id=vh0,addr=4.0,guest-cid=4: vhost-vsock: failed to open vhost device: Unknown error -2

You then have to figure out with strace that the device does not exist..

To fix this, you either have to download the kernel tree they are using (see [http://qemu-project.org/Features/VirtioVsock]), or a newer kernel source and apply RFC,v5,4/5 VSOCK: Introduce vhost_vsock.ko. (for example the Fedora rawhide kernels - the patch applies cleanly there still, bar the maintainers file which can be skipped anyway)

@totaam
Copy link
Collaborator Author

totaam commented Apr 4, 2016

2016-04-04 06:06:54: antoine uploaded file vsock-v3.patch (17.3 KiB)

updated patch

@totaam
Copy link
Collaborator Author

totaam commented Apr 4, 2016

Once I figured out that you MUST use the kernel and qemu versions from [http://qemu-project.org/Features/VirtioVsock] (other combinations may or may not work - this one definitely does, the patched kernel is needed at both ends too), it wasn't too difficult: done in r12309.
It is very fast. The latency goes from ~12ms to 0. Packets come in 256KB chunks at about 1.1GB/s with fairly low CPU usage.


Usage:

  • on the host, load the vsock module and make it accessible by non-privileged users (better than running qemu as root... will do for now):
modprobe vhost_vsock
chmod 666 /dev/vhost-vsock
  • start a session with a vsock bind (here using a specific port, "auto" will assign one):
xpra start :100 --start-child="xterm" --bind-vsock=auto:2000
  • start a guest in qemu, use the vhost-vsock option vhost-vsock-pci,id=vhost-vsock-pci0,addr=M.0,guest-cid=N, ie:
/usr/local/bin/qemu-system-x86_64 --enable-kvm -m 2048 -name Fedora-24 \
    -drive file=./Fedora-24-x86_64.raw,if=virtio,index=0,format=raw \
    -device vhost-vsock-pci,id=vhost-vsock-pci0,addr=4.0,guest-cid=4
  • in the guest, connect to the vsock using:
modprobe vsock
xpra attach vsock:host:2000

Note: I thought the connections using vsock were from guest to host only, but that is not the case: Re: AF_VSOCK status (will need re-testing).


@smo: let's discuss.

Debugging:

  • -d network
  • test scripts from r12310
  • netcat-vsock: [https://github.com/stefanha/linux/blob/vsock-extras/nc-vsock.c]

@totaam
Copy link
Collaborator Author

totaam commented Apr 8, 2016

See also #1159 comment:1 for the new vsock-auth= syntax.

@totaam
Copy link
Collaborator Author

totaam commented Apr 11, 2016

Conversely, you can run a server in the guest and connect to it using the assigned CID.
Re-using the same qemu command line as comment:4 (guest-cid=4).
The guest can start a server:

xpra start :100 --start-child="xterm" --bind-vsock=auto:10000

And we can connect to it from the host using:

xpra attach vhost:4:10000

@totaam
Copy link
Collaborator Author

totaam commented May 27, 2016

r12698 adds it to the man page.

@totaam
Copy link
Collaborator Author

totaam commented Oct 3, 2016

VSOCK is included in kernel 4.8, here was the pull request: vhost: new features for 4.8

@totaam
Copy link
Collaborator Author

totaam commented Nov 18, 2016

2016-11-18 00:41:29: smo commented


Just a quick update to this old ticket.

Looks like the kernel modules are there now with Fedora 24 which is what I run on my workstation.

After loading vhost_vsock module and trying to make use of it in qemu results in

'vhost-vsock-pci' is not a valid device model name

Does qemu perhaps have to be configured with an option to enable vsock support?

@totaam
Copy link
Collaborator Author

totaam commented Nov 18, 2016

2016-11-18 06:29:54: antoine uploaded file kvm-AF_VSOCK-status.email (0.8 KiB)

email sent to the AF_VSOCK maintainer and kvm ML

@totaam
Copy link
Collaborator Author

totaam commented Nov 18, 2016

Seems that even qemu 2.7 in Fedora 25 does not have vsock builtin.
I've pinged an email to the maintainer. (attached)

@totaam
Copy link
Collaborator Author

totaam commented Nov 19, 2016

2016-11-19 04:26:23: antoine commented


Got the answer from the 2.8 release notes [http://wiki.qemu.org/ChangeLog/2.8#virtio]: New device vhost-vsock.

You should be able to test with the 2.8 RC.

@totaam
Copy link
Collaborator Author

totaam commented Nov 21, 2016

Reply: Re: AF_VSOCK status in qemu upstream: you can use qemu.git/master .. I have also made a copr repository for Fedora available here with qemu-kvm, kernel, and other packages with virtio-vsock support : [https://copr.fedorainfracloud.org/coprs/stefanha/vsock/]

@totaam
Copy link
Collaborator Author

totaam commented Dec 26, 2016

This has been tested, see #1387 for a follow up - closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant