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 8CB285A026D for ; Fri, 3 Nov 2023 17:22:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699028522; 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=GS+6W4EMeYdHnzUzaDxTYx5NQwWwUuUdtqe98ITbCc0=; b=AMavajrAewXHifw4DU4jyNpyEUknoZX773jEFHhwvQPWiTx3ZlgRoyVnFOf1MPw3i3P8dP LJVp1ilEzBxxHhYTU2THmMX6Wn+3L7zIM9xdEdOI7M6d0DkqIgu29ctYHbu7Yke9oCkzEY MvaFlB2e8TPCW2O7GsEPPQFKMXTvmLk= 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-495-2iEbvtiHNuWu2sGF8eO5_Q-1; Fri, 03 Nov 2023 12:22:01 -0400 X-MC-Unique: 2iEbvtiHNuWu2sGF8eO5_Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 DF889381AE4D; Fri, 3 Nov 2023 16:22:00 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14B93492BFA; Fri, 3 Nov 2023 16:21:59 +0000 (UTC) Date: Fri, 3 Nov 2023 17:21:53 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 08/11] tcp_splice: Exploit side symmetry in tcp_splice_timer() Message-ID: <20231103172153.2f9894a8@elisabeth> In-Reply-To: <20231012015114.2612066-9-david@gibson.dropbear.id.au> References: <20231012015114.2612066-1-david@gibson.dropbear.id.au> <20231012015114.2612066-9-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: TNCU3TPOJLYE5UVYBA2RQIBVCW2DZHCV X-Message-ID-Hash: TNCU3TPOJLYE5UVYBA2RQIBVCW2DZHCV 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:11 +1100 David Gibson wrote: > tcp_splice_timer() has two very similar blocks one after another that > handle the SO_RCVLOWAT flags for the two sides of the connection. We can > deduplicate this with a loop across the two sides. > > Signed-off-by: David Gibson > --- > tcp_splice.c | 27 +++++++++++---------------- > 1 file changed, 11 insertions(+), 16 deletions(-) > > diff --git a/tcp_splice.c b/tcp_splice.c > index 4a0580c..259d774 100644 > --- a/tcp_splice.c > +++ b/tcp_splice.c > @@ -835,30 +835,25 @@ void tcp_splice_init(struct ctx *c) > void tcp_splice_timer(struct ctx *c, union tcp_conn *conn_union) > { > struct tcp_splice_conn *conn = &conn_union->splice; > + int side; > > if (conn->flags & CLOSING) { > tcp_splice_destroy(c, conn_union); > return; > } > > - if ( (conn->flags & RCVLOWAT_SET_0) && > - !(conn->flags & RCVLOWAT_ACT_0)) { > - if (setsockopt(conn->s[0], SOL_SOCKET, SO_RCVLOWAT, > - &((int){ 1 }), sizeof(int))) { > - trace("TCP (spliced): can't set SO_RCVLOWAT on " > - "%i", conn->s[0]); > - } > - conn_flag(c, conn, ~RCVLOWAT_SET_0); > - } > + for (side = 0; side < SIDES; side++) { > + uint8_t set = side == 0 ? RCVLOWAT_SET_0 : RCVLOWAT_SET_1; > + uint8_t act = side == 0 ? RCVLOWAT_ACT_0 : RCVLOWAT_ACT_1; > > - if ( (conn->flags & RCVLOWAT_SET_1) && > - !(conn->flags & RCVLOWAT_ACT_1)) { > - if (setsockopt(conn->s[1], SOL_SOCKET, SO_RCVLOWAT, > - &((int){ 1 }), sizeof(int))) { > - trace("TCP (spliced): can't set SO_RCVLOWAT on " > - "%i", conn->s[1]); > + if ( (conn->flags & set) && !(conn->flags & act)) { ^ Nit: this extra whitespace is now useless. -- Stefano