public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 3/4] udp: Preadjust udp[46]_l2_iov_tap[].iov_base for pasta mode
Date: Thu, 24 Nov 2022 19:54:20 +1100	[thread overview]
Message-ID: <20221124085421.3027886-4-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20221124085421.3027886-1-david@gibson.dropbear.id.au>

Currently, we always populate udp[46]_l2_iov_tap[].iov_base with the
very start of the header buffers, including space for the qemu vnet_len
tag suitable for passt mode.  That's ok because we don't actually use these
iovecs for pasta mode.

However, we do know the mode in udp_sock[46]_iov_init() so adjust these
to the beginning of the headers we'll actually need for the mode: including
the vnet_len tag for passt, but excluding it for pasta.

This allows a slightly nicer way to locate the right buffer to send in the
pasta case, and will allow some additional cleanups later.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 udp.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/udp.c b/udp.c
index 6a34e85..e2eb504 100644
--- a/udp.c
+++ b/udp.c
@@ -314,8 +314,9 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
 
 /**
  * udp_sock4_iov_init() - Initialise scatter-gather L2 buffers for IPv4 sockets
+ * @c:		Execution context
  */
-static void udp_sock4_iov_init(void)
+static void udp_sock4_iov_init(const struct ctx *c)
 {
 	struct mmsghdr *h;
 	int i;
@@ -343,7 +344,11 @@ static void udp_sock4_iov_init(void)
 	for (i = 0, h = udp4_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
 		struct msghdr *mh = &h->msg_hdr;
 
-		udp4_l2_iov_tap[i].iov_base	= &udp4_l2_buf[i].vnet_len;
+		if (c->mode == MODE_PASTA)
+			udp4_l2_iov_tap[i].iov_base	= &udp4_l2_buf[i].eh;
+		else
+			udp4_l2_iov_tap[i].iov_base	= &udp4_l2_buf[i].vnet_len;
+
 		mh->msg_iov			= &udp4_l2_iov_tap[i];
 		mh->msg_iovlen			= 1;
 	}
@@ -351,8 +356,9 @@ static void udp_sock4_iov_init(void)
 
 /**
  * udp_sock6_iov_init() - Initialise scatter-gather L2 buffers for IPv6 sockets
+ * @c:		Execution context
  */
-static void udp_sock6_iov_init(void)
+static void udp_sock6_iov_init(const struct ctx *c)
 {
 	struct mmsghdr *h;
 	int i;
@@ -383,7 +389,11 @@ static void udp_sock6_iov_init(void)
 	for (i = 0, h = udp6_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
 		struct msghdr *mh = &h->msg_hdr;
 
-		udp6_l2_iov_tap[i].iov_base	= &udp6_l2_buf[i].vnet_len;
+		if (c->mode == MODE_PASTA)
+			udp6_l2_iov_tap[i].iov_base	= &udp6_l2_buf[i].eh;
+		else
+			udp6_l2_iov_tap[i].iov_base	= &udp6_l2_buf[i].vnet_len;
+
 		mh->msg_iov			= &udp6_l2_iov_tap[i];
 		mh->msg_iovlen			= 1;
 	}
@@ -681,16 +691,7 @@ static void udp_sock_fill_data_v4(const struct ctx *c, int n,
 	b->uh.len = htons(udp4_l2_mh_sock[n].msg_len + sizeof(b->uh));
 
 	if (c->mode == MODE_PASTA) {
-		/* If we pass &b->eh directly to write(), starting from
-		 * gcc 12.1, at least on aarch64 and x86_64, we get a bogus
-		 * stringop-overread warning, due to:
-		 *   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103483
-		 *
-		 * but we can't disable it with a pragma, because it will be
-		 * ignored if LTO is enabled:
-		 *   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80922
-		 */
-		void *frame = (char *)b + offsetof(struct udp4_l2_buf_t, eh);
+		void *frame = udp4_l2_iov_tap[n].iov_base;
 
 		if (write(c->fd_tap, frame, sizeof(b->eh) + ip_len) < 0)
 			debug("tap write: %s", strerror(errno));
@@ -792,8 +793,7 @@ static void udp_sock_fill_data_v6(const struct ctx *c, int n,
 	b->ip6h.hop_limit = 255;
 
 	if (c->mode == MODE_PASTA) {
-		/* See udp_sock_fill_data_v4() for the reason behind 'frame' */
-		void *frame = (char *)b + offsetof(struct udp6_l2_buf_t, eh);
+		void *frame = udp6_l2_iov_tap[n].iov_base;
 
 		if (write(c->fd_tap, frame, sizeof(b->eh) + ip_len) < 0)
 			debug("tap write: %s", strerror(errno));
@@ -1227,10 +1227,10 @@ static void udp_splice_iov_init(void)
 int udp_init(struct ctx *c)
 {
 	if (c->ifi4)
-		udp_sock4_iov_init();
+		udp_sock4_iov_init(c);
 
 	if (c->ifi6)
-		udp_sock6_iov_init();
+		udp_sock6_iov_init(c);
 
 	udp_invert_portmap(&c->udp.fwd_in);
 	udp_invert_portmap(&c->udp.fwd_out);
-- 
@@ -314,8 +314,9 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
 
 /**
  * udp_sock4_iov_init() - Initialise scatter-gather L2 buffers for IPv4 sockets
+ * @c:		Execution context
  */
-static void udp_sock4_iov_init(void)
+static void udp_sock4_iov_init(const struct ctx *c)
 {
 	struct mmsghdr *h;
 	int i;
@@ -343,7 +344,11 @@ static void udp_sock4_iov_init(void)
 	for (i = 0, h = udp4_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
 		struct msghdr *mh = &h->msg_hdr;
 
-		udp4_l2_iov_tap[i].iov_base	= &udp4_l2_buf[i].vnet_len;
+		if (c->mode == MODE_PASTA)
+			udp4_l2_iov_tap[i].iov_base	= &udp4_l2_buf[i].eh;
+		else
+			udp4_l2_iov_tap[i].iov_base	= &udp4_l2_buf[i].vnet_len;
+
 		mh->msg_iov			= &udp4_l2_iov_tap[i];
 		mh->msg_iovlen			= 1;
 	}
@@ -351,8 +356,9 @@ static void udp_sock4_iov_init(void)
 
 /**
  * udp_sock6_iov_init() - Initialise scatter-gather L2 buffers for IPv6 sockets
+ * @c:		Execution context
  */
-static void udp_sock6_iov_init(void)
+static void udp_sock6_iov_init(const struct ctx *c)
 {
 	struct mmsghdr *h;
 	int i;
@@ -383,7 +389,11 @@ static void udp_sock6_iov_init(void)
 	for (i = 0, h = udp6_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
 		struct msghdr *mh = &h->msg_hdr;
 
-		udp6_l2_iov_tap[i].iov_base	= &udp6_l2_buf[i].vnet_len;
+		if (c->mode == MODE_PASTA)
+			udp6_l2_iov_tap[i].iov_base	= &udp6_l2_buf[i].eh;
+		else
+			udp6_l2_iov_tap[i].iov_base	= &udp6_l2_buf[i].vnet_len;
+
 		mh->msg_iov			= &udp6_l2_iov_tap[i];
 		mh->msg_iovlen			= 1;
 	}
@@ -681,16 +691,7 @@ static void udp_sock_fill_data_v4(const struct ctx *c, int n,
 	b->uh.len = htons(udp4_l2_mh_sock[n].msg_len + sizeof(b->uh));
 
 	if (c->mode == MODE_PASTA) {
-		/* If we pass &b->eh directly to write(), starting from
-		 * gcc 12.1, at least on aarch64 and x86_64, we get a bogus
-		 * stringop-overread warning, due to:
-		 *   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103483
-		 *
-		 * but we can't disable it with a pragma, because it will be
-		 * ignored if LTO is enabled:
-		 *   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80922
-		 */
-		void *frame = (char *)b + offsetof(struct udp4_l2_buf_t, eh);
+		void *frame = udp4_l2_iov_tap[n].iov_base;
 
 		if (write(c->fd_tap, frame, sizeof(b->eh) + ip_len) < 0)
 			debug("tap write: %s", strerror(errno));
@@ -792,8 +793,7 @@ static void udp_sock_fill_data_v6(const struct ctx *c, int n,
 	b->ip6h.hop_limit = 255;
 
 	if (c->mode == MODE_PASTA) {
-		/* See udp_sock_fill_data_v4() for the reason behind 'frame' */
-		void *frame = (char *)b + offsetof(struct udp6_l2_buf_t, eh);
+		void *frame = udp6_l2_iov_tap[n].iov_base;
 
 		if (write(c->fd_tap, frame, sizeof(b->eh) + ip_len) < 0)
 			debug("tap write: %s", strerror(errno));
@@ -1227,10 +1227,10 @@ static void udp_splice_iov_init(void)
 int udp_init(struct ctx *c)
 {
 	if (c->ifi4)
-		udp_sock4_iov_init();
+		udp_sock4_iov_init(c);
 
 	if (c->ifi6)
-		udp_sock6_iov_init();
+		udp_sock6_iov_init(c);
 
 	udp_invert_portmap(&c->udp.fwd_in);
 	udp_invert_portmap(&c->udp.fwd_out);
-- 
2.38.1


  parent reply	other threads:[~2022-11-24  8:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24  8:54 [PATCH 0/4] udp: Fix some confusion of IPv4 and IPv6 control structures David Gibson
2022-11-24  8:54 ` [PATCH 1/4] udp: Fix inorrect use of IPv6 mh buffers in IPv4 path David Gibson
2022-11-24  8:54 ` [PATCH 2/4] udp: Better factor IPv4 and IPv6 paths in udp_sock_handler() David Gibson
2022-11-24  8:54 ` David Gibson [this message]
2022-11-24  8:54 ` [PATCH 4/4] udp: Factor out control structure management from udp_sock_fill_data_v[46] David Gibson
2022-11-25  2:01 ` [PATCH 0/4] udp: Fix some confusion of IPv4 and IPv6 control structures Stefano Brivio
2022-11-25  7:11   ` David Gibson
2022-12-06  6:47 ` Stefano Brivio

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=20221124085421.3027886-4-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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).