* [PATCH net v2] net/smc: Don't call clcsock shutdown twice when smc shutdown
@ 2021-11-25 13:24 Tony Lu
2021-11-25 14:51 ` Karsten Graul
0 siblings, 1 reply; 3+ messages in thread
From: Tony Lu @ 2021-11-25 13:24 UTC (permalink / raw)
To: kgraul; +Cc: kuba, davem, netdev, linux-s390, linux-rdma
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>
---
changes:
v1->v2:
- code format
- use bool do_shutdown
---
net/smc/af_smc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 4b62c925a13e..9fd350fa22ba 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -2370,8 +2370,10 @@ static __poll_t smc_poll(struct file *file, struct socket *sock,
static int smc_shutdown(struct socket *sock, int how)
{
struct sock *sk = sock->sk;
+ bool do_shutdown = true;
struct smc_sock *smc;
int rc = -EINVAL;
+ int old_state;
int rc1 = 0;
smc = smc_sk(sk);
@@ -2398,7 +2400,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)
+ do_shutdown = false;
+
break;
case SHUT_WR:
rc = smc_close_shutdown_write(smc);
@@ -2408,7 +2415,7 @@ static int smc_shutdown(struct socket *sock, int how)
/* nothing more to do because peer is not involved */
break;
}
- if (smc->clcsock)
+ if (do_shutdown && smc->clcsock)
rc1 = kernel_sock_shutdown(smc->clcsock, how);
/* map sock_shutdown_cmd constants to sk_shutdown value range */
sk->sk_shutdown |= how + 1;
--
2.32.0.3.g01195cf9f
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net/smc: Don't call clcsock shutdown twice when smc shutdown
2021-11-25 13:24 [PATCH net v2] net/smc: Don't call clcsock shutdown twice when smc shutdown Tony Lu
@ 2021-11-25 14:51 ` Karsten Graul
2021-11-26 2:36 ` Tony Lu
0 siblings, 1 reply; 3+ messages in thread
From: Karsten Graul @ 2021-11-25 14:51 UTC (permalink / raw)
To: Tony Lu; +Cc: kuba, davem, netdev, linux-s390, linux-rdma
On 25/11/2021 14:24, Tony Lu wrote:
> @@ -2398,7 +2400,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)
> + do_shutdown = false;
> +
> break;
Please send a v3 without the extra empty line before the break statement,
and then the patch is fine with me.
Thank you!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net/smc: Don't call clcsock shutdown twice when smc shutdown
2021-11-25 14:51 ` Karsten Graul
@ 2021-11-26 2:36 ` Tony Lu
0 siblings, 0 replies; 3+ messages in thread
From: Tony Lu @ 2021-11-26 2:36 UTC (permalink / raw)
To: Karsten Graul; +Cc: kuba, davem, netdev, linux-s390, linux-rdma
On Thu, Nov 25, 2021 at 03:51:06PM +0100, Karsten Graul wrote:
> On 25/11/2021 14:24, Tony Lu wrote:
> > @@ -2398,7 +2400,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)
> > + do_shutdown = false;
> > +
> > break;
>
> Please send a v3 without the extra empty line before the break statement,
> and then the patch is fine with me.
>
> Thank you!
I will fix it, and send it out soon.
Thanks,
Tony Lu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-26 2:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 13:24 [PATCH net v2] net/smc: Don't call clcsock shutdown twice when smc shutdown Tony Lu
2021-11-25 14:51 ` Karsten Graul
2021-11-26 2:36 ` Tony Lu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.