virtio-win / kvm-guest-drivers-windows

Windows paravirtualized drivers for QEMU\KVM
https://www.linux-kvm.org/page/WindowsGuestDrivers
BSD 3-Clause "New" or "Revised" License
2.04k stars 387 forks source link

Q: How to use AF_VSOCK in a Windows VM? #534

Open elmarco opened 3 years ago

elmarco commented 3 years ago

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

YanVugenfirer commented 3 years ago

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.

irudakov77 commented 3 years ago

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

elmarco commented 3 years ago
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..

irudakov77 commented 3 years ago

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

fw8899 commented 6 months ago

In the latest release virtio-win-0.1.248-1, there is still no viosock driver. Any plan in 2024? @YanVugenfirer @irudakov77