From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id A5B2E5A02E9 for ; Wed, 15 May 2024 06:02:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1715745767; bh=599Yio95vC8209Uq+yoEeUK8ZU+Te06KGKG8GLRzuUw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fCuJAFytHh+5NsQhStYvTS04NvgBnbkSWh2tYuYklWRxWFeNh6k5Tiv2neI2oXbWj 9C7m+HF4AlvshZHZstmDNf0DRNMI1IT9PyZc0/u8TS3OS+X7V6V92YefXSwJ8OVZPK OwahqZNnF7+7c8R72l60G2g73eF+ajUb4GK0dW5INiwijHUuzxt/unNc0KpZ2GOfBr N80TP6TwNaF+tPAGs+BTgiU28kvcfOaSDilbcRu32RRyCkOQpY7F0WVDwbW45wZaVv sQPc/WpCXtwLXozJaefv4C/2hsZIIFOi7lOopVx0FrvD+x/on1SWrsgIv+vhM2X29J Mjb1Uz7uQdrxw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4VfKLv6QXLz4x11; Wed, 15 May 2024 14:02:47 +1000 (AEST) Date: Wed, 15 May 2024 14:00:46 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v4] tcp: move seq_to_tap update to when frame is queued Message-ID: References: <20240514194406.755076-1-jmaloy@redhat.com> <1e672f7b-2660-c2e6-6803-c2a094b84bb3@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="i1854TeNCIVTbajT" Content-Disposition: inline In-Reply-To: <1e672f7b-2660-c2e6-6803-c2a094b84bb3@redhat.com> Message-ID-Hash: 4KFGCCPGBKXJKHBN7SEJGV3FMC3RDFUH X-Message-ID-Hash: 4KFGCCPGBKXJKHBN7SEJGV3FMC3RDFUH X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --i1854TeNCIVTbajT Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 14, 2024 at 03:57:43PM -0400, Jon Maloy wrote: > Hi, > I did a little more than suggested by David/Stefano here, but I am always > happy > when I see simplifications that can reduce the code amount. > However, being able to eliminate struct tcp_buf_update led me to another > idea. >=20 > Could we just do: >=20 > struct tcp_frame { > =A0=A0=A0=A0 struct tcp_tap_conn *conn; > =A0=A0=A0=A0 struct iov headers[TCP_NUM_IOVS]; > }; > static struct tcp_frame =A0 tcp4_l2_iov [TCP_FRAMES_MEM]; > static struct tcp_frame =A0 tcp6_l2_iov [TCP_FRAMES_MEM]; I don't think this works exactly as is. At least in the qemu socket case we actually rely on the iovec arrays for multiple frames being contiguous so we can send them all in one operation. We might be able to do something a bit like the udp_meta[] structures I have in UDP, so rather than having parallel arrays for each of the various header components we have an array of structures which contains space for all the header variants a frame might want, along with any additional per-frame information we need, which could include the connection. The iov arrays then point to the various buffers within those "meta" structures. I did have a look at implementing this a while back, but ran into some complications. Nothing particularly bad, I don't think, just more than I wanted to deal with at the time. > We could even add a v4/v6 field to the struct, and possibly > eliminate the need for separate v4/v6 queues altogether, with > all its entailing extra code. It's absolutely my aim to unify most or all of the v4/v6 structures. We'll need this for things we want like v4<->v6 forwarding. I certainly think it's doable, but as above, I did hit some fiddliness when I've tried in the past. > On 2024-05-14 15:44, Jon Maloy wrote: > > commit a469fc393fa1 ("tcp, tap: Don't increase tap-side sequence counte= r for dropped frames") > > delayed update of conn->seq_to_tap until the moment the corresponding > > frame has been successfully pushed out. This has the advantage that we > > immediately can make a new attempt to transmit a frame after a failed > > trasnmit, rather than waiting for the peer to later discover a gap and > > trigger the fast retransmit mechanism to solve the problem. > >=20 > > This approach has turned out to cause a problem with spurious sequence > > number updates during peer-initiated retransmits, and we have realized > > it may not be the best way to solve the above issue. > >=20 > > We now restore the previous method, by updating the said field at the > > moment a frame is added to the outqueue. To retain the advantage of > > having a quick re-attempt based on local failure detection, we now scan > > through the part of the outqueue that had do be dropped, and restore the > > sequence counter for each affected connection to the most appropriate > > value. > >=20 > > Signed-off-by: Jon Maloy > >=20 > > --- > > v2: - Re-spun loop in tcp_revert_seq() and some other changes based on > > feedback from Stefano Brivio. > > - Added paranoid test to avoid that seq_to_tap becomes lower than > > seq_ack_from_tap. > >=20 > > v3: - Identical to v2. Called v3 because it was embedded in a series > > with that version. > >=20 > > v4: - In tcp_revert_seq(), we read the sequence number from the TCP > > header instead of keeping a copy in struct tcp_buf_seq_update. > > - Since the only remaining field in struct tcp_buf_seq_update is > > a pointer to struct tcp_tap_conn, we eliminate the struct > > altogether, and make the tcp6/tcp3_buf_seq_update arrays into > > arrays of said pointer. > > - Removed 'paranoid' test in tcp_revert_seq. If it happens, it > > is not fatal, and will be caught by other code anyway. > > - Separated from the series again. > > --- > > tcp.c | 59 +++++++++++++++++++++++++++++++++++++---------------------- > > 1 file changed, 37 insertions(+), 22 deletions(-) > >=20 > > diff --git a/tcp.c b/tcp.c > > index 21d0af0..976dba8 100644 > > --- a/tcp.c > > +++ b/tcp.c > > @@ -410,16 +410,6 @@ static int tcp_sock_ns [NUM_PORTS][IP_VERSIONS]; > > */ > > static union inany_addr low_rtt_dst[LOW_RTT_TABLE_SIZE]; > > -/** > > - * tcp_buf_seq_update - Sequences to update with length of frames once= sent > > - * @seq: Pointer to sequence number sent to tap-side, to be updated > > - * @len: TCP payload length > > - */ > > -struct tcp_buf_seq_update { > > - uint32_t *seq; > > - uint16_t len; > > -}; > > - > > /* Static buffers */ > > /** > > * struct tcp_payload_t - TCP header and data to send segments with p= ayload > > @@ -461,7 +451,8 @@ static struct tcp_payload_t tcp4_payload[TCP_FRAMES= _MEM]; > > static_assert(MSS4 <=3D sizeof(tcp4_payload[0].data), "MSS4 is greate= r than 65516"); > > -static struct tcp_buf_seq_update tcp4_seq_update[TCP_FRAMES_MEM]; > > +/* References tracking the owner connection of frames in the tap outqu= eue */ > > +static struct tcp_tap_conn *tcp4_frame_conns[TCP_FRAMES_MEM]; > > static unsigned int tcp4_payload_used; > > static struct tap_hdr tcp4_flags_tap_hdr[TCP_FRAMES_MEM]; > > @@ -483,7 +474,8 @@ static struct tcp_payload_t tcp6_payload[TCP_FRAMES= _MEM]; > > static_assert(MSS6 <=3D sizeof(tcp6_payload[0].data), "MSS6 is greate= r than 65516"); > > -static struct tcp_buf_seq_update tcp6_seq_update[TCP_FRAMES_MEM]; > > +/* References tracking the owner connection of frames in the tap outqu= eue */ > > +static struct tcp_tap_conn *tcp6_frame_conns[TCP_FRAMES_MEM]; > > static unsigned int tcp6_payload_used; > > static struct tap_hdr tcp6_flags_tap_hdr[TCP_FRAMES_MEM]; > > @@ -1261,25 +1253,49 @@ static void tcp_flags_flush(const struct ctx *c) > > tcp4_flags_used =3D 0; > > } > > +/** > > + * tcp_revert_seq() - Revert affected conn->seq_to_tap after failed tr= ansmission > > + * @conns: Array of connection pointers corresponding to queued = frames > > + * @frames: Two-dimensional array containing queued frames with s= ub-iovs > > + * @num_frames: Number of entries in the two arrays to be compared > > + */ > > +static void tcp_revert_seq(struct tcp_tap_conn **conns, struct iovec *= frames, > > + int num_frames) > > +{ > > + int c, f; > > + > > + for (c =3D 0, f =3D 0; c < num_frames; c++, f +=3D TCP_NUM_IOVS) { > > + struct tcp_tap_conn *conn =3D conns[c]; > > + struct tcphdr *th =3D frames[f + TCP_IOV_PAYLOAD].iov_base; > > + uint32_t seq =3D ntohl(th->seq); > > + > > + if (SEQ_LE(conn->seq_to_tap, seq)) > > + continue; > > + > > + conn->seq_to_tap =3D seq; > > + } > > +} > > + > > /** > > * tcp_payload_flush() - Send out buffers for segments with data > > * @c: Execution context > > */ > > static void tcp_payload_flush(const struct ctx *c) > > { > > - unsigned i; > > size_t m; > > m =3D tap_send_frames(c, &tcp6_l2_iov[0][0], TCP_NUM_IOVS, > > tcp6_payload_used); > > - for (i =3D 0; i < m; i++) > > - *tcp6_seq_update[i].seq +=3D tcp6_seq_update[i].len; > > + if (m !=3D tcp6_payload_used) > > + tcp_revert_seq(tcp6_frame_conns, &tcp6_l2_iov[m][0], > > + tcp6_payload_used - m); > > tcp6_payload_used =3D 0; > > m =3D tap_send_frames(c, &tcp4_l2_iov[0][0], TCP_NUM_IOVS, > > tcp4_payload_used); > > - for (i =3D 0; i < m; i++) > > - *tcp4_seq_update[i].seq +=3D tcp4_seq_update[i].len; > > + if (m !=3D tcp4_payload_used) > > + tcp_revert_seq(tcp4_frame_conns, &tcp4_l2_iov[m][0], > > + tcp4_payload_used - m); > > tcp4_payload_used =3D 0; > > } > > @@ -2129,10 +2145,11 @@ static int tcp_sock_consume(const struct tcp_ta= p_conn *conn, uint32_t ack_seq) > > static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn = *conn, > > ssize_t dlen, int no_csum, uint32_t seq) > > { > > - uint32_t *seq_update =3D &conn->seq_to_tap; > > struct iovec *iov; > > size_t l4len; > > + conn->seq_to_tap =3D seq + dlen; > > + > > if (CONN_V4(conn)) { > > struct iovec *iov_prev =3D tcp4_l2_iov[tcp4_payload_used - 1]; > > const uint16_t *check =3D NULL; > > @@ -2142,8 +2159,7 @@ static void tcp_data_to_tap(const struct ctx *c, = struct tcp_tap_conn *conn, > > check =3D &iph->check; > > } > > - tcp4_seq_update[tcp4_payload_used].seq =3D seq_update; > > - tcp4_seq_update[tcp4_payload_used].len =3D dlen; > > + tcp4_frame_conns[tcp4_payload_used] =3D conn; > > iov =3D tcp4_l2_iov[tcp4_payload_used++]; > > l4len =3D tcp_l2_buf_fill_headers(c, conn, iov, dlen, check, seq); > > @@ -2151,8 +2167,7 @@ static void tcp_data_to_tap(const struct ctx *c, = struct tcp_tap_conn *conn, > > if (tcp4_payload_used > TCP_FRAMES_MEM - 1) > > tcp_payload_flush(c); > > } else if (CONN_V6(conn)) { > > - tcp6_seq_update[tcp6_payload_used].seq =3D seq_update; > > - tcp6_seq_update[tcp6_payload_used].len =3D dlen; > > + tcp6_frame_conns[tcp6_payload_used] =3D conn; > > iov =3D tcp6_l2_iov[tcp6_payload_used++]; > > l4len =3D tcp_l2_buf_fill_headers(c, conn, iov, dlen, NULL, seq); >=20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --i1854TeNCIVTbajT Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZEM14ACgkQzQJF27ox 2Gfh0g/5ASDWtpf9gtQx67zDSbrZyR+Xu7SqQZe3Ob62jWkALzUf13bm8YHTj5Pu 4vYX+Opo8CoKpXK5q+JcOnTpnLfOSqaviVhfQ2p/4WmYokVda41ffB9WKxLW/pRP SiWR76v0Ci93xoBC1TtpZUZ/Efvon+u5xTloM9t/TcdHHWN32mWwncmpj9rVNdgN nz5M781KtP5VLD2gpx3LFRj7JyESqdWZoQny9Bkl2UODqmgFzy+w3FxViZ2+6J/N u2RKPZcHq4VsvvM3Is+o5bPKMA/xFnUrC3s+8tA6vKoUtcbj4o9pyaWryQqCRLX4 xG1AXDfaNeSF3APODy70ksk9jrxBU+YS9NcZYA5a7LNhRMcpvk0vKOhR8yqHWwJ4 Z6gDmIPnc5xgImNb2iRuFf7KV0zRo8tgu7/z7F56PQVTHd3bCsRl4uD3kPRdmVva 8wfLByEKXAxrC90/79IK7zuV0iWmkHXWfmwfmlqF52Di/jOHncum/S0dcSXigEEl hoiFOUXKPEiJ19s9ANMfZ46LgqfadXcAN4qSR7g/NfGSKWLifioQQl0rNDmYFqsT nb1A7jFFVLRogt1QSdoQCUAZmXmBPNx/p2GNcJkCJoF4X0uG9ahSPduNwfDZPWga c0Go7XCInch7dgV1q/PCN3+Ns3R6jWuuFlHydvBypVDXqBmDZog= =OzX/ -----END PGP SIGNATURE----- --i1854TeNCIVTbajT--