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 v3 2/5] virtiofs: don't abort DAX removemapping on allocation failure
Date: Tue, 1 Dec 2026 11:58:50 +0100 [thread overview]
Message-ID: <20261201105855.430993-2-mszeredi@redhat.com> (raw)
In-Reply-To: <20261201105855.430993-1-mszeredi@redhat.com>
dmap_removemapping_list() allocates an array of fuse_removemapping_one
entries to batch the FUSE_REMOVEMAPPING request, and returns -ENOMEM if
that fails.
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")
Reviewed-by: Li Wang <liwang@kylinos.cn>
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..e60665bb597e 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) {
+ /*
+ * Fall back to removing the ranges one at a time, which needs
+ * no allocation. It is slower, but this only happens under
+ * memory pressure. The caller ignores the error and recycles
+ * the ranges regardless, so bailing out here would just leave
+ * the server holding mappings for an inode that is gone.
+ */
+ 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
next prev parent reply other threads:[~2026-12-01 10:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 10:58 [PATCH v3 1/5] virtiofs: fix DAX range leak on unmount Miklos Szeredi
2026-12-01 10:58 ` Miklos Szeredi [this message]
2026-12-01 15:18 ` [PATCH v3 2/5] virtiofs: don't abort DAX removemapping on allocation failure German Maglione
2026-12-01 10:58 ` [PATCH v3 3/5] virtiofs: retry request submission from the worker on -ENOMEM Miklos Szeredi
2026-12-01 11:05 ` sashiko-bot
2026-12-01 15:18 ` German Maglione
2026-12-01 10:58 ` [PATCH v3 4/5] fuse: don't take a lookup count on the root inode Miklos Szeredi
2026-12-01 15:18 ` German Maglione
2026-12-02 3:50 ` Li Wang
2026-12-01 10:58 ` [PATCH v3 5/5] virtiofs: fix forget leak on submount unmount Miklos Szeredi
2026-12-01 13:23 ` Li Wang
2026-12-01 15:18 ` German Maglione
2026-12-01 11:11 ` [PATCH v3 1/5] virtiofs: fix DAX range leak on unmount sashiko-bot
2026-12-01 15:18 ` German Maglione
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=20261201105855.430993-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.