Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5468993pxb; Mon, 28 Mar 2022 12:55:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPbXQb19dQT9QZ0OBMRpMqB4tN1JbML2aucSLVKwEv1LO3rXrmLrjC2LLJu3bzHdSwcS1D X-Received: by 2002:ac8:4417:0:b0:2e1:b5bb:3474 with SMTP id j23-20020ac84417000000b002e1b5bb3474mr23400394qtn.18.1648497308212; Mon, 28 Mar 2022 12:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648497308; cv=none; d=google.com; s=arc-20160816; b=TiR1efwFZaLufcZzH5RnCE2Ue9mrRlAAhGNMEDi7QU02isPT9iw7oXLynbFzeBKXYs BMD4BYfUESQBUsGh9yAqIIndzh+7a0joek8KOyj/QNoh0RaB47H09pr0gH1fog9/z1BG frQH7dgI10tHn7mcZCO2Is3lTNy1nhy24acmd8UjHQgkbl7oR9DrEx5Kb3xX4HGq/mce wNVVuM+/f4BSNuOiE0Knom2RpWlZrBXUyFwbYANmCQ542C87r95NHIBII+wAvp8rfqDl ln3OMUPHVC+KNOQT9y29yCNGM+onfG1gpSp33jz9pnssMJMLFY8l9S+7elPLnYm7dcYT 5H6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=UKgXcl9lPkUabTYIj/GAfQVrBrAVziXzD56eTJwrL/c=; b=csqrjHxPk4xgZ1emqlLWaKNKvN7EDgxtBQ99/O9vWMrUJ3kSI23JP46gdFZqaemcQL eq8AH2WZ+asSGwgUIe78ppB/xp/DPMpl6aylIp3WxUR+UCrrmMeDd6zK6izlxMnMnchy rYFdGgb8GYJalzvM+rywgwTqGd/fTXHGwWSMbVVTC9joBx2DYPKT6T0/QLwDNEcIe3k5 ELBkvDIHNWq2UO1O71Eq4cMLH6s8AbCe9fy8nWiEYFwWf7Jxma48/YizCaGpcPsZSR3V 0zJFKwceeRjTdBP+m5qfImCtmbuC6eyafbrKTAVeM277IBFo8R/oFajH96w7bOfWFKX8 HDtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o11-20020ad4494b000000b00440e46a7bfasi8137543qvy.152.2022.03.28.12.54.38; Mon, 28 Mar 2022 12:55:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238313AbiC1GMk (ORCPT + 99 others); Mon, 28 Mar 2022 02:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238303AbiC1GMf (ORCPT ); Mon, 28 Mar 2022 02:12:35 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87D0C515BC; Sun, 27 Mar 2022 23:10:52 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0V8LmJtm_1648447836; Received: from e02h04404.eu6sqa(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0V8LmJtm_1648447836) by smtp.aliyun-inc.com(127.0.0.1); Mon, 28 Mar 2022 14:10:50 +0800 From: Wen Gu To: kgraul@linux.ibm.com, davem@davemloft.net, kuba@kernel.org, dust.li@linux.alibaba.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net] net/smc: Send out the remaining data in sndbuf before close Date: Mon, 28 Mar 2022 14:10:36 +0800 Message-Id: <1648447836-111521-1-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current autocork algorithms will delay the data transmission in BH context to smc_release_cb() when sock_lock is hold by user. So there is a possibility that when connection is being actively closed (sock_lock is hold by user now), some corked data still remains in sndbuf, waiting to be sent by smc_release_cb(). This will cause: - smc_close_stream_wait(), which is called under the sock_lock, has a high probability of timeout because data transmission is delayed until sock_lock is released. - Unexpected data sends may happen after connction closed and use the rtoken which has been deleted by remote peer through LLC_DELETE_RKEY messages. So this patch will try to send out the remaining corked data in sndbuf before active close process, to ensure data integrity and avoid unexpected data transmission after close. Reported-by: Guangguan Wang Fixes: 6b88af839d20 ("net/smc: don't send in the BH context if sock_owned_by_user") Signed-off-by: Wen Gu --- net/smc/smc_close.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c index 292e4d9..676cb23 100644 --- a/net/smc/smc_close.c +++ b/net/smc/smc_close.c @@ -57,6 +57,9 @@ static void smc_close_stream_wait(struct smc_sock *smc, long timeout) if (!smc_tx_prepared_sends(&smc->conn)) return; + /* Send out corked data remaining in sndbuf */ + smc_tx_pending(&smc->conn); + smc->wait_close_tx_prepared = 1; add_wait_queue(sk_sleep(sk), &wait); while (!signal_pending(current) && timeout) { -- 1.8.3.1