From patchwork Tue Dec 1 15:25:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paraschiv, Andra-Irina" X-Patchwork-Id: 336656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31220C83014 for ; Tue, 1 Dec 2020 15:26:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D55BC2086A for ; Tue, 1 Dec 2020 15:26:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="eVwbWXer" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391852AbgLAP0Q (ORCPT ); Tue, 1 Dec 2020 10:26:16 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:64330 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391824AbgLAP0Q (ORCPT ); Tue, 1 Dec 2020 10:26:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1606836375; x=1638372375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AaeVZAF1wZ8NpfHttbjVJiQ9rkcyAab+ouMMPH5SPnI=; b=eVwbWXer1Hi7FKjpjIvXvlpSPOBQjQnjLdS4fsa7O0Hstltk49b9Lg3x dnWzwXBtD4yBwf9SoLiDHW7RXpLVXuPETA4MHd8XDWgeKjc0p+PTF1VZO zbVdi4ILQ75BN+APH/UKkEMDvHYk8PMn/bY9Ur/Nqf7N36F4UyNt0zfEz w=; X-IronPort-AV: E=Sophos;i="5.78,384,1599523200"; d="scan'208";a="92555288" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 01 Dec 2020 15:25:24 +0000 Received: from EX13D16EUB003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id C72802421DB; Tue, 1 Dec 2020 15:25:21 +0000 (UTC) Received: from 38f9d34ed3b1.ant.amazon.com.com (10.43.162.176) by EX13D16EUB003.ant.amazon.com (10.43.166.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 1 Dec 2020 15:25:16 +0000 From: Andra Paraschiv To: netdev CC: linux-kernel , "David S . Miller" , David Duncan , Dexuan Cui , Alexander Graf , Jorgen Hansen , Jakub Kicinski , Stefano Garzarella , Stefan Hajnoczi , Vitaly Kuznetsov , Andra Paraschiv Subject: [PATCH net-next v1 1/3] vm_sockets: Include flag field in the vsock address data structure Date: Tue, 1 Dec 2020 17:25:03 +0200 Message-ID: <20201201152505.19445-2-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20201201152505.19445-1-andraprs@amazon.com> References: <20201201152505.19445-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.176] X-ClientProxiedBy: EX13D13UWA003.ant.amazon.com (10.43.160.181) To EX13D16EUB003.ant.amazon.com (10.43.166.99) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org vsock enables communication between virtual machines and the host they are running on. With the multi transport support (guest->host and host->guest), nested VMs can also use vsock channels for communication. In addition to this, by default, all the vsock packets are forwarded to the host, if no host->guest transport is loaded. This behavior can be implicitly used for enabling vsock communication between sibling VMs. Add a flag field in the vsock address data structure that can be used to explicitly mark the vsock connection as being targeted for a certain type of communication. This way, can distinguish between nested VMs and sibling VMs use cases and can also setup them at the same time. Till now, could either have nested VMs or sibling VMs at a time using the vsock communication stack. Use the already available "svm_reserved1" field and mark it as a flag field instead. This flag can be set when initializing the vsock address variable used for the connect() call. Signed-off-by: Andra Paraschiv --- include/uapi/linux/vm_sockets.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/vm_sockets.h b/include/uapi/linux/vm_sockets.h index fd0ed7221645d..58da5a91413ac 100644 --- a/include/uapi/linux/vm_sockets.h +++ b/include/uapi/linux/vm_sockets.h @@ -114,6 +114,22 @@ #define VMADDR_CID_HOST 2 +/* This sockaddr_vm flag value covers the current default use case: + * local vsock communication between guest and host and nested VMs setup. + * In addition to this, implicitly, the vsock packets are forwarded to the host + * if no host->guest vsock transport is set. + */ +#define VMADDR_FLAG_DEFAULT_COMMUNICATION 0x0000 + +/* Set this flag value in the sockaddr_vm corresponding field if the vsock + * channel needs to be setup between two sibling VMs running on the same host. + * This way can explicitly distinguish between vsock channels created for nested + * VMs (or local communication between guest and host) and the ones created for + * sibling VMs. And vsock channels for multiple use cases (nested / sibling VMs) + * can be setup at the same time. + */ +#define VMADDR_FLAG_SIBLING_VMS_COMMUNICATION 0x0001 + /* Invalid vSockets version. */ #define VM_SOCKETS_INVALID_VERSION -1U @@ -145,7 +161,7 @@ struct sockaddr_vm { __kernel_sa_family_t svm_family; - unsigned short svm_reserved1; + unsigned short svm_flag; unsigned int svm_port; unsigned int svm_cid; unsigned char svm_zero[sizeof(struct sockaddr) - From patchwork Tue Dec 1 15:25:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paraschiv, Andra-Irina" X-Patchwork-Id: 335623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B18F5C83016 for ; Tue, 1 Dec 2020 15:26:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F0F020770 for ; Tue, 1 Dec 2020 15:26:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Lu2pcPuE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391864AbgLAP0T (ORCPT ); Tue, 1 Dec 2020 10:26:19 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:32932 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391824AbgLAP0S (ORCPT ); Tue, 1 Dec 2020 10:26:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1606836378; x=1638372378; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=175i00pbzLR8fa9gozvAYFUoomwH6U7DOj8Jpaq5o/M=; b=Lu2pcPuEogztCqgGp09gOo8HQtgELf3s4rLFXfoY3bTPFsqQFcr8SWdr hsmphTUH6WG8WKKjlVTm+osVJQSab1HAFDOwNZh/gkBHb8G3w7aIAeDnD 9zahZQqzady1rX5surKImWMMkfSiHttSHvadIHwlom5GP0fljMbOHTYIn U=; X-IronPort-AV: E=Sophos;i="5.78,384,1599523200"; d="scan'208";a="100825315" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 01 Dec 2020 15:25:30 +0000 Received: from EX13D16EUB003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id 9657D240F54; Tue, 1 Dec 2020 15:25:26 +0000 (UTC) Received: from 38f9d34ed3b1.ant.amazon.com.com (10.43.162.176) by EX13D16EUB003.ant.amazon.com (10.43.166.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 1 Dec 2020 15:25:21 +0000 From: Andra Paraschiv To: netdev CC: linux-kernel , "David S . Miller" , David Duncan , Dexuan Cui , Alexander Graf , Jorgen Hansen , Jakub Kicinski , Stefano Garzarella , Stefan Hajnoczi , Vitaly Kuznetsov , Andra Paraschiv Subject: [PATCH net-next v1 2/3] virtio_transport_common: Set sibling VMs flag on the receive path Date: Tue, 1 Dec 2020 17:25:04 +0200 Message-ID: <20201201152505.19445-3-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20201201152505.19445-1-andraprs@amazon.com> References: <20201201152505.19445-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.176] X-ClientProxiedBy: EX13D13UWA003.ant.amazon.com (10.43.160.181) To EX13D16EUB003.ant.amazon.com (10.43.166.99) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The vsock flag can be set during the connect() setup logic, when initializing the vsock address data structure variable. Then the vsock transport is assigned, also considering this flag. The vsock transport is also assigned on the (listen) receive path. The flag needs to be set considering the use case. Set the vsock flag of the remote address to the one targeted for sibling VMs communication if the following conditions are met: * The source CID of the packet is higher than VMADDR_CID_HOST. * The destination CID of the packet is higher than VMADDR_CID_HOST. Signed-off-by: Andra Paraschiv --- net/vmw_vsock/virtio_transport_common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 5956939eebb78..871c84e0916b1 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1062,6 +1062,14 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt, vsock_addr_init(&vchild->remote_addr, le64_to_cpu(pkt->hdr.src_cid), le32_to_cpu(pkt->hdr.src_port)); + /* If the packet is coming with the source and destination CIDs higher + * than VMADDR_CID_HOST, then a vsock channel should be established for + * sibling VMs communication. + */ + if (vchild->local_addr.svm_cid > VMADDR_CID_HOST && + vchild->remote_addr.svm_cid > VMADDR_CID_HOST) + vchild->remote_addr.svm_flag = VMADDR_FLAG_SIBLING_VMS_COMMUNICATION; + ret = vsock_assign_transport(vchild, vsk); /* Transport assigned (looking at remote_addr) must be the same * where we received the request. From patchwork Tue Dec 1 15:25:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paraschiv, Andra-Irina" X-Patchwork-Id: 336655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FB7BC64E7B for ; Tue, 1 Dec 2020 15:27:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4EEA2084C for ; Tue, 1 Dec 2020 15:27:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="P0BYwBLu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391876AbgLAP0Y (ORCPT ); Tue, 1 Dec 2020 10:26:24 -0500 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:6198 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390460AbgLAP0X (ORCPT ); Tue, 1 Dec 2020 10:26:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1606836383; x=1638372383; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tsxlIUCNI2krlVx3neb8cyiIbG3hMUeUhuHM8BlO3mg=; b=P0BYwBLu1l3BhB1TvzpP/KPwUP4eOg+31ANouiHPhy2gYWlPw5cVG173 kEdpnBz0yQhBCvfUxdU4td+GH0Gh+rSEKT6X21R0CFhzIxeNHGYpAYt0V kkbeKgftRE1r/wcIM8CdfehJ49h0S+xiRseLlQ9EAobw+Hk+5H3dboSMF Q=; X-IronPort-AV: E=Sophos;i="5.78,384,1599523200"; d="scan'208";a="66964389" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 01 Dec 2020 15:25:36 +0000 Received: from EX13D16EUB003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (Postfix) with ESMTPS id ABA01A177C; Tue, 1 Dec 2020 15:25:31 +0000 (UTC) Received: from 38f9d34ed3b1.ant.amazon.com.com (10.43.162.176) by EX13D16EUB003.ant.amazon.com (10.43.166.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 1 Dec 2020 15:25:26 +0000 From: Andra Paraschiv To: netdev CC: linux-kernel , "David S . Miller" , David Duncan , Dexuan Cui , Alexander Graf , Jorgen Hansen , Jakub Kicinski , Stefano Garzarella , Stefan Hajnoczi , Vitaly Kuznetsov , Andra Paraschiv Subject: [PATCH net-next v1 3/3] af_vsock: Assign the vsock transport considering the vsock address flag Date: Tue, 1 Dec 2020 17:25:05 +0200 Message-ID: <20201201152505.19445-4-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20201201152505.19445-1-andraprs@amazon.com> References: <20201201152505.19445-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.176] X-ClientProxiedBy: EX13D13UWA003.ant.amazon.com (10.43.160.181) To EX13D16EUB003.ant.amazon.com (10.43.166.99) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The vsock flag has been set in the connect and (listen) receive paths. When the vsock transport is assigned, the remote CID is used to distinguish between types of connection. Use the vsock flag (in addition to the CID) from the remote address to decide which vsock transport to assign. For the sibling VMs use case, all the vsock packets need to be forwarded to the host, so always assign the guest->host transport if the vsock flag is set. For the other use cases, the vsock transport assignment logic is not changed. Signed-off-by: Andra Paraschiv --- net/vmw_vsock/af_vsock.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index d10916ab45267..bafc1cb20abd4 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -419,16 +419,21 @@ static void vsock_deassign_transport(struct vsock_sock *vsk) * (e.g. during the connect() or when a connection request on a listener * socket is received). * The vsk->remote_addr is used to decide which transport to use: - * - remote CID == VMADDR_CID_LOCAL or g2h->local_cid or VMADDR_CID_HOST if - * g2h is not loaded, will use local transport; - * - remote CID <= VMADDR_CID_HOST will use guest->host transport; - * - remote CID > VMADDR_CID_HOST will use host->guest transport; + * - remote flag == VMADDR_FLAG_SIBLING_VMS_COMMUNICATION, will always + * forward the vsock packets to the host and use guest->host transport; + * - otherwise, going forward with the remote flag default value: + * - remote CID == VMADDR_CID_LOCAL or g2h->local_cid or VMADDR_CID_HOST + * if g2h is not loaded, will use local transport; + * - remote CID <= VMADDR_CID_HOST or h2g is not loaded, will use + * guest->host transport; + * - remote CID > VMADDR_CID_HOST will use host->guest transport; */ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) { const struct vsock_transport *new_transport; struct sock *sk = sk_vsock(vsk); unsigned int remote_cid = vsk->remote_addr.svm_cid; + unsigned short remote_flag = vsk->remote_addr.svm_flag; int ret; switch (sk->sk_type) { @@ -438,6 +443,8 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) case SOCK_STREAM: if (vsock_use_local_transport(remote_cid)) new_transport = transport_local; + else if (remote_flag == VMADDR_FLAG_SIBLING_VMS_COMMUNICATION) + new_transport = transport_g2h; else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g) new_transport = transport_g2h; else