Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp658186pxf; Wed, 31 Mar 2021 12:38:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjW0bxpznRyPR8ewRF9WOHN/dz0zt3lUR25sM0qb46egN7sza+usiSi+TVeC47Q7OZ4e// X-Received: by 2002:aa7:dcc7:: with SMTP id w7mr5610604edu.255.1617219512737; Wed, 31 Mar 2021 12:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617219512; cv=none; d=google.com; s=arc-20160816; b=ImfxD1ys/UsmNTmvPliuD+gk4k7eBSpuAM2pGqt5cgP2ndTYcaQF9n7hUnBRkiVXXZ 4wNfBEElZIDjBN9iLT58kiRkmmxs1qppuxXaJQfIH0FdF73fVbxnWE2WYYSF/cfFiaeb bYJn/paRnqTl8+Sb9O+1nmWg9AmKtMkU/y9lB92y0Q2UMl8GGwMJQI1bCI0bxVubPnL+ rmYd3Pm73qFo/TEt3dgPRrOxLxihUGVBCkG17uYzoSc72D9MZFbgq88RKC110sHp4WwT 84o3GSYCT0Q9DKogyjc6no1c9wUvH5hZCxLw9DrxdjUXjH6jlqQg8twt9/x0U+D8uitB YAEQ== 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:to:from:subject; bh=hHJ64sS5tTHf2P6Ks51UPix+sCf153pKRDA8pJXL1ug=; b=BXtAsoJQqhNaJaPun1mJM95uXTR3Fmr6pEU/x5vjY2bWLYB4efhyPuscKOPhC9b6mz rPvlA32soW6yAWKcCOJ+DOI8G/hMUv5Oj8Ch1OujtPe8HH3zzrwkdtnCsFKk8o3q0wym DrzHuZKIF5M72s8ty10Tvzb8qRXVvDyjv3SlSuBXt5smM0zP7GnWe8lrVbqSqZChUiww CVoRNrLXJLfJe3u/uk3gV1C0Sn9ze33viJ8Gjc690u2U7hMzvBMVGQQiA0tKJCGj887T 9QXY++e769F+4W6JB6IMzQqTrS1LCrmUuiR8fQyj25gsW5+Fr113kWstD5919uwGm00W 2GSA== 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 r14si2344545ejb.283.2021.03.31.12.38.10; Wed, 31 Mar 2021 12:38:32 -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 S236228AbhCaTg2 (ORCPT + 99 others); Wed, 31 Mar 2021 15:36:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:44502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236084AbhCaTgY (ORCPT ); Wed, 31 Mar 2021 15:36:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2EC1C61056; Wed, 31 Mar 2021 19:36:24 +0000 (UTC) Subject: [PATCH v1 4/8] xprtrdma: Improve locking around rpcrdma_rep destruction From: Chuck Lever To: linux-rdma@vger.kernel.org, linux-nfs@vger.kernel.org Date: Wed, 31 Mar 2021 15:36:23 -0400 Message-ID: <161721938342.515226.14847295549827213112.stgit@manet.1015granger.net> In-Reply-To: <161721926778.515226.9805598788670386587.stgit@manet.1015granger.net> References: <161721926778.515226.9805598788670386587.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 should both traverse the "all" list. Instead, ensure that all rpcrdma_reps are always destroyed whether they are on the rep free list or not. Also ensure that rpcrdma_rep destruction logic is protected by the rb_lock. 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 92af272f9cc9..fe250d554695 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -1000,16 +1000,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; @@ -1042,8 +1049,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); } /**