From patchwork Fri Dec 11 10:32:38 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: 11967863 X-Patchwork-Delegate: kuba@kernel.org 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=-18.8 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 84105C2BB48 for ; Fri, 11 Dec 2020 10:34:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61D8A23EF1 for ; Fri, 11 Dec 2020 10:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387795AbgLKKea (ORCPT ); Fri, 11 Dec 2020 05:34:30 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:35271 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730586AbgLKKdr (ORCPT ); Fri, 11 Dec 2020 05:33:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1607682827; x=1639218827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oMa58ipO9lk82GqsUITsDZKmPapfMMJiBG26d4CUhXw=; b=YXLnjiqPrSlCYQN83daa7vq/HrN6okOklrpDP3LARz2os2PDBjkNNRSq ZpeA9SRLpDXl9qRTktiuGF5ZqUPrHEHr76kZTvikYfH8VnSw5Fc7uQNVy qYPME+rNvuswVT/fo7fdiZFUzqqQk4y2OEXPB4ZZYCH3VRqGtZFMaiHt6 U=; X-IronPort-AV: E=Sophos;i="5.78,411,1599523200"; d="scan'208";a="103438578" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-c6afef2e.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 11 Dec 2020 10:33:00 +0000 Received: from EX13D16EUB003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2c-c6afef2e.us-west-2.amazon.com (Postfix) with ESMTPS id EAE48A202D; Fri, 11 Dec 2020 10:32:58 +0000 (UTC) Received: from 38f9d34ed3b1.ant.amazon.com (10.43.162.252) by EX13D16EUB003.ant.amazon.com (10.43.166.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 11 Dec 2020 10:32:53 +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 v3 1/4] vm_sockets: Add flags field in the vsock address data structure Date: Fri, 11 Dec 2020 12:32:38 +0200 Message-ID: <20201211103241.17751-2-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20201211103241.17751-1-andraprs@amazon.com> References: <20201211103241.17751-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.252] X-ClientProxiedBy: EX13D28UWB003.ant.amazon.com (10.43.161.60) To EX13D16EUB003.ant.amazon.com (10.43.166.99) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 flags 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 different use cases such as nested VMs and sibling VMs. This field can be set when initializing the vsock address variable used for the connect() call. Changelog v2 -> v3 * Add "svm_flags" as a new field, not reusing "svm_reserved1". v1 -> v2 * Update the field name to "svm_flags". * Split the current patch in 2 patches. Signed-off-by: Andra Paraschiv Reviewed-by: Stefano Garzarella --- include/uapi/linux/vm_sockets.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/vm_sockets.h b/include/uapi/linux/vm_sockets.h index fd0ed7221645d..619f8e9d55ca4 100644 --- a/include/uapi/linux/vm_sockets.h +++ b/include/uapi/linux/vm_sockets.h @@ -148,10 +148,13 @@ struct sockaddr_vm { unsigned short svm_reserved1; unsigned int svm_port; unsigned int svm_cid; + unsigned short svm_flags; unsigned char svm_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - sizeof(unsigned short) - - sizeof(unsigned int) - sizeof(unsigned int)]; + sizeof(unsigned int) - + sizeof(unsigned int) - + sizeof(unsigned short)]; }; #define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9) From patchwork Fri Dec 11 10:32:39 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: 11967879 X-Patchwork-Delegate: kuba@kernel.org 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=-18.8 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 0CDB8C433FE for ; Fri, 11 Dec 2020 10:37:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4C5923EF1 for ; Fri, 11 Dec 2020 10:37:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391659AbgLKKgZ (ORCPT ); Fri, 11 Dec 2020 05:36:25 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:30305 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389482AbgLKKgG (ORCPT ); Fri, 11 Dec 2020 05:36:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1607682965; x=1639218965; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q/GCUUPD33jv3eCey1WgNMDq3Oa0SVVCKraSLnKr6Bk=; b=fMhQAizr03+TtY0p8Z4B2m6qz5SsRHlmaM7Vs+/+shEtNaZYdvE+mzV/ ny30YdumEpf0NaPI6PBgFLp+Rxa/pNvIrgERBjyx0n0MokP+15eee+P5R gJ8ScH0hX4NHvfeiYv6f+1RN1bNEag5Y4LujINBHU4z+yLAdkV5ROZJ16 Y=; X-IronPort-AV: E=Sophos;i="5.78,411,1599523200"; d="scan'208";a="70498097" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2c-397e131e.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 11 Dec 2020 10:35:18 +0000 Received: from EX13D16EUB003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-397e131e.us-west-2.amazon.com (Postfix) with ESMTPS id 7341EA03F7; Fri, 11 Dec 2020 10:33:05 +0000 (UTC) Received: from 38f9d34ed3b1.ant.amazon.com (10.43.162.252) by EX13D16EUB003.ant.amazon.com (10.43.166.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 11 Dec 2020 10:32:58 +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 v3 2/4] vm_sockets: Add VMADDR_FLAG_TO_HOST vsock flag Date: Fri, 11 Dec 2020 12:32:39 +0200 Message-ID: <20201211103241.17751-3-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20201211103241.17751-1-andraprs@amazon.com> References: <20201211103241.17751-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.252] X-ClientProxiedBy: EX13D28UWB003.ant.amazon.com (10.43.161.60) To EX13D16EUB003.ant.amazon.com (10.43.166.99) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add VMADDR_FLAG_TO_HOST vsock flag that is used to setup a vsock connection where all the packets are forwarded to the host. Then, using this type of vsock channel, vsock communication between sibling VMs can be built on top of it. Changelog v2 -> v3 * Update comments to mention when the flag is set in the connect and listen paths. v1 -> v2 * New patch in v2, it was split from the first patch in the series. * Remove the default value for the vsock flags field. * Update the naming for the vsock flag to "VMADDR_FLAG_TO_HOST". Signed-off-by: Andra Paraschiv Reviewed-by: Stefano Garzarella --- include/uapi/linux/vm_sockets.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/uapi/linux/vm_sockets.h b/include/uapi/linux/vm_sockets.h index 619f8e9d55ca4..c99ed29602345 100644 --- a/include/uapi/linux/vm_sockets.h +++ b/include/uapi/linux/vm_sockets.h @@ -114,6 +114,26 @@ #define VMADDR_CID_HOST 2 +/* The current default use case for the vsock channel is the following: + * 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. + * + * Set this flag value in the sockaddr_vm corresponding field if the vsock + * packets need to be always forwarded to the host. Using this behavior, + * vsock communication between sibling VMs can be setup. + * + * This way can explicitly distinguish between vsock channels created for + * different use cases, such as nested VMs (or local communication between + * guest and host) and sibling VMs. + * + * The flag can be set in the connect logic in the user space application flow. + * In the listen logic (from kernel space) the flag is set on the remote peer + * address. This happens for an incoming connection when it is routed from the + * host and comes from the guest (local CID and remote CID > VMADDR_CID_HOST). + */ +#define VMADDR_FLAG_TO_HOST 0x0001 + /* Invalid vSockets version. */ #define VM_SOCKETS_INVALID_VERSION -1U From patchwork Fri Dec 11 10:32:40 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: 11967865 X-Patchwork-Delegate: kuba@kernel.org 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=-18.8 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 73A5FC4167B for ; Fri, 11 Dec 2020 10:34:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34EA623ED2 for ; Fri, 11 Dec 2020 10:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732812AbgLKKe1 (ORCPT ); Fri, 11 Dec 2020 05:34:27 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:35287 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730706AbgLKKdv (ORCPT ); Fri, 11 Dec 2020 05:33:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1607682831; x=1639218831; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3eRzJpEWDyvkFeasgrVlf1SEht8OrvPE8hRj49UxTs8=; b=tBDi+r+pX21ibwfWBNJ68msHfkfYpss3axi8LJTkJ6+4KSa+giv2A9jY Wy/AXu/EJjXr0Sp6qVixu2XDOJ4mVSaqHkZeJ9Z1pmLWRuiXBJhVjrsnB QbISv/LnJEPuilhwNjAlHbfUVb0VvFvnhQzVCnfS3LHROc8+0i7YTHgwm 4=; X-IronPort-AV: E=Sophos;i="5.78,411,1599523200"; d="scan'208";a="103438615" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-cc689b93.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 11 Dec 2020 10:33:10 +0000 Received: from EX13D16EUB003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-cc689b93.us-west-2.amazon.com (Postfix) with ESMTPS id 571F7120DB2; Fri, 11 Dec 2020 10:33:09 +0000 (UTC) Received: from 38f9d34ed3b1.ant.amazon.com (10.43.162.252) by EX13D16EUB003.ant.amazon.com (10.43.166.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 11 Dec 2020 10:33:03 +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 v3 3/4] af_vsock: Set VMADDR_FLAG_TO_HOST flag on the receive path Date: Fri, 11 Dec 2020 12:32:40 +0200 Message-ID: <20201211103241.17751-4-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20201211103241.17751-1-andraprs@amazon.com> References: <20201211103241.17751-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.252] X-ClientProxiedBy: EX13D28UWB003.ant.amazon.com (10.43.161.60) To EX13D16EUB003.ant.amazon.com (10.43.166.99) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The vsock flags 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 flags field. The vsock transport is also assigned on the (listen) receive path. The flags field needs to be set considering the use case. Set the value of the vsock flags of the remote address to the one targeted for packets forwarding to the host, 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. Changelog v2 -> v3 * No changes. v1 -> v2 * Set the vsock flag on the receive path in the vsock transport assignment logic. * Use bitwise operator for the vsock flag setup. * Use the updated "VMADDR_FLAG_TO_HOST" flag naming. Signed-off-by: Andra Paraschiv Reviewed-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index d10916ab45267..83d035eab0b05 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -431,6 +431,18 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) unsigned int remote_cid = vsk->remote_addr.svm_cid; int ret; + /* If the packet is coming with the source and destination CIDs higher + * than VMADDR_CID_HOST, then a vsock channel where all the packets are + * forwarded to the host should be established. Then the host will + * need to forward the packets to the guest. + * + * The flag is set on the (listen) receive path (psk is not NULL). On + * the connect path the flag can be set by the user space application. + */ + if (psk && vsk->local_addr.svm_cid > VMADDR_CID_HOST && + vsk->remote_addr.svm_cid > VMADDR_CID_HOST) + vsk->remote_addr.svm_flags |= VMADDR_FLAG_TO_HOST; + switch (sk->sk_type) { case SOCK_DGRAM: new_transport = transport_dgram; From patchwork Fri Dec 11 10:32:41 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: 11967867 X-Patchwork-Delegate: kuba@kernel.org 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=-18.8 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 E0AF2C4361B for ; Fri, 11 Dec 2020 10:35:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9781023ED2 for ; Fri, 11 Dec 2020 10:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727680AbgLKKej (ORCPT ); Fri, 11 Dec 2020 05:34:39 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:59786 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731044AbgLKKeC (ORCPT ); Fri, 11 Dec 2020 05:34:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1607682842; x=1639218842; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QoGL4bCgtJQF8SDd8b7l82mct7ezyYbpcnvXnnmfdkY=; b=u4g71bietyAso2fiAgjNMfHAiP2+yHlYQgc99+NxwcVh8bZbrXRf8XjY ooPr1ucO0oLGC+ipB1ClsiSw7DHAjFcPXLy0OJPx+muQOfagn4nYfRFtc TF2gtPMjZ67vHCOYvF28DRI0EQZYdIt1TPsOhEgzHdU/3bqJkUKiBV6Z+ 0=; X-IronPort-AV: E=Sophos;i="5.78,411,1599523200"; d="scan'208";a="95155511" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-53356bf6.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 11 Dec 2020 10:33:15 +0000 Received: from EX13D16EUB003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2a-53356bf6.us-west-2.amazon.com (Postfix) with ESMTPS id 77B58A1F13; Fri, 11 Dec 2020 10:33:14 +0000 (UTC) Received: from 38f9d34ed3b1.ant.amazon.com (10.43.162.252) by EX13D16EUB003.ant.amazon.com (10.43.166.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 11 Dec 2020 10:33:08 +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 v3 4/4] af_vsock: Assign the vsock transport considering the vsock address flags Date: Fri, 11 Dec 2020 12:32:41 +0200 Message-ID: <20201211103241.17751-5-andraprs@amazon.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20201211103241.17751-1-andraprs@amazon.com> References: <20201211103241.17751-1-andraprs@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.252] X-ClientProxiedBy: EX13D28UWB003.ant.amazon.com (10.43.161.60) To EX13D16EUB003.ant.amazon.com (10.43.166.99) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The vsock flags field can be set in the connect path (user space app) and the (listen) receive path (kernel space logic). When the vsock transport is assigned, the remote CID is used to distinguish between types of connection. Use the vsock flags value (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 VMADDR_FLAG_TO_HOST flag is set. For the other use cases, the vsock transport assignment logic is not changed. Changelog v2 -> v3 * Update bitwise check logic to not compare result to the flag value. v1 -> v2 * Use bitwise operator to check the vsock flag. * Use the updated "VMADDR_FLAG_TO_HOST" flag naming. * Merge the checks for the g2h transport assignment in one "if" block. Signed-off-by: Andra Paraschiv Reviewed-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 83d035eab0b05..7c306ecf75250 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -421,7 +421,8 @@ static void vsock_deassign_transport(struct vsock_sock *vsk) * 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 or h2g is not loaded or remote flags field + * includes VMADDR_FLAG_TO_HOST flag value, 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) @@ -429,6 +430,7 @@ 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_flags; int ret; /* If the packet is coming with the source and destination CIDs higher @@ -443,6 +445,8 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) vsk->remote_addr.svm_cid > VMADDR_CID_HOST) vsk->remote_addr.svm_flags |= VMADDR_FLAG_TO_HOST; + remote_flags = vsk->remote_addr.svm_flags; + switch (sk->sk_type) { case SOCK_DGRAM: new_transport = transport_dgram; @@ -450,7 +454,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_cid <= VMADDR_CID_HOST || !transport_h2g) + else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g || + (remote_flags & VMADDR_FLAG_TO_HOST)) new_transport = transport_g2h; else new_transport = transport_h2g;