Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp1570196pjr; Mon, 18 May 2020 16:41:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCKLAIiIiqG5wStbxJ1XWBKL+as16IZhj0uHrUUNNVXBFI35qhXIVXeuMPBCyG6sXxlsCQ X-Received: by 2002:a50:cdd8:: with SMTP id h24mr15424656edj.260.1589845261748; Mon, 18 May 2020 16:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589845261; cv=none; d=google.com; s=arc-20160816; b=jjCnU0cubDq7LXdM9O8uRnQosjf1R0P2BjxFne0K0ovXVCpH34vDv6B9v1PaXtWBlQ eO/ITFeopwk09H0PWO1ig0OHvLQyf87wD0NszvhJSs8cyHhGobc/NEr0zfwGAlqjtNs3 NjUpWLZHSUt2d+c31Y7aPWfnpK7CS8ePQDhcTOJaJHwNV4mo5Iz6/Gmyju4mQqACMehs 0ZuSpuYAVOrI0mHUcILIwtzQp74eibBM4O37Arv7d/psp5MP/emZlVXuBXFZA4pWnWbl w7v7ccUtl6NuyXehrkLBqwRRdcM/iAatmUbqMao+wBBtMpbxh/vDqNlF9Px82nsKJkK8 o6jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZD8XKxUW7T0AtQ6IBdEq1EHgNHN4mtDfpArkcMacleM=; b=OxpXdIgGughPESIFveiSv7hNfJeQzPCarAX1x8b730VMWCUYoLZuffesFxdzFQX5zz rCYOihNeuZOfCyVR2BVOvM5M1xvMDQ+18oEznmsu6aApkJl2sZoyqU04jttljf6ljd6O yBpGQygCkTdohJT4HIw3j5BZ2gR9Z76S3EO8QrE0EY836GPRV9HdHNo8yNlj1JT+BGNa FsTgXrW/oxU45dwqiQPNxglEnUu4yDxQUmarWpZpDSVN103ez3PDUHJkLmlnVE+vBJvp qWNdgtK2myl20XiL0EPqC8HKA1gim9tnKPh9LqcipOdx0xWZwukWLuXrx8ivz2S+xvEK f1uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nYJpCFq8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n8si8052456ejl.78.2020.05.18.16.40.39; Mon, 18 May 2020 16:41:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nYJpCFq8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729614AbgERRnl (ORCPT + 99 others); Mon, 18 May 2020 13:43:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:41332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729604AbgERRng (ORCPT ); Mon, 18 May 2020 13:43:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 89B0920849; Mon, 18 May 2020 17:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589823816; bh=bd0Z/Xy/yKAVxb3vsoj/gDqfJK1l6k8boULgRIH4QG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYJpCFq8td3QcVED04wANDOAPeMp9DR1cnVrxXF3/Zf8iHMbDWt5NzTWtPNnf4cir 8CoQK3TPidP6uWrneEMn5V/jIV7nYqgBV+DdchRVwCXluAYyA7bfbhNsPTyW0XTbzz bC1rIwU/ONVxCZwq3KnbxLjnvT3ES+9KI7v5UpCg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Cabrero , =?UTF-8?q?Aur=C3=A9lien=20Aptel?= , Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 4.9 47/90] cifs: Check for timeout on Negotiate stage Date: Mon, 18 May 2020 19:36:25 +0200 Message-Id: <20200518173500.787954575@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173450.930655662@linuxfoundation.org> References: <20200518173450.930655662@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Samuel Cabrero [ Upstream commit 76e752701a8af4404bbd9c45723f7cbd6e4a251e ] Some servers seem to accept connections while booting but never send the SMBNegotiate response neither close the connection, causing all processes accessing the share hang on uninterruptible sleep state. This happens when the cifs_demultiplex_thread detects the server is unresponsive so releases the socket and start trying to reconnect. At some point, the faulty server will accept the socket and the TCP status will be set to NeedNegotiate. The first issued command accessing the share will start the negotiation (pid 5828 below), but the response will never arrive so other commands will be blocked waiting on the mutex (pid 55352). This patch checks for unresponsive servers also on the negotiate stage releasing the socket and reconnecting if the response is not received and checking again the tcp state when the mutex is acquired. PID: 55352 TASK: ffff880fd6cc02c0 CPU: 0 COMMAND: "ls" #0 [ffff880fd9add9f0] schedule at ffffffff81467eb9 #1 [ffff880fd9addb38] __mutex_lock_slowpath at ffffffff81468fe0 #2 [ffff880fd9addba8] mutex_lock at ffffffff81468b1a #3 [ffff880fd9addbc0] cifs_reconnect_tcon at ffffffffa042f905 [cifs] #4 [ffff880fd9addc60] smb_init at ffffffffa042faeb [cifs] #5 [ffff880fd9addca0] CIFSSMBQPathInfo at ffffffffa04360b5 [cifs] .... Which is waiting a mutex owned by: PID: 5828 TASK: ffff880fcc55e400 CPU: 0 COMMAND: "xxxx" #0 [ffff880fbfdc19b8] schedule at ffffffff81467eb9 #1 [ffff880fbfdc1b00] wait_for_response at ffffffffa044f96d [cifs] #2 [ffff880fbfdc1b60] SendReceive at ffffffffa04505ce [cifs] #3 [ffff880fbfdc1bb0] CIFSSMBNegotiate at ffffffffa0438d79 [cifs] #4 [ffff880fbfdc1c50] cifs_negotiate_protocol at ffffffffa043b383 [cifs] #5 [ffff880fbfdc1c80] cifs_reconnect_tcon at ffffffffa042f911 [cifs] #6 [ffff880fbfdc1d20] smb_init at ffffffffa042faeb [cifs] #7 [ffff880fbfdc1d60] CIFSSMBQFSInfo at ffffffffa0434eb0 [cifs] .... Signed-off-by: Samuel Cabrero Reviewed-by: Aurélien Aptel Reviewed-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/cifssmb.c | 12 ++++++++++++ fs/cifs/connect.c | 3 ++- fs/cifs/smb2pdu.c | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 741b83c59a306..568abcd6d0dd3 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -184,6 +184,18 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) * reconnect the same SMB session */ mutex_lock(&ses->session_mutex); + + /* + * Recheck after acquire mutex. If another thread is negotiating + * and the server never sends an answer the socket will be closed + * and tcpStatus set to reconnect. + */ + if (server->tcpStatus == CifsNeedReconnect) { + rc = -EHOSTDOWN; + mutex_unlock(&ses->session_mutex); + goto out; + } + rc = cifs_negotiate_protocol(0, ses); if (rc == 0 && ses->need_reconnect) rc = cifs_setup_session(0, ses, nls_codepage); diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index c018d161735c4..37c8cac86431f 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -561,7 +561,8 @@ server_unresponsive(struct TCP_Server_Info *server) * 65s kernel_recvmsg times out, and we see that we haven't gotten * a response in >60s. */ - if (server->tcpStatus == CifsGood && + if ((server->tcpStatus == CifsGood || + server->tcpStatus == CifsNeedNegotiate) && time_after(jiffies, server->lstrp + 2 * server->echo_interval)) { cifs_dbg(VFS, "Server %s has not responded in %lu seconds. Reconnecting...\n", server->hostname, (2 * server->echo_interval) / HZ); diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index e8dc28dbe563e..0a23b6002ff12 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -246,6 +246,18 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon) * the same SMB session */ mutex_lock(&tcon->ses->session_mutex); + + /* + * Recheck after acquire mutex. If another thread is negotiating + * and the server never sends an answer the socket will be closed + * and tcpStatus set to reconnect. + */ + if (server->tcpStatus == CifsNeedReconnect) { + rc = -EHOSTDOWN; + mutex_unlock(&tcon->ses->session_mutex); + goto out; + } + rc = cifs_negotiate_protocol(0, tcon->ses); if (!rc && tcon->ses->need_reconnect) { rc = cifs_setup_session(0, tcon->ses, nls_codepage); -- 2.20.1