Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2012933rwb; Wed, 5 Oct 2022 07:58:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5M48DVrPzUxfplEM/nJmn7ums7Oq3fm4/ixZgi19KYh4DbFdANtYDO/8VJn5tTf7f7sx2T X-Received: by 2002:a17:90b:4a52:b0:20a:c8e6:477f with SMTP id lb18-20020a17090b4a5200b0020ac8e6477fmr118479pjb.219.1664981898373; Wed, 05 Oct 2022 07:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664981898; cv=none; d=google.com; s=arc-20160816; b=Ev6tuu8hqDby8lY+zei21Gf6FotKaii/vgTYVmNq6GvnUG2VNFbAO+4HslVfOA36Nz n0IsVhbNoNC504iFuF68HlAaAcVh79kJGGtS3VqsW7RCFjoRYlgK0cxHyjRW1Tyt8TKC c46/8jAs233qs6w90bHZc7c31Xg2UFPsgmQYqIoXsO0np0wSXWA9xKGMUXFeixb0krdu UfosEiCgB6mA/ryC7UE42epg47Z6TRWcFbnnT0XNfOFievIT8cP87UefVwcdd4OfP5g/ Bg5gaBzDMK94QWJrM2t/mv4ObPAINohpVxrbO89q5L5dBvqlcapkSVF4zWle+Lvqf1pk vGwg== 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=tFnMphAYGTUrM9F50ZXmUlqsnOoi2bxjGHF+eEyjPFU=; b=TVDTDmLgNJknBH0flNJ1vDBFr7ufZaCNbbV+xIKUjdn7E8xI5FJsD8x7uJxFeMW3De vIKqT9aaQhpcFQOewTvYW2KHwa9tFZXRLiJRXzUFpG/zD1sqeNJrbCjSI6dPdV9sUOYX bfwlPih1uH4LEToOB5f5mEVLtnGETo+1rXy0MfVTt6SNwHiUB7DcLv3F3HNKyhzxsV0o 6NfBuon6v3XXgU265YK4nzlfTWC2SaJoq57Rxvv5t2azsSX6tIhfcueB6J9ppNDOJjXN 0Skw8hp5v94eZVZsK6YrqR8tOs67aNm/r8dCuRUOBnXX8jwWhAh9QBEs1f7vbKmfnitl ceiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r5-20020a654985000000b00434df5a8524si17752915pgs.396.2022.10.05.07.57.46; Wed, 05 Oct 2022 07:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229815AbiJEOzs (ORCPT + 99 others); Wed, 5 Oct 2022 10:55:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbiJEOzs (ORCPT ); Wed, 5 Oct 2022 10:55:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C0664152E for ; Wed, 5 Oct 2022 07:55:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CA541B81DED for ; Wed, 5 Oct 2022 14:55:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85FECC433D6 for ; Wed, 5 Oct 2022 14:55:43 +0000 (UTC) Subject: [PATCH RFC 1/9] nfsd: fix nfsd_file_unhash_and_dispose From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Wed, 05 Oct 2022 10:55:42 -0400 Message-ID: <166498174250.1527.18089441104110588219.stgit@manet.1015granger.net> In-Reply-To: <166497916751.1527.11190362197003358927.stgit@manet.1015granger.net> References: <166497916751.1527.11190362197003358927.stgit@manet.1015granger.net> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Jeff Layton nfsd_file_unhash_and_dispose() is called for two reasons: We're either shutting down and purging the filecache, or we've gotten a notification about a file delete, so we want to go ahead and unhash it so that it'll get cleaned up when we close. We're either walking the hashtable or doing a lookup in it and we don't take a reference in either case. What we want to do in both cases is to try and unhash the object and put it on the dispose list if that was successful. If it's no longer hashed, then we don't want to touch it, with the assumption being that something else is already cleaning up the sentinel reference. Instead of trying to selectively decrement the refcount in this function, just unhash it, and if that was successful, move it to the dispose list. Then, the disposal routine will just clean that up as usual. Also, just make this a void function, drop the WARN_ON_ONCE, and the comments about deadlocking since the nature of the purported deadlock is no longer clear. Signed-off-by: Jeff Layton Signed-off-by: Chuck Lever --- fs/nfsd/filecache.c | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index eeed4ae5b4ad..844c41832d50 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -405,22 +405,15 @@ nfsd_file_unhash(struct nfsd_file *nf) return false; } -/* - * Return true if the file was unhashed. - */ -static bool +static void nfsd_file_unhash_and_dispose(struct nfsd_file *nf, struct list_head *dispose) { trace_nfsd_file_unhash_and_dispose(nf); - if (!nfsd_file_unhash(nf)) - return false; - /* keep final reference for nfsd_file_lru_dispose */ - if (refcount_dec_not_one(&nf->nf_ref)) - return true; - - nfsd_file_lru_remove(nf); - list_add(&nf->nf_lru, dispose); - return true; + if (nfsd_file_unhash(nf)) { + /* caller must call nfsd_file_dispose_list() later */ + nfsd_file_lru_remove(nf); + list_add(&nf->nf_lru, dispose); + } } static void @@ -562,8 +555,6 @@ nfsd_file_dispose_list_delayed(struct list_head *dispose) * @lock: LRU list lock (unused) * @arg: dispose list * - * Note this can deadlock with nfsd_file_cache_purge. - * * Return values: * %LRU_REMOVED: @item was removed from the LRU * %LRU_ROTATE: @item is to be moved to the LRU tail @@ -748,8 +739,6 @@ nfsd_file_close_inode(struct inode *inode) * * Walk the LRU list and close any entries that have not been used since * the last scan. - * - * Note this can deadlock with nfsd_file_cache_purge. */ static void nfsd_file_delayed_close(struct work_struct *work) @@ -891,16 +880,12 @@ nfsd_file_cache_init(void) goto out; } -/* - * Note this can deadlock with nfsd_file_lru_cb. - */ static void __nfsd_file_cache_purge(struct net *net) { struct rhashtable_iter iter; struct nfsd_file *nf; LIST_HEAD(dispose); - bool del; rhashtable_walk_enter(&nfsd_file_rhash_tbl, &iter); do { @@ -910,14 +895,7 @@ __nfsd_file_cache_purge(struct net *net) while (!IS_ERR_OR_NULL(nf)) { if (net && nf->nf_net != net) continue; - del = nfsd_file_unhash_and_dispose(nf, &dispose); - - /* - * Deadlock detected! Something marked this entry as - * unhased, but hasn't removed it from the hash list. - */ - WARN_ON_ONCE(!del); - + nfsd_file_unhash_and_dispose(nf, &dispose); nf = rhashtable_walk_next(&iter); }