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.133.124]) by passt.top (Postfix) with ESMTP id 445755A026F for ; Mon, 6 Nov 2023 14:22:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699276921; 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=227Cfwsf2O68fdd+WAH76d8fKowZkGOcktcHL1IqusM=; b=cti1d8KWFHq25xxUzWncmuexQlQ20zcD26e9wQjnthfDkY2c8kKWskCeaMtEGapjLCApCl MCce4GZUwxv5n15aTWudo1ifUhFCMnujQiQLy4fJseYsq48pejIYfsL3lSEq+XhAxA3WnK 7RxD57YCuVpxr7JmE8bzJhI2sjpQF+w= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-dLbxbBSEO2Gb0gIgy_ZWpw-1; Mon, 06 Nov 2023 08:21:58 -0500 X-MC-Unique: dLbxbBSEO2Gb0gIgy_ZWpw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F7AC3C1E9CA; Mon, 6 Nov 2023 13:21:57 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D36440C6EB9; Mon, 6 Nov 2023 13:21:56 +0000 (UTC) Date: Mon, 6 Nov 2023 14:21:48 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 10/11] tcp_splice: Exploit side symmetry in tcp_splice_destroy() Message-ID: <20231106142148.4d32b971@elisabeth> In-Reply-To: References: <20231012015114.2612066-1-david@gibson.dropbear.id.au> <20231012015114.2612066-11-david@gibson.dropbear.id.au> <20231103172213.35610a3f@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: FYQZR5FR22FRJ6UGHNK4VH553ENJVUGW X-Message-ID-Hash: FYQZR5FR22FRJ6UGHNK4VH553ENJVUGW 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 Mon, 6 Nov 2023 13:39:14 +1100 David Gibson wrote: > On Fri, Nov 03, 2023 at 05:22:13PM +0100, Stefano Brivio wrote: > > On Thu, 12 Oct 2023 12:51:13 +1100 > > David Gibson wrote: > > > > > tcp_splice_destroy() has some close-to-duplicated logic handling closing of > > > the socket and ipies for each side of the connection. We can use a loop > > ^^^^^ pipes > > Oops, fixed. > > > > across the sides to reduce the duplication. > > > > > > Signed-off-by: David Gibson > > > --- > > > tcp_splice.c | 32 ++++++++++++++------------------ > > > 1 file changed, 14 insertions(+), 18 deletions(-) > > > > > > diff --git a/tcp_splice.c b/tcp_splice.c > > > index 99ef8a4..239f6d2 100644 > > > --- a/tcp_splice.c > > > +++ b/tcp_splice.c > > > @@ -258,30 +258,26 @@ void tcp_splice_conn_update(const struct ctx *c, struct tcp_splice_conn *new) > > > void tcp_splice_destroy(struct ctx *c, union tcp_conn *conn_union) > > > { > > > struct tcp_splice_conn *conn = &conn_union->splice; > > > + int side; > > > > > > - if (conn->events & SPLICE_ESTABLISHED) { > > > - /* Flushing might need to block: don't recycle them. */ > > > - if (conn->pipe[0][0] != -1) { > > > - close(conn->pipe[0][0]); > > > - close(conn->pipe[0][1]); > > > - conn->pipe[0][0] = conn->pipe[0][1] = -1; > > > + for (side = 0; side < SIDES; side++) { > > > + if (conn->events & SPLICE_ESTABLISHED) { > > > + /* Flushing might need to block: don't recycle them. */ > > > + if (conn->pipe[side][0] != -1) { > > > + close(conn->pipe[side][0]); > > > + close(conn->pipe[side][1]); > > > + conn->pipe[side][0] = conn->pipe[side][1] = -1; > > > + } > > > } > > > - if (conn->pipe[1][0] != -1) { > > > - close(conn->pipe[1][0]); > > > - close(conn->pipe[1][1]); > > > - conn->pipe[1][0] = conn->pipe[1][1] = -1; > > > + > > > + if (side == 0 || conn->events & SPLICE_CONNECT) { > > > + close(conn->s[side]); > > > + conn->s[side] = -1; > > > } > > > - } > > > > > > - if (conn->events & SPLICE_CONNECT) { > > > - close(conn->s[1]); > > > - conn->s[1] = -1; > > > + conn->read[side] = conn->written[side] = 0; > > > } > > > > > > - close(conn->s[0]); > > > - conn->s[0] = -1; > > > - conn->read[0] = conn->written[0] = conn->read[1] = conn->written[1] = 0; > > > > With this, on SPLICE_CONNECT, we would close the [0] side, but not the > > [1] side. SPLICE_CONNECT means we already have an open socket for [1], > > though. I think it should be: > > > > [loop on sides] > > > > if (side == 1 || conn->events & SPLICE_CONNECT) { > > close(conn->s[side]); > > conn->s[1] = -1; > > } > > } > > > > and then we still need to unconditionally close conn->s[0]. Perhaps we could > > take both parts outside of the loop: > > Uh.. I think you're misreading. In the updated code we have: > if (side == 0 || conn->events & SPLICE_CONNECT) { > close(conn->s[side]); > conn->s[side] = -1; > } > That's an OR, so we always close side 0, and we close side 1 iff we > have SPLICE_CONNECT, which matches what you're describing. Gosh, yes, sorry, I read && for some reason. -- Stefano