From patchwork Wed Jan 23 21:10:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C7406C2 for ; Wed, 23 Jan 2019 21:10:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BAE12D7B2 for ; Wed, 23 Jan 2019 21:10:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FEE72D840; Wed, 23 Jan 2019 21:10:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18E252D7B2 for ; Wed, 23 Jan 2019 21:10:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726754AbfAWVKy (ORCPT ); Wed, 23 Jan 2019 16:10:54 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41391 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVKy (ORCPT ); Wed, 23 Jan 2019 16:10:54 -0500 Received: by mail-pg1-f194.google.com with SMTP id m1so1625612pgq.8 for ; Wed, 23 Jan 2019 13:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=H3O0voJkghLaVDRQq81wH7xi53bB+6WmVAyGNfI6oXc=; b=scczZjCBukypDc48IPPWFEIbOLVszkEbIhK5phsF/eMHENrTDlsEjdpIHg3M6pn3my dNmlVcoBDYX+2PYJTWbjbwy+Y9CxlbzYyNYgi/PeJKgNyThSZ9Uf77DmHcD13qnDh2g+ tEMBrErHsDSaL6yV05gaI1av7eZTjJKbPzwyL3M6ERRnH1SJaiELAkohrCAn2NbLuoSe 3jioSSAdtM+C+txFKFq8UNp4ew9qC986ZTJIViZwor57ISDrBPj17e9NsTZRnRitZdXT m9vg0tUfqGr2ud4XHhwQuivVnbBRbX/jhU5lrA5xGmQ3kZg91lbPyJyCI39YLkDy+/Sq vqfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=H3O0voJkghLaVDRQq81wH7xi53bB+6WmVAyGNfI6oXc=; b=psyn8t3e73c2U5U/TTYEF6+i+vjVMQM/vxM66n3WCcl4xOm35isVB+BpR8ZSf2S+ZH +KmGtQ/WBHKxzU4ZtapUrzZH95R9ONN4rPiofLD7QvMuIeKQb7ZZNEGG/Lz/Ztg3ha14 LtzGjKCt8eU7mlhajG1t7M2/mYlG5qoTGrV/Ya9pm+DWE6njlNMDZuVXaZ/A2km/+9C3 /FDAyVQwII58hxc8kbGZfGaaT59CiL8bWPIfjBOMrqw19MeLKT93NtOrs4OqDDplibaW P/HeR+MfFPK/1v+cAFx3o2ZYghYasUxfU+ngg3c58pyX8juTb/GxQSbXoLC2mn1UM1WW RNUQ== X-Gm-Message-State: AJcUukeRcm039RCTGOFXWQiCUTI6X0lcG0llzoWbqE+9NBg4avVM8WIi U8xyqlFxyEXe9rp1A7O4e67PiTE= X-Google-Smtp-Source: ALg8bN7J7HtUHSHqS1BXDfKXCDLye4zywyl4OaEY3N/xcqICaN9MJBkv3Yw89tz5e1RBzp43dWY98w== X-Received: by 2002:a63:8043:: with SMTP id j64mr3530732pgd.405.1548277853179; Wed, 23 Jan 2019 13:10:53 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.10.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:10:52 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 01/15] CIFS: Do not reconnect TCP session in add_credits() Date: Wed, 23 Jan 2019 13:10:31 -0800 Message-Id: <1548277845-6746-2-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When executing add_credits() we currently call cifs_reconnect() if the number of credits is zero and there are no requests in flight. In this case we may call cifs_reconnect() recursively twice and cause memory corruption given the following sequence of functions: mid1.callback() -> add_credits() -> cifs_reconnect() -> -> mid2.callback() -> add_credits() -> cifs_reconnect(). Fix this by avoiding to call cifs_reconnect() in add_credits() and checking for zero credits in the demultiplex thread. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/connect.c | 21 +++++++++++++++++++++ fs/cifs/smb2ops.c | 29 ++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 3d5e308..dc02b6d 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -699,6 +699,21 @@ server_unresponsive(struct TCP_Server_Info *server) return false; } +static inline bool +zero_credits(struct TCP_Server_Info *server) +{ + int val; + + spin_lock(&server->req_lock); + val = server->credits + server->echo_credits + server->oplock_credits; + if (server->in_flight == 0 && val == 0) { + spin_unlock(&server->req_lock); + return true; + } + spin_unlock(&server->req_lock); + return false; +} + static int cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg) { @@ -711,6 +726,12 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg) for (total_read = 0; msg_data_left(smb_msg); total_read += length) { try_to_freeze(); + /* reconnect if no credits and no requests in flight */ + if (zero_credits(server)) { + cifs_reconnect(server); + return -ECONNABORTED; + } + if (server_unresponsive(server)) return -ECONNABORTED; if (cifs_rdma_enabled(server) && server->smbd_conn) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 82967f6..3b6c95d 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -34,6 +34,7 @@ #include "cifs_ioctl.h" #include "smbdirect.h" +/* Change credits for different ops and return the total number of credits */ static int change_conf(struct TCP_Server_Info *server) { @@ -41,17 +42,15 @@ change_conf(struct TCP_Server_Info *server) server->oplock_credits = server->echo_credits = 0; switch (server->credits) { case 0: - return -1; + return 0; case 1: server->echoes = false; server->oplocks = false; - cifs_dbg(VFS, "disabling echoes and oplocks\n"); break; case 2: server->echoes = true; server->oplocks = false; server->echo_credits = 1; - cifs_dbg(FYI, "disabling oplocks\n"); break; default: server->echoes = true; @@ -64,14 +63,15 @@ change_conf(struct TCP_Server_Info *server) server->echo_credits = 1; } server->credits -= server->echo_credits + server->oplock_credits; - return 0; + return server->credits + server->echo_credits + server->oplock_credits; } static void smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, const int optype) { - int *val, rc = 0; + int *val, rc = -1; + spin_lock(&server->req_lock); val = server->ops->get_credits_field(server, optype); @@ -101,8 +101,23 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, } spin_unlock(&server->req_lock); wake_up(&server->request_q); - if (rc) - cifs_reconnect(server); + + switch (rc) { + case -1: + /* change_conf hasn't been executed */ + break; + case 0: + cifs_dbg(VFS, "Possible client or server bug - zero credits\n"); + break; + case 1: + cifs_dbg(VFS, "disabling echoes and oplocks\n"); + break; + case 2: + cifs_dbg(FYI, "disabling oplocks\n"); + break; + default: + cifs_dbg(FYI, "add %u credits total=%d\n", add, rc); + } } static void From patchwork Wed Jan 23 21:10:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D55626C2 for ; Wed, 23 Jan 2019 21:10:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5C1B2D7AB for ; Wed, 23 Jan 2019 21:10:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9DF22D8CC; Wed, 23 Jan 2019 21:10:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D0952D7B2 for ; Wed, 23 Jan 2019 21:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726763AbfAWVK4 (ORCPT ); Wed, 23 Jan 2019 16:10:56 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33653 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVK4 (ORCPT ); Wed, 23 Jan 2019 16:10:56 -0500 Received: by mail-pf1-f193.google.com with SMTP id c123so1816315pfb.0 for ; Wed, 23 Jan 2019 13:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Xf+lP4X1WRt5+a5buBSCL3YphbH+csIt93ifvupqEJo=; b=kMKJcJRaz9N1J4rz9jHa9u/uORM3QALPv6Ky7dGyPmbtWNkxvwbzWUZi/xTuvWUnox 6LMIorEKIIKkrLun87qLPR3tSCX2GIXwt89Fszs38FdVYOAGV9BLdi1uow+lZAq/oCmx N+GWyZZKZ4VRgLkUxYcL36r6QJSI2SoV6LrnfAiW3xi/TxwuzTSS7HyJni5erCrwlMKF ou46bhVySD1Z9EBu40DkHqFBNkd03ykzEMDT5F2yuDpbtZAKHv8WJhl/K1JZcRyDAc91 +/tV/JSxtxNAi2b3xDitjMnYFBpn1wYdwsiE5B0Xt8vSiSYC/x83S2UsC3rTt2CrwD2l tdpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Xf+lP4X1WRt5+a5buBSCL3YphbH+csIt93ifvupqEJo=; b=GiIx0/q9upff06xRf+j6bz4FRHxOR4XUN7j80mNXmRZze7Y/3ex7LAdx4mWUz8uoih O6o6zo7XtNDau1uvyTsqeVGTuFPfhmkeyK9XGDonW/NB2HIgB83VZksHrETGXlnhcttK 30YrVpGcgGjGNVkJ5ITbjbYHiYl6Hhg/KrTRJrHZz73wFAVUURDIJJjKk79vhHvTWCUo ZoPrqYYQT+TCc+zeSwa+RuLQ488vE9x0i62n05O30cijat/PgdGaEzGIUMDMelS4JNdA PewzPNVj2ZddDeBe7rDPyxkeWOo/iuBqMueNpDnN0lvptay0rof4Fh1FAq3JVI0JvljT qmTg== X-Gm-Message-State: AJcUukfrfV2qHjcmkq0+xheCTmmPRep5jDjNd8p//QFD5FIX4imWHmIt 73rDT6ECHu2Hbo5JTStFLgIlGm4= X-Google-Smtp-Source: ALg8bN4Y2qUagomk8o0mVROrBYITTUMX6Rtz79GzHH6JSzH4GNvo/tvgADgieX/tjVOTVB9cVLL6aQ== X-Received: by 2002:a63:451a:: with SMTP id s26mr3540749pga.150.1548277854653; Wed, 23 Jan 2019 13:10:54 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.10.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:10:53 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 02/15] CIFS: Fix credits calculations for reads with errors Date: Wed, 23 Jan 2019 13:10:32 -0800 Message-Id: <1548277845-6746-3-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently we mark MID as malformed if we get an error from server in a read response. This leads to not properly processing credits in the readv callback. Fix this by marking such a response as normal received response and process it appropriately. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/cifssmb.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 6930cdb..920c9f5 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -1540,18 +1540,26 @@ cifs_discard_remaining_data(struct TCP_Server_Info *server) } static int -cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) +__cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid, + bool malformed) { int length; - struct cifs_readdata *rdata = mid->callback_data; length = cifs_discard_remaining_data(server); - dequeue_mid(mid, rdata->result); + dequeue_mid(mid, malformed); mid->resp_buf = server->smallbuf; server->smallbuf = NULL; return length; } +static int +cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) +{ + struct cifs_readdata *rdata = mid->callback_data; + + return __cifs_readv_discard(server, mid, rdata->result); +} + int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) { @@ -1593,12 +1601,23 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) return -1; } + /* set up first two iov for signature check and to get credits */ + rdata->iov[0].iov_base = buf; + rdata->iov[0].iov_len = 4; + rdata->iov[1].iov_base = buf + 4; + rdata->iov[1].iov_len = server->total_read - 4; + cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", + rdata->iov[0].iov_base, rdata->iov[0].iov_len); + cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", + rdata->iov[1].iov_base, rdata->iov[1].iov_len); + /* Was the SMB read successful? */ rdata->result = server->ops->map_error(buf, false); if (rdata->result != 0) { cifs_dbg(FYI, "%s: server returned error %d\n", __func__, rdata->result); - return cifs_readv_discard(server, mid); + /* normal error on read response */ + return __cifs_readv_discard(server, mid, false); } /* Is there enough to get to the rest of the READ_RSP header? */ @@ -1642,14 +1661,6 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) server->total_read += length; } - /* set up first iov for signature check */ - rdata->iov[0].iov_base = buf; - rdata->iov[0].iov_len = 4; - rdata->iov[1].iov_base = buf + 4; - rdata->iov[1].iov_len = server->total_read - 4; - cifs_dbg(FYI, "0: iov_base=%p iov_len=%u\n", - rdata->iov[0].iov_base, server->total_read); - /* how much data is in the response? */ #ifdef CONFIG_CIFS_SMB_DIRECT use_rdma_mr = rdata->mr; From patchwork Wed Jan 23 21:10:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47D836C2 for ; Wed, 23 Jan 2019 21:10:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3857E2D7AB for ; Wed, 23 Jan 2019 21:10:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CEBA2D7B2; Wed, 23 Jan 2019 21:10:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF45B2D7AB for ; Wed, 23 Jan 2019 21:10:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726766AbfAWVK5 (ORCPT ); Wed, 23 Jan 2019 16:10:57 -0500 Received: from mail-pg1-f178.google.com ([209.85.215.178]:44460 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVK5 (ORCPT ); Wed, 23 Jan 2019 16:10:57 -0500 Received: by mail-pg1-f178.google.com with SMTP id t13so1616902pgr.11 for ; Wed, 23 Jan 2019 13:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=fzzqNKTWwQT2+XfhBsjdKi5VkKGeSCzOQqeJgml7JIs=; b=TNQb64G2+LgWYUqJxGUugm1ayYDuWV+9fwG2/jZC6c9mo2LqqtNGfUW2EtsdHzmsv2 n4safGLJfrTla2OXtk3H2SCnqeW8RKwOYycDSPRkuHOmX2fyacz7IXYp3O1zde+Y5A7Q LNXycaZG2Xv4o2NcZMu+RUE7QoAsdm1C3NnytThIEPqF2ZXTfN0wQaAXjzmTmCMF4zkG oiGFdhIrX/2G+O581SwiLbLHsr0jWOF5/fM/lnraI2lQ/AKRGZVHE1O7LgqaZz10wKB2 M4H2unt/O6n+OX865Zl2jGilZ8eKoX7tF9ITqO6yd/gzSKzVAvOUM2zHwJoqVhZg/TFj C8Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=fzzqNKTWwQT2+XfhBsjdKi5VkKGeSCzOQqeJgml7JIs=; b=uGwze25oUPa5z6e/zkF3sU7OVj23ysPpogdbDhLIrGJBou4pnGKxMhLAbpSJhtAWH0 3OL2dDjxwcwshFqDO9xt0SOZN7BxU5vPJ9EctbGLoR58QOODQSwK6jlcYAkuGYGLptLw S8EEGsRkqgKFfrYHsKEHQjzy8lV+462aHbDw8fTWyaJ6EFa0eab4A0mmjuhio8AweOqd 6jaBmXpaE8e/7MVX3OcWA2+Lep2s3pku0l/hLLUl9isq6o+2Deabp0d3SXZyu7s+u8sx oRbd6s8Pe8CTITPRBVzcjl9vNzAVkbmJlrJH/iiHt7/1Y9PapJJLoQz8jL+ZJru7d+T5 qLpA== X-Gm-Message-State: AJcUukcF/tSluht9lbcusyVy7RX4mb4vg5KJ07X9qrkdRSuYN6rFuQ2x L/gni+HibhxKFbkCynzBJIYj2Ww= X-Google-Smtp-Source: ALg8bN4VIOsYRM1kTiqgvl5tdEmPkgCZZsz+S2RkDLfLzQ6uAD/TxTAppopmNK26SwL2BoBmIJ5+RQ== X-Received: by 2002:a63:4d66:: with SMTP id n38mr3489250pgl.270.1548277855891; Wed, 23 Jan 2019 13:10:55 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.10.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:10:54 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 03/15] CIFS: Fix credit calculation for encrypted reads with errors Date: Wed, 23 Jan 2019 13:10:33 -0800 Message-Id: <1548277845-6746-4-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We do need to account for credits received in error responses to read requests on encrypted sessions. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2ops.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 3b6c95d..24a19f2 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3192,11 +3192,23 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, server->ops->is_status_pending(buf, server, 0)) return -1; - rdata->result = server->ops->map_error(buf, false); + /* set up first two iov to get credits */ + rdata->iov[0].iov_base = buf; + rdata->iov[0].iov_len = 4; + rdata->iov[1].iov_base = buf + 4; + rdata->iov[1].iov_len = + min_t(unsigned int, buf_len, server->vals->read_rsp_size) - 4; + cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", + rdata->iov[0].iov_base, rdata->iov[0].iov_len); + cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", + rdata->iov[1].iov_base, rdata->iov[1].iov_len); + + rdata->result = server->ops->map_error(buf, true); if (rdata->result != 0) { cifs_dbg(FYI, "%s: server returned error %d\n", __func__, rdata->result); - dequeue_mid(mid, rdata->result); + /* normal error on read response */ + dequeue_mid(mid, false); return 0; } @@ -3269,14 +3281,6 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, return 0; } - /* set up first iov for signature check */ - rdata->iov[0].iov_base = buf; - rdata->iov[0].iov_len = 4; - rdata->iov[1].iov_base = buf + 4; - rdata->iov[1].iov_len = server->vals->read_rsp_size - 4; - cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", - rdata->iov[0].iov_base, server->vals->read_rsp_size); - length = rdata->copy_into_pages(server, rdata, &iter); kfree(bvec); From patchwork Wed Jan 23 21:10:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 367AD91E for ; Wed, 23 Jan 2019 21:10:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2619B2D7AB for ; Wed, 23 Jan 2019 21:10:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A1E02D7B2; Wed, 23 Jan 2019 21:10:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB7572D7AB for ; Wed, 23 Jan 2019 21:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726774AbfAWVK6 (ORCPT ); Wed, 23 Jan 2019 16:10:58 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:47044 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVK6 (ORCPT ); Wed, 23 Jan 2019 16:10:58 -0500 Received: by mail-pl1-f193.google.com with SMTP id t13so1762051ply.13 for ; Wed, 23 Jan 2019 13:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=diovf7Ox7u4EeWwJKbU6eYkmQyBJoUhmhEOaD60tBVw=; b=lkGdsJDS2ZB/lMNyntE2DLnPZGF2ZQdTVU36G1zBS/ydR1AGR05IVfVGvXe07qgtga F94tqkPODKnt0l8YzOC3mNn1k2gK5MPIVEQqm8rS5Jb4p9UmFkATZmMKwcZIgK8woAu4 PeLbkPIzQWT1LGHJ6Kj9IUSX9+BoMBvCuUraMmrTR6LhQT2Q2tFZIkmQTqszyIMzLDqt QgxltLGp3u33u4IpX5kflkE2rvyzVTmAUSVFNql5/SsdKU3td+tip9lmbzXz35OzrmDu zNjN8iIz4HbyfA88yc4kWa2fWyS1RcYkNSqbog6n1d9DVElbtVLqspSVNSEQl9wum4dt vkiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=diovf7Ox7u4EeWwJKbU6eYkmQyBJoUhmhEOaD60tBVw=; b=oPe3FpViQ1aHHZeZPrwrkoL88gyMCmgQDATHi7R0uXzTMQoUkBBlu4j5aUBJmPTcws RBDx0e5VDjqz4dZMKX6DmJ+myEfQp+LlrCU7z0Noq6Xw5VMVcvkQDSUscmRtya180seI exz3SnanPeSVOGNRnLN7B8KQXzcYzo6nDzOALsLi0AvQC9hszOn2AWQGgFcgmCBl7lE+ Wrd+ej7bkpQbqriLDh/8Lvstn3Mp9iByK4SM0U8MN3Zfdv5dgyDmtAevdCnRcnQRlP3E wSjXOTW48fSS4gc9wC13vlMl/PqPKoC2xNjvEL8IHRgwY58GWZnkn3brox7bH0KQIj0w Ql3Q== X-Gm-Message-State: AJcUuke77vu6diRNWzPE6XeoyDhoDQUmMl61MCbzoQptz9LccfRKw5sv Rf8LKPXVonKHLxv3iamxRKKzz/A= X-Google-Smtp-Source: ALg8bN6k443M4tN2Nmuo+jLmEvCYou8E2fxrdAmuDri8nH6IE0r/fmEjFRKfNggaN8DudGvywOKKDg== X-Received: by 2002:a17:902:82c2:: with SMTP id u2mr3872231plz.110.1548277857270; Wed, 23 Jan 2019 13:10:57 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.10.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:10:56 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 04/15] CIFS: Fix credit calculations in compound mid callback Date: Wed, 23 Jan 2019 13:10:34 -0800 Message-Id: <1548277845-6746-5-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current code doesn't do proper accounting for credits in SMB1 case: it adds one credit per response only if we get a complete response while it needs to return it unconditionally. Fix this and also include malformed responses for SMB2+ into accounting for credits because such responses have Credit Granted field, thus nothing prevents to get a proper credit value from them. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2ops.c | 6 +++++- fs/cifs/transport.c | 11 +---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 24a19f2..73eb0e5 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -151,7 +151,11 @@ smb2_get_credits(struct mid_q_entry *mid) { struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf; - return le16_to_cpu(shdr->CreditRequest); + if (mid->mid_state == MID_RESPONSE_RECEIVED + || mid->mid_state == MID_RESPONSE_MALFORMED) + return le16_to_cpu(shdr->CreditRequest); + + return 0; } static int diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 202e0e8..53532bd 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -786,17 +786,8 @@ static void cifs_compound_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->server; - unsigned int optype = mid->optype; - unsigned int credits_received = 0; - if (mid->mid_state == MID_RESPONSE_RECEIVED) { - if (mid->resp_buf) - credits_received = server->ops->get_credits(mid); - else - cifs_dbg(FYI, "Bad state for cancelled MID\n"); - } - - add_credits(server, credits_received, optype); + add_credits(server, server->ops->get_credits(mid), mid->optype); } static void From patchwork Wed Jan 23 21:10:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2EA891E for ; Wed, 23 Jan 2019 21:11:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C25B82D7AB for ; Wed, 23 Jan 2019 21:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B69FB2D7B2; Wed, 23 Jan 2019 21:11:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F8402D7AB for ; Wed, 23 Jan 2019 21:11:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbfAWVLA (ORCPT ); Wed, 23 Jan 2019 16:11:00 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36822 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVK7 (ORCPT ); Wed, 23 Jan 2019 16:10:59 -0500 Received: by mail-pl1-f196.google.com with SMTP id g9so1785339plo.3 for ; Wed, 23 Jan 2019 13:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=KWS+t4qBEih1RfDvytHOz/Tx1COye69eCvLN8HOsnPY=; b=RB38AQzkOOJskl3b4S5gbIr2UmCzP5342WxGExh03Vm/lICNEgQhzO/3eFqABXJSkm BMZFFaXSqina9vXXjfjAg/1Oud+Lias9Dmm6WyHTBa87MrLJ6CypwfwHf145iR7KEQ4V o9T2yBThOxAzEvKcHPs+EjwcHmdOfyb1psfiSotYI6Asj/vNlA6aB+erCBDDhag2OToJ fcIjLhT7i7QFcMYLyizU0v9I/U0olYl5jrlcpzWa7xorObs7XWqC+/N2WkH8/AmseF6O ccb5X1aHJ9FG0MAD0v1EaHCmq49qfH0LQyVHU+DjH3CFOmweQt5tK64OI/gF/gN+L5kC uroQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=KWS+t4qBEih1RfDvytHOz/Tx1COye69eCvLN8HOsnPY=; b=narJ/4yzOAALvCXxFcUNI3zWzdMd+8P4RhL6eZvRhpKPUxmxTbL5tCwjjgXt/xacCX gL4qk6leZgaHSEZ5gAQAbt/e3QTartAbMTPmY121wJ9eNRbMzmspYmKj/zDS2Ch/1uxf RobNfHr/c9EKLbs6aXnlPOBcyut0UsF/6m3+BnoF4Hvju+m/jwsd/HqqrsKBre8td0f8 wusdCw/di8o6NhHr/GKM6+f/Kn5ugo03Y+5gSbf/k+/cDZSrW25zBEhfa3b50Ia/mZt2 ThxdJAQHfn0OdJNoMM9dnZlunA3JU45OpJBZwqoRZ4j0aRVZJdXsuVyOEqfQGIWnreqT t2DQ== X-Gm-Message-State: AJcUukcn5IRVUg40pRCJEAJEss3k2FVCc3DEUZU7xLAaigoi1l2gvCfP 6scwwvba822AnfWM2BoE+NKBNKk= X-Google-Smtp-Source: ALg8bN5K3zPP/szxhClSkgI/3hlu2K2Jkgjg16vucms5wPxA/I+pOCP2QY9fp6jG7bm1mKHlQOZ5qw== X-Received: by 2002:a17:902:8e8b:: with SMTP id bg11mr3943568plb.332.1548277858533; Wed, 23 Jan 2019 13:10:58 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.10.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:10:57 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 05/15] CIFS: Do not assume one credit for async responses Date: Wed, 23 Jan 2019 13:10:35 -0800 Message-Id: <1548277845-6746-6-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we don't receive a response we can't assume that the server granted one credit. Assume zero credits in such cases. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2pdu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index f158825..9bd7f3d 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2893,9 +2893,10 @@ 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; - unsigned int credits_received = 1; + unsigned int credits_received = 0; - if (mid->mid_state == MID_RESPONSE_RECEIVED) + if (mid->mid_state == MID_RESPONSE_RECEIVED + || mid->mid_state == MID_RESPONSE_MALFORMED) credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); DeleteMidQEntry(mid); @@ -3152,7 +3153,7 @@ smb2_readv_callback(struct mid_q_entry *mid) struct TCP_Server_Info *server = tcon->ses->server; struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)rdata->iov[0].iov_base; - unsigned int credits_received = 1; + unsigned int credits_received = 0; struct smb_rqst rqst = { .rq_iov = rdata->iov, .rq_nvec = 2, .rq_pages = rdata->pages, @@ -3191,6 +3192,9 @@ smb2_readv_callback(struct mid_q_entry *mid) task_io_account_read(rdata->got_bytes); cifs_stats_bytes_read(tcon, rdata->got_bytes); break; + case MID_RESPONSE_MALFORMED: + credits_received = le16_to_cpu(shdr->CreditRequest); + /* fall through */ default: if (rdata->result != -ENODATA) rdata->result = -EIO; @@ -3376,7 +3380,7 @@ smb2_writev_callback(struct mid_q_entry *mid) struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); unsigned int written; struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; - unsigned int credits_received = 1; + unsigned int credits_received = 0; switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: @@ -3404,6 +3408,9 @@ smb2_writev_callback(struct mid_q_entry *mid) case MID_RETRY_NEEDED: wdata->result = -EAGAIN; break; + case MID_RESPONSE_MALFORMED: + credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); + /* fall through */ default: wdata->result = -EIO; break; From patchwork Wed Jan 23 21:10:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72E236C2 for ; Wed, 23 Jan 2019 21:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62A4D2D7AB for ; Wed, 23 Jan 2019 21:11:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 567672D7B2; Wed, 23 Jan 2019 21:11:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0669A2D7AB for ; Wed, 23 Jan 2019 21:11:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726792AbfAWVLB (ORCPT ); Wed, 23 Jan 2019 16:11:01 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39603 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLB (ORCPT ); Wed, 23 Jan 2019 16:11:01 -0500 Received: by mail-pg1-f195.google.com with SMTP id w6so1629537pgl.6 for ; Wed, 23 Jan 2019 13:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=uljiIcXzFMftdJgS1nPeUniSy11Z7HlPRtcmVgLvUhc=; b=qSACM+U6FZGgugjsa36kejI4RJfN9/U7qB52ZdpkvP+zp4WKKuK0Tugl62GWK0116S 6MCgc3nn7js/y8FlJzFQFslP1ca5w0Dz7J+CfLNbhpKf1IIcOa79JW2iVe/fpoSkzGiV YHHGgt2MiRMtdDu8IwW8p7Fx+V04k0M5kUz1uWjFpGBL4VvIUeBlZNjHILUozWOWEXbV +yKfK1LaU3Qi0smZs7A8n4RxEKQdodz1EPWxECYF6VB+kkE0v46QvKh5HI4m+2sN8Akl EnPJ8/SAg47g7SsHQJz2okwj/duSsOo/hGhFxB/j01u0WnNcGdgi5ZnNXMz1OxPulNzG BUHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=uljiIcXzFMftdJgS1nPeUniSy11Z7HlPRtcmVgLvUhc=; b=kenvcbj7/Z7Ywf6aJRgcXc/C9vnV3CDF0CvhKgTuke3/Z82keu6rdCZY0fLopWD1tF qMJQ432oIJo7OzphUibZrRGxkLSwj1CvnMHvBkYHT8Ns/X0QKUec1eZ03YXOztxmH44u Y9HQVlOLhwdjbCi6PrMIeF8DYZxXYDcXoIw6VK5VP6VjRW+I6iEgDAt0x7evPdIjkISF gTqSeKMU48G1C4rmOw8kZm0reD7LH8cfiq+BrHdlSW4Cr4pnkcVktyBri50njmtQ6LQ7 RX/Da0pBVXuHe0uWfktLxRuzPnwl2PIX+s4SVT/q0gX/PyOPjJYgN5KF0kgt8ooDM9SU Qr6w== X-Gm-Message-State: AJcUukcDaWCWoWIhQxvrU+h5M/GODf4Pvatxh+dZxxLDYA6Gg/E4TgSS TaxuPlXfjyUMpbjUMiWtqPSAHGo= X-Google-Smtp-Source: ALg8bN6GNtQmd9eNoOgdnX+HZ67Bbbifsqx1MMvA+bgZ600LlwXe3g/Rrk8sxIqyZw2lOWu1Jp+GnA== X-Received: by 2002:a62:546:: with SMTP id 67mr3552304pff.99.1548277860035; Wed, 23 Jan 2019 13:11:00 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.10.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:10:58 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 06/15] CIFS: Fix mounts if the client is low on credits Date: Wed, 23 Jan 2019 13:10:36 -0800 Message-Id: <1548277845-6746-7-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the server doesn't grant us at least 3 credits during the mount we won't be able to complete it because query path info operation requires 3 credits. Use the cached file handle if possible to allow the mount to succeed. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2inode.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c index a8999f9..057d203 100644 --- a/fs/cifs/smb2inode.c +++ b/fs/cifs/smb2inode.c @@ -294,6 +294,8 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, int rc; struct smb2_file_all_info *smb2_data; __u32 create_options = 0; + struct cifs_fid fid; + bool no_cached_open = tcon->nohandlecache; *adjust_tz = false; *symlink = false; @@ -302,6 +304,21 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, GFP_KERNEL); if (smb2_data == NULL) return -ENOMEM; + + /* If it is a root and its handle is cached then use it */ + if (!strlen(full_path) && !no_cached_open) { + rc = open_shroot(xid, tcon, &fid); + if (rc) + goto out; + rc = SMB2_query_info(xid, tcon, fid.persistent_fid, + fid.volatile_fid, smb2_data); + close_shroot(&tcon->crfid); + if (rc) + goto out; + move_smb2_info_to_cifs(data, smb2_data); + goto out; + } + if (backup_cred(cifs_sb)) create_options |= CREATE_OPEN_BACKUP_INTENT; From patchwork Wed Jan 23 21:10:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 270B36C2 for ; Wed, 23 Jan 2019 21:11:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1866C2D7AB for ; Wed, 23 Jan 2019 21:11:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B52C2D7B2; Wed, 23 Jan 2019 21:11:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7D312D7AB for ; Wed, 23 Jan 2019 21:11:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726821AbfAWVLC (ORCPT ); Wed, 23 Jan 2019 16:11:02 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43077 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLC (ORCPT ); Wed, 23 Jan 2019 16:11:02 -0500 Received: by mail-pl1-f196.google.com with SMTP id gn14so1772154plb.10 for ; Wed, 23 Jan 2019 13:11:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=RsgRSpvExNJ6oPOM2yNm0dGybgJapo/l9FMQY0v/ZCw=; b=D6oNvJAegrTqzsJa86fE5fA3gz0uGf93HaFs/LEvpLAU/0p5iIqPnpI/UR2pSBiICi lvaBfQU1sbf7X1hb1sELRXTqiJXlDGh04NZvjregPDyKeFeOzc+Y81zAcr5Cmwa8yRBe +IpGKWtt8FKGuzmFJBwCfKwW+2b86mGeQ28tB9EMaaPuWRjE840KtQzBGh3dMIAEci1B YFsN+Vr3RqAR2hPF0vyemjCf9EM+gqyyao9atEhT4CvRymEiOMu68VgRD38X17dufy2N 1PvbDd46/niWZkbOa0KwP9OxmmnwUqp2ZcLatgn3Pr3QMKsE4rk5mz+DCW/sP1y0scT2 omCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RsgRSpvExNJ6oPOM2yNm0dGybgJapo/l9FMQY0v/ZCw=; b=B0tP1Xleu9nXpRGCIK1hiWUHVutSfNQlgvDlpe9FSqB0wz4CuIYGrxHtPqp/tnZKkq pr001+k2DET/IkqwhdgYCJppFU3PbktiTATLuYWCAhejAlWcGRr3p/KZFOfQaDidcDYj tP8hyIOiU7uPv4n6wwLIHtyxmckAKhDkb91ut+tS62o2QUYM1sJvDAUat4ckKAlHnjgg uVwLou/JP9mYeSsPMueLn/TE+bFNBxSwTxARmUmUAicAuRaIGATyCO06tq+tWFKp3jdr 4jiZYJ9/j7mlXdSx5kwyBZGBKsbvVqdk6+RyYDAV6IS94b9aPpEfyFTCgonXKdaZrZ6E Q4ow== X-Gm-Message-State: AJcUukeu8OA8lUF0GwpCQW4kzztBQ78DfMJ3zuIC6wRgPJp0JA1XiJI3 WhYWw+j43xeS6BaN2eaIN/TbgpI= X-Google-Smtp-Source: ALg8bN79Pqy4OKlrXSGyX3Pqqtr9kA6IaIk6pLF8/uDlW2Ga25biu2qoSAivVqwDn1N+Gm5F06gThQ== X-Received: by 2002:a17:902:2e01:: with SMTP id q1mr3751966plb.97.1548277861312; Wed, 23 Jan 2019 13:11:01 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:00 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 07/15] CIFS: Always reset read error to -EIO if no response Date: Wed, 23 Jan 2019 13:10:37 -0800 Message-Id: <1548277845-6746-8-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently we skip setting a read error to -EIO if a stored result is -ENODATA and a response hasn't been received. With the recent changes in read error processing there shouldn't be cases when -ENODATA is set without a response from the server, so reset the error to -EIO unconditionally. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2pdu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 9bd7f3d..6d2901b 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3196,8 +3196,7 @@ smb2_readv_callback(struct mid_q_entry *mid) credits_received = le16_to_cpu(shdr->CreditRequest); /* fall through */ default: - if (rdata->result != -ENODATA) - rdata->result = -EIO; + rdata->result = -EIO; } #ifdef CONFIG_CIFS_SMB_DIRECT /* From patchwork Wed Jan 23 21:10:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A6CA6C2 for ; Wed, 23 Jan 2019 21:11:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B1122D7AB for ; Wed, 23 Jan 2019 21:11:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F15A2D7B2; Wed, 23 Jan 2019 21:11:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 286852D7AB for ; Wed, 23 Jan 2019 21:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726874AbfAWVLD (ORCPT ); Wed, 23 Jan 2019 16:11:03 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:38340 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLD (ORCPT ); Wed, 23 Jan 2019 16:11:03 -0500 Received: by mail-pl1-f196.google.com with SMTP id e5so1786109plb.5 for ; Wed, 23 Jan 2019 13:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=D8NwUr/m3AZjl9UkX0yIYPyphz0soiujfLHniP3Px70=; b=j7pCHIpbDD8XG3rAR/tevp6/dTl5bpERe+KJdwBuRP8nCMl5lU4YueHHTrZbPmln8f 5zExBTRyK67+KkfGxOZzov1PlusnOuRSu5zwzmay5HY1dp21bZ70MEJ8H/wuhIQa2PJs +y9oRVN3gC7Ifd6WuI2hdLfIbqNrci8qPmnKhYU3tB+NQapNUd56KDOXIhRA/r1sO48g bSDYwuCMks/oTKSCoGa2U++McRKs6YJ+pIAQ1wbvtzZWFKlfnyJ0NM72m5lErUImeFdH lCSZFBrWgN9JoXV/BIBPN/MQ1tLcY344wu+j40abcz04td/Prv9S2G4ZJLj38rx8kQ8D fcWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=D8NwUr/m3AZjl9UkX0yIYPyphz0soiujfLHniP3Px70=; b=Smm+2fXVt8esfVmCHQmKy85LETaJ68wj8aRpm9EsE61MOX+pjBMu3VcxaAi9NMGk8x DzIMTEsfoR5RuCMF+ykAFjFQUZOpgb6sRfG8RxvfBdzc8Dk6y7oiNO0bEolh2REThkjL wY5FgBuGiWa8SkGQJn3NrKLZm8KXS1Ds+YYa0m3HBg5iR1lfrZDt1rnC/AfGnK5Sk8Hx hwtlfYxSbalDMaBrHfRSktM4lJBPSQn2BXCfFTO6XjZXtsZrmoV9yQ+R+QNE9UFmiaBI c/GorSkXDk+YSHcJYs34RS+cAs/h/CsEQD3tBKU1QnflcjKQJAbEENlT0PN37u086XzU IqiQ== X-Gm-Message-State: AJcUukdBj0mygwrU03Xuh3h9Z7EIzi/0SfSzDdQaE0kFLIu6zoCKa/72 dVW0wbZ5wq+/jOhjWjQ+BxyM9fw= X-Google-Smtp-Source: ALg8bN4tKroclLYoGs7ZdZCQGQIz+RH4e3+u9v+ZppM2JFgZykrT1hXwHh9Lg58HxrWm6gqXfKpJiA== X-Received: by 2002:a17:902:b18b:: with SMTP id s11mr3870491plr.56.1548277862630; Wed, 23 Jan 2019 13:11:02 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:01 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 08/15] CIFS: Do not consider -ENODATA as stat failure for reads Date: Wed, 23 Jan 2019 13:10:38 -0800 Message-Id: <1548277845-6746-9-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When doing reads beyound the end of the file the server returned error STATUS_END_OF_FILE error which is mapped to -ENODATA. Currently we report it as a failure which confuses read stats. Change it to not consider -ENODATA as failure for stat purposes. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 6d2901b..291f290 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3209,7 +3209,7 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->mr = NULL; } #endif - if (rdata->result) + if (rdata->result && rdata->result != -ENODATA) cifs_stats_fail_inc(tcon, SMB2_READ_HE); queue_work(cifsiod_wq, &rdata->work); From patchwork Wed Jan 23 21:10:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 332B16C2 for ; Wed, 23 Jan 2019 21:11:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22F972D7AB for ; Wed, 23 Jan 2019 21:11:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 172D72D7B2; Wed, 23 Jan 2019 21:11:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B68D72D7AB for ; Wed, 23 Jan 2019 21:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726986AbfAWVLF (ORCPT ); Wed, 23 Jan 2019 16:11:05 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40347 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLF (ORCPT ); Wed, 23 Jan 2019 16:11:05 -0500 Received: by mail-pf1-f193.google.com with SMTP id i12so1797298pfo.7 for ; Wed, 23 Jan 2019 13:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=JAfa0JuQPeYT0y1DZJoCgVYjJwRFg7nzqNfB27hPUYU=; b=n0l7VKt8TLgzsJOfZrfsCrsY3gSfu3NmsTvnhz8qkTuXrIZLGXAbQ7F3oZS+jftIi3 0N9EmLJqpxbBk+q/2ByXDGSJdmqVgJcAoB6ub4Gt8z+W8p/KU0Oaj+ywfbI8EPN51e8/ q6PGnaJZDrnP4BtWL41QIlVVSPTmPYFJvEm3TngVoaZSrTzgRQyVKrGtKvJQDK0HfTje VkwBdsyhbRb3lfrdl05fhsOVsH74MnXg3eG92JaiVKsjL3C9QHAd4yXBL4mU+k+uV/YX fW+3oE537ETpHiFIpTfBEI/Oo7TGkrXWvPGo17noCTjpWPT1CoHue6bywY+NqiESn/5a BFhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JAfa0JuQPeYT0y1DZJoCgVYjJwRFg7nzqNfB27hPUYU=; b=tpbuK/mR402T6AE4BkjSwAUyjmODTJ7Oh7aW40wZJPlj1RcHNHGzeF2R6aInH3IooW VFS4Zk6Su7HbQMe6u5Wf/fafl6tH8ncrGXUTfwkCYniivy9miWZQKBgdKoNXo/bNgC4J v3ItqslVLVUMMsxxszy4Cb4B7EGwQVCnjun3YUoSpuNbKxHus/dN0Lev5pyWme3o4xzL 7i5dXp5KPsN+HheB5RsmmXdhsULATBuRDRL+gFTLQS0e/eJmsul7N48lSJBQUzkmHL5h OilB8L34H8uTmNaOjYgSzijqFHRDU1iJQ/j9fU39hS/p9d+pxeJAjhOq8ljuzKEpSUSb LOlg== X-Gm-Message-State: AJcUukf937Exa3ieBN5k8lYq9wPSxDtJLJoXsxs2Vu8bwwmniyYWWPTS JV4MI2JwU5I/720pjDg5S3blnT8= X-Google-Smtp-Source: ALg8bN5Pyjv7BC9b1BGR3m3jqC2WPT2ApNhv4876DnWdc9AUlZ/RuaGFPChqgr3yfVh/s78ij7pLCQ== X-Received: by 2002:aa7:8542:: with SMTP id y2mr3681362pfn.83.1548277863900; Wed, 23 Jan 2019 13:11:03 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:02 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 09/15] CIFS: Respect SMB2 hdr preamble size in read responses Date: Wed, 23 Jan 2019 13:10:39 -0800 Message-Id: <1548277845-6746-10-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a couple places where we still account for 4 bytes in the beginning of SMB2 packet which is not true in the current code. Fix this to use a header preamble size where possible. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifssmb.c | 7 ++++--- fs/cifs/smb2ops.c | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 920c9f5..c8792d2 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -1603,9 +1603,10 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) /* set up first two iov for signature check and to get credits */ rdata->iov[0].iov_base = buf; - rdata->iov[0].iov_len = 4; - rdata->iov[1].iov_base = buf + 4; - rdata->iov[1].iov_len = server->total_read - 4; + rdata->iov[0].iov_len = server->vals->header_preamble_size; + rdata->iov[1].iov_base = buf + server->vals->header_preamble_size; + rdata->iov[1].iov_len = + server->total_read - server->vals->header_preamble_size; cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", rdata->iov[0].iov_base, rdata->iov[0].iov_len); cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 73eb0e5..3ee8258 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3198,10 +3198,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, /* set up first two iov to get credits */ rdata->iov[0].iov_base = buf; - rdata->iov[0].iov_len = 4; - rdata->iov[1].iov_base = buf + 4; + rdata->iov[0].iov_len = 0; + rdata->iov[1].iov_base = buf; rdata->iov[1].iov_len = - min_t(unsigned int, buf_len, server->vals->read_rsp_size) - 4; + min_t(unsigned int, buf_len, server->vals->read_rsp_size); cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", rdata->iov[0].iov_base, rdata->iov[0].iov_len); cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", From patchwork Wed Jan 23 21:10:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0C466C2 for ; Wed, 23 Jan 2019 21:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C12032D7AB for ; Wed, 23 Jan 2019 21:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B57442D7B2; Wed, 23 Jan 2019 21:11:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57E502D7AB for ; Wed, 23 Jan 2019 21:11:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbfAWVLH (ORCPT ); Wed, 23 Jan 2019 16:11:07 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37233 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLG (ORCPT ); Wed, 23 Jan 2019 16:11:06 -0500 Received: by mail-pg1-f195.google.com with SMTP id c25so1636242pgb.4 for ; Wed, 23 Jan 2019 13:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Sx9H6OIv2BWkH1Rt0bikKAfYWn3SmyLndmDST7LdEc0=; b=EGCKCEIG6tzWFTuAJw+HgQRabMmAzwS22CP8r/awcRVspLbKy/TrANnafq0QBTsMe8 7dCdxz4HvWc4DXVy+45q29RQ8SCu0AzltPsSGQYYqqnWCiViWf2VuV6+I4C156l3q0qv mz5uEAh/A+Dt5coZ+tbczyAYB3TSi33eZ7vM/oLWJAwjbFm+FCOqNlxG2bh8Flm81s58 ySBGSQtR5vKLBJYx8+kiMBIlf8PY1T2CI+A3xMmmeYeY/+IlFP3uDSvxfPzrS11/dwn4 gjjuIaHkFiqY5W3j11akw10N5eJnlpx+Hai2w2qGUXgAMV4vBTeviybZxLpxkrzFyDGA npWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Sx9H6OIv2BWkH1Rt0bikKAfYWn3SmyLndmDST7LdEc0=; b=Z6sMFjkkQmlRUFmFBmjD1i5c05l9H/SPWJAMmGW42FNwinRpk2M5/2n9GBsrqdqaJX na1F3ooh/EKPUjxrL+Q9G2+st1LUzFe5LI9p952CNNw0ICb6fpwpqx8TWzjeCv/5KK66 gicS71xjv0RqjeVb2FJN3Sn/hGxk0SfXpvWqAysccdYWixQip3X+m3BLC78qd+1aGnnu goL8L7dsUq7HIi9gfY5pjC7ZI0aZQKk2+EAODZpc25LKX3g2AovUXl8vTrhSa1weiMow qRGzrFBPtyc5glsRJ2YTjn7L6pS+URXNL3MpKQMkUE/i9tfUxxen+rhigMkJPiXoG2hp YfHA== X-Gm-Message-State: AJcUukeQi1xcfB7KO2QSWU5SZKsUXy86uhSJPAJ54XQvtIA659NpQqat Ep6kSfPQvU0e6dac7ffWalHYgh4= X-Google-Smtp-Source: ALg8bN6szVaNsTLWV18bwn59Yeo/OG704u/smv6J7vQ5MZxKR7ld7bVpLLtbAvyyTRjQENkPufiw6g== X-Received: by 2002:a62:c505:: with SMTP id j5mr3612276pfg.149.1548277865327; Wed, 23 Jan 2019 13:11:05 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:04 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 10/15] CIFS: Mask signals during sock_sendmsg() Date: Wed, 23 Jan 2019 13:10:40 -0800 Message-Id: <1548277845-6746-11-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't want to break a session if we receive a signal during sending a packet through the network. Fix it by masking signals during execution of sock_sendmsg() and then checking for pending signals. Signed-off-by: Pavel Shilovsky --- fs/cifs/transport.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 53532bd..eff9e3c 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "cifspdu.h" #include "cifsglob.h" #include "cifsproto.h" @@ -176,6 +177,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, int rc = 0; int retries = 0; struct socket *ssocket = server->ssocket; + sigset_t mask, oldmask; *sent = 0; @@ -189,6 +191,28 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, smb_msg->msg_flags = MSG_NOSIGNAL; while (msg_data_left(smb_msg)) { + if (signal_pending(current)) { + /* Should we stop sending if we receive SIG_KILL? */ + if (__fatal_signal_pending(current)) + cifs_dbg(FYI, "SIG_KILL signal is pending\n"); + + /* It is safe to return if we haven't sent anything */ + if (*sent == 0) { + cifs_dbg(FYI, "signal is pending before sending any data\n"); + return -EINTR; + } + } + + /* + * We should not allow signals to interrupt the network send + * because any partial send will cause session reconnects thus + * increasing latency of system calls and overload a server + * with unnecessary requests. + */ + + sigfillset(&mask); + sigprocmask(SIG_BLOCK, &mask, &oldmask); + /* * If blocking send, we try 3 times, since each can block * for 5 seconds. For nonblocking we have to try more @@ -208,20 +232,23 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, * reconnect which may clear the network problem. */ rc = sock_sendmsg(ssocket, smb_msg); + + sigprocmask(SIG_SETMASK, &oldmask, NULL); + if (rc == -EAGAIN) { retries++; if (retries >= 14 || (!server->noblocksnd && (retries > 2))) { cifs_dbg(VFS, "sends on sock %p stuck for 15 seconds\n", ssocket); - return -EAGAIN; + return signal_pending(current) ? -EINTR : rc; } msleep(1 << retries); continue; } if (rc < 0) - return rc; + return signal_pending(current) ? -EINTR : rc; if (rc == 0) { /* should never happen, letting socket clear before @@ -235,7 +262,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, *sent += rc; retries = 0; /* in case we get ENOSPC on the next send */ } - return 0; + return signal_pending(current) ? -EINTR : 0; } unsigned long From patchwork Wed Jan 23 21:10:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AC881515 for ; Wed, 23 Jan 2019 21:11:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69FB72D7AB for ; Wed, 23 Jan 2019 21:11:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E5842D7B2; Wed, 23 Jan 2019 21:11:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 176D02D7AB for ; Wed, 23 Jan 2019 21:11:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726992AbfAWVLH (ORCPT ); Wed, 23 Jan 2019 16:11:07 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43941 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLH (ORCPT ); Wed, 23 Jan 2019 16:11:07 -0500 Received: by mail-pf1-f194.google.com with SMTP id w73so1789402pfk.10 for ; Wed, 23 Jan 2019 13:11:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=cOHeMwAB/ZY1Ttyh/93tA4n56exxeMOFq4aw1IzvY6I=; b=IX+pOApIC1DGZdmPIQwxFg5Er823JvKt1LxjCDKFzKad0ZpXo1OPlbYZmKtECKqhyj opkP6oVFvI606qbU9iCxM9LpiGHnx+eKq1fGxUv8z/5z5EDD6AW9quzLnAn7reFov2Az JDfdUz117KAQlkcD2/csBNVcrwxx5Wpr0tW3oZZ4hMpeRihB8MK4ptM4pVTjCGyznv+I epYTscs2FM74NlgEX4TOMt78nzBYvHCzrtsEn+gg4HAjiLH8K9C6zydCi1pg7mSyVZhZ EX8iWWSLI74ZLhxddKsjUYdVcoI+E6/Wf5EhTz50rGQpRDAuH+B5ILi92tpNf0T3EiHP tTsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=cOHeMwAB/ZY1Ttyh/93tA4n56exxeMOFq4aw1IzvY6I=; b=GvJQV0MLTzaWwZO9+SEOzJQAg8xm3yPNIk1y0NJ1aU+uOJReHlmwxSvp+CnuWLGKFg 2LMTIORPuvUM8s+9ilRCxkuZI0AKKBg9mbTfV3IPgrg0srBhdMWyM6+JEMbd212Q45F5 RqdnE7BMc0FhyE8hu6NUh3mro+CCdvwDM5yLrXL/y+sSP3VyBu5AMtckF9tMvgY0wliy Gp599VoTULe2UiIViJgUBjaP3E9wUxloofCvPfkde/61KrIsPhFyUePfzhj3l2CuBvbE X8oCr0UKESkpgc8pLH4zu5YFaaOPcJiojwZoPUwAVcvd5DMs4fC0aSFtr0XdUkeSdjrH t2Cw== X-Gm-Message-State: AJcUukd+3vNnycclUFseUL0cjSacL0JDFr0Tozxwef1wbAqFgrRDETTg BWAISQ84Y8FiUZp54/+FPXTr3aA= X-Google-Smtp-Source: ALg8bN4qYEIH6FOpaMtYa+01Y63HIliNgTx3Cd5sTuDofNN9Zn7PdEXa4eDG9qbJ/qRPuMnPocHcvw== X-Received: by 2002:a65:5387:: with SMTP id x7mr3491111pgq.412.1548277866615; Wed, 23 Jan 2019 13:11:06 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:05 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 11/15] CIFS: Set reconnect instance to one initially Date: Wed, 23 Jan 2019 13:10:41 -0800 Message-Id: <1548277845-6746-12-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently we set reconnect instance to zero on the first connection but this is not convenient because we need to reserve some special value for credit handling on reconnects which is coming in subsequent patches. Fix this by starting with one when initiating a new TCP connection. Signed-off-by: Pavel Shilovsky --- fs/cifs/connect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index dc02b6d..3e7ad68 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -2588,7 +2588,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) volume_info->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); tcp_ses->session_estab = false; tcp_ses->sequence_number = 0; - tcp_ses->reconnect_instance = 0; + tcp_ses->reconnect_instance = 1; tcp_ses->lstrp = jiffies; spin_lock_init(&tcp_ses->req_lock); INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); From patchwork Wed Jan 23 21:10:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 475656C2 for ; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 364C32D7AB for ; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ABC82D8B0; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFAA02D7AB for ; Wed, 23 Jan 2019 21:11:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726993AbfAWVLK (ORCPT ); Wed, 23 Jan 2019 16:11:10 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34224 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLK (ORCPT ); Wed, 23 Jan 2019 16:11:10 -0500 Received: by mail-pf1-f193.google.com with SMTP id h3so1815417pfg.1 for ; Wed, 23 Jan 2019 13:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=2vm9LJPxh0DUwQSZm7xpZNWq7qtMucWY9Snk00lu1WI=; b=rlRG2NN/tayinGGMWYJ67ibF3PKNld/iPAxhncQBhV+t9emcSdkcYEkg/yHTlnRbTm OBZzRpPz76QSoac5xzP+Cbdm/NAFVHhpzRhGUmrgBCOgI5eUYPK8/EOF4A1JR/lE0Srr +D1jNzkiK9b/MEOM0P/cpS0sj69ybms71BvcHWBN4yHP14KqbYB04Fq/zF+JzgOFIw2S JcFjqLyq8a+Yme1t7TLdie5aI/Bzb+xDC8KkCzWH8OaE7J75YqP9QHNhFW3LGxBFtqsU D6yQFfQTL0Yyj9fM6n+6SjZctozPPYKSn+XTS5hfISYjuypWFtqjcLzDbwFyzG0q5DOT AHyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2vm9LJPxh0DUwQSZm7xpZNWq7qtMucWY9Snk00lu1WI=; b=k6U71FuUbaFabG/y/1JXllVXZ2whMlfKhy0jxpAQrEc69cm6FLuQM08OGLP1/mDyO3 xWFosPqO+6JZPIJotwD5+WeKwIhqbhBbAKQm88VM+jp1VzXnyowpjqOEwekj6FfEHCb/ 7A+DrJjdpPr+8CMCbxTkdAx01Wob7wGq5W55nDoFDjITXo0XeLJwIwCmo8AYslE+j2WR iWEgeX4PBJ95yVkOXmwzyLo03AxDfVnAKL4vHxqIhdxeLdOvd/xLt3bB6+ee9HYnf94d vXdgo16fHE2RbB7UNLHSO1D94rx0IAiVHnz8k+VRmp+vUreaN4hhhqgNsMXSlNqOuwe4 IkSQ== X-Gm-Message-State: AJcUukdIq2lwbXSRVSrerwnIfmtAWgnlOUrkAzgcdZVUBgoDDAZ/ANiR mmym0OAvGiab2ravaEAp6mnoMLw= X-Google-Smtp-Source: ALg8bN63LmFQJRkIAbcJjdwFf+qgJ0NfDbkes7uM4TGg+fILhJTjcENuWx6+6NBWn4+7EIBaI+hgEg== X-Received: by 2002:a63:5b48:: with SMTP id l8mr3501329pgm.80.1548277867915; Wed, 23 Jan 2019 13:11:07 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:06 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 12/15] CIFS: Respect reconnect in MTU credits calculations Date: Wed, 23 Jan 2019 13:10:42 -0800 Message-Id: <1548277845-6746-13-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Every time after a session reconnect we don't need to account for credits obtained in previous sessions. Introduce new struct cifs_credits which contains both credits value and reconnect instance of the time those credits were taken. Modify a routine that add credits back to handle the reconnect instance by assuming zero credits if the reconnect happened after the credits were obtained and before we decided to add them back due to some errors during sending. This patch fixes the MTU credits cases. The subsequent patch will handle non-MTU ones. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsglob.h | 29 ++++++++++++++++--------- fs/cifs/cifsproto.h | 2 +- fs/cifs/connect.c | 3 +-- fs/cifs/file.c | 62 ++++++++++++++++++++++++++++++++--------------------- fs/cifs/smb1ops.c | 6 +++--- fs/cifs/smb2ops.c | 27 +++++++++++++++++------ fs/cifs/smb2pdu.c | 40 ++++++++++++++++++++++++---------- fs/cifs/transport.c | 13 +++++------ 8 files changed, 118 insertions(+), 64 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 94dbdbe..60a657e 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -216,6 +216,7 @@ struct cifs_io_parms; struct cifs_search_info; struct cifsInodeInfo; struct cifs_open_parms; +struct cifs_credits; struct smb_version_operations { int (*send_cancel)(struct TCP_Server_Info *, struct smb_rqst *, @@ -230,8 +231,9 @@ struct smb_version_operations { /* check response: verify signature, map error */ int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *, bool); - void (*add_credits)(struct TCP_Server_Info *, const unsigned int, - const int); + void (*add_credits)(struct TCP_Server_Info *server, + const struct cifs_credits *credits, + const int optype); void (*set_credits)(struct TCP_Server_Info *, const int); int * (*get_credits_field)(struct TCP_Server_Info *, const int); unsigned int (*get_credits)(struct mid_q_entry *); @@ -452,7 +454,7 @@ struct smb_version_operations { unsigned int (*wp_retry_size)(struct inode *); /* get mtu credits */ int (*wait_mtu_credits)(struct TCP_Server_Info *, unsigned int, - unsigned int *, unsigned int *); + unsigned int *, struct cifs_credits *); /* check if we need to issue closedir */ bool (*dir_needs_close)(struct cifsFileInfo *); long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t, @@ -710,6 +712,11 @@ struct TCP_Server_Info { int nr_targets; }; +struct cifs_credits { + unsigned int value; + unsigned int instance; +}; + static inline unsigned int in_flight(struct TCP_Server_Info *server) { @@ -734,15 +741,17 @@ static inline void add_credits(struct TCP_Server_Info *server, const unsigned int add, const int optype) { - server->ops->add_credits(server, add, optype); + struct cifs_credits credits = { .value = add, .instance = 0 }; + + server->ops->add_credits(server, &credits, optype); } static inline void -add_credits_and_wake_if(struct TCP_Server_Info *server, const unsigned int add, - const int optype) +add_credits_and_wake_if(struct TCP_Server_Info *server, + const struct cifs_credits *credits, const int optype) { - if (add) { - server->ops->add_credits(server, add, optype); + if (credits->value) { + server->ops->add_credits(server, credits, optype); wake_up(&server->request_q); } } @@ -1234,7 +1243,7 @@ struct cifs_readdata { unsigned int pagesz; unsigned int page_offset; unsigned int tailsz; - unsigned int credits; + struct cifs_credits credits; unsigned int nr_pages; struct page **pages; }; @@ -1260,7 +1269,7 @@ struct cifs_writedata { unsigned int pagesz; unsigned int page_offset; unsigned int tailsz; - unsigned int credits; + struct cifs_credits credits; unsigned int nr_pages; struct page **pages; }; diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 336c116..7a9a9fd 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -115,7 +115,7 @@ extern int cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, bool log_error); extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, unsigned int *num, - unsigned int *credits); + struct cifs_credits *credits); extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, struct kvec *, int /* nvec to send */, int * /* type of buf returned */, const int flags, diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 3e7ad68..138ac99 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -575,6 +575,7 @@ cifs_reconnect(struct TCP_Server_Info *server) if (server->tcpStatus != CifsExiting) server->tcpStatus = CifsNeedNegotiate; spin_unlock(&GlobalMid_Lock); + set_credits(server, 1); mutex_unlock(&server->srv_mutex); } } while (server->tcpStatus == CifsNeedReconnect); @@ -4870,8 +4871,6 @@ cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses) if (!server->ops->need_neg(server)) return 0; - set_credits(server, 1); - rc = server->ops->negotiate(xid, ses); if (rc == 0) { spin_lock(&GlobalMid_Lock); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 109b1ef..baaa733 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2134,11 +2134,13 @@ static int cifs_writepages(struct address_space *mapping, server = cifs_sb_master_tcon(cifs_sb)->ses->server; retry: while (!done && index <= end) { - unsigned int i, nr_pages, found_pages, wsize, credits; + unsigned int i, nr_pages, found_pages, wsize; pgoff_t next = 0, tofind, saved_index = index; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, - &wsize, &credits); + &wsize, credits); if (rc != 0) { done = true; break; @@ -2171,13 +2173,13 @@ static int cifs_writepages(struct address_space *mapping, continue; } - wdata->credits = credits; + wdata->credits = credits_on_stack; rc = wdata_send_pages(wdata, nr_pages, mapping, wbc); /* send failure -- clean up the mess */ if (rc != 0) { - add_credits_and_wake_if(server, wdata->credits, 0); + add_credits_and_wake_if(server, &wdata->credits, 0); for (i = 0; i < nr_pages; ++i) { if (is_retryable_error(rc)) redirty_page_for_writepage(wbc, @@ -2558,7 +2560,8 @@ static int cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list, struct cifs_aio_ctx *ctx) { - unsigned int wsize, credits; + unsigned int wsize; + struct cifs_credits credits; int rc; struct TCP_Server_Info *server = tlink_tcon(wdata->cfile->tlink)->ses->server; @@ -2568,18 +2571,19 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list, * Note: we are attempting to resend the whole wdata not in segments */ do { - rc = server->ops->wait_mtu_credits( - server, wdata->bytes, &wsize, &credits); + rc = server->ops->wait_mtu_credits(server, wdata->bytes, &wsize, + &credits); if (rc) goto out; if (wsize < wdata->bytes) { - add_credits_and_wake_if(server, credits, 0); + add_credits_and_wake_if(server, &credits, 0); msleep(1000); } } while (wsize < wdata->bytes); + wdata->credits = credits; rc = -EAGAIN; while (rc == -EAGAIN) { rc = 0; @@ -2595,7 +2599,7 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list, return 0; } - add_credits_and_wake_if(server, wdata->credits, 0); + add_credits_and_wake_if(server, &wdata->credits, 0); out: kref_put(&wdata->refcount, cifs_uncached_writedata_release); @@ -2618,6 +2622,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, struct TCP_Server_Info *server; struct page **pagevec; size_t start; + unsigned int xid; if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) pid = open_file->pid; @@ -2625,12 +2630,15 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, pid = current->tgid; server = tlink_tcon(open_file->tlink)->ses->server; + xid = get_xid(); do { - unsigned int wsize, credits; + unsigned int wsize; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, - &wsize, &credits); + &wsize, credits); if (rc) break; @@ -2720,7 +2728,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, wdata->pid = pid; wdata->bytes = cur_len; wdata->pagesz = PAGE_SIZE; - wdata->credits = credits; + wdata->credits = credits_on_stack; wdata->ctx = ctx; kref_get(&ctx->refcount); @@ -2729,7 +2737,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, rc = server->ops->async_writev(wdata, cifs_uncached_writedata_release); if (rc) { - add_credits_and_wake_if(server, wdata->credits, 0); + add_credits_and_wake_if(server, &wdata->credits, 0); kref_put(&wdata->refcount, cifs_uncached_writedata_release); if (rc == -EAGAIN) { @@ -2745,6 +2753,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, len -= cur_len; } while (len > 0); + free_xid(xid); return rc; } @@ -3249,7 +3258,8 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata, struct list_head *rdata_list, struct cifs_aio_ctx *ctx) { - unsigned int rsize, credits; + unsigned int rsize; + struct cifs_credits credits; int rc; struct TCP_Server_Info *server = tlink_tcon(rdata->cfile->tlink)->ses->server; @@ -3266,11 +3276,12 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata, goto out; if (rsize < rdata->bytes) { - add_credits_and_wake_if(server, credits, 0); + add_credits_and_wake_if(server, &credits, 0); msleep(1000); } } while (rsize < rdata->bytes); + rdata->credits = credits; rc = -EAGAIN; while (rc == -EAGAIN) { rc = 0; @@ -3286,7 +3297,7 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata, return 0; } - add_credits_and_wake_if(server, rdata->credits, 0); + add_credits_and_wake_if(server, &rdata->credits, 0); out: kref_put(&rdata->refcount, cifs_uncached_readdata_release); @@ -3300,7 +3311,9 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, struct cifs_aio_ctx *ctx) { struct cifs_readdata *rdata; - unsigned int npages, rsize, credits; + unsigned int npages, rsize; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; size_t cur_len; int rc; pid_t pid; @@ -3321,7 +3334,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, do { rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, - &rsize, &credits); + &rsize, credits); if (rc) break; @@ -3391,7 +3404,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, rdata->pagesz = PAGE_SIZE; rdata->read_into_pages = cifs_uncached_read_into_pages; rdata->copy_into_pages = cifs_uncached_copy_into_pages; - rdata->credits = credits; + rdata->credits = credits_on_stack; rdata->ctx = ctx; kref_get(&ctx->refcount); @@ -3400,7 +3413,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, rc = server->ops->async_readv(rdata); error: if (rc) { - add_credits_and_wake_if(server, rdata->credits, 0); + add_credits_and_wake_if(server, &rdata->credits, 0); kref_put(&rdata->refcount, cifs_uncached_readdata_release); if (rc == -EAGAIN) { @@ -4081,10 +4094,11 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, loff_t offset; struct page *page, *tpage; struct cifs_readdata *rdata; - unsigned credits; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, - &rsize, &credits); + &rsize, credits); if (rc) break; @@ -4130,7 +4144,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, rdata->tailsz = PAGE_SIZE; rdata->read_into_pages = cifs_readpages_read_into_pages; rdata->copy_into_pages = cifs_readpages_copy_into_pages; - rdata->credits = credits; + rdata->credits = credits_on_stack; list_for_each_entry_safe(page, tpage, &tmplist, lru) { list_del(&page->lru); @@ -4141,7 +4155,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, !(rc = cifs_reopen_file(rdata->cfile, true))) rc = server->ops->async_readv(rdata); if (rc) { - add_credits_and_wake_if(server, rdata->credits, 0); + add_credits_and_wake_if(server, &rdata->credits, 0); for (i = 0; i < rdata->nr_pages; i++) { page = rdata->pages[i]; lru_cache_add_file(page); diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c index 32a6c02..6f92d64 100644 --- a/fs/cifs/smb1ops.c +++ b/fs/cifs/smb1ops.c @@ -117,11 +117,11 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer) } static void -cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add, - const int optype) +cifs_add_credits(struct TCP_Server_Info *server, + const struct cifs_credits *credits, const int optype) { spin_lock(&server->req_lock); - server->credits += add; + server->credits += credits->value; server->in_flight--; spin_unlock(&server->req_lock); wake_up(&server->request_q); diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 3ee8258..86332e6 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -67,10 +67,13 @@ change_conf(struct TCP_Server_Info *server) } static void -smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, - const int optype) +smb2_add_credits(struct TCP_Server_Info *server, + const struct cifs_credits *credits, const int optype) { int *val, rc = -1; + unsigned int add = credits->value; + unsigned int instance = credits->instance; + bool reconnect_detected = false; spin_lock(&server->req_lock); val = server->ops->get_credits_field(server, optype); @@ -79,8 +82,11 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0)) trace_smb3_reconnect_with_invalid_credits(server->CurrentMid, server->hostname, *val); + if ((instance == 0) || (instance == server->reconnect_instance)) + *val += add; + else + reconnect_detected = true; - *val += add; if (*val > 65000) { *val = 65000; /* Don't get near 64K credits, avoid srv bugs */ printk_once(KERN_WARNING "server overflowed SMB3 credits\n"); @@ -102,6 +108,10 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, spin_unlock(&server->req_lock); wake_up(&server->request_q); + if (reconnect_detected) + cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n", + add, instance); + switch (rc) { case -1: /* change_conf hasn't been executed */ @@ -160,7 +170,7 @@ smb2_get_credits(struct mid_q_entry *mid) static int smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, - unsigned int *num, unsigned int *credits) + unsigned int *num, struct cifs_credits *credits) { int rc = 0; unsigned int scredits; @@ -186,7 +196,8 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, /* can deadlock with reopen */ if (scredits <= 8) { *num = SMB2_MAX_BUFFER_SIZE; - *credits = 0; + credits->value = 0; + credits->instance = 0; break; } @@ -195,8 +206,10 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, *num = min_t(unsigned int, size, scredits * SMB2_MAX_BUFFER_SIZE); - *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); - server->credits -= *credits; + credits->value = + DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); + credits->instance = server->reconnect_instance; + server->credits -= credits->value; server->in_flight++; break; } diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 291f290..401f3a4 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3245,9 +3245,9 @@ smb2_async_readv(struct cifs_readdata *rdata) rc = smb2_new_read_req( (void **) &buf, &total_len, &io_parms, rdata, 0, 0); if (rc) { - if (rc == -EAGAIN && rdata->credits) { + if (rc == -EAGAIN && rdata->credits.value) { /* credits was reset by reconnect */ - rdata->credits = 0; + rdata->credits.value = 0; /* reduce in_flight value since we won't send the req */ spin_lock(&server->req_lock); server->in_flight--; @@ -3264,17 +3264,26 @@ smb2_async_readv(struct cifs_readdata *rdata) shdr = (struct smb2_sync_hdr *)buf; - if (rdata->credits) { + if (rdata->credits.value > 0) { shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes, SMB2_MAX_BUFFER_SIZE)); shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); spin_lock(&server->req_lock); - server->credits += rdata->credits - + if (server->reconnect_instance == rdata->credits.instance) + server->credits += rdata->credits.value - le16_to_cpu(shdr->CreditCharge); + else { + spin_unlock(&server->req_lock); + cifs_dbg(VFS, "trying to return %u credits to old session\n", + rdata->credits.value + - le16_to_cpu(shdr->CreditCharge)); + rc = -EAGAIN; + goto async_readv_out; + } spin_unlock(&server->req_lock); wake_up(&server->request_q); - rdata->credits = le16_to_cpu(shdr->CreditCharge); + rdata->credits.value = le16_to_cpu(shdr->CreditCharge); flags |= CIFS_HAS_CREDITS; } @@ -3292,7 +3301,7 @@ smb2_async_readv(struct cifs_readdata *rdata) trace_smb3_read_done(0 /* xid */, io_parms.persistent_fid, io_parms.tcon->tid, io_parms.tcon->ses->Suid, io_parms.offset, io_parms.length); - +async_readv_out: cifs_small_buf_release(buf); return rc; } @@ -3451,9 +3460,9 @@ smb2_async_writev(struct cifs_writedata *wdata, rc = smb2_plain_req_init(SMB2_WRITE, tcon, (void **) &req, &total_len); if (rc) { - if (rc == -EAGAIN && wdata->credits) { + if (rc == -EAGAIN && wdata->credits.value) { /* credits was reset by reconnect */ - wdata->credits = 0; + wdata->credits.value = 0; /* reduce in_flight value since we won't send the req */ spin_lock(&server->req_lock); server->in_flight--; @@ -3546,17 +3555,26 @@ smb2_async_writev(struct cifs_writedata *wdata, req->Length = cpu_to_le32(wdata->bytes); #endif - if (wdata->credits) { + if (wdata->credits.value > 0) { shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes, SMB2_MAX_BUFFER_SIZE)); shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); spin_lock(&server->req_lock); - server->credits += wdata->credits - + if (server->reconnect_instance == wdata->credits.instance) + server->credits += wdata->credits.value - le16_to_cpu(shdr->CreditCharge); + else { + spin_unlock(&server->req_lock); + cifs_dbg(VFS, "trying to return %d credits to old session\n", + wdata->credits.value + - le16_to_cpu(shdr->CreditCharge)); + rc = -EAGAIN; + goto async_writev_out; + } spin_unlock(&server->req_lock); wake_up(&server->request_q); - wdata->credits = le16_to_cpu(shdr->CreditCharge); + wdata->credits.value = le16_to_cpu(shdr->CreditCharge); flags |= CIFS_HAS_CREDITS; } diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index eff9e3c..f364a08 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -539,10 +539,11 @@ wait_for_free_request(struct TCP_Server_Info *server, const int timeout, int cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, - unsigned int *num, unsigned int *credits) + unsigned int *num, struct cifs_credits *credits) { *num = size; - *credits = 0; + credits->value = 0; + credits->instance = server->reconnect_instance; return 0; } @@ -633,7 +634,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, { int rc, timeout, optype; struct mid_q_entry *mid; - unsigned int credits = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; timeout = flags & CIFS_TIMEOUT_MASK; optype = flags & CIFS_OP_MASK; @@ -642,14 +643,14 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, rc = wait_for_free_request(server, timeout, optype); if (rc) return rc; - credits = 1; + credits.value = 1; } mutex_lock(&server->srv_mutex); mid = server->ops->setup_async_request(server, rqst); if (IS_ERR(mid)) { mutex_unlock(&server->srv_mutex); - add_credits_and_wake_if(server, credits, optype); + add_credits_and_wake_if(server, &credits, optype); return PTR_ERR(mid); } @@ -683,7 +684,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, if (rc == 0) return 0; - add_credits_and_wake_if(server, credits, optype); + add_credits_and_wake_if(server, &credits, optype); return rc; } From patchwork Wed Jan 23 21:10:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1FEE1515 for ; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1BC42D7AB for ; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 964D82D8B0; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E7CE2D7B1 for ; Wed, 23 Jan 2019 21:11:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726994AbfAWVLL (ORCPT ); Wed, 23 Jan 2019 16:11:11 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35034 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbfAWVLL (ORCPT ); Wed, 23 Jan 2019 16:11:11 -0500 Received: by mail-pf1-f196.google.com with SMTP id z9so1811093pfi.2 for ; Wed, 23 Jan 2019 13:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=8nQ19dxyE8Lfj5qY8xj3cn9tpBoyPsRQCTeIurIhNrU=; b=n3eKDO2HHOjsDztD0vo6C4i44uXEqPAuBhhx6/2FcZUuDMW1FR5U2B+bV2d2dG7O9y BEAC7MhS37S0222tIEllkcO6ms7uOc2tFoJ85hYdVfKcNL+8gApLAfgoA6gFZjUiqGVO qnqxqSTlIZqmo4HQSr4l2CETVw7btUDinYPMwfU0bwmIMobwDsmgSa8kPxPLHvNGEFgA PwCKdswieVOJCE67kTCO/I/L5xj9FdYPhX99fpoEEvebcxG046S1v3E0PYCWVduTYGKM CVjdSgCpW8UQk0jlQaLGLeklOyt4VJKMQoJnzSo+NTZfXct7CUfqCiTFGY+BdT2HkNHQ xvgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8nQ19dxyE8Lfj5qY8xj3cn9tpBoyPsRQCTeIurIhNrU=; b=ZgCCmupV2nMciou1e8zXM9axKPK2dljSHWhoBwWB63LR1vvVwIIfpvjgU6cxbwDtKY R7knC1sDqH1iyysRJAQr6/quY7/69oj8in3IXkeotHwJ4VX1e1anALsmGnnWa9etCS65 HuKti/Dm/B6kNF4hh4paB3RWNne9ynhhWyVZjyHYVbCaLZUvjdbQom13P465m2uNer2B LQufhqMu7uJoVm9xcnWyA22x8Al4syl1ZblkqwqbkjR8RFI4issVInO5eMeu9CWc+x12 ZJLbiJThckp+VNz5A7Lbviwzk/M9NOjxN3KIXSWSgurT/9g5fdtYv2sXUU3iAO2U4gNZ ZfjA== X-Gm-Message-State: AJcUukdAL8kspbdvyh5wU27OLnaeHNRYCMKiDmN1972ZLB3Jb7sGURlp cAvb8gx4ccAsriIlq+Zt21r8Gug= X-Google-Smtp-Source: ALg8bN6aAEG3oX/p8ZKOFHnu2+StqhVk66MYDnEgVtlIwvTu3Yq3Yv6RdFbGvlkj4uFy7/l3ULCRjA== X-Received: by 2002:a63:4948:: with SMTP id y8mr3484155pgk.32.1548277869119; Wed, 23 Jan 2019 13:11:09 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:08 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 13/15] CIFS: Respect reconnect in non-MTU credits calculations Date: Wed, 23 Jan 2019 13:10:43 -0800 Message-Id: <1548277845-6746-14-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Every time after a session reconnect we don't need to account for credits obtained in previous sessions. Make use of the recently added cifs_credits structure to properly calculate credits for non-MTU requests the same way we did for MTU ones. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsglob.h | 6 ++---- fs/cifs/cifssmb.c | 9 ++++++--- fs/cifs/smb2pdu.c | 33 +++++++++++++++++++------------- fs/cifs/transport.c | 54 +++++++++++++++++++++++++++++++++++------------------ 4 files changed, 64 insertions(+), 38 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 60a657e..24ecde1 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -738,12 +738,10 @@ has_credits(struct TCP_Server_Info *server, int *credits) } static inline void -add_credits(struct TCP_Server_Info *server, const unsigned int add, +add_credits(struct TCP_Server_Info *server, const struct cifs_credits *credits, const int optype) { - struct cifs_credits credits = { .value = add, .instance = 0 }; - - server->ops->add_credits(server, &credits, optype); + server->ops->add_credits(server, credits, optype); } static inline void diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index c8792d2..5b54882 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -813,9 +813,10 @@ static void cifs_echo_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->callback_data; + struct cifs_credits credits = { .value = 1, .instance = 0 }; DeleteMidQEntry(mid); - add_credits(server, 1, CIFS_ECHO_OP); + add_credits(server, &credits, CIFS_ECHO_OP); } int @@ -1705,6 +1706,7 @@ cifs_readv_callback(struct mid_q_entry *mid) .rq_npages = rdata->nr_pages, .rq_pagesz = rdata->pagesz, .rq_tailsz = rdata->tailsz }; + struct cifs_credits credits = { .value = 1, .instance = 0 }; cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", __func__, mid->mid, mid->mid_state, rdata->result, @@ -1742,7 +1744,7 @@ cifs_readv_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &rdata->work); DeleteMidQEntry(mid); - add_credits(server, 1, 0); + add_credits(server, &credits, 0); } /* cifs_async_readv - send an async write, and set up mid to handle result */ @@ -2218,6 +2220,7 @@ cifs_writev_callback(struct mid_q_entry *mid) struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); unsigned int written; WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; + struct cifs_credits credits = { .value = 1, .instance = 0 }; switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: @@ -2253,7 +2256,7 @@ cifs_writev_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &wdata->work); DeleteMidQEntry(mid); - add_credits(tcon->ses->server, 1, 0); + add_credits(tcon->ses->server, &credits, 0); } /* cifs_async_writev - send an async write, and set up mid to handle result */ diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 401f3a4..2a2ebaa 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2893,14 +2893,16 @@ 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; - unsigned int credits_received = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; if (mid->mid_state == MID_RESPONSE_RECEIVED - || mid->mid_state == MID_RESPONSE_MALFORMED) - credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); + || mid->mid_state == MID_RESPONSE_MALFORMED) { + credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.instance = server->reconnect_instance; + } DeleteMidQEntry(mid); - add_credits(server, credits_received, CIFS_ECHO_OP); + add_credits(server, &credits, CIFS_ECHO_OP); } void smb2_reconnect_server(struct work_struct *work) @@ -3153,7 +3155,7 @@ smb2_readv_callback(struct mid_q_entry *mid) struct TCP_Server_Info *server = tcon->ses->server; struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)rdata->iov[0].iov_base; - unsigned int credits_received = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; struct smb_rqst rqst = { .rq_iov = rdata->iov, .rq_nvec = 2, .rq_pages = rdata->pages, @@ -3168,7 +3170,8 @@ smb2_readv_callback(struct mid_q_entry *mid) switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: - credits_received = le16_to_cpu(shdr->CreditRequest); + credits.value = le16_to_cpu(shdr->CreditRequest); + credits.instance = server->reconnect_instance; /* result already set, check signature */ if (server->sign && !mid->decrypted) { int rc; @@ -3193,7 +3196,8 @@ smb2_readv_callback(struct mid_q_entry *mid) cifs_stats_bytes_read(tcon, rdata->got_bytes); break; case MID_RESPONSE_MALFORMED: - credits_received = le16_to_cpu(shdr->CreditRequest); + credits.value = le16_to_cpu(shdr->CreditRequest); + credits.instance = server->reconnect_instance; /* fall through */ default: rdata->result = -EIO; @@ -3214,7 +3218,7 @@ smb2_readv_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &rdata->work); DeleteMidQEntry(mid); - add_credits(server, credits_received, 0); + add_credits(server, &credits, 0); } /* smb2_async_readv - send an async read, and set up mid to handle result */ @@ -3386,14 +3390,16 @@ smb2_writev_callback(struct mid_q_entry *mid) { struct cifs_writedata *wdata = mid->callback_data; struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); + struct TCP_Server_Info *server = tcon->ses->server; unsigned int written; struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; - unsigned int credits_received = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: - credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); - wdata->result = smb2_check_receive(mid, tcon->ses->server, 0); + credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.instance = server->reconnect_instance; + wdata->result = smb2_check_receive(mid, server, 0); if (wdata->result != 0) break; @@ -3417,7 +3423,8 @@ smb2_writev_callback(struct mid_q_entry *mid) wdata->result = -EAGAIN; break; case MID_RESPONSE_MALFORMED: - credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.instance = server->reconnect_instance; /* fall through */ default: wdata->result = -EIO; @@ -3441,7 +3448,7 @@ smb2_writev_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &wdata->work); DeleteMidQEntry(mid); - add_credits(tcon->ses->server, credits_received, 0); + add_credits(server, &credits, 0); } /* smb2_async_writev - send an async write, and set up mid to handle result */ diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index f364a08..8b512a9 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -478,15 +478,18 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, static int wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, - int *credits) + int *credits, unsigned int *instance) { int rc; + *instance = 0; + spin_lock(&server->req_lock); if (timeout == CIFS_ASYNC_OP) { /* oplock breaks must not be held up */ server->in_flight++; *credits -= 1; + *instance = server->reconnect_instance; spin_unlock(&server->req_lock); return 0; } @@ -516,6 +519,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, if (timeout != CIFS_BLOCKING_OP) { *credits -= 1; server->in_flight++; + *instance = server->reconnect_instance; } spin_unlock(&server->req_lock); break; @@ -526,7 +530,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, static int wait_for_free_request(struct TCP_Server_Info *server, const int timeout, - const int optype) + const int optype, unsigned int *instance) { int *val; @@ -534,7 +538,7 @@ wait_for_free_request(struct TCP_Server_Info *server, const int timeout, /* Since an echo is already inflight, no need to wait to send another */ if (*val <= 0 && optype == CIFS_ECHO_OP) return -EAGAIN; - return wait_for_free_credits(server, timeout, val); + return wait_for_free_credits(server, timeout, val, instance); } int @@ -635,15 +639,17 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, int rc, timeout, optype; struct mid_q_entry *mid; struct cifs_credits credits = { .value = 0, .instance = 0 }; + unsigned int instance; timeout = flags & CIFS_TIMEOUT_MASK; optype = flags & CIFS_OP_MASK; if ((flags & CIFS_HAS_CREDITS) == 0) { - rc = wait_for_free_request(server, timeout, optype); + rc = wait_for_free_request(server, timeout, optype, &instance); if (rc) return rc; credits.value = 1; + credits.instance = instance; } mutex_lock(&server->srv_mutex); @@ -814,8 +820,12 @@ static void cifs_compound_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->server; + struct cifs_credits credits; + + credits.value = server->ops->get_credits(mid); + credits.instance = server->reconnect_instance; - add_credits(server, server->ops->get_credits(mid), mid->optype); + add_credits(server, &credits, mid->optype); } static void @@ -841,7 +851,10 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, int timeout, optype; struct mid_q_entry *midQ[MAX_COMPOUND]; bool cancelled_mid[MAX_COMPOUND] = {false}; - unsigned int credits[MAX_COMPOUND] = {0}; + struct cifs_credits credits[MAX_COMPOUND] = { + { .value = 0, .instance = 0 } + }; + unsigned int instance; char *buf; timeout = flags & CIFS_TIMEOUT_MASK; @@ -867,7 +880,8 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, * needed anyway. */ for (i = 0; i < num_rqst; i++) { - rc = wait_for_free_request(ses->server, timeout, optype); + rc = wait_for_free_request(ses->server, timeout, optype, + &instance); if (rc) { /* * We haven't sent an SMB packet to the server yet but @@ -879,10 +893,11 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, * requests correctly. */ for (j = 0; j < i; j++) - add_credits(ses->server, 1, optype); + add_credits(ses->server, &credits[j], optype); return rc; } - credits[i] = 1; + credits[i].value = 1; + credits[i].instance = instance; } /* @@ -902,7 +917,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, /* Update # of requests on wire to server */ for (j = 0; j < num_rqst; j++) - add_credits(ses->server, credits[j], optype); + add_credits(ses->server, &credits[j], optype); return PTR_ERR(midQ[i]); } @@ -933,7 +948,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, if (rc < 0) { /* Sending failed for some reason - return credits back */ for (i = 0; i < num_rqst; i++) - add_credits(ses->server, credits[i], optype); + add_credits(ses->server, &credits[i], optype); goto out; } @@ -970,7 +985,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, midQ[i]->mid_flags |= MID_WAIT_CANCELLED; midQ[i]->callback = cifs_cancelled_callback; cancelled_mid[i] = true; - credits[i] = 0; + credits[i].value = 0; } spin_unlock(&GlobalMid_Lock); } @@ -1096,6 +1111,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, unsigned int len = be32_to_cpu(in_buf->smb_buf_length); struct kvec iov = { .iov_base = in_buf, .iov_len = len }; struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; + struct cifs_credits credits = { .value = 1, .instance = 0 }; if (ses == NULL) { cifs_dbg(VFS, "Null smb session\n"); @@ -1119,7 +1135,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, return -EIO; } - rc = wait_for_free_request(ses->server, timeout, 0); + rc = wait_for_free_request(ses->server, timeout, 0, &credits.instance); if (rc) return rc; @@ -1133,7 +1149,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, if (rc) { mutex_unlock(&ses->server->srv_mutex); /* Update # of requests on wire to server */ - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } @@ -1169,7 +1185,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, /* no longer considered to be "in-flight" */ midQ->callback = DeleteMidQEntry; spin_unlock(&GlobalMid_Lock); - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } spin_unlock(&GlobalMid_Lock); @@ -1177,7 +1193,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, rc = cifs_sync_mid_result(midQ, ses->server); if (rc != 0) { - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } @@ -1193,7 +1209,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, rc = cifs_check_receive(midQ, ses->server, 0); out: cifs_delete_mid(midQ); - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } @@ -1235,6 +1251,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, unsigned int len = be32_to_cpu(in_buf->smb_buf_length); struct kvec iov = { .iov_base = in_buf, .iov_len = len }; struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; + unsigned int instance; if (tcon == NULL || tcon->ses == NULL) { cifs_dbg(VFS, "Null smb session\n"); @@ -1260,7 +1277,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, return -EIO; } - rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0); + rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0, + &instance); if (rc) return rc; From patchwork Wed Jan 23 21:10:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 123BA91E for ; Wed, 23 Jan 2019 21:11:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 035352D7AB for ; Wed, 23 Jan 2019 21:11:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC75F2D7B1; Wed, 23 Jan 2019 21:11:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27CB52D840 for ; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726991AbfAWVLL (ORCPT ); Wed, 23 Jan 2019 16:11:11 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35033 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLL (ORCPT ); Wed, 23 Jan 2019 16:11:11 -0500 Received: by mail-pf1-f194.google.com with SMTP id z9so1811100pfi.2 for ; Wed, 23 Jan 2019 13:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=PDx0iyWL61oeuUnTWzWNC22mPhRa7M1Su/1+XGqZfbE=; b=SRgvgVT42bh/ph8bhWvSbcxa9bnd4JhcccCuKJcxzlA0UAncM3f//y51C+o30MW+as Sp61z8ztsCh3Z2Z6zcuqadIyIb2JdjrVssSSFt3/HyvO+SWK3Ru6ojFvmM5V1EJY2wIs tG3kemkBtL4t9/qK33yCkt3kOqInoouO6m+noPNsZyhF0TwYfCPTNg90zXBwzVo4ATzI EDGrTPga7Uw/vtzGvh/I7o/R+KSSNINcHQsStrzAMHac7utttIuwZ3PcE7m9FD7ggk00 4zUoSLm9gOt26OmPhf4aiJfN+Jrj1ED9/vKRCn8uSo3WscvexDLywgAeRiDuynjY1JXs UkIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=PDx0iyWL61oeuUnTWzWNC22mPhRa7M1Su/1+XGqZfbE=; b=QsiOksMmwBGjhJrM0i57GlvmyL0olWTo36dnRrSt/xr2fPsu/iEDKI2dd/8KweAUyO lWDzriURHG7n/r9XKSLFw9V7Z78c7XgwGpZAoMIumQaJNuk87gDvuelPV8yJ0IUhvY7a +KWiXDAvRi0TFCVCIACMDgRY5PuOhly2Mhq4+yaGvJRiix3dhdjWnE+qSjFT48gzpHcM u7AjZ3v1JSQz+y4AYFXd7szNI3ZQ8PdOA1TFcqkhy90IO317S62zLu2xH9MTnqjXTMsm qzT31+g05qaOSNW1+U/z16GciSR/4VPiesuIHRxga7q/EUnWvvaYhezs+mf+WI3pg4WH esWQ== X-Gm-Message-State: AJcUukdiatJA8Sz7UyImJVaWIj9+uuFFeRlXPV6CdLO9rRpUPVBvMYFN LqmTYMTnK6Ra0Fdpeu0b/uzHf0w= X-Google-Smtp-Source: ALg8bN5z0nR/e+j18aOdc8a3Ub5m4yJPyOrtV/E8Ym44shCw7yBq5Da2hAmsL6URL+EfPEo0961pFA== X-Received: by 2002:a63:de46:: with SMTP id y6mr3481538pgi.198.1548277870100; Wed, 23 Jan 2019 13:11:10 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:09 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 14/15] CIFS: Check for reconnects before sending async requests Date: Wed, 23 Jan 2019 13:10:44 -0800 Message-Id: <1548277845-6746-15-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The reconnect might have happended after we obtained credits and before we acquired srv_mutex. Check for that under the mutex and retry an async operation if the reconnect is detected. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsproto.h | 3 ++- fs/cifs/cifssmb.c | 6 +++--- fs/cifs/smb2pdu.c | 7 ++++--- fs/cifs/transport.c | 18 ++++++++++++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 7a9a9fd..9e8394f 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -93,7 +93,8 @@ extern int cifs_discard_remaining_data(struct TCP_Server_Info *server); extern int cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback, - mid_handle_t *handle, void *cbdata, const int flags); + mid_handle_t *handle, void *cbdata, const int flags, + const struct cifs_credits *exist_credits); extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, struct smb_rqst *rqst, int *resp_buf_type, const int flags, struct kvec *resp_iov); diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 5b54882..8f44415 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -851,7 +851,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) iov[1].iov_base = (char *)smb + 4; rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, NULL, - server, CIFS_ASYNC_OP | CIFS_ECHO_OP); + server, CIFS_ASYNC_OP | CIFS_ECHO_OP, NULL); if (rc) cifs_dbg(FYI, "Echo request failed: %d\n", rc); @@ -1803,7 +1803,7 @@ cifs_async_readv(struct cifs_readdata *rdata) kref_get(&rdata->refcount); rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, - cifs_readv_callback, NULL, rdata, 0); + cifs_readv_callback, NULL, rdata, 0, NULL); if (rc == 0) cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); @@ -2334,7 +2334,7 @@ cifs_async_writev(struct cifs_writedata *wdata, kref_get(&wdata->refcount); rc = cifs_call_async(tcon->ses->server, &rqst, NULL, - cifs_writev_callback, NULL, wdata, 0); + cifs_writev_callback, NULL, wdata, 0, NULL); if (rc == 0) cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 2a2ebaa..8d3a96d 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2994,7 +2994,7 @@ SMB2_echo(struct TCP_Server_Info *server) iov[0].iov_base = (char *)req; rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, NULL, - server, CIFS_ECHO_OP); + server, CIFS_ECHO_OP, NULL); if (rc) cifs_dbg(FYI, "Echo request failed: %d\n", rc); @@ -3294,7 +3294,8 @@ smb2_async_readv(struct cifs_readdata *rdata) kref_get(&rdata->refcount); rc = cifs_call_async(io_parms.tcon->ses->server, &rqst, cifs_readv_receive, smb2_readv_callback, - smb3_handle_read_data, rdata, flags); + smb3_handle_read_data, rdata, flags, + &rdata->credits); if (rc) { kref_put(&rdata->refcount, cifs_readdata_release); cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); @@ -3587,7 +3588,7 @@ smb2_async_writev(struct cifs_writedata *wdata, kref_get(&wdata->refcount); rc = cifs_call_async(server, &rqst, NULL, smb2_writev_callback, NULL, - wdata, flags); + wdata, flags, &wdata->credits); if (rc) { trace_smb3_write_err(0 /* no xid */, req->PersistentFileId, diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 8b512a9..26e9912 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -634,7 +634,8 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) int cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback, - mid_handle_t *handle, void *cbdata, const int flags) + mid_handle_t *handle, void *cbdata, const int flags, + const struct cifs_credits *exist_credits) { int rc, timeout, optype; struct mid_q_entry *mid; @@ -650,9 +651,22 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, return rc; credits.value = 1; credits.instance = instance; - } + } else + instance = exist_credits->instance; mutex_lock(&server->srv_mutex); + + /* + * We can't use credits obtained from the previous session to send this + * request. Check if there were reconnects after we obtained credits and + * return -EAGAIN in such cases to let callers handle it. + */ + if (instance != server->reconnect_instance) { + mutex_unlock(&server->srv_mutex); + add_credits_and_wake_if(server, &credits, optype); + return -EAGAIN; + } + mid = server->ops->setup_async_request(server, rqst); if (IS_ERR(mid)) { mutex_unlock(&server->srv_mutex); From patchwork Wed Jan 23 21:10:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B96617F0 for ; Wed, 23 Jan 2019 21:11:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D12A2D7AB for ; Wed, 23 Jan 2019 21:11:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41EF82D8B0; Wed, 23 Jan 2019 21:11:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D90652D7AB for ; Wed, 23 Jan 2019 21:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726996AbfAWVLM (ORCPT ); Wed, 23 Jan 2019 16:11:12 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34035 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLM (ORCPT ); Wed, 23 Jan 2019 16:11:12 -0500 Received: by mail-pl1-f194.google.com with SMTP id w4so1796425plz.1 for ; Wed, 23 Jan 2019 13:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Z52VzKseuL2Hl6Nusz/58NYaohbON2kvRAIHzgKuHCM=; b=XYMRjZGnRTH7kkvgE+L6CoBYoRooJ/2RgenDe54yZMZdDyCuW75pIO4vx399L6BR2F 3ZHxh02UGC2P0vwSkmiuwXjXu7xRA5ZpEsBuT1q7bMjO6oSulyfBrCuWW3f+okJjJsHN /omYV6IkegmpJR26EIvaaBamJAcOUVj0vU0AqIFO0GD9kM+aL5eGudTSRgux5pDZ3F2F VOuOyhldS86jfV/DkTFjwSxvPOQ748OA1rLyYKolPZl2O908hf/igYeWKl8tcwnezPrU sWTlHxa0ZHn3Lc7kj+GS4Ox8UmjP+HL+3o8nopxQZaauKybUsz6zUGpRGvU19wFG5Bcw uqPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Z52VzKseuL2Hl6Nusz/58NYaohbON2kvRAIHzgKuHCM=; b=dSwy6Y3evFmi5/AvgF/flSy5w15vQOTFwbvNcEV2ttNCufD5ebNWgMPRLK9vZUqyQ9 AWeVAg0Cd3khbQ7x+pTyb0oFzy7Pg0k1qSfR2mNX60/SCh3H8jSk4v2fWkHwGGEzsBhK FIxBlUsVHBH0zZvk4s9kS6lYKAqfVkN9FBPr1wADqlSEHC+TmaQKgRhMaOEXV1HN3EjP t0eI+YG1uA0GkOcdChKZiDVbJ7DmKWH3DjRdol6HQ5LUL7R/7g6UqBVkoTVDblDJB8Cr hU7ZoifsaP2kMkF3MpSWTMAD0gUQ6plqxvWx9YVpB2YjzNKQ+ie9VPH+oS1JDpz4yRcZ gBRw== X-Gm-Message-State: AJcUukfR9PEVFTBXcJ/tKlF1qWosnv1rts+yZoREDZYIbnA16idx331Z cMGOoHAB8Ji9A/lFlkS+xz0Rlmk= X-Google-Smtp-Source: ALg8bN5i+sSE1axIKnLw+BljzbTYCC2Hn0irNEvqwfw3jRPefOrYoMx5wo62z4ZLHklHJoldB7nNbQ== X-Received: by 2002:a17:902:7107:: with SMTP id a7mr3865115pll.290.1548277871285; Wed, 23 Jan 2019 13:11:11 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:10 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 15/15] CIFS: Check for reconnects before sending compound requests Date: Wed, 23 Jan 2019 13:10:45 -0800 Message-Id: <1548277845-6746-16-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The reconnect might have happended after we obtained credits and before we acquired srv_mutex. Check for that under the mutex and retry a sync operation if the reconnect is detected. Signed-off-by: Pavel Shilovsky --- fs/cifs/transport.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 26e9912..2187bc3 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -869,6 +869,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, { .value = 0, .instance = 0 } }; unsigned int instance; + unsigned int first_instance = 0; char *buf; timeout = flags & CIFS_TIMEOUT_MASK; @@ -896,6 +897,25 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, for (i = 0; i < num_rqst; i++) { rc = wait_for_free_request(ses->server, timeout, optype, &instance); + + if (rc == 0) { + credits[i].value = 1; + credits[i].instance = instance; + /* + * All parts of the compound chain must get credits from + * the same session, otherwise we may end up using more + * credits than the server granted. If there were + * reconnects in between, return -EAGAIN and let callers + * handle it. + */ + if (i == 0) + first_instance = instance; + else if (first_instance != instance) { + i++; + rc = -EAGAIN; + } + } + if (rc) { /* * We haven't sent an SMB packet to the server yet but @@ -910,8 +930,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, add_credits(ses->server, &credits[j], optype); return rc; } - credits[i].value = 1; - credits[i].instance = instance; } /* @@ -922,6 +940,22 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, mutex_lock(&ses->server->srv_mutex); + /* + * All the parts of the compound chain belong obtained credits from the + * same session (see the appropriate checks above). In the same time + * there might be reconnects after those checks but before we acquired + * the srv_mutex. We can not use credits obtained from the previous + * session to send this request. Check if there were reconnects after + * we obtained credits and return -EAGAIN in such cases to let callers + * handle it. + */ + if (first_instance != ses->server->reconnect_instance) { + mutex_unlock(&ses->server->srv_mutex); + for (j = 0; j < num_rqst; j++) + add_credits(ses->server, &credits[j], optype); + return -EAGAIN; + } + for (i = 0; i < num_rqst; i++) { midQ[i] = ses->server->ops->setup_request(ses, &rqst[i]); if (IS_ERR(midQ[i])) {