hvsock: introduce Hyper-V Socket feature
Subsystems (4)
Dexuan Cui
maintainerPATCH v6 8/8 hvsock: introduce Hyper-V Socket feature
Hyper-V socket (hvsock) supplies a byte-stream based communication mechanism between the host and a guest. It's kind of like TCP over VMBus, but the transportation layer (VMBus) is much simpler than IP. With Hyper-V Socket, applications between the host and a guest can talk to each other directly by the traditional BSD-style socket APIs.
Hyper-V Socket is only available on new Windows hosts. The patch implements the necessary support in the guest side by introducing a new socket address family AF_HYPERV.
--- MAINTAINERS | 2 + include/linux/hyperv.h | 16 + include/linux/socket.h | 4 +- include/net/af_hvsock.h | 51 ++ include/uapi/linux/hyperv.h | 16 + net/Kconfig | 1 + net/Makefile | 1 + net/hv_sock/Kconfig | 10 + net/hv_sock/Makefile | 3 + net/hv_sock/af_hvsock.c | 1480 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 1583 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
@@ -5200,7 +5200,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/ F: Documentation/ABI/stable/sysfs-bus-vmbus
include/linux/hyperv.h +16 -0
@@ -1293,4 +1293,20 @@ extern __u32 vmbus_proto_version;int vmbus_send_tl_connect_request (const uuid_le *shv_guest_servie_id,const uuid_le *shv_host_servie_id); +struct vmpipe_proto_header { +u32 pkt_type; +u32 data_size; +} __packed; + +#define HVSOCK_HEADER_LEN (sizeof(struct vmpacket_descriptor) + \ + sizeof(struct vmpipe_proto_header)) + +/* See 'prev_indices' in hv_ringbuffer_read(), hv_ringbuffer_write() */ +#define PREV_INDICES_LEN (sizeof(u64)) + +#define HVSOCK_PKT_LEN (payload_len) (HVSOCK_HEADER_LEN + \ + ALIGN((payload_len), 8) + \ + PREV_INDICES_LEN) +#define HVSOCK_MIN_PKT_LEN HVSOCK_PKT_LEN(1) +#endif /* _HYPERV_H */
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 +51 -0
51 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.
@@ -396,4 +397,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. 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
@@ -231,6 +231,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 if HYPERV + 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.
net/hv_sock/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_HYPERV_SOCK) += hv_sock.o + +hv_sock-y += af_hvsock.o
net/hv_sock/af_hvsock.c new file +1480 -0
1,480 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 1 line · Dexuan Cui
+#define
AF_MAX42 /* For now.. */
Maybe net/core/sock.c needs additional strings for the new socket?
Olaf
Dexuan Cui
maintainerQuoted 11 lines
From: Olaf Hering [mailto:[email protected]]
Sent: Tuesday, January 26, 2016 18:24
To: Dexuan Cui <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V6 8/8] hvsock: introduce Hyper-V Socket feature
Quoted 7 lines
Quoted 1 line · Dexuan Cui
+#define
AF_MAX42 /* For now.. */Maybe
net/core/sock.cneeds additional strings for the new socket?Olaf
Olaf, Thanks for the reminder!
I'll add a new patch like this:
net/core/sock.c +6 -3
@@ -221,7 +221,8 @@ static const char *const af_family_key_strings[AF_MAX+1] = {"sk_lock-AF_TIPC" ,"sk_lock-AF_BLUETOOTH" ,"sk_lock-IUCV" ,"sk_lock-AF_RXRPC" ,"sk_lock-AF_ISDN" ,"sk_lock-AF_PHONET" ,"sk_lock-AF_IEEE802154" ,"sk_lock-AF_CAIF" ,"sk_lock-AF_ALG" , -"sk_lock-AF_NFC" ,"sk_lock-AF_VSOCK" ,"sk_lock-AF_MAX" +"sk_lock-AF_NFC" ,"sk_lock-AF_VSOCK" ,"sk_lock-AF_HYPERV" +"sk_lock-AF_MAX" };static const char *const af_family_slock_key_strings[AF_MAX +1 ] = { "slock-AF_UNSPEC", "slock-AF_UNIX" , "slock-AF_INET" ,
@@ -237,7 +238,8 @@ static const char *const af_family_slock_key_strings[AF_MAX+1] = {"slock-AF_TIPC" ,"slock-AF_BLUETOOTH" ,"slock-AF_IUCV" ,"slock-AF_RXRPC" ,"slock-AF_ISDN" ,"slock-AF_PHONET" ,"slock-AF_IEEE802154" ,"slock-AF_CAIF" ,"slock-AF_ALG" , -"slock-AF_NFC" ,"slock-AF_VSOCK" ,"slock-AF_MAX" +"slock-AF_NFC" ,"slock-AF_VSOCK" ,"slock-AF_HYPERV" +"slock-AF_MAX" };static const char *const af_family_clock_key_strings[AF_MAX +1 ] = { "clock-AF_UNSPEC", "clock-AF_UNIX" , "clock-AF_INET" ,
@@ -253,7 +255,8 @@ static const char *const af_family_clock_key_strings[AF_MAX+1] = {"clock-AF_TIPC" ,"clock-AF_BLUETOOTH" ,"clock-AF_IUCV" ,"clock-AF_RXRPC" ,"clock-AF_ISDN" ,"clock-AF_PHONET" ,"clock-AF_IEEE802154" ,"clock-AF_CAIF" ,"clock-AF_ALG" , -"clock-AF_NFC" ,"clock-AF_VSOCK" ,"clock-AF_MAX" +"clock-AF_NFC" ,"clock-AF_VSOCK" ,"clock-AF_HYPERV" +"clock-AF_MAX" };/*
Thanks,
-- Dexuan