From patchwork Thu Nov 25 06:19:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lu X-Patchwork-Id: 12638451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04C1BC433F5 for ; Thu, 25 Nov 2021 06:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347303AbhKYG0Z (ORCPT ); Thu, 25 Nov 2021 01:26:25 -0500 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:56884 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347307AbhKYGYZ (ORCPT ); Thu, 25 Nov 2021 01:24:25 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=tonylu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UyDiBcg_1637821271; Received: from localhost(mailfrom:tonylu@linux.alibaba.com fp:SMTPD_---0UyDiBcg_1637821271) by smtp.aliyun-inc.com(127.0.0.1); Thu, 25 Nov 2021 14:21:12 +0800 From: Tony Lu To: kgraul@linux.ibm.com Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH net 1/2] net/smc: Keep smc_close_final rc during active close Date: Thu, 25 Nov 2021 14:19:33 +0800 Message-Id: <20211125061932.74874-2-tonylu@linux.alibaba.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211125061932.74874-1-tonylu@linux.alibaba.com> References: <20211125061932.74874-1-tonylu@linux.alibaba.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org When smc_close_final() returns error, the return code overwrites by kernel_sock_shutdown() in smc_close_active(). The return code of smc_close_final() is more important than kernel_sock_shutdown(), and it will pass to userspace directly. Fix it by keeping both return codes, if smc_close_final() raises an error, return it or kernel_sock_shutdown()'s. 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") Suggested-by: Karsten Graul Signed-off-by: Tony Lu Reviewed-by: Wen Gu Acked-by: Karsten Graul --- net/smc/smc_close.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c index 3715d2f5ad55..292e4d904ab6 100644 --- a/net/smc/smc_close.c +++ b/net/smc/smc_close.c @@ -195,6 +195,7 @@ int smc_close_active(struct smc_sock *smc) int old_state; long timeout; int rc = 0; + int rc1 = 0; timeout = current->flags & PF_EXITING ? 0 : sock_flag(sk, SOCK_LINGER) ? @@ -232,8 +233,11 @@ int smc_close_active(struct smc_sock *smc) /* actively shutdown clcsock before peer close it, * prevent peer from entering TIME_WAIT state. */ - if (smc->clcsock && smc->clcsock->sk) - rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR); + if (smc->clcsock && smc->clcsock->sk) { + rc1 = kernel_sock_shutdown(smc->clcsock, + SHUT_RDWR); + rc = rc ? rc : rc1; + } } else { /* peer event has changed the state */ goto again; From patchwork Thu Nov 25 06:19:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lu X-Patchwork-Id: 12638471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1349C433F5 for ; Thu, 25 Nov 2021 06:24:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348844AbhKYG1b (ORCPT ); Thu, 25 Nov 2021 01:27:31 -0500 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:52526 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347376AbhKYGZb (ORCPT ); Thu, 25 Nov 2021 01:25:31 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R761e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=tonylu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UyDiZwl_1637821337; Received: from localhost(mailfrom:tonylu@linux.alibaba.com fp:SMTPD_---0UyDiZwl_1637821337) by smtp.aliyun-inc.com(127.0.0.1); Thu, 25 Nov 2021 14:22:17 +0800 From: Tony Lu To: kgraul@linux.ibm.com Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH net 2/2] net/smc: Don't call clcsock shutdown twice when smc shutdown Date: Thu, 25 Nov 2021 14:19:35 +0800 Message-Id: <20211125061932.74874-3-tonylu@linux.alibaba.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211125061932.74874-1-tonylu@linux.alibaba.com> References: <20211125061932.74874-1-tonylu@linux.alibaba.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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 Reviewed-by: Wen Gu --- net/smc/af_smc.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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;