From patchwork Thu Jun 29 08:58:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Winston Wen X-Patchwork-Id: 13296797 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 697B5EB64DC for ; Thu, 29 Jun 2023 08:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbjF2I7m (ORCPT ); Thu, 29 Jun 2023 04:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjF2I7k (ORCPT ); Thu, 29 Jun 2023 04:59:40 -0400 Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79BCCE4B for ; Thu, 29 Jun 2023 01:59:38 -0700 (PDT) X-QQ-mid: bizesmtp71t1688029170t5li198q Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 16:59:29 +0800 (CST) X-QQ-SSF: 01400000000000F0H000000A0000000 X-QQ-FEAT: zT6n3Y95oi1aCGkfXogeSa7YQtC2lUYv1KYRnqbdWTTG6yl+PB/9g2NexvJBB A6dEwSWHOEZolVS+rqLhwCZeN+kaTInUnlCWTivYT5nlKIv7Pl/eyfo7goCPPC9lj6HBzxo okBGgzrPkjivzfwJuJamFYCxuBQkDMtuNLMQwzZeyFQG7cnGYaA8xNhcFycekjzJbRLUow6 eKaId0oH/3WF3Pji+TjRhgG/yZqciknBc3G29Yy9NyRWy2t5k8Gyv3eWNFvlXRTFG0U7V+l jLZI1C/5xEmbDKskOyoNQ1OZWZtOQW+5xW5DGZjqPtlLQmrVhhPbDMYA3Sn93JaM01VFAzM VjC8dktLYhOn2/DEl0Dx210+soN6+I/b83tb9/sURvUMxfXxor+jCUxk4viNKcNX5TFdMvn ClCOgLDhkNM= X-QQ-GoodBg: 1 X-BIZMAIL-ID: 8565504980206895837 From: Winston Wen To: smfrench@gmail.com, linux-cifs@vger.kernel.org, pc@manguebit.com, nspmangalore@gmail.com Cc: Winston Wen Subject: [PATCH 1/3] cifs: fix credit leaks in async callback Date: Thu, 29 Jun 2023 16:58:56 +0800 Message-Id: <20230629085858.2834937-1-wentao@uniontech.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz6a-1 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Initialize credits.value to 1, which will be passed to add_credits() if mid->mid_state is not MID_RESPONSE_RECEIVED or MID_RESPONSE_MALFORMED. Signed-off-by: Winston Wen --- fs/smb/client/smb2pdu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index e04766fe6f80..4c71979fca6d 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -3760,7 +3760,7 @@ smb2_echo_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->callback_data; struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf; - struct cifs_credits credits = { .value = 0, .instance = 0 }; + struct cifs_credits credits = { .value = 1, .instance = 0 }; if (mid->mid_state == MID_RESPONSE_RECEIVED || mid->mid_state == MID_RESPONSE_MALFORMED) { @@ -4150,7 +4150,7 @@ smb2_readv_callback(struct mid_q_entry *mid) struct TCP_Server_Info *server = rdata->server; struct smb2_hdr *shdr = (struct smb2_hdr *)rdata->iov[0].iov_base; - struct cifs_credits credits = { .value = 0, .instance = 0 }; + struct cifs_credits credits = { .value = 1, .instance = 0 }; struct smb_rqst rqst = { .rq_iov = &rdata->iov[1], .rq_nvec = 1 }; if (rdata->got_bytes) { @@ -4402,7 +4402,7 @@ smb2_writev_callback(struct mid_q_entry *mid) struct TCP_Server_Info *server = wdata->server; unsigned int written; struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; - struct cifs_credits credits = { .value = 0, .instance = 0 }; + struct cifs_credits credits = { .value = 1, .instance = 0 }; WARN_ONCE(wdata->server != mid->server, "wdata server %p != mid server %p", From patchwork Thu Jun 29 08:58:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Winston Wen X-Patchwork-Id: 13296799 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 E76F1EB64DD for ; Thu, 29 Jun 2023 09:00:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232097AbjF2JAN (ORCPT ); Thu, 29 Jun 2023 05:00:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232371AbjF2I76 (ORCPT ); Thu, 29 Jun 2023 04:59:58 -0400 Received: from smtpbg154.qq.com (smtpbg154.qq.com [15.184.224.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3462E4B for ; Thu, 29 Jun 2023 01:59:55 -0700 (PDT) X-QQ-mid: bizesmtp71t1688029182te8nlnxs Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 16:59:34 +0800 (CST) X-QQ-SSF: 01400000000000F0H000000A0000000 X-QQ-FEAT: WP/PdQRFMYs8L0/4aWn/8mGsurvVJEdL43dlS+uxRokZl8yhk+mPOSYWKwWiz zjUTBQVHnv9by/aiMjahHNy8s2CWzQjraiEkNCVnodAeYTQLjr8xP1lRZPC1VVipyWYcPKC LdrCkGxG3bsVFUtTX9GNu+FpKyXpFQF6AQpmzhQj3Jvka7WcNYxb+ckUgPyZ6QfMoOVAsaW wHqFehqJWwZCMf9GONoPw/Qe15SEidmX1LPdxcnrkGSQei4ns/9OI6Pcox+mdyK7Id2yHpH KLkg0cvmaBl5uDyo934qEwtvnv/te7TWHoDPcsd/kBNVUNsCcrU8fpW4BuC9JwcG2XQDxom OpyWMdWRRq+1I7mIFHLQogB0snNtXwSDSR6CmpwAYl5Dbp/BuSrYPdfHEzf5jnLF11ICKgM z/6HXtL5pwrBegj7dM61dC1OzhHY7maD X-QQ-GoodBg: 1 X-BIZMAIL-ID: 6905205907467928356 From: Winston Wen To: smfrench@gmail.com, linux-cifs@vger.kernel.org, pc@manguebit.com, nspmangalore@gmail.com Cc: Winston Wen Subject: [PATCH 2/3] cifs: stop waiting for credits if there are no more requests in flight Date: Thu, 29 Jun 2023 16:58:57 +0800 Message-Id: <20230629085858.2834937-2-wentao@uniontech.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230629085858.2834937-1-wentao@uniontech.com> References: <20230629085858.2834937-1-wentao@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz6a-1 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org A compound request will wait for credits if free credits are not enough now but there are in flight requests which might bring back some credits to meet our needs in the near future. But if the in-flight requests don't bring back enough credits, the compound request will continue to wait unnecessarily until it times out (60s now). So add a helper has_credits_or_insufficient() to check if we should stop waiting for credits in the loop to return faster. Signed-off-by: Winston Wen --- fs/smb/client/cifsglob.h | 13 +++++++++++++ fs/smb/client/transport.c | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index cb38c29b9a73..43d0a675b543 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -800,6 +800,19 @@ has_credits(struct TCP_Server_Info *server, int *credits, int num_credits) return num >= num_credits; } +static inline bool +has_credits_or_insufficient(struct TCP_Server_Info *server, int *credits, int num_credits) +{ + int scredits; + int in_flight; + + spin_lock(&server->req_lock); + scredits = *credits; + in_flight = server->in_flight; + spin_unlock(&server->req_lock); + return scredits >= num_credits || in_flight == 0; +} + static inline void add_credits(struct TCP_Server_Info *server, const struct cifs_credits *credits, const int optype) diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c index f280502a2aee..82071142d72b 100644 --- a/fs/smb/client/transport.c +++ b/fs/smb/client/transport.c @@ -534,11 +534,21 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, spin_lock(&server->req_lock); if (*credits < num_credits) { scredits = *credits; + in_flight = server->in_flight; + if (in_flight == 0) { + spin_unlock(&server->req_lock); + trace_smb3_insufficient_credits(server->CurrentMid, + server->conn_id, server->hostname, scredits, + num_credits, in_flight); + cifs_dbg(FYI, "%s: %d requests in flight, needed %d total=%d\n", + __func__, in_flight, num_credits, scredits); + return -EDEADLK; + } spin_unlock(&server->req_lock); cifs_num_waiters_inc(server); rc = wait_event_killable_timeout(server->request_q, - has_credits(server, credits, num_credits), t); + has_credits_or_insufficient(server, credits, num_credits), t); cifs_num_waiters_dec(server); if (!rc) { spin_lock(&server->req_lock); @@ -578,8 +588,8 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, cifs_num_waiters_inc(server); rc = wait_event_killable_timeout( server->request_q, - has_credits(server, credits, - MAX_COMPOUND + 1), + has_credits_or_insufficient(server, credits, + MAX_COMPOUND + 1), t); cifs_num_waiters_dec(server); if (!rc) { From patchwork Thu Jun 29 08:58:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Winston Wen X-Patchwork-Id: 13296798 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 BFF7BEB64D9 for ; Thu, 29 Jun 2023 09:00:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbjF2JAN (ORCPT ); Thu, 29 Jun 2023 05:00:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232514AbjF2JAD (ORCPT ); Thu, 29 Jun 2023 05:00:03 -0400 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2BEB10FF for ; Thu, 29 Jun 2023 02:00:00 -0700 (PDT) X-QQ-mid: bizesmtp71t1688029192tjp6xhh7 Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 16:59:46 +0800 (CST) X-QQ-SSF: 01400000000000F0H000000A0000000 X-QQ-FEAT: 7jw2iSiCazpkOTl9O4nSALZ0LxINjsbdBRmPSbN8nEf8IcgWFDt+ruMMTDloD VE3F05W8/FmabXktO2CHRy6A2FwnSLiVD63IymYwWWYBi88yUa1lx9vJasICz00JJHHIn3T E/DAibnLj4VbILzCd/gum068UGBNLFD8CwE7xey9iyx6ZDRWU1xszEfk62BCvce5vq0Q45F LZkITfRxyLKWgZhD1GnrUqCjHPcgTZQ5LP8ZsROjwzLpqbPd9ABd4XUNkIKmpLFWy+Xsso3 tXU1Hd38nwkGCO6C2I/bMI5AkMXtDagSZipaeLHPpSI7rXWOadBiKq7Ux4iIwAj6wUxatOz NB7G4W96gclXHHrmZd3gz+U8u3ppyPgk0qzFYLHi3+9ChxTTnMZEf/g7veEwaspQ9jhEwlY IW3TZELVjCXuqu+mbyJYOw== X-QQ-GoodBg: 1 X-BIZMAIL-ID: 16652897333829944861 From: Winston Wen To: smfrench@gmail.com, linux-cifs@vger.kernel.org, pc@manguebit.com, nspmangalore@gmail.com Cc: Winston Wen Subject: [PATCH 3/3] cifs: add signal check in the loop in smb2_get_dfs_refer() Date: Thu, 29 Jun 2023 16:58:58 +0800 Message-Id: <20230629085858.2834937-3-wentao@uniontech.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230629085858.2834937-1-wentao@uniontech.com> References: <20230629085858.2834937-1-wentao@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz6a-1 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org If a process has a pending fatal signal, the request will not be sent in __smb_send_rqst(), but will return -ERESTARTSYS instead. In the loop in smb2_get_dfs_refer(), -ERESTARTSYS returned from SMB_ioctl will cause an retry that still can't succeed and will do some unnecessary work, like allocating/releasing buffer, getting/adding credits. So let us add signal check in the loop to avoid unnecessary retries and return faster. Signed-off-by: Winston Wen --- fs/smb/client/smb2ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index eb1340b9125e..64f78e1b5ea7 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -2818,7 +2818,7 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses, FSCTL_DFS_GET_REFERRALS, (char *)dfs_req, dfs_req_size, CIFSMaxBufSize, (char **)&dfs_rsp, &dfs_rsp_size); - if (!is_retryable_error(rc)) + if (!is_retryable_error(rc) || fatal_signal_pending(current)) break; usleep_range(512, 2048); } while (++retry_count < 5);