virtiofs: fix DAX range leak on unmount
Subsystems (3)
PATCH 1/5 virtiofs: fix DAX range leak on unmount
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.
--- fs/fuse/inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/fuse/inode.c +7 -2
@@ -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);
Signature · 1 line
2.56.1
PATCH 2/5 virtiofs: don't abort DAX removemapping on allocation failure
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.
--- fs/fuse/dax.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-)
fs/fuse/dax.c +31 -18
@@ -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
Signature · 1 line
2.56.1
PATCH 3/5 virtiofs: retry request submission from the worker on -ENOMEM
In reply to Miklos Szeredivirtio_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.
--- fs/fuse/virtio_fs.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/fuse/virtio_fs.c +17 -0
@@ -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);
Signature · 1 line
2.56.1
Re: [PATCH 3/5] virtiofs: retry request submission from the worker on -ENOMEM
Hi Miklos,
Quoted 44 lines · Miklos Szeredi
virtio_fs_send_req()enqueues withGFP_ATOMIC, because it may be called withfc->chan->bg_lockheld.copy_args_to_argbuf()allocates the bounce buffer with those flags, so under memory pressure a request can be failed with-ENOMEMeven 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:
-ENOSPCputs the request onfsvq->queued_reqsandvirtio_fs_request_dispatch_work()retries it withGFP_KERNELundermemalloc_nofs_save(). A failed atomic allocation is just as transient, so treat it the same way instead of ending the request. Unlike-ENOSPCthere is no completion to kick the worker afterwards, so schedule it here.
virtio_fs_enqueue_req()queues on-ENOSPConly after checkingfsvq->connectedunderfsvq->lock; do the same here and fail the request with-ENOTCONNif the queue is gone.req->argbufhas 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 <[email protected]>--- fs/fuse/virtio_fs.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)fs/fuse/virtio_fs.c +10
-0@@ -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);
fs/fuse/virtio_fs.c static void virtio_fs_send_req(struct fuse_iqueue *fiq, struct fuse_req *req) · line 1608
Quoted 10 lines
fs/fuse/virtio_fs.c +7
-0+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);
Minor nit: in virtio_fs_enqueue_req(), besides allocating the bounce buffer via copy_args_to_argbuf(), it also calls virtqueue_add_sgs() with GFP_ATOMIC later, which can also return -ENOMEM on a DMA mapping error (note that failing to allocate the indirect descriptor table with GFP_ATOMIC does not return -ENOMEM). If -ENOMEM comes from virtqueue_add_sgs(), retrying once in virtio_fs_request_dispatch_work() is unlikely to succeed. However, distinguishing the two cases would require checking whether req->argbuf is NULL.
Alternatively, we could consider noting in the commit message that a failed atomic allocation in copy_args_to_argbuf() is just as transient.
Thanks,
Li Wang
PATCH 4/5 virtiofs: abort the connection if the server fails to unmap a DAX range
In reply to Miklos SzerediIf 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.
--- fs/fuse/dax.c | 59 ++++++++++++++++++++++++++++++++++++++------------- fs/fuse/dev.c | 5 +++++ fs/fuse/dev.h | 1 + 3 files changed, 50 insertions(+), 15 deletions(-)
fs/fuse/dax.c +44 -15
@@ -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 ; }
fs/fuse/dev.c +5 -0
@@ -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;
fs/fuse/dev.h +1 -0
@@ -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);
Signature · 1 line
2.56.1
Re: [PATCH 4/5] virtiofs: abort the connection if the server fails to unmap a DAX range
Hi Miklos,
Quoted 5 lines · Miklos Szeredi
If
FUSE_REMOVEMAPPINGfails, 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.
Quoted 9 lines
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 inwait_event()for a free range that can never arrive. Quietly retiring ranges only delays the failure and makes it worse when it comes.
As far as I understand it—please correct me if I'm wrong:reclaim_one_dmap_locked() first calls dmap_writeback_invalidate() to write back and invalidate the pages in the file range corresponding to the DAX window on the old inode, tearing down any userspace page table entries pointing to this DAX window. Then interval_tree_remove() ensures the old inode can no longer look up this window. Both steps happen before dmap_removemapping_one().
The same applies to inode eviction: fuse_evict_inode() calls dax_break_layout_final() and fuse_vdax_inode_cleanup() before sending FUSE_REMOVEMAPPING.
Therefore, even if FUSE_REMOVEMAPPING is skipped or fails and a subsequent FUSE_SETUPMAPPING is issued for the same DAX window, the guest page tables of the old inode no longer point to it. When mapping that same DAX window to another inode via FUSE_SETUPMAPPING, the legacy implementation (the C version of virtiofsd and the out-of-tree DAX patches in QEMU) directly mmaps the new inode over the same virtual address range backing the DAX window, and guest virtiofs only inserts the DAX window into the new inode's interval tree after FUSE_SETUPMAPPING succeeds. Thus, stale data from the old file will not leak into the new file. As for the latest Rust virtiofsd implementation, it simply returns -ENOSYS for any FUSE_SETUPMAPPING / FUSE_REMOVEMAPPING requests from guest virtiofs.
Given this, I feel FUSE_REMOVEMAPPING can just be best-effort, without needing to abort the connection.
Thanks,
Li Wang
PATCH 5/5 virtiofs: fix forget leak on submount unmount
In reply to Miklos Szeredigeneric_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().
--- fs/fuse/inode.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
fs/fuse/inode.c +20 -11
@@ -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
Signature · 1 line
2.56.1
Hi Miklos,
Quoted 9 lines · Miklos Szeredi
generic_shutdown_super()clearsSB_ACTIVEbefore callingevict_inodes(), so at unmount timefuse_evict_inode()skippedfuse_vdax_inode_cleanup()for every remaining inode. The DAX ranges owned by those inodes stay onfc->vdax->busy_rangesinstead of being returned to the free pool, andfuse_vdax_conn_free()only freesfree_rangesbefore kfree()ing the connection, so the busyfuse_dax_mappingobjects are leaked. Nothing warns about it:fuse_free_inode()kfree()sfi->vdaxwithout checking that the interval tree is empty.
Quoted 6 lines
Call
fuse_vdax_inode_cleanup()regardless ofSB_ACTIVE. That is whatvirtio_fs_conn_destroy()has always assumed ("Soonevict_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.
Minor nit: should we consider adding
"WARN_ON(!list_empty(&fc->vdax->busy_ranges));"
in fuse_vdax_conn_free()? Since as you noted,fuse_vdax_conn_free() only frees free_ranges.
Thanks,
Li Wang