From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=sDgxcm6A; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 8AF725A0262 for ; Fri, 20 Sep 2024 06:52:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1726807958; bh=/32hhVJ9PHdK5TA4Vxqi1TEtneJE2MzsHmTmq5H1Ops=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sDgxcm6ARZBSyFSRPKpLhvoDz9MSxtIcuOAgfQGwgzP9r0J0qL280pwdLKeHLAGUJ 0u+g97whcINHVvNtT3E03nZmNNm1VI36D06iMnoLMm4F6Gc8Ih62MTzKVHHVHnPYhW YjfcebBZ3btoI/hWGITwH2YY9BK4MM2gC4QE8bDf9lFtE5Q0CcBFtNjQe/jvfSz0wE 4o27AShEE1ZKmabDF0jdw0+FqaQ22vkLvOFN3ggMgOzME5e1nEd4Rs9aVAnmAxnADv JXqvbzSnQT/6B0YX6yBIJpAIc85V+xCTiFTJS4MJiCHOya0xS9huT3FVJv7Ji+gYQn jtS+cR15Jdpgw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X90PL1H9Kz4xPy; Fri, 20 Sep 2024 14:52:38 +1000 (AEST) Date: Fri, 20 Sep 2024 14:20:02 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3 1/2] tcp: set ip and eth headers in l2 tap queues on the fly Message-ID: References: <20240919184409.3511070-1-jmaloy@redhat.com> <20240919184409.3511070-2-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UlPqvtwQ2YeiifD2" Content-Disposition: inline In-Reply-To: <20240919184409.3511070-2-jmaloy@redhat.com> Message-ID-Hash: 5HQ5WN6J6333LW6B7VDSBXOV4SOOU3EC X-Message-ID-Hash: 5HQ5WN6J6333LW6B7VDSBXOV4SOOU3EC 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: --UlPqvtwQ2YeiifD2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 19, 2024 at 02:44:08PM -0400, Jon Maloy wrote: > l2 tap queue entries are currently initialized at system start, and > reused with preset headers through its whole life time. The only > fields we need to update per message are things like payload size > and checksums. >=20 > If we want to reuse these entries between ipv4 and ipv6 messages we > will need to set the pointer to the right header on the fly per > message, since the header type may differ between entries in the same > queue. >=20 > The same needs to be done for the ethernet header. >=20 > We do these changes here. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson >=20 > --- > v2: Setting pointers to pre-initialized IP and MAC headers instead of > copying them in on the fly. > v3: Adapted to D. Gibson's recent commit eliminitaing overlapping memcpy() > --- > tcp_buf.c | 54 ++++++++++++++++++++++++++++++------------------------ > 1 file changed, 30 insertions(+), 24 deletions(-) >=20 > diff --git a/tcp_buf.c b/tcp_buf.c > index ffbff5e..c56fb9c 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -159,8 +159,7 @@ void tcp_sock4_iov_init(const struct ctx *c) > iov =3D tcp4_l2_iov[i]; > =20 > iov[TCP_IOV_TAP] =3D tap_hdr_iov(c, &tcp4_payload_tap_hdr[i]); > - iov[TCP_IOV_ETH] =3D IOV_OF_LVALUE(tcp4_eth_src); > - iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp4_payload_ip[i]); > + iov[TCP_IOV_ETH].iov_len =3D sizeof(struct ethhdr); > iov[TCP_IOV_PAYLOAD].iov_base =3D &tcp4_payload[i]; > } > =20 > @@ -202,8 +201,7 @@ void tcp_sock6_iov_init(const struct ctx *c) > iov =3D tcp6_l2_iov[i]; > =20 > iov[TCP_IOV_TAP] =3D tap_hdr_iov(c, &tcp6_payload_tap_hdr[i]); > - iov[TCP_IOV_ETH] =3D IOV_OF_LVALUE(tcp6_eth_src); > - iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp6_payload_ip[i]); > + iov[TCP_IOV_ETH].iov_len =3D sizeof(struct ethhdr); > iov[TCP_IOV_PAYLOAD].iov_base =3D &tcp6_payload[i]; > } > =20 > @@ -302,11 +300,17 @@ int tcp_buf_send_flag(const struct ctx *c, struct t= cp_tap_conn *conn, int flags) > uint32_t seq; > int ret; > =20 > - if (CONN_V4(conn)) > - iov =3D tcp4_l2_flags_iov[tcp4_flags_used++]; > - else > - iov =3D tcp6_l2_flags_iov[tcp6_flags_used++]; > - > + if (CONN_V4(conn)) { > + iov =3D tcp4_l2_flags_iov[tcp4_flags_used]; > + iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp4_flags_ip[tcp4_flags_used]); > + iov[TCP_IOV_ETH].iov_base =3D &tcp4_eth_src; > + tcp4_flags_used++; > + } else { > + iov =3D tcp6_l2_flags_iov[tcp6_flags_used]; > + iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp6_flags_ip[tcp6_flags_used]); > + iov[TCP_IOV_ETH].iov_base =3D &tcp6_eth_src; > + tcp6_flags_used++; > + } > payload =3D iov[TCP_IOV_PAYLOAD].iov_base; > =20 > seq =3D conn->seq_to_tap; > @@ -325,21 +329,19 @@ int tcp_buf_send_flag(const struct ctx *c, struct t= cp_tap_conn *conn, int flags) > =20 > if (flags & DUP_ACK) { > struct iovec *dup_iov; > - int i; > =20 > if (CONN_V4(conn)) > dup_iov =3D tcp4_l2_flags_iov[tcp4_flags_used++]; > else > - dup_iov =3D tcp6_l2_flags_iov[tcp6_flags_used++]; > - > - for (i =3D 0; i < TCP_NUM_IOVS; i++) { > - /* All frames share the same ethernet header buffer */ > - if (i !=3D TCP_IOV_ETH) { > - memcpy(dup_iov[i].iov_base, iov[i].iov_base, > - iov[i].iov_len); > - } > - } > - dup_iov[TCP_IOV_PAYLOAD].iov_len =3D iov[TCP_IOV_PAYLOAD].iov_len; > + dup_iov =3D tcp4_l2_flags_iov[tcp6_flags_used++]; > + > + memcpy(dup_iov[TCP_IOV_TAP].iov_base, iov[TCP_IOV_TAP].iov_base, > + iov[TCP_IOV_TAP].iov_len); > + dup_iov[TCP_IOV_ETH].iov_base =3D iov[TCP_IOV_ETH].iov_base; > + dup_iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(iov[TCP_IOV_IP]); > + memcpy(dup_iov[TCP_IOV_PAYLOAD].iov_base, > + iov[TCP_IOV_PAYLOAD].iov_base, l4len); > + dup_iov[TCP_IOV_PAYLOAD].iov_len =3D l4len; > } > =20 > if (CONN_V4(conn)) { > @@ -379,8 +381,10 @@ static void tcp_data_to_tap(const struct ctx *c, str= uct tcp_tap_conn *conn, > } > =20 > tcp4_frame_conns[tcp4_payload_used] =3D conn; > - > - iov =3D tcp4_l2_iov[tcp4_payload_used++]; > + iov =3D tcp4_l2_iov[tcp4_payload_used]; > + iov[TCP_IOV_IP] =3D > + IOV_OF_LVALUE(tcp4_payload_ip[tcp4_payload_used++]); > + iov[TCP_IOV_ETH].iov_base =3D &tcp4_eth_src; > l4len =3D tcp_l2_buf_fill_headers(conn, iov, dlen, check, seq, > false); > iov[TCP_IOV_PAYLOAD].iov_len =3D l4len; > @@ -388,8 +392,10 @@ static void tcp_data_to_tap(const struct ctx *c, str= uct tcp_tap_conn *conn, > tcp_payload_flush(c); > } else if (CONN_V6(conn)) { > tcp6_frame_conns[tcp6_payload_used] =3D conn; > - > - iov =3D tcp6_l2_iov[tcp6_payload_used++]; > + iov =3D tcp6_l2_iov[tcp6_payload_used]; > + iov[TCP_IOV_IP] =3D > + IOV_OF_LVALUE(tcp6_payload_ip[tcp6_payload_used++]); > + iov[TCP_IOV_ETH].iov_base =3D &tcp6_eth_src; > l4len =3D tcp_l2_buf_fill_headers(conn, iov, dlen, NULL, seq, > false); > iov[TCP_IOV_PAYLOAD].iov_len =3D l4len; --=20 David Gibson (he or they) | 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 --UlPqvtwQ2YeiifD2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbs9+0ACgkQzQJF27ox 2GddhRAAqfXLYLgt3TpDbp9phgNrBD3W1j983eEl0SH1ROgFv4blo4zRR2Ui4NBj Tl2/ux49+hgAtAjzXnXRFv321mV0hfxTt4enrh+nsxR0qWLmmHCTVbRHAF0pOCe3 ry1F8RtwhaH+V7uC67afsTjzyE6SrsswOgLF9CZzfQtHygtG9pdvNTOXjUKrvetE zVuJziSeFP8I/eMTfanZpSOgUr3jbUsVwe1QakO4bJOUN5d0uqFPFkWuDUVqsJ7p saKY8wTDEQvQxrL80AiiCzt/6KVcC6X+W7RiZDKiFaBw7YNNYUqzfGW9BNE/PON5 NySTU/bJ9eWHJskjpERIoHaRQ2Z5BhIuepfwQ7Z5etECkATn62Levyjjy/gVH64N DCEAilMWYwGyF9IREDI7BDQ617LuYf7ZHVm3Y2UqCf0NGy6gRbRjHlPve4H753YW lt6vKG/GnYdFt9eK9azXeJaljYNauW8xMqA4/iTfBVwOjWlOtw6H8b+H2YhNRzHf mRDcUQrSVFp1s3MsvbqTnNtL8mSh/vqtqfL2galghDr5wXwPzJrbnq3k2hR4+FMY YeeLaYQauNFZMWrCJfXASINEQnhcwmoH8G4QEzL/r0N5uG+r1JXhO/RF8EilEWCl sEzsSrFtPBdySo+W9YQv41MO3GUQE5VbJqvWg4n0+cX3zU8V0Og= =MH4d -----END PGP SIGNATURE----- --UlPqvtwQ2YeiifD2--