]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFS: Fix up commit deadlocks
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 4 Oct 2021 19:37:42 +0000 (15:37 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:21:37 +0000 (16:21 +0200)
commit 133a48abf6ecc535d7eddc6da1c3e4c972445882 upstream.

If O_DIRECT bumps the commit_info rpcs_out field, then that could lead
to fsync() hangs. The fix is to ensure that O_DIRECT calls
nfs_commit_end().

Fixes: 723c921e7dfc ("sched/wait, fs/nfs: Convert wait_on_atomic_t() usage to the new wait_var_event() API")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Chanho Min <chanho.min@lge.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfs/direct.c
fs/nfs/write.c
include/linux/nfs_fs.h

index 0682037f972beb6feca3fdda252eacda995e83f2..32dc176ea1aba8830bf3cd3c7841e7b2108da60b 100644 (file)
@@ -700,7 +700,7 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
                nfs_unlock_and_release_request(req);
        }
 
-       if (atomic_dec_and_test(&cinfo.mds->rpcs_out))
+       if (nfs_commit_end(cinfo.mds))
                nfs_direct_write_complete(dreq);
 }
 
index 10ce264a64567e70b637e12fac4e8736efc9e9ba..c9895316fc070576e56a6a6bdcd0312f7fe72521 100644 (file)
@@ -1658,10 +1658,13 @@ static void nfs_commit_begin(struct nfs_mds_commit_info *cinfo)
        atomic_inc(&cinfo->rpcs_out);
 }
 
-static void nfs_commit_end(struct nfs_mds_commit_info *cinfo)
+bool nfs_commit_end(struct nfs_mds_commit_info *cinfo)
 {
-       if (atomic_dec_and_test(&cinfo->rpcs_out))
+       if (atomic_dec_and_test(&cinfo->rpcs_out)) {
                wake_up_var(&cinfo->rpcs_out);
+               return true;
+       }
+       return false;
 }
 
 void nfs_commitdata_release(struct nfs_commit_data *data)
@@ -1756,6 +1759,7 @@ void nfs_init_commit(struct nfs_commit_data *data,
        data->res.fattr   = &data->fattr;
        data->res.verf    = &data->verf;
        nfs_fattr_init(&data->fattr);
+       nfs_commit_begin(cinfo->mds);
 }
 EXPORT_SYMBOL_GPL(nfs_init_commit);
 
@@ -1801,7 +1805,6 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
 
        /* Set up the argument struct */
        nfs_init_commit(data, head, NULL, cinfo);
-       atomic_inc(&cinfo->mds->rpcs_out);
        return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),
                                   data->mds_ops, how, 0);
 }
index 49cf5c855cbe5944c09f5bd48fe378d59f5cb89f..a96b116cc9224d59c3acc36d002c7bc4ec0621b7 100644 (file)
@@ -549,6 +549,7 @@ extern int nfs_wb_page_cancel(struct inode *inode, struct page* page);
 extern int  nfs_commit_inode(struct inode *, int);
 extern struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail);
 extern void nfs_commit_free(struct nfs_commit_data *data);
+bool nfs_commit_end(struct nfs_mds_commit_info *cinfo);
 
 static inline int
 nfs_have_writebacks(struct inode *inode)