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=FlUHMdbt; 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 181485A0271 for ; Mon, 07 Apr 2025 23:49:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744062568; 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=9c4pXumuNYfCMb4qg0qGGuhN0Xc9TZMBmdTmSuOQUgE=; b=FlUHMdbtARZHD+T51rLLFo0XYq8fBUGnL2zTF2IFRYwOtjSVHFcGVvF46JDZUrRRH73vAH QUT92RL6oSjP+HEvPIAqW5YZC8191Uoun/wEyB1xY80uSujsjPhTSz8FuM3nuUVJw/4OMf v7Vr2fYbqSxep0u7SQVm2oFTU3xMp38= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-LU0rGdrjMt-oJ0X10YnP3g-1; Mon, 07 Apr 2025 17:49:27 -0400 X-MC-Unique: LU0rGdrjMt-oJ0X10YnP3g-1 X-Mimecast-MFC-AGG-ID: LU0rGdrjMt-oJ0X10YnP3g_1744062566 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43e9a3d2977so38956935e9.1 for ; Mon, 07 Apr 2025 14:49:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744062566; x=1744667366; 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=9c4pXumuNYfCMb4qg0qGGuhN0Xc9TZMBmdTmSuOQUgE=; b=KafU51/YYlwwozZEb0t7NhNqFFPxONlNo3rlcZdbp8nTWknCRBVyGjw1Oti8ahl80+ uspGtQW6lot9OhnA++4Yqj7n+46scQqC+pqTQaFyRHB/PCcrWhSfsVXPZ3Bniw6f1NeA Pv76ulS/i0uWCCPebOTAnU7rL2FzFve9ZiWJa+R3gyrYIAcIX7IWEg9VPzFYdkbci+58 8khqP38ToIGoIJja194dCGT4sLTcm6ke8KdHdCgfcu/VON5hObGj4KkOp6RrXbwtqDXz EW+D8pR9Nx7Tt+mF3qTV46uHzeB/5pGDIDGQLakx5TrI/Tda9ue9ZarGvvxTJw6MEaew 3X7Q== X-Gm-Message-State: AOJu0YwmHCXi+dWxTXA9bAoA7Lg7RNMIim8Zfp65oVzsyxS/x57hE2Mz FE8UThAN3X4H0EmDnXv1nEZ8N5iRFrNXSLRkck5fIrHqi+TFgpRfJcqgArsEWmbG4yX1d1nzViX /clN2Ey/+Gl3LcYerLU/dd2W1zV0reZgN6yCdZkpWfMwWLy2GLBKn3sKtyQ== X-Gm-Gg: ASbGncsCzWcF0wYk7aUHs7H6W1eXo9Gh13TQ5vT24TIS7K17B+FEH5UEkrQia8aKJ1R p+s39fTYnWdOD+Ct06K7im0V+U2+Z6KNxObIYRnwA9Vz8/I3pHYdm9b0tAVpdPgkZyhOWWVaV2I tGC/eQZIE7OnCUyn0/DV58yAlJ5FU023yuI8ehQekHpI7/ejsyciv9k1ToZPvlXOpS2hiXHeZy6 S5OrOEw9y8yNiYHly4Ta17Vn4P/nJ2nM6u0+kkdZDJxAS3CWbMjPh3M51k1FMCOpbbLI0EbTBLp klSUQYbplPj495sOViWolygS41pFVPsUOyQZ0KusvyUW X-Received: by 2002:a05:6000:2909:b0:391:3d12:9afa with SMTP id ffacd0b85a97d-39d0de19dcdmr11730379f8f.21.1744062566011; Mon, 07 Apr 2025 14:49:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpSnEsLq/JFZ+Vxp599Kbx0gPQL6oq6POzApXgLFVWT3Ri8EqPFrKqi+inVHFNjICtZBu1FA== X-Received: by 2002:a05:6000:2909:b0:391:3d12:9afa with SMTP id ffacd0b85a97d-39d0de19dcdmr11730369f8f.21.1744062565597; Mon, 07 Apr 2025 14:49:25 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c301a6c89sm13035015f8f.28.2025.04.07.14.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 14:49:25 -0700 (PDT) Date: Mon, 7 Apr 2025 23:49:24 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 06/12] udp: Split spliced forwarding path from udp_buf_reply_sock_data() Message-ID: <20250407234924.6043b3ee@elisabeth> In-Reply-To: <20250404101542.3729316-7-david@gibson.dropbear.id.au> References: <20250404101542.3729316-1-david@gibson.dropbear.id.au> <20250404101542.3729316-7-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6ODEVEPlUBmzVuB77OZZ9-iFAy4PZKer-gXSP5m1dvE_1744062566 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: S7FFBIBSCM5B2JQSFW6OZQEYRXVWHAOZ X-Message-ID-Hash: S7FFBIBSCM5B2JQSFW6OZQEYRXVWHAOZ 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 Fri, 4 Apr 2025 21:15:36 +1100 David Gibson wrote: > udp_buf_reply_sock_data() can handle forwarding data either from socket > to socket ("splicing") or from socket to tap. It has a test on each > datagram for which case we're in, but that will be the same for everything > in the batch. > > Split out the spliced path into a separate udp_sock_to_sock() function. > This leaves udp_{buf,vu}_reply_sock_data() handling only forwards from > socket to tap, so rename and simplify them accordingly. > > This makes the code slightly longer for now, but will allow future cleanups > to shrink it back down again. > > Signed-off-by: David Gibson > --- > udp.c | 103 ++++++++++++++++++++++++++++++------------------------- > udp_vu.c | 12 ++----- > udp_vu.h | 3 +- > 3 files changed, 60 insertions(+), 58 deletions(-) > > diff --git a/udp.c b/udp.c > index d81f1213..144e625f 100644 > --- a/udp.c > +++ b/udp.c > @@ -671,6 +671,49 @@ static int udp_sock_recv(const struct ctx *c, int s, struct mmsghdr *mmh, int n) > return n; > } > > +/** > + * udp_sock_to_sock() - Forward datagrams from socket to socket > + * @c: Execution context > + * @from_s: Socket to receive datagrams from > + * @n: Maximum number of datagrams to forward > + * @tosidx: Flow & side to forward datagrams too "to", fixed on merge. > + */ > +static void udp_sock_to_sock(const struct ctx *c, int from_s, int n, > + flow_sidx_t tosidx) > +{ > + int i; > + > + if ((n = udp_sock_recv(c, from_s, udp_mh_recv, n)) <= 0) > + return; > + > + for (i = 0; i < n; i++) > + udp_splice_prepare(udp_mh_recv, i); > + > + udp_splice_send(c, 0, n, tosidx); > +} > + > +/** > + * udp_buf_sock_to_tap() - Forward datagrams from socket to tap > + * @c: Execution context > + * @s: Socket to read data from > + * @n: Maximum number of datagrams to forward > + * @tosidx: Flow & side to forward data from @s to > + */ > +static void udp_buf_sock_to_tap(const struct ctx *c, int s, int n, > + flow_sidx_t tosidx) > +{ > + const struct flowside *toside = flowside_at_sidx(tosidx); > + int i; > + > + if ((n = udp_sock_recv(c, s, udp_mh_recv, n)) <= 0) > + return; > + > + for (i = 0; i < n; i++) > + udp_tap_prepare(udp_mh_recv, i, toside, false); > + > + tap_send_frames(c, &udp_l2_iov[0][0], UDP_NUM_IOVS, n); > +} > + > /** > * udp_buf_listen_sock_data() - Handle new data from socket > * @c: Execution context > @@ -738,43 +781,6 @@ void udp_listen_sock_handler(const struct ctx *c, > } > } > > -/** > - * udp_buf_reply_sock_data() - Handle new data from flow specific socket > - * @c: Execution context > - * @s: Socket to read data from > - * @n: Maximum number of datagrams to forward > - * @tosidx: Flow & side to forward data from @s to > - * > - * Return: true on success, false if can't forward from socket to flow's pif > - */ > -static bool udp_buf_reply_sock_data(const struct ctx *c, int s, int n, > - flow_sidx_t tosidx) > -{ > - const struct flowside *toside = flowside_at_sidx(tosidx); > - uint8_t topif = pif_at_sidx(tosidx); > - int i; > - > - if ((n = udp_sock_recv(c, s, udp_mh_recv, n)) <= 0) > - return true; > - > - for (i = 0; i < n; i++) { > - if (pif_is_socket(topif)) > - udp_splice_prepare(udp_mh_recv, i); > - else if (topif == PIF_TAP) > - udp_tap_prepare(udp_mh_recv, i, toside, false); > - } > - > - if (pif_is_socket(topif)) { > - udp_splice_send(c, 0, n, tosidx); > - } else if (topif == PIF_TAP) { > - tap_send_frames(c, &udp_l2_iov[0][0], UDP_NUM_IOVS, n); > - } else { > - return false; > - } > - > - return true; > -} > - > /** > * udp_sock_handler() - Handle new data from flow specific socket > * @c: Execution context > @@ -806,21 +812,26 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, > */ > size_t n = (c->mode == MODE_PASTA ? 1 : UDP_MAX_FRAMES); > flow_sidx_t tosidx = flow_sidx_opposite(ref.flowside); > + uint8_t topif = pif_at_sidx(tosidx); > int s = ref.fd; > - bool ret; > > flow_trace(uflow, "Received data on reply socket"); > uflow->ts = now->tv_sec; > > - if (c->mode == MODE_VU) { > - ret = udp_vu_reply_sock_data(c, s, UDP_MAX_FRAMES, > - tosidx); > + if (pif_is_socket(topif)) { > + udp_sock_to_sock(c, ref.fd, n, tosidx); > + } else if (topif == PIF_TAP) { > + if (c->mode == MODE_VU) { > + udp_vu_sock_to_tap(c, s, UDP_MAX_FRAMES, > + tosidx); > + } else { > + udp_buf_sock_to_tap(c, s, n, tosidx); > + } > } else { > - ret = udp_buf_reply_sock_data(c, s, n, tosidx); > - } > - > - if (!ret) { > - flow_err(uflow, "Unable to forward UDP"); > + flow_err(uflow, > + "No support for forwarding UDP from %s to %s", > + pif_name(pif_at_sidx(ref.flowside)), > + pif_name(topif)); > goto fail; > } > } > diff --git a/udp_vu.c b/udp_vu.c > index b2618b39..fcccef65 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -254,16 +254,13 @@ void udp_vu_listen_sock_data(const struct ctx *c, union epoll_ref ref, > } > > /** > - * udp_vu_reply_sock_data() - Handle new data from flow specific socket > + * udp_vu_sock_to_tap() - Forward datagrames from socket to tap "datagrams", fixed on merge. > * @c: Execution context > * @s: Socket to read data from > * @n: Maximum number of datagrams to forward > * @tosidx: Flow & side to forward data from @s to > - * > - * Return: true on success, false if can't forward from socket to flow's pif > */ > -bool udp_vu_reply_sock_data(const struct ctx *c, int s, int n, > - flow_sidx_t tosidx) > +void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx) > { > const struct flowside *toside = flowside_at_sidx(tosidx); > bool v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); > @@ -271,9 +268,6 @@ bool udp_vu_reply_sock_data(const struct ctx *c, int s, int n, > struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; > int i; > > - if (pif_at_sidx(tosidx) != PIF_TAP) > - return false; > - > for (i = 0; i < n; i++) { > ssize_t dlen; > int iov_used; > @@ -290,6 +284,4 @@ bool udp_vu_reply_sock_data(const struct ctx *c, int s, int n, > } > vu_flush(vdev, vq, elem, iov_used); > } > - > - return true; > } > diff --git a/udp_vu.h b/udp_vu.h > index c897c36f..576b0e71 100644 > --- a/udp_vu.h > +++ b/udp_vu.h > @@ -8,7 +8,6 @@ > > void udp_vu_listen_sock_data(const struct ctx *c, union epoll_ref ref, > const struct timespec *now); > -bool udp_vu_reply_sock_data(const struct ctx *c, int s, int n, > - flow_sidx_t tosidx); > +void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx); > > #endif /* UDP_VU_H */ -- Stefano