Skip to contentSkip to conversation

Add virtio transport for AF_VSOCK

RFC Superseded Stefan Hajnoczi 1 participant 13 messages Jul 28, 2016

Subsystems (9)
lore
Share & tools
lore

Stefan Hajnoczi

author maintainer
#0 lore raw

v6 cover Add virtio transport for AF_VSOCK

This series is based on v4.7.

This RFC is the implementation for the new VIRTIO Socket device. It is developed in parallel with the VIRTIO device specification and proves the design. Once the specification has been accepted I will send a non-RFC version of this patch series.

v6:
* Add VHOST_VSOCK_SET_RUNNING ioctl to start/stop vhost cleanly
* Add graceful shutdown to avoid port reuse while peer is still closing socket [Ian Campbell]
* Start/stop rx depending on reply packet accounting to bound memory allocation if the host is not processing rx packets
* Use send_pkt_list to defer transmission
* Use spinlocks instead of mutexes for tx_lock/rx_lock because they are used in sections that are not allowed to sleep. [Claudio]
* 64-bit CIDs in virtio_vsock.h to match virtio-vsock specification
* Move duplicated send_pkt() logic from vhost and virtio transports into virtio_transport_common.ko
* ...and more, see individual patch changelogs

v5:
* Transport reset event for live migration support
* Reorder virtqueues, drop unused ctrl virtqueue
* Switch to a free virtio device ID
* More small changes, see patches for individual items

v4:
* Addressed code review comments from Alex Bennee
* MAINTAINERS file entries for new files
* Trace events instead of pr_debug()
* RST packet is sent when there is no listen socket
* Allow guest->host connections again (began discussing netfilter support with Matt Benjamin instead of hard-coding security policy in virtio-vsock code)
* Many checkpatch.pl cleanups (will be 100% clean in v5)

v3:
* Remove unnecessary 3-way handshake, just do REQUEST/RESPONSE instead of REQUEST/RESPONSE/ACK
* Remove SOCK_DGRAM support and focus on SOCK_STREAM first (also drop v2 Patch 1, it's only needed for SOCK_DGRAM)
* Only allow host->guest connections (same security model as latest VMware)
* Don't put vhost vsock driver into staging
* Add missing Kconfig dependencies (Arnd Bergmann <[email protected]>)
* Remove unneeded variable used to store return value (Fengguang Wu <[email protected]> and Julia Lawall <[email protected]>)

v2:
* Rebased onto Linux v4.4-rc2
* vhost: Refuse to assign reserved CIDs
* vhost: Refuse guest CID if already in use
* vhost: Only accept correctly addressed packets (no spoofing!)
* vhost: Support flexible rx/tx descriptor layout
* vhost: Add missing total_tx_buf decrement
* virtio_transport: Fix total_tx_buf accounting
* virtio_transport: Add virtio_transport global mutex to prevent races
* common: Notify other side of SOCK_STREAM disconnect (fixes shutdown semantics)
* common: Avoid recursive mutex_lock(tx_lock) for write_space (fixes deadlock)
* common: Define VIRTIO_VSOCK_TYPE_STREAM/DGRAM hardware interface constants
* common: Define VIRTIO_VSOCK_SHUTDOWN_RCV/SEND hardware interface constants
* common: Fix peer_buf_alloc inheritance on child socket

This patch series adds a virtio transport for AF_VSOCK (net/vmw_vsock/). AF_VSOCK is designed for communication between virtual machines and hypervisors. It is currently only implemented for VMware's VMCI transport.

Much of the work was done by Asias He and Gerd Hoffmann a while back. I have picked up the series again.

The QEMU userspace changes are here:
https://github.com/stefanha/qemu/commits/vsock

Why virtio-vsock?
-----------------
Guest<->host communication is currently done over the virtio-serial device. This makes it hard to port sockets API-based applications and is limited to static ports.

virtio-vsock uses the sockets API so that applications can rely on familiar SOCK_STREAM semantics. Applications on the host can easily connect to guest agents because the sockets API allows multiple connections to a listen socket (unlike virtio-serial). This simplifies the guest<->host communication and eliminates the need for extra processes on the host to arbitrate virtio-serial ports.

Overview
--------
This series adds 3 pieces:

1. virtio_transport_common.ko - core virtio vsock code that uses vsock.ko

2. virtio_transport.ko - guest driver

3. drivers/vhost/vsock.ko - host driver

Howto
-----
The following kernel options are needed:
CONFIG_VSOCKETS=y
CONFIG_VIRTIO_VSOCKETS=y
CONFIG_VIRTIO_VSOCKETS_COMMON=y
CONFIG_VHOST_VSOCK=m

Launch QEMU as follows:

  # qemu ... -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3

Guest and host can communicate via AF_VSOCK sockets. The host's CID (address) is 2 and the guest must be assigned a CID (3 in the example above).

See http://qemu-project.org/Features/VirtioVsock for more info.

Asias He (4):
VSOCK: Introduce virtio_vsock_common.ko
VSOCK: Introduce virtio_transport.ko
VSOCK: Introduce vhost_vsock.ko
VSOCK: Add Makefile and Kconfig

Stefan Hajnoczi (2):
VSOCK: transport-specific vsock_transport functions
VSOCK: defer sock removal to transports

 MAINTAINERS                                        |  13 +
 drivers/vhost/Kconfig                              |  15 +
 drivers/vhost/Makefile                             |   4 +
 drivers/vhost/vsock.c                              | 722 +++++++++++++++
 include/linux/virtio_vsock.h                       | 154 ++++
 include/net/af_vsock.h                             |   6 +
 .../trace/events/vsock_virtio_transport_common.h   | 144 +++
 include/uapi/linux/Kbuild                          |   1 +
 include/uapi/linux/vhost.h                         |   5 +
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  94 ++
 net/vmw_vsock/Kconfig                              |  20 +
 net/vmw_vsock/Makefile                             |   6 +
 net/vmw_vsock/af_vsock.c                           |  25 +-
 net/vmw_vsock/virtio_transport.c                   | 624 +++++++++++++
 net/vmw_vsock/virtio_transport_common.c            | 992 +++++++++++++++++++++
 net/vmw_vsock/vmci_transport.c                     |   2 +
 17 files changed, 2822 insertions(+), 6 deletions(-)
 create mode 100644 drivers/vhost/vsock.c
 create mode 100644 include/linux/virtio_vsock.h
 create mode 100644 include/trace/events/vsock_virtio_transport_common.h
 create mode 100644 include/uapi/linux/virtio_vsock.h
 create mode 100644 net/vmw_vsock/virtio_transport.c
 create mode 100644 net/vmw_vsock/virtio_transport_common.c
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

RFC v6 1/6 VSOCK: transport-specific vsock_transport functions

struct vsock_transport contains function pointers called by AF_VSOCK core code. The transport may want its own transport-specific function pointers and they can be added after struct vsock_transport.

Allow the transport to fetch vsock_transport. It can downcast it to access transport-specific function pointers.

The virtio transport will use this.

---
 include/net/af_vsock.h   | 3 +++
 net/vmw_vsock/af_vsock.c | 9 +++++++++
 2 files changed, 12 insertions(+)
include/net/af_vsock.h +3 -0
index e9eb2d6..23f5525 100644
@@ -165,6 +165,9 @@ static inline int vsock_core_init(const struct vsock_transport *t)
 }
 void vsock_core_exit(void);
 
+/* The transport may downcast this to access transport-specific functions */
+const struct vsock_transport *vsock_core_get_transport(void);
+
 /**** UTILS ****/
 
 void vsock_release_pending(struct sock *pending);
net/vmw_vsock/af_vsock.c +9 -0
index b96ac91..e34d96f 100644
@@ -1995,6 +1995,15 @@ void vsock_core_exit(void)
 }
 EXPORT_SYMBOL_GPL(vsock_core_exit);
 
+const struct vsock_transport *vsock_core_get_transport(void)
+{
+	/* vsock_register_mutex not taken since only the transport uses this
+	 * function and only while registered.
+	 */
+	return transport;
+}
+EXPORT_SYMBOL_GPL(vsock_core_get_transport);
+
 MODULE_AUTHOR("VMware, Inc.");
 MODULE_DESCRIPTION("VMware Virtual Socket Family");
 MODULE_VERSION("1.0.1.0-k");
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

RFC v6 1/6 VSOCK: transport-specific vsock_transport functions

In reply to Stefan Hajnoczi

struct vsock_transport contains function pointers called by AF_VSOCK core code. The transport may want its own transport-specific function pointers and they can be added after struct vsock_transport.

Allow the transport to fetch vsock_transport. It can downcast it to access transport-specific function pointers.

The virtio transport will use this.

---
 include/net/af_vsock.h   | 3 +++
 net/vmw_vsock/af_vsock.c | 9 +++++++++
 2 files changed, 12 insertions(+)
include/net/af_vsock.h +3 -0
index e9eb2d6..23f5525 100644
@@ -165,6 +165,9 @@ static inline int vsock_core_init(const struct vsock_transport *t)
 }
 void vsock_core_exit(void);
 
+/* The transport may downcast this to access transport-specific functions */
+const struct vsock_transport *vsock_core_get_transport(void);
+
 /**** UTILS ****/
 
 void vsock_release_pending(struct sock *pending);
net/vmw_vsock/af_vsock.c +9 -0
index b96ac91..e34d96f 100644
@@ -1995,6 +1995,15 @@ void vsock_core_exit(void)
 }
 EXPORT_SYMBOL_GPL(vsock_core_exit);
 
+const struct vsock_transport *vsock_core_get_transport(void)
+{
+	/* vsock_register_mutex not taken since only the transport uses this
+	 * function and only while registered.
+	 */
+	return transport;
+}
+EXPORT_SYMBOL_GPL(vsock_core_get_transport);
+
 MODULE_AUTHOR("VMware, Inc.");
 MODULE_DESCRIPTION("VMware Virtual Socket Family");
 MODULE_VERSION("1.0.1.0-k");
Signature · 1 line
2.7.4
author maintainer
#3 lore raw

RFC v6 2/6 VSOCK: defer sock removal to transports

In reply to Stefan Hajnoczi

The virtio transport will implement graceful shutdown and the related SO_LINGER socket option. This requires orphaning the sock but keeping it in the table of connections after .release().

This patch adds the vsock_remove_sock() function and leaves it up to the transport when to remove the sock.

---
 include/net/af_vsock.h         |  1 +
 net/vmw_vsock/af_vsock.c       | 16 ++++++++++------
 net/vmw_vsock/vmci_transport.c |  2 ++
 3 files changed, 13 insertions(+), 6 deletions(-)
include/net/af_vsock.h +1 -0
index 23f5525..3af0b22 100644
@@ -180,6 +180,7 @@ void vsock_remove_connected(struct vsock_sock *vsk);
 struct sock *vsock_find_bound_socket(struct sockaddr_vm *addr);
 struct sock *vsock_find_connected_socket(struct sockaddr_vm *src,
 					 struct sockaddr_vm *dst);
+void vsock_remove_sock(struct vsock_sock *vsk);
 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk));
 
 #endif /* __AF_VSOCK_H__ */
