Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH 1/5] virtiofs: fix DAX range leak on unmount
@ 2026-11-26 14:47 Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 2/5] virtiofs: don't abort DAX removemapping on allocation failure Miklos Szeredi
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Miklos Szeredi @ 2026-11-26 14:47 UTC (permalink / raw)
  To: fuse-devel, virtualization; +Cc: Li Wang, German Maglione, Stefan Hajnoczi

generic_shutdown_super() clears SB_ACTIVE before calling evict_inodes(),
so at unmount time fuse_evict_inode() skipped fuse_vdax_inode_cleanup()
for every remaining inode.  The DAX ranges owned by those inodes stay on
fc->vdax->busy_ranges instead of being returned to the free pool, and
fuse_vdax_conn_free() only frees free_ranges before kfree()ing the
connection, so the busy fuse_dax_mapping objects are leaked.  Nothing
warns about it: fuse_free_inode() kfree()s fi->vdax without checking
that the interval tree is empty.

Call fuse_vdax_inode_cleanup() regardless of SB_ACTIVE.  That is what
virtio_fs_conn_destroy() has always assumed ("Soon evict_inodes() will
be called which will free all memory ranges belonging to all inodes").
Unlike the FORGET in the same block, which is pointless once DESTROY has
been sent, the DAX cleanup is the only thing there that owns memory.

On a full unmount virtio_fs_conn_destroy() has already run by the time
evict_inodes() is called, so the FUSE_REMOVEMAPPING requests sent by
fuse_vdax_inode_cleanup() fail with -ENOTCONN, which
inode_reclaim_dmap_range() ignores.  On a submount unmount the
connection is still alive and those requests are both valid and needed.

Fixes: c2d0ad00d948 ("virtiofs: implement dax read/write operations")
Cc: <stable@vger.kernel.org>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-3b38f8c0-5e4a-4c21-87a6-4f96cc3cf147
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/fuse/inode.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 20fbc99f3590..344fcb55a64b 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -150,11 +150,16 @@ static void fuse_evict_inode(struct inode *inode)
 
 	truncate_inode_pages_final(&inode->i_data);
 	clear_inode(inode);
+	/*
+	 * Must be done unconditionally: the DAX ranges owned by this inode
+	 * are freed nowhere else, so skipping this on an inactive
+	 * superblock would leak them.
+	 */
+	if (FUSE_IS_VDAX(inode))
+		fuse_vdax_inode_cleanup(inode);
 	if (inode->i_sb->s_flags & SB_ACTIVE) {
 		struct fuse_conn *fc = get_fuse_conn(inode);
 
-		if (FUSE_IS_VDAX(inode))
-			fuse_vdax_inode_cleanup(inode);
 		if (fi->nlookup) {
 			fuse_chan_queue_forget(fc->chan, fi->forget, fi->nodeid,
 					       fi->nlookup);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/5] virtiofs: don't abort DAX removemapping on allocation failure
  2026-11-26 14:47 [PATCH 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
@ 2026-11-26 14:47 ` Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 3/5] virtiofs: retry request submission from the worker on -ENOMEM Miklos Szeredi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Miklos Szeredi @ 2026-11-26 14:47 UTC (permalink / raw)
  To: fuse-devel, virtualization; +Cc: Li Wang, German Maglione, Stefan Hajnoczi

dmap_removemapping_list() allocates an array of fuse_removemapping_one
entries to batch the FUSE_REMOVEMAPPING request, and returns -ENOMEM if
that fails.  The only caller, inode_reclaim_dmap_range(), has no way to
recover: it just warns and returns the ranges to the free pool, where
they can be handed to another inode while the server still has them
mapped.  The request is never retried either, so a single failed
allocation is enough to lose the removal.

The allocation is up to FUSE_REMOVEMAPPING_MAX_ENTRY (PAGE_SIZE / 16)
entries, i.e. a page, and it is GFP_NOFS.  Inode eviction and the DAX
free worker are exactly the paths that run under memory pressure, so
this is not hypothetical.

The batch array is only a convenience: dmap_removemapping_one() already
sends a single entry entirely from the stack.  Move it above
dmap_removemapping_list() and use it to remove the ranges one at a time
when the array cannot be allocated.  That is slower, but it cannot fail
for lack of memory, and it only happens under memory pressure.

While at it, initialize ret, which was left uninitialized if the list
passed in was empty.  The current caller checks for that beforehand, so
this is not a bug today.

Fixes: c2d0ad00d948 ("virtiofs: implement dax read/write operations")
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/fuse/dax.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c
index e20a5ae6fecc..c5bbb5d91026 100644
--- a/fs/fuse/dax.c
+++ b/fs/fuse/dax.c
@@ -248,18 +248,46 @@ static int fuse_send_removemapping(struct inode *inode,
 	return fuse_simple_request(fm, &args);
 }
 
+static int dmap_removemapping_one(struct inode *inode,
+				  struct fuse_dax_mapping *dmap)
+{
+	struct fuse_removemapping_one forget_one;
+	struct fuse_removemapping_in inarg;
+
+	memset(&inarg, 0, sizeof(inarg));
+	inarg.count = 1;
+	memset(&forget_one, 0, sizeof(forget_one));
+	forget_one.moffset = dmap->window_offset;
+	forget_one.len = dmap->length;
+
+	return fuse_send_removemapping(inode, &inarg, &forget_one);
+}
+
 static int dmap_removemapping_list(struct inode *inode, unsigned int num,
 				   struct list_head *to_remove)
 {
 	struct fuse_removemapping_one *remove_one, *ptr;
 	struct fuse_removemapping_in inarg;
 	struct fuse_dax_mapping *dmap;
-	int ret, i = 0, nr_alloc;
+	int ret = 0, i = 0, nr_alloc;
 
 	nr_alloc = min_t(unsigned int, num, FUSE_REMOVEMAPPING_MAX_ENTRY);
 	remove_one = kmalloc_objs(*remove_one, nr_alloc, GFP_NOFS);
-	if (!remove_one)
-		return -ENOMEM;
+	if (!remove_one) {
+		/*
+		 * The ranges are not reusable until the server has dropped
+		 * the mappings, and the request is never retried, so failing
+		 * here would take them out of use for good.  Fall back to
+		 * removing them one at a time, which needs no allocation;
+		 * slow, but this only happens under memory pressure.
+		 */
+		list_for_each_entry(dmap, to_remove, list) {
+			ret = dmap_removemapping_one(inode, dmap);
+			if (ret)
+				break;
+		}
+		return ret;
+	}
 
 	ptr = remove_one;
 	list_for_each_entry(dmap, to_remove, list) {
@@ -350,21 +378,6 @@ static void inode_reclaim_dmap_range(struct fuse_conn_vdax *fcd,
 	spin_unlock(&fcd->lock);
 }
 
-static int dmap_removemapping_one(struct inode *inode,
-				  struct fuse_dax_mapping *dmap)
-{
-	struct fuse_removemapping_one forget_one;
-	struct fuse_removemapping_in inarg;
-
-	memset(&inarg, 0, sizeof(inarg));
-	inarg.count = 1;
-	memset(&forget_one, 0, sizeof(forget_one));
-	forget_one.moffset = dmap->window_offset;
-	forget_one.len = dmap->length;
-
-	return fuse_send_removemapping(inode, &inarg, &forget_one);
-}
-
 /*
  * It is called from evict_inode() and by that time inode is going away. So
  * this function does not take any locks like fi->vdax->sem for traversing
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/5] virtiofs: retry request submission from the worker on -ENOMEM
  2026-11-26 14:47 [PATCH 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 2/5] virtiofs: don't abort DAX removemapping on allocation failure Miklos Szeredi
@ 2026-11-26 14:47 ` Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 4/5] virtiofs: abort the connection if the server fails to unmap a DAX range Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 5/5] virtiofs: fix forget leak on submount unmount Miklos Szeredi
  3 siblings, 0 replies; 5+ messages in thread
From: Miklos Szeredi @ 2026-11-26 14:47 UTC (permalink / raw)
  To: fuse-devel, virtualization; +Cc: Li Wang, German Maglione, Stefan Hajnoczi

virtio_fs_send_req() enqueues with GFP_ATOMIC, because it may be called
with fc->chan->bg_lock held.  copy_args_to_argbuf() allocates the bounce
buffer with those flags, so under memory pressure a request can be
failed with -ENOMEM even though nothing is wrong with it.  The buffer is
as large as the request arguments, so this is not limited to tiny
allocations: FUSE_REMOVEMAPPING, for example, can ask for just over
4 KiB, an order-1 allocation out of the atomic reserves with no reclaim.

A virtqueue that is merely full is already handled gracefully: -ENOSPC
puts the request on fsvq->queued_reqs and virtio_fs_request_dispatch_work()
retries it with GFP_KERNEL under memalloc_nofs_save().  A failed atomic
allocation is just as transient, so treat it the same way instead of
ending the request.  Unlike -ENOSPC there is no completion to kick the
worker afterwards, so schedule it here.

virtio_fs_enqueue_req() queues on -ENOSPC only after checking
fsvq->connected under fsvq->lock; do the same here and fail the request
with -ENOTCONN if the queue is gone.  req->argbuf has already been freed
and cleared on the error path, so the retry reallocates it.

Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem")
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/fuse/virtio_fs.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 8bd63c6165d2..6ddb2f181a16 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1586,6 +1586,23 @@ static void virtio_fs_send_req(struct fuse_iqueue *fiq, struct fuse_req *req)
 			 */
 			return;
 		}
