public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Jon Maloy <jmaloy@redhat.com>,
	passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com,
	dgibson@redhat.com
Subject: Re: [PATCH v2] tcp: add support for SO_PEEK_OFF
Date: Thu, 08 Feb 2024 17:05:36 +0100	[thread overview]
Message-ID: <c6edb4fa61e80a30f27b5b86da6453ba168bbe7f.camel@redhat.com> (raw)
In-Reply-To: <20240208145017.2938015-1-jmaloy@redhat.com>

On Thu, 2024-02-08 at 09:50 -0500, Jon Maloy wrote:
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index fce5668a6a3d..ad03e0cee3c1 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -863,6 +863,14 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
>  }
>  EXPORT_SYMBOL(tcp_splice_read);
>  
> +int tcp_set_peek_offset(struct sock *sk, int val)
> +{
> +	WRITE_ONCE(sk->sk_peek_off, val);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(tcp_set_peek_offset);

this looks equal to sk_set_peek_off. why not reusing the latter?

[...]
> @@ -2317,6 +2323,7 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len,
>  	long timeo;
>  	struct sk_buff *skb, *last;
>  	u32 urg_hole = 0;
> +	u32 peek_offset = 0;

Very minor nit: the variable definition should follow the reverse xmas
tree order. Here such order is already broken, but I still place this
definition just before 'urg_hole'.

>  	err = -ENOTCONN;
>  	if (sk->sk_state == TCP_LISTEN)
> @@ -2774,6 +2785,7 @@ void __tcp_close(struct sock *sk, long timeout)
>  		data_was_unread += len;
>  		__kfree_skb(skb);
>  	}
> +	sk_set_peek_off(sk, -1);

Why are you resetting the peek offset at close time? nobody can read or
poll the socket at this point.

You should instead reset it at tcp_disconnect() time.

>  	/* If socket has been already reset (e.g. in tcp_reset()) - kill it. */
>  	if (sk->sk_state == TCP_CLOSE)
> @@ -4492,7 +4504,7 @@ void tcp_done(struct sock *sk)
>  		reqsk_fastopen_remove(sk, req, false);
>  
>  	WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
> -
> +	sk_set_peek_off(sk, -1);

Similar question here. tcp_done is called e.g. after an incoming
reset() and the socket is still readable after an incoming reset, if
there is pending data in the receive buffer.

Resetting the peek offset could produce unexpected results for the
reader.

Cheers,

Paolo


      parent reply	other threads:[~2024-02-08 16:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08 14:50 [PATCH v2] tcp: add support for SO_PEEK_OFF Jon Maloy
2024-02-08 14:52 ` Jon Maloy
2024-02-08 15:48 ` Stefano Brivio
2024-02-08 16:05 ` Paolo Abeni [this message]

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=c6edb4fa61e80a30f27b5b86da6453ba168bbe7f.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=dgibson@redhat.com \
    --cc=jmaloy@redhat.com \
    --cc=lvivier@redhat.com \
    --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).