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 113C55A004F for ; Thu, 04 Jul 2024 23:20:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720128045; 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=gN4yGpQ0W4CyuGuJgJAZJHuBYpU+bDQbcjX1hgEgJpM=; b=cZcog0uIPpyRfdFJJUYo+TS5j4qqmQH9BuwhTAxyzys0Edwl1CmAiaEVZntgqWJyrDsJSI Pb92daZpVWEIThNEYackpex5Uckq1asofexZgC9vfiKPpz6+PK7/sLNLWv3cBQdZ/zWfXs U2UbQiD+2Y+kGdcVU/KeU2lG8vuJyzw= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-CIW4jJZwONeR4QDmlza62Q-1; Thu, 04 Jul 2024 17:20:44 -0400 X-MC-Unique: CIW4jJZwONeR4QDmlza62Q-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-4ed02be3439so355790e0c.2 for ; Thu, 04 Jul 2024 14:20:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720128043; x=1720732843; 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=gN4yGpQ0W4CyuGuJgJAZJHuBYpU+bDQbcjX1hgEgJpM=; b=a1j6tdonl66a7ZrxQMBcnb8YnIlpPSLpQ2+PD671V0sAYi94LbObK8dec8uNG4j0rP jNhRGRpMFVe2R+4mZkGwJT+/vgt6orDS4sWsEsJktz920STGjH2vAZeFJPUr3Ygt9AMA GzcdXM1mmP4apxqMR9XTW1Q8HlJuIYBewISz8YyaD3EPQtKOQw2NpJqNaDppE8XBvbpx z18QoDppmqdjP+MRyVxwgra9Lh1AchxpnKJ/eivzsPpQniUt9BvXHD9rC2NH1wqUIOAw ooGgBE/TNBktzuEvJcwYoEjSQvUfoQ96VkZ6TipqDQltK7f36w6F7wCA+nHHz4PqFeOd IyWw== X-Gm-Message-State: AOJu0YyxxPnrpfjCGr6d6/xeAyYYPbPH5jT2NE+f8AwB9iUJkvOgldWm vqupjeCd3//KBbF5KehQo5qfXWuvWgY8/zZBwEiA/i4JK/4Pc83/TSxoHo1uIs+0+98OYPUgSF6 nPIuv4+UZpzUf1l6jQd2NkQinBcXjGp0w/mYo+lH14frw2HCvafJbcL9WGwL0 X-Received: by 2002:a05:6122:f91:b0:4ed:740:c2a9 with SMTP id 71dfb90a1353d-4f2f40a44b8mr3618169e0c.16.1720128042680; Thu, 04 Jul 2024 14:20:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwRvWjIQDCyPGEqje63Fxlw2cnoKgQtHzutMIJ1F6xxwT/Tp3+wwgpskXpRX2Dy11lMH7joA== X-Received: by 2002:a05:6122:f91:b0:4ed:740:c2a9 with SMTP id 71dfb90a1353d-4f2f40a44b8mr3618151e0c.16.1720128042204; Thu, 04 Jul 2024 14:20:42 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-446514984b6sm62927661cf.68.2024.07.04.14.20.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jul 2024 14:20:41 -0700 (PDT) Date: Thu, 4 Jul 2024 23:20:07 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 03/11] udp: Pass full epoll reference through more of sock handler path Message-ID: <20240704232007.0aa0cbe5@elisabeth> In-Reply-To: <20240704045835.1149746-4-david@gibson.dropbear.id.au> References: <20240704045835.1149746-1-david@gibson.dropbear.id.au> <20240704045835.1149746-4-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: 5C36XHP6WOSU5JLVX4FYPWY4ULV4J7DT X-Message-ID-Hash: 5C36XHP6WOSU5JLVX4FYPWY4ULV4J7DT 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 Thu, 4 Jul 2024 14:58:27 +1000 David Gibson wrote: > udp_buf_sock_handler() takes the epoll reference from the receiving socket, > and passes the UDP relevant part on to several other functions. Future > changes are going to need several different epoll types for UDP, and to > pass that information through to some of those functions. To avoid extra > noise in the patches making the real changes, change those functions now > to take the full epoll reference, rather than just the UDP part. > > Signed-off-by: David Gibson > --- > udp.c | 63 +++++++++++++++++++++++++++++++---------------------------- > 1 file changed, 33 insertions(+), 30 deletions(-) > > diff --git a/udp.c b/udp.c > index eadf4872..6301bda2 100644 > --- a/udp.c > +++ b/udp.c > @@ -477,25 +477,26 @@ static int udp_splice_new_ns(void *arg) > > /** > * udp_mmh_splice_port() - Is source address of message suitable for splicing? > - * @uref: UDP epoll reference for incoming message's origin socket > + * @ref: Epoll reference for incoming message's origin socket Nit: in 1/11 (and later in this patch), this is "epoll" instead, which looks more correct to me as it's a proper noun, but not capitalised. Same for udp_update_hdr6(). > * @mmh: mmsghdr of incoming message > * > * Return: if source address of message in @mmh refers to localhost (127.0.0.1 > * or ::1) its source port (host order), otherwise -1. > */ > -static int udp_mmh_splice_port(union udp_epoll_ref uref, > - const struct mmsghdr *mmh) > +static int udp_mmh_splice_port(union epoll_ref ref, 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 (!uref.splice) > + ASSERT(ref.type == EPOLL_TYPE_UDP); > + > + if (!ref.udp.splice) > return -1; > > - if (uref.v6 && IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) > + if (ref.udp.v6 && IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) > return ntohs(sa6->sin6_port); > > - if (!uref.v6 && IN4_IS_ADDR_LOOPBACK(&sa4->sin_addr)) > + if (!ref.udp.v6 && IN4_IS_ADDR_LOOPBACK(&sa4->sin_addr)) > return ntohs(sa4->sin_port); > > return -1; > @@ -507,7 +508,7 @@ static int udp_mmh_splice_port(union udp_epoll_ref uref, > * @start: Index of first datagram in udp[46]_l2_buf > * @n: Total number of datagrams in udp[46]_l2_buf pool > * @dst: Datagrams will be sent to this port (on destination side) > - * @uref: UDP epoll reference for origin socket > + * @ref: epoll reference for origin socket > * @now: Timestamp > * > * This consumes as many datagrams as are sendable via a single socket. It > @@ -518,7 +519,7 @@ static int udp_mmh_splice_port(union udp_epoll_ref uref, > * Return: Number of datagrams forwarded > */ > static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n, > - in_port_t dst, union udp_epoll_ref uref, > + in_port_t dst, union epoll_ref ref, > const struct timespec *now) > { > in_port_t src = udp_meta[start].splicesrc; > @@ -527,8 +528,9 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n, > int s; > > ASSERT(udp_meta[start].splicesrc >= 0); > + ASSERT(ref.type == EPOLL_TYPE_UDP); > > - if (uref.v6) { > + if (ref.udp.v6) { > mmh_recv = udp6_l2_mh_sock; > mmh_send = udp6_mh_splice; > udp6_localname.sin6_port = htons(dst); > @@ -544,27 +546,27 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n, > if (++i >= n) > break; > > - udp_meta[i].splicesrc = udp_mmh_splice_port(uref, &mmh_recv[i]); > + udp_meta[i].splicesrc = udp_mmh_splice_port(ref, &mmh_recv[i]); > } while (udp_meta[i].splicesrc == src); > > - if (uref.pif == PIF_SPLICE) { > + if (ref.udp.pif == PIF_SPLICE) { > src += c->udp.fwd_in.rdelta[src]; > - s = udp_splice_init[uref.v6][src].sock; > - if (s < 0 && uref.orig) > - s = udp_splice_new(c, uref.v6, src, false); > + s = udp_splice_init[ref.udp.v6][src].sock; > + if (s < 0 && ref.udp.orig) > + s = udp_splice_new(c, ref.udp.v6, src, false); > > if (s < 0) > goto out; > > - udp_splice_ns[uref.v6][dst].ts = now->tv_sec; > - udp_splice_init[uref.v6][src].ts = now->tv_sec; > + udp_splice_ns[ref.udp.v6][dst].ts = now->tv_sec; > + udp_splice_init[ref.udp.v6][src].ts = now->tv_sec; > } else { > - ASSERT(uref.pif == PIF_HOST); > + ASSERT(ref.udp.pif == PIF_HOST); > src += c->udp.fwd_out.rdelta[src]; > - s = udp_splice_ns[uref.v6][src].sock; > - if (s < 0 && uref.orig) { > + s = udp_splice_ns[ref.udp.v6][src].sock; > + if (s < 0 && ref.udp.orig) { > struct udp_splice_new_ns_arg arg = { > - c, uref.v6, src, -1, > + c, ref.udp.v6, src, -1, > }; > > NS_CALL(udp_splice_new_ns, &arg); > @@ -573,8 +575,8 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n, > if (s < 0) > goto out; > > - udp_splice_init[uref.v6][dst].ts = now->tv_sec; > - udp_splice_ns[uref.v6][src].ts = now->tv_sec; > + udp_splice_init[ref.udp.v6][dst].ts = now->tv_sec; > + udp_splice_ns[ref.udp.v6][src].ts = now->tv_sec; > } > > sendmmsg(s, mmh_send + start, i - start, MSG_NOSIGNAL); > @@ -716,7 +718,7 @@ static size_t udp_update_hdr6(const struct ctx *c, > * @start: Index of first datagram in udp[46]_l2_buf pool > * @n: Total number of datagrams in udp[46]_l2_buf pool > * @dstport: Destination port number on destination side > - * @uref: UDP epoll reference for origin socket > + * @ref: Epoll reference for origin socket > * @now: Current timestamp > * > * This consumes as many frames as are sendable via tap. It requires that > @@ -726,7 +728,7 @@ static size_t udp_update_hdr6(const struct ctx *c, > * Return: Number of frames sent via tap > */ > static unsigned udp_tap_send(const struct ctx *c, size_t start, size_t n, > - in_port_t dstport, union udp_epoll_ref uref, > + in_port_t dstport, union epoll_ref ref, > const struct timespec *now) > { > struct iovec (*tap_iov)[UDP_NUM_IOVS]; > @@ -734,8 +736,9 @@ static unsigned udp_tap_send(const struct ctx *c, size_t start, size_t n, > size_t i = start; > > ASSERT(udp_meta[start].splicesrc == -1); > + ASSERT(ref.type == EPOLL_TYPE_UDP); > > - if (uref.v6) { > + if (ref.udp.v6) { > tap_iov = udp6_l2_iov_tap; > mmh_recv = udp6_l2_mh_sock; > } else { > @@ -748,7 +751,7 @@ static unsigned udp_tap_send(const struct ctx *c, size_t start, size_t n, > struct udp_meta_t *bm = &udp_meta[i]; > size_t l4len; > > - if (uref.v6) { > + if (ref.udp.v6) { > l4len = udp_update_hdr6(c, &bm->ip6h, > &bm->s_in.sa6, bp, dstport, > udp6_l2_mh_sock[i].msg_len, now); > @@ -766,7 +769,7 @@ static unsigned udp_tap_send(const struct ctx *c, size_t start, size_t n, > if (++i >= n) > break; > > - udp_meta[i].splicesrc = udp_mmh_splice_port(uref, &mmh_recv[i]); > + udp_meta[i].splicesrc = udp_mmh_splice_port(ref, &mmh_recv[i]); > } while (udp_meta[i].splicesrc == -1); > > tap_send_frames(c, &tap_iov[start][0], UDP_NUM_IOVS, i - start); > @@ -823,12 +826,12 @@ void udp_buf_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t eve > * present). So we fill in entry 0 before the loop, then udp_*_send() > * populate one entry past where they consume. > */ > - udp_meta[0].splicesrc = udp_mmh_splice_port(ref.udp, mmh_recv); > + udp_meta[0].splicesrc = udp_mmh_splice_port(ref, mmh_recv); > for (i = 0; i < n; i += m) { > if (udp_meta[i].splicesrc >= 0) > - m = udp_splice_send(c, i, n, dstport, ref.udp, now); > + m = udp_splice_send(c, i, n, dstport, ref, now); > else > - m = udp_tap_send(c, i, n, dstport, ref.udp, now); > + m = udp_tap_send(c, i, n, dstport, ref, now); > } > } > -- Stefano