From: Miklos Szeredi <mszeredi@redhat.com>
To: fuse-devel@lists.linux.dev, virtualization@lists.linux.dev
Cc: Li Wang <liwang@kylinos.cn>,
German Maglione <gmaglione@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH 4/5] virtiofs: abort the connection if the server fails to unmap a DAX range
Date: Thu, 26 Nov 2026 15:47:17 +0100 [thread overview]
Message-ID: <20261126144719.232329-4-mszeredi@redhat.com> (raw)
In-Reply-To: <20261126144719.232329-1-mszeredi@redhat.com>
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
next prev parent reply other threads:[~2026-11-26 14:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-26 14:47 ` [PATCH 5/5] virtiofs: fix forget leak on submount unmount Miklos Szeredi
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=20261126144719.232329-4-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=fuse-devel@lists.linux.dev \
--cc=gmaglione@redhat.com \
--cc=liwang@kylinos.cn \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
/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