Skip to contentSkip to conversation

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

PATCH Superseded Tony Lu 2 participants 3 messages Nov 25, 2021 – Nov 26, 2021

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tony Lu

author reviewer
#0 lore raw

PATCH v2 1/1 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().

Fixes 606a63c9783a ("net/smc: Ensure the active closing peer first closes clcsock")

---

changes:

v1->v2:
- code format
- use bool do_shutdown

---
 net/smc/af_smc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/smc/af_smc.c +8 -1
index 4b62c925a13e..9fd350fa22ba 100644
@@ -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;
Signature · 1 line
2.32.0.3.g01195cf9f
#1 lore raw

net/smc/af_smc.c static int smc_shutdown(struct socket *sock, int how) · line 2409

Quoted 11 lines · Tony Lu
net/smc/af_smc.c +5 -0
@@ -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!

author reviewer
#2 lore raw
Quoted 16 lines · Karsten Graul

net/smc/af_smc.c static int smc_shutdown(struct socket *sock, int how) · line 2409

Quoted 11 lines · Tony Lu
net/smc/af_smc.c +5 -0
@@ -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.

Quoted 1 line

Thank you!

I will fix it, and send it out soon.

Thanks,
Tony Lu