Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932893AbdHVNHJ (ORCPT ); Tue, 22 Aug 2017 09:07:09 -0400 Received: from mail-cys01nam02on0069.outbound.protection.outlook.com ([104.47.37.69]:52160 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932787AbdHVNHH (ORCPT ); Tue, 22 Aug 2017 09:07:07 -0400 From: "Jorgen S. Hansen" To: Stefan Hajnoczi CC: Dexuan Cui , "davem@davemloft.net" , "netdev@vger.kernel.org" , "gregkh@linuxfoundation.org" , "devel@linuxdriverproject.org" , KY Srinivasan , Haiyang Zhang , "Stephen Hemminger" , George Zhang , Michal Kubecek , Asias He , "Vitaly Kuznetsov" , Cathy Avery , "jasowang@redhat.com" , Rolf Neugebauer , Dave Scott , "Marcelo Cerri" , "apw@canonical.com" , "olaf@aepfle.de" , "joe@perches.com" , "linux-kernel@vger.kernel.org" , Dan Carpenter Subject: Re: [PATCH] vsock: only load vmci transport on VMware hypervisor by default Thread-Topic: [PATCH] vsock: only load vmci transport on VMware hypervisor by default Thread-Index: AdMXLqHUpz8ZGmCVQCq3Yks74VajMAAMewiAAALTwAAAF9gwEAAbKDYAAA5QEwAAruLPgAAGuDGA Date: Tue, 22 Aug 2017 13:07:04 +0000 Message-ID: References: <20170817135559.GG5539@stefanha-x1.localdomain> <04460E3B-B213-4090-96CD-00CEEBE6AC32@vmware.com> <20170818153716.GB17572@stefanha-x1.localdomain> <20170822095437.GB16799@stefanha-x1.localdomain> In-Reply-To: <20170822095437.GB16799@stefanha-x1.localdomain> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [80.197.119.203] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY1PR05MB2730;20:V8OJvLG5D+83LBIRujKHsJXYzwlxcElwmjwiOCoDiybTfrgopRbUlfW8bqDJ6AletyrxD6HOOeo/OkUykHqVG2+106ez1DT6HPDJY1pWYVieZ5Ra03/WXI25xD5CIEET5p4s89B7xRLV2CmyiHoDBluAYS8p+3DhZou3xZR/kyU= x-ms-office365-filtering-correlation-id: b6366552-2f1b-461f-34e7-08d4e95eaf60 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(2017052603168)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CY1PR05MB2730; x-ms-traffictypediagnostic: CY1PR05MB2730: authentication-results: spf=none (sender IP is ) smtp.mailfrom=jhansen@vmware.com; x-exchange-antispam-report-test: UriScan:(278428928389397)(21532816269658); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6041248)(20161123558100)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY1PR05MB2730;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY1PR05MB2730; x-forefront-prvs: 04073E895A x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(24454002)(199003)(377454003)(189002)(53546010)(82746002)(83716003)(101416001)(54356999)(50986999)(478600001)(25786009)(86362001)(7416002)(5660300001)(6506006)(6486002)(6916009)(8676002)(81156014)(77096006)(81166006)(4326008)(8936002)(3846002)(102836003)(189998001)(6116002)(97736004)(76176999)(3280700002)(2950100002)(3660700001)(7736002)(105586002)(305945005)(106356001)(229853002)(36756003)(14454004)(6512007)(53936002)(54906002)(8666007)(33656002)(110136004)(6246003)(6436002)(2900100001)(93886005)(68736007)(99286003)(2906002)(66066001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR05MB2730;H:CY1PR05MB2217.namprd05.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" Content-ID: <910DD74B3469E64E8E9951A082C45246@namprd05.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Aug 2017 13:07:04.3035 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR05MB2730 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id v7MD7D7q022143 Content-Length: 3511 Lines: 60 > On Aug 22, 2017, at 11:54 AM, Stefan Hajnoczi wrote: > > On Fri, Aug 18, 2017 at 11:07:37PM +0000, Dexuan Cui wrote: >>> Not all features need to be supported. For example, VMCI supports >>> SOCK_DGRAM while Hyper-V and virtio do not. But features that are >>> available should behave identically. >> I totally agree, though I'm afraid Hyper-V may have a little more limitations >> compared to VMware/KVM duo to the <--> >> mapping. >> >>>> Can we use the 'protocol' parameter in the socket() function: >>>> int socket(int domain, int type, int protocol) >>>> >>>> IMO currently the 'protocol' is not really used. >>>> I think we can modify __vsock_core_init() to allow multiple transport layers >>> to >>>> be registered, and we can define different 'protocol' numbers for >>>> VMware/KVM/Hyper-V, and ask the application to explicitly specify what >>> should >>>> be used. Considering compatibility, we can use the default transport in a >>> given >>>> VM depending on the underlying hypervisor. >>> >>> I think AF_VSOCK should hide the transport from users/applications. >> Ideally yes, but let's consider the KVM-on-KVM nested scenario: when >> an application in the Level-1 VM creates an AF_VSOCK socket and call >> connect() for it, how can we know if the app is trying to connect to >> the Level-0 host, or connect to the Level-2 VM? We can't. > > We *can* by looking at the destination CID. Please take a look at > drivers/misc/vmw_vmci/vmci_route.c:vmci_route() to see how VMCI handles > nested virt. > > It boils down to something like this: > > static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, > int addr_len, int flags) > { > ... > if (remote_addr.svm_cid == VMADDR_CID_HOST) > transport = host_transport; > else > transport = guest_transport; > > It's easy for connect(2) but Jorgen mentioned it's harder for listen(2) > because the socket would need to listen on both transports. We define > two new constants VMADDR_CID_LISTEN_FROM_GUEST and > VMADDR_CID_LISTEN_FROM_HOST for bind(2) so that applications can decide > which side to listen on. If a socket is bound to VMADDR_CID_HOST, we would consider that socket as bound to the host side transport, so that would be the same as VMADDR_CID_LISTEN_FROM_GUEST. For the guest, we have IOCTL_VM_SOCKETS_GET_LOCAL_CID, so that could be used to get and bind a socket to the guest transport (VMCI will always return the guest CID as the local one, if the VMCI driver is used in a guest, and it looks like virtio will do the same). We could treat VMADDR_CID_ANY as always being the guest transport, since that is the use case where you don’t know upfront what your CID is, if we don’t want to listen on all transports. So we would use the host transport, if a socket is bound to VMADDR_CID_HOST, or if there is no guest transport, and in all other cases use the guest transport. However, having a couple of symbolic names like you suggest certainly makes it more obvious, and could be used in combination with this. It would be a plus if existing applications would function as intended in most cases. > Or the listen socket could simply listen to > both sides. The only problem here would be the potential for a guest and a host app to have a conflict wrt port numbers, even though they would be able to operate fine, if restricted to their appropriate transport. Thanks, Jorgen