From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id E4A875A004E for ; Thu, 13 Jun 2024 17:07:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pelKSZ/EOipa2J/khW4kxAH22tSk2nuRADgwdNSYejk=; b=hlW63beH3by3riiand2ZUXwAvhHeJfAefnQolz71OtMIPOWCUVekc1jhivA+EXHX0Hv4MW xOJkCMOFnHpt5B+whdok1ETwG5+GjO/uHJU0k5axy+q1xxisRLAWRWuJHWbxtAF8DWQumI Q14o6JEaXSlRBY2Cji3naKvMSDuRbcs= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-PxLSIm3oPP6SL9gbKmVWug-1; Thu, 13 Jun 2024 11:07:33 -0400 X-MC-Unique: PxLSIm3oPP6SL9gbKmVWug-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-795589ae41fso133520885a.0 for ; Thu, 13 Jun 2024 08:07:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718291252; x=1718896052; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pelKSZ/EOipa2J/khW4kxAH22tSk2nuRADgwdNSYejk=; b=ZhVVYB5pcYTHq9D3xYa0v/P0+tWTnVPn0CX0AwQ4e509/LJR2c7CLAcR7FlAJjUYlL lU1vlbstOesyKBs/YS+K6KjT0ayNYrZEawoLGuzQF26Bxyt6kVWjUfuKHzb42mZO3axR aJafXHnuGNExFWShsdrxMG34Tn64LAcUasAsRxFgdDP9kliBCPl4lHf53Ll/ZRxPPbc0 aN8Dhy5AcEY0Jnz19LgqSUf42pQPrNIyQHa41iBQcApc5aBx3DrjCnBN+Q5OtLoH5/Kw 2MB2rYkCFlE0vvN8Ok6xgzfaZWq3QA5wPVA5KoEIU586BSZttxQjOhLJSwEBjfWbNy7i jkUg== X-Gm-Message-State: AOJu0YwmwcfAcAbkloqMjulTIxR06kilzhRnVYWsjU/p6Ji7NqCJAiaF wrUUjTZNIMno4/miLyzkbqsShMSZCfK80orQ0pl6CpMUoR86dS8CoyywZaVbqgJiauEFgAuvuXC adC202QG2hq865QyxVVVaefeSaL5M+O6O8KeDqDqNTlLPR6L8L7PwJ6prF5qC X-Received: by 2002:a05:620a:2483:b0:795:5d83:9f8f with SMTP id af79cd13be357-797f602c8a1mr548164285a.39.1718291251947; Thu, 13 Jun 2024 08:07:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqmeyazljeyPGPEbXoSklRiKmnEb64EFUBzvFr3PM2Kdbp7j9ubqavcEI38vrt4i+UfasYDw== X-Received: by 2002:a05:620a:2483:b0:795:5d83:9f8f with SMTP id af79cd13be357-797f602c8a1mr548159585a.39.1718291251383; Thu, 13 Jun 2024 08:07:31 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798c39d8cafsm38502685a.127.2024.06.13.08.07.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2024 08:07:30 -0700 (PDT) Date: Thu, 13 Jun 2024 17:06:54 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/4] udp: Fold checking of splice flag into udp_mmh_splice_port() Message-ID: <20240613170654.4a2b9731@elisabeth> In-Reply-To: <20240605013903.3694452-3-david@gibson.dropbear.id.au> References: <20240605013903.3694452-1-david@gibson.dropbear.id.au> <20240605013903.3694452-3-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: NXS5BVFIWIIQLFXAZLVVPHGEHRVYJ42H X-Message-ID-Hash: NXS5BVFIWIIQLFXAZLVVPHGEHRVYJ42H X-MailFrom: sbrivio@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 CC: passt-dev@passt.top 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 Wed, 5 Jun 2024 11:39:01 +1000 David Gibson wrote: > udp_mmh_splice_port() is used to determine if a UDP datagram can be > "spliced" (forwarded via a socket instead of tap). We only invoke it if > the origin socket has the 'splice' flag set. > > Fold the checking of the flag into the helper itself, which makes the > caller simpler. It does mean we have a loop looking for a batch of > spliceable or non-spliceable packets even in the case where the flag is > clear. This shouldn't be that expensive though, since each call to > udp_mmh_splice_port() will return without accessing memory in that case. > In any case we're going to need a similar loop in more cases with upcoming > flow table work. > > Signed-off-by: David Gibson > --- > udp.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/udp.c b/udp.c > index 3abafc99..7487d2b2 100644 > --- a/udp.c > +++ b/udp.c > @@ -467,21 +467,25 @@ static int udp_splice_new_ns(void *arg) > > /** > * udp_mmh_splice_port() - Is source address of message suitable for splicing? > - * @v6: Is @sa a sockaddr_in6 (otherwise sockaddr_in)? > + * @uref: UDP epoll reference for incoming message's origin socket > * @mmh: mmsghdr of incoming message > * > - * Return: if @sa refers to localhost (127.0.0.1 or ::1) the port from > - * @sa in host order, otherwise -1. > + * Return: if source address of message in @mmh refers to localhost (127.0.0.1 Pre-existing, and I guess this might change again with the complete flow table implementation, so it probably doesn't make sense to fix this now: it's 127.0.0.0/8, not necessarily 127.0.0.1. As to whether we actually need to preserve a source address that's not 127.0.0.1, but in 127.0.0.0/8, as we "splice", I'm not quite sure. I think we could bind() the socket in the target namespace, but I haven't tried, and I don't know if it makes sense at all (I can't think of any use case). > + * or ::1) its source port (host order), otherwise -1. > */ > -static int udp_mmh_splice_port(bool v6, const struct mmsghdr *mmh) > +static int udp_mmh_splice_port(union udp_epoll_ref uref, > + const struct mmsghdr *mmh) > { > const struct sockaddr_in6 *sa6 = mmh->msg_hdr.msg_name; > const struct sockaddr_in *sa4 = mmh->msg_hdr.msg_name; > > - if (v6 && IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) > + if (!uref.splice) > + return -1; > + > + if (uref.v6 && IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) > return ntohs(sa6->sin6_port); > > - if (!v6 && IN4_IS_ADDR_LOOPBACK(&sa4->sin_addr)) > + if (!uref.v6 && IN4_IS_ADDR_LOOPBACK(&sa4->sin_addr)) > return ntohs(sa4->sin_port); > > return -1; > @@ -768,18 +772,15 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, (now renamed to udp_buf_sock_handler() if you're wondering) > > for (i = 0; i < n; i += m) { > int splicefrom = -1; > - m = n; > > - if (ref.udp.splice) { > - splicefrom = udp_mmh_splice_port(v6, mmh_recv + i); > + splicefrom = udp_mmh_splice_port(ref.udp, mmh_recv + i); > > - for (m = 1; i + m < n; m++) { > - int p; > + for (m = 1; i + m < n; m++) { > + int p; > > - p = udp_mmh_splice_port(v6, mmh_recv + i + m); > - if (p != splicefrom) > - break; > - } > + p = udp_mmh_splice_port(ref.udp, mmh_recv + i + m); > + if (p != splicefrom) > + break; > } > > if (splicefrom >= 0) -- Stefano