RE: [PATCH V6 8/8] hvsock: introduce Hyper-V Socket feature
> From: Olaf Hering [mailto:o...@aepfle.de] > Sent: Tuesday, January 26, 2016 18:24 > To: Dexuan Cui > Cc: gre...@linuxfoundation.org; da...@davemloft.net; > step...@networkplumber.org; netdev@vger.kernel.org; linux- > ker...@vger.kernel.org; driverdev-de...@linuxdriverproject.org; > a...@canonical.com; jasow...@redhat.com; KY Srinivasan > ; vkuzn...@redhat.com; pebo...@tiscali.nl; > stefa...@redhat.com; dan.carpen...@oracle.com > Subject: Re: [PATCH V6 8/8] hvsock: introduce Hyper-V Socket feature > > On Tue, Jan 26, Dexuan Cui wrote: > > > +#define AF_MAX 42 /* For now.. */ > > Maybe net/core/sock.c needs additional strings for the new socket? > > Olaf Olaf, Thanks for the reminder! I'll add a new patch like this: diff --git a/net/core/sock.c b/net/core/sock.c index 6c1c8bc..3c0aedb 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -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
Re: [PATCH V6 8/8] hvsock: introduce Hyper-V Socket feature
On Tue, Jan 26, Dexuan Cui wrote: > +#define AF_MAX 42 /* For now.. */ Maybe net/core/sock.c needs additional strings for the new socket? Olaf
[PATCH 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. Signed-off-by: Dexuan Cui Cc: Vitaly Kuznetsov --- 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 diff --git a/MAINTAINERS b/MAINTAINERS index 10b3f33..86eb25b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index acbbcb1..4bbc7f6 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -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 */ diff --git a/include/linux/socket.h b/include/linux/socket.h index 5bf59c8..d5ef612 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -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. */ diff --git a/include/net/af_hvsock.h b/include/net/af_hvsock.h new file mode 100644 index 000..a5aa28d --- /dev/null +++ b/include/net/af_hvsock.h @@ -0,0 +1,51 @@ +#ifndef __AF_HVSOCK_H__ +#define __AF_HVSOCK_H__ + +#include +#include +#include + +#define VMBUS_RINGBUFFER_SIZE_HVSOCK_RECV (5 * PAGE_SIZE) +#define VMBUS_RINGBUFFER_SIZE_HVSOCK_SEND (5 * PAGE_SIZE) + +#define HVSOCK_RCV_BUF_SZ VMBUS_RINGBUFFER_SIZE_HVSOCK_RECV +#define HVSOCK_SND_BUF_SZ PAGE_SIZE + +#define sk_to_hvsock(__sk)((struct hvsock_sock *)(__sk)) +#define hvsock_to_sk(__hvsk) ((struct sock *)(__hvsk)) + +struct hvsock_sock { + /* sk must be the first member. */ + struct sock sk; + + struct sockaddr_hv local_addr; + struct sockaddr_hv remote_addr; + + /* protected by the global hvsock_mutex */ + struct list_head bound_list; + struct list_head connected_list; + + struct list_head accept_queue; + /* used by enqueue and dequeue */ + struct mutex accept_queue_mutex; + + struct delayed_work dwork; + + u32 peer_shutdown; + + struct vmbus_channel *channel; + + struct { + struct vmpipe_proto_header hdr; + char buf[HVSOCK_SND_BUF_SZ]; + } __packed send; + + struct { + struct vmpipe_proto_header hdr; + char buf[HVSOCK_RCV_BUF_SZ]; + unsigned int data_len; + unsigned int data_offset; + } __packed recv; +}; + +#e