public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Tony Lu <tonylu@linux.alibaba.com>
To: Gerd Bayer <gbayer@linux.ibm.com>
Cc: Wenjia Zhang <wenjia@linux.ibm.com>,
	Jan Karcher <jaka@linux.ibm.com>, Paolo Abeni <pabeni@redhat.com>,
	Karsten Graul <kgraul@linux.ibm.com>,
	"D . Wythe" <alibuda@linux.alibaba.com>,
	Wen Gu <guwen@linux.alibaba.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	linux-s390@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 2/2] net/smc: Use correct buffer sizes when switching between TCP and SMC
Date: Wed, 2 Aug 2023 20:43:56 +0800	[thread overview]
Message-ID: <ZMpPjAaRzSRy-Vo_@TONYMAC-ALIBABA.local> (raw)
In-Reply-To: <20230802093313.1501605-3-gbayer@linux.ibm.com>

On Wed, Aug 02, 2023 at 11:33:13AM +0200, Gerd Bayer wrote:
> Tuning of the effective buffer size through setsockopts was working for
> SMC traffic only but not for TCP fall-back connections even before
> commit 0227f058aa29 ("net/smc: Unbind r/w buffer size from clcsock and
> make them tunable"). That change made it apparent that TCP fall-back
> connections would use net.smc.[rw]mem as buffer size instead of
> net.ipv4_tcp_[rw]mem.
> 
> Amend the code that copies attributes between the (TCP) clcsock and the
> SMC socket and adjust buffer sizes appropriately:
> - Copy over sk_userlocks so that both sockets agree on whether tuning
>   via setsockopt is active.
> - When falling back to TCP use sk_sndbuf or sk_rcvbuf as specified with
>   setsockopt. Otherwise, use the sysctl value for TCP/IPv4.
> - Likewise, use either values from setsockopt or from sysctl for SMC
>   (duplicated) on successful SMC connect.
> 
> In smc_tcp_listen_work() drop the explicit copy of buffer sizes as that
> is taken care of by the attribute copy.
> 
> Fixes: 0227f058aa29 ("net/smc: Unbind r/w buffer size from clcsock and make them tunable")
> Signed-off-by: Gerd Bayer <gbayer@linux.ibm.com>
> Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
> Reviewed-by: Jan Karcher <jaka@linux.ibm.com>

Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>

> 
^^^^ nit: a extra new line here.
> ---
>  net/smc/af_smc.c | 76 ++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 54 insertions(+), 22 deletions(-)
> 
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index 1fcf1e42474a..1c8ed19041d7 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -436,13 +436,63 @@ static int smc_bind(struct socket *sock, struct sockaddr *uaddr,
>  	return rc;
>  }
>  
> +/* copy only relevant settings and flags of SOL_SOCKET level from smc to
> + * clc socket (since smc is not called for these options from net/core)
> + */
> +
> +#define SK_FLAGS_SMC_TO_CLC ((1UL << SOCK_URGINLINE) | \
> +			     (1UL << SOCK_KEEPOPEN) | \
> +			     (1UL << SOCK_LINGER) | \
> +			     (1UL << SOCK_BROADCAST) | \
> +			     (1UL << SOCK_TIMESTAMP) | \
> +			     (1UL << SOCK_DBG) | \
> +			     (1UL << SOCK_RCVTSTAMP) | \
> +			     (1UL << SOCK_RCVTSTAMPNS) | \
> +			     (1UL << SOCK_LOCALROUTE) | \
> +			     (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE) | \
> +			     (1UL << SOCK_RXQ_OVFL) | \
> +			     (1UL << SOCK_WIFI_STATUS) | \
> +			     (1UL << SOCK_NOFCS) | \
> +			     (1UL << SOCK_FILTER_LOCKED) | \
> +			     (1UL << SOCK_TSTAMP_NEW))
> +
> +/* if set, use value set by setsockopt() - else use IPv4 or SMC sysctl value */
> +static void smc_adjust_sock_bufsizes(struct sock *nsk, struct sock *osk,
> +				     unsigned long mask)
> +{
> +	struct net *nnet;
> +
> +	nnet = nsk->sk_net.net;

Better to combine these two lines with existed helper.

struct net *net = sock_net(nsk);

> +
> +	nsk->sk_userlocks = osk->sk_userlocks;
> +
> +	if (osk->sk_userlocks & SOCK_SNDBUF_LOCK) {
> +		nsk->sk_sndbuf = osk->sk_sndbuf;
> +	} else {
> +		if (mask == SK_FLAGS_SMC_TO_CLC)
> +			WRITE_ONCE(nsk->sk_sndbuf,
> +				   READ_ONCE(nnet->ipv4.sysctl_tcp_wmem[1]));
> +		else
> +			WRITE_ONCE(nsk->sk_sndbuf,
> +				   2 * READ_ONCE(nnet->smc.sysctl_wmem));
> +	}
> +	if (osk->sk_userlocks & SOCK_RCVBUF_LOCK) {
> +		nsk->sk_rcvbuf = osk->sk_rcvbuf;
> +	} else {
> +		if (mask == SK_FLAGS_SMC_TO_CLC)
> +			WRITE_ONCE(nsk->sk_rcvbuf,
> +				   READ_ONCE(nnet->ipv4.sysctl_tcp_rmem[1]));
> +		else
> +			WRITE_ONCE(nsk->sk_rcvbuf,
> +				   2 * READ_ONCE(nnet->smc.sysctl_rmem));
> +	}
> +}
> +
>  static void smc_copy_sock_settings(struct sock *nsk, struct sock *osk,
>  				   unsigned long mask)
>  {
>  	/* options we don't get control via setsockopt for */
>  	nsk->sk_type = osk->sk_type;
> -	nsk->sk_sndbuf = osk->sk_sndbuf;
> -	nsk->sk_rcvbuf = osk->sk_rcvbuf;
>  	nsk->sk_sndtimeo = osk->sk_sndtimeo;
>  	nsk->sk_rcvtimeo = osk->sk_rcvtimeo;
>  	nsk->sk_mark = osk->sk_mark;
> @@ -453,26 +503,10 @@ static void smc_copy_sock_settings(struct sock *nsk, struct sock *osk,
>  
>  	nsk->sk_flags &= ~mask;
>  	nsk->sk_flags |= osk->sk_flags & mask;
> +
> +	smc_adjust_sock_bufsizes(nsk, osk, mask);
>  }
>  
> -#define SK_FLAGS_SMC_TO_CLC ((1UL << SOCK_URGINLINE) | \
> -			     (1UL << SOCK_KEEPOPEN) | \
> -			     (1UL << SOCK_LINGER) | \
> -			     (1UL << SOCK_BROADCAST) | \
> -			     (1UL << SOCK_TIMESTAMP) | \
> -			     (1UL << SOCK_DBG) | \
> -			     (1UL << SOCK_RCVTSTAMP) | \
> -			     (1UL << SOCK_RCVTSTAMPNS) | \
> -			     (1UL << SOCK_LOCALROUTE) | \
> -			     (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE) | \
> -			     (1UL << SOCK_RXQ_OVFL) | \
> -			     (1UL << SOCK_WIFI_STATUS) | \
> -			     (1UL << SOCK_NOFCS) | \
> -			     (1UL << SOCK_FILTER_LOCKED) | \
> -			     (1UL << SOCK_TSTAMP_NEW))
> -/* copy only relevant settings and flags of SOL_SOCKET level from smc to
> - * clc socket (since smc is not called for these options from net/core)
> - */
>  static void smc_copy_sock_settings_to_clc(struct smc_sock *smc)
>  {
>  	smc_copy_sock_settings(smc->clcsock->sk, &smc->sk, SK_FLAGS_SMC_TO_CLC);
> @@ -2479,8 +2513,6 @@ static void smc_tcp_listen_work(struct work_struct *work)
>  		sock_hold(lsk); /* sock_put in smc_listen_work */
>  		INIT_WORK(&new_smc->smc_listen_work, smc_listen_work);
>  		smc_copy_sock_settings_to_smc(new_smc);
> -		new_smc->sk.sk_sndbuf = lsmc->sk.sk_sndbuf;
> -		new_smc->sk.sk_rcvbuf = lsmc->sk.sk_rcvbuf;
>  		sock_hold(&new_smc->sk); /* sock_put in passive closing */
>  		if (!queue_work(smc_hs_wq, &new_smc->smc_listen_work))
>  			sock_put(&new_smc->sk);
> -- 
> 2.41.0

  reply	other threads:[~2023-08-02 12:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02  9:33 [PATCH net 0/2] net/smc: Fix effective buffer size Gerd Bayer
2023-08-02  9:33 ` [PATCH net 1/2] net/smc: Fix setsockopt and sysctl to specify same buffer size again Gerd Bayer
2023-08-02 12:33   ` Tony Lu
2023-08-02  9:33 ` [PATCH net 2/2] net/smc: Use correct buffer sizes when switching between TCP and SMC Gerd Bayer
2023-08-02 12:43   ` Tony Lu [this message]
2023-08-02 16:47     ` Gerd Bayer
2023-08-02 23:17   ` kernel test robot

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=ZMpPjAaRzSRy-Vo_@TONYMAC-ALIBABA.local \
    --to=tonylu@linux.alibaba.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gbayer@linux.ibm.com \
    --cc=guwen@linux.alibaba.com \
    --cc=jaka@linux.ibm.com \
    --cc=kgraul@linux.ibm.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=wenjia@linux.ibm.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox