Commit bacb6c1e authored by Tony Lu's avatar Tony Lu Committed by Jakub Kicinski

net/smc: Don't call clcsock shutdown twice when smc shutdown

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: 606a63c9 ("net/smc: Ensure the active closing peer first closes clcsock")
Signed-off-by: default avatarTony Lu <tonylu@linux.alibaba.com>
Reviewed-by: default avatarWen Gu <guwen@linux.alibaba.com>
Acked-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
Link: https://lore.kernel.org/r/20211126024134.45693-1-tonylu@linux.alibaba.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 01d9cc2d
...@@ -2370,8 +2370,10 @@ static __poll_t smc_poll(struct file *file, struct socket *sock, ...@@ -2370,8 +2370,10 @@ static __poll_t smc_poll(struct file *file, struct socket *sock,
static int smc_shutdown(struct socket *sock, int how) static int smc_shutdown(struct socket *sock, int how)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
bool do_shutdown = true;
struct smc_sock *smc; struct smc_sock *smc;
int rc = -EINVAL; int rc = -EINVAL;
int old_state;
int rc1 = 0; int rc1 = 0;
smc = smc_sk(sk); smc = smc_sk(sk);
...@@ -2398,7 +2400,11 @@ static int smc_shutdown(struct socket *sock, int how) ...@@ -2398,7 +2400,11 @@ static int smc_shutdown(struct socket *sock, int how)
} }
switch (how) { switch (how) {
case SHUT_RDWR: /* shutdown in both directions */ case SHUT_RDWR: /* shutdown in both directions */
old_state = sk->sk_state;
rc = smc_close_active(smc); rc = smc_close_active(smc);
if (old_state == SMC_ACTIVE &&
sk->sk_state == SMC_PEERCLOSEWAIT1)
do_shutdown = false;
break; break;
case SHUT_WR: case SHUT_WR:
rc = smc_close_shutdown_write(smc); rc = smc_close_shutdown_write(smc);
...@@ -2408,7 +2414,7 @@ static int smc_shutdown(struct socket *sock, int how) ...@@ -2408,7 +2414,7 @@ static int smc_shutdown(struct socket *sock, int how)
/* nothing more to do because peer is not involved */ /* nothing more to do because peer is not involved */
break; break;
} }
if (smc->clcsock) if (do_shutdown && smc->clcsock)
rc1 = kernel_sock_shutdown(smc->clcsock, how); rc1 = kernel_sock_shutdown(smc->clcsock, how);
/* map sock_shutdown_cmd constants to sk_shutdown value range */ /* map sock_shutdown_cmd constants to sk_shutdown value range */
sk->sk_shutdown |= how + 1; sk->sk_shutdown |= how + 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment