public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jeff Layton <jlayton@kernel.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-nfs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.0 28/32] nfsd: fix nfsd_file_unhash_and_dispose
Date: Mon, 17 Oct 2022 20:07:25 -0400	[thread overview]
Message-ID: <20221018000729.2730519-28-sashal@kernel.org> (raw)
In-Reply-To: <20221018000729.2730519-1-sashal@kernel.org>

From: Jeff Layton <jlayton@kernel.org>

[ Upstream commit 8d0d254b15cc5b7d46d85fb7ab8ecede9575e672 ]

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 <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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);
 		}
 
-- 
2.35.1


  parent reply	other threads:[~2022-10-18  0:11 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18  0:06 [PATCH AUTOSEL 6.0 01/32] crypto: qcom-rng - Fix qcom_rng_of_match unused warning Sasha Levin
2022-10-18  0:06 ` [PATCH AUTOSEL 6.0 02/32] crypto: ccp - Add a quirk to firmware update Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 03/32] crypto: ccp - Initialize PSP when reading psp data file failed Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 04/32] gfs2: Switch from strlcpy to strscpy Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 05/32] powerpc/hw_breakpoint: Avoid relying on caller synchronization Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 06/32] cgroup: Remove data-race around cgrp_dfl_visible Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 07/32] iommu/vt-d: Handle race between registration and device probe Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 08/32] of/fdt: Don't calculate initrd size from DT if start > end Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 09/32] tools/vm/page_owner_sort: fix -f option Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 10/32] objtool,x86: Teach decode about LOOP* instructions Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 11/32] locking/rwsem: Disable preemption while trying for rwsem lock Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 12/32] swiotlb: don't panic! Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 13/32] gfs2: Check sb_bsize_shift after reading superblock Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 14/32] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 15/32] m68knommu: fix non-specific 68328 choice interrupt build failure Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 16/32] m68knommu: fix non-mmu classic 68000 legacy timer tick selection Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 17/32] kbuild: take into account DT_SCHEMA_FILES changes while checking dtbs Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 18/32] tracing/user_events: Use WRITE instead of READ for io vector import Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 19/32] tracing/user_events: Ensure user provided strings are safely formatted Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 20/32] of: Fix "dma-ranges" handling for bus controllers Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 21/32] x86/hyperv: Replace kmap() with kmap_local_page() Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 22/32] kmsan: disable instrumentation of unsupported common kernel code Sasha Levin
2022-10-18  1:00   ` Marco Elver
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 23/32] kmsan: disable physical page merging in biovec Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 24/32] f2fs: fix wrong dirty page count when race between mmap and fallocate Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 25/32] f2fs: code clean and fix a type error Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 26/32] f2fs: fix to detect corrupted meta ino Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 27/32] 9p: trans_fd/p9_conn_cancel: drop client lock earlier Sasha Levin
2022-10-18  0:07 ` Sasha Levin [this message]
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 29/32] 9p/trans_fd: always use O_NONBLOCK read/write Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 30/32] net/9p: use a dedicated spinlock for trans_fd Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 31/32] virtio_pci: don't try to use intxif pin is zero Sasha Levin
2022-10-18  0:07 ` [PATCH AUTOSEL 6.0 32/32] cifs: replace kfree() with kfree_sensitive() for sensitive data Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221018000729.2730519-28-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox