From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 551C85A0082 for ; Thu, 24 Nov 2022 09:54:27 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NHsHg5fVSz4xN7; Thu, 24 Nov 2022 19:54:23 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1669280063; bh=Uv3AttC0Am91epdlBL99FT8IUEGz+AfhvLtPc3VfJVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hf4OSerwRZDdkmbu5SelQfvc2yUDOgIksiXlskDz6AnvTcICFXV7l+b6mkaWrvVzd GVrU4kWqsRO11T/aBiXRWSNALVcKvgTKVPpwqYJoVl0idZUp/A9BUSTOgt8cymPtID 6uv6dAQpevz4yez33TbuoryMoUBctE1zii3LxMA4= From: David Gibson To: Stefano Brivio , passt-dev@passt.top 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 Message-Id: <20221124085421.3027886-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221124085421.3027886-1-david@gibson.dropbear.id.au> References: <20221124085421.3027886-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 74ROOE5MEGPRLWNQR6WB364BKGFCEK6I X-Message-ID-Hash: 74ROOE5MEGPRLWNQR6WB364BKGFCEK6I 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: David Gibson X-Mailman-Version: 3.3.3 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: 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 --- 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); -- 2.38.1