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=202410 header.b=DtXYQx6z; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id BE65E5A004E for ; Mon, 14 Oct 2024 07:02:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1728882164; bh=ovz82i7MDX4ZZbVbDMBA1xBJk28EWvFatNsVudEYXKU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DtXYQx6zW3YeOiA5HApdvgmqEOiO7D9oU10Lbs4FO/xHp9WuMhb93afwvpSuZFERN nDR8h29wEWXNSBvccd/Ztvk/n9b5rDz2T/5Mz8gV7WoYXlImo0Badj/YzQmZPkgMRD QgC7nbZUaT4vgzf5OGHvHiUDdB4Q5iSWsRz1xMhdGyXA2f+jrvKind6JNSNqcG8S8o jGMeN6H+wSNpdezauQ5fXYCZGej9HB1ADwRVtUbS/TCGE29ayL/DsguOKzVcw/N3hI rxur/jM7NXeor5vM8K00Q/CKsk5H0WYx4iLYKgOrAm7cg1uLnvSlNIKMNBMuTgq/Fg ADDOxkSxLlU3w== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XRlTw2V8tz4x8W; Mon, 14 Oct 2024 16:02:44 +1100 (AEDT) Date: Mon, 14 Oct 2024 13:35:00 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v4 1/2] tcp: set ip and eth headers in l2 tap queues on the fly Message-ID: References: <20241011183540.3045143-1-jmaloy@redhat.com> <20241011183540.3045143-2-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pkvgDetgpwfTMK5d" Content-Disposition: inline In-Reply-To: <20241011183540.3045143-2-jmaloy@redhat.com> Message-ID-Hash: PYSG3T3N6L23DKGJCEU4WRTL5D64OFIT X-Message-ID-Hash: PYSG3T3N6L23DKGJCEU4WRTL5D64OFIT 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: --pkvgDetgpwfTMK5d Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 11, 2024 at 02:35:39PM -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 >=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 238827b..e4fa59f 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -130,8 +130,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 > @@ -173,8 +172,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 > @@ -273,11 +271,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; > @@ -296,21 +300,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++]; This should be tcp6_l2_flags_iov[], no? I guess it will become when the arrays are merged in a subsequent patch. > + > + 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]); This should be: dup_iov[TCP_IOV_IP] =3D iov[TCP_IOV_IP]; IOV_OF_LVALUE() won't work because you don't have a sized lvalue to use. In fact, I think this will make the dup packet's IP header have the contents of the struct iovec pointing at the original header, which is clearly nonsense. > + 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)) { > @@ -350,8 +352,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; > @@ -359,8 +363,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 --pkvgDetgpwfTMK5d Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmcMg0QACgkQzQJF27ox 2Gcdgg/+POA27K/laceH5JzQK/+TGE49QAmoc8o/Kj7EMj9jw11LoSJTCvFGWxfH SGP06QZgqdJBOeM94Ko+JN/9Z65AvumdB9zmD8M/sH4/5SYKpTO/H99QJVu69vw9 McPHvta0koFspJc9ZVs2mOSrQPzrqg0gJwilSDGzyhIo6axn08Rw1lm2eVHmMJxk vKBnlATv4HZPUPgZkJqsKMNCeEBzxzM+NAZmpjasuOZEDNucTE0MayOOp2Oclv29 JGcMb1Cl0wPunVmiF0YvkHNV7RJ9G0dbOzl6czhSDGZhovWEOYL6GIAwXFRQNK2H EWqGDr3U2c6YoNrK8E01hoPuuFFJqwP5apky4MkUAXqKZd6ije3l+cBEYtY2ctwR xuZQakyiu5CHnYxgHdg/yY/BOpQ5vM/ncXedSBET2B2h+MmDSJOu4AMwvNcH7z57 lQq8VwOKtvDHm9DZoq6ZKzX6PdG2hfcaPkPtXgT63vgFT7TYKwVc03FN7qvFqZnl MBOH2NZrBtA94eVV/l2RwwQPDvmTJ1AV61GBS4lZxpjSB9P9L9eKZ2Y9jXCvvoBS oxv3/g7nXojiZfa7XcmXvOsq6G4cRVnWO1jDiCDXs4FGQHjE4X4IfjACgRys8xrh bpFPl0FkhVzryF/HUYAeJsdgySOPqT9rEp8Jqu95flYu5A2z6sk= =B52q -----END PGP SIGNATURE----- --pkvgDetgpwfTMK5d--