Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753454AbdHXPxx (ORCPT ); Thu, 24 Aug 2017 11:53:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46982 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752759AbdHXPxv (ORCPT ); Thu, 24 Aug 2017 11:53:51 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3ADAC40430A Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=stefanha@redhat.com Date: Thu, 24 Aug 2017 16:53:45 +0100 From: Stefan Hajnoczi To: Dexuan Cui Cc: "davem@davemloft.net" , "netdev@vger.kernel.org" , "devel@linuxdriverproject.org" , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , George Zhang , Jorgen Hansen , Michal Kubecek , 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 net-next 3/3] hv_sock: implements Hyper-V transport for Virtual Sockets (AF_VSOCK) Message-ID: <20170824155345.GA2512@stefanha-x1.localdomain> References: <20170817145551.GI5539@stefanha-x1.localdomain> <20170822101433.GC16799@stefanha-x1.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 24 Aug 2017 15:53:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3093 Lines: 80 On Tue, Aug 22, 2017 at 09:40:01PM +0000, Dexuan Cui wrote: > > From: Stefan Hajnoczi [mailto:stefanha@redhat.com] > > On Fri, Aug 18, 2017 at 10:23:54PM +0000, Dexuan Cui wrote: > > > > > +static bool hvs_stream_allow(u32 cid, u32 port) > > > > > +{ > > > > > + static const u32 valid_cids[] = { > > > > > + VMADDR_CID_ANY, > > > > > > > > Is this for loopback? > > > > > > No, we don't support lookback in Linux VM, at least for now. > > > In our Linux implementation, Linux VM can only connect to the host, and > > > here when Linux VM calls connect(), I treat VMADDR_CID_ANY > > > the same as VMADDR_CID_HOST. > > > > VMCI and virtio-vsock do not treat connect(VMADDR_CID_ANY) the same as > > connect(VMADDR_CID_HOST). It is an error to connect to VMADDR_CID_ANY. > > Ok. Then I'll only allow VMADDR_CID_HOST as the destination CID, since > we don't support loopback mode. > > > > > > + /* The host's port range [MIN_HOST_EPHEMERAL_PORT, 0xFFFFFFFF) > > > > is > > > > > + * reserved as ephemeral ports, which are used as the host's ports > > > > > + * when the host initiates connections. > > > > > + */ > > > > > + if (port > MAX_HOST_LISTEN_PORT) > > > > > + return false; > > > > > > > > Without this if statement the guest will attempt to connect. I guess > > > > there will be no listen sockets above MAX_HOST_LISTEN_PORT, so the > > > > connection attempt will fail. > > > > > > You're correct. > > > To use the vsock common infrastructure, we have to map Hyper-V's > > > GUID to int , and hence we must limit > > > the port range we can listen() on to [0, MAX_LISTEN_PORT], i.e. > > > we can only use half of the whole 32-bit port space for listen(). > > > This is detailed in the long comments starting at about Line 100. > > > > > > > ...but hardcode this knowledge into the guest driver? > > > I'd like the guest's connect() to fail immediately here. > > > IMO this is better than a connect timeout. :-) > > > > Thanks for explaining. Perhaps the comment could be updated: > > > > /* The host's port range [MIN_HOST_EPHEMERAL_PORT, 0xFFFFFFFF) is > > * reserved as ephemeral ports, which are used as the host's ports when > > * the host initiates connections. > > * > > * Perform this check in the guest so an immediate error is produced > > * instead of a timeout. > > */ > > > > Stefan > > Thank you, Stefan! > Please see the below for the updated version of the function: > > static bool hvs_stream_allow(u32 cid, u32 port) > { > /* The host's port range [MIN_HOST_EPHEMERAL_PORT, 0xFFFFFFFF) is > * reserved as ephemeral ports, which are used as the host's ports > * when the host initiates connections. > * > * Perform this check in the guest so an immediate error is produced > * instead of a timeout. > */ > if (port > MAX_HOST_LISTEN_PORT) > return false; > > if (cid == VMADDR_CID_HOST) > return true; > > return false; > } > > I'll send a v2 of the patch later today. Great, thanks!