+		if (ret == -ENOMEM) {
+			/*
+			 * Only the GFP_ATOMIC allocation failed.  Hand the
+			 * request to the dispatch worker, which retries with
+			 * GFP_KERNEL, rather than failing it outright.
+			 */
+			spin_lock(&fsvq->lock);
+			if (fsvq->connected) {
+				list_add_tail(&req->list, &fsvq->queued_reqs);
+				inc_in_flight_req(fsvq);
+				schedule_work(&fsvq->dispatch_work);
+				spin_unlock(&fsvq->lock);
+				return;
+			}
+			spin_unlock(&fsvq->lock);
+			ret = -ENOTCONN;
+		}
 		req->out.h.error = ret;
 		pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n", ret);
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/5] virtiofs: abort the connection if the server fails to unmap a DAX range
  2026-11-26 14:47 [PATCH 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 2/5] virtiofs: don't abort DAX removemapping on allocation failure Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 3/5] virtiofs: retry request submission from the worker on -ENOMEM Miklos Szeredi
@ 2026-11-26 14:47 ` Miklos Szeredi
  2026-11-26 14:47 ` [PATCH 5/5] virtiofs: fix forget leak on submount unmount Miklos Szeredi
  3 siblings, 0 replies; 5+ messages in thread
From: Miklos Szeredi @ 2026-11-26 14:47 UTC (permalink / raw)
  To: fuse-devel, virtualization; +Cc: Li Wang, German Maglione, Stefan Hajnoczi

If FUSE_REMOVEMAPPING fails, at least one range is still mapped on the
server side.  Both callers return the ranges to the free pool regardless,
so the next allocation can hand one to a different inode while the server
still has it mapped, exposing one file's data in another.

The ranges cannot be reused, but they also cannot usefully be tracked.
The requests are sent in batches and the first failure aborts the rest, so
it is not known which of them the server did drop; and a server that
refuses a request it is required to honour will keep refusing, so every
range ends up retired one by one, with nothing to replenish the pool.
__fuse_dax_fault() then waits uninterruptibly in wait_event() for a free
range that can never arrive.  Quietly retiring ranges only delays the
failure and makes it worse when it comes.

Abort the connection instead.  No FUSE_SETUPMAPPING can succeed after
that, so no range is ever handed out again and the pool stays reusable
without any bookkeeping, which is why both callers can go back to
ignoring the error.  The abort is done in fuse_send_removemapping(),
synchronously, because it has to happen before the caller returns the
ranges to the free pool: deferring it would leave a window in which
another thread could allocate a range and map it on top of the one the
server kept.

A dead connection is not such a case: the server is not going to access
the ranges any more, so they stay reusable.  Test the connection rather
than matching on -ENOTCONN, which missed the -ECONNABORTED and -ENODEV
that fuse_chan_abort() ends requests with.  For that, add a
fuse_chan_connected() accessor, as fuse_chan is private to dev.c.

For the abort to mean what it says, a failure has to be the server's
fault and nothing else.  Send the request with args.force, which allocates
with __GFP_NOFAIL and waits uninterruptibly, so that neither a fatal
signal on the calling task nor a failed request allocation is mistaken
for a refusal.  The remaining kernel-side allocation failures were
addressed by the two preceding patches.

Note that the uninterruptible wait means an unresponsive server now hangs
the caller rather than letting a fatal signal out; the connection's
request timeout, if configured, is what breaks that.  This matches what
the rest of the eviction path already does.

Fixes: c2d0ad00d948 ("virtiofs: implement dax read/write operations")
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/fuse/dax.c | 59 ++++++++++++++++++++++++++++++++++++++-------------
 fs/fuse/dev.c |  5 +++++
 fs/fuse/dev.h |  1 +
 3 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c
index c5bbb5d91026..ac84ada25a5a 100644
--- a/fs/fuse/dax.c
+++ b/fs/fuse/dax.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2020 Red Hat, Inc.
  */
 
+#include "dev.h"
 #include "fuse_i.h"
 
 #include <linux/delay.h>
@@ -229,6 +230,25 @@ static int fuse_setup_one_mapping(struct inode *inode, unsigned long start_idx,
 	return 0;
 }
 
+/*
+ * The server is required to drop the mappings it is asked to drop.  If it
+ * refuses, the ranges stay mapped on the server side, and handing one to
+ * another inode would expose one file's data in another.
+ *
+ * Rather than keep track of which ranges are still live, abort the
+ * connection.  No FUSE_SETUPMAPPING can succeed after that, so no range is
+ * ever handed out again and the pool can be reused without a second thought.
+ * The abort has to happen here, before the caller returns the ranges to the
+ * free pool, so that it cannot race with a concurrent allocation.
+ *
+ * A dead connection is not such a case: the server is not going to access
+ * the ranges any more, so they stay reusable.  Test the connection rather
+ * than matching on -ENOTCONN, which misses the -ECONNABORTED and -ENODEV
+ * that fuse_chan_abort() ends requests with.
+ *
+ * The request is sent with args.force so that neither a fatal signal nor a
+ * failed request allocation can be mistaken for the server refusing.
+ */
 static int fuse_send_removemapping(struct inode *inode,
 				   struct fuse_removemapping_in *inargp,
 				   struct fuse_removemapping_one *remove_one)
@@ -236,6 +256,7 @@ static int fuse_send_removemapping(struct inode *inode,
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_mount *fm = get_fuse_mount(inode);
 	FUSE_ARGS(args);
+	int ret;
 
 	args.opcode = FUSE_REMOVEMAPPING;
 	args.nodeid = fi->nodeid;
@@ -245,7 +266,16 @@ static int fuse_send_removemapping(struct inode *inode,
 	args.in_args[1].value = inargp;
 	args.in_args[2].size = inargp->count * sizeof(*remove_one);
 	args.in_args[2].value = remove_one;
-	return fuse_simple_request(fm, &args);
+	args.force = true;
+
+	ret = fuse_simple_request(fm, &args);
+	if (ret && fuse_chan_connected(fm->fc->chan)) {
+		pr_err("fuse: server failed to remove DAX mapping, aborting connection.  count=%u offset=0x%llx len=0x%llx ret=%d\n",
+		       inargp->count, remove_one->moffset, remove_one->len,
+		       ret);
+		fuse_chan_abort(fm->fc->chan, false);
+	}
+	return ret;
 }
 
 static int dmap_removemapping_one(struct inode *inode,
@@ -340,7 +370,7 @@ static void inode_reclaim_dmap_range(struct fuse_conn_vdax *fcd,
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_dax_mapping *dmap, *n;
-	int err, num = 0;
+	int num = 0;
 	LIST_HEAD(to_remove);
 	unsigned long start_idx = start >> FUSE_DAX_SHIFT;
 	unsigned long end_idx = end >> FUSE_DAX_SHIFT;
@@ -365,11 +395,13 @@ static void inode_reclaim_dmap_range(struct fuse_conn_vdax *fcd,
 
 	WARN_ON(fi->vdax->nr < num);
 	fi->vdax->nr -= num;
-	err = dmap_removemapping_list(inode, num, &to_remove);
-	if (err && err != -ENOTCONN) {
-		pr_warn("Failed to removemappings. start=0x%llx end=0x%llx\n",
-			start, end);
-	}
+	/*
+	 * A failure is dealt with in fuse_send_removemapping(): either the
+	 * connection is already gone, or it has just been aborted because the
+	 * server refused.  Either way nothing can be mapped any more, so the
+	 * ranges are safe to return to the free pool.
+	 */
+	dmap_removemapping_list(inode, num, &to_remove);
 	spin_lock(&fcd->lock);
 	list_for_each_entry_safe(dmap, n, &to_remove, list) {
 		list_del_init(&dmap->list);
@@ -882,15 +914,12 @@ static int reclaim_one_dmap_locked(struct inode *inode,
 	interval_tree_remove(&dmap->itn, &fi->vdax->tree);
 	fi->vdax->nr--;
 
-	/* It is possible that umount/shutdown has killed the fuse connection
-	 * and worker thread is trying to reclaim memory in parallel.  Don't
-	 * warn in that case.
+	/*
+	 * A failure is dealt with in fuse_send_removemapping(), which aborts
+	 * the connection if the server refused.  The caller owns the mapping
+	 * either way.
 	 */
-	ret = dmap_removemapping_one(inode, dmap);
-	if (ret && ret != -ENOTCONN) {
-		pr_warn("Failed to remove mapping. offset=0x%llx len=0x%llx ret=%d\n",
-			dmap->window_offset, dmap->length, ret);
-	}
+	dmap_removemapping_one(inode, dmap);
 	return 0;
 }
 
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index b198cc729cba..c653aabf2449 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -424,6 +424,11 @@ unsigned int fuse_chan_num_waiting(struct fuse_chan *fch)
 	return atomic_read(&fch->num_waiting);
 }
 
+bool fuse_chan_connected(struct fuse_chan *fch)
+{
+	return READ_ONCE(fch->connected);
+}
+
 void fuse_chan_set_fc(struct fuse_chan *fch, struct fuse_conn *fc)
 {
 	fch->conn = fc;
diff --git a/fs/fuse/dev.h b/fs/fuse/dev.h
index dbffd5bed2f5..71f56e71c899 100644
--- a/fs/fuse/dev.h
+++ b/fs/fuse/dev.h
@@ -34,6 +34,7 @@ unsigned int fuse_chan_num_background(struct fuse_chan *fch);
 unsigned int fuse_chan_max_background(struct fuse_chan *fch);
 void fuse_chan_max_background_set(struct fuse_chan *fch, unsigned int val);
 unsigned int fuse_chan_num_waiting(struct fuse_chan *fch);
+bool fuse_chan_connected(struct fuse_chan *fch);
 void fuse_chan_set_fc(struct fuse_chan *fch, struct fuse_conn *fc);
 void fuse_chan_set_initialized(struct fuse_chan *fch, struct fuse_chan_param *param);
 ssize_t fuse_chan_send(struct fuse_chan *fch, struct fuse_args *args);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 5/5] virtiofs: fix forget leak on submount unmount
  2026-11-26 14:47 [PATCH 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
                   ` (2 preceding siblings ...)
  2026-11-26 14:47 ` [PATCH 4/5] virtiofs: abort the connection if the server fails to unmap a DAX range Miklos Szeredi
@ 2026-11-26 14:47 ` Miklos Szeredi
  3 siblings, 0 replies; 5+ messages in thread
From: Miklos Szeredi @ 2026-11-26 14:47 UTC (permalink / raw)
  To: fuse-devel, virtualization; +Cc: Li Wang, German Maglione, Stefan Hajnoczi

generic_shutdown_super() clears SB_ACTIVE before calling evict_inodes(),
so fuse_evict_inode() skipped both the FUSE_FORGET for fi->nlookup and
fuse_cleanup_submount_lookup() for every remaining inode.

For a full unmount that is mostly fine: FUSE_DESTROY has already told the
server to drop everything.  But a submount unmount takes the same path
with the connection still alive: fuse_mount_remove() returns false, so
fuse_conn_destroy() is not called and no FUSE_DESTROY is sent.  The
server then keeps the lookup count of every inode of the submount for the
lifetime of the connection, which can be arbitrarily long if the parent
mount stays around and submounts come and go.

fuse_submount_lookup is worse, because it is freed nowhere else: the
object and its embedded forget are leaked on any unmount, including a
full one, for every inode that has one.

Queue both regardless of SB_ACTIVE.  This is safe on the paths where the
connection is already gone: both fuse_dev_queue_forget() and
virtio_fs_send_forget() just free the link when the queue is
disconnected, and fc->chan stays valid until fuse_free_conn(), well after
evict_inodes().

Fixes: c4d361f66ac9 ("fuse: share lookup state between submount and its parent")
Cc: <stable@vger.kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/fuse/inode.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 344fcb55a64b..81ee6c96203c 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -141,6 +141,7 @@ static void fuse_cleanup_submount_lookup(struct fuse_conn *fc,
 static void fuse_evict_inode(struct inode *inode)
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
+	struct fuse_conn *fc = get_fuse_conn(inode);
 
 	/* Will write inode on close/munmap and in all other dirtiers */
 	WARN_ON(inode_state_read_once(inode) & I_DIRTY_INODE);
@@ -157,19 +158,27 @@ static void fuse_evict_inode(struct inode *inode)
 	 */
 	if (FUSE_IS_VDAX(inode))
 		fuse_vdax_inode_cleanup(inode);
-	if (inode->i_sb->s_flags & SB_ACTIVE) {
-		struct fuse_conn *fc = get_fuse_conn(inode);
+	/*
+	 * Must be done unconditionally as well: on a submount unmount the
+	 * connection stays alive and no FUSE_DESTROY is sent, so without
+	 * this the server keeps the lookup counts of every inode in the
+	 * submount for the lifetime of the connection.  The
+	 * fuse_submount_lookup object is freed nowhere else, so skipping it
+	 * leaks that too.  If the connection is already gone (full unmount,
+	 * failed mount) fuse_chan_queue_forget() just frees the forget.
+	 */
+	if (fi->nlookup) {
+		fuse_chan_queue_forget(fc->chan, fi->forget, fi->nodeid,
+				       fi->nlookup);
+		fi->forget = NULL;
+	}
 
-		if (fi->nlookup) {
-			fuse_chan_queue_forget(fc->chan, fi->forget, fi->nodeid,
-					       fi->nlookup);
-			fi->forget = NULL;
-		}
+	if (fi->submount_lookup) {
+		fuse_cleanup_submount_lookup(fc, fi->submount_lookup);
+		fi->submount_lookup = NULL;
+	}
 
-		if (fi->submount_lookup) {
-			fuse_cleanup_submount_lookup(fc, fi->submount_lookup);
-			fi->submount_lookup = NULL;
-		}
+	if (inode->i_sb->s_flags & SB_ACTIVE) {
 		/*
 		 * Evict of non-deleted inode may race with outstanding
 		 * LOOKUP/READDIRPLUS requests and result in inconsistency when
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26 14:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 14:47 [PATCH 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
2026-11-26 14:47 ` [PATCH 2/5] virtiofs: don't abort DAX removemapping on allocation failure Miklos Szeredi
2026-11-26 14:47 ` [PATCH 3/5] virtiofs: retry request submission from the worker on -ENOMEM Miklos Szeredi
2026-11-26 14:47 ` [PATCH 4/5] virtiofs: abort the connection if the server fails to unmap a DAX range Miklos Szeredi
2026-11-26 14:47 ` [PATCH 5/5] virtiofs: fix forget leak on submount unmount Miklos Szeredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox