vsock: add multi-transports support
Subsystems (12)
Stefano Garzarella
maintainerv2 cover vsock: add multi-transports support
Most of the patches are reviewed by Dexuan, Stefan, and Jorgen. The following patches need reviews:
- [11/15] vsock: add multi-transports support
- [12/15] vsock/vmci: register vmci_transport only when VMCI guest/host are active
- [15/15] vhost/vsock: refuse CID assigned to the guest->host transport
RFC: https://patchwork.ozlabs.org/cover/1168442/
v1: https://patchwork.ozlabs.org/cover/1181986/
v1 -> v2:
- Patch 11:
+ vmci_transport: sent reset when vsock_assign_transport() fails [Jorgen]
+ fixed loopback in the guests, checking if the remote_addr is the same of transport_g2h->get_local_cid()
+ virtio_transport_common: updated space available while creating the new child socket during a connection request
- Patch 12:
+ removed 'features' variable in vmci_transport_init() [Stefan]
+ added a flag to register only once the host [Jorgen]
- Added patch 15 to refuse CID assigned to the guest->host transport in the vhost_transport
This series adds the multi-transports support to vsock, following this proposal: https://www.spinics.net/lists/netdev/msg575792.html
With the multi-transports support, we can use VSOCK with nested VMs (using also different hypervisors) loading both guest->host and host->guest transports at the same time.
Before this series, vmci_transport supported this behavior but only using VMware hypervisor on L0, L1, etc.
The first 9 patches are cleanups and preparations, maybe some of these can go regardless of this series.
Patch 10 changes the hvs_remote_addr_init(). setting the VMADDR_CID_HOST as remote CID instead of VMADDR_CID_ANY to make the choice of transport to be used work properly.
Patch 11 adds multi-transports support.
Patch 12 changes a little bit the vmci_transport and the vmci driver to register the vmci_transport only when there are active host/guest.
Patch 13 prevents the transport modules unloading while sockets are assigned to them.
Patch 14 fixes an issue in the bind() logic discoverable only with the new multi-transport support.
Patch 15 refuses CID assigned to the guest->host transport in the vhost_transport.
I've tested this series with nested KVM (vsock-transport [L0,L1], virtio-transport[L1,L2]) and with VMware (L0) + KVM (L1) (vmci-transport [L0,L1], vhost-transport [L1], virtio-transport[L2]).
Dexuan successfully tested the RFC series on HyperV with a Linux guest.
Stefano Garzarella (15):
vsock/vmci: remove unused VSOCK_DEFAULT_CONNECT_TIMEOUT
vsock: remove vm_sockets_get_local_cid()
vsock: remove include/linux/vm_sockets.h file
vsock: add 'transport' member in the struct vsock_sock vsock/virtio: add transport parameter to the
virtio_transport_reset_no_sock()
vsock: add 'struct vsock_sock *' param to vsock_core_get_transport()
vsock: handle buffer_size sockopts in the core
vsock: add vsock_create_connected() called by transports
vsock: move vsock_insert_unbound() in the vsock_create()
hv_sock: set VMADDR_CID_HOST in the hvs_remote_addr_init()
vsock: add multi-transports support
vsock/vmci: register vmci_transport only when VMCI guest/host are
active
vsock: prevent transport modules unloading
vsock: fix bind() behaviour taking care of CID vhost/vsock: refuse CID assigned to the guest->host transport
drivers/misc/vmw_vmci/vmci_driver.c | 67 +++++ drivers/misc/vmw_vmci/vmci_driver.h | 2 + drivers/misc/vmw_vmci/vmci_guest.c | 2 + drivers/misc/vmw_vmci/vmci_host.c | 7 + drivers/vhost/vsock.c | 102 ++++--- include/linux/virtio_vsock.h | 18 +- include/linux/vm_sockets.h | 15 - include/linux/vmw_vmci_api.h | 2 + include/net/af_vsock.h | 45 +-- include/net/vsock_addr.h | 2 +- net/vmw_vsock/af_vsock.c | 382 ++++++++++++++++++------ net/vmw_vsock/hyperv_transport.c | 70 ++--- net/vmw_vsock/virtio_transport.c | 177 ++++++----- net/vmw_vsock/virtio_transport_common.c | 166 +++++----- net/vmw_vsock/vmci_transport.c | 140 ++++----- net/vmw_vsock/vmci_transport.h | 3 - net/vmw_vsock/vmci_transport_notify.h | 1 - 17 files changed, 679 insertions(+), 522 deletions(-) delete mode 100644 include/linux/vm_sockets.h
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 1/15 vsock/vmci: remove unused VSOCK_DEFAULT_CONNECT_TIMEOUT
The VSOCK_DEFAULT_CONNECT_TIMEOUT definition was introduced with commit d021c344051af ("VSOCK: Introduce VM Sockets"), but it is never used in the net/vmw_vsock/vmci_transport.c.
VSOCK_DEFAULT_CONNECT_TIMEOUT is used and defined in net/vmw_vsock/af_vsock.c
--- net/vmw_vsock/vmci_transport.c | 5 ----- 1 file changed, 5 deletions(-)
net/vmw_vsock/vmci_transport.c +0 -5
@@ -78,11 +78,6 @@ static int PROTOCOL_OVERRIDE = -1;#define VMCI_TRANSPORT_DEFAULT_QP_SIZE 262144#define VMCI_TRANSPORT_DEFAULT_QP_SIZE_MAX 262144 -/* The default peer timeout indicates how long we will wait for a peer response -* to a control message. -*/ -#define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) -/* Helper function to convert from a VMCI error code to a VSock error code. */ static s32 vmci_transport_error_to_vsock_error (s32 vmci_error)
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 1/15 vsock/vmci: remove unused VSOCK_DEFAULT_CONNECT_TIMEOUT
In reply to Stefano GarzarellaThe VSOCK_DEFAULT_CONNECT_TIMEOUT definition was introduced with commit d021c344051af ("VSOCK: Introduce VM Sockets"), but it is never used in the net/vmw_vsock/vmci_transport.c.
VSOCK_DEFAULT_CONNECT_TIMEOUT is used and defined in net/vmw_vsock/af_vsock.c
--- net/vmw_vsock/vmci_transport.c | 5 ----- 1 file changed, 5 deletions(-)
net/vmw_vsock/vmci_transport.c +0 -5
@@ -78,11 +78,6 @@ static int PROTOCOL_OVERRIDE = -1;#define VMCI_TRANSPORT_DEFAULT_QP_SIZE 262144#define VMCI_TRANSPORT_DEFAULT_QP_SIZE_MAX 262144 -/* The default peer timeout indicates how long we will wait for a peer response -* to a control message. -*/ -#define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) -/* Helper function to convert from a VMCI error code to a VSock error code. */ static s32 vmci_transport_error_to_vsock_error (s32 vmci_error)
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 2/15 vsock: remove vm_sockets_get_local_cid()
In reply to Stefano Garzarellavm_sockets_get_local_cid() is only used in virtio_transport_common.c. We can replace it calling the virtio_transport_get_ops() and using the get_local_cid() callback registered by the transport.
--- include/linux/vm_sockets.h | 2 -- net/vmw_vsock/af_vsock.c | 10 ---------- net/vmw_vsock/virtio_transport_common.c | 2 +- 3 files changed, 1 insertion(+), 13 deletions(-)
include/linux/vm_sockets.h +0 -2
@@ -10,6 +10,4 @@#include <uapi/linux/vm_sockets.h> -int vm_sockets_get_local_cid (void ); -#endif /* _VM_SOCKETS_H */
net/vmw_vsock/af_vsock.c +0 -10
@@ -129,16 +129,6 @@ static struct proto vsock_proto = {static const struct vsock_transport *transport;static DEFINE_MUTEX (vsock_register_mutex); -/**** EXPORTS ****/ - -/* Get the ID of the local context. This is transport dependent. */ - -int vm_sockets_get_local_cid (void ) -{ -return transport->get_local_cid (); -} -EXPORT_SYMBOL_GPL (vm_sockets_get_local_cid); -/**** UTILS ****/ /* Each bound VSocket is stored in the bind hash table and each connected
net/vmw_vsock/virtio_transport_common.c +1 -1
@@ -168,7 +168,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,struct virtio_vsock_pkt *pkt;u32 pkt_len = info->pkt_len; - src_cid =vm_sockets_get_local_cid (); + src_cid =virtio_transport_get_ops ()->transport.get_local_cid (); src_port = vsk->local_addr.svm_port;if (!info->remote_cid) { dst_cid = vsk->remote_addr.svm_cid;
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 2/15 vsock: remove vm_sockets_get_local_cid()
In reply to Stefano Garzarellavm_sockets_get_local_cid() is only used in virtio_transport_common.c. We can replace it calling the virtio_transport_get_ops() and using the get_local_cid() callback registered by the transport.
--- include/linux/vm_sockets.h | 2 -- net/vmw_vsock/af_vsock.c | 10 ---------- net/vmw_vsock/virtio_transport_common.c | 2 +- 3 files changed, 1 insertion(+), 13 deletions(-)
include/linux/vm_sockets.h +0 -2
@@ -10,6 +10,4 @@#include <uapi/linux/vm_sockets.h> -int vm_sockets_get_local_cid (void ); -#endif /* _VM_SOCKETS_H */
net/vmw_vsock/af_vsock.c +0 -10
@@ -129,16 +129,6 @@ static struct proto vsock_proto = {static const struct vsock_transport *transport;static DEFINE_MUTEX (vsock_register_mutex); -/**** EXPORTS ****/ - -/* Get the ID of the local context. This is transport dependent. */ - -int vm_sockets_get_local_cid (void ) -{ -return transport->get_local_cid (); -} -EXPORT_SYMBOL_GPL (vm_sockets_get_local_cid); -/**** UTILS ****/ /* Each bound VSocket is stored in the bind hash table and each connected
net/vmw_vsock/virtio_transport_common.c +1 -1
@@ -168,7 +168,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,struct virtio_vsock_pkt *pkt;u32 pkt_len = info->pkt_len; - src_cid =vm_sockets_get_local_cid (); + src_cid =virtio_transport_get_ops ()->transport.get_local_cid (); src_port = vsk->local_addr.svm_port;if (!info->remote_cid) { dst_cid = vsk->remote_addr.svm_cid;
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 3/15 vsock: remove include/linux/vm_sockets.h file
In reply to Stefano GarzarellaThis header file now only includes the "uapi/linux/vm_sockets.h". We can include directly it when needed.
--- include/linux/vm_sockets.h | 13 ------------- include/net/af_vsock.h | 2 +- include/net/vsock_addr.h | 2 +- net/vmw_vsock/vmci_transport_notify.h | 1 - 4 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 include/linux/vm_sockets.h
include/linux/vm_sockets.h deleted +0 -13
@@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* VMware vSockets Driver -* -* Copyright (C) 2007-2013 VMware, Inc. All rights reserved. -*/ - -#ifndef _VM_SOCKETS_H -#define _VM_SOCKETS_H - -#include <uapi/linux/vm_sockets.h> - -#endif /* _VM_SOCKETS_H */
include/net/af_vsock.h +1 -1
@@ -10,7 +10,7 @@#include <linux/kernel.h> #include <linux/workqueue.h> -#include <linux/vm_sockets.h> +#include <uapi/linux/vm_sockets.h> #include "vsock_addr.h"
include/net/vsock_addr.h +1 -1
@@ -8,7 +8,7 @@#ifndef _VSOCK_ADDR_H_#define _VSOCK_ADDR_H_ -#include <linux/vm_sockets.h> +#include <uapi/linux/vm_sockets.h> void vsock_addr_init (struct sockaddr_vm *addr,u32 cid,u32 port);int vsock_addr_validate (const struct sockaddr_vm *addr);
net/vmw_vsock/vmci_transport_notify.h +0 -1
@@ -11,7 +11,6 @@#include <linux/types.h> #include <linux/vmw_vmci_defs.h> #include <linux/vmw_vmci_api.h> -#include <linux/vm_sockets.h> #include "vmci_transport.h"
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 3/15 vsock: remove include/linux/vm_sockets.h file
In reply to Stefano GarzarellaThis header file now only includes the "uapi/linux/vm_sockets.h". We can include directly it when needed.
--- include/linux/vm_sockets.h | 13 ------------- include/net/af_vsock.h | 2 +- include/net/vsock_addr.h | 2 +- net/vmw_vsock/vmci_transport_notify.h | 1 - 4 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 include/linux/vm_sockets.h
include/linux/vm_sockets.h deleted +0 -13
@@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* VMware vSockets Driver -* -* Copyright (C) 2007-2013 VMware, Inc. All rights reserved. -*/ - -#ifndef _VM_SOCKETS_H -#define _VM_SOCKETS_H - -#include <uapi/linux/vm_sockets.h> - -#endif /* _VM_SOCKETS_H */
include/net/af_vsock.h +1 -1
@@ -10,7 +10,7 @@#include <linux/kernel.h> #include <linux/workqueue.h> -#include <linux/vm_sockets.h> +#include <uapi/linux/vm_sockets.h> #include "vsock_addr.h"
include/net/vsock_addr.h +1 -1
@@ -8,7 +8,7 @@#ifndef _VSOCK_ADDR_H_#define _VSOCK_ADDR_H_ -#include <linux/vm_sockets.h> +#include <uapi/linux/vm_sockets.h> void vsock_addr_init (struct sockaddr_vm *addr,u32 cid,u32 port);int vsock_addr_validate (const struct sockaddr_vm *addr);
net/vmw_vsock/vmci_transport_notify.h +0 -1
@@ -11,7 +11,6 @@#include <linux/types.h> #include <linux/vmw_vmci_defs.h> #include <linux/vmw_vmci_api.h> -#include <linux/vm_sockets.h> #include "vmci_transport.h"
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 4/15 vsock: add 'transport' member in the struct vsock_sock
In reply to Stefano GarzarellaAs a preparation to support multiple transports, this patch adds the 'transport' member at the 'struct vsock_sock'. This new field is initialized during the creation in the __vsock_create() function.
This patch also renames the global 'transport' pointer to 'transport_single', since for now we're only supporting a single transport registered at run-time.
--- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 56 +++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 18 deletions(-)
include/net/af_vsock.h +1 -0
@@ -27,6 +27,7 @@ extern spinlock_t vsock_table_lock;struct vsock_sock {/* sk must be the first member. */ struct sock sk; +const struct vsock_transport *transport;struct sockaddr_vm local_addr;struct sockaddr_vm remote_addr;/* Links for the global tables of bound and connected sockets. */
net/vmw_vsock/af_vsock.c +38 -18
247 lines not on this page · raw message
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 4/15 vsock: add 'transport' member in the struct vsock_sock
In reply to Stefano GarzarellaAs a preparation to support multiple transports, this patch adds the 'transport' member at the 'struct vsock_sock'. This new field is initialized during the creation in the __vsock_create() function.
This patch also renames the global 'transport' pointer to 'transport_single', since for now we're only supporting a single transport registered at run-time.
--- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 56 +++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 18 deletions(-)
include/net/af_vsock.h +1 -0
@@ -27,6 +27,7 @@ extern spinlock_t vsock_table_lock;struct vsock_sock {/* sk must be the first member. */ struct sock sk; +const struct vsock_transport *transport;struct sockaddr_vm local_addr;struct sockaddr_vm remote_addr;/* Links for the global tables of bound and connected sockets. */
net/vmw_vsock/af_vsock.c +38 -18
247 lines not on this page · raw message
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 5/15 vsock/virtio: add transport parameter to the virtio_transport_reset_no_sock()
In reply to Stefano GarzarellaWe are going to add 'struct vsock_sock *' parameter to virtio_transport_get_ops().
In some cases, like in the virtio_transport_reset_no_sock(), we don't have any socket assigned to the packet received, so we can't use the virtio_transport_get_ops().
In order to allow virtio_transport_reset_no_sock() to use the '.send_pkt' callback from the 'vhost_transport' or 'virtio_transport', we add the 'struct virtio_transport *' to it and to its caller:virtio_transport_recv_pkt().
We moved the 'vhost_transport' and 'virtio_transport' definition, to pass their address to the virtio_transport_recv_pkt().
--- drivers/vhost/vsock.c | 94 +++++++------- include/linux/virtio_vsock.h | 3 +- net/vmw_vsock/virtio_transport.c | 160 ++++++++++++------------ net/vmw_vsock/virtio_transport_common.c | 12 +- 4 files changed, 135 insertions(+), 134 deletions(-)
drivers/vhost/vsock.c +47 -47
@@ -384,6 +384,52 @@ static bool vhost_vsock_more_replies(struct vhost_vsock *vsock)return val < vq->num; } +static struct virtio_transport vhost_transport = { + .transport = { + .get_local_cid = vhost_transport_get_local_cid, + + .init = virtio_transport_do_socket_init, + .destruct = virtio_transport_destruct, + .release = virtio_transport_release, + .connect = virtio_transport_connect, + .shutdown = virtio_transport_shutdown, + .cancel_pkt = vhost_transport_cancel_pkt, + + .dgram_enqueue = virtio_transport_dgram_enqueue, + .dgram_dequeue = virtio_transport_dgram_dequeue, + .dgram_bind = virtio_transport_dgram_bind, + .dgram_allow = virtio_transport_dgram_allow, + + .stream_enqueue = virtio_transport_stream_enqueue, + .stream_dequeue = virtio_transport_stream_dequeue, + .stream_has_data = virtio_transport_stream_has_data, + .stream_has_space = virtio_transport_stream_has_space, + .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, + .stream_is_active = virtio_transport_stream_is_active, + .stream_allow = virtio_transport_stream_allow, + + .notify_poll_in = virtio_transport_notify_poll_in, + .notify_poll_out = virtio_transport_notify_poll_out, + .notify_recv_init = virtio_transport_notify_recv_init, + .notify_recv_pre_block = virtio_transport_notify_recv_pre_block, + .notify_recv_pre_dequeue = virtio_transport_notify_recv_pre_dequeue, + .notify_recv_post_dequeue = virtio_transport_notify_recv_post_dequeue, + .notify_send_init = virtio_transport_notify_send_init, + .notify_send_pre_block = virtio_transport_notify_send_pre_block, + .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, + .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, + + .set_buffer_size = virtio_transport_set_buffer_size, + .set_min_buffer_size = virtio_transport_set_min_buffer_size, + .set_max_buffer_size = virtio_transport_set_max_buffer_size, + .get_buffer_size = virtio_transport_get_buffer_size, + .get_min_buffer_size = virtio_transport_get_min_buffer_size, + .get_max_buffer_size = virtio_transport_get_max_buffer_size, + }, + + .send_pkt = vhost_transport_send_pkt, +}; +static void vhost_vsock_handle_tx_kick (struct vhost_work *work) { struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
@@ -438,7 +484,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)/* Only accept correctly addressed packets */ if (le64_to_cpu (pkt->hdr.src_cid) == vsock->guest_cid) -virtio_transport_recv_pkt (pkt); +virtio_transport_recv_pkt (&vhost_transport, pkt);else virtio_transport_free_pkt (pkt);
@@ -786,52 +832,6 @@ static struct miscdevice vhost_vsock_misc = { .fops = &vhost_vsock_fops, }; -static struct virtio_transport vhost_transport = { - .transport = { - .get_local_cid = vhost_transport_get_local_cid, - - .init = virtio_transport_do_socket_init, - .destruct = virtio_transport_destruct, - .release = virtio_transport_release, - .connect = virtio_transport_connect, - .shutdown = virtio_transport_shutdown, - .cancel_pkt = vhost_transport_cancel_pkt, - - .dgram_enqueue = virtio_transport_dgram_enqueue, - .dgram_dequeue = virtio_transport_dgram_dequeue, - .dgram_bind = virtio_transport_dgram_bind, - .dgram_allow = virtio_transport_dgram_allow, - - .stream_enqueue = virtio_transport_stream_enqueue, - .stream_dequeue = virtio_transport_stream_dequeue, - .stream_has_data = virtio_transport_stream_has_data, - .stream_has_space = virtio_transport_stream_has_space, - .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, - .stream_is_active = virtio_transport_stream_is_active, - .stream_allow = virtio_transport_stream_allow, - - .notify_poll_in = virtio_transport_notify_poll_in, - .notify_poll_out = virtio_transport_notify_poll_out, - .notify_recv_init = virtio_transport_notify_recv_init, - .notify_recv_pre_block = virtio_transport_notify_recv_pre_block, - .notify_recv_pre_dequeue = virtio_transport_notify_recv_pre_dequeue, - .notify_recv_post_dequeue = virtio_transport_notify_recv_post_dequeue, - .notify_send_init = virtio_transport_notify_send_init, - .notify_send_pre_block = virtio_transport_notify_send_pre_block, - .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, - .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, - - .set_buffer_size = virtio_transport_set_buffer_size, - .set_min_buffer_size = virtio_transport_set_min_buffer_size, - .set_max_buffer_size = virtio_transport_set_max_buffer_size, - .get_buffer_size = virtio_transport_get_buffer_size, - .get_min_buffer_size = virtio_transport_get_min_buffer_size, - .get_max_buffer_size = virtio_transport_get_max_buffer_size, - }, - - .send_pkt = vhost_transport_send_pkt, -}; -static int __init vhost_vsock_init (void ) {int ret;
include/linux/virtio_vsock.h +2 -1
@@ -150,7 +150,8 @@ virtio_transport_dgram_enqueue(struct vsock_sock *vsk,void virtio_transport_destruct (struct vsock_sock *vsk); -void virtio_transport_recv_pkt (struct virtio_vsock_pkt *pkt); +void virtio_transport_recv_pkt (struct virtio_transport *t, +struct virtio_vsock_pkt *pkt);void virtio_transport_free_pkt (struct virtio_vsock_pkt *pkt);void virtio_transport_inc_tx_pkt (struct virtio_vsock_sock *vvs,struct virtio_vsock_pkt *pkt);u32 virtio_transport_get_credit (struct virtio_vsock_sock *vvs,u32 wanted);
net/vmw_vsock/virtio_transport.c +80 -80
178 lines not on this page · raw message
net/vmw_vsock/virtio_transport_common.c +6 -6
@@ -745,9 +745,9 @@ static int virtio_transport_reset(struct vsock_sock *vsk,/* Normally packets are associated with a socket. There may be no socket if an * attempt was made to connect to a socket that does not exist. */ -static int virtio_transport_reset_no_sock (struct virtio_vsock_pkt *pkt) +static int virtio_transport_reset_no_sock (const struct virtio_transport *t, +struct virtio_vsock_pkt *pkt) { -const struct virtio_transport *t;struct virtio_vsock_pkt *reply;struct virtio_vsock_pkt_info info = { .op =VIRTIO_VSOCK_OP_RST ,
@@ -767,7 +767,6 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)if (!reply)return -ENOMEM ; - t =virtio_transport_get_ops ();if (!t) {virtio_transport_free_pkt (reply);return -ENOTCONN ;
@@ -1109,7 +1108,8 @@ static bool virtio_transport_space_update(struct sock *sk,/* We are under the virtio-vsock's vsock->rx_lock or vhost-vsock's vq->mutex * lock. */ -void virtio_transport_recv_pkt (struct virtio_vsock_pkt *pkt) +void virtio_transport_recv_pkt (struct virtio_transport *t, +struct virtio_vsock_pkt *pkt) {struct sockaddr_vm src, dst;struct vsock_sock *vsk;
@@ -1131,7 +1131,7 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt) le32_to_cpu(pkt->hdr.fwd_cnt));if (le16_to_cpu (pkt->hdr.type) !=VIRTIO_VSOCK_TYPE_STREAM ) { - (void )virtio_transport_reset_no_sock (pkt); + (void )virtio_transport_reset_no_sock (t, pkt); goto free_pkt; }
@@ -1142,7 +1142,7 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)if (!sk) { sk =vsock_find_bound_socket (&dst);if (!sk) { - (void )virtio_transport_reset_no_sock (pkt); + (void )virtio_transport_reset_no_sock (t, pkt); goto free_pkt; } }
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 5/15 vsock/virtio: add transport parameter to the virtio_transport_reset_no_sock()
In reply to Stefano GarzarellaWe are going to add 'struct vsock_sock *' parameter to virtio_transport_get_ops().
In some cases, like in the virtio_transport_reset_no_sock(), we don't have any socket assigned to the packet received, so we can't use the virtio_transport_get_ops().
In order to allow virtio_transport_reset_no_sock() to use the '.send_pkt' callback from the 'vhost_transport' or 'virtio_transport', we add the 'struct virtio_transport *' to it and to its caller:virtio_transport_recv_pkt().
We moved the 'vhost_transport' and 'virtio_transport' definition, to pass their address to the virtio_transport_recv_pkt().
--- drivers/vhost/vsock.c | 94 +++++++------- include/linux/virtio_vsock.h | 3 +- net/vmw_vsock/virtio_transport.c | 160 ++++++++++++------------ net/vmw_vsock/virtio_transport_common.c | 12 +- 4 files changed, 135 insertions(+), 134 deletions(-)
drivers/vhost/vsock.c +47 -47
@@ -384,6 +384,52 @@ static bool vhost_vsock_more_replies(struct vhost_vsock *vsock)return val < vq->num; } +static struct virtio_transport vhost_transport = { + .transport = { + .get_local_cid = vhost_transport_get_local_cid, + + .init = virtio_transport_do_socket_init, + .destruct = virtio_transport_destruct, + .release = virtio_transport_release, + .connect = virtio_transport_connect, + .shutdown = virtio_transport_shutdown, + .cancel_pkt = vhost_transport_cancel_pkt, + + .dgram_enqueue = virtio_transport_dgram_enqueue, + .dgram_dequeue = virtio_transport_dgram_dequeue, + .dgram_bind = virtio_transport_dgram_bind, + .dgram_allow = virtio_transport_dgram_allow, + + .stream_enqueue = virtio_transport_stream_enqueue, + .stream_dequeue = virtio_transport_stream_dequeue, + .stream_has_data = virtio_transport_stream_has_data, + .stream_has_space = virtio_transport_stream_has_space, + .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, + .stream_is_active = virtio_transport_stream_is_active, + .stream_allow = virtio_transport_stream_allow, + + .notify_poll_in = virtio_transport_notify_poll_in, + .notify_poll_out = virtio_transport_notify_poll_out, + .notify_recv_init = virtio_transport_notify_recv_init, + .notify_recv_pre_block = virtio_transport_notify_recv_pre_block, + .notify_recv_pre_dequeue = virtio_transport_notify_recv_pre_dequeue, + .notify_recv_post_dequeue = virtio_transport_notify_recv_post_dequeue, + .notify_send_init = virtio_transport_notify_send_init, + .notify_send_pre_block = virtio_transport_notify_send_pre_block, + .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, + .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, + + .set_buffer_size = virtio_transport_set_buffer_size, + .set_min_buffer_size = virtio_transport_set_min_buffer_size, + .set_max_buffer_size = virtio_transport_set_max_buffer_size, + .get_buffer_size = virtio_transport_get_buffer_size, + .get_min_buffer_size = virtio_transport_get_min_buffer_size, + .get_max_buffer_size = virtio_transport_get_max_buffer_size, + }, + + .send_pkt = vhost_transport_send_pkt, +}; +static void vhost_vsock_handle_tx_kick (struct vhost_work *work) { struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
@@ -438,7 +484,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)/* Only accept correctly addressed packets */ if (le64_to_cpu (pkt->hdr.src_cid) == vsock->guest_cid) -virtio_transport_recv_pkt (pkt); +virtio_transport_recv_pkt (&vhost_transport, pkt);else virtio_transport_free_pkt (pkt);
@@ -786,52 +832,6 @@ static struct miscdevice vhost_vsock_misc = { .fops = &vhost_vsock_fops, }; -static struct virtio_transport vhost_transport = { - .transport = { - .get_local_cid = vhost_transport_get_local_cid, - - .init = virtio_transport_do_socket_init, - .destruct = virtio_transport_destruct, - .release = virtio_transport_release, - .connect = virtio_transport_connect, - .shutdown = virtio_transport_shutdown, - .cancel_pkt = vhost_transport_cancel_pkt, - - .dgram_enqueue = virtio_transport_dgram_enqueue, - .dgram_dequeue = virtio_transport_dgram_dequeue, - .dgram_bind = virtio_transport_dgram_bind, - .dgram_allow = virtio_transport_dgram_allow, - - .stream_enqueue = virtio_transport_stream_enqueue, - .stream_dequeue = virtio_transport_stream_dequeue, - .stream_has_data = virtio_transport_stream_has_data, - .stream_has_space = virtio_transport_stream_has_space, - .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, - .stream_is_active = virtio_transport_stream_is_active, - .stream_allow = virtio_transport_stream_allow, - - .notify_poll_in = virtio_transport_notify_poll_in, - .notify_poll_out = virtio_transport_notify_poll_out, - .notify_recv_init = virtio_transport_notify_recv_init, - .notify_recv_pre_block = virtio_transport_notify_recv_pre_block, - .notify_recv_pre_dequeue = virtio_transport_notify_recv_pre_dequeue, - .notify_recv_post_dequeue = virtio_transport_notify_recv_post_dequeue, - .notify_send_init = virtio_transport_notify_send_init, - .notify_send_pre_block = virtio_transport_notify_send_pre_block, - .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, - .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, - - .set_buffer_size = virtio_transport_set_buffer_size, - .set_min_buffer_size = virtio_transport_set_min_buffer_size, - .set_max_buffer_size = virtio_transport_set_max_buffer_size, - .get_buffer_size = virtio_transport_get_buffer_size, - .get_min_buffer_size = virtio_transport_get_min_buffer_size, - .get_max_buffer_size = virtio_transport_get_max_buffer_size, - }, - - .send_pkt = vhost_transport_send_pkt, -}; -static int __init vhost_vsock_init (void ) {int ret;
include/linux/virtio_vsock.h +2 -1
@@ -150,7 +150,8 @@ virtio_transport_dgram_enqueue(struct vsock_sock *vsk,void virtio_transport_destruct (struct vsock_sock *vsk); -void virtio_transport_recv_pkt (struct virtio_vsock_pkt *pkt); +void virtio_transport_recv_pkt (struct virtio_transport *t, +struct virtio_vsock_pkt *pkt);void virtio_transport_free_pkt (struct virtio_vsock_pkt *pkt);void virtio_transport_inc_tx_pkt (struct virtio_vsock_sock *vvs,struct virtio_vsock_pkt *pkt);u32 virtio_transport_get_credit (struct virtio_vsock_sock *vvs,u32 wanted);
net/vmw_vsock/virtio_transport.c +80 -80
178 lines not on this page · raw message
net/vmw_vsock/virtio_transport_common.c +6 -6
@@ -745,9 +745,9 @@ static int virtio_transport_reset(struct vsock_sock *vsk,/* Normally packets are associated with a socket. There may be no socket if an * attempt was made to connect to a socket that does not exist. */ -static int virtio_transport_reset_no_sock (struct virtio_vsock_pkt *pkt) +static int virtio_transport_reset_no_sock (const struct virtio_transport *t, +struct virtio_vsock_pkt *pkt) { -const struct virtio_transport *t;struct virtio_vsock_pkt *reply;struct virtio_vsock_pkt_info info = { .op =VIRTIO_VSOCK_OP_RST ,
@@ -767,7 +767,6 @@ static int virtio_transport_reset_no_sock(struct virtio_vsock_pkt *pkt)if (!reply)return -ENOMEM ; - t =virtio_transport_get_ops ();if (!t) {virtio_transport_free_pkt (reply);return -ENOTCONN ;
@@ -1109,7 +1108,8 @@ static bool virtio_transport_space_update(struct sock *sk,/* We are under the virtio-vsock's vsock->rx_lock or vhost-vsock's vq->mutex * lock. */ -void virtio_transport_recv_pkt (struct virtio_vsock_pkt *pkt) +void virtio_transport_recv_pkt (struct virtio_transport *t, +struct virtio_vsock_pkt *pkt) {struct sockaddr_vm src, dst;struct vsock_sock *vsk;
@@ -1131,7 +1131,7 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt) le32_to_cpu(pkt->hdr.fwd_cnt));if (le16_to_cpu (pkt->hdr.type) !=VIRTIO_VSOCK_TYPE_STREAM ) { - (void )virtio_transport_reset_no_sock (pkt); + (void )virtio_transport_reset_no_sock (t, pkt); goto free_pkt; }
@@ -1142,7 +1142,7 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)if (!sk) { sk =vsock_find_bound_socket (&dst);if (!sk) { - (void )virtio_transport_reset_no_sock (pkt); + (void )virtio_transport_reset_no_sock (t, pkt); goto free_pkt; } }
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 6/15 vsock: add 'struct vsock_sock *' param to vsock_core_get_transport()
In reply to Stefano GarzarellaSince now the 'struct vsock_sock' object contains a pointer to the transport, this patch adds a parameter to the vsock_core_get_transport() to return the right transport assigned to the socket.
This patch modifies also the virtio_transport_get_ops(), that uses the vsock_core_get_transport(), adding the 'struct vsock_sock *' parameter.
--- include/net/af_vsock.h | 2 +- net/vmw_vsock/af_vsock.c | 7 ++----- net/vmw_vsock/virtio_transport_common.c | 9 +++++---- 3 files changed, 8 insertions(+), 10 deletions(-)
include/net/af_vsock.h +1 -1
@@ -166,7 +166,7 @@ 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 ); +const struct vsock_transport *vsock_core_get_transport (struct vsock_sock *vsk);/**** UTILS ****/
net/vmw_vsock/af_vsock.c +2 -5
@@ -1999,12 +1999,9 @@ void vsock_core_exit(void) }EXPORT_SYMBOL_GPL (vsock_core_exit); -const struct vsock_transport *vsock_core_get_transport (void ) +const struct vsock_transport *vsock_core_get_transport (struct vsock_sock *vsk) { -/* vsock_register_mutex not taken since only the transport uses this -* function and only while registered. -*/ -return transport_single; +return vsk->transport; }EXPORT_SYMBOL_GPL (vsock_core_get_transport);
net/vmw_vsock/virtio_transport_common.c +5 -4
@@ -29,9 +29,10 @@/* Threshold for detecting small packets to copy */ #define GOOD_COPY_LEN 128 -static const struct virtio_transport *virtio_transport_get_ops (void ) +static const struct virtio_transport * +virtio_transport_get_ops (struct vsock_sock *vsk) { -const struct vsock_transport *t =vsock_core_get_transport (); +const struct vsock_transport *t =vsock_core_get_transport (vsk); return container_of(t, struct virtio_transport, transport); }
@@ -168,7 +169,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,struct virtio_vsock_pkt *pkt;u32 pkt_len = info->pkt_len; - src_cid =virtio_transport_get_ops ()->transport.get_local_cid (); + src_cid =virtio_transport_get_ops (vsk)->transport.get_local_cid (); src_port = vsk->local_addr.svm_port;if (!info->remote_cid) { dst_cid = vsk->remote_addr.svm_cid;
@@ -201,7 +202,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,virtio_transport_inc_tx_pkt (vvs, pkt); -return virtio_transport_get_ops ()->send_pkt (pkt); +return virtio_transport_get_ops (vsk)->send_pkt (pkt); } static bool virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs,
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 6/15 vsock: add 'struct vsock_sock *' param to vsock_core_get_transport()
In reply to Stefano GarzarellaSince now the 'struct vsock_sock' object contains a pointer to the transport, this patch adds a parameter to the vsock_core_get_transport() to return the right transport assigned to the socket.
This patch modifies also the virtio_transport_get_ops(), that uses the vsock_core_get_transport(), adding the 'struct vsock_sock *' parameter.
--- include/net/af_vsock.h | 2 +- net/vmw_vsock/af_vsock.c | 7 ++----- net/vmw_vsock/virtio_transport_common.c | 9 +++++---- 3 files changed, 8 insertions(+), 10 deletions(-)
include/net/af_vsock.h +1 -1
@@ -166,7 +166,7 @@ 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 ); +const struct vsock_transport *vsock_core_get_transport (struct vsock_sock *vsk);/**** UTILS ****/
net/vmw_vsock/af_vsock.c +2 -5
@@ -1999,12 +1999,9 @@ void vsock_core_exit(void) }EXPORT_SYMBOL_GPL (vsock_core_exit); -const struct vsock_transport *vsock_core_get_transport (void ) +const struct vsock_transport *vsock_core_get_transport (struct vsock_sock *vsk) { -/* vsock_register_mutex not taken since only the transport uses this -* function and only while registered. -*/ -return transport_single; +return vsk->transport; }EXPORT_SYMBOL_GPL (vsock_core_get_transport);
net/vmw_vsock/virtio_transport_common.c +5 -4
@@ -29,9 +29,10 @@/* Threshold for detecting small packets to copy */ #define GOOD_COPY_LEN 128 -static const struct virtio_transport *virtio_transport_get_ops (void ) +static const struct virtio_transport * +virtio_transport_get_ops (struct vsock_sock *vsk) { -const struct vsock_transport *t =vsock_core_get_transport (); +const struct vsock_transport *t =vsock_core_get_transport (vsk); return container_of(t, struct virtio_transport, transport); }
@@ -168,7 +169,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,struct virtio_vsock_pkt *pkt;u32 pkt_len = info->pkt_len; - src_cid =virtio_transport_get_ops ()->transport.get_local_cid (); + src_cid =virtio_transport_get_ops (vsk)->transport.get_local_cid (); src_port = vsk->local_addr.svm_port;if (!info->remote_cid) { dst_cid = vsk->remote_addr.svm_cid;
@@ -201,7 +202,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,virtio_transport_inc_tx_pkt (vvs, pkt); -return virtio_transport_get_ops ()->send_pkt (pkt); +return virtio_transport_get_ops (vsk)->send_pkt (pkt); } static bool virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs,
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 7/15 vsock: handle buffer_size sockopts in the core
In reply to Stefano Garzarellavirtio_transport and vmci_transport handle the buffer_size sockopts in a very similar way.
In order to support multiple transports, this patch moves this handling in the core to allow the user to change the options also if the socket is not yet assigned to any transport.
This patch also adds the '.notify_buffer_size' callback in the 'struct virtio_transport' in order to inform the transport, when the buffer_size is changed by the user. It is also useful to limit the 'buffer_size' requested (e.g. virtio transports).
--- drivers/vhost/vsock.c | 7 +- include/linux/virtio_vsock.h | 15 +---- include/net/af_vsock.h | 15 ++--- net/vmw_vsock/af_vsock.c | 43 ++++++++++--- net/vmw_vsock/hyperv_transport.c | 36 ----------- net/vmw_vsock/virtio_transport.c | 8 +-- net/vmw_vsock/virtio_transport_common.c | 79 ++++------------------- net/vmw_vsock/vmci_transport.c | 86 +++---------------------- net/vmw_vsock/vmci_transport.h | 3 - 9 files changed, 65 insertions(+), 227 deletions(-)
drivers/vhost/vsock.c +1 -6
@@ -418,13 +418,8 @@ static struct virtio_transport vhost_transport = { .notify_send_pre_block = virtio_transport_notify_send_pre_block, .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, + .notify_buffer_size = virtio_transport_notify_buffer_size, - .set_buffer_size = virtio_transport_set_buffer_size, - .set_min_buffer_size = virtio_transport_set_min_buffer_size, - .set_max_buffer_size = virtio_transport_set_max_buffer_size, - .get_buffer_size = virtio_transport_get_buffer_size, - .get_min_buffer_size = virtio_transport_get_min_buffer_size, - .get_max_buffer_size = virtio_transport_get_max_buffer_size, }, .send_pkt = vhost_transport_send_pkt,
include/linux/virtio_vsock.h +1 -14
@@ -7,9 +7,6 @@#include <net/sock.h> #include <net/af_vsock.h> -#define VIRTIO_VSOCK_DEFAULT_MIN_BUF_SIZE 128 -#define VIRTIO_VSOCK_DEFAULT_BUF_SIZE (1024 * 256) -#define VIRTIO_VSOCK_DEFAULT_MAX_BUF_SIZE (1024 * 256)#define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE (1024 * 4)#define VIRTIO_VSOCK_MAX_BUF_SIZE 0xFFFFFFFFUL#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64)
@@ -25,11 +22,6 @@ enum {struct virtio_vsock_sock {struct vsock_sock *vsk; -/* Protected by lock_sock(sk_vsock(trans->vsk)) */ -u32 buf_size; -u32 buf_size_min; -u32 buf_size_max; -spinlock_t tx_lock;spinlock_t rx_lock;
@@ -92,12 +84,6 @@ s64 virtio_transport_stream_has_space(struct vsock_sock *vsk);int virtio_transport_do_socket_init (struct vsock_sock *vsk,struct vsock_sock *psk); -u64 virtio_transport_get_buffer_size (struct vsock_sock *vsk); -u64 virtio_transport_get_min_buffer_size (struct vsock_sock *vsk); -u64 virtio_transport_get_max_buffer_size (struct vsock_sock *vsk); -void virtio_transport_set_buffer_size (struct vsock_sock *vsk,u64 val); -void virtio_transport_set_min_buffer_size (struct vsock_sock *vsk,u64 val); -void virtio_transport_set_max_buffer_size (struct vsock_sock *vs,u64 val); int virtio_transport_notify_poll_in(struct vsock_sock *vsk, size_t target,
@@ -124,6 +110,7 @@ int virtio_transport_notify_send_pre_enqueue(struct vsock_sock *vsk, struct vsock_transport_send_notify_data *data);int virtio_transport_notify_send_post_enqueue (struct vsock_sock *vsk,ssize_t written,struct vsock_transport_send_notify_data *data); +void virtio_transport_notify_buffer_size (struct vsock_sock *vsk,u64 *val);u64 virtio_transport_stream_rcvhiwat (struct vsock_sock *vsk);bool virtio_transport_stream_is_active (struct vsock_sock *vsk);
include/net/af_vsock.h +7 -8
@@ -65,6 +65,11 @@ struct vsock_sock {bool sent_request;bool ignore_connecting_rst; +/* Protected by lock_sock(sk) */ +u64 buffer_size; +u64 buffer_min_size; +u64 buffer_max_size; +/* Private to transport. */ void *trans; };
@@ -140,18 +145,12 @@ struct vsock_transport { struct vsock_transport_send_notify_data *); int (*notify_send_post_enqueue)(struct vsock_sock *, ssize_t,struct vsock_transport_send_notify_data *); +/* sk_lock held by the caller */ +void (*notify_buffer_size)(struct vsock_sock *,u64 *);/* Shutdown. */ int (*shutdown)(struct vsock_sock *,int ); -/* Buffer sizes. */ -void (*set_buffer_size)(struct vsock_sock *,u64 ); -void (*set_min_buffer_size)(struct vsock_sock *,u64 ); -void (*set_max_buffer_size)(struct vsock_sock *,u64 ); -u64 (*get_buffer_size)(struct vsock_sock *); -u64 (*get_min_buffer_size)(struct vsock_sock *); -u64 (*get_max_buffer_size)(struct vsock_sock *); -/* Addressing. */ u32 (*get_local_cid)(void); };
net/vmw_vsock/af_vsock.c +35 -8
102 lines not on this page · raw message
net/vmw_vsock/hyperv_transport.c +0 -36
@@ -845,36 +845,6 @@ int hvs_notify_send_post_enqueue(struct vsock_sock *vsk, ssize_t written,return 0 ; } -static void hvs_set_buffer_size (struct vsock_sock *vsk,u64 val) -{ -/* Ignored. */ -} - -static void hvs_set_min_buffer_size (struct vsock_sock *vsk,u64 val) -{ -/* Ignored. */ -} - -static void hvs_set_max_buffer_size (struct vsock_sock *vsk,u64 val) -{ -/* Ignored. */ -} - -static u64 hvs_get_buffer_size (struct vsock_sock *vsk) -{ -return -ENOPROTOOPT ; -} - -static u64 hvs_get_min_buffer_size (struct vsock_sock *vsk) -{ -return -ENOPROTOOPT ; -} - -static u64 hvs_get_max_buffer_size (struct vsock_sock *vsk) -{ -return -ENOPROTOOPT ; -} -static struct vsock_transport hvs_transport = { .get_local_cid = hvs_get_local_cid,
@@ -908,12 +878,6 @@ static struct vsock_transport hvs_transport = { .notify_send_pre_enqueue = hvs_notify_send_pre_enqueue, .notify_send_post_enqueue = hvs_notify_send_post_enqueue, - .set_buffer_size = hvs_set_buffer_size, - .set_min_buffer_size = hvs_set_min_buffer_size, - .set_max_buffer_size = hvs_set_max_buffer_size, - .get_buffer_size = hvs_get_buffer_size, - .get_min_buffer_size = hvs_get_min_buffer_size, - .get_max_buffer_size = hvs_get_max_buffer_size, }; static int hvs_probe(struct hv_device *hdev,
net/vmw_vsock/virtio_transport.c +1 -7
@@ -494,13 +494,7 @@ static struct virtio_transport virtio_transport = { .notify_send_pre_block = virtio_transport_notify_send_pre_block, .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, - - .set_buffer_size = virtio_transport_set_buffer_size, - .set_min_buffer_size = virtio_transport_set_min_buffer_size, - .set_max_buffer_size = virtio_transport_set_max_buffer_size, - .get_buffer_size = virtio_transport_get_buffer_size, - .get_min_buffer_size = virtio_transport_get_min_buffer_size, - .get_max_buffer_size = virtio_transport_get_max_buffer_size, + .notify_buffer_size = virtio_transport_notify_buffer_size, }, .send_pkt = virtio_transport_send_pkt,
net/vmw_vsock/virtio_transport_common.c +11 -68
108 lines not on this page · raw message
net/vmw_vsock/vmci_transport.c +9 -77
148 lines not on this page · raw message
net/vmw_vsock/vmci_transport.h +0 -3
@@ -108,9 +108,6 @@ struct vmci_transport {struct vmci_qp *qpair;u64 produce_size;u64 consume_size; -u64 queue_pair_size; -u64 queue_pair_min_size; -u64 queue_pair_max_size;u32 detach_sub_id;union vmci_transport_notify notify;const struct vmci_transport_notify_ops *notify_ops;
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 7/15 vsock: handle buffer_size sockopts in the core
In reply to Stefano Garzarellavirtio_transport and vmci_transport handle the buffer_size sockopts in a very similar way.
In order to support multiple transports, this patch moves this handling in the core to allow the user to change the options also if the socket is not yet assigned to any transport.
This patch also adds the '.notify_buffer_size' callback in the 'struct virtio_transport' in order to inform the transport, when the buffer_size is changed by the user. It is also useful to limit the 'buffer_size' requested (e.g. virtio transports).
--- drivers/vhost/vsock.c | 7 +- include/linux/virtio_vsock.h | 15 +---- include/net/af_vsock.h | 15 ++--- net/vmw_vsock/af_vsock.c | 43 ++++++++++--- net/vmw_vsock/hyperv_transport.c | 36 ----------- net/vmw_vsock/virtio_transport.c | 8 +-- net/vmw_vsock/virtio_transport_common.c | 79 ++++------------------- net/vmw_vsock/vmci_transport.c | 86 +++---------------------- net/vmw_vsock/vmci_transport.h | 3 - 9 files changed, 65 insertions(+), 227 deletions(-)
drivers/vhost/vsock.c +1 -6
@@ -418,13 +418,8 @@ static struct virtio_transport vhost_transport = { .notify_send_pre_block = virtio_transport_notify_send_pre_block, .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, + .notify_buffer_size = virtio_transport_notify_buffer_size, - .set_buffer_size = virtio_transport_set_buffer_size, - .set_min_buffer_size = virtio_transport_set_min_buffer_size, - .set_max_buffer_size = virtio_transport_set_max_buffer_size, - .get_buffer_size = virtio_transport_get_buffer_size, - .get_min_buffer_size = virtio_transport_get_min_buffer_size, - .get_max_buffer_size = virtio_transport_get_max_buffer_size, }, .send_pkt = vhost_transport_send_pkt,
include/linux/virtio_vsock.h +1 -14
@@ -7,9 +7,6 @@#include <net/sock.h> #include <net/af_vsock.h> -#define VIRTIO_VSOCK_DEFAULT_MIN_BUF_SIZE 128 -#define VIRTIO_VSOCK_DEFAULT_BUF_SIZE (1024 * 256) -#define VIRTIO_VSOCK_DEFAULT_MAX_BUF_SIZE (1024 * 256)#define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE (1024 * 4)#define VIRTIO_VSOCK_MAX_BUF_SIZE 0xFFFFFFFFUL#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE (1024 * 64)
@@ -25,11 +22,6 @@ enum {struct virtio_vsock_sock {struct vsock_sock *vsk; -/* Protected by lock_sock(sk_vsock(trans->vsk)) */ -u32 buf_size; -u32 buf_size_min; -u32 buf_size_max; -spinlock_t tx_lock;spinlock_t rx_lock;
@@ -92,12 +84,6 @@ s64 virtio_transport_stream_has_space(struct vsock_sock *vsk);int virtio_transport_do_socket_init (struct vsock_sock *vsk,struct vsock_sock *psk); -u64 virtio_transport_get_buffer_size (struct vsock_sock *vsk); -u64 virtio_transport_get_min_buffer_size (struct vsock_sock *vsk); -u64 virtio_transport_get_max_buffer_size (struct vsock_sock *vsk); -void virtio_transport_set_buffer_size (struct vsock_sock *vsk,u64 val); -void virtio_transport_set_min_buffer_size (struct vsock_sock *vsk,u64 val); -void virtio_transport_set_max_buffer_size (struct vsock_sock *vs,u64 val); int virtio_transport_notify_poll_in(struct vsock_sock *vsk, size_t target,
@@ -124,6 +110,7 @@ int virtio_transport_notify_send_pre_enqueue(struct vsock_sock *vsk, struct vsock_transport_send_notify_data *data);int virtio_transport_notify_send_post_enqueue (struct vsock_sock *vsk,ssize_t written,struct vsock_transport_send_notify_data *data); +void virtio_transport_notify_buffer_size (struct vsock_sock *vsk,u64 *val);u64 virtio_transport_stream_rcvhiwat (struct vsock_sock *vsk);bool virtio_transport_stream_is_active (struct vsock_sock *vsk);
include/net/af_vsock.h +7 -8
@@ -65,6 +65,11 @@ struct vsock_sock {bool sent_request;bool ignore_connecting_rst; +/* Protected by lock_sock(sk) */ +u64 buffer_size; +u64 buffer_min_size; +u64 buffer_max_size; +/* Private to transport. */ void *trans; };
@@ -140,18 +145,12 @@ struct vsock_transport { struct vsock_transport_send_notify_data *); int (*notify_send_post_enqueue)(struct vsock_sock *, ssize_t,struct vsock_transport_send_notify_data *); +/* sk_lock held by the caller */ +void (*notify_buffer_size)(struct vsock_sock *,u64 *);/* Shutdown. */ int (*shutdown)(struct vsock_sock *,int ); -/* Buffer sizes. */ -void (*set_buffer_size)(struct vsock_sock *,u64 ); -void (*set_min_buffer_size)(struct vsock_sock *,u64 ); -void (*set_max_buffer_size)(struct vsock_sock *,u64 ); -u64 (*get_buffer_size)(struct vsock_sock *); -u64 (*get_min_buffer_size)(struct vsock_sock *); -u64 (*get_max_buffer_size)(struct vsock_sock *); -/* Addressing. */ u32 (*get_local_cid)(void); };
net/vmw_vsock/af_vsock.c +35 -8
102 lines not on this page · raw message
net/vmw_vsock/hyperv_transport.c +0 -36
@@ -845,36 +845,6 @@ int hvs_notify_send_post_enqueue(struct vsock_sock *vsk, ssize_t written,return 0 ; } -static void hvs_set_buffer_size (struct vsock_sock *vsk,u64 val) -{ -/* Ignored. */ -} - -static void hvs_set_min_buffer_size (struct vsock_sock *vsk,u64 val) -{ -/* Ignored. */ -} - -static void hvs_set_max_buffer_size (struct vsock_sock *vsk,u64 val) -{ -/* Ignored. */ -} - -static u64 hvs_get_buffer_size (struct vsock_sock *vsk) -{ -return -ENOPROTOOPT ; -} - -static u64 hvs_get_min_buffer_size (struct vsock_sock *vsk) -{ -return -ENOPROTOOPT ; -} - -static u64 hvs_get_max_buffer_size (struct vsock_sock *vsk) -{ -return -ENOPROTOOPT ; -} -static struct vsock_transport hvs_transport = { .get_local_cid = hvs_get_local_cid,
@@ -908,12 +878,6 @@ static struct vsock_transport hvs_transport = { .notify_send_pre_enqueue = hvs_notify_send_pre_enqueue, .notify_send_post_enqueue = hvs_notify_send_post_enqueue, - .set_buffer_size = hvs_set_buffer_size, - .set_min_buffer_size = hvs_set_min_buffer_size, - .set_max_buffer_size = hvs_set_max_buffer_size, - .get_buffer_size = hvs_get_buffer_size, - .get_min_buffer_size = hvs_get_min_buffer_size, - .get_max_buffer_size = hvs_get_max_buffer_size, }; static int hvs_probe(struct hv_device *hdev,
net/vmw_vsock/virtio_transport.c +1 -7
@@ -494,13 +494,7 @@ static struct virtio_transport virtio_transport = { .notify_send_pre_block = virtio_transport_notify_send_pre_block, .notify_send_pre_enqueue = virtio_transport_notify_send_pre_enqueue, .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue, - - .set_buffer_size = virtio_transport_set_buffer_size, - .set_min_buffer_size = virtio_transport_set_min_buffer_size, - .set_max_buffer_size = virtio_transport_set_max_buffer_size, - .get_buffer_size = virtio_transport_get_buffer_size, - .get_min_buffer_size = virtio_transport_get_min_buffer_size, - .get_max_buffer_size = virtio_transport_get_max_buffer_size, + .notify_buffer_size = virtio_transport_notify_buffer_size, }, .send_pkt = virtio_transport_send_pkt,
net/vmw_vsock/virtio_transport_common.c +11 -68
108 lines not on this page · raw message
net/vmw_vsock/vmci_transport.c +9 -77
148 lines not on this page · raw message
net/vmw_vsock/vmci_transport.h +0 -3
@@ -108,9 +108,6 @@ struct vmci_transport {struct vmci_qp *qpair;u64 produce_size;u64 consume_size; -u64 queue_pair_size; -u64 queue_pair_min_size; -u64 queue_pair_max_size;u32 detach_sub_id;union vmci_transport_notify notify;const struct vmci_transport_notify_ops *notify_ops;
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 8/15 vsock: add vsock_create_connected() called by transports
In reply to Stefano GarzarellaAll transports call __vsock_create() with the same parameters, most of them depending on the parent socket. In order to simplify the VSOCK core APIs exposed to the transports, this patch adds the vsock_create_connected() callable from transports to create a new socket when a connection request is received.
We also unexported the __vsock_create().
--- include/net/af_vsock.h | 5 +---- net/vmw_vsock/af_vsock.c | 20 +++++++++++++------- net/vmw_vsock/hyperv_transport.c | 3 +-- net/vmw_vsock/virtio_transport_common.c | 3 +-- net/vmw_vsock/vmci_transport.c | 3 +-- 5 files changed, 17 insertions(+), 17 deletions(-)
include/net/af_vsock.h +1 -4
@@ -76,10 +76,7 @@ struct vsock_sock {s64 vsock_stream_has_data (struct vsock_sock *vsk);s64 vsock_stream_has_space (struct vsock_sock *vsk); -struct sock *__vsock_create (struct net *net, -struct socket *sock, -struct sock *parent, -gfp_t priority,unsigned short type,int kern); +struct sock *vsock_create_connected (struct sock *parent);/**** TRANSPORT ****/
net/vmw_vsock/af_vsock.c +13 -7
@@ -567,12 +567,12 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr)static void vsock_connect_timeout (struct work_struct *work); -struct sock *__vsock_create (struct net *net, -struct socket *sock, -struct sock *parent, -gfp_t priority, -unsigned short type, -int kern) +static struct sock *__vsock_create (struct net *net, +struct socket *sock, +struct sock *parent, +gfp_t priority, +unsigned short type, +int kern) {struct sock *sk;struct vsock_sock *psk;
@@ -639,7 +639,6 @@ struct sock *__vsock_create(struct net *net,return sk; } -EXPORT_SYMBOL_GPL (__vsock_create);static void __vsock_release (struct sock *sk,int level) {
@@ -703,6 +702,13 @@ static int vsock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)return err; } +struct sock *vsock_create_connected (struct sock *parent) +{ +return __vsock_create (sock_net (parent),NULL , parent,GFP_KERNEL , + parent->sk_type,0 ); +} +EXPORT_SYMBOL_GPL (vsock_create_connected); +s64 vsock_stream_has_data (struct vsock_sock *vsk) {return vsk->transport->stream_has_data (vsk);
net/vmw_vsock/hyperv_transport.c +1 -2
@@ -360,8 +360,7 @@ static void hvs_open_connection(struct vmbus_channel *chan)if (sk->sk_ack_backlog >= sk->sk_max_ack_backlog) goto out; - new =__vsock_create (sock_net (sk),NULL , sk,GFP_KERNEL , - sk->sk_type,0 ); + new =vsock_create_connected (sk);if (!new) goto out;
net/vmw_vsock/virtio_transport_common.c +1 -2
@@ -1004,8 +1004,7 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)return -ENOMEM ; } - child =__vsock_create (sock_net (sk),NULL , sk,GFP_KERNEL , - sk->sk_type,0 ); + child =vsock_create_connected (sk);if (!child) {virtio_transport_reset (vsk, pkt);return -ENOMEM ;
net/vmw_vsock/vmci_transport.c +1 -2
@@ -1004,8 +1004,7 @@ static int vmci_transport_recv_listen(struct sock *sk,return -ECONNREFUSED ; } - pending =__vsock_create (sock_net (sk),NULL , sk,GFP_KERNEL , - sk->sk_type,0 ); + pending =vsock_create_connected (sk);if (!pending) {vmci_transport_send_reset (sk, pkt);return -ENOMEM ;
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 8/15 vsock: add vsock_create_connected() called by transports
In reply to Stefano GarzarellaAll transports call __vsock_create() with the same parameters, most of them depending on the parent socket. In order to simplify the VSOCK core APIs exposed to the transports, this patch adds the vsock_create_connected() callable from transports to create a new socket when a connection request is received.
We also unexported the __vsock_create().
--- include/net/af_vsock.h | 5 +---- net/vmw_vsock/af_vsock.c | 20 +++++++++++++------- net/vmw_vsock/hyperv_transport.c | 3 +-- net/vmw_vsock/virtio_transport_common.c | 3 +-- net/vmw_vsock/vmci_transport.c | 3 +-- 5 files changed, 17 insertions(+), 17 deletions(-)
include/net/af_vsock.h +1 -4
@@ -76,10 +76,7 @@ struct vsock_sock {s64 vsock_stream_has_data (struct vsock_sock *vsk);s64 vsock_stream_has_space (struct vsock_sock *vsk); -struct sock *__vsock_create (struct net *net, -struct socket *sock, -struct sock *parent, -gfp_t priority,unsigned short type,int kern); +struct sock *vsock_create_connected (struct sock *parent);/**** TRANSPORT ****/
net/vmw_vsock/af_vsock.c +13 -7
@@ -567,12 +567,12 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr)static void vsock_connect_timeout (struct work_struct *work); -struct sock *__vsock_create (struct net *net, -struct socket *sock, -struct sock *parent, -gfp_t priority, -unsigned short type, -int kern) +static struct sock *__vsock_create (struct net *net, +struct socket *sock, +struct sock *parent, +gfp_t priority, +unsigned short type, +int kern) {struct sock *sk;struct vsock_sock *psk;
@@ -639,7 +639,6 @@ struct sock *__vsock_create(struct net *net,return sk; } -EXPORT_SYMBOL_GPL (__vsock_create);static void __vsock_release (struct sock *sk,int level) {
@@ -703,6 +702,13 @@ static int vsock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)return err; } +struct sock *vsock_create_connected (struct sock *parent) +{ +return __vsock_create (sock_net (parent),NULL , parent,GFP_KERNEL , + parent->sk_type,0 ); +} +EXPORT_SYMBOL_GPL (vsock_create_connected); +s64 vsock_stream_has_data (struct vsock_sock *vsk) {return vsk->transport->stream_has_data (vsk);
net/vmw_vsock/hyperv_transport.c +1 -2
@@ -360,8 +360,7 @@ static void hvs_open_connection(struct vmbus_channel *chan)if (sk->sk_ack_backlog >= sk->sk_max_ack_backlog) goto out; - new =__vsock_create (sock_net (sk),NULL , sk,GFP_KERNEL , - sk->sk_type,0 ); + new =vsock_create_connected (sk);if (!new) goto out;
net/vmw_vsock/virtio_transport_common.c +1 -2
@@ -1004,8 +1004,7 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)return -ENOMEM ; } - child =__vsock_create (sock_net (sk),NULL , sk,GFP_KERNEL , - sk->sk_type,0 ); + child =vsock_create_connected (sk);if (!child) {virtio_transport_reset (vsk, pkt);return -ENOMEM ;
net/vmw_vsock/vmci_transport.c +1 -2
@@ -1004,8 +1004,7 @@ static int vmci_transport_recv_listen(struct sock *sk,return -ECONNREFUSED ; } - pending =__vsock_create (sock_net (sk),NULL , sk,GFP_KERNEL , - sk->sk_type,0 ); + pending =vsock_create_connected (sk);if (!pending) {vmci_transport_send_reset (sk, pkt);return -ENOMEM ;
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 9/15 vsock: move vsock_insert_unbound() in the vsock_create()
In reply to Stefano Garzarellavsock_insert_unbound() was called only when 'sock' parameter of __vsock_create() was not null. This only happened when __vsock_create() was called by vsock_create().
In order to simplify the multi-transports support, this patch moves vsock_insert_unbound() at the end of vsock_create().
--- net/vmw_vsock/af_vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/vmw_vsock/af_vsock.c +9 -4
@@ -634,9 +634,6 @@ static struct sock *__vsock_create(struct net *net,return NULL ; } -if (sock) -vsock_insert_unbound (vsk); -return sk; }
@@ -1887,6 +1884,8 @@ static const struct proto_ops vsock_stream_ops = {static int vsock_create (struct net *net,struct socket *sock,int protocol,int kern) { +struct sock *sk; +if (!sock)return -EINVAL ;
@@ -1906,7 +1905,13 @@ static int vsock_create(struct net *net, struct socket *sock, sock->state =SS_UNCONNECTED ; -return __vsock_create (net, sock,NULL ,GFP_KERNEL ,0 , kern) ?0 : -ENOMEM ; + sk =__vsock_create (net, sock,NULL ,GFP_KERNEL ,0 , kern); +if (!sk) +return -ENOMEM ; + +vsock_insert_unbound (vsock_sk (sk)); + +return 0 ; }static const struct net_proto_family vsock_family_ops = {
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 9/15 vsock: move vsock_insert_unbound() in the vsock_create()
In reply to Stefano Garzarellavsock_insert_unbound() was called only when 'sock' parameter of __vsock_create() was not null. This only happened when __vsock_create() was called by vsock_create().
In order to simplify the multi-transports support, this patch moves vsock_insert_unbound() at the end of vsock_create().
--- net/vmw_vsock/af_vsock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/vmw_vsock/af_vsock.c +9 -4
@@ -634,9 +634,6 @@ static struct sock *__vsock_create(struct net *net,return NULL ; } -if (sock) -vsock_insert_unbound (vsk); -return sk; }
@@ -1887,6 +1884,8 @@ static const struct proto_ops vsock_stream_ops = {static int vsock_create (struct net *net,struct socket *sock,int protocol,int kern) { +struct sock *sk; +if (!sock)return -EINVAL ;
@@ -1906,7 +1905,13 @@ static int vsock_create(struct net *net, struct socket *sock, sock->state =SS_UNCONNECTED ; -return __vsock_create (net, sock,NULL ,GFP_KERNEL ,0 , kern) ?0 : -ENOMEM ; + sk =__vsock_create (net, sock,NULL ,GFP_KERNEL ,0 , kern); +if (!sk) +return -ENOMEM ; + +vsock_insert_unbound (vsock_sk (sk)); + +return 0 ; }static const struct net_proto_family vsock_family_ops = {
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 10/15 hv_sock: set VMADDR_CID_HOST in the hvs_remote_addr_init()
In reply to Stefano GarzarellaRemote peer is always the host, so we set VMADDR_CID_HOST as remote CID instead of VMADDR_CID_ANY.
--- net/vmw_vsock/hyperv_transport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/hyperv_transport.c +2 -1
@@ -188,7 +188,8 @@ static void hvs_remote_addr_init(struct sockaddr_vm *remote,static u32 host_ephemeral_port =MIN_HOST_EPHEMERAL_PORT ;struct sock *sk; -vsock_addr_init (remote,VMADDR_CID_ANY ,VMADDR_PORT_ANY ); +/* Remote peer is always the host */ +vsock_addr_init (remote,VMADDR_CID_HOST ,VMADDR_PORT_ANY );while (1 ) {/* Wrap around ? */
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 10/15 hv_sock: set VMADDR_CID_HOST in the hvs_remote_addr_init()
In reply to Stefano GarzarellaRemote peer is always the host, so we set VMADDR_CID_HOST as remote CID instead of VMADDR_CID_ANY.
--- net/vmw_vsock/hyperv_transport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/hyperv_transport.c +2 -1
@@ -188,7 +188,8 @@ static void hvs_remote_addr_init(struct sockaddr_vm *remote,static u32 host_ephemeral_port =MIN_HOST_EPHEMERAL_PORT ;struct sock *sk; -vsock_addr_init (remote,VMADDR_CID_ANY ,VMADDR_PORT_ANY ); +/* Remote peer is always the host */ +vsock_addr_init (remote,VMADDR_CID_HOST ,VMADDR_PORT_ANY );while (1 ) {/* Wrap around ? */
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 11/15 vsock: add multi-transports support
In reply to Stefano GarzarellaThis patch adds the support of multiple transports in the VSOCK core.
With the multi-transports support, we can use vsock with nested VMs (using also different hypervisors) loading both guest->host and host->guest transports at the same time.
Major changes:
- vsock core module can be loaded regardless of the transports
- vsock_core_init() and vsock_core_exit() are renamed to vsock_core_register() and vsock_core_unregister()
- vsock_core_register() has a feature parameter (H2G, G2H, DGRAM) to identify which directions the transport can handle and if it's support DGRAM (only vmci)
- each stream socket is assigned to a transport when the remote CID is set (during the connect() or when we receive a connection request on a listener socket).
The remote CID is used to decide which transport to use:
- remote CID <= VMADDR_CID_HOST will use guest->host transport;
- remote CID == local_cid (guest->host transport) will use guest->host
transport for loopback (host->guest transports don't support loopback);
- remote CID > VMADDR_CID_HOST will use host->guest transport;
- listener sockets are not bound to any transports since no transport operations are done on it. In this way we can create a listener socket, also if the transports are not loaded or with VMADDR_CID_ANY to listen on all transports.
- DGRAM sockets are handled as before, since only the vmci_transport provides this feature.
---
v1 -> v2:
- vmci_transport: sent reset when vsock_assign_transport() fails [Jorgen]
- fixed loopback in the guests, checking if the remote_addr is the same of transport_g2h->get_local_cid()
- virtio_transport_common: updated space available while creating the new child socket during a connection request
--- drivers/vhost/vsock.c | 5 +- include/net/af_vsock.h | 18 +- net/vmw_vsock/af_vsock.c | 243 ++++++++++++++++++------ net/vmw_vsock/hyperv_transport.c | 26 ++- net/vmw_vsock/virtio_transport.c | 7 +- net/vmw_vsock/virtio_transport_common.c | 63 ++++-- net/vmw_vsock/vmci_transport.c | 32 +++- 7 files changed, 297 insertions(+), 97 deletions(-)
drivers/vhost/vsock.c +3 -2
@@ -831,7 +831,8 @@ static int __init vhost_vsock_init(void) {int ret; - ret =vsock_core_init (&vhost_transport.transport); + ret =vsock_core_register (&vhost_transport.transport, +VSOCK_TRANSPORT_F_H2G );if (ret <0 )return ret;return misc_register (&vhost_vsock_misc);
@@ -840,7 +841,7 @@ static int __init vhost_vsock_init(void) static void __exit vhost_vsock_exit(void) {misc_deregister (&vhost_vsock_misc); -vsock_core_exit (); +vsock_core_unregister (&vhost_transport.transport); };module_init (vhost_vsock_init);
include/net/af_vsock.h +12 -6
@@ -91,6 +91,14 @@ struct vsock_transport_send_notify_data {u64 data2;/* Transport-defined. */ }; +/* Transport features flags */ +/* Transport provides host->guest communication */ +#define VSOCK_TRANSPORT_F_H2G 0x00000001 +/* Transport provides guest->host communication */ +#define VSOCK_TRANSPORT_F_G2H 0x00000002 +/* Transport provides DGRAM communication */ +#define VSOCK_TRANSPORT_F_DGRAM 0x00000004 +struct vsock_transport {/* Initialize/tear-down socket. */ int (*init)(struct vsock_sock *,struct vsock_sock *);
@@ -154,12 +162,8 @@ struct vsock_transport {/**** CORE ****/ -int __vsock_core_init (const struct vsock_transport *t,struct module *owner); -static inline int vsock_core_init (const struct vsock_transport *t) -{ -return __vsock_core_init (t,THIS_MODULE ); -} -void vsock_core_exit (void ); +int vsock_core_register (const struct vsock_transport *t,int features); +void vsock_core_unregister (const struct vsock_transport *t);/* The transport may downcast this to access transport-specific functions */ const struct vsock_transport *vsock_core_get_transport (struct vsock_sock *vsk);
@@ -190,6 +194,8 @@ 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)); +int vsock_assign_transport (struct vsock_sock *vsk,struct vsock_sock *psk); +bool vsock_find_cid (unsigned int cid);/**** TAP ****/
net/vmw_vsock/af_vsock.c +184 -59
409 lines not on this page · raw message
net/vmw_vsock/hyperv_transport.c +21 -5
@@ -165,6 +165,8 @@ static const guid_t srv_id_template =GUID_INIT (0x00000000 ,0xfacb ,0x11e6 ,0xbd ,0x58 ,0x64 ,0x00 ,0x6a ,0x79 ,0x86 ,0xd3 ); +static bool hvs_check_transport (struct vsock_sock *vsk); +static bool is_valid_srv_id (const guid_t *id) {return !memcmp (&id->b[4 ], &srv_id_template.b[4 ],sizeof (guid_t) -4 );
@@ -367,6 +369,18 @@ static void hvs_open_connection(struct vmbus_channel *chan) new->sk_state =TCP_SYN_SENT ; vnew =vsock_sk (new); + +hvs_addr_init (&vnew->local_addr, if_type); +hvs_remote_addr_init (&vnew->remote_addr, &vnew->local_addr); + + ret =vsock_assign_transport (vnew,vsock_sk (sk)); +/* Transport assigned (looking at remote_addr) must be the +* same where we received the request. +*/ +if (ret || !hvs_check_transport (vnew)) { +sock_put (new); + goto out; + } hvs_new = vnew->trans; hvs_new->chan = chan; }else {
@@ -430,9 +444,6 @@ static void hvs_open_connection(struct vmbus_channel *chan) new->sk_state =TCP_ESTABLISHED ;sk_acceptq_added (sk); -hvs_addr_init (&vnew->local_addr, if_type); -hvs_remote_addr_init (&vnew->remote_addr, &vnew->local_addr); - hvs_new->vm_srv_id = *if_type; hvs_new->host_srv_id = *if_instance;
@@ -880,6 +891,11 @@ static struct vsock_transport hvs_transport = { }; +static bool hvs_check_transport (struct vsock_sock *vsk) +{ +return vsk->transport == &hvs_transport; +} +static int hvs_probe (struct hv_device *hdev,const struct hv_vmbus_device_id *dev_id) {
@@ -928,7 +944,7 @@ static int __init hvs_init(void)if (ret !=0 )return ret; - ret =vsock_core_init (&hvs_transport); + ret =vsock_core_register (&hvs_transport,VSOCK_TRANSPORT_F_G2H );if (ret) {vmbus_driver_unregister (&hvs_drv);return ret;
@@ -939,7 +955,7 @@ static int __init hvs_init(void) static void __exit hvs_exit(void) { -vsock_core_exit (); +vsock_core_unregister (&hvs_transport);vmbus_driver_unregister (&hvs_drv); }
net/vmw_vsock/virtio_transport.c +4 -3
@@ -770,7 +770,8 @@ static int __init virtio_vsock_init(void)if (!virtio_vsock_workqueue)return -ENOMEM ; - ret =vsock_core_init (&virtio_transport.transport); + ret =vsock_core_register (&virtio_transport.transport, +VSOCK_TRANSPORT_F_G2H );if (ret) goto out_wq;
@@ -781,7 +782,7 @@ static int __init virtio_vsock_init(void)return 0 ; out_vci: -vsock_core_exit (); +vsock_core_unregister (&virtio_transport.transport); out_wq:destroy_workqueue (virtio_vsock_workqueue);return ret;
@@ -790,7 +791,7 @@ static int __init virtio_vsock_init(void) static void __exit virtio_vsock_exit(void) {unregister_virtio_driver (&virtio_vsock_driver); -vsock_core_exit (); +vsock_core_unregister (&virtio_transport.transport);destroy_workqueue (virtio_vsock_workqueue); }
net/vmw_vsock/virtio_transport_common.c +44 -19
105 lines not on this page · raw message
net/vmw_vsock/vmci_transport.c +29 -3
@@ -57,6 +57,7 @@ static bool vmci_transport_old_proto_override(bool *old_pkt_proto);static u16 vmci_transport_new_proto_supported_versions (void );static bool vmci_transport_proto_to_notify_struct (struct sock *sk,u16 *proto,bool old_pkt_proto); +static bool vmci_check_transport (struct vsock_sock *vsk);struct vmci_transport_recv_pkt_info {struct work_struct work;
@@ -1017,6 +1018,16 @@ static int vmci_transport_recv_listen(struct sock *sk,vsock_addr_init (&vpending->remote_addr, pkt->dg.src.context, pkt->src_port); + err =vsock_assign_transport (vpending,vsock_sk (sk)); +/* Transport assigned (looking at remote_addr) must be the same +* where we received the request. +*/ +if (err || !vmci_check_transport (vpending)) { +vmci_transport_send_reset (sk, pkt); +sock_put (pending); +return err; + } +/* If the proposed size fits within our min/max, accept it. Otherwise * propose our own size. */
@@ -2008,7 +2019,7 @@ static u32 vmci_transport_get_local_cid(void)return vmci_get_context_id (); } -static const struct vsock_transport vmci_transport = { +static struct vsock_transport vmci_transport = { .init = vmci_transport_socket_init, .destruct = vmci_transport_destruct, .release = vmci_transport_release,
@@ -2038,10 +2049,25 @@ static const struct vsock_transport vmci_transport = { .get_local_cid = vmci_transport_get_local_cid, }; +static bool vmci_check_transport (struct vsock_sock *vsk) +{ +return vsk->transport == &vmci_transport; +} +static int __init vmci_transport_init (void ) { +int features =VSOCK_TRANSPORT_F_DGRAM |VSOCK_TRANSPORT_F_H2G ; +int cid;int err; + cid =vmci_get_context_id (); + +if (cid ==VMCI_INVALID_ID ) +return -EINVAL ; + +if (cid !=VMCI_HOST_CONTEXT_ID ) + features |=VSOCK_TRANSPORT_F_G2H ; +/* Create the datagram handle that we will use to send and receive all * VSocket control messages for this context. */
@@ -2065,7 +2091,7 @@ static int __init vmci_transport_init(void) goto err_destroy_stream_handle; } - err =vsock_core_init (&vmci_transport); + err =vsock_core_register (&vmci_transport, features);if (err <0 ) goto err_unsubscribe;
@@ -2096,7 +2122,7 @@ static void __exit vmci_transport_exit(void) vmci_transport_qp_resumed_sub_id =VMCI_INVALID_ID ; } -vsock_core_exit (); +vsock_core_unregister (&vmci_transport); }module_exit (vmci_transport_exit);
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 11/15 vsock: add multi-transports support
In reply to Stefano GarzarellaThis patch adds the support of multiple transports in the VSOCK core.
With the multi-transports support, we can use vsock with nested VMs (using also different hypervisors) loading both guest->host and host->guest transports at the same time.
Major changes:
- vsock core module can be loaded regardless of the transports
- vsock_core_init() and vsock_core_exit() are renamed to vsock_core_register() and vsock_core_unregister()
- vsock_core_register() has a feature parameter (H2G, G2H, DGRAM) to identify which directions the transport can handle and if it's support DGRAM (only vmci)
- each stream socket is assigned to a transport when the remote CID is set (during the connect() or when we receive a connection request on a listener socket).
The remote CID is used to decide which transport to use:
- remote CID <= VMADDR_CID_HOST will use guest->host transport;
- remote CID == local_cid (guest->host transport) will use guest->host
transport for loopback (host->guest transports don't support loopback);
- remote CID > VMADDR_CID_HOST will use host->guest transport;
- listener sockets are not bound to any transports since no transport operations are done on it. In this way we can create a listener socket, also if the transports are not loaded or with VMADDR_CID_ANY to listen on all transports.
- DGRAM sockets are handled as before, since only the vmci_transport provides this feature.
---
v1 -> v2:
- vmci_transport: sent reset when vsock_assign_transport() fails [Jorgen]
- fixed loopback in the guests, checking if the remote_addr is the same of transport_g2h->get_local_cid()
- virtio_transport_common: updated space available while creating the new child socket during a connection request
--- drivers/vhost/vsock.c | 5 +- include/net/af_vsock.h | 18 +- net/vmw_vsock/af_vsock.c | 243 ++++++++++++++++++------ net/vmw_vsock/hyperv_transport.c | 26 ++- net/vmw_vsock/virtio_transport.c | 7 +- net/vmw_vsock/virtio_transport_common.c | 63 ++++-- net/vmw_vsock/vmci_transport.c | 32 +++- 7 files changed, 297 insertions(+), 97 deletions(-)
drivers/vhost/vsock.c +3 -2
@@ -831,7 +831,8 @@ static int __init vhost_vsock_init(void) {int ret; - ret =vsock_core_init (&vhost_transport.transport); + ret =vsock_core_register (&vhost_transport.transport, +VSOCK_TRANSPORT_F_H2G );if (ret <0 )return ret;return misc_register (&vhost_vsock_misc);
@@ -840,7 +841,7 @@ static int __init vhost_vsock_init(void) static void __exit vhost_vsock_exit(void) {misc_deregister (&vhost_vsock_misc); -vsock_core_exit (); +vsock_core_unregister (&vhost_transport.transport); };module_init (vhost_vsock_init);
include/net/af_vsock.h +12 -6
@@ -91,6 +91,14 @@ struct vsock_transport_send_notify_data {u64 data2;/* Transport-defined. */ }; +/* Transport features flags */ +/* Transport provides host->guest communication */ +#define VSOCK_TRANSPORT_F_H2G 0x00000001 +/* Transport provides guest->host communication */ +#define VSOCK_TRANSPORT_F_G2H 0x00000002 +/* Transport provides DGRAM communication */ +#define VSOCK_TRANSPORT_F_DGRAM 0x00000004 +struct vsock_transport {/* Initialize/tear-down socket. */ int (*init)(struct vsock_sock *,struct vsock_sock *);
@@ -154,12 +162,8 @@ struct vsock_transport {/**** CORE ****/ -int __vsock_core_init (const struct vsock_transport *t,struct module *owner); -static inline int vsock_core_init (const struct vsock_transport *t) -{ -return __vsock_core_init (t,THIS_MODULE ); -} -void vsock_core_exit (void ); +int vsock_core_register (const struct vsock_transport *t,int features); +void vsock_core_unregister (const struct vsock_transport *t);/* The transport may downcast this to access transport-specific functions */ const struct vsock_transport *vsock_core_get_transport (struct vsock_sock *vsk);
@@ -190,6 +194,8 @@ 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)); +int vsock_assign_transport (struct vsock_sock *vsk,struct vsock_sock *psk); +bool vsock_find_cid (unsigned int cid);/**** TAP ****/
net/vmw_vsock/af_vsock.c +184 -59
409 lines not on this page · raw message
net/vmw_vsock/hyperv_transport.c +21 -5
@@ -165,6 +165,8 @@ static const guid_t srv_id_template =GUID_INIT (0x00000000 ,0xfacb ,0x11e6 ,0xbd ,0x58 ,0x64 ,0x00 ,0x6a ,0x79 ,0x86 ,0xd3 ); +static bool hvs_check_transport (struct vsock_sock *vsk); +static bool is_valid_srv_id (const guid_t *id) {return !memcmp (&id->b[4 ], &srv_id_template.b[4 ],sizeof (guid_t) -4 );
@@ -367,6 +369,18 @@ static void hvs_open_connection(struct vmbus_channel *chan) new->sk_state =TCP_SYN_SENT ; vnew =vsock_sk (new); + +hvs_addr_init (&vnew->local_addr, if_type); +hvs_remote_addr_init (&vnew->remote_addr, &vnew->local_addr); + + ret =vsock_assign_transport (vnew,vsock_sk (sk)); +/* Transport assigned (looking at remote_addr) must be the +* same where we received the request. +*/ +if (ret || !hvs_check_transport (vnew)) { +sock_put (new); + goto out; + } hvs_new = vnew->trans; hvs_new->chan = chan; }else {
@@ -430,9 +444,6 @@ static void hvs_open_connection(struct vmbus_channel *chan) new->sk_state =TCP_ESTABLISHED ;sk_acceptq_added (sk); -hvs_addr_init (&vnew->local_addr, if_type); -hvs_remote_addr_init (&vnew->remote_addr, &vnew->local_addr); - hvs_new->vm_srv_id = *if_type; hvs_new->host_srv_id = *if_instance;
@@ -880,6 +891,11 @@ static struct vsock_transport hvs_transport = { }; +static bool hvs_check_transport (struct vsock_sock *vsk) +{ +return vsk->transport == &hvs_transport; +} +static int hvs_probe (struct hv_device *hdev,const struct hv_vmbus_device_id *dev_id) {
@@ -928,7 +944,7 @@ static int __init hvs_init(void)if (ret !=0 )return ret; - ret =vsock_core_init (&hvs_transport); + ret =vsock_core_register (&hvs_transport,VSOCK_TRANSPORT_F_G2H );if (ret) {vmbus_driver_unregister (&hvs_drv);return ret;
@@ -939,7 +955,7 @@ static int __init hvs_init(void) static void __exit hvs_exit(void) { -vsock_core_exit (); +vsock_core_unregister (&hvs_transport);vmbus_driver_unregister (&hvs_drv); }
net/vmw_vsock/virtio_transport.c +4 -3
@@ -770,7 +770,8 @@ static int __init virtio_vsock_init(void)if (!virtio_vsock_workqueue)return -ENOMEM ; - ret =vsock_core_init (&virtio_transport.transport); + ret =vsock_core_register (&virtio_transport.transport, +VSOCK_TRANSPORT_F_G2H );if (ret) goto out_wq;
@@ -781,7 +782,7 @@ static int __init virtio_vsock_init(void)return 0 ; out_vci: -vsock_core_exit (); +vsock_core_unregister (&virtio_transport.transport); out_wq:destroy_workqueue (virtio_vsock_workqueue);return ret;
@@ -790,7 +791,7 @@ static int __init virtio_vsock_init(void) static void __exit virtio_vsock_exit(void) {unregister_virtio_driver (&virtio_vsock_driver); -vsock_core_exit (); +vsock_core_unregister (&virtio_transport.transport);destroy_workqueue (virtio_vsock_workqueue); }
net/vmw_vsock/virtio_transport_common.c +44 -19
105 lines not on this page · raw message
net/vmw_vsock/vmci_transport.c +29 -3
@@ -57,6 +57,7 @@ static bool vmci_transport_old_proto_override(bool *old_pkt_proto);static u16 vmci_transport_new_proto_supported_versions (void );static bool vmci_transport_proto_to_notify_struct (struct sock *sk,u16 *proto,bool old_pkt_proto); +static bool vmci_check_transport (struct vsock_sock *vsk);struct vmci_transport_recv_pkt_info {struct work_struct work;
@@ -1017,6 +1018,16 @@ static int vmci_transport_recv_listen(struct sock *sk,vsock_addr_init (&vpending->remote_addr, pkt->dg.src.context, pkt->src_port); + err =vsock_assign_transport (vpending,vsock_sk (sk)); +/* Transport assigned (looking at remote_addr) must be the same +* where we received the request. +*/ +if (err || !vmci_check_transport (vpending)) { +vmci_transport_send_reset (sk, pkt); +sock_put (pending); +return err; + } +/* If the proposed size fits within our min/max, accept it. Otherwise * propose our own size. */
@@ -2008,7 +2019,7 @@ static u32 vmci_transport_get_local_cid(void)return vmci_get_context_id (); } -static const struct vsock_transport vmci_transport = { +static struct vsock_transport vmci_transport = { .init = vmci_transport_socket_init, .destruct = vmci_transport_destruct, .release = vmci_transport_release,
@@ -2038,10 +2049,25 @@ static const struct vsock_transport vmci_transport = { .get_local_cid = vmci_transport_get_local_cid, }; +static bool vmci_check_transport (struct vsock_sock *vsk) +{ +return vsk->transport == &vmci_transport; +} +static int __init vmci_transport_init (void ) { +int features =VSOCK_TRANSPORT_F_DGRAM |VSOCK_TRANSPORT_F_H2G ; +int cid;int err; + cid =vmci_get_context_id (); + +if (cid ==VMCI_INVALID_ID ) +return -EINVAL ; + +if (cid !=VMCI_HOST_CONTEXT_ID ) + features |=VSOCK_TRANSPORT_F_G2H ; +/* Create the datagram handle that we will use to send and receive all * VSocket control messages for this context. */
@@ -2065,7 +2091,7 @@ static int __init vmci_transport_init(void) goto err_destroy_stream_handle; } - err =vsock_core_init (&vmci_transport); + err =vsock_core_register (&vmci_transport, features);if (err <0 ) goto err_unsubscribe;
@@ -2096,7 +2122,7 @@ static void __exit vmci_transport_exit(void) vmci_transport_qp_resumed_sub_id =VMCI_INVALID_ID ; } -vsock_core_exit (); +vsock_core_unregister (&vmci_transport); }module_exit (vmci_transport_exit);
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 12/15 vsock/vmci: register vmci_transport only when VMCI guest/host are active
In reply to Stefano GarzarellaTo allow other transports to be loaded with vmci_transport, we register the vmci_transport as G2H or H2G only when a VMCI guest or host is active.
To do that, this patch adds a callback registered in the vmci driver that will be called when the host or guest becomes active. This callback will register the vmci_transport in the VSOCK core.
---
v1 -> v2
- removed features variable in vmci_transport_init() [Stefan]
- added a flag to register only once the host [Jorgen]
--- drivers/misc/vmw_vmci/vmci_driver.c | 67 +++++++++++++++++++++++++++++ drivers/misc/vmw_vmci/vmci_driver.h | 2 + drivers/misc/vmw_vmci/vmci_guest.c | 2 + drivers/misc/vmw_vmci/vmci_host.c | 7 +++ include/linux/vmw_vmci_api.h | 2 + net/vmw_vsock/vmci_transport.c | 33 +++++++++----- 6 files changed, 102 insertions(+), 11 deletions(-)
drivers/misc/vmw_vmci/vmci_driver.c +67 -0
@@ -28,6 +28,10 @@ MODULE_PARM_DESC(disable_guest,static bool vmci_guest_personality_initialized;static bool vmci_host_personality_initialized; +static DEFINE_MUTEX (vmci_vsock_mutex);/* protects vmci_vsock_transport_cb */ +static vmci_vsock_cb vmci_vsock_transport_cb; +bool vmci_vsock_cb_host_called; +/* * vmci_get_context_id() - Gets the current context ID. *
@@ -45,6 +49,69 @@ u32 vmci_get_context_id(void) }EXPORT_SYMBOL_GPL (vmci_get_context_id); +/* +* vmci_register_vsock_callback() - Register the VSOCK vmci_transport callback. +* +* The callback will be called when the first host or guest becomes active, +* or if they are already active when this function is called. +* To unregister the callback, call this function with NULL parameter. +* +* Returns 0 on success. -EBUSY if a callback is already registered. +*/ +int vmci_register_vsock_callback (vmci_vsock_cb callback) +{ +int err =0 ; + +mutex_lock (&vmci_vsock_mutex); + +if (vmci_vsock_transport_cb && callback) { + err = -EBUSY ; + goto out; + } + + vmci_vsock_transport_cb = callback; + +if (!vmci_vsock_transport_cb) { + vmci_vsock_cb_host_called = false; + goto out; + } + +if (vmci_guest_code_active ()) +vmci_vsock_transport_cb (false); + +if (vmci_host_users () >0 ) { + vmci_vsock_cb_host_called = true; +vmci_vsock_transport_cb (true); + } + +out: +mutex_unlock (&vmci_vsock_mutex); +return err; +} +EXPORT_SYMBOL_GPL (vmci_register_vsock_callback); + +void vmci_call_vsock_callback (bool is_host) +{ +mutex_lock (&vmci_vsock_mutex); + +if (!vmci_vsock_transport_cb) + goto out; + +/* In the host, this function could be called multiple times, +* but we want to register it only once. +*/ +if (is_host) { +if (vmci_vsock_cb_host_called) + goto out; + + vmci_vsock_cb_host_called = true; + } + +vmci_vsock_transport_cb (is_host); +out: +mutex_unlock (&vmci_vsock_mutex); +} +static int __init vmci_drv_init (void ) {int vmci_err;
drivers/misc/vmw_vmci/vmci_driver.h +2 -0
@@ -36,10 +36,12 @@ extern struct pci_dev *vmci_pdev;u32 vmci_get_context_id (void );int vmci_send_datagram (struct vmci_datagram *dg); +void vmci_call_vsock_callback (bool is_host);int vmci_host_init (void );void vmci_host_exit (void );bool vmci_host_code_active (void ); +int vmci_host_users (void );int vmci_guest_init (void );void vmci_guest_exit (void );
drivers/misc/vmw_vmci/vmci_guest.c +2 -0
@@ -637,6 +637,8 @@ static int vmci_guest_probe_device(struct pci_dev *pdev, vmci_dev->iobase + VMCI_CONTROL_ADDR);pci_set_drvdata (pdev, vmci_dev); + +vmci_call_vsock_callback (false);return 0 ; err_free_irq:
drivers/misc/vmw_vmci/vmci_host.c +7 -0
@@ -108,6 +108,11 @@ bool vmci_host_code_active(void) atomic_read(&vmci_host_active_users) > 0); } +int vmci_host_users (void ) +{ +return atomic_read (&vmci_host_active_users); +} +/* * Called on open of /dev/vmci. */
@@ -338,6 +343,8 @@ static int vmci_host_do_init_context(struct vmci_host_dev *vmci_host_dev, vmci_host_dev->ct_type =VMCIOBJ_CONTEXT ;atomic_inc (&vmci_host_active_users); +vmci_call_vsock_callback (true); + retval =0 ; out:
include/linux/vmw_vmci_api.h +2 -0
@@ -19,6 +19,7 @@struct msghdr ;typedef void (vmci_device_shutdown_fn ) (void *device_registration,void *user_data); +typedef void (*vmci_vsock_cb ) (bool is_host); int vmci_datagram_create_handle(u32 resource_id, u32 flags, vmci_datagram_recv_cb recv_cb,
@@ -37,6 +38,7 @@ int vmci_doorbell_destroy(struct vmci_handle handle);int vmci_doorbell_notify (struct vmci_handle handle,u32 priv_flags);u32 vmci_get_context_id (void );bool vmci_is_context_owner (u32 context_id,kuid_t uid); +int vmci_register_vsock_callback (vmci_vsock_cb callback); int vmci_event_subscribe(u32 event, vmci_event_cb callback, void *callback_data,
net/vmw_vsock/vmci_transport.c +22 -11
@@ -2054,19 +2054,21 @@ static bool vmci_check_transport(struct vsock_sock *vsk)return vsk->transport == &vmci_transport; } -static int __init vmci_transport_init (void ) +void vmci_vsock_transport_cb (bool is_host) { -int features =VSOCK_TRANSPORT_F_DGRAM |VSOCK_TRANSPORT_F_H2G ; -int cid; -int err; +int features; - cid =vmci_get_context_id (); +if (is_host) + features =VSOCK_TRANSPORT_F_H2G ; +else + features =VSOCK_TRANSPORT_F_G2H ; -if (cid ==VMCI_INVALID_ID ) -return -EINVAL ; +vsock_core_register (&vmci_transport, features); +} -if (cid !=VMCI_HOST_CONTEXT_ID ) - features |=VSOCK_TRANSPORT_F_G2H ; +static int __init vmci_transport_init (void ) +{ +int err;/* Create the datagram handle that we will use to send and receive all * VSocket control messages for this context.
@@ -2080,7 +2082,6 @@ static int __init vmci_transport_init(void)pr_err ("Unable to create datagram handle. (%d)\n" , err);return vmci_transport_error_to_vsock_error (err); } - err =vmci_event_subscribe (VMCI_EVENT_QP_RESUMED , vmci_transport_qp_resumed_cb,NULL , &vmci_transport_qp_resumed_sub_id);
@@ -2091,12 +2092,21 @@ static int __init vmci_transport_init(void) goto err_destroy_stream_handle; } - err =vsock_core_register (&vmci_transport, features); +/* Register only with dgram feature, other features (H2G, G2H) will be +* registered when the first host or guest becomes active. +*/ + err =vsock_core_register (&vmci_transport,VSOCK_TRANSPORT_F_DGRAM );if (err <0 ) goto err_unsubscribe; + err =vmci_register_vsock_callback (vmci_vsock_transport_cb); +if (err <0 ) + goto err_unregister; +return 0 ; +err_unregister: +vsock_core_unregister (&vmci_transport); err_unsubscribe:vmci_event_unsubscribe (vmci_transport_qp_resumed_sub_id); err_destroy_stream_handle:
@@ -2122,6 +2132,7 @@ static void __exit vmci_transport_exit(void) vmci_transport_qp_resumed_sub_id =VMCI_INVALID_ID ; } +vmci_register_vsock_callback (NULL );vsock_core_unregister (&vmci_transport); }module_exit (vmci_transport_exit);
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 12/15 vsock/vmci: register vmci_transport only when VMCI guest/host are active
In reply to Stefano GarzarellaTo allow other transports to be loaded with vmci_transport, we register the vmci_transport as G2H or H2G only when a VMCI guest or host is active.
To do that, this patch adds a callback registered in the vmci driver that will be called when the host or guest becomes active. This callback will register the vmci_transport in the VSOCK core.
---
v1 -> v2
- removed features variable in vmci_transport_init() [Stefan]
- added a flag to register only once the host [Jorgen]
--- drivers/misc/vmw_vmci/vmci_driver.c | 67 +++++++++++++++++++++++++++++ drivers/misc/vmw_vmci/vmci_driver.h | 2 + drivers/misc/vmw_vmci/vmci_guest.c | 2 + drivers/misc/vmw_vmci/vmci_host.c | 7 +++ include/linux/vmw_vmci_api.h | 2 + net/vmw_vsock/vmci_transport.c | 33 +++++++++----- 6 files changed, 102 insertions(+), 11 deletions(-)
drivers/misc/vmw_vmci/vmci_driver.c +67 -0
@@ -28,6 +28,10 @@ MODULE_PARM_DESC(disable_guest,static bool vmci_guest_personality_initialized;static bool vmci_host_personality_initialized; +static DEFINE_MUTEX (vmci_vsock_mutex);/* protects vmci_vsock_transport_cb */ +static vmci_vsock_cb vmci_vsock_transport_cb; +bool vmci_vsock_cb_host_called; +/* * vmci_get_context_id() - Gets the current context ID. *
@@ -45,6 +49,69 @@ u32 vmci_get_context_id(void) }EXPORT_SYMBOL_GPL (vmci_get_context_id); +/* +* vmci_register_vsock_callback() - Register the VSOCK vmci_transport callback. +* +* The callback will be called when the first host or guest becomes active, +* or if they are already active when this function is called. +* To unregister the callback, call this function with NULL parameter. +* +* Returns 0 on success. -EBUSY if a callback is already registered. +*/ +int vmci_register_vsock_callback (vmci_vsock_cb callback) +{ +int err =0 ; + +mutex_lock (&vmci_vsock_mutex); + +if (vmci_vsock_transport_cb && callback) { + err = -EBUSY ; + goto out; + } + + vmci_vsock_transport_cb = callback; + +if (!vmci_vsock_transport_cb) { + vmci_vsock_cb_host_called = false; + goto out; + } + +if (vmci_guest_code_active ()) +vmci_vsock_transport_cb (false); + +if (vmci_host_users () >0 ) { + vmci_vsock_cb_host_called = true; +vmci_vsock_transport_cb (true); + } + +out: +mutex_unlock (&vmci_vsock_mutex); +return err; +} +EXPORT_SYMBOL_GPL (vmci_register_vsock_callback); + +void vmci_call_vsock_callback (bool is_host) +{ +mutex_lock (&vmci_vsock_mutex); + +if (!vmci_vsock_transport_cb) + goto out; + +/* In the host, this function could be called multiple times, +* but we want to register it only once. +*/ +if (is_host) { +if (vmci_vsock_cb_host_called) + goto out; + + vmci_vsock_cb_host_called = true; + } + +vmci_vsock_transport_cb (is_host); +out: +mutex_unlock (&vmci_vsock_mutex); +} +static int __init vmci_drv_init (void ) {int vmci_err;
drivers/misc/vmw_vmci/vmci_driver.h +2 -0
@@ -36,10 +36,12 @@ extern struct pci_dev *vmci_pdev;u32 vmci_get_context_id (void );int vmci_send_datagram (struct vmci_datagram *dg); +void vmci_call_vsock_callback (bool is_host);int vmci_host_init (void );void vmci_host_exit (void );bool vmci_host_code_active (void ); +int vmci_host_users (void );int vmci_guest_init (void );void vmci_guest_exit (void );
drivers/misc/vmw_vmci/vmci_guest.c +2 -0
@@ -637,6 +637,8 @@ static int vmci_guest_probe_device(struct pci_dev *pdev, vmci_dev->iobase + VMCI_CONTROL_ADDR);pci_set_drvdata (pdev, vmci_dev); + +vmci_call_vsock_callback (false);return 0 ; err_free_irq:
drivers/misc/vmw_vmci/vmci_host.c +7 -0
@@ -108,6 +108,11 @@ bool vmci_host_code_active(void) atomic_read(&vmci_host_active_users) > 0); } +int vmci_host_users (void ) +{ +return atomic_read (&vmci_host_active_users); +} +/* * Called on open of /dev/vmci. */
@@ -338,6 +343,8 @@ static int vmci_host_do_init_context(struct vmci_host_dev *vmci_host_dev, vmci_host_dev->ct_type =VMCIOBJ_CONTEXT ;atomic_inc (&vmci_host_active_users); +vmci_call_vsock_callback (true); + retval =0 ; out:
include/linux/vmw_vmci_api.h +2 -0
@@ -19,6 +19,7 @@struct msghdr ;typedef void (vmci_device_shutdown_fn ) (void *device_registration,void *user_data); +typedef void (*vmci_vsock_cb ) (bool is_host); int vmci_datagram_create_handle(u32 resource_id, u32 flags, vmci_datagram_recv_cb recv_cb,
@@ -37,6 +38,7 @@ int vmci_doorbell_destroy(struct vmci_handle handle);int vmci_doorbell_notify (struct vmci_handle handle,u32 priv_flags);u32 vmci_get_context_id (void );bool vmci_is_context_owner (u32 context_id,kuid_t uid); +int vmci_register_vsock_callback (vmci_vsock_cb callback); int vmci_event_subscribe(u32 event, vmci_event_cb callback, void *callback_data,
net/vmw_vsock/vmci_transport.c +22 -11
@@ -2054,19 +2054,21 @@ static bool vmci_check_transport(struct vsock_sock *vsk)return vsk->transport == &vmci_transport; } -static int __init vmci_transport_init (void ) +void vmci_vsock_transport_cb (bool is_host) { -int features =VSOCK_TRANSPORT_F_DGRAM |VSOCK_TRANSPORT_F_H2G ; -int cid; -int err; +int features; - cid =vmci_get_context_id (); +if (is_host) + features =VSOCK_TRANSPORT_F_H2G ; +else + features =VSOCK_TRANSPORT_F_G2H ; -if (cid ==VMCI_INVALID_ID ) -return -EINVAL ; +vsock_core_register (&vmci_transport, features); +} -if (cid !=VMCI_HOST_CONTEXT_ID ) - features |=VSOCK_TRANSPORT_F_G2H ; +static int __init vmci_transport_init (void ) +{ +int err;/* Create the datagram handle that we will use to send and receive all * VSocket control messages for this context.
@@ -2080,7 +2082,6 @@ static int __init vmci_transport_init(void)pr_err ("Unable to create datagram handle. (%d)\n" , err);return vmci_transport_error_to_vsock_error (err); } - err =vmci_event_subscribe (VMCI_EVENT_QP_RESUMED , vmci_transport_qp_resumed_cb,NULL , &vmci_transport_qp_resumed_sub_id);
@@ -2091,12 +2092,21 @@ static int __init vmci_transport_init(void) goto err_destroy_stream_handle; } - err =vsock_core_register (&vmci_transport, features); +/* Register only with dgram feature, other features (H2G, G2H) will be +* registered when the first host or guest becomes active. +*/ + err =vsock_core_register (&vmci_transport,VSOCK_TRANSPORT_F_DGRAM );if (err <0 ) goto err_unsubscribe; + err =vmci_register_vsock_callback (vmci_vsock_transport_cb); +if (err <0 ) + goto err_unregister; +return 0 ; +err_unregister: +vsock_core_unregister (&vmci_transport); err_unsubscribe:vmci_event_unsubscribe (vmci_transport_qp_resumed_sub_id); err_destroy_stream_handle:
@@ -2122,6 +2132,7 @@ static void __exit vmci_transport_exit(void) vmci_transport_qp_resumed_sub_id =VMCI_INVALID_ID ; } +vmci_register_vsock_callback (NULL );vsock_core_unregister (&vmci_transport); }module_exit (vmci_transport_exit);
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 13/15 vsock: prevent transport modules unloading
In reply to Stefano GarzarellaThis patch adds 'module' member in the 'struct vsock_transport' in order to get/put the transport module. This prevents the module unloading while sockets are assigned to it.
We increase the module refcnt when a socket is assigned to a transport, and we decrease the module refcnt when the socket is destructed.
--- drivers/vhost/vsock.c | 2 ++ include/net/af_vsock.h | 2 ++ net/vmw_vsock/af_vsock.c | 20 ++++++++++++++++---- net/vmw_vsock/hyperv_transport.c | 2 ++ net/vmw_vsock/virtio_transport.c | 2 ++ net/vmw_vsock/vmci_transport.c | 1 + 6 files changed, 25 insertions(+), 4 deletions(-)
drivers/vhost/vsock.c +2 -0
@@ -386,6 +386,8 @@ static bool vhost_vsock_more_replies(struct vhost_vsock *vsock)static struct virtio_transport vhost_transport = { .transport = { + .module =THIS_MODULE , + .get_local_cid = vhost_transport_get_local_cid, .init = virtio_transport_do_socket_init,
include/net/af_vsock.h +2 -0
@@ -100,6 +100,8 @@ struct vsock_transport_send_notify_data {#define VSOCK_TRANSPORT_F_DGRAM 0x00000004struct vsock_transport { +struct module *module; +/* Initialize/tear-down socket. */ int (*init)(struct vsock_sock *,struct vsock_sock *);void (*destruct)(struct vsock_sock *);
net/vmw_vsock/af_vsock.c +16 -4
@@ -380,6 +380,16 @@ void vsock_enqueue_accept(struct sock *listener, struct sock *connected) }EXPORT_SYMBOL_GPL (vsock_enqueue_accept); +static void vsock_deassign_transport (struct vsock_sock *vsk) +{ +if (!vsk->transport) +return ; + + vsk->transport->destruct (vsk); +module_put (vsk->transport->module); + vsk->transport =NULL ; +} +/* Assign a transport to a socket and call the .init transport callback. * * Note: for stream socket this must be called when vsk->remote_addr is set
@@ -418,10 +428,13 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)return 0 ; vsk->transport->release (vsk); - vsk->transport->destruct (vsk); +vsock_deassign_transport (vsk); } -if (!new_transport) +/* We increase the module refcnt to prevent the transport unloading +* while there are open sockets assigned to it. +*/ +if (!new_transport || !try_module_get (new_transport->module))return -ENODEV ; vsk->transport = new_transport;
@@ -741,8 +754,7 @@ static void vsock_sk_destruct(struct sock *sk) {struct vsock_sock *vsk =vsock_sk (sk); -if (vsk->transport) - vsk->transport->destruct (vsk); +vsock_deassign_transport (vsk);/* When clearing these addresses, there's no need to set the family and * possibly register the address family with the kernel.
net/vmw_vsock/hyperv_transport.c +2 -0
@@ -857,6 +857,8 @@ int hvs_notify_send_post_enqueue(struct vsock_sock *vsk, ssize_t written, }static struct vsock_transport hvs_transport = { + .module =THIS_MODULE , + .get_local_cid = hvs_get_local_cid, .init = hvs_sock_init,
net/vmw_vsock/virtio_transport.c +2 -0
@@ -462,6 +462,8 @@ static void virtio_vsock_rx_done(struct virtqueue *vq)static struct virtio_transport virtio_transport = { .transport = { + .module =THIS_MODULE , + .get_local_cid = virtio_transport_get_local_cid, .init = virtio_transport_do_socket_init,
net/vmw_vsock/vmci_transport.c +1 -0
@@ -2020,6 +2020,7 @@ static u32 vmci_transport_get_local_cid(void) }static struct vsock_transport vmci_transport = { + .module =THIS_MODULE , .init = vmci_transport_socket_init, .destruct = vmci_transport_destruct, .release = vmci_transport_release,
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 13/15 vsock: prevent transport modules unloading
In reply to Stefano GarzarellaThis patch adds 'module' member in the 'struct vsock_transport' in order to get/put the transport module. This prevents the module unloading while sockets are assigned to it.
We increase the module refcnt when a socket is assigned to a transport, and we decrease the module refcnt when the socket is destructed.
--- drivers/vhost/vsock.c | 2 ++ include/net/af_vsock.h | 2 ++ net/vmw_vsock/af_vsock.c | 20 ++++++++++++++++---- net/vmw_vsock/hyperv_transport.c | 2 ++ net/vmw_vsock/virtio_transport.c | 2 ++ net/vmw_vsock/vmci_transport.c | 1 + 6 files changed, 25 insertions(+), 4 deletions(-)
drivers/vhost/vsock.c +2 -0
@@ -386,6 +386,8 @@ static bool vhost_vsock_more_replies(struct vhost_vsock *vsock)static struct virtio_transport vhost_transport = { .transport = { + .module =THIS_MODULE , + .get_local_cid = vhost_transport_get_local_cid, .init = virtio_transport_do_socket_init,
include/net/af_vsock.h +2 -0
@@ -100,6 +100,8 @@ struct vsock_transport_send_notify_data {#define VSOCK_TRANSPORT_F_DGRAM 0x00000004struct vsock_transport { +struct module *module; +/* Initialize/tear-down socket. */ int (*init)(struct vsock_sock *,struct vsock_sock *);void (*destruct)(struct vsock_sock *);
net/vmw_vsock/af_vsock.c +16 -4
@@ -380,6 +380,16 @@ void vsock_enqueue_accept(struct sock *listener, struct sock *connected) }EXPORT_SYMBOL_GPL (vsock_enqueue_accept); +static void vsock_deassign_transport (struct vsock_sock *vsk) +{ +if (!vsk->transport) +return ; + + vsk->transport->destruct (vsk); +module_put (vsk->transport->module); + vsk->transport =NULL ; +} +/* Assign a transport to a socket and call the .init transport callback. * * Note: for stream socket this must be called when vsk->remote_addr is set
@@ -418,10 +428,13 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)return 0 ; vsk->transport->release (vsk); - vsk->transport->destruct (vsk); +vsock_deassign_transport (vsk); } -if (!new_transport) +/* We increase the module refcnt to prevent the transport unloading +* while there are open sockets assigned to it. +*/ +if (!new_transport || !try_module_get (new_transport->module))return -ENODEV ; vsk->transport = new_transport;
@@ -741,8 +754,7 @@ static void vsock_sk_destruct(struct sock *sk) {struct vsock_sock *vsk =vsock_sk (sk); -if (vsk->transport) - vsk->transport->destruct (vsk); +vsock_deassign_transport (vsk);/* When clearing these addresses, there's no need to set the family and * possibly register the address family with the kernel.
net/vmw_vsock/hyperv_transport.c +2 -0
@@ -857,6 +857,8 @@ int hvs_notify_send_post_enqueue(struct vsock_sock *vsk, ssize_t written, }static struct vsock_transport hvs_transport = { + .module =THIS_MODULE , + .get_local_cid = hvs_get_local_cid, .init = hvs_sock_init,
net/vmw_vsock/virtio_transport.c +2 -0
@@ -462,6 +462,8 @@ static void virtio_vsock_rx_done(struct virtqueue *vq)static struct virtio_transport virtio_transport = { .transport = { + .module =THIS_MODULE , + .get_local_cid = virtio_transport_get_local_cid, .init = virtio_transport_do_socket_init,
net/vmw_vsock/vmci_transport.c +1 -0
@@ -2020,6 +2020,7 @@ static u32 vmci_transport_get_local_cid(void) }static struct vsock_transport vmci_transport = { + .module =THIS_MODULE , .init = vmci_transport_socket_init, .destruct = vmci_transport_destruct, .release = vmci_transport_release,
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 14/15 vsock: fix bind() behaviour taking care of CID
In reply to Stefano GarzarellaWhen we are looking for a socket bound to a specific address, we also have to take into account the CID.
This patch is useful with multi-transports support because it allows the binding of the same port with different CID, and it prevents a connection to a wrong socket bound to the same port, but with different CID.
--- net/vmw_vsock/af_vsock.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/vmw_vsock/af_vsock.c +8 -2
@@ -228,10 +228,16 @@ static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr) {struct vsock_sock *vsk; -list_for_each_entry (vsk,vsock_bound_sockets (addr), bound_table) -if (addr->svm_port == vsk->local_addr.svm_port) +list_for_each_entry (vsk,vsock_bound_sockets (addr), bound_table) { +if (vsock_addr_equals_addr (addr, &vsk->local_addr))return sk_vsock (vsk); +if (addr->svm_port == vsk->local_addr.svm_port && + (vsk->local_addr.svm_cid ==VMADDR_CID_ANY || + addr->svm_cid ==VMADDR_CID_ANY )) +return sk_vsock (vsk); + } +return NULL ; }
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 14/15 vsock: fix bind() behaviour taking care of CID
In reply to Stefano GarzarellaWhen we are looking for a socket bound to a specific address, we also have to take into account the CID.
This patch is useful with multi-transports support because it allows the binding of the same port with different CID, and it prevents a connection to a wrong socket bound to the same port, but with different CID.
--- net/vmw_vsock/af_vsock.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/vmw_vsock/af_vsock.c +8 -2
@@ -228,10 +228,16 @@ static struct sock *__vsock_find_bound_socket(struct sockaddr_vm *addr) {struct vsock_sock *vsk; -list_for_each_entry (vsk,vsock_bound_sockets (addr), bound_table) -if (addr->svm_port == vsk->local_addr.svm_port) +list_for_each_entry (vsk,vsock_bound_sockets (addr), bound_table) { +if (vsock_addr_equals_addr (addr, &vsk->local_addr))return sk_vsock (vsk); +if (addr->svm_port == vsk->local_addr.svm_port && + (vsk->local_addr.svm_cid ==VMADDR_CID_ANY || + addr->svm_cid ==VMADDR_CID_ANY )) +return sk_vsock (vsk); + } +return NULL ; }
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 15/15 vhost/vsock: refuse CID assigned to the guest->host transport
In reply to Stefano GarzarellaIn a nested VM environment, we have to refuse to assign to a nested guest the same CID assigned to our guest->host transport. In this way, the user can use the local CID for loopback.
--- drivers/vhost/vsock.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/vhost/vsock.c +6 -0
@@ -718,6 +718,12 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid)if (guest_cid >U32_MAX )return -EINVAL ; +/* Refuse if CID is assigned to the guest->host transport (i.e. nested +* VM), to make the loopback work. +*/ +if (vsock_find_cid (guest_cid)) +return -EADDRINUSE ; +/* Refuse if CID is already in use */ mutex_lock (&vhost_vsock_mutex); other =vhost_vsock_get (guest_cid);
Signature · 1 line
2.21.0
Stefano Garzarella
maintainerPATCH v2 15/15 vhost/vsock: refuse CID assigned to the guest->host transport
In reply to Stefano GarzarellaIn a nested VM environment, we have to refuse to assign to a nested guest the same CID assigned to our guest->host transport. In this way, the user can use the local CID for loopback.
--- drivers/vhost/vsock.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/vhost/vsock.c +6 -0
@@ -718,6 +718,12 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid)if (guest_cid >U32_MAX )return -EINVAL ; +/* Refuse if CID is assigned to the guest->host transport (i.e. nested +* VM), to make the loopback work. +*/ +if (vsock_find_cid (guest_cid)) +return -EADDRINUSE ; +/* Refuse if CID is already in use */ mutex_lock (&vhost_vsock_mutex); other =vhost_vsock_get (guest_cid);
Signature · 1 line
2.21.0
David Miller
maintainerFrom: Stefano Garzarella <[email protected]>
Date: Thu, 14 Nov 2019 10:57:35 +0100
Quoted 9 lines
Most of the patches are reviewed by Dexuan, Stefan, and Jorgen. The following patches need reviews:
- [11/15] vsock: add multi-transports support
- [12/15] vsock/vmci: registervmci_transportonly when VMCI guest/host are active
- [15/15] vhost/vsock: refuse CID assigned to theguest->hosttransportRFC: https://patchwork.ozlabs.org/cover/1168442/
v1: https://patchwork.ozlabs.org/cover/1181986/
I'm applying this as-is, if there is feedback changes required on 11, 12, and 15 please deal with this using follow-up patches.
Thanks.
Stefano Garzarella
maintainerQuoted 10 lines · David Miller
From: Stefano Garzarella <[email protected]>
Date: Thu, 14 Nov 2019 10:57:35 +0100Quoted 7 lines
Most of the patches are reviewed by Dexuan, Stefan, and Jorgen. The following patches need reviews:
- [11/15] vsock: add multi-transports support
- [12/15] vsock/vmci: registervmci_transportonly when VMCI guest/host are active
- [15/15] vhost/vsock: refuse CID assigned to theguest->hosttransport
Quoted 5 lines
Quoted 2 lines
RFC: https://patchwork.ozlabs.org/cover/1168442/
v1: https://patchwork.ozlabs.org/cover/1181986/I'm applying this as-is, if there is feedback changes required on 11, 12, and 15 please deal with this using follow-up patches.
Thank you very much,
Stefano