hv_sock: introduce Hyper-V Sockets
Subsystems (4)
Dexuan Cui
maintainerPATCH v7 1/1 hv_sock: introduce Hyper-V Sockets
Hyper-V Sockets (hv_sock) supplies a byte-stream based communication mechanism between the host and the guest. It's somewhat like TCP over VMBus, but the transportation layer (VMBus) is much simpler than IP.
With Hyper-V Sockets, applications between the host and the guest can talk to each other directly by the traditional BSD-style socket APIs.
Hyper-V Sockets is only available on new Windows hosts, like Windows Server 2016. More info is in this article "Make your own integration services":
https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/develop/make_mgmt_service
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 | 5 +- 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 | 1481 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 1584 insertions(+), 2 deletions(-) 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
@@ -5267,7 +5267,9 @@ F: drivers/pci/host/pci-hyperv.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
@@ -1338,4 +1338,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 -2
@@ -201,8 +201,8 @@ struct ucred {#define AF_NFC 39/* NFC sockets */ #define AF_VSOCK 40/* vSockets */ #define AF_KCM 41/* Kernel Connection Multiplexor*/ - -#define AF_MAX 42/* For now.. */ +#define AF_HYPERV 42/* Hyper-V Sockets */ +#define AF_MAX 43/* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC
@@ -249,6 +249,7 @@ struct ucred {#define PF_NFC AF_NFC#define PF_VSOCK AF_VSOCK#define PF_KCM AF_KCM +#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 address fromat of Hyper-V Sockets. */ +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
@@ -70,6 +70,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 "Hyper-V Sockets" + depends on HYPERV + default m if HYPERV + help + Hyper-V Sockets is somewhat like TCP over VMBus, allowing + communication between Linux guest and Hyper-V host without TCP/IP. + + 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 +1481 -0
1,481 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 3 lines · Dexuan Cui
Hyper-V Sockets (
hv_sock) supplies a byte-stream based communication mechanism between the host and the guest. It's somewhat like TCP over VMBus, but the transportation layer (VMBus) is much simpler than IP.
style trivia:
net/hv_sock/af_hvsock.c
Quoted 1 line
net/hv_sock/af_hvsock.c +0
-0
[]
net/hv_sock/af_hvsock.c line 91
Quoted 8 lines
net/hv_sock/af_hvsock.c +8
-0+static struct sock *__hvsock_find_bound_socket (const struct sockaddr_hv *addr) +{ +struct hvsock_sock *hvsk; + +list_for_each_entry (hvsk, &hvsock_bound_list, bound_list) +if (uuid_equals (addr->shv_service_id, + hvsk->local_addr.shv_service_id)) +return hvsock_to_sk (hvsk);
Because there's an if, it's generally nicer to use braces in the list_for_each
net/hv_sock/af_hvsock.c line 103
Quoted 9 lines
net/hv_sock/af_hvsock.c +9
-0+static struct sock *__hvsock_find_connected_socket_by_channel ( +const struct vmbus_channel *channel) +{ +struct hvsock_sock *hvsk; + +list_for_each_entry (hvsk, &hvsock_connected_list, connected_list) +if (hvsk->channel == channel) +return hvsock_to_sk (hvsk); +return NULL ;
here too
net/hv_sock/af_hvsock.c line 1012
Quoted 2 lines
net/hv_sock/af_hvsock.c +2
-0+static int hvsock_sendmsg (struct socket *sock,struct msghdr *msg,size_t len) +{
[]
net/hv_sock/af_hvsock.c line 1031
Quoted 3 lines
net/hv_sock/af_hvsock.c +3
-0+if (msg->msg_flags & ~MSG_DONTWAIT ) { +pr_err ("hvsock_sendmsg: unsupported flags=0x%x\n" , + msg->msg_flags);
All the pr_<level> messages with embedded function names could use "%s:", __func__
Dexuan Cui
maintainerQuoted 21 lines
From: Joe Perches [mailto:[email protected]]
Sent: Thursday, April 7, 2016 19:30
To: Dexuan Cui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v7 net-next 1/1]hv_sock: introduce Hyper-V SocketsQuoted 3 lines · Dexuan Cui
Hyper-V Sockets (
hv_sock) supplies a byte-stream based communication mechanism between the host and the guest. It's somewhat like TCP over VMBus, but the transportation layer (VMBus) is much simpler than IP.style trivia:
net/hv_sock/af_hvsock.c
Quoted 1 line
net/hv_sock/af_hvsock.c +0
-0[]
Quoted 1 line
+static struct sock *__hvsock_find_bound_socket(const struct
sockaddr_hv*addr)
Quoted 10 lines
net/hv_sock/af_hvsock.c line 91
Quoted 7 lines
net/hv_sock/af_hvsock.c +7
-0+{ +struct hvsock_sock *hvsk; + +list_for_each_entry (hvsk, &hvsock_bound_list, bound_list) +if (uuid_equals (addr->shv_service_id, + hvsk->local_addr.shv_service_id)) +return hvsock_to_sk (hvsk);Because there's an if, it's generally nicer to use braces in the
list_for_each
Thanks for the suggestion, Joe!
I'll add {}.
Quoted 11 lines
net/hv_sock/af_hvsock.c line 103
Quoted 9 lines
net/hv_sock/af_hvsock.c +9
-0+static struct sock *__hvsock_find_connected_socket_by_channel ( +const struct vmbus_channel *channel) +{ +struct hvsock_sock *hvsk; + +list_for_each_entry (hvsk, &hvsock_connected_list, connected_list) +if (hvsk->channel == channel) +return hvsock_to_sk (hvsk); +return NULL ;here too
I'll fix this too.
Quoted 9 lines
net/hv_sock/af_hvsock.c line 1012
Quoted 2 lines
net/hv_sock/af_hvsock.c +2
-0+static int hvsock_sendmsg (struct socket *sock,struct msghdr *msg,size_t len) +{[]
net/hv_sock/af_hvsock.c line 1031
Quoted 3 lines
net/hv_sock/af_hvsock.c +3
-0+if (msg->msg_flags & ~MSG_DONTWAIT ) { +pr_err ("hvsock_sendmsg: unsupported flags=0x%x\n" , + msg->msg_flags);All the pr_<level> messages with embedded function names could use "%s:",
__func__
I'll fix this.
Thanks,
-- Dexuan