diff options
| -rw-r--r-- | fs/fuse/Kconfig | 8 | ||||
| -rw-r--r-- | fs/fuse/Makefile | 2 | ||||
| -rw-r--r-- | fs/fuse/backing.c | 2 | ||||
| -rw-r--r-- | fs/fuse/dax.c | 215 | ||||
| -rw-r--r-- | fs/fuse/dev.c | 50 | ||||
| -rw-r--r-- | fs/fuse/dev.h | 2 | ||||
| -rw-r--r-- | fs/fuse/dev_uring.c | 6 | ||||
| -rw-r--r-- | fs/fuse/dir.c | 4 | ||||
| -rw-r--r-- | fs/fuse/file.c | 129 | ||||
| -rw-r--r-- | fs/fuse/fuse_i.h | 98 | ||||
| -rw-r--r-- | fs/fuse/inode.c | 82 | ||||
| -rw-r--r-- | fs/fuse/ioctl.c | 3 | ||||
| -rw-r--r-- | fs/fuse/iomode.c | 4 | ||||
| -rw-r--r-- | fs/fuse/notify.c | 4 | ||||
| -rw-r--r-- | fs/fuse/passthrough.c | 13 | ||||
| -rw-r--r-- | fs/fuse/req.c | 7 | ||||
| -rw-r--r-- | fs/fuse/virtio_fs.c | 28 | ||||
| -rw-r--r-- | include/uapi/linux/fuse.h | 12 | ||||
| -rw-r--r-- | tools/testing/selftests/filesystems/fuse/.gitignore | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/filesystems/fuse/Makefile | 2 |
20 files changed, 380 insertions, 292 deletions
diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig index 3a4ae632c94a..3d1e52896b87 100644 --- a/fs/fuse/Kconfig +++ b/fs/fuse/Kconfig @@ -40,9 +40,9 @@ config VIRTIO_FS If you want to share files between guests or with the host, answer Y or M. -config FUSE_DAX +config FUSE_VDAX bool "Virtio Filesystem Direct Host Memory Access support" - default y + default FUSE_DAX select INTERVAL_TREE depends on VIRTIO_FS depends on FS_DAX @@ -54,6 +54,10 @@ config FUSE_DAX If you want to allow mounting a Virtio Filesystem with the "dax" option, answer Y. +config FUSE_DAX + bool + transitional + config FUSE_PASSTHROUGH bool "FUSE passthrough operations support" default y diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile index 245e67852b03..5858feafa916 100644 --- a/fs/fuse/Makefile +++ b/fs/fuse/Makefile @@ -14,7 +14,7 @@ fuse-y := trace.o # put trace.o first so we see ftrace errors sooner fuse-y += dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o ioctl.o req_timeout.o req.o fuse-y += poll.o notify.o fuse-y += iomode.o -fuse-$(CONFIG_FUSE_DAX) += dax.o +fuse-$(CONFIG_FUSE_VDAX) += dax.o fuse-$(CONFIG_FUSE_PASSTHROUGH) += passthrough.o backing.o fuse-$(CONFIG_SYSCTL) += sysctl.o fuse-$(CONFIG_FUSE_IO_URING) += dev_uring.o diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 472b6afa7dff..433fa3098d71 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -10,7 +10,7 @@ #include <linux/file.h> -struct fuse_backing *fuse_backing_get(struct fuse_backing *fb) +static struct fuse_backing *fuse_backing_get(struct fuse_backing *fb) { if (fb && refcount_inc_not_zero(&fb->count)) return fb; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 85cdf0199bc0..7905e7b36644 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * dax: direct host memory access + * dax: direct host memory access for virtiofs * Copyright (C) 2020 Red Hat, Inc. */ @@ -59,7 +59,7 @@ struct fuse_dax_mapping { }; /* Per-inode dax map */ -struct fuse_inode_dax { +struct fuse_inode_vdax { /* Semaphore to protect modifications to the dmap tree */ struct rw_semaphore sem; @@ -68,7 +68,7 @@ struct fuse_inode_dax { unsigned long nr; }; -struct fuse_conn_dax { +struct fuse_conn_vdax { /* DAX device */ struct dax_device *dev; @@ -102,10 +102,10 @@ node_to_dmap(struct interval_tree_node *node) } static struct fuse_dax_mapping * -alloc_dax_mapping_reclaim(struct fuse_conn_dax *fcd, struct inode *inode); +alloc_dax_mapping_reclaim(struct fuse_conn_vdax *fcd, struct inode *inode); static void -__kick_dmap_free_worker(struct fuse_conn_dax *fcd, unsigned long delay_ms) +__kick_dmap_free_worker(struct fuse_conn_vdax *fcd, unsigned long delay_ms) { unsigned long free_threshold; @@ -117,7 +117,7 @@ __kick_dmap_free_worker(struct fuse_conn_dax *fcd, unsigned long delay_ms) msecs_to_jiffies(delay_ms)); } -static void kick_dmap_free_worker(struct fuse_conn_dax *fcd, +static void kick_dmap_free_worker(struct fuse_conn_vdax *fcd, unsigned long delay_ms) { spin_lock(&fcd->lock); @@ -125,7 +125,7 @@ static void kick_dmap_free_worker(struct fuse_conn_dax *fcd, spin_unlock(&fcd->lock); } -static struct fuse_dax_mapping *alloc_dax_mapping(struct fuse_conn_dax *fcd) +static struct fuse_dax_mapping *alloc_dax_mapping(struct fuse_conn_vdax *fcd) { struct fuse_dax_mapping *dmap; @@ -144,7 +144,7 @@ static struct fuse_dax_mapping *alloc_dax_mapping(struct fuse_conn_dax *fcd) } /* This assumes fcd->lock is held */ -static void __dmap_remove_busy_list(struct fuse_conn_dax *fcd, +static void __dmap_remove_busy_list(struct fuse_conn_vdax *fcd, struct fuse_dax_mapping *dmap) { list_del_init(&dmap->busy_list); @@ -152,7 +152,7 @@ static void __dmap_remove_busy_list(struct fuse_conn_dax *fcd, fcd->nr_busy_ranges--; } -static void dmap_remove_busy_list(struct fuse_conn_dax *fcd, +static void dmap_remove_busy_list(struct fuse_conn_vdax *fcd, struct fuse_dax_mapping *dmap) { spin_lock(&fcd->lock); @@ -161,7 +161,7 @@ static void dmap_remove_busy_list(struct fuse_conn_dax *fcd, } /* This assumes fcd->lock is held */ -static void __dmap_add_to_free_pool(struct fuse_conn_dax *fcd, +static void __dmap_add_to_free_pool(struct fuse_conn_vdax *fcd, struct fuse_dax_mapping *dmap) { list_add_tail(&dmap->list, &fcd->free_ranges); @@ -169,7 +169,7 @@ static void __dmap_add_to_free_pool(struct fuse_conn_dax *fcd, wake_up(&fcd->range_waitq); } -static void dmap_add_to_free_pool(struct fuse_conn_dax *fcd, +static void dmap_add_to_free_pool(struct fuse_conn_vdax *fcd, struct fuse_dax_mapping *dmap) { /* Return fuse_dax_mapping to free list */ @@ -183,7 +183,7 @@ static int fuse_setup_one_mapping(struct inode *inode, unsigned long start_idx, bool upgrade) { struct fuse_mount *fm = get_fuse_mount(inode); - struct fuse_conn_dax *fcd = fm->fc->dax; + struct fuse_conn_vdax *fcd = fm->fc->vdax; struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_setupmapping_in inarg; loff_t offset = start_idx << FUSE_DAX_SHIFT; @@ -218,9 +218,9 @@ static int fuse_setup_one_mapping(struct inode *inode, unsigned long start_idx, */ dmap->inode = inode; dmap->itn.start = dmap->itn.last = start_idx; - /* Protected by fi->dax->sem */ - interval_tree_insert(&dmap->itn, &fi->dax->tree); - fi->dax->nr++; + /* Protected by fi->vdax->sem */ + interval_tree_insert(&dmap->itn, &fi->vdax->tree); + fi->vdax->nr++; spin_lock(&fcd->lock); list_add_tail(&dmap->busy_list, &fcd->busy_ranges); fcd->nr_busy_ranges++; @@ -288,7 +288,7 @@ out: * Cleanup dmap entry and add back to free list. This should be called with * fcd->lock held. */ -static void dmap_reinit_add_to_free_pool(struct fuse_conn_dax *fcd, +static void dmap_reinit_add_to_free_pool(struct fuse_conn_vdax *fcd, struct fuse_dax_mapping *dmap) { pr_debug("fuse: freeing memory range start_idx=0x%lx end_idx=0x%lx window_offset=0x%llx length=0x%llx\n", @@ -306,7 +306,7 @@ static void dmap_reinit_add_to_free_pool(struct fuse_conn_dax *fcd, * called from evict_inode() path where we know all dmap entries can be * reclaimed. */ -static void inode_reclaim_dmap_range(struct fuse_conn_dax *fcd, +static void inode_reclaim_dmap_range(struct fuse_conn_vdax *fcd, struct inode *inode, loff_t start, loff_t end) { @@ -319,14 +319,14 @@ static void inode_reclaim_dmap_range(struct fuse_conn_dax *fcd, struct interval_tree_node *node; while (1) { - node = interval_tree_iter_first(&fi->dax->tree, start_idx, + node = interval_tree_iter_first(&fi->vdax->tree, start_idx, end_idx); if (!node) break; dmap = node_to_dmap(node); /* inode is going away. There should not be any users of dmap */ WARN_ON(refcount_read(&dmap->refcnt) > 1); - interval_tree_remove(&dmap->itn, &fi->dax->tree); + interval_tree_remove(&dmap->itn, &fi->vdax->tree); num++; list_add(&dmap->list, &to_remove); } @@ -335,8 +335,8 @@ static void inode_reclaim_dmap_range(struct fuse_conn_dax *fcd, if (list_empty(&to_remove)) return; - WARN_ON(fi->dax->nr < num); - fi->dax->nr -= num; + 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", @@ -367,11 +367,11 @@ static int dmap_removemapping_one(struct inode *inode, /* * It is called from evict_inode() and by that time inode is going away. So - * this function does not take any locks like fi->dax->sem for traversing + * this function does not take any locks like fi->vdax->sem for traversing * that fuse inode interval tree. If that lock is taken then lock validator * complains of deadlock situation w.r.t fs_reclaim lock. */ -void fuse_dax_inode_cleanup(struct inode *inode) +void fuse_vdax_inode_cleanup(struct inode *inode) { struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_inode *fi = get_fuse_inode(inode); @@ -381,8 +381,8 @@ void fuse_dax_inode_cleanup(struct inode *inode) * before we arrive here. So we should not have to worry about any * pages/exception entries still associated with inode. */ - inode_reclaim_dmap_range(fc->dax, inode, 0, -1); - WARN_ON(fi->dax->nr); + inode_reclaim_dmap_range(fc->vdax, inode, 0, -1); + WARN_ON(fi->vdax->nr); } static void fuse_fill_iomap_hole(struct iomap *iomap, loff_t length) @@ -414,7 +414,7 @@ static void fuse_fill_iomap(struct inode *inode, loff_t pos, loff_t length, iomap->type = IOMAP_MAPPED; /* * increace refcnt so that reclaim code knows this dmap is in - * use. This assumes fi->dax->sem mutex is held either + * use. This assumes fi->vdax->sem mutex is held either * shared/exclusive. */ refcount_inc(&dmap->refcnt); @@ -434,7 +434,7 @@ static int fuse_setup_new_dax_mapping(struct inode *inode, loff_t pos, { struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_conn *fc = get_fuse_conn(inode); - struct fuse_conn_dax *fcd = fc->dax; + struct fuse_conn_vdax *fcd = fc->vdax; struct fuse_dax_mapping *dmap, *alloc_dmap = NULL; int ret; bool writable = flags & IOMAP_WRITE; @@ -469,17 +469,17 @@ static int fuse_setup_new_dax_mapping(struct inode *inode, loff_t pos, * Take write lock so that only one caller can try to setup mapping * and other waits. */ - down_write(&fi->dax->sem); + down_write(&fi->vdax->sem); /* * We dropped lock. Check again if somebody else setup * mapping already. */ - node = interval_tree_iter_first(&fi->dax->tree, start_idx, start_idx); + node = interval_tree_iter_first(&fi->vdax->tree, start_idx, start_idx); if (node) { dmap = node_to_dmap(node); fuse_fill_iomap(inode, pos, length, iomap, dmap, flags); dmap_add_to_free_pool(fcd, alloc_dmap); - up_write(&fi->dax->sem); + up_write(&fi->vdax->sem); return 0; } @@ -488,11 +488,11 @@ static int fuse_setup_new_dax_mapping(struct inode *inode, loff_t pos, writable, false); if (ret < 0) { dmap_add_to_free_pool(fcd, alloc_dmap); - up_write(&fi->dax->sem); + up_write(&fi->vdax->sem); return ret; } fuse_fill_iomap(inode, pos, length, iomap, alloc_dmap, flags); - up_write(&fi->dax->sem); + up_write(&fi->vdax->sem); return 0; } @@ -510,14 +510,14 @@ static int fuse_upgrade_dax_mapping(struct inode *inode, loff_t pos, * Take exclusive lock so that only one caller can try to setup * mapping and others wait. */ - down_write(&fi->dax->sem); - node = interval_tree_iter_first(&fi->dax->tree, idx, idx); + down_write(&fi->vdax->sem); + node = interval_tree_iter_first(&fi->vdax->tree, idx, idx); /* We are holding either inode lock or invalidate_lock, and that should * ensure that dmap can't be truncated. We are holding a reference * on dmap and that should make sure it can't be reclaimed. So dmap * should still be there in tree despite the fact we dropped and - * re-acquired the fi->dax->sem lock. + * re-acquired the fi->vdax->sem lock. */ ret = -EIO; if (WARN_ON(!node)) @@ -526,7 +526,7 @@ static int fuse_upgrade_dax_mapping(struct inode *inode, loff_t pos, dmap = node_to_dmap(node); /* We took an extra reference on dmap to make sure its not reclaimd. - * Now we hold fi->dax->sem lock and that reference is not needed + * Now we hold fi->vdax->sem lock and that reference is not needed * anymore. Drop it. */ if (refcount_dec_and_test(&dmap->refcnt)) { @@ -551,7 +551,7 @@ static int fuse_upgrade_dax_mapping(struct inode *inode, loff_t pos, out_fill_iomap: fuse_fill_iomap(inode, pos, length, iomap, dmap, flags); out_err: - up_write(&fi->dax->sem); + up_write(&fi->vdax->sem); return ret; } @@ -576,7 +576,7 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t length, iomap->offset = pos; iomap->flags = 0; iomap->bdev = NULL; - iomap->dax_dev = fc->dax->dev; + iomap->dax_dev = fc->vdax->dev; /* * Both read/write and mmap path can race here. So we need something @@ -585,33 +585,33 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t length, * For now, use a semaphore for this. It probably needs to be * optimized later. */ - down_read(&fi->dax->sem); - node = interval_tree_iter_first(&fi->dax->tree, start_idx, start_idx); + down_read(&fi->vdax->sem); + node = interval_tree_iter_first(&fi->vdax->tree, start_idx, start_idx); if (node) { dmap = node_to_dmap(node); if (writable && !dmap->writable) { /* Upgrade read-only mapping to read-write. This will - * require exclusive fi->dax->sem lock as we don't want + * require exclusive fi->vdax->sem lock as we don't want * two threads to be trying to this simultaneously * for same dmap. So drop shared lock and acquire * exclusive lock. * - * Before dropping fi->dax->sem lock, take reference + * Before dropping fi->vdax->sem lock, take reference * on dmap so that its not freed by range reclaim. */ refcount_inc(&dmap->refcnt); - up_read(&fi->dax->sem); + up_read(&fi->vdax->sem); pr_debug("%s: Upgrading mapping at offset 0x%llx length 0x%llx\n", __func__, pos, length); return fuse_upgrade_dax_mapping(inode, pos, length, flags, iomap); } else { fuse_fill_iomap(inode, pos, length, iomap, dmap, flags); - up_read(&fi->dax->sem); + up_read(&fi->vdax->sem); return 0; } } else { - up_read(&fi->dax->sem); + up_read(&fi->vdax->sem); pr_debug("%s: no mapping at offset 0x%llx length 0x%llx\n", __func__, pos, length); if (pos >= i_size_read(inode)) @@ -668,14 +668,14 @@ static void fuse_wait_dax_page(struct inode *inode) } /* Should be called with mapping->invalidate_lock held exclusively. */ -int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, +int fuse_vdax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end) { return dax_break_layout(inode, dmap_start, dmap_end, fuse_wait_dax_page); } -ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) +ssize_t fuse_vdax_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct inode *inode = file_inode(iocb->ki_filp); ssize_t ret; @@ -715,7 +715,7 @@ static ssize_t fuse_dax_direct_write(struct kiocb *iocb, struct iov_iter *from) return ret; } -ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from) +ssize_t fuse_vdax_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct inode *inode = file_inode(iocb->ki_filp); ssize_t ret; @@ -761,7 +761,7 @@ static vm_fault_t __fuse_dax_fault(struct vm_fault *vmf, unsigned int order, unsigned long pfn; int error = 0; struct fuse_conn *fc = get_fuse_conn(inode); - struct fuse_conn_dax *fcd = fc->dax; + struct fuse_conn_vdax *fcd = fc->vdax; bool retry = false; if (write) @@ -822,11 +822,12 @@ static const struct vm_operations_struct fuse_dax_vm_ops = { .pfn_mkwrite = fuse_dax_pfn_mkwrite, }; -int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma) +int fuse_vdax_mmap(struct file *file, struct vm_area_struct *vma) { file_accessed(file); vma->vm_ops = &fuse_dax_vm_ops; vm_flags_set(vma, VM_MIXEDMAP | VM_HUGEPAGE); + vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); return 0; } @@ -869,8 +870,8 @@ static int reclaim_one_dmap_locked(struct inode *inode, return ret; /* Remove dax mapping from inode interval tree now */ - interval_tree_remove(&dmap->itn, &fi->dax->tree); - fi->dax->nr--; + 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 @@ -885,7 +886,7 @@ static int reclaim_one_dmap_locked(struct inode *inode, } /* Find first mapped dmap for an inode and return file offset. Caller needs - * to hold fi->dax->sem lock either shared or exclusive. + * to hold fi->vdax->sem lock either shared or exclusive. */ static struct fuse_dax_mapping *inode_lookup_first_dmap(struct inode *inode) { @@ -893,7 +894,7 @@ static struct fuse_dax_mapping *inode_lookup_first_dmap(struct inode *inode) struct fuse_dax_mapping *dmap; struct interval_tree_node *node; - for (node = interval_tree_iter_first(&fi->dax->tree, 0, -1); node; + for (node = interval_tree_iter_first(&fi->vdax->tree, 0, -1); node; node = interval_tree_iter_next(node, 0, -1)) { dmap = node_to_dmap(node); /* still in use. */ @@ -911,7 +912,7 @@ static struct fuse_dax_mapping *inode_lookup_first_dmap(struct inode *inode) * it back to free pool. */ static struct fuse_dax_mapping * -inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode, +inode_inline_reclaim_one_dmap(struct fuse_conn_vdax *fcd, struct inode *inode, bool *retry) { struct fuse_inode *fi = get_fuse_inode(inode); @@ -924,14 +925,14 @@ inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode, filemap_invalidate_lock(inode->i_mapping); /* Lookup a dmap and corresponding file offset to reclaim. */ - down_read(&fi->dax->sem); + down_read(&fi->vdax->sem); dmap = inode_lookup_first_dmap(inode); if (dmap) { start_idx = dmap->itn.start; dmap_start = start_idx << FUSE_DAX_SHIFT; dmap_end = dmap_start + FUSE_DAX_SZ - 1; } - up_read(&fi->dax->sem); + up_read(&fi->vdax->sem); if (!dmap) goto out_mmap_sem; @@ -939,16 +940,16 @@ inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode, * Make sure there are no references to inode pages using * get_user_pages() */ - ret = fuse_dax_break_layouts(inode, dmap_start, dmap_end); + ret = fuse_vdax_break_layouts(inode, dmap_start, dmap_end); if (ret) { - pr_debug("fuse: fuse_dax_break_layouts() failed. err=%d\n", + pr_debug("fuse: fuse_vdax_break_layouts() failed. err=%d\n", ret); dmap = ERR_PTR(ret); goto out_mmap_sem; } - down_write(&fi->dax->sem); - node = interval_tree_iter_first(&fi->dax->tree, start_idx, start_idx); + down_write(&fi->vdax->sem); + node = interval_tree_iter_first(&fi->vdax->tree, start_idx, start_idx); /* Range already got reclaimed by somebody else */ if (!node) { if (retry) @@ -980,14 +981,14 @@ inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode, __func__, inode, dmap->window_offset, dmap->length); out_write_dmap_sem: - up_write(&fi->dax->sem); + up_write(&fi->vdax->sem); out_mmap_sem: filemap_invalidate_unlock(inode->i_mapping); return dmap; } static struct fuse_dax_mapping * -alloc_dax_mapping_reclaim(struct fuse_conn_dax *fcd, struct inode *inode) +alloc_dax_mapping_reclaim(struct fuse_conn_vdax *fcd, struct inode *inode) { struct fuse_dax_mapping *dmap; struct fuse_inode *fi = get_fuse_inode(inode); @@ -1014,18 +1015,18 @@ alloc_dax_mapping_reclaim(struct fuse_conn_dax *fcd, struct inode *inode) * if a deadlock is possible if we sleep with * mapping->invalidate_lock held and worker to free memory * can't make progress due to unavailability of - * mapping->invalidate_lock. So sleep only if fi->dax->nr=0 + * mapping->invalidate_lock. So sleep only if fi->vdax->nr=0 */ if (retry) continue; /* * There are no mappings which can be reclaimed. Wait for one. - * We are not holding fi->dax->sem. So it is possible + * We are not holding fi->vdax->sem. So it is possible * that range gets added now. But as we are not holding * mapping->invalidate_lock, worker should still be able to * free up a range and wake us up. */ - if (!fi->dax->nr && !(fcd->nr_free_ranges > 0)) { + if (!fi->vdax->nr && !(fcd->nr_free_ranges > 0)) { if (wait_event_killable_exclusive(fcd->range_waitq, (fcd->nr_free_ranges > 0))) { return ERR_PTR(-EINTR); @@ -1034,7 +1035,7 @@ alloc_dax_mapping_reclaim(struct fuse_conn_dax *fcd, struct inode *inode) } } -static int lookup_and_reclaim_dmap_locked(struct fuse_conn_dax *fcd, +static int lookup_and_reclaim_dmap_locked(struct fuse_conn_vdax *fcd, struct inode *inode, unsigned long start_idx) { @@ -1044,7 +1045,7 @@ static int lookup_and_reclaim_dmap_locked(struct fuse_conn_dax *fcd, struct interval_tree_node *node; /* Find fuse dax mapping at file offset inode. */ - node = interval_tree_iter_first(&fi->dax->tree, start_idx, start_idx); + node = interval_tree_iter_first(&fi->vdax->tree, start_idx, start_idx); /* Range already got cleaned up by somebody else */ if (!node) @@ -1070,10 +1071,10 @@ static int lookup_and_reclaim_dmap_locked(struct fuse_conn_dax *fcd, * Free a range of memory. * Locking: * 1. Take mapping->invalidate_lock to block dax faults. - * 2. Take fi->dax->sem to protect interval tree and also to make sure + * 2. Take fi->vdax->sem to protect interval tree and also to make sure * read/write can not reuse a dmap which we might be freeing. */ -static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd, +static int lookup_and_reclaim_dmap(struct fuse_conn_vdax *fcd, struct inode *inode, unsigned long start_idx, unsigned long end_idx) @@ -1084,22 +1085,22 @@ static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd, loff_t dmap_end = (dmap_start + FUSE_DAX_SZ) - 1; filemap_invalidate_lock(inode->i_mapping); - ret = fuse_dax_break_layouts(inode, dmap_start, dmap_end); + ret = fuse_vdax_break_layouts(inode, dmap_start, dmap_end); if (ret) { - pr_debug("virtio_fs: fuse_dax_break_layouts() failed. err=%d\n", + pr_debug("virtio_fs: fuse_vdax_break_layouts() failed. err=%d\n", ret); goto out_mmap_sem; } - down_write(&fi->dax->sem); + down_write(&fi->vdax->sem); ret = lookup_and_reclaim_dmap_locked(fcd, inode, start_idx); - up_write(&fi->dax->sem); + up_write(&fi->vdax->sem); out_mmap_sem: filemap_invalidate_unlock(inode->i_mapping); return ret; } -static int try_to_free_dmap_chunks(struct fuse_conn_dax *fcd, +static int try_to_free_dmap_chunks(struct fuse_conn_vdax *fcd, unsigned long nr_to_free) { struct fuse_dax_mapping *dmap, *pos, *temp; @@ -1160,7 +1161,7 @@ static int try_to_free_dmap_chunks(struct fuse_conn_dax *fcd, static void fuse_dax_free_mem_worker(struct work_struct *work) { int ret; - struct fuse_conn_dax *fcd = container_of(work, struct fuse_conn_dax, + struct fuse_conn_vdax *fcd = container_of(work, struct fuse_conn_vdax, free_work.work); ret = try_to_free_dmap_chunks(fcd, FUSE_DAX_RECLAIM_CHUNK); if (ret) { @@ -1185,16 +1186,16 @@ static void fuse_free_dax_mem_ranges(struct list_head *mem_list) } } -void fuse_dax_conn_free(struct fuse_conn *fc) +void fuse_vdax_conn_free(struct fuse_conn *fc) { - if (fc->dax) { - fuse_free_dax_mem_ranges(&fc->dax->free_ranges); - kfree(fc->dax); - fc->dax = NULL; + if (fc->vdax) { + fuse_free_dax_mem_ranges(&fc->vdax->free_ranges); + kfree(fc->vdax); + fc->vdax = NULL; } } -static int fuse_dax_mem_range_init(struct fuse_conn_dax *fcd) +static int fuse_dax_mem_range_init(struct fuse_conn_vdax *fcd) { long nr_pages, nr_ranges; struct fuse_dax_mapping *range; @@ -1246,13 +1247,13 @@ out_err: return ret; } -int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode dax_mode, +int fuse_vdax_conn_alloc(struct fuse_conn *fc, enum fuse_vdax_mode dax_mode, struct dax_device *dax_dev) { - struct fuse_conn_dax *fcd; + struct fuse_conn_vdax *fcd; int err; - fc->dax_mode = dax_mode; + fc->vdax_mode = dax_mode; if (!dax_dev) return 0; @@ -1269,22 +1270,22 @@ int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode dax_mode, return err; } - fc->dax = fcd; + fc->vdax = fcd; return 0; } -bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi) +bool fuse_vdax_inode_alloc(struct super_block *sb, struct fuse_inode *fi) { struct fuse_conn *fc = get_fuse_conn_super(sb); - fi->dax = NULL; - if (fc->dax) { - fi->dax = kzalloc_obj(*fi->dax, GFP_KERNEL_ACCOUNT); - if (!fi->dax) + fi->vdax = NULL; + if (fc->vdax) { + fi->vdax = kzalloc_obj(*fi->vdax, GFP_KERNEL_ACCOUNT); + if (!fi->vdax) return false; - init_rwsem(&fi->dax->sem); - fi->dax->tree = RB_ROOT_CACHED; + init_rwsem(&fi->vdax->sem); + fi->vdax->tree = RB_ROOT_CACHED; } return true; @@ -1298,26 +1299,26 @@ static const struct address_space_operations fuse_dax_file_aops = { static bool fuse_should_enable_dax(struct inode *inode, unsigned int flags) { struct fuse_conn *fc = get_fuse_conn(inode); - enum fuse_dax_mode dax_mode = fc->dax_mode; + enum fuse_vdax_mode dax_mode = fc->vdax_mode; - if (dax_mode == FUSE_DAX_NEVER) + if (dax_mode == FUSE_VDAX_NEVER) return false; /* - * fc->dax may be NULL in 'inode' mode when filesystem device doesn't + * fc->vdax may be NULL in 'inode' mode when filesystem device doesn't * support DAX, in which case it will silently fallback to 'never' mode. */ - if (!fc->dax) + if (!fc->vdax) return false; - if (dax_mode == FUSE_DAX_ALWAYS) + if (dax_mode == FUSE_VDAX_ALWAYS) return true; /* dax_mode is FUSE_DAX_INODE* */ - return fc->inode_dax && (flags & FUSE_ATTR_DAX); + return fc->inode_vdax && (flags & FUSE_ATTR_DAX); } -void fuse_dax_inode_init(struct inode *inode, unsigned int flags) +void fuse_vdax_inode_init(struct inode *inode, unsigned int flags) { if (!fuse_should_enable_dax(inode, flags)) return; @@ -1326,18 +1327,18 @@ void fuse_dax_inode_init(struct inode *inode, unsigned int flags) inode->i_data.a_ops = &fuse_dax_file_aops; } -void fuse_dax_dontcache(struct inode *inode, unsigned int flags) +void fuse_vdax_dontcache(struct inode *inode, unsigned int flags) { struct fuse_conn *fc = get_fuse_conn(inode); - if (fuse_is_inode_dax_mode(fc->dax_mode) && + if (fuse_is_inode_vdax_mode(fc->vdax_mode) && ((bool) IS_DAX(inode) != (bool) (flags & FUSE_ATTR_DAX))) d_mark_dontcache(inode); } -bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment) +bool fuse_vdax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment) { - if (fc->dax && (map_alignment > FUSE_DAX_SHIFT)) { + if (fc->vdax && (map_alignment > FUSE_DAX_SHIFT)) { pr_warn("FUSE: map_alignment %u incompatible with dax mem range size %u\n", map_alignment, FUSE_DAX_SZ); return false; @@ -1345,12 +1346,12 @@ bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment) return true; } -void fuse_dax_cancel_work(struct fuse_conn *fc) +void fuse_vdax_cancel_work(struct fuse_conn *fc) { - struct fuse_conn_dax *fcd = fc->dax; + struct fuse_conn_vdax *fcd = fc->vdax; if (fcd) cancel_delayed_work_sync(&fcd->free_work); } -EXPORT_SYMBOL_GPL(fuse_dax_cancel_work); +EXPORT_SYMBOL_GPL(fuse_vdax_cancel_work); diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 4fec31fc0b84..2d7ee5498f1c 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1061,7 +1061,8 @@ static int fuse_copy_fill(struct fuse_copy_state *cs) err = iov_iter_get_pages2(cs->iter, &page, PAGE_SIZE, 1, &off); if (err < 0) return err; - BUG_ON(!err); + if (!err) + return -EIO; cs->len = err; cs->offset = off; cs->pg = page; @@ -1252,31 +1253,10 @@ static int fuse_ref_folio(struct fuse_copy_state *cs, struct folio *folio, * done atomically */ int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop, - unsigned offset, unsigned count, int zeroing) + unsigned offset, unsigned count) { int err; struct folio *folio = *foliop; - size_t size; - - if (folio) { - size = folio_size(folio); - if (zeroing && count < size) { - /* - * When the copy is skipped the folio already holds the - * payload, so only the bytes outside [offset, offset + - * count) may be zeroed. - * - * Otherwise, the whole folio is cleared first so that a - * failed copy leaves zeros rather than stale folio - * contents. - */ - if (cs->skip_folio_copy) - folio_zero_segments(folio, 0, offset, - offset + count, size); - else - folio_zero_range(folio, 0, size); - } - } while (!cs->skip_folio_copy && count) { if (cs->write && cs->pipebufs && folio) { @@ -1293,7 +1273,7 @@ int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop, } } else if (!cs->len) { if (cs->move_folios && folio && - offset == 0 && count == size) { + offset == 0 && count == folio_size(folio)) { err = fuse_try_move_folio(cs, foliop); if (err <= 0) return err; @@ -1309,7 +1289,8 @@ int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop, unsigned int copy = count; unsigned int bytes_copied; - if (folio_test_highmem(folio) && count > PAGE_SIZE - offset_in_page(offset)) + if (folio_test_partial_kmap(folio) && + count > PAGE_SIZE - offset_in_page(offset)) copy = PAGE_SIZE - offset_in_page(offset); bytes_copied = fuse_copy_do(cs, &buf, ©); @@ -1334,10 +1315,25 @@ static int fuse_copy_folios(struct fuse_copy_state *cs, unsigned nbytes, for (i = 0; i < ap->num_folios && (nbytes || zeroing); i++) { int err; + struct folio *folio = ap->folios[i]; unsigned int offset = ap->descs[i].offset; - unsigned int count = min(nbytes, ap->descs[i].length); + unsigned int length = ap->descs[i].length; + unsigned int count = min(nbytes, length); + + /* + * The reply may be shorter than what was asked for. The full + * descs[i].length is reported as read, so the tail bytes the + * server did not send are about to be marked uptodate and need + * to be zeroed. + * + * Only [offset, offset + length) can be touched since the + * rest of the folio can hold blocks that are already uptodate + * or dirty, and clearing those would lose data. + */ + if (folio && zeroing && count < length) + folio_zero_range(folio, offset + count, length - count); - err = fuse_copy_folio(cs, &ap->folios[i], offset, count, zeroing); + err = fuse_copy_folio(cs, &ap->folios[i], offset, count); if (err) return err; diff --git a/fs/fuse/dev.h b/fs/fuse/dev.h index 8d25378c0918..f6c47ae0395b 100644 --- a/fs/fuse/dev.h +++ b/fs/fuse/dev.h @@ -90,7 +90,7 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id); int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size); int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop, - unsigned offset, unsigned count, int zeroing); + unsigned offset, unsigned count); void fuse_copy_finish(struct fuse_copy_state *cs); #ifdef CONFIG_FUSE_IO_URING diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c index c6dd420c4034..460776cd69cd 100644 --- a/fs/fuse/dev_uring.c +++ b/fs/fuse/dev_uring.c @@ -893,6 +893,12 @@ static int fuse_uring_args_to_ring(struct fuse_req *req, fuse_copy_finish(&cs); if (err) { pr_info_ratelimited("%s fuse_copy_args failed\n", __func__); + /* + * fuse-uring does not use pipe buffers, so -EIO here can only + * mean the in-args did not fit ent->payload + */ + if (err == -EIO && args->opcode == FUSE_SETXATTR) + err = -E2BIG; return err; } diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index e49b4e874b15..f48fafccce4b 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -2174,10 +2174,10 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry, is_truncate = true; } - if (FUSE_IS_DAX(inode) && is_truncate) { + if (FUSE_IS_VDAX(inode) && is_truncate) { filemap_invalidate_lock(mapping); fault_blocked = true; - err = fuse_dax_break_layouts(inode, 0, -1); + err = fuse_vdax_break_layouts(inode, 0, -1); if (err) goto unlock; } diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 9a36d0329e22..d73afcbc1eb2 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -119,7 +119,7 @@ static void fuse_file_put(struct fuse_file *ff, bool sync) * DAX inodes may need to issue a number of synchronous * request for clearing the mappings. */ - if (ra && ra->inode && FUSE_IS_DAX(ra->inode)) + if (ra && ra->inode && FUSE_IS_VDAX(ra->inode)) args->may_block = true; args->end = fuse_release_end; if (fuse_simple_background(ff->fm, args, @@ -256,7 +256,7 @@ static int fuse_open(struct inode *inode, struct file *file) int err; bool is_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc; bool is_wb_truncate = is_truncate && fc->writeback_cache; - bool dax_truncate = is_truncate && FUSE_IS_DAX(inode); + bool vdax_truncate = is_truncate && FUSE_IS_VDAX(inode); if (fuse_is_bad(inode)) return -EIO; @@ -265,17 +265,17 @@ static int fuse_open(struct inode *inode, struct file *file) if (err) return err; - if (is_wb_truncate || dax_truncate) + if (is_wb_truncate || vdax_truncate) inode_lock(inode); - if (dax_truncate) { + if (vdax_truncate) { filemap_invalidate_lock(inode->i_mapping); - err = fuse_dax_break_layouts(inode, 0, -1); + err = fuse_vdax_break_layouts(inode, 0, -1); if (err) goto out_unlock; } - if (is_wb_truncate || dax_truncate) + if (is_wb_truncate || vdax_truncate) fuse_set_nowrite(inode); err = fuse_do_open(fm, get_node_id(inode), file, false); @@ -288,7 +288,7 @@ static int fuse_open(struct inode *inode, struct file *file) fuse_truncate_update_attr(inode, file); } - if (is_wb_truncate || dax_truncate) + if (is_wb_truncate || vdax_truncate) fuse_release_nowrite(inode); if (!err) { if (is_truncate) @@ -297,9 +297,9 @@ static int fuse_open(struct inode *inode, struct file *file) invalidate_inode_pages2(inode->i_mapping); } out_unlock: - if (dax_truncate) + if (vdax_truncate) filemap_invalidate_unlock(inode->i_mapping); - if (is_wb_truncate || dax_truncate) + if (is_wb_truncate || vdax_truncate) inode_unlock(inode); return err; @@ -311,7 +311,7 @@ static void fuse_prepare_release(struct fuse_inode *fi, struct fuse_file *ff, struct fuse_conn *fc = ff->fm->fc; struct fuse_release_args *ra = &ff->args->release_args; - if (fuse_file_passthrough(ff)) + if (fuse_is_passthrough(ff)) fuse_passthrough_release(ff, fuse_inode_backing(fi)); /* Inode is NULL on error path of fuse_create_open() */ @@ -689,7 +689,7 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos) struct address_space *mapping = io->iocb->ki_filp->f_mapping; ssize_t res = fuse_get_res_by_io(io); - if (res >= 0) { + if (res >= 0 && io->write) { struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_inode *fi = get_fuse_inode(inode); @@ -864,18 +864,29 @@ static int fuse_do_readfolio(struct file *file, struct folio *folio, attr_ver = fuse_get_attr_version(fm->fc); - /* Don't overflow end offset */ - if (pos + (desc.length - 1) == LLONG_MAX) - desc.length--; + /* + * Don't overflow end offset. + * + * Ask the server for len - 1 bytes. desc.length still holds the full + * length. When the reply comes back, it will be one byte shorter than + * desc.length and fuse_copy_folios() will zero that last byte. + * + * For this reason, desc.length must not be decremented too. The caller + * reports the full length to iomap_finish_folio_read(), which marks + * every block it covers uptodate. Shortening the descriptor would + * suppress zeroing and leave the last byte holding stale data. + */ + if (pos + (len - 1) == LLONG_MAX) + len--; - fuse_read_args_fill(&ia, file, pos, desc.length, FUSE_READ); + fuse_read_args_fill(&ia, file, pos, len, FUSE_READ); res = fuse_simple_request(fm, &ia.ap.args); if (res < 0) return res; /* * Short read means EOF. If file size is larger, truncate it */ - if (res < desc.length) + if (res < len) fuse_short_read(inode, attr_ver, res, &ia.ap); return 0; @@ -1068,11 +1079,20 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file, ap->args.page_zeroing = true; ap->args.page_replace = true; - /* Don't overflow end offset */ - if (pos + (count - 1) == LLONG_MAX) { + /* + * Don't overflow end offset. + * + * Ask the server for count - 1 bytes. The reply is then one byte + * shorter than what the descriptor lengths add up to, so + * fuse_copy_folios() zeroes the last byte when it walks the folios. + * + * ap->descs[] must not be decremented here. It is what + * fuse_readpages_end() reports back to iomap_finish_folio_read(), and + * iomap has already accounted the full descriptor length, so shortening + * it would leave ifs->read_bytes_pending nonzero and the folio locked. + */ + if (pos + (count - 1) == LLONG_MAX) count--; - ap->descs[ap->num_folios - 1].length--; - } WARN_ON((loff_t) (pos + count) < 0); fuse_read_args_fill(ia, file, pos, count, FUSE_READ); @@ -1835,13 +1855,13 @@ static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to) if (fuse_is_bad(inode)) return -EIO; - if (FUSE_IS_DAX(inode)) - return fuse_dax_read_iter(iocb, to); + if (FUSE_IS_VDAX(inode)) + return fuse_vdax_read_iter(iocb, to); /* FOPEN_DIRECT_IO overrides FOPEN_PASSTHROUGH */ if (ff->open_flags & FOPEN_DIRECT_IO) return fuse_direct_read_iter(iocb, to); - else if (fuse_file_passthrough(ff)) + else if (fuse_is_passthrough(ff)) return fuse_passthrough_read_iter(iocb, to); else return fuse_cache_read_iter(iocb, to); @@ -1856,13 +1876,13 @@ static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (fuse_is_bad(inode)) return -EIO; - if (FUSE_IS_DAX(inode)) - return fuse_dax_write_iter(iocb, from); + if (FUSE_IS_VDAX(inode)) + return fuse_vdax_write_iter(iocb, from); /* FOPEN_DIRECT_IO overrides FOPEN_PASSTHROUGH */ if (ff->open_flags & FOPEN_DIRECT_IO) return fuse_direct_write_iter(iocb, from); - else if (fuse_file_passthrough(ff)) + else if (fuse_is_passthrough(ff)) return fuse_passthrough_write_iter(iocb, from); else return fuse_cache_write_iter(iocb, from); @@ -1875,7 +1895,10 @@ static ssize_t fuse_splice_read(struct file *in, loff_t *ppos, struct fuse_file *ff = in->private_data; /* FOPEN_DIRECT_IO overrides FOPEN_PASSTHROUGH */ - if (fuse_file_passthrough(ff) && !(ff->open_flags & FOPEN_DIRECT_IO)) + + if (ff->open_flags & FOPEN_DIRECT_IO) + return copy_splice_read(in, ppos, pipe, len, flags); + else if (fuse_is_passthrough(ff)) return fuse_passthrough_splice_read(in, ppos, pipe, len, flags); else return filemap_splice_read(in, ppos, pipe, len, flags); @@ -1887,7 +1910,7 @@ static ssize_t fuse_splice_write(struct pipe_inode_info *pipe, struct file *out, struct fuse_file *ff = out->private_data; /* FOPEN_DIRECT_IO overrides FOPEN_PASSTHROUGH */ - if (fuse_file_passthrough(ff) && !(ff->open_flags & FOPEN_DIRECT_IO)) + if (fuse_is_passthrough(ff) && !(ff->open_flags & FOPEN_DIRECT_IO)) return fuse_passthrough_splice_write(pipe, out, ppos, len, flags); else return iter_file_splice_write(pipe, out, ppos, len, flags); @@ -2394,15 +2417,15 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) int rc; /* DAX mmap is superior to direct_io mmap */ - if (FUSE_IS_DAX(inode)) - return fuse_dax_mmap(file, vma); + if (FUSE_IS_VDAX(inode)) + return fuse_vdax_mmap(file, vma); /* * If inode is in passthrough io mode, because it has some file open * in passthrough mode, either mmap to backing file or fail mmap, * because mixing cached mmap and passthrough io mode is not allowed. */ - if (fuse_file_passthrough(ff)) + if (fuse_is_passthrough(ff)) return fuse_passthrough_mmap(file, vma); else if (fuse_inode_backing(get_fuse_inode(inode))) return -ENODEV; @@ -2844,7 +2867,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, .mode = mode }; int err; - bool block_faults = FUSE_IS_DAX(inode) && + bool block_faults = FUSE_IS_VDAX(inode) && (!(mode & FALLOC_FL_KEEP_SIZE) || (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))); @@ -2858,7 +2881,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, inode_lock(inode); if (block_faults) { filemap_invalidate_lock(inode->i_mapping); - err = fuse_dax_break_layouts(inode, 0, -1); + err = fuse_vdax_break_layouts(inode, 0, -1); if (err) goto out; } @@ -2978,14 +3001,16 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, /* * Write out dirty pages in the destination file before sending the COPY - * request to userspace. After the request is completed, truncate off - * pages (including partial ones) from the cache that have been copied, - * since these contain stale data at that point. + * request to userspace. After the request is completed, drop the + * folios covering the copied range from the cache, since these contain + * stale data at that point. * - * This should be mostly correct, but if the COPY writes to partial - * pages (at the start or end) and the parts not covered by the COPY are + * This should be mostly correct, but if the COPY writes to a partial + * folio (at the start or end) and the parts not covered by the COPY are * written through a memory map after calling fuse_writeback_range(), - * then these partial page modifications will be lost on truncation. + * then that folio is laundered before it is dropped, so the memory map + * modifications are written back over the range the server just copied + * into and the copied data is lost. * * It is unlikely that someone would rely on such mixed style * modifications. Yet this does give less guarantees than if the @@ -3038,9 +3063,10 @@ fallback: goto out; } - truncate_inode_pages_range(inode_out->i_mapping, - ALIGN_DOWN(pos_out, PAGE_SIZE), - ALIGN(pos_out + bytes_copied, PAGE_SIZE) - 1); + if (bytes_copied) + invalidate_inode_pages2_range(inode_out->i_mapping, + pos_out >> PAGE_SHIFT, + (pos_out + bytes_copied - 1) >> PAGE_SHIFT); file_update_time(file_out); fuse_write_update_attr(inode_out, pos_out + bytes_copied, bytes_copied); @@ -3113,6 +3139,7 @@ void fuse_init_file_inode(struct inode *inode, unsigned int flags) { struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_conn *fc = get_fuse_conn(inode); + unsigned int max_folio_pages; inode->i_fop = &fuse_file_operations; inode->i_data.a_ops = &fuse_file_aops; @@ -3126,6 +3153,20 @@ void fuse_init_file_inode(struct inode *inode, unsigned int flags) init_waitqueue_head(&fi->page_waitq); init_waitqueue_head(&fi->direct_io_waitq); - if (IS_ENABLED(CONFIG_FUSE_DAX)) - fuse_dax_inode_init(inode, flags); + if (IS_ENABLED(CONFIG_FUSE_VDAX)) + fuse_vdax_inode_init(inode, flags); + + if (FUSE_IS_VDAX(inode)) + return; + + /* + * A folio is never split across requests so cap the order so that one + * always fits in a single request. + */ + max_folio_pages = min3(fc->max_write >> PAGE_SHIFT, + fc->max_read >> PAGE_SHIFT, fc->max_pages); + + if (max_folio_pages) + mapping_set_folio_order_range(inode->i_mapping, 0, + ilog2(max_folio_pages)); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index c8d4c5f3af7e..8546855386b5 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -218,11 +218,11 @@ struct fuse_inode { /** @lock: Lock to protect write-related fields */ spinlock_t lock; -#ifdef CONFIG_FUSE_DAX +#ifdef CONFIG_FUSE_VDAX /** - * @dax: Dax specific inode data + * @vdax: Virtiofs DAX specific inode data */ - struct fuse_inode_dax *dax; + struct fuse_inode_vdax *vdax; #endif /** @submount_lookup: Submount specific lookup tracking */ struct fuse_submount_lookup *submount_lookup; @@ -364,16 +364,16 @@ struct fuse_io_priv { .iocb = i, \ } -enum fuse_dax_mode { - FUSE_DAX_INODE_DEFAULT, /* default */ - FUSE_DAX_ALWAYS, /* "-o dax=always" */ - FUSE_DAX_NEVER, /* "-o dax=never" */ - FUSE_DAX_INODE_USER, /* "-o dax=inode" */ +enum fuse_vdax_mode { + FUSE_VDAX_INODE_DEFAULT, /* default */ + FUSE_VDAX_ALWAYS, /* "-o dax=always" */ + FUSE_VDAX_NEVER, /* "-o dax=never" */ + FUSE_VDAX_INODE_USER, /* "-o dax=inode" */ }; -static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode) +static inline bool fuse_is_inode_vdax_mode(enum fuse_vdax_mode mode) { - return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER; + return mode == FUSE_VDAX_INODE_DEFAULT || mode == FUSE_VDAX_INODE_USER; } struct fuse_fs_context { @@ -391,13 +391,14 @@ struct fuse_fs_context { bool no_control:1; bool no_force_umount:1; bool legacy_opts_show:1; - enum fuse_dax_mode dax_mode; + bool syncfs_capable:1; + enum fuse_vdax_mode vdax_mode; unsigned int max_read; unsigned int blksize; const char *subtype; - /* DAX device, may be NULL */ - struct dax_device *dax_dev; + /* Virtiofs DAX device, may be NULL */ + struct dax_device *vdax_dev; }; struct fuse_sync_bucket { @@ -675,6 +676,14 @@ struct fuse_conn { /** @sync_fs: Propagate syncfs() to server */ unsigned int sync_fs:1; + /** + * @syncfs_capable: the privilege required to honor FUSE_HAS_SYNCFS was + * present when /dev/fuse was opened (CAP_SYS_ADMIN in the initial user + * namespace), i.e. the same privilege that mounting virtiofs/fuseblk + * requires. + */ + unsigned int syncfs_capable:1; + /** @init_security: Initialize security xattrs when creating a new inode */ unsigned int init_security:1; @@ -684,8 +693,8 @@ struct fuse_conn { */ unsigned int create_supp_group:1; - /** @inode_dax: Does the filesystem support per inode DAX? */ - unsigned int inode_dax:1; + /** @inode_vdax: Does the filesystem support per inode virtiofs DAX? */ + unsigned int inode_vdax:1; /** @no_tmpfile: Is tmpfile not implemented by fs? */ unsigned int no_tmpfile:1; @@ -744,12 +753,12 @@ struct fuse_conn { */ struct rw_semaphore killsb; -#ifdef CONFIG_FUSE_DAX - /** @dax_mode: Dax mode */ - enum fuse_dax_mode dax_mode; +#ifdef CONFIG_FUSE_VDAX + /** @vdax_mode: Virtiofs DAX mode */ + enum fuse_vdax_mode vdax_mode; - /** @dax: Dax specific conn data, non-NULL if DAX is enabled */ - struct fuse_conn_dax *dax; + /** @dax: Dax specific conn data, non-NULL if virtiofs DAX is enabled */ + struct fuse_conn_vdax *vdax; #endif /** @mounts: List of filesystems using this connection */ @@ -1217,21 +1226,21 @@ void fuse_free_conn(struct fuse_conn *fc); /* dax.c */ -#define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode)) - -ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to); -ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from); -int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma); -int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end); -int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode, - struct dax_device *dax_dev); -void fuse_dax_conn_free(struct fuse_conn *fc); -bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi); -void fuse_dax_inode_init(struct inode *inode, unsigned int flags); -void fuse_dax_inode_cleanup(struct inode *inode); -void fuse_dax_dontcache(struct inode *inode, unsigned int flags); -bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment); -void fuse_dax_cancel_work(struct fuse_conn *fc); +#define FUSE_IS_VDAX(inode) (IS_ENABLED(CONFIG_FUSE_VDAX) && IS_DAX(inode)) + +ssize_t fuse_vdax_read_iter(struct kiocb *iocb, struct iov_iter *to); +ssize_t fuse_vdax_write_iter(struct kiocb *iocb, struct iov_iter *from); +int fuse_vdax_mmap(struct file *file, struct vm_area_struct *vma); +int fuse_vdax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end); +int fuse_vdax_conn_alloc(struct fuse_conn *fc, enum fuse_vdax_mode mode, + struct dax_device *vdax_dev); +void fuse_vdax_conn_free(struct fuse_conn *fc); +bool fuse_vdax_inode_alloc(struct super_block *sb, struct fuse_inode *fi); +void fuse_vdax_inode_init(struct inode *inode, unsigned int flags); +void fuse_vdax_inode_cleanup(struct inode *inode); +void fuse_vdax_dontcache(struct inode *inode, unsigned int flags); +bool fuse_vdax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment); +void fuse_vdax_cancel_work(struct fuse_conn *fc); /* ioctl.c */ long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); @@ -1258,24 +1267,13 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff, /* backing.c */ #ifdef CONFIG_FUSE_PASSTHROUGH -struct fuse_backing *fuse_backing_get(struct fuse_backing *fb); void fuse_backing_put(struct fuse_backing *fb); struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id); #else -static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb) -{ - return NULL; -} - static inline void fuse_backing_put(struct fuse_backing *fb) { } -static inline struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, - int backing_id) -{ - return NULL; -} #endif void fuse_backing_files_init(struct fuse_conn *fc); @@ -1304,13 +1302,9 @@ static inline struct fuse_backing *fuse_inode_backing_set(struct fuse_inode *fi, struct fuse_backing *fuse_passthrough_open(struct file *file, int backing_id); void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb); -static inline struct file *fuse_file_passthrough(struct fuse_file *ff) +static inline bool fuse_is_passthrough(struct fuse_file *ff) { -#ifdef CONFIG_FUSE_PASSTHROUGH - return ff->passthrough; -#else - return NULL; -#endif + return IS_ENABLED(CONFIG_FUSE_PASSTHROUGH) && (ff->open_flags & FOPEN_PASSTHROUGH); } ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter); diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index e9552be3637b..cbb10e19e7e8 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -100,7 +100,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb) if (!fi->forget) goto out_free; - if (IS_ENABLED(CONFIG_FUSE_DAX) && !fuse_dax_inode_alloc(sb, fi)) + if (IS_ENABLED(CONFIG_FUSE_VDAX) && !fuse_vdax_inode_alloc(sb, fi)) goto out_free_forget; if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH)) @@ -121,8 +121,8 @@ static void fuse_free_inode(struct inode *inode) mutex_destroy(&fi->mutex); kfree(fi->forget); -#ifdef CONFIG_FUSE_DAX - kfree(fi->dax); +#ifdef CONFIG_FUSE_VDAX + kfree(fi->vdax); #endif if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH)) fuse_backing_put(fuse_inode_backing(fi)); @@ -148,7 +148,7 @@ static void fuse_evict_inode(struct inode *inode) /* Will write inode on close/munmap and in all other dirtiers */ WARN_ON(inode_state_read_once(inode) & I_DIRTY_INODE); - if (FUSE_IS_DAX(inode)) + if (FUSE_IS_VDAX(inode)) dax_break_layout_final(inode); truncate_inode_pages_final(&inode->i_data); @@ -156,8 +156,8 @@ static void fuse_evict_inode(struct inode *inode) if (inode->i_sb->s_flags & SB_ACTIVE) { struct fuse_conn *fc = get_fuse_conn(inode); - if (FUSE_IS_DAX(inode)) - fuse_dax_inode_cleanup(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); @@ -385,8 +385,8 @@ static void fuse_change_attributes_i(struct inode *inode, struct fuse_attr *attr invalidate_inode_pages2(inode->i_mapping); } - if (IS_ENABLED(CONFIG_FUSE_DAX)) - fuse_dax_dontcache(inode, attr->flags); + if (IS_ENABLED(CONFIG_FUSE_VDAX)) + fuse_vdax_dontcache(inode, attr->flags); } void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, @@ -803,6 +803,15 @@ static int fuse_opt_fd(struct fs_context *fsc, struct file *file) if (file->f_cred->user_ns != fsc->user_ns) return invalfc(fsc, "wrong user namespace for fuse device"); + /* + * Record whether the server opened /dev/fuse with CAP_SYS_ADMIN in the + * initial user namespace -- the same privilege that mounting virtiofs + * or fuseblk requires. Only such servers are trusted to receive + * FUSE_SYNCFS (see fuse_syncfs_enable()). + */ + ctx->syncfs_capable = file_ns_capable(file, &init_user_ns, + CAP_SYS_ADMIN); + ctx->fud = fuse_dev_grab(file); return 0; @@ -944,12 +953,12 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root) if (sb->s_bdev && sb->s_blocksize != FUSE_DEFAULT_BLKSIZE) seq_printf(m, ",blksize=%lu", sb->s_blocksize); } -#ifdef CONFIG_FUSE_DAX - if (fc->dax_mode == FUSE_DAX_ALWAYS) +#ifdef CONFIG_FUSE_VDAX + if (fc->vdax_mode == FUSE_VDAX_ALWAYS) seq_puts(m, ",dax=always"); - else if (fc->dax_mode == FUSE_DAX_NEVER) + else if (fc->vdax_mode == FUSE_VDAX_NEVER) seq_puts(m, ",dax=never"); - else if (fc->dax_mode == FUSE_DAX_INODE_USER) + else if (fc->vdax_mode == FUSE_VDAX_INODE_USER) seq_puts(m, ",dax=inode"); #endif @@ -1007,8 +1016,8 @@ void fuse_conn_put(struct fuse_conn *fc) if (!refcount_dec_and_test(&fc->count)) return; - if (IS_ENABLED(CONFIG_FUSE_DAX)) - fuse_dax_conn_free(fc); + if (IS_ENABLED(CONFIG_FUSE_VDAX)) + fuse_vdax_conn_free(fc); cancel_work_sync(&fc->epoch_work); fuse_chan_release(fc->chan); put_pid_ns(fc->pid_ns); @@ -1269,6 +1278,16 @@ struct fuse_init_args { struct fuse_mount *fm; }; +/* + * A server can stall syncfs()/sync(), so only honor FUSE_HAS_SYNCFS for + * servers that opened /dev/fuse with CAP_SYS_ADMIN in the initial user + * namespace -- the same privilege required to mount virtiofs or fuseblk. + */ +static bool fuse_syncfs_enable(struct fuse_conn *fc, u64 flags) +{ + return (flags & FUSE_HAS_SYNCFS) && fc->syncfs_capable; +} + static void process_init_reply(struct fuse_args *args, int error) { struct fuse_init_args *ia = container_of(args, typeof(*ia), args); @@ -1354,13 +1373,13 @@ static void process_init_reply(struct fuse_args *args, int error) if (fc->max_pages > 1) fc->name_max = FUSE_NAME_MAX; } - if (IS_ENABLED(CONFIG_FUSE_DAX)) { + if (IS_ENABLED(CONFIG_FUSE_VDAX)) { if (flags & FUSE_MAP_ALIGNMENT && - !fuse_dax_check_alignment(fc, arg->map_alignment)) { + !fuse_vdax_check_alignment(fc, arg->map_alignment)) { ok = false; } if (flags & FUSE_HAS_INODE_DAX) - fc->inode_dax = 1; + fc->inode_vdax = 1; } if (flags & FUSE_HANDLE_KILLPRIV_V2) { fc->handle_killpriv_v2 = 1; @@ -1410,6 +1429,9 @@ static void process_init_reply(struct fuse_args *args, int error) if (flags & FUSE_REQUEST_TIMEOUT) timeout = arg->request_timeout; + + if (fuse_syncfs_enable(fc, flags)) + fc->sync_fs = 1; } else { ra_pages = fc->max_read / PAGE_SIZE; fc->no_lock = 1; @@ -1469,16 +1491,21 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm) FUSE_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP | FUSE_NO_EXPORT_SUPPORT | FUSE_HAS_RESEND | FUSE_ALLOW_IDMAP | FUSE_REQUEST_TIMEOUT; -#ifdef CONFIG_FUSE_DAX - if (fm->fc->dax) +#ifdef CONFIG_FUSE_VDAX + if (fm->fc->vdax) flags |= FUSE_MAP_ALIGNMENT; - if (fuse_is_inode_dax_mode(fm->fc->dax_mode)) + if (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)) flags |= FUSE_PASSTHROUGH; + /* Only offered to sufficiently privileged servers; see + * fuse_syncfs_enable(). + */ + if (fm->fc->syncfs_capable) + flags |= FUSE_HAS_SYNCFS; if (fuse_uring_enabled()) flags |= FUSE_OVER_IO_URING | FUSE_HAS_IO_URING_BUFPOOL; @@ -1751,8 +1778,8 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) sb->s_subtype = ctx->subtype; ctx->subtype = NULL; - if (IS_ENABLED(CONFIG_FUSE_DAX)) { - err = fuse_dax_conn_alloc(fc, ctx->dax_mode, ctx->dax_dev); + if (IS_ENABLED(CONFIG_FUSE_VDAX)) { + err = fuse_vdax_conn_alloc(fc, ctx->vdax_mode, ctx->vdax_dev); if (err) goto err; } @@ -1761,7 +1788,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) fm->sb = sb; err = fuse_bdi_init(fc, sb); if (err) - goto err_free_dax; + goto err_free_vdax; /* Handle umasking inside the fuse code */ if (sb->s_flags & SB_POSIXACL) @@ -1770,6 +1797,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) fc->default_permissions = ctx->default_permissions; fc->allow_other = ctx->allow_other; + fc->syncfs_capable = ctx->syncfs_capable; fc->user_id = ctx->user_id; fc->group_id = ctx->group_id; fc->legacy_opts_show = ctx->legacy_opts_show; @@ -1783,7 +1811,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) set_default_d_op(sb, &fuse_dentry_operations); root_dentry = d_make_root(root); if (!root_dentry) - goto err_free_dax; + goto err_free_vdax; mutex_lock(&fuse_mutex); err = -EINVAL; @@ -1809,9 +1837,9 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) err_unlock: mutex_unlock(&fuse_mutex); dput(root_dentry); - err_free_dax: - if (IS_ENABLED(CONFIG_FUSE_DAX)) - fuse_dax_conn_free(fc); + err_free_vdax: + if (IS_ENABLED(CONFIG_FUSE_VDAX)) + fuse_vdax_conn_free(fc); err: return err; } diff --git a/fs/fuse/ioctl.c b/fs/fuse/ioctl.c index 3614ea603913..dc3a188f5d72 100644 --- a/fs/fuse/ioctl.c +++ b/fs/fuse/ioctl.c @@ -130,9 +130,6 @@ static int fuse_setup_measure_verity(unsigned long arg, struct iovec *iov) if (copy_from_user(&digest_size, &uarg->digest_size, sizeof(digest_size))) return -EFAULT; - if (digest_size > SIZE_MAX - sizeof(struct fsverity_digest)) - return -EINVAL; - iov->iov_len = sizeof(struct fsverity_digest) + digest_size; return 0; diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c index 3728933188f3..79637c09e883 100644 --- a/fs/fuse/iomode.c +++ b/fs/fuse/iomode.c @@ -200,10 +200,10 @@ int fuse_file_io_open(struct file *file, struct inode *inode) int err; /* - * io modes are not relevant with DAX and with server that does not + * io modes are not relevant with virtiofs DAX and with server that does not * implement open. */ - if (FUSE_IS_DAX(inode) || !ff->args) + if (FUSE_IS_VDAX(inode) || !ff->args) return 0; /* diff --git a/fs/fuse/notify.c b/fs/fuse/notify.c index 1ba763705d91..c0428e03d138 100644 --- a/fs/fuse/notify.c +++ b/fs/fuse/notify.c @@ -155,7 +155,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size, nodeid = outarg.nodeid; pos = outarg.offset; - num = min(outarg.size, MAX_LFS_FILESIZE - pos); + num = umin(outarg.size, MAX_LFS_FILESIZE - pos); down_read(&fc->killsb); @@ -190,7 +190,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size, folio_offset = offset_in_folio(folio, pos); nr_bytes = min(num, folio_size(folio) - folio_offset); - err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0); + err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes); if (!folio_test_uptodate(folio) && !err && folio_offset == 0 && (nr_bytes == folio_size(folio) || file_size == end)) { folio_zero_segment(folio, nr_bytes, folio_size(folio)); diff --git a/fs/fuse/passthrough.c b/fs/fuse/passthrough.c index f2d08ac2459b..b43d3e0f7081 100644 --- a/fs/fuse/passthrough.c +++ b/fs/fuse/passthrough.c @@ -11,6 +11,10 @@ #include <linux/backing-file.h> #include <linux/splice.h> +static inline struct file *fuse_file_passthrough(struct fuse_file *ff) +{ + return ff->passthrough; +} static void fuse_file_accessed(struct file *file) { struct inode *inode = file_inode(file); @@ -187,10 +191,15 @@ out: void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb) { + struct file *backing_file = fuse_file_passthrough(ff); + pr_debug("%s: fb=0x%p, backing_file=0x%p\n", __func__, - fb, ff->passthrough); + fb, backing_file); + + if (!backing_file) + return; - fput(ff->passthrough); + fput(backing_file); ff->passthrough = NULL; put_cred(ff->cred); ff->cred = NULL; diff --git a/fs/fuse/req.c b/fs/fuse/req.c index a01ee743d31e..51cfd64ea1ba 100644 --- a/fs/fuse/req.c +++ b/fs/fuse/req.c @@ -10,12 +10,12 @@ static int fuse_fill_creds(struct fuse_mount *fm, struct fuse_args *args, struct kuid_t fsuid = mapped_fsuid(idmap, fc->user_ns); kgid_t fsgid = mapped_fsgid(idmap, fc->user_ns); + if (args->nocreds) + return 0; + args->pid = pid_nr_ns(task_pid(current), fc->pid_ns); if (args->force) { - if (args->nocreds) - return 0; - if (no_idmap) { args->uid = from_kuid_munged(fc->user_ns, current_fsuid()); args->gid = from_kgid_munged(fc->user_ns, current_fsgid()); @@ -26,7 +26,6 @@ static int fuse_fill_creds(struct fuse_mount *fm, struct fuse_args *args, struct return 0; } - WARN_ON(args->nocreds); /* * Keep the old behavior when idmappings support was not * declared by a FUSE server. diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index f15e516ebcb5..4f334766b8c3 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -102,9 +102,9 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, gfp_t gfp); static const struct constant_table dax_param_enums[] = { - {"always", FUSE_DAX_ALWAYS }, - {"never", FUSE_DAX_NEVER }, - {"inode", FUSE_DAX_INODE_USER }, + {"always", FUSE_VDAX_ALWAYS }, + {"never", FUSE_VDAX_NEVER }, + {"inode", FUSE_VDAX_INODE_USER }, {} }; @@ -132,10 +132,10 @@ static int virtio_fs_parse_param(struct fs_context *fsc, switch (opt) { case OPT_DAX: - ctx->dax_mode = FUSE_DAX_ALWAYS; + ctx->vdax_mode = FUSE_VDAX_ALWAYS; break; case OPT_DAX_ENUM: - ctx->dax_mode = result.uint_32; + ctx->vdax_mode = result.uint_32; break; default: return -EINVAL; @@ -798,9 +798,11 @@ static void virtio_fs_request_complete(struct fuse_req *req, for (i = 0; i < ap->num_folios; i++) { thislen = ap->descs[i].length; if (len < thislen) { - WARN_ON(ap->descs[i].offset); + unsigned int offset = ap->descs[i].offset; + folio = ap->folios[i]; - folio_zero_segment(folio, len, thislen); + folio_zero_segment(folio, offset + len, + offset + thislen); len = 0; } else { len -= thislen; @@ -1079,7 +1081,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) struct dev_pagemap *pgmap; bool have_cache; - if (!IS_ENABLED(CONFIG_FUSE_DAX)) + if (!IS_ENABLED(CONFIG_FUSE_VDAX)) return 0; dax_dev = alloc_dax(fs, &virtio_fs_dax_ops); @@ -1592,14 +1594,14 @@ static int virtio_fs_fill_super(struct super_block *sb, struct fs_context *fsc) goto err_free_fuse_devs; } - if (ctx->dax_mode != FUSE_DAX_NEVER) { - if (ctx->dax_mode == FUSE_DAX_ALWAYS && !fs->dax_dev) { + if (ctx->vdax_mode != FUSE_VDAX_NEVER) { + if (ctx->vdax_mode == FUSE_VDAX_ALWAYS && !fs->dax_dev) { err = -EINVAL; pr_err("virtio-fs: dax can't be enabled as filesystem" " device does not support it.\n"); goto err_free_fuse_devs; } - ctx->dax_dev = fs->dax_dev; + ctx->vdax_dev = fs->dax_dev; } err = fuse_fill_super_common(sb, ctx); if (err < 0) @@ -1633,8 +1635,8 @@ static void virtio_fs_conn_destroy(struct fuse_mount *fm) /* Stop dax worker. Soon evict_inodes() will be called which * will free all memory ranges belonging to all inodes. */ - if (IS_ENABLED(CONFIG_FUSE_DAX)) - fuse_dax_cancel_work(fc); + if (IS_ENABLED(CONFIG_FUSE_VDAX)) + fuse_vdax_cancel_work(fc); /* Stop forget queue. Soon destroy will be sent */ spin_lock(&fsvq->lock); diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index 7435e09c87fe..10a7f31c4bdf 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -248,6 +248,9 @@ * - add bufpool offset field to fuse_uring_ent_in_out struct * - add FUSE_URING_ZERO_COPY, FUSE_URING_ENT_ZERO_COPY, and * FOPEN_IO_URING_ZERO_COPY flag + * + * 7.47 + * - add FUSE_HAS_SYNCFS opt-in flag for privileged userspace servers */ #ifndef _LINUX_FUSE_H @@ -283,7 +286,7 @@ #define FUSE_KERNEL_VERSION 7 /** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 46 +#define FUSE_KERNEL_MINOR_VERSION 47 /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 @@ -464,6 +467,12 @@ struct fuse_file_lock { * FUSE_REQUEST_TIMEOUT: kernel supports timing out requests. * init_out.request_timeout contains the timeout (in secs) * FUSE_HAS_IO_URING_BUFPOOL: kernel supports io-uring buffer pools + * FUSE_HAS_SYNCFS: server requests that syncfs()/sync() be propagated as + * FUSE_SYNCFS requests. Since an untrusted server can use this + * to stall sync(), it is only honored when /dev/fuse was opened + * with CAP_SYS_ADMIN in the initial user namespace (the same + * privilege that mounting virtiofs or fuseblk requires). + * Insufficiently privileged servers ignore it. */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) @@ -512,6 +521,7 @@ struct fuse_file_lock { #define FUSE_OVER_IO_URING (1ULL << 41) #define FUSE_REQUEST_TIMEOUT (1ULL << 42) #define FUSE_HAS_IO_URING_BUFPOOL (1ULL << 43) +#define FUSE_HAS_SYNCFS (1ULL << 44) /** * CUSE INIT request/reply flags diff --git a/tools/testing/selftests/filesystems/fuse/.gitignore b/tools/testing/selftests/filesystems/fuse/.gitignore index fb51603fe419..b5b03db1118c 100644 --- a/tools/testing/selftests/filesystems/fuse/.gitignore +++ b/tools/testing/selftests/filesystems/fuse/.gitignore @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only fuse_mnt fusectl_test +test_syncfs write_extend_eof_test diff --git a/tools/testing/selftests/filesystems/fuse/Makefile b/tools/testing/selftests/filesystems/fuse/Makefile index 95a1ee947ca7..c2de8d225447 100644 --- a/tools/testing/selftests/filesystems/fuse/Makefile +++ b/tools/testing/selftests/filesystems/fuse/Makefile @@ -2,7 +2,7 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) -TEST_GEN_PROGS := fusectl_test +TEST_GEN_PROGS := fusectl_test test_syncfs TEST_GEN_PROGS += write_extend_eof_test TEST_GEN_FILES := fuse_mnt |
