diff mbox series

[net,2/2] net/smc: Don't call clcsock shutdown twice when smc shutdown

Message ID 20211125061932.74874-3-tonylu@linux.alibaba.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Fixes for clcsock shutdown behaviors | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: guwen@linux.alibaba.com; 1 maintainers not CCed: guwen@linux.alibaba.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tony Lu Nov. 25, 2021, 6:19 a.m. UTC
When applications call shutdown() with SHUT_RDWR in userspace,
smc_close_active() calls kernel_sock_shutdown(), and it is called
twice in smc_shutdown().

This fixes this by checking sk_state before do clcsock shutdown, and
avoids missing the application's call of smc_shutdown().

Link: https://lore.kernel.org/linux-s390/1f67548e-cbf6-0dce-82b5-10288a4583bd@linux.ibm.com/
Fixes: 606a63c9783a ("net/smc: Ensure the active closing peer first closes clcsock")
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Wen Gu <guwen@linux.alibaba.com>
---
 net/smc/af_smc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Karsten Graul Nov. 25, 2021, 11:02 a.m. UTC | #1
On 25/11/2021 07:19, Tony Lu wrote:
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index 4b62c925a13e..7b04cb4d15f4 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -2373,6 +2373,7 @@ static int smc_shutdown(struct socket *sock, int how)
>  	struct smc_sock *smc;
>  	int rc = -EINVAL;
>  	int rc1 = 0;
> +	int old_state;

Reverse Christmas tree formatting, please.

>  
>  	smc = smc_sk(sk);
>  
> @@ -2398,7 +2399,12 @@ static int smc_shutdown(struct socket *sock, int how)
>  	}
>  	switch (how) {
>  	case SHUT_RDWR:		/* shutdown in both directions */
> +		old_state = sk->sk_state;
>  		rc = smc_close_active(smc);
> +		if (old_state == SMC_ACTIVE &&
> +		    sk->sk_state == SMC_PEERCLOSEWAIT1)
> +			goto out_no_shutdown;
> +

I would prefer a new "bool do_shutdown" instead of a goto for this skip
of the shutdown. What do you think?

>  		break;
>  	case SHUT_WR:
>  		rc = smc_close_shutdown_write(smc);
> @@ -2410,6 +2416,8 @@ static int smc_shutdown(struct socket *sock, int how)
>  	}
>  	if (smc->clcsock)
>  		rc1 = kernel_sock_shutdown(smc->clcsock, how);
> +
> +out_no_shutdown:
>  	/* map sock_shutdown_cmd constants to sk_shutdown value range */
>  	sk->sk_shutdown |= how + 1;
>  
>
Tony Lu Nov. 25, 2021, 12:41 p.m. UTC | #2
On Thu, Nov 25, 2021 at 12:02:06PM +0100, Karsten Graul wrote:
> On 25/11/2021 07:19, Tony Lu wrote:
> > diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> > index 4b62c925a13e..7b04cb4d15f4 100644
> > --- a/net/smc/af_smc.c
> > +++ b/net/smc/af_smc.c
> > @@ -2373,6 +2373,7 @@ static int smc_shutdown(struct socket *sock, int how)
> >  	struct smc_sock *smc;
> >  	int rc = -EINVAL;
> >  	int rc1 = 0;
> > +	int old_state;
> 
> Reverse Christmas tree formatting, please.

Sorry for that, I will fix it in the next patch.

> 
> >  
> >  	smc = smc_sk(sk);
> >  
> > @@ -2398,7 +2399,12 @@ static int smc_shutdown(struct socket *sock, int how)
> >  	}
> >  	switch (how) {
> >  	case SHUT_RDWR:		/* shutdown in both directions */
> > +		old_state = sk->sk_state;
> >  		rc = smc_close_active(smc);
> > +		if (old_state == SMC_ACTIVE &&
> > +		    sk->sk_state == SMC_PEERCLOSEWAIT1)
> > +			goto out_no_shutdown;
> > +
> 
> I would prefer a new "bool do_shutdown" instead of a goto for this skip
> of the shutdown. What do you think?

I agree with you, I'd like bool condition rather than goto, which will
disturb the continuity of reading code.

I will fix it soon. Thank you.

Tony Lu

> 
> >  		break;
> >  	case SHUT_WR:
> >  		rc = smc_close_shutdown_write(smc);
> > @@ -2410,6 +2416,8 @@ static int smc_shutdown(struct socket *sock, int how)
> >  	}
> >  	if (smc->clcsock)
> >  		rc1 = kernel_sock_shutdown(smc->clcsock, how);
> > +
> > +out_no_shutdown:
> >  	/* map sock_shutdown_cmd constants to sk_shutdown value range */
> >  	sk->sk_shutdown |= how + 1;
> >  
> > 
> 
> -- 
> Karsten
diff mbox series

Patch

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 4b62c925a13e..7b04cb4d15f4 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -2373,6 +2373,7 @@  static int smc_shutdown(struct socket *sock, int how)
 	struct smc_sock *smc;
 	int rc = -EINVAL;
 	int rc1 = 0;
+	int old_state;
 
 	smc = smc_sk(sk);
 
@@ -2398,7 +2399,12 @@  static int smc_shutdown(struct socket *sock, int how)
 	}
 	switch (how) {
 	case SHUT_RDWR:		/* shutdown in both directions */
+		old_state = sk->sk_state;
 		rc = smc_close_active(smc);
+		if (old_state == SMC_ACTIVE &&
+		    sk->sk_state == SMC_PEERCLOSEWAIT1)
+			goto out_no_shutdown;
+
 		break;
 	case SHUT_WR:
 		rc = smc_close_shutdown_write(smc);
@@ -2410,6 +2416,8 @@  static int smc_shutdown(struct socket *sock, int how)
 	}
 	if (smc->clcsock)
 		rc1 = kernel_sock_shutdown(smc->clcsock, how);
+
+out_no_shutdown:
 	/* map sock_shutdown_cmd constants to sk_shutdown value range */
 	sk->sk_shutdown |= how + 1;