Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2777260pxb; Mon, 19 Apr 2021 13:44:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJinIh5Mfec5mGog91oX6JkDCHu5d8sGfFy5qoiqTA+6wPw9DZyuuGcpwVnlIBRCBvjKda X-Received: by 2002:a65:4d4c:: with SMTP id j12mr13356072pgt.346.1618865086928; Mon, 19 Apr 2021 13:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618865086; cv=none; d=google.com; s=arc-20160816; b=OojihmeQc9gVBIxKLBhhUbaeGzoc8X/udJRrt9AzlzVPmisLn9xQFzC1NfSWZCnm3e /pint6Kk8UHM57RzX8mXjqkjGB9eUlOUcuZ7Hc0hlXb+iqo4M1THfZ2yjdprXpYfhzJV 8xuMUcBM+Nr8Giso6J+DvcCohQJiGX2+imqYunZ3hyRF01QSmux5xDd8dysu/scpZoqE iqcNFgTmyC8YSXJevgraM8XwWbSAe3sEIUdQjsqXoWCBUFUnL2nSNRW20La4G89utMEW E0As5WFmPq3dGAAa2k5Uxl1InCyaycNK6t0LO243Gv1wqhKMxIzWa/y8f8fQLSP9tSiB ArHg== 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:cc:to:from :subject; bh=XtMfJEwvFvmt3LSINCE+lZF5ve+iJ9nbPNuFh5DzDjQ=; b=J1R2k8EOxJHTP4m9D2YzP0fs63usgLGLLwhRLNU3yHkIhqnkNayHY65FZqei4hiQ7H qEjst7raqFFUinL6xVqnh1/EGj2aGKoc6I3Cc62djc+hXk2KfjogIYejdPYgC0eNJbpZ m+RKOmWiT4DTUYtA4K88HFX4Vdj8zPp1YTFlCRDX1goeI7NvH9WaynrIZr1VVN/Yjvlb w2AGWj2DbxxKhkpVZtrcSG7mOouSApLvIqZTTPJ0HrHl/NWK4WGv1TXsHX1ArGlkY8gj RFRgfnEk7IiMsMi4kgIhF2ln6DMkmh709ZDWn/jBGiPgOt+60w0Z0Bg44b0cZsi1V7/a p/fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k11si15421732pfd.334.2021.04.19.13.44.27; Mon, 19 Apr 2021 13:44:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240494AbhDSSCy (ORCPT + 99 others); Mon, 19 Apr 2021 14:02:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:40938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240433AbhDSSCx (ORCPT ); Mon, 19 Apr 2021 14:02:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5CDE061001; Mon, 19 Apr 2021 18:02:23 +0000 (UTC) Subject: [PATCH v3 07/26] xprtrdma: Improve locking around rpcrdma_rep destruction From: Chuck Lever To: trondmy@hammerspace.com Cc: linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org Date: Mon, 19 Apr 2021 14:02:22 -0400 Message-ID: <161885534259.38598.17355600080366820390.stgit@manet.1015granger.net> In-Reply-To: <161885481568.38598.16682844600209775665.stgit@manet.1015granger.net> References: <161885481568.38598.16682844600209775665.stgit@manet.1015granger.net> User-Agent: StGit/0.23-29-ga622f1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Currently rpcrdma_reps_destroy() assumes that, at transport tear-down, the content of the rb_free_reps list is the same as the content of the rb_all_reps list. Although that is usually true, using the rb_all_reps list should be more reliable because of the way it's managed. And, rpcrdma_reps_unmap() uses rb_all_reps; these two functions should both traverse the "all" list. Ensure that all rpcrdma_reps are always destroyed whether they are on the rep free list or not. Signed-off-by: Chuck Lever --- net/sunrpc/xprtrdma/verbs.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 1b599a623eea..482fdc9e25c2 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -1007,16 +1007,23 @@ struct rpcrdma_rep *rpcrdma_rep_create(struct rpcrdma_xprt *r_xprt, return NULL; } -/* No locking needed here. This function is invoked only by the - * Receive completion handler, or during transport shutdown. - */ -static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep) +static void rpcrdma_rep_destroy_locked(struct rpcrdma_rep *rep) { - list_del(&rep->rr_all); rpcrdma_regbuf_free(rep->rr_rdmabuf); kfree(rep); } +static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep) +{ + struct rpcrdma_buffer *buf = &rep->rr_rxprt->rx_buf; + + spin_lock(&buf->rb_lock); + list_del(&rep->rr_all); + spin_unlock(&buf->rb_lock); + + rpcrdma_rep_destroy_locked(rep); +} + static struct rpcrdma_rep *rpcrdma_rep_get_locked(struct rpcrdma_buffer *buf) { struct llist_node *node; @@ -1049,8 +1056,18 @@ static void rpcrdma_reps_destroy(struct rpcrdma_buffer *buf) { struct rpcrdma_rep *rep; - while ((rep = rpcrdma_rep_get_locked(buf)) != NULL) - rpcrdma_rep_destroy(rep); + spin_lock(&buf->rb_lock); + while ((rep = list_first_entry_or_null(&buf->rb_all_reps, + struct rpcrdma_rep, + rr_all)) != NULL) { + list_del(&rep->rr_all); + spin_unlock(&buf->rb_lock); + + rpcrdma_rep_destroy_locked(rep); + + spin_lock(&buf->rb_lock); + } + spin_unlock(&buf->rb_lock); } /**