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=202506 header.b=DLeHkxAf; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 50A585A0280 for ; Wed, 23 Jul 2025 09:06:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202506; t=1753254218; bh=JbLEqocJ6CXlnSmEzLlvIXtu4QmsT4ZwXtEi+ZZPjhQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DLeHkxAfoKTeoSZ3KdOTODl63dtixUT0CTVPWp+etbenj5SA6kS06EQhkMD5/VspK g0Aixmz2yyFuhYR3loYtWubFse6rr47KPvAWdqnRa2y1UAh7e3PrUhaldJdggm1L5C 7u/QJfLrvHhUl22o+anLjg+hlI1eRQ9rBA0K7f5fR2xOBq+aBWghrfMMNEmkj7U5ND upfzXEfdOcm7y0JEsBQduVPsSzBPabLi0MUoKcjwH1531t29vwr7oKqCfHEeP8FQlb 5vTD1pE4m0gxNRsXIwOfj8qS/jEP3PhIUhWzgKV2rj5KYV3MBjJWl+Ht/al2/dkEet TOcta90pieGCA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bn4qG1ZgWz4xPd; Wed, 23 Jul 2025 17:03:38 +1000 (AEST) Date: Wed, 23 Jul 2025 17:06:18 +1000 From: David Gibson To: Eugenio =?iso-8859-1?Q?P=E9rez?= Subject: Re: [RFC v2 04/11] tcp: export memory regions to vhost Message-ID: References: <20250709174748.3514693-1-eperezma@redhat.com> <20250709174748.3514693-5-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="DE2RRd2rF1u2tWfN" Content-Disposition: inline In-Reply-To: <20250709174748.3514693-5-eperezma@redhat.com> Message-ID-Hash: JZ53QADBWIHOBD5EQBVD4GUVZSTTVDEF X-Message-ID-Hash: JZ53QADBWIHOBD5EQBVD4GUVZSTTVDEF 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, jasowang@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: --DE2RRd2rF1u2tWfN Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 09, 2025 at 07:47:41PM +0200, Eugenio P=E9rez wrote: > So vhost kernel is able to access the TCP buffers. >=20 > Signed-off-by: Eugenio P=E9rez > --- > tap.c | 14 +++++++++++--- > tcp_buf.c | 14 ++++---------- > tcp_buf.h | 19 +++++++++++++++++++ > 3 files changed, 34 insertions(+), 13 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index 0656294..8b3ec45 100644 > --- a/tap.c > +++ b/tap.c > @@ -63,6 +63,8 @@ > #include "vhost_user.h" > #include "vu_common.h" >=20 > +#include "tcp_buf.h" > + I don't love including the pretty specific content of tcp_buf.h into the mostly protocol unaware tap.c. Though I do realise that avoiding it will probably have other tradeoffs. > /* Maximum allowed frame lengths (including L2 header) */ >=20 > /* Verify that an L2 frame length limit is large enough to contain the h= eader, > @@ -136,8 +138,8 @@ static union { > char buf[offsetof(struct vring_used, ring[VHOST_NDESCS])]; > } vring_used_0 __attribute__((aligned(PAGE_SIZE))), vring_used_1 __attri= bute__((aligned(PAGE_SIZE))); >=20 > -/* all descs ring + 2rings * 2vqs + tx pkt buf + rx pkt buf */ > -#define N_VHOST_REGIONS 6 > +/* all descs ring + 2rings * 2vqs + tx pkt buf + rx pkt buf + TCP virtio= hdr + TCP eth(src,dst) + TCP ip hdr */ > +#define N_VHOST_REGIONS 12 Hmm. Keeping this and the region initialisation in sync is pretty clunky. I recall that before I went on leave we were discussing just exposing pasta's whole data segment to vhost; was there a reason for changing that plan, or just that you haven't implemented it so far? > union { > struct vhost_memory mem; > char buf[offsetof(struct vhost_memory, regions[N_VHOST_REGIONS])]; > @@ -1635,7 +1637,13 @@ static int tap_ns_tun(void *arg) > vhost_memory.mem.regions[3] =3D VHOST_MEMORY_REGION(vring_used_0); > vhost_memory.mem.regions[4] =3D VHOST_MEMORY_REGION(vring_used_1); > vhost_memory.mem.regions[5] =3D VHOST_MEMORY_REGION(pkt_buf); > - static_assert(5 < N_VHOST_REGIONS); > + vhost_memory.mem.regions[6] =3D VHOST_MEMORY_REGION(tcp_payload_tap_hdr= ); > + vhost_memory.mem.regions[7] =3D VHOST_MEMORY_REGION(tcp4_eth_src); > + vhost_memory.mem.regions[8] =3D VHOST_MEMORY_REGION(tcp6_eth_src); > + vhost_memory.mem.regions[9] =3D VHOST_MEMORY_REGION(tcp4_payload_ip); > + vhost_memory.mem.regions[10] =3D VHOST_MEMORY_REGION(tcp6_payload_ip); > + vhost_memory.mem.regions[11] =3D VHOST_MEMORY_REGION(tcp_payload); > + static_assert(11 < N_VHOST_REGIONS); If all the regions are global variables, you could put them into a static const array, then define N_VHOST_REGIONS via ARRAY_SIZE(). > #undef VHOST_MEMORY_REGION > #undef VHOST_MEMORY_REGION_PTR >=20 > diff --git a/tcp_buf.c b/tcp_buf.c > index 2fbd056..c999d2e 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -22,8 +22,6 @@ >=20 > #include >=20 > -#include > - > #include "util.h" > #include "ip.h" > #include "iov.h" > @@ -35,24 +33,20 @@ > #include "tcp_internal.h" > #include "tcp_buf.h" >=20 > -#define TCP_FRAMES_MEM 128 > -#define TCP_FRAMES \ > - (c->mode =3D=3D MODE_PASTA ? 1 : TCP_FRAMES_MEM) > - > /* Static buffers */ >=20 > /* Ethernet header for IPv4 and IPv6 frames */ > -static struct ethhdr tcp4_eth_src; > -static struct ethhdr tcp6_eth_src; > +struct ethhdr tcp4_eth_src; > +struct ethhdr tcp6_eth_src; >=20 > -static struct virtio_net_hdr_mrg_rxbuf tcp_payload_tap_hdr[TCP_FRAMES_ME= M]; > +struct virtio_net_hdr_mrg_rxbuf tcp_payload_tap_hdr[TCP_FRAMES_MEM]; >=20 > /* IP headers for IPv4 and IPv6 */ > struct iphdr tcp4_payload_ip[TCP_FRAMES_MEM]; > struct ipv6hdr tcp6_payload_ip[TCP_FRAMES_MEM]; >=20 > /* TCP segments with payload for IPv4 and IPv6 frames */ > -static struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM]; > +struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM]; >=20 > static_assert(MSS4 <=3D sizeof(tcp_payload[0].data), "MSS4 is greater th= an 65516"); > static_assert(MSS6 <=3D sizeof(tcp_payload[0].data), "MSS6 is greater th= an 65516"); > diff --git a/tcp_buf.h b/tcp_buf.h > index 54f5e53..7ae2536 100644 > --- a/tcp_buf.h > +++ b/tcp_buf.h > @@ -6,9 +6,28 @@ > #ifndef TCP_BUF_H > #define TCP_BUF_H >=20 > +#include > + > +#include "tcp_conn.h" > +#include "tcp_internal.h" > + > void tcp_sock_iov_init(const struct ctx *c); > void tcp_payload_flush(const struct ctx *c); > +struct tcp_tap_conn; > int tcp_buf_data_from_sock(const struct ctx *c, struct tcp_tap_conn *con= n); > int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, in= t flags); >=20 > +#define TCP_FRAMES_MEM 128 > +#define TCP_FRAMES \ > +(c->mode =3D=3D MODE_PASTA ? 1 : TCP_FRAMES_MEM) > + > +extern struct virtio_net_hdr_mrg_rxbuf tcp_payload_tap_hdr[TCP_FRAMES_ME= M]; > +extern struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM]; > + > +extern struct ethhdr tcp4_eth_src; > +extern struct ethhdr tcp6_eth_src; > + > +extern struct iphdr tcp4_payload_ip[TCP_FRAMES_MEM]; > +extern struct ipv6hdr tcp6_payload_ip[TCP_FRAMES_MEM]; > + > #endif /*TCP_BUF_H */ --=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 --DE2RRd2rF1u2tWfN Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmiAiekACgkQzQJF27ox 2GffOg/8CLfAcp9ko5gvCClDi3yYJrcmTzulJkoIHmKvDYzIvjhRm2gP6LL6hEQ1 3UnXK5iR0S7lfE/e4LtmyS+bMqTGlWA2bEH0yNxNR/bySW3wnWTnEPg7Jc2cPZvK rCahbKQQtyvk/qBx5peFR/x3MoWEVy+/8EYYgaJyAZLtUnMqXtyie2W8vaaMgFlL cF+mF4aDiSZ9C8wUdfAT1Olu3CI8lZCg0mBROQaL2kwlf9sPz5CTJVsG8S4L2i+a Npf73Ljc1vDilbcIFjMx69s7D3kMDLTVJd++gKIs6LToVvheK9/79kcROZsXPOMh L5lu3zyjxBy52soDZufgnOnlsi5c/aOo9hKWkzHnX0uIM+9Xin11RZD/7QDX780A VmmtrfZY7IM18AvHXO4ha0e9fYUKFasmWCUFSYTI9BwqtStvL8FdSS+R3SBITEte GT5GcjKo2aC8x3wQDlrEL4Uo36LpxEClQuhtncfmjyJgSDfK3X8dFyzSPMs+vm8I 3IiV5k32yrNyq5C3HtUiUERhd1JvRJJhOmRStewwvThGZ3VNyYho3JhkkMuva+Rs 6Fm23qgC/zQE9mPIl4H8VBK5EZKtK47qpM0/16rwwl0wV9DlEiYjhVdNjsi238an FW4UDMXOzgeR2Kvm2mg7RizOkL311ZOrJFUJcDYBVVsz7Uez2XA= =jNX9 -----END PGP SIGNATURE----- --DE2RRd2rF1u2tWfN--