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: 1030191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XYMRjZGn"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43lHyV1Sm8z9s55 for ; Thu, 24 Jan 2019 08:11:14 +1100 (AEDT) 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 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])) {