hvsock: introduce Hyper-V VM Sockets feature
Subsystems (4)
Dexuan Cui
maintainerPATCH 6/7 hvsock: introduce Hyper-V VM Sockets feature
Hyper-V VM sockets (hvsock) supplies a byte-stream based communication mechanism between the host and a guest. It's kind of TCP over VMBus, but the transportation layer (VMBus) is much simpler than IP. With Hyper-V VM Sockets, applications between the host and a guest can talk with each other directly by the traditional BSD-style socket APIs.
Hyper-V VM Sockets is only available on Windows 10 host and later. The patch implements the necessary support in the guest side by introducing a new socket address family AF_HYPERV.
--- MAINTAINERS | 2 + include/linux/socket.h | 4 +- include/net/af_hvsock.h | 44 ++ include/uapi/linux/hyperv.h | 16 + net/Kconfig | 1 + net/Makefile | 1 + net/hv_sock/Kconfig | 10 + net/hv_sock/Makefile | 5 + net/hv_sock/af_hvsock.c | 1463 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 1545 insertions(+), 1 deletion(-) create mode 100644 include/net/af_hvsock.h create mode 100644 net/hv_sock/Kconfig create mode 100644 net/hv_sock/Makefile create mode 100644 net/hv_sock/af_hvsock.c
MAINTAINERS +2 -0
@@ -4941,7 +4941,9 @@ F: drivers/input/serio/hyperv-keyboard.c F: drivers/net/hyperv/ F: drivers/scsi/storvsc_drv.c F: drivers/video/fbdev/hyperv_fb.c +F: net/hv_sock/ F: include/linux/hyperv.h +F: include/net/af_hvsock.h F: tools/hv/ I2C OVER PARALLEL PORT
include/linux/socket.h +3 -1
@@ -200,7 +200,8 @@ struct ucred {#define AF_ALG 38/* Algorithm sockets */ #define AF_NFC 39/* NFC sockets */ #define AF_VSOCK 40/* vSockets */ -#define AF_MAX 41/* For now.. */ +#define AF_HYPERV 41/* Hyper-V virtual sockets */ +#define AF_MAX 42/* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC
@@ -246,6 +247,7 @@ struct ucred {#define PF_ALG AF_ALG#define PF_NFC AF_NFC#define PF_VSOCK AF_VSOCK +#define PF_HYPERV AF_HYPERV#define PF_MAX AF_MAX/* Maximum queue length specifiable by listen. */
include/net/af_hvsock.h new file +44 -0
44 lines not on this page · raw message
include/uapi/linux/hyperv.h +16 -0
@@ -26,6 +26,7 @@#define _UAPI_HYPERV_H#include <linux/uuid.h> +#include <linux/socket.h> /* * Framework version for util services.
@@ -395,4 +396,19 @@ struct hv_kvp_ip_msg {struct hv_kvp_ipaddr_value kvp_ip_val; } __attribute__((packed)); +/* This is the Hyper-V socket's address format. */ +struct sockaddr_hv { +__kernel_sa_family_t shv_family;/* Address family */ +__le16 reserved;/* Must be zero */ +uuid_le shv_vm_id;/* Not used by Linux. Must be Zero. */ +uuid_le shv_service_id;/* Service ID */ +}; + +#define SHV_VMID_GUEST NULL_UUID_LE +#define SHV_VMID_HOST NULL_UUID_LE + +#define SHV_SERVICE_ID_ANY NULL_UUID_LE + +#define SHV_PROTO_RAW 1 +#endif /* _UAPI_HYPERV_H */
net/Kconfig +1 -0
@@ -228,6 +228,7 @@ source "net/dns_resolver/Kconfig" source "net/batman-adv/Kconfig" source "net/openvswitch/Kconfig" source "net/vmw_vsock/Kconfig" +source "net/hv_sock/Kconfig" source "net/netlink/Kconfig" source "net/mpls/Kconfig" source "net/hsr/Kconfig"
net/Makefile +1 -0
@@ -69,6 +69,7 @@ obj-$(CONFIG_BATMAN_ADV) += batman-adv/ obj-$(CONFIG_NFC) += nfc/ obj-$(CONFIG_OPENVSWITCH) += openvswitch/ obj-$(CONFIG_VSOCKETS) += vmw_vsock/ +obj-$(CONFIG_HYPERV_SOCK) += hv_sock/ obj-$(CONFIG_MPLS) += mpls/ obj-$(CONFIG_HSR) += hsr/ ifneq ($(CONFIG_NET_SWITCHDEV),)
net/hv_sock/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config HYPERV_SOCK + tristate "Microsoft Hyper-V Socket (EXPERIMENTAL)" + depends on HYPERV + default m + help + Hyper-V Socket is a socket protocol similar to TCP, allowing + communication between a Linux guest and the host. + + To compile this driver as a module, choose M here: the module + will be called hv_sock. If unsure, say N.
net/hv_sock/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +obj-$(CONFIG_HYPERV_SOCK) += hv_sock.o + +hv_sock-y += af_hvsock.o + +ccflags-y += -Wall -Werror
net/hv_sock/af_hvsock.c new file +1463 -0
1,463 lines not on this page · raw message
Signature · 1 line
2.1.0
Just two nits.
net/hv_sock/Kconfig line 10
Quoted 13 lines · Dexuan Cui
net/hv_sock/Kconfig new file +10
-0+config HYPERV_SOCK + tristate "Microsoft Hyper-V Socket (EXPERIMENTAL)" + depends on HYPERV + default m + help + Hyper-V Socket is a socket protocol similar to TCP, allowing + communication between a Linux guest and the host. + + To compile this driver as a module, choose M here: the module + will be called hv_sock. If unsure, say N.
It's a bit odd to advise to say N if one is unsure and set the default to 'm' at the same time.
Quoted 5 lines
net/hv_sock/af_hvsock.c new file +2
-0+static int hvsock_init (void ) +{
net/hv_sock/af_hvsock.c line 1459
Quoted 10 lines
net/hv_sock/af_hvsock.c new file +10
-0+ [...] +} + +static void hvsock_exit (void ) +{ + [...] +} + +module_init (hvsock_init); +module_exit (hvsock_exit);
Any specific reason not to mark these functions __init and __exit?
Thanks,
Paul Bolle
Dexuan Cui
maintainerQuoted 12 lines
-----Original Message-----
From: Paul Bolle
Sent: Tuesday, July 7, 2015 17:38
To: Dexuan Cui
Subject: Re: [PATCH 6/7] hvsock: introduce Hyper-V VM Sockets featureJust two nits.
Quoted 2 lines · Dexuan Cui
net/hv_sock/Kconfig new file +0
-0
Quoted 13 lines
net/hv_sock/Kconfig line 10
Quoted 10 lines
net/hv_sock/Kconfig new file +10
-0+config HYPERV_SOCK + tristate "Microsoft Hyper-V Socket (EXPERIMENTAL)" + depends on HYPERV + default m + help + Hyper-V Socket is a socket protocol similar to TCP, allowing + communication between a Linux guest and the host. + + To compile this driver as a module, choose M here: the module + will be called hv_sock. If unsure, say N.It's a bit odd to advise to say N if one is unsure and set the default to 'm' at the same time.
Hi Paul,
Thanks for the suggestion!
I'll change the 'default' to n in V2.
Quoted 18 lines
Quoted 5 lines
net/hv_sock/af_hvsock.c new file +2
-0+static int hvsock_init (void ) +{net/hv_sock/af_hvsock.c line 1459
Quoted 10 lines
net/hv_sock/af_hvsock.c new file +10
-0+ [...] +} + +static void hvsock_exit (void ) +{ + [...] +} + +module_init (hvsock_init); +module_exit (hvsock_exit);Any specific reason not to mark these functions
__initand__exit?
Quoted 1 line
Paul Bolle
Thanks for pointing this out -- I missed that.
I'll add __init and __exit in V2.
Thanks,
-- Dexuan
Quoted 11 lines · Paul Bolle
net/hv_sock/Kconfig line 4
Quoted 7 lines · Dexuan Cui
net/hv_sock/Kconfig new file +4
-0+config HYPERV_SOCK + tristate "Microsoft Hyper-V Socket (EXPERIMENTAL)" + depends on HYPERV + default mIt's a bit odd to advise to say N if one is unsure and set the default to 'm' at the same time.
The 'default' line has to be removed IMO.
Olaf
Dexuan Cui
maintainerQuoted 24 lines
-----Original Message-----
From: Olaf Hering [mailto:[email protected]]
Sent: Tuesday, July 7, 2015 18:10
To: Dexuan Cui; Paul Bolle
Cc: [email protected]; [email protected]; [email protected]; [email protected]; driverdev- [email protected]; [email protected]; [email protected]; KY Srinivasan; Haiyang Zhang
Subject: Re: [PATCH 6/7] hvsock: introduce Hyper-V VM Sockets featureQuoted 11 lines · Paul Bolle
net/hv_sock/Kconfig line 4
Quoted 7 lines · Dexuan Cui
net/hv_sock/Kconfig new file +4
-0+config HYPERV_SOCK + tristate "Microsoft Hyper-V Socket (EXPERIMENTAL)" + depends on HYPERV + default mIt's a bit odd to advise to say N if one is unsure and set the default to 'm' at the same time.
Quoted 3 lines
The 'default' line has to be removed IMO.
Olaf
OK, removing the line seems better than 'default n', though both reproduce the same "# CONFIG_HYPERV_SOCK is not set".
-- Dexuan
Quoted 2 lines · Dexuan Cui
OK, removing the line seems better than 'default n', though both reproduce the same "#
CONFIG_HYPERV_SOCKis not set".
Perhaps "default VMBUS" (or whatever syntax is needed) may be the way to enable it conditionally.
Olaf
Quoted 2 lines · Dexuan Cui
OK, removing the line seems better than 'default n', though both reproduce the same "#
CONFIG_HYPERV_SOCKis not set".
Speaking from memory (so chances are I'm forgetting some silly detail) that is because
# CONFIG_FOO is not set
will be printed if FOO's dependencies are met and FOO either has a "prompt" or a default of 'n'.
Hope this helps,
Paul Bolle
Quoted 11 lines · On Mon, 6 Jul 2015 07:47:29 -0700 Dexuan Cui <[email protected]> wrote:
Hyper-V VM sockets (hvsock) supplies a byte-stream based communication mechanism between the host and a guest. It's kind of TCP over VMBus, but the transportation layer (VMBus) is much simpler than IP. With Hyper-V VM Sockets, applications between the host and a guest can talk with each other directly by the traditional BSD-style socket APIs.
Hyper-V VM Sockets is only available on Windows 10 host and later. The patch implements the necessary support in the guest side by introducing a new socket address family
AF_HYPERV.Signed-off-by Dexuan Cui <[email protected]>
Is there any chance that AF_VSOCK could be used with different transport for VMware and Hyper-V. Better to make guest applications host independent.
Dexuan Cui
maintainerQuoted 14 lines
-----Original Message-----
From: Stephen Hemminger
Sent: Wednesday, July 8, 2015 2:31
Subject: Re: [PATCH 6/7] hvsock: introduce Hyper-V VM Sockets featureQuoted 6 lines · On Mon, 6 Jul 2015 07:47:29 -0700 Dexuan Cui <[email protected]> wrote:
Hyper-V VM sockets (hvsock) supplies a byte-stream based communication mechanism between the host and a guest. It's kind of TCP over VMBus, but the transportation layer (VMBus) is much simpler than IP. With Hyper-V VM Sockets, applications between the host and a guest can talk with each other directly by the traditional BSD-style socket APIs.
Quoted 8 lines
Quoted 5 lines
Hyper-V VM Sockets is only available on Windows 10 host and later. The patch implements the necessary support in the guest side by introducing a new socket address family
AF_HYPERV.Signed-off-by Dexuan Cui <[email protected]>Is there any chance that
AF_VSOCKcould be used with different transport for VMware and Hyper-V. Better to make guest applications host independent.
Hi Stephen,
Thanks for the question. I tried to do that (since AF_HYPERV and AF_VSOCK are conceptually similar), but I found it would be impractical: I listed the reasons in my cover letter of the patchset:
https://lkml.org/lkml/2015/7/6/431
IMO the biggest difference is the size of the endpoint (u128 vs. u32):
<u32 ContextID, u32 Port> in AF_VOSCK
vs.
<u128 GUID_VM_ID, u128 GUID_ServiceID> in AF_HYPERV.
In the current code of AF_VSOCK and the related transport layer (the wrapper ops of VMware's VMCI), the size is widely used by "struct sockaddr_vm" (this struct is also exported to the user space).
So, anyway, the user space application has to explicitly handle the different endpoint size.
And in the driver side, I'm afraid there is no way to directly reuse the code of AF_VSOCK with trivial change :-( , because we would have to make the AF_VSOCK code be able to know the real sockaddr type (sockaddr_vm or sockaddr_hv? The two structs have different layout and different field names) at runtime and behave differently. This would make the code a mess, IMO.
That's why I think it would be better to introduce a new address family.
Thanks,
-- Dexuan
Dexuan Cui
maintainerQuoted 7 lines
-----Original Message-----
From: Olaf Hering
Sent: Tuesday, July 7, 2015 18:59
Subject: Re: [PATCH 6/7] hvsock: introduce Hyper-V VM Sockets featureOn Tue, Jul 07, Dexuan Cui wrote:
Quoted 7 lines
Quoted 2 lines
OK, removing the line seems better than 'default n', though both reproduce the same "#
CONFIG_HYPERV_SOCKis not set".Perhaps "default VMBUS" (or whatever syntax is needed) may be the way to enable it conditionally.
Olaf
Thanks, Olaf!
I think we can use "default m if HYPERV".
Paul, I'll remove the sentence "If unsure, say N."
Thanks,
-- Dexuan