From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 502F6C65BAE for ; Thu, 13 Dec 2018 04:31:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0787F20880 for ; Thu, 13 Dec 2018 04:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544675479; bh=FxkpqWoTuJX9diGQLF44vV72exKIZ56+MI4NWgcTSxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Cy0Ts+YvCDEwnqabyuZiE1SYaYihs7+ql7uakbH9zAlnghPAoHvAYUxgWoVfpF3Ho SIuxhkzx/XXxh8u5CL7crI/G2n52VUlmofZUj4KN2eGV9OmQwjqkyrpHgGRpG8a3LN PivjW5XSR2AY8Xj18x+bnGYS7d1BXWvNAhrYrXHU= DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0787F20880 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728695AbeLMEbR (ORCPT ); Wed, 12 Dec 2018 23:31:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:44048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728629AbeLMEbN (ORCPT ); Wed, 12 Dec 2018 23:31:13 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C474620879; Thu, 13 Dec 2018 04:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544675472; bh=FxkpqWoTuJX9diGQLF44vV72exKIZ56+MI4NWgcTSxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C50amsKonGYIMPTf6PpRrcCh0X9mSjlWQUtYDTlEDivauaJI5zRidYxvB8fSvK1iM w+uA7z4z++vItv6h9zvFLfLUNC0hWiOjdKNJhoGjPFaeabu9e5Z9tlP3VEbH8rIti2 +0sO27QlBAPwg3StB73B//b5E8OljgfydREg0c4U= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Trond Myklebust , Sasha Levin , linux-nfs@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 12/41] SUNRPC: Fix a potential race in xprt_connect() Date: Wed, 12 Dec 2018 23:30:25 -0500 Message-Id: <20181213043054.75891-12-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181213043054.75891-1-sashal@kernel.org> References: <20181213043054.75891-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust [ Upstream commit 0a9a4304f3614e25d9de9b63502ca633c01c0d70 ] If an asynchronous connection attempt completes while another task is in xprt_connect(), then the call to rpc_sleep_on() could end up racing with the call to xprt_wake_pending_tasks(). So add a second test of the connection state after we've put the task to sleep and set the XPRT_CONNECTING flag, when we know that there can be no asynchronous connection attempts still in progress. Fixes: 0b9e79431377d ("SUNRPC: Move the test for XPRT_CONNECTING into...") Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- net/sunrpc/xprt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 8eb0c4f3b3e9..d0282cc88b14 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -780,8 +780,15 @@ void xprt_connect(struct rpc_task *task) return; if (xprt_test_and_set_connecting(xprt)) return; - xprt->stat.connect_start = jiffies; - xprt->ops->connect(xprt, task); + /* Race breaker */ + if (!xprt_connected(xprt)) { + xprt->stat.connect_start = jiffies; + xprt->ops->connect(xprt, task); + } else { + xprt_clear_connecting(xprt); + task->tk_status = 0; + rpc_wake_up_queued_task(&xprt->pending, task); + } } xprt_release_write(xprt, task); } -- 2.19.1