public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: "Eugenio Pérez" <eperezma@redhat.com>
To: passt-dev@passt.top
Cc: jasowang@redhat.com
Subject: [RFC v2 04/11] tcp: export memory regions to vhost
Date: Wed,  9 Jul 2025 19:47:41 +0200	[thread overview]
Message-ID: <20250709174748.3514693-5-eperezma@redhat.com> (raw)
In-Reply-To: <20250709174748.3514693-1-eperezma@redhat.com>

So vhost kernel is able to access the TCP buffers.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 tap.c     | 14 +++++++++++---
 tcp_buf.c | 14 ++++----------
 tcp_buf.h | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+), 13 deletions(-)

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"

+#include "tcp_buf.h"
+
 /* Maximum allowed frame lengths (including L2 header) */

 /* Verify that an L2 frame length limit is large enough to contain the header,
@@ -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 __attribute__((aligned(PAGE_SIZE)));

-/* 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
 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] = VHOST_MEMORY_REGION(vring_used_0);
 	vhost_memory.mem.regions[4] = VHOST_MEMORY_REGION(vring_used_1);
 	vhost_memory.mem.regions[5] = VHOST_MEMORY_REGION(pkt_buf);
-	static_assert(5 < N_VHOST_REGIONS);
+	vhost_memory.mem.regions[6] = VHOST_MEMORY_REGION(tcp_payload_tap_hdr);
+	vhost_memory.mem.regions[7] = VHOST_MEMORY_REGION(tcp4_eth_src);
+	vhost_memory.mem.regions[8] = VHOST_MEMORY_REGION(tcp6_eth_src);
+	vhost_memory.mem.regions[9] = VHOST_MEMORY_REGION(tcp4_payload_ip);
+	vhost_memory.mem.regions[10] = VHOST_MEMORY_REGION(tcp6_payload_ip);
+	vhost_memory.mem.regions[11] = VHOST_MEMORY_REGION(tcp_payload);
+	static_assert(11 < N_VHOST_REGIONS);
 #undef VHOST_MEMORY_REGION
 #undef VHOST_MEMORY_REGION_PTR

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 @@

 #include <netinet/tcp.h>

-#include <linux/virtio_net.h>
-
 #include "util.h"
 #include "ip.h"
 #include "iov.h"
@@ -35,24 +33,20 @@
 #include "tcp_internal.h"
 #include "tcp_buf.h"

-#define TCP_FRAMES_MEM			128
-#define TCP_FRAMES							   \
-	(c->mode == MODE_PASTA ? 1 : TCP_FRAMES_MEM)
-
 /* Static buffers */

 /* 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;

-static struct virtio_net_hdr_mrg_rxbuf tcp_payload_tap_hdr[TCP_FRAMES_MEM];
+struct virtio_net_hdr_mrg_rxbuf tcp_payload_tap_hdr[TCP_FRAMES_MEM];

 /* IP headers for IPv4 and IPv6 */
 struct iphdr		tcp4_payload_ip[TCP_FRAMES_MEM];
 struct ipv6hdr		tcp6_payload_ip[TCP_FRAMES_MEM];

 /* 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];

 static_assert(MSS4 <= sizeof(tcp_payload[0].data), "MSS4 is greater than 65516");
 static_assert(MSS6 <= sizeof(tcp_payload[0].data), "MSS6 is greater than 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

+#include <linux/virtio_net.h>
+
+#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 *conn);
 int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags);

+#define TCP_FRAMES_MEM			128
+#define TCP_FRAMES							   \
+(c->mode == MODE_PASTA ? 1 : TCP_FRAMES_MEM)
+
+extern struct virtio_net_hdr_mrg_rxbuf tcp_payload_tap_hdr[TCP_FRAMES_MEM];
+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 */
--
2.50.0


  parent reply	other threads:[~2025-07-09 17:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 17:47 [RFC v2 00/11] Add vhost-net kernel support Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 01/11] tap: implement vhost_call_cb Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 02/11] tap: add die() on vhost error Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 03/11] tap: replace tx tap hdr with virtio_nethdr_mrg_rxbuf Eugenio Pérez
2025-07-09 17:47 ` Eugenio Pérez [this message]
2025-07-09 17:47 ` [RFC v2 05/11] virtio: Fill .next in tx queue Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 06/11] tap: move static iov_sock to tcp_buf_data_from_sock Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 07/11] tap: support tx through vhost Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 08/11] tap: add tap_free_old_xmit Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 09/11] tcp: start conversion to circular buffer Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 10/11] tap: add poll(2) to used_idx Eugenio Pérez
2025-07-09 17:47 ` [RFC v2 11/11] tcp_buf: adding TCP tx circular buffer Eugenio Pérez
2025-07-10  9:46 ` [RFC v2 00/11] Add vhost-net kernel support Eugenio Perez Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250709174748.3514693-5-eperezma@redhat.com \
    --to=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).