From patchwork Fri Oct 11 13:07:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 11185441 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 B161F14DB for ; Fri, 11 Oct 2019 13:08:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C22121D56 for ; Fri, 11 Oct 2019 13:08:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728550AbfJKNIK (ORCPT ); Fri, 11 Oct 2019 09:08:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36798 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728537AbfJKNIJ (ORCPT ); Fri, 11 Oct 2019 09:08:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F4703067288; Fri, 11 Oct 2019 13:08:09 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-54.ams2.redhat.com [10.36.117.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AE6160A9F; Fri, 11 Oct 2019 13:08:07 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, Jorgen Hansen , "David S. Miller" , "Michael S. Tsirkin" , Stefan Hajnoczi , Adit Ranadive , Jason Wang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 1/2] vsock: add half-closed socket details in the implementation notes Date: Fri, 11 Oct 2019 15:07:57 +0200 Message-Id: <20191011130758.22134-2-sgarzare@redhat.com> In-Reply-To: <20191011130758.22134-1-sgarzare@redhat.com> References: <20191011130758.22134-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 11 Oct 2019 13:08:09 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vmci_transport never allowed half-closed socket on the host side. Since we want to have the same behaviour across all transports, we add a section in the "Implementation notes". Cc: Jorgen Hansen Cc: Adit Ranadive Signed-off-by: Stefano Garzarella --- net/vmw_vsock/af_vsock.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 2ab43b2bba31..27df57c2024b 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -83,6 +83,10 @@ * TCP_ESTABLISHED - connected * TCP_CLOSING - disconnecting * TCP_LISTEN - listening + * + * - Half-closed socket is supported only on the guest side. recv() on the host + * side should return EOF when the guest closes a connection, also if some + * data is still in the receive queue. */ #include From patchwork Fri Oct 11 13:07:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 11185439 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 1093D14DB for ; Fri, 11 Oct 2019 13:08:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EFDD221D71 for ; Fri, 11 Oct 2019 13:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728583AbfJKNIO (ORCPT ); Fri, 11 Oct 2019 09:08:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51694 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728568AbfJKNIM (ORCPT ); Fri, 11 Oct 2019 09:08:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 046D588384F; Fri, 11 Oct 2019 13:08:12 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-54.ams2.redhat.com [10.36.117.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF76160623; Fri, 11 Oct 2019 13:08:09 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, Jorgen Hansen , "David S. Miller" , "Michael S. Tsirkin" , Stefan Hajnoczi , Adit Ranadive , Jason Wang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 2/2] vhost/vsock: don't allow half-closed socket in the host Date: Fri, 11 Oct 2019 15:07:58 +0200 Message-Id: <20191011130758.22134-3-sgarzare@redhat.com> In-Reply-To: <20191011130758.22134-1-sgarzare@redhat.com> References: <20191011130758.22134-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Fri, 11 Oct 2019 13:08:12 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org vmci_transport never allowed half-closed socket on the host side. In order to provide the same behaviour, we changed the vhost_transport_stream_has_data() to return 0 (no data available) if the peer (guest) closed the connection. Signed-off-by: Stefano Garzarella --- drivers/vhost/vsock.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 9f57736fe15e..754120aa4478 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -58,6 +58,21 @@ static u32 vhost_transport_get_local_cid(void) return VHOST_VSOCK_DEFAULT_HOST_CID; } +static s64 vhost_transport_stream_has_data(struct vsock_sock *vsk) +{ + /* vmci_transport doesn't allow half-closed socket on the host side. + * recv() on the host side returns EOF when the guest closes a + * connection, also if some data is still in the receive queue. + * + * In order to provide the same behaviour, we always return 0 + * (no data available) if the peer (guest) closed the connection. + */ + if (vsk->peer_shutdown == SHUTDOWN_MASK) + return 0; + + return virtio_transport_stream_has_data(vsk); +} + /* Callers that dereference the return value must hold vhost_vsock_mutex or the * RCU read lock. */ @@ -804,7 +819,7 @@ static struct virtio_transport vhost_transport = { .stream_enqueue = virtio_transport_stream_enqueue, .stream_dequeue = virtio_transport_stream_dequeue, - .stream_has_data = virtio_transport_stream_has_data, + .stream_has_data = vhost_transport_stream_has_data, .stream_has_space = virtio_transport_stream_has_space, .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, .stream_is_active = virtio_transport_stream_is_active,