Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp898860ybp; Fri, 11 Oct 2019 06:12:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIfPj161bfc+y3Yfl2cbIGdAyMwAG9EmqiKHgmHNoSlxf3YSUVxdpZWaGLSdW9BDfFpu2O X-Received: by 2002:a17:906:5e19:: with SMTP id n25mr14059698eju.131.1570799528681; Fri, 11 Oct 2019 06:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570799528; cv=none; d=google.com; s=arc-20160816; b=Hasu0M+Wj9Fy5upNTfU57qCI94rbRMhaQRTlrZd62K+ntkZ8tJjG368tY0SeRjyYHd lYpgq0DvcWAMn+MOXIzXSdoYyuk0pd/4t1Ci2fxZ32Fi2lHmBwYABHVcEF/Gcia4UF8R YoJrEYE4nyQnRbGRvJTt/JMaVzui0qwEV9JaAIGsaL9ntBL6hlkKTdxSnymc9Y2swLLL m/A9fey0501rNbqJ1XYa+3lHFceXl0ZTOm8vU4lSgMfmvnq+/h829MzFxflwz14W5GqU 0DRELJDwp7JNmpDEaKGG92591OCscoAXk1NK6NWO8dQO/JG3+jm9Tx/QHH12Z6keoR0K 20tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=r73yImiLMiieJneWIEbFrfabJU43Q9n9IyjV4JcnS/k=; b=I4+Y5K5i1jB2ulSFl2svo9QT1kkemRe6Kk30saZr0Q/Wg7+bLIQOLoy/s9V3iJ+CCZ MRaNfL36sLjW/opZ2ja+CggXTp3o8x2Ci9+X/ILE1Mzrh/Qj+tBGizRJ+EvGG8gJFe/u 7BCEadBs8T6qnNweCW5NtuoSVEHn5mfLos6M9DwDca+Y3nKxtRBjNiZRa5k0dsMPUUui 6zGI/w/6MNNKDhsw+RoY5gdjuRHcWfijQi/1Yln0B2MC0b73rQVEE8WlUyd7FWPaNcuS YU8Xw9Id+AKVURExuw+rT1Moy3CF2mbAQ+vkINpGvfmKBMxvP4cXeESqhDbQLotwEkFd vI2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si5400763ejw.116.2019.10.11.06.11.44; Fri, 11 Oct 2019 06:12:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728593AbfJKNIP (ORCPT + 99 others); Fri, 11 Oct 2019 09:08:15 -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 Content-Transfer-Encoding: 8bit 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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, -- 2.21.0