From patchwork Tue Nov 19 11:01:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 11251739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F40CE6C1 for ; Tue, 19 Nov 2019 11:01:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D472A22304 for ; Tue, 19 Nov 2019 11:01:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="clPkmOff" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727822AbfKSLBp (ORCPT ); Tue, 19 Nov 2019 06:01:45 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:28406 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727811AbfKSLBo (ORCPT ); Tue, 19 Nov 2019 06:01:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574161303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k/VeJds5qaMYhPiq90nAYjkDf0ayvTRObqcxf9AwYA8=; b=clPkmOffwDdWZI6uUo9cOdg+jipbQ5iZOD3rkYja97SNf+MXvFyQw18JKUhyifDKpk+dJr aVobFLt8NYogIiuEFUG1J4qljCvFdQCkPFXSxwnFNHlWfMQyQ1SZdj7jgqz7MlxaZ9a0TI 9mE53WG1buF3TEEGmhVojxZ5AxuygVo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-iIIW8aj3MP-9gpfHsmbf1A-1; Tue, 19 Nov 2019 06:01:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DAA3B107ACE8; Tue, 19 Nov 2019 11:01:38 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-41.ams2.redhat.com [10.36.117.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0764260BE0; Tue, 19 Nov 2019 11:01:36 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, Dexuan Cui , Stefan Hajnoczi , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, "David S. Miller" , Jorgen Hansen Subject: [PATCH net-next 5/6] vsock: use local transport when it is loaded Date: Tue, 19 Nov 2019 12:01:20 +0100 Message-Id: <20191119110121.14480-6-sgarzare@redhat.com> In-Reply-To: <20191119110121.14480-1-sgarzare@redhat.com> References: <20191119110121.14480-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: iIIW8aj3MP-9gpfHsmbf1A-1 X-Mimecast-Spam-Score: 0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that we have a transport that can handle the local communication, we can use it when it is loaded. A socket will use the local transport (loopback) when the remote CID is: - equal to VMADDR_CID_LOCAL - or equal to transport_g2h->get_local_cid(), if transport_g2h is loaded (this allows us to keep the same behavior implemented by virtio and vmci transports) - or equal to VMADDR_CID_HOST, if transport_g2h is not loaded Signed-off-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index c9e5bad59dc1..40bbb2a17e3d 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -388,6 +388,21 @@ void vsock_enqueue_accept(struct sock *listener, struct sock *connected) } EXPORT_SYMBOL_GPL(vsock_enqueue_accept); +static bool vsock_use_local_transport(unsigned int remote_cid) +{ + if (!transport_local) + return false; + + if (remote_cid == VMADDR_CID_LOCAL) + return true; + + if (transport_g2h) { + return remote_cid == transport_g2h->get_local_cid(); + } else { + return remote_cid == VMADDR_CID_HOST; + } +} + static void vsock_deassign_transport(struct vsock_sock *vsk) { if (!vsk->transport) @@ -404,9 +419,10 @@ 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_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_LOCAL or g2h->local_cid or VMADDR_CID_HOST if + * g2h is not loaded, will use local transport; + * - remote CID == VMADDR_CID_HOST or VMADDR_CID_HYPERVISOR, 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) @@ -420,9 +436,10 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) new_transport = transport_dgram; break; case SOCK_STREAM: - if (remote_cid <= VMADDR_CID_HOST || - (transport_g2h && - remote_cid == transport_g2h->get_local_cid())) + if (vsock_use_local_transport(remote_cid)) + new_transport = transport_local; + else if (remote_cid == VMADDR_CID_HOST || + remote_cid == VMADDR_CID_HYPERVISOR) new_transport = transport_g2h; else new_transport = transport_h2g; @@ -459,6 +476,9 @@ bool vsock_find_cid(unsigned int cid) if (transport_h2g && cid == VMADDR_CID_HOST) return true; + if (transport_local && cid == VMADDR_CID_LOCAL) + return true; + return false; } EXPORT_SYMBOL_GPL(vsock_find_cid);