public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 10/11] tcp_splice: Exploit side symmetry in tcp_splice_destroy()
Date: Mon, 6 Nov 2023 13:39:14 +1100	[thread overview]
Message-ID: <ZUhR0p5zSj0UNuvG@zatzit> (raw)
In-Reply-To: <20231103172213.35610a3f@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 3553 bytes --]

On Fri, Nov 03, 2023 at 05:22:13PM +0100, Stefano Brivio wrote:
> On Thu, 12 Oct 2023 12:51:13 +1100
> David Gibson <david@gibson.dropbear.id.au> 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 <david@gibson.dropbear.id.au>
> > ---
> >  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.

> 	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.

We are relying on the fact that setting SPLICE_ESTABLISHED doesn't
clear SPLICE_CONNECT.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-11-06  2:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12  1:51 [PATCH 00/11] tcp_splice: Better exploit symmetry between sides of connection David Gibson
2023-10-12  1:51 ` [PATCH 01/11] tcp_splice: Remove redundant tcp_splice_epoll_ctl() David Gibson
2023-10-12  1:51 ` [PATCH 02/11] tcp_splice: Correct error handling in tcp_splice_epoll_ctl() David Gibson
2023-10-12  1:51 ` [PATCH 03/11] tcp_splice: Don't handle EPOLL_CTL_DEL as part of tcp_splice_epoll_ctl() David Gibson
2023-11-03 16:20   ` Stefano Brivio
2023-11-04  5:56     ` David Gibson
2023-10-12  1:51 ` [PATCH 04/11] tcp_splice: Remove unnecessary forward declaration David Gibson
2023-10-12  1:51 ` [PATCH 05/11] tcp_splice: Avoid awkward temporaries in tcp_splice_epoll_ctl() David Gibson
2023-11-03 16:21   ` Stefano Brivio
2023-11-04  5:58     ` David Gibson
2023-10-12  1:51 ` [PATCH 06/11] tcp_splice: Don't pool pipes in pairs David Gibson
2023-10-12  1:51 ` [PATCH 07/11] tcp_splice: Rename sides of connection from a/b to 0/1 David Gibson
2023-10-12  1:51 ` [PATCH 08/11] tcp_splice: Exploit side symmetry in tcp_splice_timer() David Gibson
2023-11-03 16:21   ` Stefano Brivio
2023-11-04  5:59     ` David Gibson
2023-10-12  1:51 ` [PATCH 09/11] tcp_splice: Exploit side symmetry in tcp_splice_connect_finish() David Gibson
2023-10-12  1:51 ` [PATCH 10/11] tcp_splice: Exploit side symmetry in tcp_splice_destroy() David Gibson
2023-11-03 16:22   ` Stefano Brivio
2023-11-06  2:39     ` David Gibson [this message]
2023-11-06 13:21       ` Stefano Brivio
2023-10-12  1:51 ` [PATCH 11/11] tcp_splice: Simplify selection of socket and pipe sides in socket handler David Gibson
2023-11-03 16:21   ` Stefano Brivio
2023-11-04  6:02     ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZUhR0p5zSj0UNuvG@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).