Message ID | 20230603204939.1598818-3-AVKrasnov@sberdevices.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1841002vqr; Sat, 3 Jun 2023 13:56:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5pUw+wmYZpIThKnKQOrleKIzi5/4m1DlOYWJABf/ERpSvppNQKSmvDBWL18OfNstGAeWmI X-Received: by 2002:a17:902:9005:b0:1af:fbb6:23b7 with SMTP id a5-20020a170902900500b001affbb623b7mr3369437plp.3.1685825769880; Sat, 03 Jun 2023 13:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685825769; cv=none; d=google.com; s=arc-20160816; b=EXF3vSLb0XBEfqTJpz1FKi/ISch1Anos+NyFBbyaUAWjCokQuNgqin2UfXRc/LUDHP 85vvNdCHQEKExZc0/Eu2K+DvjbmmWND0j8MKuQJvToXXlYk8f0MyU06krtgGslFNfFY3 HSm35dYOav0LvXBZczj4p5jVPg9Rv8vQlUaIs0JFn+WF3fa9zouiwXASQDbIzyhauY2p iCK6cFKfZy8dKQz6DKVjiupQLisQJZSCwm+D01v1505WN2bZQBu4kZ99rRYHuYWzNAed jzZWh5WugvOZ8TpillENYN/VNzCq+Zj7CE69X/bOI3/CrS5UZAG7fULjG/EK2eIYHYPj wPww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=igltWeKmorgVWzwhU5OIAduVRvDTNdsf6zEVkCG3inE=; b=T6WHvxHvXZTl28jL33/X7n+8e25M1O9RLMAQKTv19Ym7VAiMVnYim2+3akXOJH/l/M P8gjLnm/rp9t7xGaMrrxUbZfvam/VDhgb7d5T/ej7IxE+GWbbU8VH2r59Kr2Jgy15AuV rACfQyILJO0+hC9C07zYmoBj9zbO9h8tt7MJBHt2h3mpyVLf60g+57zNlBwY6z7IhRaS ey5wz2d7cv7kOdpeRePycGfnOG4rvQz1c/HtpkhmDdxHuXhrAkzFd+p43dNojuE2H4AO uvvnJPzGc2CX0D6HKuX6kscS+sWw3kiQcwb8Qpx5Hn1XQFlTsWwAZ+onEIc5MJF/TGh/ 9Qjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=cIi46CdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a170902c10600b001ab007aff67si3033324pli.32.2023.06.03.13.55.57; Sat, 03 Jun 2023 13:56:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=cIi46CdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232484AbjFCUy7 (ORCPT <rfc822;stefanalexe802@gmail.com> + 99 others); Sat, 3 Jun 2023 16:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232437AbjFCUyy (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 3 Jun 2023 16:54:54 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC9E11B4; Sat, 3 Jun 2023 13:54:49 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 8EA405FD13; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825686; bh=igltWeKmorgVWzwhU5OIAduVRvDTNdsf6zEVkCG3inE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cIi46CdNwdrGNMaH2xIlNdLoSFp8Nw/8YXjkcRw+A60vXrV/HreerMNjqhUg1A9HP m54vYaxqn8X33u6N2JW3VcP5SaOPznh7eto0w/pu2MrKgsOzPz0d8UnUHCEt9eHJEa 3IPmqy5Uv/vz6OVPFdOn6MyUMi+groTLrIbMhrr1+qYpvaP0t6c/3kTyGZUd/NGxjM jBxfDpjfbEFPLazKh8GCQA+1SJMgGSuE2vl7Jq9DN5mwiYjwn9a5AN4Bdtsa2N64Fc 05/PDM1Dj7eejcbTXIHm+IaTka8vL5+asKvW3cHKNqWIt2cV94rIc37rUPipJxEv6N EKn5xhZmRmQOg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) 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 v4 02/17] vhost/vsock: read data from non-linear skb Date: Sat, 3 Jun 2023 23:49:24 +0300 Message-ID: <20230603204939.1598818-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716442110758517?= X-GMAIL-MSGID: =?utf-8?q?1767716442110758517?= |
Series |
vsock: MSG_ZEROCOPY flag support
|
|
Commit Message
Arseniy Krasnov
June 3, 2023, 8:49 p.m. UTC
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
changes call of 'copy_to_iter()' to 'skb_copy_datagram_iter()'. Second
function can read data from non-linear skb.
See commit to 'net/vmw_vsock/virtio_transport_common.c' with the same
name for more details.
Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
---
drivers/vhost/vsock.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
Comments
On Sat, Jun 03, 2023 at 11:49:24PM +0300, Arseniy Krasnov wrote: > 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 > changes call of 'copy_to_iter()' to 'skb_copy_datagram_iter()'. Second > function can read data from non-linear skb. > > See commit to 'net/vmw_vsock/virtio_transport_common.c' with the same > name for more details. > > Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru> > --- > drivers/vhost/vsock.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > index 6578db78f0ae..b254aa4b756a 100644 > --- a/drivers/vhost/vsock.c > +++ b/drivers/vhost/vsock.c > @@ -156,7 +156,7 @@ 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; > + payload_len = skb->len - VIRTIO_VSOCK_SKB_CB(skb)->frag_off; > hdr = virtio_vsock_hdr(skb); > > /* If the packet is greater than the space available in the > @@ -197,8 +197,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, > + VIRTIO_VSOCK_SKB_CB(skb)->frag_off, > + &iov_iter, > + payload_len)) { > kfree_skb(skb); > vq_err(vq, "Faulted on copying pkt buf\n"); > break; > @@ -212,13 +214,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 > LGTM. Reviewed-by: Bobby Eshleman <bobby.eshleman@bytedance.com>
On Sat, Jun 03, 2023 at 11:49:24PM +0300, Arseniy Krasnov wrote: >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 >changes call of 'copy_to_iter()' to 'skb_copy_datagram_iter()'. Second >function can read data from non-linear skb. > >See commit to 'net/vmw_vsock/virtio_transport_common.c' with the same >name for more details. I think it's okay if we report the same details here. > >Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru> >--- > drivers/vhost/vsock.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > >diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c >index 6578db78f0ae..b254aa4b756a 100644 >--- a/drivers/vhost/vsock.c >+++ b/drivers/vhost/vsock.c >@@ -156,7 +156,7 @@ 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; >+ payload_len = skb->len - VIRTIO_VSOCK_SKB_CB(skb)->frag_off; Also here a variable should make the code more readable. Stefano > hdr = virtio_vsock_hdr(skb); > > /* If the packet is greater than the space available in the >@@ -197,8 +197,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, >+ VIRTIO_VSOCK_SKB_CB(skb)->frag_off, >+ &iov_iter, >+ payload_len)) { > kfree_skb(skb); > vq_err(vq, "Faulted on copying pkt buf\n"); > break; >@@ -212,13 +214,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 >
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 6578db78f0ae..b254aa4b756a 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -156,7 +156,7 @@ 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; + payload_len = skb->len - VIRTIO_VSOCK_SKB_CB(skb)->frag_off; hdr = virtio_vsock_hdr(skb); /* If the packet is greater than the space available in the @@ -197,8 +197,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, + VIRTIO_VSOCK_SKB_CB(skb)->frag_off, + &iov_iter, + payload_len)) { kfree_skb(skb); vq_err(vq, "Faulted on copying pkt buf\n"); break; @@ -212,13 +214,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