From: "Michael S. Tsirkin" <mst@redhat.com>
To: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Cc: Bobby Eshleman <bobby.eshleman@bytedance.com>,
kvm@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org, oxffffaa@gmail.com,
Eric Dumazet <edumazet@google.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
kernel@sberdevices.ru, Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next v2 2/4] vsock/virtio: support to send non-linear skb
Date: Tue, 18 Jul 2023 16:27:32 -0400 [thread overview]
Message-ID: <20230718162202-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230718180237.3248179-3-AVKrasnov@sberdevices.ru>
On Tue, Jul 18, 2023 at 09:02:35PM +0300, Arseniy Krasnov wrote:
> For non-linear skb use its pages from fragment array as buffers in
> virtio tx queue. These pages are already pinned by 'get_user_pages()'
> during such skb creation.
>
> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> net/vmw_vsock/virtio_transport.c | 40 +++++++++++++++++++++++++++-----
> 1 file changed, 34 insertions(+), 6 deletions(-)
>
> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> index e95df847176b..6cbb45bb12d2 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -100,7 +100,9 @@ virtio_transport_send_pkt_work(struct work_struct *work)
> vq = vsock->vqs[VSOCK_VQ_TX];
>
> for (;;) {
> - struct scatterlist hdr, buf, *sgs[2];
> + /* +1 is for packet header. */
> + struct scatterlist *sgs[MAX_SKB_FRAGS + 1];
> + struct scatterlist bufs[MAX_SKB_FRAGS + 1];
> int ret, in_sg = 0, out_sg = 0;
> struct sk_buff *skb;
> bool reply;
> @@ -111,12 +113,38 @@ virtio_transport_send_pkt_work(struct work_struct *work)
>
> virtio_transport_deliver_tap_pkt(skb);
> reply = virtio_vsock_skb_reply(skb);
> + sg_init_one(&bufs[out_sg], virtio_vsock_hdr(skb),
> + sizeof(*virtio_vsock_hdr(skb)));
> + sgs[out_sg] = &bufs[out_sg];
> + out_sg++;
> +
> + if (!skb_is_nonlinear(skb)) {
> + if (skb->len > 0) {
> + sg_init_one(&bufs[out_sg], skb->data, skb->len);
> + sgs[out_sg] = &bufs[out_sg];
> + out_sg++;
> + }
> + } else {
> + struct skb_shared_info *si;
> + int i;
> +
> + si = skb_shinfo(skb);
> +
> + for (i = 0; i < si->nr_frags; i++) {
> + skb_frag_t *skb_frag = &si->frags[i];
> + void *va = page_to_virt(skb_frag->bv_page);
>
> - sg_init_one(&hdr, virtio_vsock_hdr(skb), sizeof(*virtio_vsock_hdr(skb)));
> - sgs[out_sg++] = &hdr;
> - if (skb->len > 0) {
> - sg_init_one(&buf, skb->data, skb->len);
> - sgs[out_sg++] = &buf;
> + /* We will use 'page_to_virt()' for userspace page here,
don't put comments after code they refer to, please?
> + * because virtio layer will call 'virt_to_phys()' later
it will but not always. sometimes it's the dma mapping layer.
> + * to fill buffer descriptor. We don't touch memory at
> + * "virtual" address of this page.
you need to stick "the" in a bunch of places above.
> + */
> + sg_init_one(&bufs[out_sg],
> + va + skb_frag->bv_offset,
> + skb_frag->bv_len);
> + sgs[out_sg] = &bufs[out_sg];
> + out_sg++;
> + }
> }
>
> ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, GFP_KERNEL);
There's a problem here: if there vq is small this will fail.
So you really should check free vq s/gs and switch to non-zcopy
if too small.
> --
> 2.25.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Cc: 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>,
Jason Wang <jasowang@redhat.com>,
Bobby Eshleman <bobby.eshleman@bytedance.com>,
kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@sberdevices.ru, oxffffaa@gmail.com
Subject: Re: [PATCH net-next v2 2/4] vsock/virtio: support to send non-linear skb
Date: Tue, 18 Jul 2023 16:27:32 -0400 [thread overview]
Message-ID: <20230718162202-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230718180237.3248179-3-AVKrasnov@sberdevices.ru>
On Tue, Jul 18, 2023 at 09:02:35PM +0300, Arseniy Krasnov wrote:
> For non-linear skb use its pages from fragment array as buffers in
> virtio tx queue. These pages are already pinned by 'get_user_pages()'
> during such skb creation.
>
> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> net/vmw_vsock/virtio_transport.c | 40 +++++++++++++++++++++++++++-----
> 1 file changed, 34 insertions(+), 6 deletions(-)
>
> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> index e95df847176b..6cbb45bb12d2 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -100,7 +100,9 @@ virtio_transport_send_pkt_work(struct work_struct *work)
> vq = vsock->vqs[VSOCK_VQ_TX];
>
> for (;;) {
> - struct scatterlist hdr, buf, *sgs[2];
> + /* +1 is for packet header. */
> + struct scatterlist *sgs[MAX_SKB_FRAGS + 1];
> + struct scatterlist bufs[MAX_SKB_FRAGS + 1];
> int ret, in_sg = 0, out_sg = 0;
> struct sk_buff *skb;
> bool reply;
> @@ -111,12 +113,38 @@ virtio_transport_send_pkt_work(struct work_struct *work)
>
> virtio_transport_deliver_tap_pkt(skb);
> reply = virtio_vsock_skb_reply(skb);
> + sg_init_one(&bufs[out_sg], virtio_vsock_hdr(skb),
> + sizeof(*virtio_vsock_hdr(skb)));
> + sgs[out_sg] = &bufs[out_sg];
> + out_sg++;
> +
> + if (!skb_is_nonlinear(skb)) {
> + if (skb->len > 0) {
> + sg_init_one(&bufs[out_sg], skb->data, skb->len);
> + sgs[out_sg] = &bufs[out_sg];
> + out_sg++;
> + }
> + } else {
> + struct skb_shared_info *si;
> + int i;
> +
> + si = skb_shinfo(skb);
> +
> + for (i = 0; i < si->nr_frags; i++) {
> + skb_frag_t *skb_frag = &si->frags[i];
> + void *va = page_to_virt(skb_frag->bv_page);
>
> - sg_init_one(&hdr, virtio_vsock_hdr(skb), sizeof(*virtio_vsock_hdr(skb)));
> - sgs[out_sg++] = &hdr;
> - if (skb->len > 0) {
> - sg_init_one(&buf, skb->data, skb->len);
> - sgs[out_sg++] = &buf;
> + /* We will use 'page_to_virt()' for userspace page here,
don't put comments after code they refer to, please?
> + * because virtio layer will call 'virt_to_phys()' later
it will but not always. sometimes it's the dma mapping layer.
> + * to fill buffer descriptor. We don't touch memory at
> + * "virtual" address of this page.
you need to stick "the" in a bunch of places above.
> + */
> + sg_init_one(&bufs[out_sg],
> + va + skb_frag->bv_offset,
> + skb_frag->bv_len);
> + sgs[out_sg] = &bufs[out_sg];
> + out_sg++;
> + }
> }
>
> ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, GFP_KERNEL);
There's a problem here: if there vq is small this will fail.
So you really should check free vq s/gs and switch to non-zcopy
if too small.
> --
> 2.25.1
next prev parent reply other threads:[~2023-07-18 20:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 18:02 [PATCH net-next v2 0/4] vsock/virtio/vhost: MSG_ZEROCOPY preparations Arseniy Krasnov
2023-07-18 18:02 ` [PATCH net-next v2 1/4] vsock/virtio/vhost: read data from non-linear skb Arseniy Krasnov
2023-07-18 18:02 ` [PATCH net-next v2 2/4] vsock/virtio: support to send " Arseniy Krasnov
2023-07-18 20:27 ` Michael S. Tsirkin [this message]
2023-07-18 20:27 ` Michael S. Tsirkin
2023-07-19 4:46 ` Arseniy Krasnov
2023-07-19 6:13 ` Arseniy Krasnov
2023-07-19 7:36 ` Stefano Garzarella
2023-07-19 7:36 ` Stefano Garzarella
2023-07-19 7:47 ` Arseniy Krasnov
2023-07-18 18:02 ` [PATCH net-next v2 3/4] vsock/virtio: non-linear skb handling for tap Arseniy Krasnov
2023-07-18 18:02 ` [PATCH net-next v2 4/4] vsock/virtio: MSG_ZEROCOPY flag support Arseniy Krasnov
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=20230718162202-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=AVKrasnov@sberdevices.ru \
--cc=bobby.eshleman@bytedance.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kernel@sberdevices.ru \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oxffffaa@gmail.com \
--cc=pabeni@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.