From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UcqKAwbG; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 0B15B5A0262 for ; Sun, 10 May 2026 01:57:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778371058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jshsvM32rI5e5atj814rwVXQcyqOtq1VIRQdkXPPgr0=; b=UcqKAwbGS63nszEy13vUR5FgZJiBITftJpNGZCH4qP+BbtymjDhBLiqPnkkVaFidtCmHTO ZYpaKDqdY0T+UJ9JOCIpQOBiT0S96JpAMCFLwkqau8G46OWTt+3Lz9PS/xBEkg13bc1lxO tkNzMqj5PeRZjCOp/iNfcDJUkXIRmo0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-04vmtjBLNRqWuhJ0nQ9caA-1; Sat, 09 May 2026 19:57:37 -0400 X-MC-Unique: 04vmtjBLNRqWuhJ0nQ9caA-1 X-Mimecast-MFC-AGG-ID: 04vmtjBLNRqWuhJ0nQ9caA_1778371057 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8dd61e9d1faso506706385a.2 for ; Sat, 09 May 2026 16:57:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778371057; x=1778975857; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jshsvM32rI5e5atj814rwVXQcyqOtq1VIRQdkXPPgr0=; b=POX1wM90fxaShI7gl/1K1PxKWMXZXWoEr8ovgPUU4YaMxFyvGhAfNuEVBr8587NX3D 8Zq1MV48TYl3eB0L0ler+7TkdgovBc70IhZAhy1RBhtaSZkkJeX2I2ipwt0Z83gpPJZK 2m+yE94aKIWpVAD6ECoRJtEgnOvdb8BIOdgwZlTsPMqAg6Zl6LzCKpUyKsgfUqA+yGkU zV9P9fa2O0Wua0DoRQudbmEUqC3pQVcxCETpIDY3U1AnNQJmeda1i2cPCl4JboUFS1d9 rDq/cJE/QLsgUXKOGcHsXBE8t1YPB/csrt7vNjo4SqAtYKlP3/bPfUbdG7ddt2UBy8V4 JHPw== X-Forwarded-Encrypted: i=1; AFNElJ+NEKPYqXBVY+W2O6zklBe0cqSlGjRD/J8ab89wxwV2cWkLzyhA6book1Lpp2lIRkLeFkx9XegNo4I=@passt.top X-Gm-Message-State: AOJu0Yw5fWJHezq9wRyyaTAs9UsatKXuHMzNBjJGYC/Twxxm3fok7lPO aPHLhFbpapN9MKKhpDO8O4tmBKX2wjAOf26Aribmz2FfGIKkLC9YBm0Hb5HX9dGAD1OTJqY3hXE KpNejRyFNvfhvF6IaoAfIWNKOne34tO5KSmtsC3znhxdJfVWiDSEP9w== X-Gm-Gg: Acq92OGM/3eQUVZCqaBDmGvdlLhYlERjjDOBS5dV+iAgW/R8IAeEjgsJw7FPc5rEsQd ZkX03RAcVp2Pl3KldAayvYr5qm41JX6uu24ignfU1n0jQG8cZELCapTMLm57sRrQPMpyMKQxNap HzF5w7gFJB0ifKp5Zzkrw7HYDZK76uKLws/nW6LssCklowY89UT2WKqTX/JU0cxIGt0wnYLm3mV xC2BuJwAETMD37Fcz8Cw8p4/ZnQmiLGNW/Zr8b6sRozpsvQFHzoX0E+lxjQI/eaYW+0Fz1E+F0u JsGmHBGECwHGoWelsM+VhIMR5itGoG3BDYb9zpg7gqEoD8+lpJL1NMYlwLxkMUXWNFvSlcuzsYX wdCK0kqZx++EGGydaFfzdJ/L12EIL+UlZfpoVhHbx49ZDRD9C+tM48n6f4ojucuCSdDjnYtxRmf j+0yxyvZh3lT6h X-Received: by 2002:a05:620a:2283:b0:905:f3df:7fd2 with SMTP id af79cd13be357-905f3df84a6mr1698182785a.44.1778371056930; Sat, 09 May 2026 16:57:36 -0700 (PDT) X-Received: by 2002:a05:620a:2283:b0:905:f3df:7fd2 with SMTP id af79cd13be357-905f3df84a6mr1698180685a.44.1778371056495; Sat, 09 May 2026 16:57:36 -0700 (PDT) Received: from [192.168.2.15] (lnsm4-toronto63-142-116-28-118.internet.virginmobile.ca. [142.116.28.118]) by smtp.gmail.com with ESMTPSA id af79cd13be357-907b8e98521sm633289485a.17.2026.05.09.16.57.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 May 2026 16:57:36 -0700 (PDT) Message-ID: Date: Sat, 9 May 2026 19:57:35 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 2/4] tcp_vu: Build headers on the stack and write them into the iovec To: Laurent Vivier , passt-dev@passt.top References: <20260416161618.3826904-1-lvivier@redhat.com> <20260416161618.3826904-3-lvivier@redhat.com> From: Jon Maloy In-Reply-To: <20260416161618.3826904-3-lvivier@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wQXyodP15K3HT4ph77o5x6swVa9tv1jdgoVnVVmLQiQ_1778371057 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: SANZAI6EM7FPEODLYIWTY2C6F45ZUJLR X-Message-ID-Hash: SANZAI6EM7FPEODLYIWTY2C6F45ZUJLR X-MailFrom: jmaloy@redhat.com 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 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: On 2026-04-16 12:16, Laurent Vivier wrote: > tcp_vu_prepare() currently assumes the first iovec element provided by > the guest is large enough to hold all L2-L4 headers, and builds them > in place via pointer casts into iov[0].iov_base. This assumption is > enforced by an assert(). > > Since the headers in the buffer are uninitialized anyway, we can just > as well build the Ethernet, IP, and TCP headers on the stack instead, > and write them into the iovec with IOV_PUSH_HEADER(). This mirrors the > approach already used in udp_vu_prepare(), and prepares for support of > elements with multiple iovecs. > > Signed-off-by: Laurent Vivier LGTM Reviewed-by: Jon Maloy > --- > tcp_vu.c | 60 ++++++++++++++++++++++++-------------------------------- > 1 file changed, 26 insertions(+), 34 deletions(-) > > diff --git a/tcp_vu.c b/tcp_vu.c > index 3e399c20f0d7..2017aec90342 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -296,49 +296,41 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, > bool v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); > size_t hdrlen = tcp_vu_hdrlen(v6); > struct iov_tail payload = IOV_TAIL(iov, iov_cnt, hdrlen); > - char *base = iov[0].iov_base; > - struct ipv6hdr *ip6h = NULL; > - struct iphdr *ip4h = NULL; > - struct tcphdr *th; > - struct ethhdr *eh; > - > - /* we guess the first iovec provided by the guest can embed > - * all the headers needed by L2 frame, including any padding > - */ > - assert(iov[0].iov_len >= hdrlen); > + struct ipv6hdr ip6h; > + struct iphdr ip4h; > + struct tcphdr th; > + struct ethhdr eh; > > - eh = vu_eth(base); > - > - memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > + memcpy(eh.h_dest, c->guest_mac, sizeof(eh.h_dest)); > > /* initialize header */ > > - if (!v6) { > - eh->h_proto = htons(ETH_P_IP); > - > - ip4h = vu_ip(base); > - *ip4h = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); > - th = vu_payloadv4(base); > - } else { > - eh->h_proto = htons(ETH_P_IPV6); > + if (!v6) > + ip4h = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); > + else > + ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); > > - ip6h = vu_ip(base); > - *ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); > + memset(&th, 0, sizeof(th)); > + th.doff = sizeof(th) / 4; > + th.ack = 1; > + th.psh = push; > > - th = vu_payloadv6(base); > - } > + tcp_fill_headers(c, conn, &eh, v6 ? NULL : &ip4h, v6 ? &ip6h : NULL, &th, > + &payload, dlen, *csum_flags, conn->seq_to_tap); > > - memset(th, 0, sizeof(*th)); > - th->doff = sizeof(*th) / 4; > - th->ack = 1; > - th->psh = push; > + /* Preserve TCP_CSUM, overwrite IP4_CSUM as we set the checksum */ > + if (!v6) > + *csum_flags = (*csum_flags & TCP_CSUM) | ip4h.check; > > - tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, dlen, > - *csum_flags, conn->seq_to_tap); > + /* write headers */ > + payload = IOV_TAIL(iov, iov_cnt, VNET_HLEN); > > - /* Preserve TCP_CSUM, overwrite IP4_CSUM as we set the checksum */ > - if (ip4h) > - *csum_flags = (*csum_flags & TCP_CSUM) | ip4h->check; > + IOV_PUSH_HEADER(&payload, eh); > + if (!v6) > + IOV_PUSH_HEADER(&payload, ip4h); > + else > + IOV_PUSH_HEADER(&payload, ip6h); > + IOV_PUSH_HEADER(&payload, th); > } > > /**