net/vmw_vsock/af_vsock.c +10 -6
index e34d96f..17dbbe6 100644
@@ -344,6 +344,16 @@ static bool vsock_in_connected_table(struct vsock_sock *vsk)
 	return ret;
 }
 
+void vsock_remove_sock(struct vsock_sock *vsk)
+{
+	if (vsock_in_bound_table(vsk))
+		vsock_remove_bound(vsk);
+
+	if (vsock_in_connected_table(vsk))
+		vsock_remove_connected(vsk);
+}
+EXPORT_SYMBOL_GPL(vsock_remove_sock);
+
 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk))
 {
 	int i;
@@ -660,12 +670,6 @@ static void __vsock_release(struct sock *sk)
 		vsk = vsock_sk(sk);
 		pending = NULL;	/* Compiler warning. */
 
-		if (vsock_in_bound_table(vsk))
-			vsock_remove_bound(vsk);
-
-		if (vsock_in_connected_table(vsk))
-			vsock_remove_connected(vsk);
-
 		transport->release(vsk);
 
 		lock_sock(sk);
net/vmw_vsock/vmci_transport.c +2 -0
index 4120b7a..4be4fbb 100644
@@ -1644,6 +1644,8 @@ static void vmci_transport_destruct(struct vsock_sock *vsk)
 
 static void vmci_transport_release(struct vsock_sock *vsk)
 {
+	vsock_remove_sock(vsk);
+
 	if (!vmci_handle_is_invalid(vmci_trans(vsk)->dg_handle)) {
 		vmci_datagram_destroy_handle(vmci_trans(vsk)->dg_handle);
 		vmci_trans(vsk)->dg_handle = VMCI_INVALID_HANDLE;
Signature · 1 line
2.7.4
author maintainer
#4 lore raw

RFC v6 2/6 VSOCK: defer sock removal to transports

In reply to Stefan Hajnoczi

The virtio transport will implement graceful shutdown and the related SO_LINGER socket option. This requires orphaning the sock but keeping it in the table of connections after .release().

This patch adds the vsock_remove_sock() function and leaves it up to the transport when to remove the sock.

---
 include/net/af_vsock.h         |  1 +
 net/vmw_vsock/af_vsock.c       | 16 ++++++++++------
 net/vmw_vsock/vmci_transport.c |  2 ++
 3 files changed, 13 insertions(+), 6 deletions(-)
include/net/af_vsock.h +1 -0
index 23f5525..3af0b22 100644
@@ -180,6 +180,7 @@ void vsock_remove_connected(struct vsock_sock *vsk);
 struct sock *vsock_find_bound_socket(struct sockaddr_vm *addr);
 struct sock *vsock_find_connected_socket(struct sockaddr_vm *src,
 					 struct sockaddr_vm *dst);
+void vsock_remove_sock(struct vsock_sock *vsk);
 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk));
 
 #endif /* __AF_VSOCK_H__ */
net/vmw_vsock/af_vsock.c +10 -6
index e34d96f..17dbbe6 100644
@@ -344,6 +344,16 @@ static bool vsock_in_connected_table(struct vsock_sock *vsk)
 	return ret;
 }
 
