Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1552944pxb; Thu, 16 Sep 2021 09:46:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJe0i0FjjO3QSHPzfBYcDf89NHbCFqeny3o9c1676p6KdCaoRACN3hVMmq3azwNY6P8oos X-Received: by 2002:a17:906:a04f:: with SMTP id bg15mr7548306ejb.417.1631810784029; Thu, 16 Sep 2021 09:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631810784; cv=none; d=google.com; s=arc-20160816; b=JJ70/t4meg7qliCXgq7C4o1nzUsdHQlC3lbUwVltvzyIjZAtKkLaMD3YOCAdpcnWvq s1ovm8ySj4jX6NaZsV6bV3+pBzOp4YRa7X/JMSgcdM53F2+P/F4CfiPPnQMRZHblooX7 vNJTZoQQpiCmeudMIW35Al5ZqOQUgVGwFH0OZEplCnz0CkdmMy3pOnFCiTfbsMGZ6QvR 4U5yiKt4gpsJVDeJj1xRPmsdT8kMKTGynfwlIF34RvVGBQY/xb8nd7+6vn3pHRvpxE9E 6gO7MapUZbsluZ//wWRjxOfjXRcsVb0pWqpQSCRPOp6GXp+iwulresK1Ku4PbCMZbwfg f9Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vTU9JLgneLx/Do3pVEIbkXi2xYoUeJ8DC0lRZOP1mp0=; b=UdBPVZlP1OT8jcEAZ7ERbTze1rm+cnqH1jjQS8ZwAYqXXfmHlI/hiEuZb9R038zCO/ GAFVf3Ljf6J/BNIjXWkCooM7S+JI6yov/LMa/XKjmBJGqHi7uphYkXlgw63XhLOyR6Qg aQvjajMm9M+tp+g1iUPyMv68u8vtQYPahlKY8Y9IRpGet9Xk9IlhqysCT7zKlRf3TK+v 7LBDX2Nxjjs012UajjirU+giyT7lofQVADGpuCadP3fLtybu8W7x+SnUE0mM2D9rZYX/ 1Wm7pRbiUZCxQlRXWQoATrDJXONMliMQtmoh7TIVY5DHQparV74M74xkazZHtWNFEprS 9xcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LT5Xk+wR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si4490943ejl.772.2021.09.16.09.45.55; Thu, 16 Sep 2021 09:46:24 -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=@linuxfoundation.org header.s=korg header.b=LT5Xk+wR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245694AbhIPQmF (ORCPT + 99 others); Thu, 16 Sep 2021 12:42:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:44898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242383AbhIPQf2 (ORCPT ); Thu, 16 Sep 2021 12:35:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8304F619E5; Thu, 16 Sep 2021 16:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809285; bh=5uWLQIGjypxunhfDBSoc978te0fgAKCKAPXtNb+PCdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LT5Xk+wR708p43QCsJncuPitRwm6lNARZZA4B5TT4wCugNbe8Eif4hrJAinRL66Bg r9SGC+7BfBOhCA8qSHm2OUbmHnwt5RQ0IeX9PGqyCeGR5OUlr5vXdeZ3DWEN3XM4bR cQHOp4dbMgVq2NFVTPF3CxTfaEjykzW8RLit3Ib4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Anna Schumaker , Sasha Levin Subject: [PATCH 5.13 098/380] SUNRPC/xprtrdma: Fix reconnection locking Date: Thu, 16 Sep 2021 17:57:35 +0200 Message-Id: <20210916155807.361980100@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust [ Upstream commit f99fa50880f5300fbbb3c0754ddc7f8738d24fe7 ] The xprtrdma client code currently relies on the task that initiated the connect to hold the XPRT_LOCK for the duration of the connection attempt. If the task is woken early, due to some other event, then that lock could get released early. Avoid races by using the same mechanism that the socket code uses of transferring lock ownership to the RDMA connect worker itself. That frees us to call rpcrdma_xprt_disconnect() directly since we're now guaranteed exclusion w.r.t. other callers. Fixes: 4cf44be6f1e8 ("xprtrdma: Fix recursion into rpcrdma_xprt_disconnect()") Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- net/sunrpc/xprt.c | 2 ++ net/sunrpc/xprtrdma/transport.c | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 19fa8616b8cf..8d3983c8b4d6 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -872,6 +872,7 @@ bool xprt_lock_connect(struct rpc_xprt *xprt, spin_unlock(&xprt->transport_lock); return ret; } +EXPORT_SYMBOL_GPL(xprt_lock_connect); void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie) { @@ -888,6 +889,7 @@ void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie) spin_unlock(&xprt->transport_lock); wake_up_bit(&xprt->state, XPRT_LOCKED); } +EXPORT_SYMBOL_GPL(xprt_unlock_connect); /** * xprt_connect - schedule a transport connect operation diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index 19a49d26b1e4..d2052f06acfa 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c @@ -249,12 +249,9 @@ xprt_rdma_connect_worker(struct work_struct *work) xprt->stat.connect_start; xprt_set_connected(xprt); rc = -EAGAIN; - } else { - /* Force a call to xprt_rdma_close to clean up */ - spin_lock(&xprt->transport_lock); - set_bit(XPRT_CLOSE_WAIT, &xprt->state); - spin_unlock(&xprt->transport_lock); - } + } else + rpcrdma_xprt_disconnect(r_xprt); + xprt_unlock_connect(xprt, r_xprt); xprt_wake_pending_tasks(xprt, rc); } @@ -487,6 +484,8 @@ xprt_rdma_connect(struct rpc_xprt *xprt, struct rpc_task *task) struct rpcrdma_ep *ep = r_xprt->rx_ep; unsigned long delay; + WARN_ON_ONCE(!xprt_lock_connect(xprt, task, r_xprt)); + delay = 0; if (ep && ep->re_connect_status != 0) { delay = xprt_reconnect_delay(xprt); -- 2.30.2