From patchwork Mon Jun 15 13:20:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever III X-Patchwork-Id: 11604961 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 895DC912 for ; Mon, 15 Jun 2020 13:20:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7208C207DA for ; Mon, 15 Jun 2020 13:20:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QlnV63ze" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730434AbgFONUy (ORCPT ); Mon, 15 Jun 2020 09:20:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729916AbgFONUx (ORCPT ); Mon, 15 Jun 2020 09:20:53 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F09BC061A0E; Mon, 15 Jun 2020 06:20:53 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id r2so17805923ioo.4; Mon, 15 Jun 2020 06:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=ZlaCqm28R2FksyPTvJwuLIvLy4AIg5LN7n2O1w/Bits=; b=QlnV63zeug6pQnYg6vnoJzPm0y8E//o6KVERapQG68Of08elRjV7wObp0IuV73bnVg jXRmV8O1g9SrvgF0lnQX0A/YA2qNGTD/DwmIYFQt3AUh01WjxKWzkRonUMQdOEQsiiY/ PMmJzmA03iNO8265V2wsAEDWUfZbsWwHqwU6Qdh+F9by/dmI/b2HXxVvDchrDOh5PScR vvp2iQxOkAB7SZw3HQRjnNUFshGwA0ifi/b8DRaMJNARVOSFvGBkGe03uVZmH2kUp4id ClJpq4VfmUbGhIzgfpt2+d2F4VydF/6qc02R9v9S7HVeJsyrV67ik1EMpxz19gtNrasm 9EXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=ZlaCqm28R2FksyPTvJwuLIvLy4AIg5LN7n2O1w/Bits=; b=UTYWAhfOC1jufNRHpC3fusIP8ewlCO/Fpv2AyE0A9GjjGO8SIkQSklZhQ8suwKijvT UUu9ud/hhRy5yAidLvEgPw6a/wDdnhrK7fQ8LHocO7pWefdGnFl/xIVH0h3boGZhU9P5 tQ7HJnzr052Pcn5Aypn0UkCuE/UsWIACC9w5/h+y3oiQfG3Dwou3WwRRhFw5l0ogSN5O jNaODu6ywaoOg0mewj//AADN96v2HVUK4rUOsCEwF7DLNI02jFtR5YruJB5tntJ83x7H M6LiLoHlFNVzjOd+wvTskiOSR0Q5+zoYxAy+E2Buz19b2+GseQxWqFLyf5XzMAYWHwIf GjkA== X-Gm-Message-State: AOAM533t1ThWgqoO9X5abGZrAtVg3Urw5KJljHEBlPDGkbiAp0CxS73F gJ5PzE/RWFVncz7hyyMZcsM= X-Google-Smtp-Source: ABdhPJxMolEMSQ+i7ojEJX7CQ587h0J4op1u5R/b8FTxtIP9Fz0svZnPVUwQ0XgfUkAxxsRYJ9HFRg== X-Received: by 2002:a05:6602:140b:: with SMTP id t11mr27484929iov.198.1592227252968; Mon, 15 Jun 2020 06:20:52 -0700 (PDT) Received: from gateway.1015granger.net (c-68-61-232-219.hsd1.mi.comcast.net. [68.61.232.219]) by smtp.gmail.com with ESMTPSA id f22sm7967055iob.18.2020.06.15.06.20.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 06:20:52 -0700 (PDT) Received: from manet.1015granger.net (manet.1015granger.net [192.168.1.51]) by gateway.1015granger.net (8.14.7/8.14.7) with ESMTP id 05FDKqaN018432; Mon, 15 Jun 2020 13:20:52 GMT Subject: [PATCH v1 1/5] xprtrdma: Prevent dereferencing r_xprt->rx_ep after it is freed From: Chuck Lever To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org Date: Mon, 15 Jun 2020 09:20:52 -0400 Message-ID: <20200615132052.11800.40928.stgit@manet.1015granger.net> In-Reply-To: <20200615131642.11800.27486.stgit@manet.1015granger.net> References: <20200615131642.11800.27486.stgit@manet.1015granger.net> User-Agent: StGit/0.22-38-gfb18 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org r_xprt->rx_ep is known to be good while the transport's send lock is held. Otherwise additional references on rx_ep must be held when it is used outside of that lock's critical sections. For now, bump the rx_ep reference count once whenever there is at least one outstanding Receive WR. This avoids the memory bandwidth overhead of taking and releasing the reference count for every ib_post_recv() and Receive completion. Signed-off-by: Chuck Lever --- net/sunrpc/xprtrdma/verbs.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 2ae348377806..b021baa4b28d 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -84,7 +84,8 @@ static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep); static void rpcrdma_reps_unmap(struct rpcrdma_xprt *r_xprt); static void rpcrdma_mrs_create(struct rpcrdma_xprt *r_xprt); static void rpcrdma_mrs_destroy(struct rpcrdma_xprt *r_xprt); -static int rpcrdma_ep_destroy(struct rpcrdma_ep *ep); +static void rpcrdma_ep_get(struct rpcrdma_ep *ep); +static int rpcrdma_ep_put(struct rpcrdma_ep *ep); static struct rpcrdma_regbuf * rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction, gfp_t flags); @@ -97,7 +98,8 @@ static void rpcrdma_regbuf_free(struct rpcrdma_regbuf *rb); */ static void rpcrdma_xprt_drain(struct rpcrdma_xprt *r_xprt) { - struct rdma_cm_id *id = r_xprt->rx_ep->re_id; + struct rpcrdma_ep *ep = r_xprt->rx_ep; + struct rdma_cm_id *id = ep->re_id; /* Flush Receives, then wait for deferred Reply work * to complete. @@ -108,6 +110,8 @@ static void rpcrdma_xprt_drain(struct rpcrdma_xprt *r_xprt) * local invalidations. */ ib_drain_sq(id->qp); + + rpcrdma_ep_put(ep); } /** @@ -266,7 +270,7 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) xprt_force_disconnect(xprt); goto disconnected; case RDMA_CM_EVENT_ESTABLISHED: - kref_get(&ep->re_kref); + rpcrdma_ep_get(ep); ep->re_connect_status = 1; rpcrdma_update_cm_private(ep, &event->param.conn); trace_xprtrdma_inline_thresh(ep); @@ -289,7 +293,7 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) ep->re_connect_status = -ECONNABORTED; disconnected: xprt_force_disconnect(xprt); - return rpcrdma_ep_destroy(ep); + return rpcrdma_ep_put(ep); default: break; } @@ -345,7 +349,7 @@ static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt, return ERR_PTR(rc); } -static void rpcrdma_ep_put(struct kref *kref) +static void rpcrdma_ep_destroy(struct kref *kref) { struct rpcrdma_ep *ep = container_of(kref, struct rpcrdma_ep, re_kref); @@ -369,13 +373,18 @@ static void rpcrdma_ep_put(struct kref *kref) module_put(THIS_MODULE); } +static noinline void rpcrdma_ep_get(struct rpcrdma_ep *ep) +{ + kref_get(&ep->re_kref); +} + /* Returns: * %0 if @ep still has a positive kref count, or * %1 if @ep was destroyed successfully. */ -static int rpcrdma_ep_destroy(struct rpcrdma_ep *ep) +static noinline int rpcrdma_ep_put(struct rpcrdma_ep *ep) { - return kref_put(&ep->re_kref, rpcrdma_ep_put); + return kref_put(&ep->re_kref, rpcrdma_ep_destroy); } static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) @@ -492,7 +501,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) return 0; out_destroy: - rpcrdma_ep_destroy(ep); + rpcrdma_ep_put(ep); rdma_destroy_id(id); out_free: kfree(ep); @@ -521,8 +530,12 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt) ep->re_connect_status = 0; xprt_clear_connected(xprt); - rpcrdma_reset_cwnd(r_xprt); + + /* Bump the ep's reference count while there are + * outstanding Receives. + */ + rpcrdma_ep_get(ep); rpcrdma_post_recvs(r_xprt, true); rc = rpcrdma_sendctxs_create(r_xprt); @@ -587,7 +600,7 @@ void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt) rpcrdma_mrs_destroy(r_xprt); rpcrdma_sendctxs_destroy(r_xprt); - if (rpcrdma_ep_destroy(ep)) + if (rpcrdma_ep_put(ep)) rdma_destroy_id(id); r_xprt->rx_ep = NULL; From patchwork Mon Jun 15 13:20:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever III X-Patchwork-Id: 11604965 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1096790 for ; Mon, 15 Jun 2020 13:21:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBF1C207DA for ; Mon, 15 Jun 2020 13:20:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fd1CBEFv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730150AbgFONU7 (ORCPT ); Mon, 15 Jun 2020 09:20:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729916AbgFONU6 (ORCPT ); Mon, 15 Jun 2020 09:20:58 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D495DC061A0E; Mon, 15 Jun 2020 06:20:58 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id m81so17781192ioa.1; Mon, 15 Jun 2020 06:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=UgNi9mQzpoWUcbq2gN4k8yjQNoDX3PMgf0ODBpMXze0=; b=fd1CBEFvbwGcP+d4GOrza+cMnPE/htZ3fcXH+VfDecEAavjRP6FIJap4rCb/+JASyh jf0t7xUivAdLedXNuo9poI4P0Tz7g3RgbxHxq+bCDFfgOI4LQqc2tRUch0C50n28V1tK 4j/quPOtcrU5aSxCQMSo49bbHmbGckAagy6C7ROjra0a1H1Wr7KUN02mEJ8o1N60PJBs 72MbDiDUKIq2JOpGc8IBh8lIlJIRhHWAvnscC/1Tc1g1z4fUZB2EZjGqwmtOLur+ZWup X3hkVj5JDwikXJrKWsYzwp+Q1ZdJEQFtMRtc4PkbZqpEdgmVywTQbWZOm2MvQCx5CwU/ 1p8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=UgNi9mQzpoWUcbq2gN4k8yjQNoDX3PMgf0ODBpMXze0=; b=mEqzFf0fVZQ75CJleMKVNrMJ7oouEfcWqNmda+XGnTUm2ztv7CdOePjRANAGFMmmeJ aMHbnllNV6kwtGSbZcgNqC77mgcDRDRBojJH67UnR94bKLm3i8QuxqOoGX78saNN14zM 6M1oKraTVzc/kBrkJ9sYyT97FDbxJnu3i2wKzt0Tid5co5dGApYHFtnAOXaoyQjXZJAX Knfop0vC4dN1qiO+7WZFbbOtpOnfulB4HmH8nxVlexPlgMvSrUSw7c28s/Vkegtv3KPp uLAVZLkmtUo/EyqfrPEGW1F1bGF3ZHI1zjzMTUOC8EkeXZK0I1hSFYzr7UEoPfTbGwTn zvDg== X-Gm-Message-State: AOAM532dIL8/nIMd8i78bIcEf80pcH6kSeu8JHoy9Rq/Y+8w9eHGEL7u +2p3srQdQj6fE+B7xTY5tZXO4Ekn X-Google-Smtp-Source: ABdhPJx/ZLNPjG3ncn4a+kvB1SZfzLX4T7CJCVR3DZul+F7PIJ4W4pwifpaEqY1QdC72HahgPx/dbg== X-Received: by 2002:a6b:b984:: with SMTP id j126mr6171303iof.114.1592227258285; Mon, 15 Jun 2020 06:20:58 -0700 (PDT) Received: from gateway.1015granger.net (c-68-61-232-219.hsd1.mi.comcast.net. [68.61.232.219]) by smtp.gmail.com with ESMTPSA id y2sm7900675ilg.69.2020.06.15.06.20.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 06:20:57 -0700 (PDT) Received: from manet.1015granger.net (manet.1015granger.net [192.168.1.51]) by gateway.1015granger.net (8.14.7/8.14.7) with ESMTP id 05FDKvSf018435; Mon, 15 Jun 2020 13:20:57 GMT Subject: [PATCH v1 2/5] xprtrdma: Use re_connect_status safely in rpcrdma_xprt_connect() From: Chuck Lever To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org Date: Mon, 15 Jun 2020 09:20:57 -0400 Message-ID: <20200615132057.11800.5582.stgit@manet.1015granger.net> In-Reply-To: <20200615131642.11800.27486.stgit@manet.1015granger.net> References: <20200615131642.11800.27486.stgit@manet.1015granger.net> User-Agent: StGit/0.22-38-gfb18 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Clean up: Sometimes creating a fresh rpcrdma_ep can fail. That's why xprt_rdma_connect() always checks if the r_xprt->rx_ep pointer is valid before dereferencing it. Instead, xprt_rdma_connect() can simply check rpcrdma_xprt_connect()'s return value. Also, there's no need to set re_connect_status to zero just after the rpcrdma_ep is created, since it is allocated with kzalloc. Signed-off-by: Chuck Lever --- net/sunrpc/xprtrdma/transport.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index 048c2fd85728..243aa6dd74af 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c @@ -242,7 +242,7 @@ xprt_rdma_connect_worker(struct work_struct *work) rc = rpcrdma_xprt_connect(r_xprt); xprt_clear_connecting(xprt); - if (r_xprt->rx_ep && r_xprt->rx_ep->re_connect_status > 0) { + if (!rc) { xprt->connect_cookie++; xprt->stat.connect_count++; xprt->stat.connect_time += (long)jiffies - diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index b021baa4b28d..b172e43cb204 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -528,7 +528,6 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt) return rc; ep = r_xprt->rx_ep; - ep->re_connect_status = 0; xprt_clear_connected(xprt); rpcrdma_reset_cwnd(r_xprt); @@ -565,8 +564,6 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt) rpcrdma_mrs_create(r_xprt); out: - if (rc) - ep->re_connect_status = rc; trace_xprtrdma_connect(r_xprt, rc); return rc; } From patchwork Mon Jun 15 13:21:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever III X-Patchwork-Id: 11604971 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A669912 for ; Mon, 15 Jun 2020 13:21:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82880207BB for ; Mon, 15 Jun 2020 13:21:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NW+9OE/U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730305AbgFONVF (ORCPT ); Mon, 15 Jun 2020 09:21:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729916AbgFONVE (ORCPT ); Mon, 15 Jun 2020 09:21:04 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CEB9C061A0E; Mon, 15 Jun 2020 06:21:04 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id o5so17729420iow.8; Mon, 15 Jun 2020 06:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=HizMT9Lgi2Uu04lsSCxN6oFeFJPre5YnAUaTvLWnAk8=; b=NW+9OE/UvSrmnchJI1tXUu8VBYi22WZTSDJdro29qRNoAXD3spMviMIqiI7av4Elij V2VqE645V+jQjkZqFYkvZfylspdkG78ARnP6z839mtFs7+RfHPAQ46ztaR4t3r2A907J zsaaAmjd10zGrAEf+XHKjny65MwyMOLF8+Vup54UVEhKmnvyappWs9zBsWolq1pVMlWD 8XSFCSGpclgAqrJcazC1igTmdjtuhrytNJ/aEmf/YEchxPzxlfAY3L6ornJSKI0f6I2U OMsXe5vdWrMusxnXsugnw3610uCWm8sTmWUX0GAxTx7UtCpK7t+u0vpbgN+BtGtI3+gl L16w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=HizMT9Lgi2Uu04lsSCxN6oFeFJPre5YnAUaTvLWnAk8=; b=cTQj8Uf18Qsh6gjruXYQTwAMBMkjt2DdiyquoS8+4aF7e+DOuPWQioTqW9v6ozcvVd aQsWtGHLJtF4TWo8yUUZaXN7yKHu2ml3ZXwdzd+Ov+DSKkl6n4y+8V/0iVevZbxxt5ah c+XNtr3B4Rh+C+xpSgpHCzcfgs9w3r/pi2nwo6EubFXQDRHZ733Q87uzM4lLvglqBxc4 70dJ0NCU2drwVu1qNGFZ3E0F5yXFnZ78+Rw2B7VrhfwPB9AieqJDnzpLeGF28LGO73D7 A73yNyaHPeHZiXe35Et4lwC1PT5Gzkdmc+bbqNmkYhFQcKIif53RZwOZAQgMK1ypD61w T6YA== X-Gm-Message-State: AOAM530icsDs9qBSEJBUQc28UJi9SY5XWyShrmQP5Yh1YabkHevP4m2C mINcNHEdjyc3Lcm1CWoRI6PNuJzQ X-Google-Smtp-Source: ABdhPJwAhoIyPEp3u021VwWKU+Ej0+Vq4o0cmuvYlirrHv1toB1GVQ7Vv7oQyY0fYJPTX0Pjowt8Sg== X-Received: by 2002:a5e:8e47:: with SMTP id r7mr27640479ioo.204.1592227263879; Mon, 15 Jun 2020 06:21:03 -0700 (PDT) Received: from gateway.1015granger.net (c-68-61-232-219.hsd1.mi.comcast.net. [68.61.232.219]) by smtp.gmail.com with ESMTPSA id b8sm8001924ior.35.2020.06.15.06.21.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 06:21:03 -0700 (PDT) Received: from manet.1015granger.net (manet.1015granger.net [192.168.1.51]) by gateway.1015granger.net (8.14.7/8.14.7) with ESMTP id 05FDL25O018438; Mon, 15 Jun 2020 13:21:02 GMT Subject: [PATCH v1 3/5] xprtrdma: Clean up synopsis of rpcrdma_flush_disconnect() From: Chuck Lever To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org Date: Mon, 15 Jun 2020 09:21:02 -0400 Message-ID: <20200615132102.11800.39700.stgit@manet.1015granger.net> In-Reply-To: <20200615131642.11800.27486.stgit@manet.1015granger.net> References: <20200615131642.11800.27486.stgit@manet.1015granger.net> User-Agent: StGit/0.22-38-gfb18 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Refactor: Pass struct rpcrdma_xprt instead of an IB layer object. Signed-off-by: Chuck Lever --- net/sunrpc/xprtrdma/frwr_ops.c | 8 ++++---- net/sunrpc/xprtrdma/verbs.c | 12 ++++++------ net/sunrpc/xprtrdma/xprt_rdma.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/net/sunrpc/xprtrdma/frwr_ops.c b/net/sunrpc/xprtrdma/frwr_ops.c index ef997880e17a..b647562a26dd 100644 --- a/net/sunrpc/xprtrdma/frwr_ops.c +++ b/net/sunrpc/xprtrdma/frwr_ops.c @@ -367,7 +367,7 @@ static void frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc) trace_xprtrdma_wc_fastreg(wc, frwr); /* The MR will get recycled when the associated req is retransmitted */ - rpcrdma_flush_disconnect(cq, wc); + rpcrdma_flush_disconnect(cq->cq_context, wc); } /** @@ -452,7 +452,7 @@ static void frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc) trace_xprtrdma_wc_li(wc, frwr); __frwr_release_mr(wc, mr); - rpcrdma_flush_disconnect(cq, wc); + rpcrdma_flush_disconnect(cq->cq_context, wc); } /** @@ -474,7 +474,7 @@ static void frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc) __frwr_release_mr(wc, mr); complete(&frwr->fr_linv_done); - rpcrdma_flush_disconnect(cq, wc); + rpcrdma_flush_disconnect(cq->cq_context, wc); } /** @@ -582,7 +582,7 @@ static void frwr_wc_localinv_done(struct ib_cq *cq, struct ib_wc *wc) smp_rmb(); rpcrdma_complete_rqst(rep); - rpcrdma_flush_disconnect(cq, wc); + rpcrdma_flush_disconnect(cq->cq_context, wc); } /** diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index b172e43cb204..7a112612fc8f 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -132,14 +132,13 @@ static void rpcrdma_qp_event_handler(struct ib_event *event, void *context) /** * rpcrdma_flush_disconnect - Disconnect on flushed completion - * @cq: completion queue + * @r_xprt: transport to disconnect * @wc: work completion entry * * Must be called in process context. */ -void rpcrdma_flush_disconnect(struct ib_cq *cq, struct ib_wc *wc) +void rpcrdma_flush_disconnect(struct rpcrdma_xprt *r_xprt, struct ib_wc *wc) { - struct rpcrdma_xprt *r_xprt = cq->cq_context; struct rpc_xprt *xprt = &r_xprt->rx_xprt; if (wc->status != IB_WC_SUCCESS && @@ -160,11 +159,12 @@ static void rpcrdma_wc_send(struct ib_cq *cq, struct ib_wc *wc) struct ib_cqe *cqe = wc->wr_cqe; struct rpcrdma_sendctx *sc = container_of(cqe, struct rpcrdma_sendctx, sc_cqe); + struct rpcrdma_xprt *r_xprt = cq->cq_context; /* WARNING: Only wr_cqe and status are reliable at this point */ trace_xprtrdma_wc_send(sc, wc); - rpcrdma_sendctx_put_locked((struct rpcrdma_xprt *)cq->cq_context, sc); - rpcrdma_flush_disconnect(cq, wc); + rpcrdma_sendctx_put_locked(r_xprt, sc); + rpcrdma_flush_disconnect(r_xprt, wc); } /** @@ -199,7 +199,7 @@ static void rpcrdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc) return; out_flushed: - rpcrdma_flush_disconnect(cq, wc); + rpcrdma_flush_disconnect(r_xprt, wc); rpcrdma_rep_destroy(rep); } diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h index 0a16fdb09b2c..098d05a62ead 100644 --- a/net/sunrpc/xprtrdma/xprt_rdma.h +++ b/net/sunrpc/xprtrdma/xprt_rdma.h @@ -446,7 +446,7 @@ extern unsigned int xprt_rdma_memreg_strategy; /* * Endpoint calls - xprtrdma/verbs.c */ -void rpcrdma_flush_disconnect(struct ib_cq *cq, struct ib_wc *wc); +void rpcrdma_flush_disconnect(struct rpcrdma_xprt *r_xprt, struct ib_wc *wc); int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt); void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt); From patchwork Mon Jun 15 13:21:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever III X-Patchwork-Id: 11604975 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D270D912 for ; Mon, 15 Jun 2020 13:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA188207BB for ; Mon, 15 Jun 2020 13:21:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g0ybEJW4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730043AbgFONVL (ORCPT ); Mon, 15 Jun 2020 09:21:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729916AbgFONVK (ORCPT ); Mon, 15 Jun 2020 09:21:10 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C5ABC061A0E; Mon, 15 Jun 2020 06:21:09 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id x189so8685603iof.9; Mon, 15 Jun 2020 06:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=SGsil05SR5HyEHxBqow0AuD9rbhVsw4TLPg5c/VcqZw=; b=g0ybEJW4V18N3WdbeKPGuiCzBGFUnIhO34bjpwDKfrTYCPoRmzr2ckTOxH72t4dnzw fAqqme3xzKSL8SX4Park350Lambi2PP2H4jHlGV6Zu7D/o2i25Rf8QmCjPoNAIYCJNzU kjos6KdzO+vKW6rYTMUEG592GFbjUkYa/Aj4OIjaXQserr9K1pYW2zKcDD09lrQEep6f mE/smCtmbAuHXhAAK4fWLXwhU5SUUS2n6wMiJNiwqH+GOXPnhvE7qPypd7kho6GnR7Kh p4t2Fta0BbKWpZLEZC97gnDg5SA3d4t1toqYuVPOtN4CWrLl/3N3RTcJD49gE+5nzFVQ GDOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=SGsil05SR5HyEHxBqow0AuD9rbhVsw4TLPg5c/VcqZw=; b=PHhdp15hCK8sTMNkI55x4XivqM+aJS5Nl2u8tImIphqw+jmf/YoJ8VO4uAnliD61RI DHrW45rkmBuTP49KT3fWRp9iI0gQJqoX5SGCrtSul2EY1Obtf2K7hxxG6dW46l7/OQFQ e5sJgraubhgQ1b34T8W6+COgkohyAYXVK+AagTfVf6qo5u/Jwc5NsppLtI5dlx3lGJz/ Jps8A3mnMvUGZZZd5LsFxtNe72I3gsVvgDG1RMV8qhmYiAfwF+lTQkwShZozbEc1p+zK i/oD/bhoGuDnXPzhtPR6J5aueA+Gb+Wa6ILrZwXYU+2WaNOKQT8Sru7J8mxWcVuPw/bt 7Cqg== X-Gm-Message-State: AOAM531idtrm2DDwtqYlyDONslOmSOhBkqmJh/1lbep2V08wQa6j7Msr F1E4ag7SEgm1ayW5yQILk/tN4yJM X-Google-Smtp-Source: ABdhPJzVq4HvLVbJYAQwSYBN3oupkDPxJd6rUakldO2GKLKLUH1qFjyqP0I3SNTAqkHNBYz1w6ygHQ== X-Received: by 2002:a5e:dd0a:: with SMTP id t10mr28365436iop.9.1592227268829; Mon, 15 Jun 2020 06:21:08 -0700 (PDT) Received: from gateway.1015granger.net (c-68-61-232-219.hsd1.mi.comcast.net. [68.61.232.219]) by smtp.gmail.com with ESMTPSA id p11sm7971935ioo.26.2020.06.15.06.21.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 06:21:08 -0700 (PDT) Received: from manet.1015granger.net (manet.1015granger.net [192.168.1.51]) by gateway.1015granger.net (8.14.7/8.14.7) with ESMTP id 05FDL7k2018441; Mon, 15 Jun 2020 13:21:07 GMT Subject: [PATCH v1 4/5] xprtrdma: Clean up disconnect From: Chuck Lever To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org Date: Mon, 15 Jun 2020 09:21:07 -0400 Message-ID: <20200615132107.11800.86974.stgit@manet.1015granger.net> In-Reply-To: <20200615131642.11800.27486.stgit@manet.1015granger.net> References: <20200615131642.11800.27486.stgit@manet.1015granger.net> User-Agent: StGit/0.22-38-gfb18 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 1. Ensure that only rpcrdma_cm_event_handler() modifies ep->re_connect_status to avoid racy changes to that field. 2. Ensure that xprt_force_disconnect() is invoked only once as a transport is closed or destroyed. Signed-off-by: Chuck Lever --- net/sunrpc/xprtrdma/verbs.c | 23 +++++++++++++---------- net/sunrpc/xprtrdma/xprt_rdma.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 7a112612fc8f..2198c8ec8dff 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -130,6 +130,16 @@ static void rpcrdma_qp_event_handler(struct ib_event *event, void *context) trace_xprtrdma_qp_event(ep, event); } +/* Ensure xprt_force_disconnect() is invoked exactly once when a + * connection is closed or lost. (The important thing is it needs + * to be invoked "at least" once). + */ +static void rpcrdma_force_disconnect(struct rpcrdma_ep *ep) +{ + if (atomic_add_unless(&ep->re_force_disconnect, 1, 1)) + xprt_force_disconnect(ep->re_xprt); +} + /** * rpcrdma_flush_disconnect - Disconnect on flushed completion * @r_xprt: transport to disconnect @@ -139,13 +149,8 @@ static void rpcrdma_qp_event_handler(struct ib_event *event, void *context) */ void rpcrdma_flush_disconnect(struct rpcrdma_xprt *r_xprt, struct ib_wc *wc) { - struct rpc_xprt *xprt = &r_xprt->rx_xprt; - - if (wc->status != IB_WC_SUCCESS && - r_xprt->rx_ep->re_connect_status == 1) { - r_xprt->rx_ep->re_connect_status = -ECONNABORTED; - xprt_force_disconnect(xprt); - } + if (wc->status != IB_WC_SUCCESS) + rpcrdma_force_disconnect(r_xprt->rx_ep); } /** @@ -243,7 +248,6 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) { struct sockaddr *sap = (struct sockaddr *)&id->route.addr.dst_addr; struct rpcrdma_ep *ep = id->context; - struct rpc_xprt *xprt = ep->re_xprt; might_sleep(); @@ -267,7 +271,6 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) /* fall through */ case RDMA_CM_EVENT_ADDR_CHANGE: ep->re_connect_status = -ENODEV; - xprt_force_disconnect(xprt); goto disconnected; case RDMA_CM_EVENT_ESTABLISHED: rpcrdma_ep_get(ep); @@ -292,7 +295,7 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) case RDMA_CM_EVENT_DISCONNECTED: ep->re_connect_status = -ECONNABORTED; disconnected: - xprt_force_disconnect(xprt); + rpcrdma_force_disconnect(ep); return rpcrdma_ep_put(ep); default: break; diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h index 098d05a62ead..43974ef39a50 100644 --- a/net/sunrpc/xprtrdma/xprt_rdma.h +++ b/net/sunrpc/xprtrdma/xprt_rdma.h @@ -82,6 +82,7 @@ struct rpcrdma_ep { unsigned int re_max_inline_recv; int re_async_rc; int re_connect_status; + atomic_t re_force_disconnect; struct ib_qp_init_attr re_attr; wait_queue_head_t re_connect_wait; struct rpc_xprt *re_xprt; From patchwork Mon Jun 15 13:21:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever III X-Patchwork-Id: 11604981 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6126E90 for ; Mon, 15 Jun 2020 13:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48DC72076A for ; Mon, 15 Jun 2020 13:21:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RZRksO3y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730333AbgFONVP (ORCPT ); Mon, 15 Jun 2020 09:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729965AbgFONVO (ORCPT ); Mon, 15 Jun 2020 09:21:14 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C244CC061A0E; Mon, 15 Jun 2020 06:21:14 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id o5so17730076iow.8; Mon, 15 Jun 2020 06:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=SjNLJ91cqhULMfUPkTYp0OY2T4Mkc4LkzZDNbiHB4Nc=; b=RZRksO3ycfjFO3RdOXuk4Sqo3hGvAP0JdBG1HwHx0N7aMiwfdfwhqtpHhBrfFgw5Rf Z24Gc+8gNSnayDv08TDxtrv8oHiZouCQGV4bqy7ate9Jq6Zm2FtY+DPmCEGLrod91UkI RcksliCk0ZOnLSrdH4+galCNZdAGNi7DRreCgZ9VwvixC8AjWn91YYYdNYXyhjRmOD8g GW7tdRDzoETsJnAbFGqCbqQLuRfXEHDG1/ykIOQyzCmZA0OK/CGz/ZnOfrDk23Xvy7LE izXj32JRf6CGPyDkgWokdsXRtp41PqOwp2F84RBCIUJmWOEgUZoFCd9xCLisRYwGs1Vr GnDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=SjNLJ91cqhULMfUPkTYp0OY2T4Mkc4LkzZDNbiHB4Nc=; b=C9zFCf1DwrygloAxrXFCfKMPAYpMkkutLTZqZ2o/xqFGaU46tsaDpjhphqX9WnuuVu HTLoPWhe+qw19jwPb9h3ZrV1kamEpLo9X2NaynU4UGV6BCPep1c50auPVJp8ZJ126U+r 1EvVgfInbAIgTmPtsiaeX0Ks+Zua1sdkiPpSF4jAhoyhxirYDh09fT5/Dj/73+XzOstw bn+BPkWx7RlaitDKRGqOPWF88zGWmnP01J2VDpKc7jj8BkFLF84J9WPntPp0ErgULLsz aRNfgcRG4F3jjcrUnUDdyOPwcin9Be+szkVVyk3Ejey6JL2ljxM5cJDLqPUjWaUhHZ8I 9NDw== X-Gm-Message-State: AOAM532n39YQAC33aG0mLxxGAODNfwLheHJ9P32dbocO6UmQCRcBH9yo NQSFkpHhM+2C8xaAPR7oH3g= X-Google-Smtp-Source: ABdhPJzEqhCJ0I+jhP7ALxkXT4AJX7Ap4ce+fcHr0aiFji2tihBExiJWNW532uyhMnt5GkS5Mv8XMw== X-Received: by 2002:a6b:630d:: with SMTP id p13mr27599094iog.145.1592227274182; Mon, 15 Jun 2020 06:21:14 -0700 (PDT) Received: from gateway.1015granger.net (c-68-61-232-219.hsd1.mi.comcast.net. [68.61.232.219]) by smtp.gmail.com with ESMTPSA id n4sm8106768ioc.8.2020.06.15.06.21.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 06:21:13 -0700 (PDT) Received: from manet.1015granger.net (manet.1015granger.net [192.168.1.51]) by gateway.1015granger.net (8.14.7/8.14.7) with ESMTP id 05FDLDbi018444; Mon, 15 Jun 2020 13:21:13 GMT Subject: [PATCH v1 5/5] xprtrdma: Fix handling of RDMA_ERROR replies From: Chuck Lever To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org Date: Mon, 15 Jun 2020 09:21:13 -0400 Message-ID: <20200615132113.11800.52604.stgit@manet.1015granger.net> In-Reply-To: <20200615131642.11800.27486.stgit@manet.1015granger.net> References: <20200615131642.11800.27486.stgit@manet.1015granger.net> User-Agent: StGit/0.22-38-gfb18 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The RPC client currently doesn't handle ERR_CHUNK replies correctly. rpcrdma_complete_rqst() incorrectly passes a negative number to xprt_complete_rqst() as the number of bytes copied. Instead, set task->tk_status to the error value, and return zero bytes copied. In these cases, return -EIO rather than -EREMOTEIO. The RPC client's finite state machine doesn't know what to do with -EREMOTEIO. Additional clean ups: - Don't double-count RDMA_ERROR replies - Remove a stale comment Signed-off-by: Chuck Lever Cc: --- net/sunrpc/xprtrdma/rpc_rdma.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/net/sunrpc/xprtrdma/rpc_rdma.c b/net/sunrpc/xprtrdma/rpc_rdma.c index 2081c8fbfa48..935bbef2f7be 100644 --- a/net/sunrpc/xprtrdma/rpc_rdma.c +++ b/net/sunrpc/xprtrdma/rpc_rdma.c @@ -1349,8 +1349,7 @@ rpcrdma_decode_error(struct rpcrdma_xprt *r_xprt, struct rpcrdma_rep *rep, be32_to_cpup(p), be32_to_cpu(rep->rr_xid)); } - r_xprt->rx_stats.bad_reply_count++; - return -EREMOTEIO; + return -EIO; } /* Perform XID lookup, reconstruction of the RPC reply, and @@ -1387,13 +1386,11 @@ void rpcrdma_complete_rqst(struct rpcrdma_rep *rep) spin_unlock(&xprt->queue_lock); return; -/* If the incoming reply terminated a pending RPC, the next - * RPC call will post a replacement receive buffer as it is - * being marshaled. - */ out_badheader: trace_xprtrdma_reply_hdr(rep); r_xprt->rx_stats.bad_reply_count++; + rqst->rq_task->tk_status = status; + status = 0; goto out; }