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=UpXTqDtf; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6B96F5A004E for ; Tue, 29 Oct 2024 05:18:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1730175480; bh=J8M93dHbocPKiZshf8vtuVlcnTUTsZLvVWtvJb6hwRQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UpXTqDtfmfnx+ztvaiZ9cG8A8X1SmHMPSpG67su/qQRz6z+6tmW+xaffUN1IAAO8T JjnyCdEaoiqBULglQv97t7wdWecs5JXMTxn7AryQZgpIOD7mo7k4tWnbmmDICR9EB2 lqk9FbsK0WJZ7IZKJ0V/7kd+r99I7NA+cAS8Q0wCJBgPF3ibbulktIcthqcWnzVijK Y2lxmUoP+KFQQ0WWh7Yz6ltaIJFZIW0F7LFmnumjejRvL7gymRqA0VIvBsg/Psoy99 WVbC9lasn6SdPSEbHZtq4wvbL8kXKpSRG1w+hL8D+t6DfO2FYOmZfxx3UxXAwJTx4K rA2EeExUEJkLw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XcxnN4RXrz4wbR; Tue, 29 Oct 2024 15:18:00 +1100 (AEDT) Date: Tue, 29 Oct 2024 15:11:20 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v5 1/2] tcp: set ip and eth headers in l2 tap queues on the fly Message-ID: References: <20241029021400.784052-1-jmaloy@redhat.com> <20241029021400.784052-2-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RjlZFP3EA8pCaRdh" Content-Disposition: inline In-Reply-To: <20241029021400.784052-2-jmaloy@redhat.com> Message-ID-Hash: ZZGD2ENS3PQPA3AFOMT3E3RZYDA63Z5V X-Message-ID-Hash: ZZGD2ENS3PQPA3AFOMT3E3RZYDA63Z5V 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: --RjlZFP3EA8pCaRdh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 28, 2024 at 10:13:59PM -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() > v5: Fixed two bugs as per feedback from D. Gibson. > --- > tcp_buf.c | 50 ++++++++++++++++++++++++++++---------------------- > 1 file changed, 28 insertions(+), 22 deletions(-) >=20 > diff --git a/tcp_buf.c b/tcp_buf.c > index cb6742c..e249c6b 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++]; > =20 > - 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; > + 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[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)) { > @@ -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 --RjlZFP3EA8pCaRdh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmcgYGcACgkQzQJF27ox 2GeZvg/+L2HJ4jRjVPHSez3+3mh7o1VGBAAG1KFrZI1spKinBhvlm0pMlyKzNUOv UBgfzmmo6aQMS0EE8TmgBZrsZqvsRygUxRWIWxAv8Y0NUtNQyRZxW2vKIG1gyNp0 z3VsdrGgUg3M0bzET/4KjTQvEJEvrXR/AehFUQWYIZBP3eueOw2aATHR8+1Bw9+e uHhqWj2cw69UcRZYEYrOJkUBaTR+o+LpA234d7rfFjj0DLha0Whg9zkqwcOHAi5R mZbZRlGHgtWy3v3Eld/c10kkEEtMk0bp73cp0dLX7ZxLdSUuj2F4hWYDXu6ThbyB 0MHUXOhIDEODXkN5HNrt+dAnBlitc4WCYjl1mNRywNCj8tqzZiyaKdaO5fUCmp4G 2mu0LnWhAPV8gdDFXrhAvJmAauI3gEOYZtqncHIVIW5YFE8ArfOSuiub0bp4mr/0 X1sfrl6iMt2plSEqkMt9bEbKOzbhvkeIwOvbBR3dSsdAbpvLdyKihuEUD+ZjbgCw 2OR6Ljdf22vDEqvzLDQ62aJU/X8v9uaoK5xRFu+yMxSAc6+JMEsa1Wbb+59R29YJ y9/obMM6sPU5ieLJJ/pJEL5YLzqiLxQswxEbWMM+segpzKXFtbs5/UD0NsHPTE34 d207vQZ8LyLvs0PyeLGaJbkYRd+YHHpvJmSONXUf/zO4dcjeDo0= =3p3Q -----END PGP SIGNATURE----- --RjlZFP3EA8pCaRdh--