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 4B07C5A026D for ; Fri, 3 Nov 2023 17:25:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699028722; 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=MIvrMuu3+3P3NHo/+FGITGVKY9RhETqbrmx+XNUlEdc=; b=CJGa9r3U0d2+M1hj0YCx6hx1tiMBc4jRQGZkQCZSUHcZEf5ZdlILwZX3rfautVF6GJPIoX mhiUwvGfIqnevs5BoaHI1hnvbfQ8oITbe6Ztdxi8rKNUZYHSV+Myp/QI9mG9rP4hR5QE61 eLVVd3+EdX6MgZiT748vZaibyrLWeE4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-o7aH51M8Ng-cK-ewVgeeKQ-1; Fri, 03 Nov 2023 12:22:28 -0400 X-MC-Unique: o7aH51M8Ng-cK-ewVgeeKQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 EEA3B101A529; Fri, 3 Nov 2023 16:22:19 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25F552026D4C; Fri, 3 Nov 2023 16:22:18 +0000 (UTC) Date: Fri, 3 Nov 2023 17:22:13 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 10/11] tcp_splice: Exploit side symmetry in tcp_splice_destroy() Message-ID: <20231103172213.35610a3f@elisabeth> In-Reply-To: <20231012015114.2612066-11-david@gibson.dropbear.id.au> References: <20231012015114.2612066-1-david@gibson.dropbear.id.au> <20231012015114.2612066-11-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 73OPIMFBD5Q4XCHPE5H7AABTN3UE6SH5 X-Message-ID-Hash: 73OPIMFBD5Q4XCHPE5H7AABTN3UE6SH5 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, 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 > 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: if (conn->events & SPLICE_CONNECT) { close(conn->s[1]); conn->s[1] = -1; } close(conn->s[0]); conn->s[0] = -1; conn->read[side] = conn->written[side] = 0; The handling for the SPLICE_ESTABLISHED case looks correct to me. -- Stefano