+void vsock_remove_sock(struct vsock_sock *vsk)
+{
+	if (vsock_in_bound_table(vsk))
+		vsock_remove_bound(vsk);
+
+	if (vsock_in_connected_table(vsk))
+		vsock_remove_connected(vsk);
+}
+EXPORT_SYMBOL_GPL(vsock_remove_sock);
+
 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk))
 {
 	int i;
@@ -660,12 +670,6 @@ static void __vsock_release(struct sock *sk)
 		vsk = vsock_sk(sk);
 		pending = NULL;	/* Compiler warning. */
 
-		if (vsock_in_bound_table(vsk))
-			vsock_remove_bound(vsk);
-
-		if (vsock_in_connected_table(vsk))
-			vsock_remove_connected(vsk);
-
 		transport->release(vsk);
 
 		lock_sock(sk);
net/vmw_vsock/vmci_transport.c +2 -0
index 4120b7a..4be4fbb 100644
@@ -1644,6 +1644,8 @@ static void vmci_transport_destruct(struct vsock_sock *vsk)
 
 static void vmci_transport_release(struct vsock_sock *vsk)
 {
+	vsock_remove_sock(vsk);
+
 	if (!vmci_handle_is_invalid(vmci_trans(vsk)->dg_handle)) {
 		vmci_datagram_destroy_handle(vmci_trans(vsk)->dg_handle);
 		vmci_trans(vsk)->dg_handle = VMCI_INVALID_HANDLE;
Signature · 1 line
2.7.4
author maintainer
#5 lore raw

RFC v6 3/6 VSOCK: Introduce virtio_vsock_common.ko

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

This module contains the common code and header files for the following virtio_transporto and vhost_vsock kernel modules.

---
v6:
* Add graceful shutdown to avoid port reuse while peer is still closing socket [Ian Campbell]
* Use spinlocks instead of mutexes for tx_lock/rx_lock because they are used in sections that are not allowed to sleep. [Claudio]
* Used nested lock notation in cases where child socket is held [Claudio]
* 64-bit CIDs in virtio_vsock.h to match virtio-vsock specification
* Avoid memcpy_to_msg() in atomic region
* Call sk_write_space() with sk_lock held
* Move duplicated send_pkt() logic from vhost and virtio transports into virtio_transport_common.ko
* Add __attribute__((packed)) to avoid struct padding for ABI structs [Gerard Garcia]
v5:
* Add event virtqueue, struct virtio_vsock_event, and transport reset event
* Reorder virtqueue indices: rx, tx, event
* Drop unused virtqueue_pairs config field
* Drop unused ctrl virtqueue
* Switch to a free virtio device ID, the previous one was reserved
v4:
* Add MAINTAINERS file entry
* checkpatch.pl cleanups
* linux_vsock.h: drop wrong copy-pasted license header
* Move tx sock refcounting to virtio_transport_alloc/free_pkt() to fix leaks in error paths
* Add send_pkt_no_sock() to send RST packets with no listen socket
* Rename per-socket state from virtio_transport to virtio_vsock_sock
* Move send_pkt_ops to new virtio_transport struct
* Drop dumppkt function, packet capture will be added in the future
* Drop empty virtio_transport_dec_tx_pkt()
* Allow guest->host connections again
* Use trace events instead of pr_debug()
v3:
* Remove unnecessary 3-way handshake, just do REQUEST/RESPONSE instead of REQUEST/RESPONSE/ACK
* Remove SOCK_DGRAM support and focus on SOCK_STREAM first
* Only allow host->guest connections (same security model as latest VMware)
v2:
* Fix peer_buf_alloc inheritance on child socket
* Notify other side of SOCK_STREAM disconnect (fixes shutdown semantics)
* Avoid recursive mutex_lock(tx_lock) for write_space (fixes deadlock)
* Define VIRTIO_VSOCK_TYPE_STREAM/DGRAM hardware interface constants
* Define VIRTIO_VSOCK_SHUTDOWN_RCV/SEND hardware interface constants

---
 MAINTAINERS                                        |  10 +
 include/linux/virtio_vsock.h                       | 154 ++++
 include/net/af_vsock.h                             |   2 +
 .../trace/events/vsock_virtio_transport_common.h   | 144 +++
 include/uapi/linux/Kbuild                          |   1 +
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  94 ++
 net/vmw_vsock/virtio_transport_common.c            | 992 +++++++++++++++++++++
 8 files changed, 1398 insertions(+)
 create mode 100644 include/linux/virtio_vsock.h
 create mode 100644 include/trace/events/vsock_virtio_transport_common.h
 create mode 100644 include/uapi/linux/virtio_vsock.h
 create mode 100644 net/vmw_vsock/virtio_transport_common.c
MAINTAINERS +10 -0
index 8c20323..b49ffb8 100644
@@ -12138,6 +12138,16 @@ S:	Maintained
 F:	drivers/media/v4l2-core/videobuf2-*
 F:	include/media/videobuf2-*
 
+VIRTIO AND VHOST VSOCK DRIVER
+M:	Stefan Hajnoczi <[email protected]>
+L:	[email protected]
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	include/linux/virtio_vsock.h
+F:	include/uapi/linux/virtio_vsock.h
+F:	net/vmw_vsock/virtio_transport_common.c
+
 VIRTUAL SERIO DEVICE DRIVER
 M:	Stephen Chandler Paul <[email protected]>
 S:	Maintained
include/linux/virtio_vsock.h new file +154 -0

154 lines not on this page · raw message

include/net/af_vsock.h +2 -0
index 3af0b22..f275896 100644
@@ -63,6 +63,8 @@ struct vsock_sock {
 	struct list_head accept_queue;
 	bool rejected;
 	struct delayed_work dwork;
+	struct delayed_work close_work;
+	bool close_work_scheduled;
 	u32 peer_shutdown;
 	bool sent_request;
 	bool ignore_connecting_rst;
include/trace/events/vsock_virtio_transport_common.h new file +144 -0

144 lines not on this page · raw message

include/uapi/linux/Kbuild +1 -0
index ec10cfe..3cf0116 100644
@@ -453,6 +453,7 @@ header-y += virtio_ring.h
 header-y += virtio_rng.h
 header-y += virtio_scsi.h
 header-y += virtio_types.h
+header-y += virtio_vsock.h
 header-y += vm_sockets.h
 header-y += vt.h
 header-y += wait.h
include/uapi/linux/virtio_ids.h +1 -0
index 77925f5..3228d58 100644
@@ -41,5 +41,6 @@
 #define VIRTIO_ID_CAIF	       12 /* Virtio caif */
 #define VIRTIO_ID_GPU          16 /* virtio GPU */
 #define VIRTIO_ID_INPUT        18 /* virtio input */
+#define VIRTIO_ID_VSOCK        19 /* virtio vsock transport */
 
 #endif /* _LINUX_VIRTIO_IDS_H */
include/uapi/linux/virtio_vsock.h new file +94 -0

94 lines not on this page · raw message

net/vmw_vsock/virtio_transport_common.c new file +992 -0

992 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#6 lore raw

RFC v6 3/6 VSOCK: Introduce virtio_vsock_common.ko

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

This module contains the common code and header files for the following virtio_transporto and vhost_vsock kernel modules.

---
v6:
* Add graceful shutdown to avoid port reuse while peer is still closing socket [Ian Campbell]
* Use spinlocks instead of mutexes for tx_lock/rx_lock because they are used in sections that are not allowed to sleep. [Claudio]
* Used nested lock notation in cases where child socket is held [Claudio]
* 64-bit CIDs in virtio_vsock.h to match virtio-vsock specification
* Avoid memcpy_to_msg() in atomic region
* Call sk_write_space() with sk_lock held
* Move duplicated send_pkt() logic from vhost and virtio transports into virtio_transport_common.ko
* Add __attribute__((packed)) to avoid struct padding for ABI structs [Gerard Garcia]
v5:
* Add event virtqueue, struct virtio_vsock_event, and transport reset event
* Reorder virtqueue indices: rx, tx, event
* Drop unused virtqueue_pairs config field
* Drop unused ctrl virtqueue
* Switch to a free virtio device ID, the previous one was reserved
v4:
* Add MAINTAINERS file entry
* checkpatch.pl cleanups
* linux_vsock.h: drop wrong copy-pasted license header
* Move tx sock refcounting to virtio_transport_alloc/free_pkt() to fix leaks in error paths
* Add send_pkt_no_sock() to send RST packets with no listen socket
* Rename per-socket state from virtio_transport to virtio_vsock_sock
* Move send_pkt_ops to new virtio_transport struct
* Drop dumppkt function, packet capture will be added in the future
* Drop empty virtio_transport_dec_tx_pkt()
* Allow guest->host connections again
* Use trace events instead of pr_debug()
v3:
* Remove unnecessary 3-way handshake, just do REQUEST/RESPONSE instead of REQUEST/RESPONSE/ACK
* Remove SOCK_DGRAM support and focus on SOCK_STREAM first
* Only allow host->guest connections (same security model as latest VMware)
v2:
* Fix peer_buf_alloc inheritance on child socket
* Notify other side of SOCK_STREAM disconnect (fixes shutdown semantics)
* Avoid recursive mutex_lock(tx_lock) for write_space (fixes deadlock)
* Define VIRTIO_VSOCK_TYPE_STREAM/DGRAM hardware interface constants
* Define VIRTIO_VSOCK_SHUTDOWN_RCV/SEND hardware interface constants

---
 MAINTAINERS                                        |  10 +
 include/linux/virtio_vsock.h                       | 154 ++++
 include/net/af_vsock.h                             |   2 +
 .../trace/events/vsock_virtio_transport_common.h   | 144 +++
 include/uapi/linux/Kbuild                          |   1 +
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  94 ++
 net/vmw_vsock/virtio_transport_common.c            | 992 +++++++++++++++++++++
 8 files changed, 1398 insertions(+)
 create mode 100644 include/linux/virtio_vsock.h
 create mode 100644 include/trace/events/vsock_virtio_transport_common.h
 create mode 100644 include/uapi/linux/virtio_vsock.h
 create mode 100644 net/vmw_vsock/virtio_transport_common.c
MAINTAINERS +10 -0
index 8c20323..b49ffb8 100644
@@ -12138,6 +12138,16 @@ S:	Maintained
 F:	drivers/media/v4l2-core/videobuf2-*
 F:	include/media/videobuf2-*
 
+VIRTIO AND VHOST VSOCK DRIVER
+M:	Stefan Hajnoczi <[email protected]>
+L:	[email protected]
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	include/linux/virtio_vsock.h
+F:	include/uapi/linux/virtio_vsock.h
+F:	net/vmw_vsock/virtio_transport_common.c
+
 VIRTUAL SERIO DEVICE DRIVER
 M:	Stephen Chandler Paul <[email protected]>
 S:	Maintained
include/linux/virtio_vsock.h new file +154 -0

154 lines not on this page · raw message

include/net/af_vsock.h +2 -0
index 3af0b22..f275896 100644
@@ -63,6 +63,8 @@ struct vsock_sock {
 	struct list_head accept_queue;
 	bool rejected;
 	struct delayed_work dwork;
+	struct delayed_work close_work;
+	bool close_work_scheduled;
 	u32 peer_shutdown;
 	bool sent_request;
 	bool ignore_connecting_rst;
include/trace/events/vsock_virtio_transport_common.h new file +144 -0

144 lines not on this page · raw message

include/uapi/linux/Kbuild +1 -0
index ec10cfe..3cf0116 100644
@@ -453,6 +453,7 @@ header-y += virtio_ring.h
 header-y += virtio_rng.h
 header-y += virtio_scsi.h
 header-y += virtio_types.h
+header-y += virtio_vsock.h
 header-y += vm_sockets.h
 header-y += vt.h
 header-y += wait.h
include/uapi/linux/virtio_ids.h +1 -0
index 77925f5..3228d58 100644
@@ -41,5 +41,6 @@
 #define VIRTIO_ID_CAIF	       12 /* Virtio caif */
 #define VIRTIO_ID_GPU          16 /* virtio GPU */
 #define VIRTIO_ID_INPUT        18 /* virtio input */
+#define VIRTIO_ID_VSOCK        19 /* virtio vsock transport */
 
 #endif /* _LINUX_VIRTIO_IDS_H */
include/uapi/linux/virtio_vsock.h new file +94 -0

94 lines not on this page · raw message

net/vmw_vsock/virtio_transport_common.c new file +992 -0

992 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#7 lore raw

RFC v6 4/6 VSOCK: Introduce virtio_transport.ko

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

VM sockets virtio transport implementation. This driver runs in the guest.

---
v6:
* Start/stop rx depending on reply packet accounting to bound memory allocation if the host is not processing rx packets
* 64-bit CID in packet header to match virtio-vsock specification
* Use send_pkt_list to defer transmission
* Avoid leaking virtqueue buffers and pkt lists on shutdown
* Remove total_tx_buf accounting, it is ineffective because control packets are not included
v5:
* Add transport reset event handling
* Drop ctrl virtqueue
v4:
* Add MAINTAINERS file entry
* Drop short/long rx packets
* checkpatch.pl cleanups
* Clarify locking in struct virtio_vsock
* Narrow local variable scopes as suggested by Alex Bennee
* Call wake_up() after decrementing total_tx_buf to avoid deadlock
v2:
* Fix total_tx_buf accounting
* Add virtio_transport global mutex to prevent races

---
 MAINTAINERS                      |   1 +
 net/vmw_vsock/virtio_transport.c | 624 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 625 insertions(+)
 create mode 100644 net/vmw_vsock/virtio_transport.c
MAINTAINERS +1 -0
index b49ffb8..7302663 100644
@@ -12147,6 +12147,7 @@ S:	Maintained
 F:	include/linux/virtio_vsock.h
 F:	include/uapi/linux/virtio_vsock.h
 F:	net/vmw_vsock/virtio_transport_common.c
+F:	net/vmw_vsock/virtio_transport.c
 
 VIRTUAL SERIO DEVICE DRIVER
 M:	Stephen Chandler Paul <[email protected]>
net/vmw_vsock/virtio_transport.c new file +624 -0

624 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#8 lore raw

RFC v6 4/6 VSOCK: Introduce virtio_transport.ko

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

VM sockets virtio transport implementation. This driver runs in the guest.

---
v6:
* Start/stop rx depending on reply packet accounting to bound memory allocation if the host is not processing rx packets
* 64-bit CID in packet header to match virtio-vsock specification
* Use send_pkt_list to defer transmission
* Avoid leaking virtqueue buffers and pkt lists on shutdown
* Remove total_tx_buf accounting, it is ineffective because control packets are not included
v5:
* Add transport reset event handling
* Drop ctrl virtqueue
v4:
* Add MAINTAINERS file entry
* Drop short/long rx packets
* checkpatch.pl cleanups
* Clarify locking in struct virtio_vsock
* Narrow local variable scopes as suggested by Alex Bennee
* Call wake_up() after decrementing total_tx_buf to avoid deadlock
v2:
* Fix total_tx_buf accounting
* Add virtio_transport global mutex to prevent races

---
 MAINTAINERS                      |   1 +
 net/vmw_vsock/virtio_transport.c | 624 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 625 insertions(+)
 create mode 100644 net/vmw_vsock/virtio_transport.c
MAINTAINERS +1 -0
index b49ffb8..7302663 100644
@@ -12147,6 +12147,7 @@ S:	Maintained
 F:	include/linux/virtio_vsock.h
 F:	include/uapi/linux/virtio_vsock.h
 F:	net/vmw_vsock/virtio_transport_common.c
+F:	net/vmw_vsock/virtio_transport.c
 
 VIRTUAL SERIO DEVICE DRIVER
 M:	Stephen Chandler Paul <[email protected]>
net/vmw_vsock/virtio_transport.c new file +624 -0

624 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#9 lore raw

RFC v6 5/6 VSOCK: Introduce vhost_vsock.ko

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

VM sockets vhost transport implementation. This driver runs on the host.

---
v6:
* Fall back to non-contiguous pages if vsock struct is too large (idea stolen from vhost_net)
* 64-bit CIDs in packet header and ioctl to match virtio-vsock specification
* Add VHOST_VSOCK_SET_RUNNING ioctl to start/stop vhost cleanly
* Remove total_tx_buf accounting, it is ineffective because control packets are not included
* Start/stop rx depending on reply packet accounting to bound memory allocation if the guest is not processing rx packets
* Turn vhost_vsock_mutex into a spinlock so packets can be sent in atomic context without lockdep errors
v5:
* Only take rx/tx virtqueues, userspace handles the other virtqueues
* Explicitly skip instances without a CID when transferring packets
* Add VHOST_VSOCK_START ioctl to being vhost virtqueue processing
* Reset established connections when device is closed
v4:
* Add MAINTAINERS file entry
* virtqueue used len is now sizeof(pkt->hdr) + pkt->len instead of just pkt->len
* checkpatch.pl cleanups
* Clarify struct vhost_vsock locking
* Add comments about optimization that disables virtqueue notify
* Drop unused vhost_vsock_handle_ctl_kick()
* Call wake_up() after decrementing total_tx_buf to prevent deadlock
v3:
* Remove unneeded variable used to store return value (Fengguang Wu <[email protected]> and Julia Lawall <[email protected]>)
v2:
* Add missing total_tx_buf decrement
* Support flexible rx/tx descriptor layout
* Refuse to assign reserved CIDs
* Refuse guest CID if already in use
* Only accept correctly addressed packets

---
 MAINTAINERS                |   2 +
 drivers/vhost/vsock.c      | 722 +++++++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/vhost.h |   5 +
 3 files changed, 729 insertions(+)
 create mode 100644 drivers/vhost/vsock.c
MAINTAINERS +2 -0
index 7302663..12c79e5 100644
@@ -12148,6 +12148,8 @@ F:	include/linux/virtio_vsock.h
 F:	include/uapi/linux/virtio_vsock.h
 F:	net/vmw_vsock/virtio_transport_common.c
 F:	net/vmw_vsock/virtio_transport.c
+F:	drivers/vhost/vsock.c
+F:	drivers/vhost/vsock.h
 
 VIRTUAL SERIO DEVICE DRIVER
 M:	Stephen Chandler Paul <[email protected]>
drivers/vhost/vsock.c new file +722 -0

722 lines not on this page · raw message

include/uapi/linux/vhost.h +5 -0
index 61a8777..c4400b2 100644
@@ -175,4 +175,9 @@ struct vhost_scsi_target {
 #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
 #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
 
+/* VHOST_VSOCK specific defines */
+
+#define VHOST_VSOCK_SET_GUEST_CID	_IOW(VHOST_VIRTIO, 0x60, __u64)
+#define VHOST_VSOCK_SET_RUNNING		_IOW(VHOST_VIRTIO, 0x61, int)
+
 #endif
Signature · 1 line
2.7.4
author maintainer
#10 lore raw

RFC v6 5/6 VSOCK: Introduce vhost_vsock.ko

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

VM sockets vhost transport implementation. This driver runs on the host.

---
v6:
* Fall back to non-contiguous pages if vsock struct is too large (idea stolen from vhost_net)
* 64-bit CIDs in packet header and ioctl to match virtio-vsock specification
* Add VHOST_VSOCK_SET_RUNNING ioctl to start/stop vhost cleanly
* Remove total_tx_buf accounting, it is ineffective because control packets are not included
* Start/stop rx depending on reply packet accounting to bound memory allocation if the guest is not processing rx packets
* Turn vhost_vsock_mutex into a spinlock so packets can be sent in atomic context without lockdep errors
v5:
* Only take rx/tx virtqueues, userspace handles the other virtqueues
* Explicitly skip instances without a CID when transferring packets
* Add VHOST_VSOCK_START ioctl to being vhost virtqueue processing
* Reset established connections when device is closed
v4:
* Add MAINTAINERS file entry
* virtqueue used len is now sizeof(pkt->hdr) + pkt->len instead of just pkt->len
* checkpatch.pl cleanups
* Clarify struct vhost_vsock locking
* Add comments about optimization that disables virtqueue notify
* Drop unused vhost_vsock_handle_ctl_kick()
* Call wake_up() after decrementing total_tx_buf to prevent deadlock
v3:
* Remove unneeded variable used to store return value (Fengguang Wu <[email protected]> and Julia Lawall <[email protected]>)
v2:
* Add missing total_tx_buf decrement
* Support flexible rx/tx descriptor layout
* Refuse to assign reserved CIDs
* Refuse guest CID if already in use
* Only accept correctly addressed packets

---
 MAINTAINERS                |   2 +
 drivers/vhost/vsock.c      | 722 +++++++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/vhost.h |   5 +
 3 files changed, 729 insertions(+)
 create mode 100644 drivers/vhost/vsock.c
MAINTAINERS +2 -0
index 7302663..12c79e5 100644
@@ -12148,6 +12148,8 @@ F:	include/linux/virtio_vsock.h
 F:	include/uapi/linux/virtio_vsock.h
 F:	net/vmw_vsock/virtio_transport_common.c
 F:	net/vmw_vsock/virtio_transport.c
+F:	drivers/vhost/vsock.c
+F:	drivers/vhost/vsock.h
 
 VIRTUAL SERIO DEVICE DRIVER
 M:	Stephen Chandler Paul <[email protected]>
drivers/vhost/vsock.c new file +722 -0

722 lines not on this page · raw message

include/uapi/linux/vhost.h +5 -0
index 61a8777..c4400b2 100644
@@ -175,4 +175,9 @@ struct vhost_scsi_target {
 #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
 #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
 
+/* VHOST_VSOCK specific defines */
+
+#define VHOST_VSOCK_SET_GUEST_CID	_IOW(VHOST_VIRTIO, 0x60, __u64)
+#define VHOST_VSOCK_SET_RUNNING		_IOW(VHOST_VIRTIO, 0x61, int)
+
 #endif
Signature · 1 line
2.7.4
author maintainer
#11 lore raw

RFC v6 6/6 VSOCK: Add Makefile and Kconfig

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

Enable virtio-vsock and vhost-vsock.

---
v6:
* Rename to virtio-vsock kernel modules to vmw_vsock_virtio_transport* instead of just virtio_transport to make the name clearer [Ian Campbell]
v4:
* Make checkpatch.pl happy with longer option description
* Clarify dependency on virtio rather than QEMU as suggested by Alex Bennee
v3:
* Don't put vhost vsock driver into staging
* Add missing Kconfig dependencies (Arnd Bergmann <[email protected]>)

---
 drivers/vhost/Kconfig  | 15 +++++++++++++++
 drivers/vhost/Makefile |  4 ++++
 net/vmw_vsock/Kconfig  | 20 ++++++++++++++++++++
 net/vmw_vsock/Makefile |  6 ++++++
 4 files changed, 45 insertions(+)
drivers/vhost/Kconfig +15 -0
index 533eaf0..d7aae9e 100644
@@ -21,6 +21,21 @@ config VHOST_SCSI
 	Say M here to enable the vhost_scsi TCM fabric module
 	for use with virtio-scsi guests
 
+config VHOST_VSOCK
+	tristate "vhost virtio-vsock driver"
+	depends on VSOCKETS && EVENTFD
+	select VIRTIO_VSOCKETS_COMMON
+	select VHOST
+	select VHOST_RING
+	default n
+	---help---
+	This kernel module can be loaded in the host kernel to provide AF_VSOCK
+	sockets for communicating with guests.  The guests must have the
+	virtio_transport.ko driver loaded to use the virtio-vsock device.
+
+	To compile this driver as a module, choose M here: the module will be called
+	vhost_vsock.
+
 config VHOST_RING
 	tristate
 	---help---
drivers/vhost/Makefile +4 -0
index e0441c3..6b012b9 100644
@@ -4,5 +4,9 @@ vhost_net-y := net.o
 obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o
 vhost_scsi-y := scsi.o
 
+obj-$(CONFIG_VHOST_VSOCK) += vhost_vsock.o
+vhost_vsock-y := vsock.o
+
 obj-$(CONFIG_VHOST_RING) += vringh.o
+
 obj-$(CONFIG_VHOST)	+= vhost.o
net/vmw_vsock/Kconfig +20 -0
index 14810ab..8831e7c 100644
@@ -26,3 +26,23 @@ config VMWARE_VMCI_VSOCKETS
 
 	  To compile this driver as a module, choose M here: the module
 	  will be called vmw_vsock_vmci_transport. If unsure, say N.
+
+config VIRTIO_VSOCKETS
+	tristate "virtio transport for Virtual Sockets"
+	depends on VSOCKETS && VIRTIO
+	select VIRTIO_VSOCKETS_COMMON
+	help
+	  This module implements a virtio transport for Virtual Sockets.
+
+	  Enable this transport if your Virtual Machine host supports Virtual
+	  Sockets over virtio.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called vmw_vsock_virtio_transport. If unsure, say N.
+
+config VIRTIO_VSOCKETS_COMMON
+	tristate
+	help
+	  This option is selected by any driver which needs to access
+	  the virtio_vsock.  The module will be called
+	  vmw_vsock_virtio_transport_common.
net/vmw_vsock/Makefile +6 -0
index 2ce52d7..bc27c70 100644
@@ -1,7 +1,13 @@
 obj-$(CONFIG_VSOCKETS) += vsock.o
 obj-$(CONFIG_VMWARE_VMCI_VSOCKETS) += vmw_vsock_vmci_transport.o
+obj-$(CONFIG_VIRTIO_VSOCKETS) += vmw_vsock_virtio_transport.o
+obj-$(CONFIG_VIRTIO_VSOCKETS_COMMON) += vmw_vsock_virtio_transport_common.o
 
 vsock-y += af_vsock.o vsock_addr.o
 
 vmw_vsock_vmci_transport-y += vmci_transport.o vmci_transport_notify.o \
 	vmci_transport_notify_qstate.o
+
+vmw_vsock_virtio_transport-y += virtio_transport.o
+
+vmw_vsock_virtio_transport_common-y += virtio_transport_common.o
Signature · 1 line
2.7.4
author maintainer
#12 lore raw

RFC v6 6/6 VSOCK: Add Makefile and Kconfig

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

Enable virtio-vsock and vhost-vsock.

---
v6:
* Rename to virtio-vsock kernel modules to vmw_vsock_virtio_transport* instead of just virtio_transport to make the name clearer [Ian Campbell]
v4:
* Make checkpatch.pl happy with longer option description
* Clarify dependency on virtio rather than QEMU as suggested by Alex Bennee
v3:
* Don't put vhost vsock driver into staging
* Add missing Kconfig dependencies (Arnd Bergmann <[email protected]>)

---
 drivers/vhost/Kconfig  | 15 +++++++++++++++
 drivers/vhost/Makefile |  4 ++++
 net/vmw_vsock/Kconfig  | 20 ++++++++++++++++++++
 net/vmw_vsock/Makefile |  6 ++++++
 4 files changed, 45 insertions(+)
drivers/vhost/Kconfig +15 -0
index 533eaf0..d7aae9e 100644
@@ -21,6 +21,21 @@ config VHOST_SCSI
 	Say M here to enable the vhost_scsi TCM fabric module
 	for use with virtio-scsi guests
 
+config VHOST_VSOCK
+	tristate "vhost virtio-vsock driver"
+	depends on VSOCKETS && EVENTFD
+	select VIRTIO_VSOCKETS_COMMON
+	select VHOST
+	select VHOST_RING
+	default n
+	---help---
+	This kernel module can be loaded in the host kernel to provide AF_VSOCK
+	sockets for communicating with guests.  The guests must have the
+	virtio_transport.ko driver loaded to use the virtio-vsock device.
+
+	To compile this driver as a module, choose M here: the module will be called
+	vhost_vsock.
+
 config VHOST_RING
 	tristate
 	---help---
drivers/vhost/Makefile +4 -0
index e0441c3..6b012b9 100644
@@ -4,5 +4,9 @@ vhost_net-y := net.o
 obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o
 vhost_scsi-y := scsi.o
 
+obj-$(CONFIG_VHOST_VSOCK) += vhost_vsock.o
+vhost_vsock-y := vsock.o
+
 obj-$(CONFIG_VHOST_RING) += vringh.o
+
 obj-$(CONFIG_VHOST)	+= vhost.o
net/vmw_vsock/Kconfig +20 -0
index 14810ab..8831e7c 100644
@@ -26,3 +26,23 @@ config VMWARE_VMCI_VSOCKETS
 
 	  To compile this driver as a module, choose M here: the module
 	  will be called vmw_vsock_vmci_transport. If unsure, say N.
+
+config VIRTIO_VSOCKETS
+	tristate "virtio transport for Virtual Sockets"
+	depends on VSOCKETS && VIRTIO
+	select VIRTIO_VSOCKETS_COMMON
+	help
+	  This module implements a virtio transport for Virtual Sockets.
+
+	  Enable this transport if your Virtual Machine host supports Virtual
+	  Sockets over virtio.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called vmw_vsock_virtio_transport. If unsure, say N.
+
+config VIRTIO_VSOCKETS_COMMON
+	tristate
+	help
+	  This option is selected by any driver which needs to access
+	  the virtio_vsock.  The module will be called
+	  vmw_vsock_virtio_transport_common.
net/vmw_vsock/Makefile +6 -0
index 2ce52d7..bc27c70 100644
@@ -1,7 +1,13 @@
 obj-$(CONFIG_VSOCKETS) += vsock.o
 obj-$(CONFIG_VMWARE_VMCI_VSOCKETS) += vmw_vsock_vmci_transport.o
+obj-$(CONFIG_VIRTIO_VSOCKETS) += vmw_vsock_virtio_transport.o
+obj-$(CONFIG_VIRTIO_VSOCKETS_COMMON) += vmw_vsock_virtio_transport_common.o
 
 vsock-y += af_vsock.o vsock_addr.o
 
 vmw_vsock_vmci_transport-y += vmci_transport.o vmci_transport_notify.o \
 	vmci_transport_notify_qstate.o
+
+vmw_vsock_virtio_transport-y += virtio_transport.o
+
+vmw_vsock_virtio_transport_common-y += virtio_transport_common.o
Signature · 1 line
2.7.4