summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2026-11-10 11:26:55 +0100
committerMiklos Szeredi <mszeredi@redhat.com>2026-11-19 18:25:59 +0100
commit6704a78171aa20caab2cd16da9ae2ff8edd4bb1d (patch)
treef956689c043c4e686ff39415ffcf8cb3838ec0cf
parentf7e0ed317736fb33d18e0b903743c2d7f9faa92c (diff)
fuse: advertise support for DAX mappings
Reuse the FUSE_HAS_INODE_DAX flag, which previously was only used for the virtiofs case. The two uses are unrelated: for virtiofs the flag means that host memory can be mapped directly into the guest, while here it means that the server may back an inode with a dax device opened via FUSE_DEV_IOC_BACKING_OPEN. Gate the advertisement on IS_REACHABLE(CONFIG_DEV_DAX_FSDEV), which is what fuse_backing_open_file() requires before it accepts a dax device as backing; CONFIG_FS_DAX alone is not sufficient. Plain fuse servers should check both FUSE_HAS_INODE_DAX and FUSE_PASSTHROUGH_V2 before enabling passthrough dax support. Stop advertising FUSE_PASSTHROUGH(_V2) in the virtiofs case, which doesn't support passthrough mode. Note: FUSE_HAS_INODE_DAX flag in the INIT reply is ignored, so it's handled slightly differently from the virtiofs case. This is deliberate. The server needs to check both FUSE_PASSTHROUGH_V2 and FUSE_HAS_INODE_DAX before enabling DAX based extent map if it wants to bail or fall back to plain I/O mode on kernels not supporting this feature. A broken server that does not check the features yet sets FUSE_ATTR_DAX will result in an error on open. This is not backward compatible, since this flag was silently ignored previously, but unlikely to be an issue in real life. Fixes: 2fbe4586cff3 ("fuse: add support for opening dax device as backing") Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
-rw-r--r--fs/fuse/fuse_i.h13
-rw-r--r--fs/fuse/inode.c32
-rw-r--r--fs/fuse/virtio_fs.c1
-rw-r--r--include/uapi/linux/fuse.h10
4 files changed, 47 insertions, 9 deletions
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index a033b0bc4576..e0992fcbcc55 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -421,6 +421,7 @@ struct fuse_fs_context {
bool no_req_timeout:1;
bool legacy_opts_show:1;
bool syncfs_capable:1;
+ bool is_virtiofs:1;
enum fuse_vdax_mode vdax_mode;
unsigned int max_read;
unsigned int blksize;
@@ -761,6 +762,9 @@ struct fuse_conn {
/** @sync_init: Is synchronous FUSE_INIT allowed? */
unsigned int sync_init:1;
+ /** @is_virtiofs: Is this a virtio-fs connection? */
+ unsigned int is_virtiofs:1;
+
/** @max_stack_depth: Maximum stack depth for passthrough backing files */
int max_stack_depth;
@@ -1273,6 +1277,15 @@ void fuse_free_conn(struct fuse_conn *fc);
/* dax.c */
+static inline bool fuse_conn_vdax(struct fuse_conn *fc)
+{
+#ifdef CONFIG_FUSE_VDAX
+ return fc->vdax;
+#else
+ return false;
+#endif
+}
+
static inline bool fuse_inode_vdax(struct inode *inode)
{
#ifdef CONFIG_FUSE_VDAX
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index c6bfc66317ad..af6d9e0af190 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -385,7 +385,7 @@ static void fuse_change_attributes_i(struct inode *inode, struct fuse_attr *attr
invalidate_inode_pages2(inode->i_mapping);
}
- if (IS_ENABLED(CONFIG_FUSE_VDAX))
+ if (fuse_conn_vdax(fc))
fuse_vdax_dontcache(inode, attr->flags);
}
@@ -419,13 +419,18 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr,
fuse_init_file_inode(inode, attr->flags);
/*
+ * FUSE_ATTR_DAX means a passthrough extent map on a dax
+ * device, which only exists on a plain fuse connection. On
+ * virtiofs the same bit means per inode virtiofs DAX, which
+ * is handled by fuse_vdax_inode_init() instead.
+ *
* Without CONFIG_FS_DAX, S_DAX is zero and IS_DAX() is
* constant false, so all the checks that keep DAX inodes away
* from the page cache are compiled out. Don't install address
* space operations that have no ->read_folio in that case.
*/
- if (IS_ENABLED(CONFIG_FS_DAX) && (attr->flags & FUSE_ATTR_DAX) &&
- !fuse_inode_vdax(inode)) {
+ if (IS_ENABLED(CONFIG_FS_DAX) && !fc->is_virtiofs &&
+ (attr->flags & FUSE_ATTR_DAX)) {
inode->i_flags |= S_DAX;
inode->i_data.a_ops = &fuse_dax_aops;
}
@@ -1394,7 +1399,7 @@ static void process_init_reply(struct fuse_args *args, int error)
!fuse_vdax_check_alignment(fc, arg->map_alignment)) {
ok = false;
}
- if (flags & FUSE_HAS_INODE_DAX)
+ if (fuse_conn_vdax(fc) && (flags & FUSE_HAS_INODE_DAX))
fc->inode_vdax = 1;
}
if (flags & FUSE_HANDLE_KILLPRIV_V2) {
@@ -1423,7 +1428,7 @@ static void process_init_reply(struct fuse_args *args, int error)
* and FUSE_WRITEBACK_CACHE, current design doesn't handle
* them together.
*/
- if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH) &&
+ if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH) && !fm->fc->is_virtiofs &&
(flags & (FUSE_PASSTHROUGH | FUSE_PASSTHROUGH_V2)) &&
arg->max_stack_depth > 0 &&
arg->max_stack_depth <= FILESYSTEM_MAX_STACK_DEPTH &&
@@ -1516,13 +1521,25 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)
#ifdef CONFIG_FUSE_VDAX
if (fm->fc->vdax)
flags |= FUSE_MAP_ALIGNMENT;
- if (fuse_is_inode_vdax_mode(fm->fc->vdax_mode))
+ if (fm->fc->vdax && fuse_is_inode_vdax_mode(fm->fc->vdax_mode))
flags |= FUSE_HAS_INODE_DAX;
#endif
if (fm->fc->auto_submounts)
flags |= FUSE_SUBMOUNTS;
- if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
+ /*
+ * Passthrough requires a backing file registered with
+ * FUSE_DEV_IOC_BACKING_OPEN on the fuse device, which a virtiofs
+ * server has no way to do.
+ */
+ if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH) && !fm->fc->is_virtiofs) {
flags |= FUSE_PASSTHROUGH | FUSE_PASSTHROUGH_V2;
+ /*
+ * Per inode DAX needs a dax device opened as backing, which
+ * is unrelated to how virtiofs uses the same flag above.
+ */
+ if (IS_REACHABLE(CONFIG_DEV_DAX_FSDEV))
+ flags |= FUSE_HAS_INODE_DAX;
+ }
/* Only offered to sufficiently privileged servers; see
* fuse_syncfs_enable().
*/
@@ -1830,6 +1847,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
fc->no_control = ctx->no_control;
fc->no_force_umount = ctx->no_force_umount;
fc->no_req_timeout = ctx->no_req_timeout;
+ fc->is_virtiofs = ctx->is_virtiofs;
err = -ENOMEM;
root = fuse_get_root_inode(sb, ctx->rootmode);
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index cdd6f5c50d6d..e17c96fa876e 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -1827,6 +1827,7 @@ static int virtio_fs_init_fs_context(struct fs_context *fsc)
ctx = kzalloc_obj(struct fuse_fs_context);
if (!ctx)
return -ENOMEM;
+ ctx->is_virtiofs = true;
fsc->fs_private = ctx;
fsc->ops = &virtio_fs_context_ops;
return 0;
diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index 616430a2973c..cb9e9554f0ef 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -257,6 +257,7 @@
* - add backing_id_64 to fuse_open_out
* - add FUSE_NOTIFY_BACKING_MAP, fuse_notify_backing_map_out, fuse_extent
* - add FUSE_BACKING_MAP_CREATE, FUSE_BACKING_MAP_CYCLIC
+ * - extend the meaning of FUSE_HAS_INODE_DAX and FUSE_ATTR_DAX
*/
#ifndef _LINUX_FUSE_H
@@ -460,7 +461,11 @@ struct fuse_file_lock {
* FUSE_INIT_RESERVED: reserved, do not use
* FUSE_SECURITY_CTX: add security context to create, mkdir, symlink, and
* mknod
- * FUSE_HAS_INODE_DAX: use per inode DAX
+ * FUSE_HAS_INODE_DAX: use per inode DAX. The meaning depends on the
+ * transport: on virtio-fs it indicates per-inode DAX
+ * support, while on /dev/fuse (where FUSE_PASSTHROUGH_V2
+ * is also offered) it indicates support for passthrough
+ * extent maps on a DAX device.
* FUSE_CREATE_SUPP_GROUP: add supplementary group info to create, mkdir,
* symlink and mknod (single group that matches parent)
* FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
@@ -612,7 +617,8 @@ struct fuse_file_lock {
* fuse_attr flags
*
* FUSE_ATTR_SUBMOUNT: Object is a submount root
- * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode
+ * FUSE_ATTR_DAX: Enable DAX for this file in per inode DAX mode and in
+ * extent mapping passthrough mode
*/
#define FUSE_ATTR_SUBMOUNT (1 << 0)
#define FUSE_ATTR_DAX (1 << 1)