public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>,
	passt-dev@passt.top, Jon Maloy <jmaloy@redhat.com>
Subject: Re: [PATCH v8 7/8] vhost-user: add vhost-user
Date: Wed, 23 Oct 2024 18:23:53 +0200	[thread overview]
Message-ID: <20241023182353.2e471c17@elisabeth> (raw)
In-Reply-To: <8ac883f3-f1ff-4cb7-85e7-02e590313261@redhat.com>

On Wed, 23 Oct 2024 17:27:49 +0200
Laurent Vivier <lvivier@redhat.com> wrote:

> On 22/10/2024 14:59, Laurent Vivier wrote:
> > On 17/10/2024 02:10, Stefano Brivio wrote:  
> >> On Wed, 16 Oct 2024 11:41:34 +1100
> >> David Gibson <david@gibson.dropbear.id.au> wrote:
> >>  
> >>> On Tue, Oct 15, 2024 at 09:54:38PM +0200, Stefano Brivio wrote:  
> >>>> [Still partial review]  
> >>> [snip]  
> >>>>> +    if (peek_offset_cap)
> >>>>> +        already_sent = 0;
> >>>>> +
> >>>>> +    iov_vu[0].iov_base = tcp_buf_discard;
> >>>>> +    iov_vu[0].iov_len = already_sent;  
> >>>>
> >>>> I think I had a similar comment to a previous revision. Now, I haven't
> >>>> tested this (yet) on a kernel with support for SO_PEEK_OFF on TCP, but
> >>>> I think this should eventually follow the same logic as the (updated)
> >>>> tcp_buf_data_from_sock(): we should use tcp_buf_discard only if
> >>>> (!peek_offset_cap).
> >>>>
> >>>> It's fine to always initialise VIRTQUEUE_MAX_SIZE iov_vu items,
> >>>> starting from 1, for simplicity. But I'm not sure if it's safe to pass a
> >>>> zero iov_len if (peek_offset_cap).  
> >>>  
> >>>> I'll test that (unless you already did) -- if it works, we can fix this
> >>>> up later as well.  
> >>>
> >>> I believe I tested it at some point, and I think we're already using
> >>> it somewhere.  
> >>
> >> I tested it again just to be sure on a recent net.git kernel: sometimes
> >> the first test in passt_vu_in_ns/tcp, "TCP/IPv4: host to guest: big
> >> transfer" hangs on my setup, sometimes it's the "TCP/IPv4: ns to guest
> >> (using loopback address): big transfer" test instead.
> >>
> >> I can reproduce at least one of the two issues consistently (tests
> >> stopped 5 times out of 5).
> >>
> >> The socat client completes the transfer, the server is still waiting
> >> for something. I haven't taken captures yet or tried to re-send from
> >> the client.
> >>
> >> It all works (consistently) with an older kernel without support for
> >> SO_PEEK_OFF on TCP, but also on this kernel if I force peek_offset_cap
> >> to false in tcp_init().
> >>  
> > 
> > I have a fix for that but there is an error I don't understand:
> > when I run twice the test, the second time I have:
> > 
> > guest:
> > # socat -u TCP4-LISTEN:10001 OPEN:test_big.bin,create,trunc
> > # socat -u TCP4-LISTEN:10001 OPEN:test_big.bin,create,trunc
> > 2024/10/22 08:51:58 socat[1485] E bind(5, {AF=2 0.0.0.0:10001}, 16): Address already in use
> > 
> > host:
> > $ socat -u OPEN:test/big.bin TCP4:127.0.0.1:10001
> > 
> > If I wait a little it can work again several times and fails again.
> > 
> > Any idea?
> > 
> > The patch is:
> > diff --git a/tcp_vu.c b/tcp_vu.c
> > index 78884c673215..83e40fb07a03 100644
> > --- a/tcp_vu.c
> > +++ b/tcp_vu.c
> > @@ -379,6 +379,10 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn 
> > *conn)
> >                             conn->seq_ack_from_tap, conn->seq_to_tap);
> >                  conn->seq_to_tap = conn->seq_ack_from_tap;
> >                  already_sent = 0;
> > +               if (tcp_set_peek_offset(conn->sock, 0)) {
> > +                       tcp_rst(c, conn);
> > +                       return -1;
> > +               }
> >          }
> > 
> >          if (!wnd_scaled || already_sent >= wnd_scaled) {
> > @@ -389,14 +393,13 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn 
> > *conn)
> > 
> >          /* Set up buffer descriptors we'll fill completely and partially. */
> > 
> > -       fillsize = wnd_scaled;
> > +       fillsize = wnd_scaled - already_sent;
> > 
> >          if (peek_offset_cap)
> >                  already_sent = 0;
> > 
> >          iov_vu[0].iov_base = tcp_buf_discard;
> >          iov_vu[0].iov_len = already_sent;
> > -       fillsize -= already_sent;
> > 
> >          /* collect the buffers from vhost-user and fill them with the
> >           * data from the socket
> > 
> >   
> 
> For the moment, I can see a behavior change of recvmsg() with the new kernel.
> 
> without peek_offset_cap, if no new data is available, it returns "already_sent", so it 
> enters in (found with tcp_vu.c but code samples from tcp_buf.c):
> 
> 	==> recvmsg() returns already_sent, so len > 0  
> 
>          ...
>          sendlen -= already_sent; ==> here sendlen becomes 0
> 
>          if (sendlen <= 0) {
>                  conn_flag(c, conn, STALLED);
>                  return 0;
>          }
> 
> With peek_offset, it returns -1, so it enters in:

This is expected, I think (and unfortunately not documented).

> 
>          if (len < 0)
>                  goto err;
> ...
> err:
>          if (errno != EAGAIN && errno != EWOULDBLOCK) {

But errno here should be EAGAIN, so yes, it looks buggy to me in the
sense that:

>                  ret = -errno;
>                  tcp_rst(c, conn);
>          }

we return 0 here without setting the STALLED flag. While it should
be fixed, that flag is some kind of optimisation, so this doesn't
really explain the issue that I mentioned in
20241022201914.072f7c7d@elisabeth:

  https://archives.passt.top/passt-dev/20241022201914.072f7c7d@elisabeth/

As a quick fix, you should probably do this in tcp_vu_data_from_sock():

	if (peek_offset_cap)	/* add this condition */
		len -= already_sent;

	if (len <= 0 || (peek_offset_cap && len == -1 && errno == EAGAIN))
		/* change this condition */
		...

