Skip to contentSkip to conversation

Add virtio transport for AF_VSOCK

RFC Superseded Stefan Hajnoczi 3 participants 12 messages Dec 22, 2015 – Jan 28, 2016

Subsystems (8)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Stefan Hajnoczi

author maintainer
#0 lore raw

v4 cover Add virtio transport for AF_VSOCK

This series is based on v4.4-rc2 and the "virtio: make find_vqs() checkpatch.pl-friendly" patch I recently submitted.

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.

This series implements the proposed virtio-vsock device specification from here:
http://permalink.gmane.org/gmane.comp.emulators.virtio.devel/980

Most 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).

Status
------
This patch series implements the latest draft specification. Please review.

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 (1):
VSOCK: transport-specific vsock_transport functions

 MAINTAINERS                                        |  13 +
 drivers/vhost/Kconfig                              |  15 +
 drivers/vhost/Makefile                             |   4 +
 drivers/vhost/vsock.c                              | 607 +++++++++++++++
 drivers/vhost/vsock.h                              |   4 +
 include/linux/virtio_vsock.h                       | 167 +++++
 include/net/af_vsock.h                             |   3 +
 .../trace/events/vsock_virtio_transport_common.h   | 144 ++++
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  87 +++
 net/vmw_vsock/Kconfig                              |  19 +
 net/vmw_vsock/Makefile                             |   2 +
 net/vmw_vsock/af_vsock.c                           |   9 +
 net/vmw_vsock/virtio_transport.c                   | 481 ++++++++++++
 net/vmw_vsock/virtio_transport_common.c            | 834 +++++++++++++++++++++
 15 files changed, 2390 insertions(+)
 create mode 100644 drivers/vhost/vsock.c
 create mode 100644 drivers/vhost/vsock.h
 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.5.0
author maintainer
#1 lore raw

RFC v4 1/5 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 7fd1220..9783a38 100644
@@ -1994,6 +1994,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.5.0
author maintainer
#2 lore raw

RFC v4 1/5 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 7fd1220..9783a38 100644
@@ -1994,6 +1994,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.5.0
author maintainer
#3 lore raw

RFC v4 2/5 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.

---
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                       | 167 +++++
 .../trace/events/vsock_virtio_transport_common.h   | 144 ++++
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  87 +++
 net/vmw_vsock/virtio_transport_common.c            | 834 +++++++++++++++++++++
 6 files changed, 1243 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 050d0e7..d42db78 100644
@@ -11360,6 +11360,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 +167 -0

167 lines not on this page · raw message

include/trace/events/vsock_virtio_transport_common.h new file +144 -0

144 lines not on this page · raw message

include/uapi/linux/virtio_ids.h +1 -0
index 77925f5..16dcf5d 100644
@@ -39,6 +39,7 @@
 #define VIRTIO_ID_9P		9 /* 9p virtio console */
 #define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */
 #define VIRTIO_ID_CAIF	       12 /* Virtio caif */
+#define VIRTIO_ID_VSOCK        13 /* virtio vsock transport */
 #define VIRTIO_ID_GPU          16 /* virtio GPU */
 #define VIRTIO_ID_INPUT        18 /* virtio input */
 
include/uapi/linux/virtio_vsock.h new file +87 -0

87 lines not on this page · raw message

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

834 lines not on this page · raw message

Signature · 1 line
2.5.0
author maintainer
#4 lore raw

RFC v4 3/5 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.

---
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 | 481 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 482 insertions(+)
 create mode 100644 net/vmw_vsock/virtio_transport.c
MAINTAINERS +1 -0
index d42db78..67d8504 100644
@@ -11369,6 +11369,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 +481 -0

481 lines not on this page · raw message

Signature · 1 line
2.5.0
author maintainer
#5 lore raw

RFC v4 4/5 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.

---
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
vhost: checkpatch.pl cleanups

---
 MAINTAINERS           |   2 +
 drivers/vhost/vsock.c | 607 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/vhost/vsock.h |   4 +
 3 files changed, 613 insertions(+)
 create mode 100644 drivers/vhost/vsock.c
 create mode 100644 drivers/vhost/vsock.h
MAINTAINERS +2 -0
index 67d8504..0181dc2 100644
@@ -11370,6 +11370,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 +607 -0

607 lines not on this page · raw message

drivers/vhost/vsock.h new file +4 -0
new file mode 100644
index 0000000..0ddb107
@@ -0,0 +1,4 @@
+#ifndef VHOST_VSOCK_H
+#define VHOST_VSOCK_H
+#define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u32)
+#endif
Signature · 1 line
2.5.0
author maintainer
#6 lore raw

RFC v4 5/5 VSOCK: Add Makefile and Kconfig

In reply to Stefan Hajnoczi

From: Asias He <[email protected]>

Enable virtio-vsock and vhost-vsock.

---
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  | 19 +++++++++++++++++++
 net/vmw_vsock/Makefile |  2 ++
 4 files changed, 40 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 +19 -0
index 14810ab..f27e74b 100644
@@ -26,3 +26,22 @@ 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 virtio_vsock_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.
net/vmw_vsock/Makefile +2 -0
index 2ce52d7..cf4c294 100644
@@ -1,5 +1,7 @@
 obj-$(CONFIG_VSOCKETS) += vsock.o
 obj-$(CONFIG_VMWARE_VMCI_VSOCKETS) += vmw_vsock_vmci_transport.o
+obj-$(CONFIG_VIRTIO_VSOCKETS) += virtio_transport.o
+obj-$(CONFIG_VIRTIO_VSOCKETS_COMMON) += virtio_transport_common.o
 
 vsock-y += af_vsock.o vsock_addr.o
 
Signature · 1 line
2.5.0
#7 lore raw
In reply to Stefan Hajnoczi
Quoted 72 lines · Stefan Hajnoczi

This series is based on v4.4-rc2 and the "virtio: make find_vqs() checkpatch.pl-friendly" patch I recently submitted.

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.

This series implements the proposed virtio-vsock device specification from here:
http://permalink.gmane.org/gmane.comp.emulators.virtio.devel/980

Most 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:

Quoted 5 lines

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

Have a (dumb maybe) question after a quick glance at the codes:

Is there any chance to reuse existed virtio-net/vhost-net codes? For example, using virito-net instead of a new device as a transport in guest and using vhost-net (especially consider it uses a socket as backend) in host. Maybe just a new virtio-net header type for vsock. I'm asking since I don't see any blocker for doing this.

Thanks

Quoted 51 lines

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).

Status
------
This patch series implements the latest draft specification. Please review.

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 (1):
VSOCK: transport-specific vsock_transport functions

 MAINTAINERS                                        |  13 +
 drivers/vhost/Kconfig                              |  15 +
 drivers/vhost/Makefile                             |   4 +
 drivers/vhost/vsock.c                              | 607 +++++++++++++++
 drivers/vhost/vsock.h                              |   4 +
 include/linux/virtio_vsock.h                       | 167 +++++
 include/net/af_vsock.h                             |   3 +
 .../trace/events/vsock_virtio_transport_common.h   | 144 ++++
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  87 +++
 net/vmw_vsock/Kconfig                              |  19 +
 net/vmw_vsock/Makefile                             |   2 +
 net/vmw_vsock/af_vsock.c                           |   9 +
 net/vmw_vsock/virtio_transport.c                   | 481 ++++++++++++
 net/vmw_vsock/virtio_transport_common.c            | 834 +++++++++++++++++++++
 15 files changed, 2390 insertions(+)
 create mode 100644 drivers/vhost/vsock.c
 create mode 100644 drivers/vhost/vsock.h
 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
#10 lore raw
In reply to Stefan Hajnoczi
Quoted 72 lines · Stefan Hajnoczi

This series is based on v4.4-rc2 and the "virtio: make find_vqs() checkpatch.pl-friendly" patch I recently submitted.

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.

This series implements the proposed virtio-vsock device specification from here:
http://permalink.gmane.org/gmane.comp.emulators.virtio.devel/980

Most 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:

Quoted 5 lines

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

Have a (dumb maybe) question after a quick glance at the codes:

Is there any chance to reuse existed virtio-net/vhost-net codes? For example, using virito-net instead of a new device as a transport in guest and using vhost-net (especially consider it uses a socket as backend) in host. Maybe just a new virtio-net header type for vsock. I'm asking since I don't see any blocker for doing this.

Thanks

Quoted 51 lines

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).

Status
------
This patch series implements the latest draft specification. Please review.

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 (1):
VSOCK: transport-specific vsock_transport functions

 MAINTAINERS                                        |  13 +
 drivers/vhost/Kconfig                              |  15 +
 drivers/vhost/Makefile                             |   4 +
 drivers/vhost/vsock.c                              | 607 +++++++++++++++
 drivers/vhost/vsock.h                              |   4 +
 include/linux/virtio_vsock.h                       | 167 +++++
 include/net/af_vsock.h                             |   3 +
 .../trace/events/vsock_virtio_transport_common.h   | 144 ++++
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  87 +++
 net/vmw_vsock/Kconfig                              |  19 +
 net/vmw_vsock/Makefile                             |   2 +
 net/vmw_vsock/af_vsock.c                           |   9 +
 net/vmw_vsock/virtio_transport.c                   | 481 ++++++++++++
 net/vmw_vsock/virtio_transport_common.c            | 834 +++++++++++++++++++++
 15 files changed, 2390 insertions(+)
 create mode 100644 drivers/vhost/vsock.c
 create mode 100644 drivers/vhost/vsock.h
 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
#8 lore raw
In reply to Jason Wang
Quoted 81 lines · Jason Wang
Quoted 72 lines · Stefan Hajnoczi

This series is based on v4.4-rc2 and the "virtio: make find_vqs() checkpatch.pl-friendly" patch I recently submitted.

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.

This series implements the proposed virtio-vsock device specification from here:
http://permalink.gmane.org/gmane.comp.emulators.virtio.devel/980

Most 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:

Quoted 5 lines

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

Quoted 7 lines

Have a (dumb maybe) question after a quick glance at the codes:

Is there any chance to reuse existed virtio-net/vhost-net codes? For example, using virito-net instead of a new device as a transport in guest and using vhost-net (especially consider it uses a socket as backend) in host. Maybe just a new virtio-net header type for vsock. I'm asking since I don't see any blocker for doing this.

virtio-net is an Ethernet device with best-effort delivery while virtio-vsock is guaranteed delivery. That's the fundamental difference at the protocol level.

At the driver level AF_VSOCK isn't supposed to have a netdev or user-visible network interface that can be misconfigured by the guest administrator.

Trying to make the existing virtio-net device work for this use case is probably nastier than using a dedicated device since lot of the virtio-net configuration space and control features don't make sense for AF_VSOCK.

Stefan

#9 lore raw
In reply to Jason Wang
Quoted 81 lines · Jason Wang
Quoted 72 lines · Stefan Hajnoczi

This series is based on v4.4-rc2 and the "virtio: make find_vqs() checkpatch.pl-friendly" patch I recently submitted.

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.

This series implements the proposed virtio-vsock device specification from here:
http://permalink.gmane.org/gmane.comp.emulators.virtio.devel/980

Most 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:

Quoted 5 lines

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

Quoted 7 lines

Have a (dumb maybe) question after a quick glance at the codes:

Is there any chance to reuse existed virtio-net/vhost-net codes? For example, using virito-net instead of a new device as a transport in guest and using vhost-net (especially consider it uses a socket as backend) in host. Maybe just a new virtio-net header type for vsock. I'm asking since I don't see any blocker for doing this.

virtio-net is an Ethernet device with best-effort delivery while virtio-vsock is guaranteed delivery. That's the fundamental difference at the protocol level.

At the driver level AF_VSOCK isn't supposed to have a netdev or user-visible network interface that can be misconfigured by the guest administrator.

Trying to make the existing virtio-net device work for this use case is probably nastier than using a dedicated device since lot of the virtio-net configuration space and control features don't make sense for AF_VSOCK.

Stefan

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author maintainer
#11 lore raw
In reply to Stefan Hajnoczi
Quoted 120 lines · Stefan Hajnoczi

This series is based on v4.4-rc2 and the "virtio: make find_vqs() checkpatch.pl-friendly" patch I recently submitted.

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.

This series implements the proposed virtio-vsock device specification from here:
http://permalink.gmane.org/gmane.comp.emulators.virtio.devel/980

Most 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).

Status
------
This patch series implements the latest draft specification. Please review.

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 (1):
VSOCK: transport-specific vsock_transport functions

 MAINTAINERS                                        |  13 +
 drivers/vhost/Kconfig                              |  15 +
 drivers/vhost/Makefile                             |   4 +
 drivers/vhost/vsock.c                              | 607 +++++++++++++++
 drivers/vhost/vsock.h                              |   4 +
 include/linux/virtio_vsock.h                       | 167 +++++
 include/net/af_vsock.h                             |   3 +
 .../trace/events/vsock_virtio_transport_common.h   | 144 ++++
 include/uapi/linux/virtio_ids.h                    |   1 +
 include/uapi/linux/virtio_vsock.h                  |  87 +++
 net/vmw_vsock/Kconfig                              |  19 +
 net/vmw_vsock/Makefile                             |   2 +
 net/vmw_vsock/af_vsock.c                           |   9 +
 net/vmw_vsock/virtio_transport.c                   | 481 ++++++++++++
 net/vmw_vsock/virtio_transport_common.c            | 834 +++++++++++++++++++++
Quoted 8 lines
 15 files changed, 2390 insertions(+)
 create mode 100644 drivers/vhost/vsock.c
 create mode 100644 drivers/vhost/vsock.h
 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

Michael and Jason: Ping

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization