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 AAEF25A0265 for ; Mon, 7 Nov 2022 19:08:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667844492; 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=SEKpTLYYFaHk81ePmUa6rsICNnBzBMwcccBme5Pf2mo=; b=YrOZB5SXh3OPZApYY3/J7/nqCFOw2nOsJkgopL/fpvuPzQUHJSFs3rFhxdq06kGRm34d9P Fv2pfFyplPzaW1H4ieBCcnyCMoT3zErC5q0sR1awCePKXAeVUDffXiu0bUFasFsNm39hdT lwVOjtogRJaPYntpbc+na/UyNQD97ZA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-Os0KO5sfMz6AQgOhQqO4qQ-1; Mon, 07 Nov 2022 13:08:09 -0500 X-MC-Unique: Os0KO5sfMz6AQgOhQqO4qQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BCC2F381078F; Mon, 7 Nov 2022 18:08:08 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-9.brq.redhat.com [10.40.208.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1951C42222; Mon, 7 Nov 2022 18:08:08 +0000 (UTC) Date: Mon, 7 Nov 2022 19:07:53 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 01/10] tcp: no v6 flag in ref Message-ID: <20221107190753.5e1cf0de@elisabeth> In-Reply-To: <20221104084333.3761760-2-david@gibson.dropbear.id.au> References: <20221104084333.3761760-1-david@gibson.dropbear.id.au> <20221104084333.3761760-2-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: HYZYPKSPVIZ2IGQBH3YAR43GANLZRIO2 X-Message-ID-Hash: HYZYPKSPVIZ2IGQBH3YAR43GANLZRIO2 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.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: On Fri, 4 Nov 2022 19:43:24 +1100 David Gibson wrote: > --- > tcp.c | 9 ++++----- > tcp.h | 1 - > tcp_splice.c | 13 +++++++------ > 3 files changed, 11 insertions(+), 12 deletions(-) > > diff --git a/tcp.c b/tcp.c > index 713248f..3d48d6e 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -761,8 +761,7 @@ static int tcp_epoll_ctl(const struct ctx *c, struct tcp_conn *conn) > { > int m = (conn->flags & IN_EPOLL) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; > union epoll_ref ref = { .r.proto = IPPROTO_TCP, .r.s = conn->sock, > - .r.p.tcp.tcp.index = conn - tc, > - .r.p.tcp.tcp.v6 = CONN_V6(conn) }; > + .r.p.tcp.tcp.index = conn - tc, }; > struct epoll_event ev = { .data.u64 = ref.u64 }; > > if (conn->events == CLOSED) { > @@ -2857,6 +2856,7 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref, > if (c->tcp.conn_count >= TCP_MAX_CONNS) > return; > > + sa.ss_family = AF_UNSPEC; /* FIXME: stop clang-tidy complaining */ No need for /* FIXME */ here in my opinion, valgrind should also hit this -- perhaps move to initialiser though. > sl = sizeof(sa); > s = accept4(ref.r.s, (struct sockaddr *)&sa, &sl, SOCK_NONBLOCK); > if (s < 0) > @@ -2868,7 +2868,7 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref, > conn->ws_to_tap = conn->ws_from_tap = 0; > conn_event(c, conn, SOCK_ACCEPTED); > > - if (ref.r.p.tcp.tcp.v6) { > + if (sa.ss_family == AF_INET6) { > struct sockaddr_in6 sa6; > > memcpy(&sa6, &sa, sizeof(sa6)); > @@ -3147,8 +3147,7 @@ static void tcp_sock_init6(const struct ctx *c, int ns, > const struct in6_addr *addr, const char *ifname, > in_port_t port) > { > - union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.outbound = ns, > - .tcp.v6 = 1 }; > + union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.outbound = ns, }; Undocumented style rule: no comma at the end, it's post-modern C anyway. > bool spliced = false, tap = true; > int s; > > diff --git a/tcp.h b/tcp.h > index 3fabb5a..85ac750 100644 > --- a/tcp.h > +++ b/tcp.h > @@ -45,7 +45,6 @@ union tcp_epoll_ref { > uint32_t listen:1, > splice:1, > outbound:1, > - v6:1, Don't forget to update the comment above. > timer:1, > index:20; > } tcp; > diff --git a/tcp_splice.c b/tcp_splice.c > index 99c5fa7..1f26ff4 100644 > --- a/tcp_splice.c > +++ b/tcp_splice.c > @@ -211,12 +211,10 @@ static int tcp_splice_epoll_ctl(const struct ctx *c, > int m = (conn->flags & IN_EPOLL) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; > union epoll_ref ref_a = { .r.proto = IPPROTO_TCP, .r.s = conn->a, > .r.p.tcp.tcp.splice = 1, > - .r.p.tcp.tcp.index = conn - tc, > - .r.p.tcp.tcp.v6 = CONN_V6(conn) }; > + .r.p.tcp.tcp.index = conn - tc, }; > union epoll_ref ref_b = { .r.proto = IPPROTO_TCP, .r.s = conn->b, > .r.p.tcp.tcp.splice = 1, > - .r.p.tcp.tcp.index = conn - tc, > - .r.p.tcp.tcp.v6 = CONN_V6(conn) }; > + .r.p.tcp.tcp.index = conn - tc, }; Commas. > struct epoll_event ev_a = { .data.u64 = ref_a.u64 }; > struct epoll_event ev_b = { .data.u64 = ref_b.u64 }; > uint32_t events_a, events_b; > @@ -579,12 +577,15 @@ void tcp_sock_handler_splice(struct ctx *c, union epoll_ref ref, > struct tcp_splice_conn *conn; > > if (ref.r.p.tcp.tcp.listen) { > + struct sockaddr sa; Should this be sockaddr_storage in this case and then cast? I never remember. > + socklen_t sl = sizeof(sa); > int s; > > if (c->tcp.splice_conn_count >= TCP_SPLICE_MAX_CONNS) > return; > > - if ((s = accept4(ref.r.s, NULL, NULL, SOCK_NONBLOCK)) < 0) > + sa.sa_family = AF_UNSPEC; /* FIXME: stop clang-tidy complaining */ > + if ((s = accept4(ref.r.s, &sa, &sl, SOCK_NONBLOCK)) < 0) Same comment about /* FIXME */ as above. This adds a copy_to_user() and microseconds, but it's unavoidable. I tried harder to optimise for latency on the spliced path, that's why it was NULL here and not above. > return; > > if (setsockopt(s, SOL_TCP, TCP_QUICKACK, &((int){ 1 }), > @@ -595,7 +596,7 @@ void tcp_sock_handler_splice(struct ctx *c, union epoll_ref ref, > > conn = CONN(c->tcp.splice_conn_count++); > conn->a = s; > - conn->flags = ref.r.p.tcp.tcp.v6 ? SOCK_V6 : 0; > + conn->flags = (sa.sa_family == AF_INET6) ? SOCK_V6 : 0; > > if (tcp_splice_new(c, conn, ref.r.p.tcp.tcp.index, > ref.r.p.tcp.tcp.outbound)) -- Stefano