Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1081123yba; Thu, 4 Apr 2019 03:59:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwz6SXV8M9ZGsTUY+Z5dpLP+IM9xemcjwQYB9h8TR/s+SXn6f5TCm1TRye2uzxOvFrzz/F7 X-Received: by 2002:a63:707:: with SMTP id 7mr5023891pgh.390.1554375593637; Thu, 04 Apr 2019 03:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554375593; cv=none; d=google.com; s=arc-20160816; b=vIXz5RbwXk88lX8cNSLklueE7pT58bpVapVF9AS1jpvBu2SnECj84wZOqExpBXpxYL wwqZ8lu/xBZgRNRDtLjlt5i16gLN1TZGIHE/pG9Ru0pXxJigMTVnNsgISgmL1VJfsL/Z rTfINzxGMvIgKsghWqGCVwZXjb8SbOiU10hn53W93y0L+Hl2O3CiB29K4kGktC7ANeXb NVxOCTsekgRKV5hLUnsNHY+M3j7z2xSh7suMQH33UfYZsW9lHjkV+X2v7PxRS530T2Ds CUKFxkst46wQiFoout/yAOkfDf17cIsLfP1FXQQJcZem7Lep82mUW95xac5367dfFZe1 vDJg== 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=qsewfmU2qefJdHh2S6clU7TSVN+z2urW973grmHXF5Y=; b=IFiQ5u9U6ZcP5gvk9PxDGGLYEieskZICHWLMyzRxnp7irIOK2PFqGxVKSd8beRYvBw Uke4yQoFv1IueVtZvD8qfssORzrVXrx7eXAkq6+RNj3gt6BR1JzChzcqOwpwi8NwlH0j T5GPd4WXJtcM+0dBw0VCfenj6XY2HhGiMdpf1JhcD2pv1WNHoR8nMyjEKZxJCQOLyOmf PWHiMl0xYRtRRC6DuZb0Kx6+SCQROfstSjUk0GJvNg4KUfNm7Ikw302w21XG/OZh+/ip znSHlkRWUEdm8/1akNF/iQIcvW3wR8dT4+zL8BPlicLt+rPRtAJe+HAmbha2Mv6SrBQW FuhA== 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 p6si16176404pgs.407.2019.04.04.03.59.38; Thu, 04 Apr 2019 03:59:53 -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 S1729764AbfDDK6x (ORCPT + 99 others); Thu, 4 Apr 2019 06:58:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38904 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729718AbfDDK6w (ORCPT ); Thu, 4 Apr 2019 06:58:52 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 091DC19D39B; Thu, 4 Apr 2019 10:58:52 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-25.ams2.redhat.com [10.36.117.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id B52FB1001E65; Thu, 4 Apr 2019 10:58:49 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Jason Wang , "Michael S. Tsirkin" , Stefan Hajnoczi , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, "David S. Miller" Subject: [PATCH RFC 2/4] vhost/vsock: split packets to send using multiple buffers Date: Thu, 4 Apr 2019 12:58:36 +0200 Message-Id: <20190404105838.101559-3-sgarzare@redhat.com> In-Reply-To: <20190404105838.101559-1-sgarzare@redhat.com> References: <20190404105838.101559-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 04 Apr 2019 10:58:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the packets to sent to the guest are bigger than the buffer available, we can split them, using multiple buffers and fixing the length in the packet header. This is safe since virtio-vsock supports only stream sockets. Signed-off-by: Stefano Garzarella --- drivers/vhost/vsock.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index bb5fc0e9fbc2..9951b7e661f6 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -94,7 +94,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, struct iov_iter iov_iter; unsigned out, in; size_t nbytes; - size_t len; + size_t iov_len, payload_len; int head; spin_lock_bh(&vsock->send_pkt_list_lock); @@ -139,8 +139,18 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, break; } - len = iov_length(&vq->iov[out], in); - iov_iter_init(&iov_iter, READ, &vq->iov[out], in, len); + payload_len = pkt->len - pkt->off; + iov_len = iov_length(&vq->iov[out], in); + iov_iter_init(&iov_iter, READ, &vq->iov[out], in, iov_len); + + /* If the packet is greater than the space available in the + * buffer, we split it using multiple buffers. + */ + if (payload_len > iov_len - sizeof(pkt->hdr)) + payload_len = iov_len - sizeof(pkt->hdr); + + /* Set the correct length in the header */ + pkt->hdr.len = cpu_to_le32(payload_len); nbytes = copy_to_iter(&pkt->hdr, sizeof(pkt->hdr), &iov_iter); if (nbytes != sizeof(pkt->hdr)) { @@ -149,16 +159,29 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, break; } - nbytes = copy_to_iter(pkt->buf, pkt->len, &iov_iter); - if (nbytes != pkt->len) { + nbytes = copy_to_iter(pkt->buf + pkt->off, payload_len, + &iov_iter); + if (nbytes != payload_len) { virtio_transport_free_pkt(pkt); vq_err(vq, "Faulted on copying pkt buf\n"); break; } - vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len); + vhost_add_used(vq, head, sizeof(pkt->hdr) + payload_len); added = true; + pkt->off += payload_len; + + /* If we didn't send all the payload we can requeue the packet + * to send it with the next available buffer. + */ + if (pkt->off < pkt->len) { + spin_lock_bh(&vsock->send_pkt_list_lock); + list_add(&pkt->list, &vsock->send_pkt_list); + spin_unlock_bh(&vsock->send_pkt_list_lock); + continue; + } + if (pkt->reply) { int val; -- 2.20.1