From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6003C12BF17; Tue, 23 Jan 2024 00:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705971422; cv=none; b=bzdFmrFI1MwFmq/a+gdEktWiPAk4AASRrCYALhfV2g+uspLASa4/9C38We2Rh5ksfwiKQp461LtohNz7o0BkWa5hBtuU03UgL/jqzQzxGLmnR9UbL69QnbheZa0/89TXi9SAE4mBB097SoCR+owi+ByjXL0FqpkLcGWznmvcOSk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705971422; c=relaxed/simple; bh=+RbH7rz1y4i3ak2O/mdPtUDWqRoxGbqAwsJYmua0Vds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NO8zNxJzpE5gG32OeOQaBdHih7RMFdkZfEZq1gHrSZ3HjeHwkXKLkTGanMT4oqhoGXMpowykVkfhkt3Q16zaSxg+hfhGr+k3ITSrNnoJ+1rIoeAD1QAVFGjHAaTOcAHr8mJ62JYZXIBAgYouJZioAVuKiyWGOUjJiZL8dYKvDtk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vMVLTD9Y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vMVLTD9Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E422C433C7; Tue, 23 Jan 2024 00:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705971422; bh=+RbH7rz1y4i3ak2O/mdPtUDWqRoxGbqAwsJYmua0Vds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vMVLTD9Y5ybpLj2vamijPLnbSYk9kvj9OafvHxBDk6V7ISLSZzIIeQgFK3mddZgjv lG4Cc5CIVt7dEzzQh4Iu4fR7lYjHQqRIp6K6kMDHRRvOOhjKhry0tUMnPK/eMkSm5q eXjdNBp/qOsCpkzIg9D6zzMD9VQ6dpYDDdBhcvwc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Arseniy Krasnov , Stefano Garzarella , "Michael S. Tsirkin" , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 127/286] virtio/vsock: fix logic which reduces credit update messages Date: Mon, 22 Jan 2024 15:57:13 -0800 Message-ID: <20240122235737.032200781@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235732.009174833@linuxfoundation.org> References: <20240122235732.009174833@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arseniy Krasnov [ Upstream commit 93b80887668226180ea5f5349cc728ca6dc700ab ] Add one more condition for sending credit update during dequeue from stream socket: when number of bytes in the rx queue is smaller than SO_RCVLOWAT value of the socket. This is actual for non-default value of SO_RCVLOWAT (e.g. not 1) - idea is to "kick" peer to continue data transmission, because we need at least SO_RCVLOWAT bytes in our rx queue to wake up user for reading data (in corner case it is also possible to stuck both tx and rx sides, this is why 'Fixes' is used). Fixes: b89d882dc9fc ("vsock/virtio: reduce credit update messages") Signed-off-by: Arseniy Krasnov Reviewed-by: Stefano Garzarella Acked-by: Michael S. Tsirkin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/vmw_vsock/virtio_transport_common.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 080e8f2bf985..4102689b3348 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -340,6 +340,8 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, struct virtio_vsock_pkt *pkt; size_t bytes, total = 0; u32 free_space; + u32 fwd_cnt_delta; + bool low_rx_bytes; int err = -EFAULT; spin_lock_bh(&vvs->rx_lock); @@ -371,7 +373,10 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, } } - free_space = vvs->buf_alloc - (vvs->fwd_cnt - vvs->last_fwd_cnt); + fwd_cnt_delta = vvs->fwd_cnt - vvs->last_fwd_cnt; + free_space = vvs->buf_alloc - fwd_cnt_delta; + low_rx_bytes = (vvs->rx_bytes < + sock_rcvlowat(sk_vsock(vsk), 0, INT_MAX)); spin_unlock_bh(&vvs->rx_lock); @@ -381,9 +386,11 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, * too high causes extra messages. Too low causes transmitter * stalls. As stalls are in theory more expensive than extra * messages, we set the limit to a high value. TODO: experiment - * with different values. + * with different values. Also send credit update message when + * number of bytes in rx queue is not enough to wake up reader. */ - if (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE) { + if (fwd_cnt_delta && + (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE || low_rx_bytes)) { virtio_transport_send_credit_update(vsk, VIRTIO_VSOCK_TYPE_STREAM, NULL); -- 2.43.0