...or you mean that due to this behaviour you don't call vu_queue_rewind()
and that causes troubles?

-- 
Stefano


  reply	other threads:[~2024-10-23 16:24 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 12:28 [PATCH v8 0/8] Add vhost-user support to passt. (part 3) Laurent Vivier
2024-10-10 12:28 ` [PATCH v8 1/8] packet: replace struct desc by struct iovec Laurent Vivier
2024-10-10 12:28 ` [PATCH v8 2/8] vhost-user: introduce virtio API Laurent Vivier
2024-10-10 12:28 ` [PATCH v8 3/8] vhost-user: introduce vhost-user API Laurent Vivier
2024-10-10 12:28 ` [PATCH v8 4/8] udp: Prepare udp.c to be shared with vhost-user Laurent Vivier
2024-10-14  4:29   ` David Gibson
2024-10-10 12:28 ` [PATCH v8 5/8] tcp: Export headers functions Laurent Vivier
2024-10-14  4:29   ` David Gibson
2024-10-10 12:29 ` [PATCH v8 6/8] passt: rename tap_sock_init() to tap_backend_init() Laurent Vivier
2024-10-14  4:30   ` David Gibson
2024-10-14 22:38   ` Stefano Brivio
2024-10-10 12:29 ` [PATCH v8 7/8] vhost-user: add vhost-user Laurent Vivier
2024-10-15  3:23   ` David Gibson
2024-10-16 10:07     ` Laurent Vivier
2024-10-16 16:26       ` Stefano Brivio
2024-10-15 19:54   ` Stefano Brivio
2024-10-16  0:41     ` David Gibson
2024-10-17  0:10       ` Stefano Brivio
2024-10-17 11:25         ` Stefano Brivio
2024-10-17 11:54           ` Laurent Vivier
2024-10-17 17:18           ` Laurent Vivier
2024-10-17 17:25             ` Laurent Vivier
2024-10-17 17:33             ` Stefano Brivio
2024-10-17 21:21               ` Stefano Brivio
2024-10-22 12:59         ` Laurent Vivier
2024-10-22 13:19           ` Stefano Brivio
2024-10-22 18:19             ` Stefano Brivio
2024-10-22 18:22               ` Stefano Brivio
2024-10-23 15:27           ` Laurent Vivier
2024-10-23 16:23             ` Stefano Brivio [this message]
2024-10-17  0:10   ` Stefano Brivio
2024-10-17  7:28     ` Laurent Vivier
2024-10-17  8:33       ` Stefano Brivio
2024-11-14 10:20     ` Laurent Vivier
2024-11-14 14:23       ` Stefano Brivio
2024-11-14 15:16         ` Laurent Vivier
2024-11-14 15:38           ` Stefano Brivio
2024-11-14 10:23     ` Laurent Vivier
2024-11-14 14:23       ` Stefano Brivio
2024-11-15  8:30         ` Laurent Vivier
2024-11-15 10:08           ` Stefano Brivio
2024-11-14 10:29     ` Laurent Vivier
2024-11-14 14:23       ` Stefano Brivio
2024-11-15 11:13         ` Laurent Vivier
2024-11-15 11:23           ` Stefano Brivio
2024-10-10 12:29 ` [PATCH v8 8/8] test: Add tests for passt in vhost-user mode Laurent Vivier
2024-10-15  3:40   ` David Gibson
2024-10-15 19:54   ` Stefano Brivio
2024-10-16  8:06     ` Laurent Vivier
2024-10-16  9:47       ` Stefano Brivio

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=20241023182353.2e471c17@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=jmaloy@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).