kvm-guest-drivers-windows icon indicating copy to clipboard operation
kvm-guest-drivers-windows copied to clipboard

Q: How to use AF_VSOCK in a Windows VM?

Open elmarco opened this issue 4 years ago • 5 comments

Not being very familiar with Windows in general, I thought I could simply add a virtio-vsock device, install the latest drivers (from https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso?) and follow https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/make-integration-service to connect to the host via VSOCK.

Alas, winsock2.h still doesn't define AF_VSOCK, and there seems to be a mix of concern in that documentation page. Then I looked at this repository and found viosocklib-test.c.

What are the steps to get socket(AF_VSOCK, SOCK_STREAM, 0) working from a Windows VM. Is there some virtio-win specific documentation available?

cc @irudakov77 thanks

elmarco avatar Jan 13 '21 12:01 elmarco

Hi @elmarco,

As far as I understand the driver installation is not installing (yet) the viosocklib.dll that registers Virtio Socket Provider. The viosocklib-test has a command-line option /i to install the protocol: https://github.com/virtio-win/kvm-guest-drivers-windows/blob/57eee37e5ccfee280d35de2998b30baa34d555cd/viosock/lib/install.c#L91

I think @irudakov77 can provide more info on the subject.

Best regards, Yan.

YanVugenfirer avatar Jan 13 '21 12:01 YanVugenfirer

Hi @elmarco,

  1. Unfortunately the latest virtio-win.iso still does not contain socket driver. Maybe because the driver is not fully tested and has no any performance optimizations yet. I would not recommend to release socket driver in its current state. Driver improvement work has been suspended until April. If you suddenly want to build and check the driver, any feedback would be appreciated and I'll try to fix bugs ASAP.

  2. The mentioned article about Hyper-V sockets, and AF_VSOCK is used by Linux guests to create such a socket and is not defined for Windows guests which use AF_HYPERV instead. Please include https://github.com/virtio-win/kvm-guest-drivers-windows/blob/master/viosock/inc/vio_sockets.h to use AF_VSOCK for virtio sockets on Windows.

  3. https://github.com/virtio-win/kvm-guest-drivers-windows/pull/491/commits/fb849eebe3c9ae4119c32fa163de1a9559b4cd43 introduced optional co-installer to register socket provider during driver installation. Co-installer is enabled for RHEL (default) vendor and there is no need to run viosocklib-test /i to install provider dll.

Best regards, Ilya

irudakov77 avatar Jan 13 '21 15:01 irudakov77

2\. The mentioned article about Hyper-V sockets, and AF_VSOCK is used by Linux guests to create such a socket and is not defined for Windows guests which use AF_HYPERV instead. Please include https://github.com/virtio-win/kvm-guest-drivers-windows/blob/master/viosock/inc/vio_sockets.h to use AF_VSOCK for virtio sockets on Windows.

The value of AF_VSOCK will never conflict with other Windows values? Iow, is the value registered with Microsoft, or are they following a numbering? It would be nice if they included it in their winsock2.h..

elmarco avatar Jan 13 '21 20:01 elmarco

The value of AF_VSOCK will never conflict with other Windows values? Iow, is the value registered with Microsoft, or are they following a numbering? It would be nice if they included it in their winsock2.h..

Of course it will, but not today or even tomorrow. I get this value from Linux and use it at the time of development because it is grater than the current AF_MAX. It can easily conflict with other third-party socket provider AFs. Conflict can be avoided by requesting AF value from the viosock driver, it was planned to implement at the very end of development, but I can do it now. I liked the idea to "register" AF_VSOCK with Microsoft, thanks. But this will not be quick and the result is not guaranteed.

Regards, Ilya

irudakov77 avatar Jan 18 '21 15:01 irudakov77