All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krasnov Arseniy <AVKrasnov@sberdevices.ru>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Krasnov Arseniy <oxffffaa@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"virtualization@lists.linux-foundation.org" 
	<virtualization@lists.linux-foundation.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	kernel <kernel@sberdevices.ru>
Subject: Re: [RFC PATCH v1 04/12] vhost/vsock: non-linear skb handling support
Date: Mon, 20 Feb 2023 09:01:33 +0000	[thread overview]
Message-ID: <df350d42-bfc3-d0d3-f04f-8b3ebeea4d0a@sberdevices.ru> (raw)
In-Reply-To: <20230216140917.jpcmfrwl5gpdzdzi@sgarzare-redhat>

On 16.02.2023 17:09, Stefano Garzarella wrote:
> On Mon, Feb 06, 2023 at 06:57:16AM +0000, 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.
>>
>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>> ---
>> drivers/vhost/vsock.c        | 56 ++++++++++++++++++++++++++++++++----
>> include/linux/virtio_vsock.h | 12 ++++++++
>> 2 files changed, 63 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>> index 1f3b89c885cc..60b9cafa3e31 100644
>> --- a/drivers/vhost/vsock.c
>> +++ b/drivers/vhost/vsock.c
>> @@ -86,6 +86,44 @@ static struct vhost_vsock *vhost_vsock_get(u32 guest_cid)
>>     return NULL;
>> }
>>
>> +static int vhost_transport_copy_nonlinear_skb(struct sk_buff *skb,
>> +                          struct iov_iter *iov_iter,
>> +                          size_t len)
>> +{
>> +    size_t rest_len = len;
>> +
>> +    while (rest_len && virtio_vsock_skb_has_frags(skb)) {
>> +        struct bio_vec *curr_vec;
>> +        size_t curr_vec_end;
>> +        size_t to_copy;
>> +        int curr_frag;
>> +        int curr_offs;
>> +
>> +        curr_frag = VIRTIO_VSOCK_SKB_CB(skb)->curr_frag;
>> +        curr_offs = VIRTIO_VSOCK_SKB_CB(skb)->frag_off;
>> +        curr_vec = &skb_shinfo(skb)->frags[curr_frag];
>> +
>> +        curr_vec_end = curr_vec->bv_offset + curr_vec->bv_len;
>> +        to_copy = min(rest_len, (size_t)(curr_vec_end - curr_offs));
>> +
>> +        if (copy_page_to_iter(curr_vec->bv_page, curr_offs,
>> +                      to_copy, iov_iter) != to_copy)
>> +            return -1;
>> +
>> +        rest_len -= to_copy;
>> +        VIRTIO_VSOCK_SKB_CB(skb)->frag_off += to_copy;
>> +
>> +        if (VIRTIO_VSOCK_SKB_CB(skb)->frag_off == (curr_vec_end)) {
>> +            VIRTIO_VSOCK_SKB_CB(skb)->curr_frag++;
>> +            VIRTIO_VSOCK_SKB_CB(skb)->frag_off = 0;
>> +        }
>> +    }
> 
> Can it happen that we exit this loop and rest_len is not 0?
> 
> In this case, is it correct to decrement data_len by len?

I see

> 
> Thanks,
> Stefano
> 
>> +
>> +    skb->data_len -= len;
>> +
>> +    return 0;
>> +}
>> +
>> static void
>> vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>>                 struct vhost_virtqueue *vq)
>> @@ -197,11 +235,19 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>>             break;
>>         }
>>
>> -        nbytes = copy_to_iter(skb->data, payload_len, &iov_iter);
>> -        if (nbytes != payload_len) {
>> -            kfree_skb(skb);
>> -            vq_err(vq, "Faulted on copying pkt buf\n");
>> -            break;
>> +        if (skb_is_nonlinear(skb)) {
>> +            if (vhost_transport_copy_nonlinear_skb(skb, &iov_iter,
>> +                                   payload_len)) {
>> +                vq_err(vq, "Faulted on copying pkt buf from page\n");
>> +                break;
>> +            }
>> +        } else {
>> +            nbytes = copy_to_iter(skb->data, payload_len, &iov_iter);
>> +            if (nbytes != payload_len) {
>> +                kfree_skb(skb);
>> +                vq_err(vq, "Faulted on copying pkt buf\n");
>> +                break;
>> +            }
>>         }
>>
>>         /* Deliver to monitoring devices all packets that we
>> diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
>> index 3f9c16611306..e7efdb78ce6e 100644
>> --- a/include/linux/virtio_vsock.h
>> +++ b/include/linux/virtio_vsock.h
>> @@ -12,6 +12,10 @@
>> struct virtio_vsock_skb_cb {
>>     bool reply;
>>     bool tap_delivered;
>> +    /* Current fragment in 'frags' of skb. */
>> +    u32 curr_frag;
>> +    /* Offset from 0 in current fragment. */
>> +    u32 frag_off;
>> };
>>
>> #define VIRTIO_VSOCK_SKB_CB(skb) ((struct virtio_vsock_skb_cb *)((skb)->cb))
>> @@ -46,6 +50,14 @@ static inline void virtio_vsock_skb_clear_tap_delivered(struct sk_buff *skb)
>>     VIRTIO_VSOCK_SKB_CB(skb)->tap_delivered = false;
>> }
>>
>> +static inline bool virtio_vsock_skb_has_frags(struct sk_buff *skb)
>> +{
>> +    if (!skb_is_nonlinear(skb))
>> +        return false;
>> +
>> +    return VIRTIO_VSOCK_SKB_CB(skb)->curr_frag != skb_shinfo(skb)->nr_frags;
>> +}
>> +
>> static inline void virtio_vsock_skb_rx_put(struct sk_buff *skb)
>> {
>>     u32 len;
>> -- 
>> 2.25.1
> 


  reply	other threads:[~2023-02-20  9:01 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06  6:51 [RFC PATCH v1 00/12] vsock: MSG_ZEROCOPY flag support Arseniy Krasnov
2023-02-06  6:53 ` [RFC PATCH v1 01/12] vsock: check error queue to set EPOLLERR Arseniy Krasnov
2023-02-16 13:40   ` Stefano Garzarella
2023-02-16 13:40     ` Stefano Garzarella
2023-02-20  9:00     ` Krasnov Arseniy
2023-02-06  6:54 ` [RFC PATCH v1 02/12] vsock: read from socket's error queue Arseniy Krasnov
2023-02-16 13:55   ` Stefano Garzarella
2023-02-16 13:55     ` Stefano Garzarella
2023-02-06  6:55 ` [RFC PATCH v1 03/12] vsock: check for MSG_ZEROCOPY support Arseniy Krasnov
2023-02-16 14:02   ` Stefano Garzarella
2023-02-16 14:02     ` Stefano Garzarella
2023-02-06  6:57 ` [RFC PATCH v1 04/12] vhost/vsock: non-linear skb handling support Arseniy Krasnov
2023-02-16 14:09   ` Stefano Garzarella
2023-02-16 14:09     ` Stefano Garzarella
2023-02-20  9:01     ` Krasnov Arseniy [this message]
2023-02-06  6:58 ` [RFC PATCH v1 05/12] vsock/virtio: non-linear skb support Arseniy Krasnov
2023-02-16 14:18   ` Stefano Garzarella
2023-02-16 14:18     ` Stefano Garzarella
2023-02-20  9:02     ` Krasnov Arseniy
2023-02-06  6:59 ` [RFC PATCH v1 06/12] vsock/virtio: non-linear skb handling for TAP dev Arseniy Krasnov
2023-02-16 14:30   ` Stefano Garzarella
2023-02-16 14:30     ` Stefano Garzarella
2023-02-06  7:00 ` [RFC PATCH v1 07/12] vsock/virtio: MGS_ZEROCOPY flag support Arseniy Krasnov
2023-02-16 15:16   ` Stefano Garzarella
2023-02-16 15:16     ` Stefano Garzarella
2023-02-20  9:04     ` Krasnov Arseniy
2023-02-28 10:26       ` Stefano Garzarella
2023-02-28 10:26         ` Stefano Garzarella
2023-02-06  7:01 ` [RFC PATCH v1 08/12] vhost/vsock: support MSG_ZEROCOPY for transport Arseniy Krasnov
2023-02-06  7:02 ` [RFC PATCH v1 09/12] vsock/virtio: " Arseniy Krasnov
2023-02-06  7:03 ` [RFC PATCH v1 10/12] net/sock: enable setting SO_ZEROCOPY for PF_VSOCK Arseniy Krasnov
2023-02-06  7:05 ` [RFC PATCH v1 11/12] test/vsock: MSG_ZEROCOPY flag tests Arseniy Krasnov
2023-02-06  7:06 ` [RFC PATCH v1 12/12] test/vsock: MSG_ZEROCOPY support for vsock_perf Arseniy Krasnov
2023-02-16 15:29   ` Stefano Garzarella
2023-02-16 15:29     ` Stefano Garzarella
2023-02-20  9:05     ` Krasnov Arseniy
2023-02-28 10:32       ` Stefano Garzarella
2023-02-28 10:32         ` Stefano Garzarella
2023-02-16 13:33 ` [RFC PATCH v1 00/12] vsock: MSG_ZEROCOPY flag support Stefano Garzarella
2023-02-16 13:33   ` Stefano Garzarella
2023-02-20  8:59   ` Krasnov Arseniy
2023-02-28 10:23     ` Stefano Garzarella
2023-02-28 10:23       ` 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=df350d42-bfc3-d0d3-f04f-8b3ebeea4d0a@sberdevices.ru \
    --to=avkrasnov@sberdevices.ru \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.