netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
To: Stefan Hajnoczi <stefanha@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Bobby Eshleman <bobby.eshleman@bytedance.com>
Cc: <kvm@vger.kernel.org>,
	<virtualization@lists.linux-foundation.org>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<kernel@sberdevices.ru>, <oxffffaa@gmail.com>,
	<avkrasnov@sberdevices.ru>,
	Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Subject: [RFC PATCH v5 02/17] vhost/vsock: read data from non-linear skb
Date: Sat, 1 Jul 2023 09:22:55 +0300	[thread overview]
Message-ID: <20230701062310.3397129-3-AVKrasnov@sberdevices.ru> (raw)
In-Reply-To: <20230701062310.3397129-1-AVKrasnov@sberdevices.ru>

This adds copying to guest's virtio buffers from non-linear skbs. Such
skbs are created by protocol layer when MSG_ZEROCOPY flags is used. It
replaces call of 'copy_to_iter()' to 'skb_copy_datagram_iter()'- second
function can read data from non-linear skb. Also this patch uses field
'frag_off' from skb control block. This field shows current offset to
read data from skb which could be both linear or not.

Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
---
 Changelog:
 v4 -> v5:
  * Use local variable for 'frag_off'.
  * Update commit message by adding some details about 'frag_off' field.
  * R-b from Bobby Eshleman removed due to patch update.

 drivers/vhost/vsock.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 6578db78f0ae..cb00e0e059e4 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -114,6 +114,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 		struct sk_buff *skb;
 		unsigned out, in;
 		size_t nbytes;
+		u32 frag_off;
 		int head;
 
 		skb = virtio_vsock_skb_dequeue(&vsock->send_pkt_queue);
@@ -156,7 +157,8 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 		}
 
 		iov_iter_init(&iov_iter, ITER_DEST, &vq->iov[out], in, iov_len);
-		payload_len = skb->len;
+		frag_off = VIRTIO_VSOCK_SKB_CB(skb)->frag_off;
+		payload_len = skb->len - frag_off;
 		hdr = virtio_vsock_hdr(skb);
 
 		/* If the packet is greater than the space available in the
@@ -197,8 +199,10 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 			break;
 		}
 
-		nbytes = copy_to_iter(skb->data, payload_len, &iov_iter);
-		if (nbytes != payload_len) {
+		if (skb_copy_datagram_iter(skb,
+					   frag_off,
+					   &iov_iter,
+					   payload_len)) {
 			kfree_skb(skb);
 			vq_err(vq, "Faulted on copying pkt buf\n");
 			break;
@@ -212,13 +216,13 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
 		vhost_add_used(vq, head, sizeof(*hdr) + payload_len);
 		added = true;
 
-		skb_pull(skb, payload_len);
+		VIRTIO_VSOCK_SKB_CB(skb)->frag_off += payload_len;
 		total_len += payload_len;
 
 		/* If we didn't send all the payload we can requeue the packet
 		 * to send it with the next available buffer.
 		 */
-		if (skb->len > 0) {
+		if (VIRTIO_VSOCK_SKB_CB(skb)->frag_off < skb->len) {
 			hdr->flags |= cpu_to_le32(flags_to_restore);
 
 			/* We are queueing the same skb to handle
-- 
2.25.1


  parent reply	other threads:[~2023-07-01  6:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-01  6:22 [RFC PATCH v5 00/17] vsock: MSG_ZEROCOPY flag support Arseniy Krasnov
2023-07-01  6:22 ` [RFC PATCH v5 01/17] vsock/virtio: read data from non-linear skb Arseniy Krasnov
2023-07-01  6:22 ` Arseniy Krasnov [this message]
2023-07-01  6:22 ` [RFC PATCH v5 03/17] vsock/virtio: support to send " Arseniy Krasnov
2023-07-01  6:22 ` [RFC PATCH v5 04/17] vsock/virtio: non-linear skb handling for tap Arseniy Krasnov
2023-07-01  6:22 ` [RFC PATCH v5 05/17] vsock/virtio: MSG_ZEROCOPY flag support Arseniy Krasnov
2023-07-01  6:22 ` [RFC PATCH v5 06/17] vsock: fix EPOLLERR set on non-empty error queue Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 07/17] vsock: read from socket's " Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 08/17] vsock: check for MSG_ZEROCOPY support on send Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 09/17] vsock: enable SOCK_SUPPORT_ZC bit Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 10/17] vhost/vsock: support MSG_ZEROCOPY for transport Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 11/17] vsock/virtio: " Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 12/17] vsock/loopback: " Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5] vsock: enable setting SO_ZEROCOPY Arseniy Krasnov
2023-07-01  6:26   ` Arseniy Krasnov
2023-07-01  6:38     ` Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 14/17] docs: net: description of MSG_ZEROCOPY for AF_VSOCK Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 15/17] test/vsock: MSG_ZEROCOPY flag tests Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 16/17] test/vsock: MSG_ZEROCOPY support for vsock_perf Arseniy Krasnov
2023-07-01  6:23 ` [RFC PATCH v5 17/17] test/vsock: io_uring rx/tx tests Arseniy Krasnov
2023-07-01  6:45 ` [RFC PATCH v5 00/17] vsock: MSG_ZEROCOPY flag support Arseniy Krasnov
2023-07-01  6:39 Arseniy Krasnov
2023-07-01  6:39 ` [RFC PATCH v5 02/17] vhost/vsock: read data from non-linear skb Arseniy Krasnov
2023-07-06 16:49   ` Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230701062310.3397129-3-AVKrasnov@sberdevices.ru \
    --to=avkrasnov@sberdevices.ru \
    --cc=bobby.eshleman@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jasowang@redhat.com \
    --cc=kernel@sberdevices.ru \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=oxffffaa@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).