hv_sock: introduce Hyper-V Sockets
Subsystems (4)
Dexuan Cui
maintainerPATCH v11 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.
---
You can also get the patch on this branch:
https://github.com/dcui/linux/commits/decui/hv_sock/net-next/20160515_v11
For the change log before v10, please see https://lkml.org/lkml/2016/5/4/532
In v10, the main changes consist of
1) minimize struct hvsock_sock by making the send/recv buffers pointers. the buffers are allocated by kmalloc() in __hvsock_create().
2) minimize the sizes of the send/recv buffers and the vmbus ringbuffers.
In v11, the changes are:
1) add module params: send_ring_page, recv_ring_page. They can be used to enlarge the ringbuffer size to get better performance, e.g.,
# modprobe hv_sock recv_ring_page=16 send_ring_page=16 By default, recv_ring_page is 3 and send_ring_page is 2.
2) add module param max_socket_number (the default is 1024).
A user can enlarge the number to create more than 1024 hv_sock sockets. By default, 1024 sockets take about 1024 * (3+2+1+1) * 4KB = 28M bytes. (Here 1+1 means 1 page for send/recv buffers per connection, respectively.)
3) implement the TODO in hvsock_shutdown().
4) fix a bug in hvsock_close_connection():
I remove "sk->sk_socket->state = SS_UNCONNECTED;" -- actually this line
is not really useful. For a connection triggered by a host app’s connect(), sk->sk_socket remains NULL before the connection is accepted by the server app (in Linux VM): see hvsock_accept() -> hvsock_accept_wait() -> sock_graft(connected, newsock). If the host app exits before the server app’s accept() returns, the host can send a rescind-message to close the connection and later in the Linux VM’s message handler
i.e. vmbus_onoffer_rescind()), Linux will get a NULL de-referencing crash.
5) fix a bug in hvsock_open_connection()
I move the vmbus_set_chn_rescind_callback() to a later place, because
when vmbus_open() fails, hvsock_close_connection() can do nothing and we count on vmbus_onoffer_rescind() -> vmbus_device_unregister() to clean up the device.
6) some stylistic modificiation.
MAINTAINERS | 2 + include/linux/hyperv.h | 14 + include/linux/socket.h | 4 +- include/net/af_hvsock.h | 78 +++ include/uapi/linux/hyperv.h | 25 + net/Kconfig | 1 + net/Makefile | 1 + net/hv_sock/Kconfig | 10 + net/hv_sock/Makefile | 3 + net/hv_sock/af_hvsock.c | 1520 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 1657 insertions(+), 1 deletion(-)
MAINTAINERS +2 -0
@@ -5271,7 +5271,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 +14 -0
@@ -1338,4 +1338,18 @@ 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; +}; + +#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)#endif /* _HYPERV_H */
include/linux/socket.h +3 -1
@@ -202,8 +202,9 @@ struct ucred {#define AF_VSOCK 40/* vSockets */ #define AF_KCM 41/* Kernel Connection Multiplexor*/ #define AF_QIPCRTR 42/* Qualcomm IPC Router */ +#define AF_HYPERV 43/* Hyper-V Sockets */ -#define AF_MAX 43/* For now.. */ +#define AF_MAX 44/* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC
@@ -251,6 +252,7 @@ struct ucred {#define PF_VSOCK AF_VSOCK#define PF_KCM AF_KCM#define PF_QIPCRTR AF_QIPCRTR +#define PF_HYPERV AF_HYPERV#define PF_MAX AF_MAX/* Maximum queue length specifiable by listen. */
include/net/af_hvsock.h new file +78 -0
78 lines not on this page · raw message
include/uapi/linux/hyperv.h +25 -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,28 @@ struct hv_kvp_ip_msg {struct hv_kvp_ipaddr_value kvp_ip_val; } __attribute__((packed)); +/* +* This is the address fromat of Hyper-V Sockets. +* Note: here we just borrow the kernel's built-in type uuid_le. When +* an application calls bind() or connect(), the 2 members of struct +* sockaddr_hv must be of GUID. +* The GUID format differs from the UUID format only in the byte order of +* the first 3 fields. Refer to: +* https://en.wikipedia.org/wiki/Globally_unique_identifier +*/ +#define guid_t uuid_le +struct sockaddr_hv { +__kernel_sa_family_t shv_family;/* Address family */ +__le16 reserved;/* Must be Zero */ +guid_t shv_vm_id;/* VM ID */ +guid_t 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 +1520 -0
1,520 lines not on this page · raw message
Signature · 1 line
2.7.4