[Devel] [PATCH RHEL7 COMMIT] fs/fuse kio_pcs: add WARN_ON to find race between setattr and write/falloc

Konstantin Khorenko khorenko at virtuozzo.com
Wed Jun 27 19:04:01 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-862.3.2.vz7.61.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.3.2.vz7.61.5
------>
commit 79ee26fdda173d6724c635684b0c72f5e5f66d89
Author: Pavel Butsykin <pbutsykin at virtuozzo.com>
Date:   Tue Jun 26 19:33:58 2018 +0300

    fs/fuse kio_pcs: add WARN_ON to find race between setattr and write/falloc
    
    All write/falloc requests should be protected from simultaneous execution
    with truncate (setattr size). Sync write/falloc protected by mutex, async
    write/falloc protected by fc->lock and fuse_set_nowrite/__fuse_release_nowrite.
    
    But it looks like somewhere there is a bug that allows the execution of
    write/falloc requests during the shrink operation:
    
        kernel BUG at fs/fuse/kio/pcs/pcs_fuse_kdirect.c:1036!
    
           Call Trace:
         [<ffffffff99136e82>] ? from_kgid_munged+0x12/0x20
         [<ffffffffc087c582>] ? fuse_req_init_context.isra.14+0x62/0x70 [fuse]
         [<ffffffffc087c8e7>] __fuse_request_send+0x47/0x110 [fuse]
         [<ffffffffc087fdb7>] fuse_request_check_and_send+0x27/0x30 [fuse]
         [<ffffffffc087fdd0>] fuse_request_send+0x10/0x20 [fuse]
         [<ffffffffc094461b>] submit_size_grow+0x13b/0x190 [fuse_kio_pcs]
         [<ffffffffc0944792>] fuse_size_grow_work+0x122/0x320 [fuse_kio_pcs]
         [<ffffffff990b65b2>] process_one_work+0x182/0x440
         [<ffffffff990b786c>] worker_thread+0x22c/0x3c0
         [<ffffffff990b7640>] ? manage_workers.isra.24+0x2a0/0x2a0
         [<ffffffff990be8f1>] kthread+0xd1/0xe0
         [<ffffffff990be820>] ? create_kthread+0x60/0x60
         [<ffffffff997506f7>] ret_from_fork_nospec_begin+0x21/0x21
         [<ffffffff990be820>] ? create_kthread+0x60/0x60
    
    This patch should be reverted after solving #PSBM-85945
    
    Signed-off-by: Pavel Butsykin <pbutsykin at virtuozzo.com>
---
 fs/fuse/kio/pcs/pcs_fuse_kdirect.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
index 2f300d39d5b2..5091eb04c0e0 100644
--- a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
+++ b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
@@ -771,6 +771,17 @@ static int pcs_fuse_prep_rw(struct pcs_fuse_req *r)
 	spin_lock(&di->lock);
 	/* Deffer all requests if shrink requested to prevent livelock */
 	if (di->size.shrink) {
+		struct inode *inode = &di->inode->inode;
+		struct fuse_conn *fc = get_fuse_conn(inode);
+
+		if (r->req.in.h.opcode == FUSE_WRITE ||
+				r->req.in.h.opcode == FUSE_FALLOCATE) {
+			WARN_ON(1);
+			pr_info("fi->writectr: %d, mutex: %d, fc->lock: %d\n",
+					fi->writectr < 0, mutex_is_locked(&inode->i_mutex),
+					spin_is_locked(&fc->lock));
+		}
+
 		wait_shrink(r, di);
 		spin_unlock(&di->lock);
 		return 1;


More information about the Devel mailing list