[Devel] [PATCH vz7 07/46] fuse: add memory barrier to INIT

Maxim Patlasov mpatlasov at virtuozzo.com
Fri Mar 24 19:14:26 PDT 2017


Backport from ml:

commit 9759bd51899458af4f4bcc11046f01285642ca10
Author: Miklos Szeredi <mszeredi at suse.cz>
Date:   Tue Jan 6 10:45:35 2015 +0100

    fuse: add memory barrier to INIT

    Theoretically we need to order setting of various fields in fc with
    fc->initialized.

    No known bug reports related to this yet.

    Signed-off-by: Miklos Szeredi <mszeredi at suse.cz>

Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
 fs/fuse/dev.c    |   15 +++++++++++++--
 fs/fuse/fuse_i.h |    2 ++
 fs/fuse/inode.c  |    2 +-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index c2a3392..5e7f812 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -119,6 +119,13 @@ static void fuse_req_init_context(struct fuse_req *req)
 	req->in.h.pid = task_pid_vnr(current);
 }
 
+void fuse_set_initialized(struct fuse_conn *fc)
+{
+	/* Make sure stores before this are seen on another CPU */
+	smp_wmb();
+	fc->initialized = 1;
+}
+
 static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
 {
 	return !fc->initialized || (for_background && fc->blocked);
@@ -137,6 +144,8 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
 				!fuse_block_alloc(fc, for_background)))
 			goto out;
 	}
+	/* Matches smp_wmb() in fuse_set_initialized() */
+	smp_rmb();
 
 	err = -ENOTCONN;
 	if (!fc->connected)
@@ -239,6 +248,8 @@ struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
 
 	atomic_inc(&fc->num_waiting);
 	wait_event(fc->blocked_waitq, fc->initialized);
+	/* Matches smp_wmb() in fuse_set_initialized() */
+	smp_rmb();
 	req = fuse_request_alloc(0);
 	if (!req)
 		req = get_reserved_req(fc, file);
@@ -2178,7 +2189,7 @@ void fuse_abort_conn(struct fuse_conn *fc)
 	if (fc->connected) {
 		fc->connected = 0;
 		fc->blocked = 0;
-		fc->initialized = 1;
+		fuse_set_initialized(fc);
 		end_io_requests(fc);
 		end_queued_requests(fc);
 		end_polls(fc);
@@ -2197,7 +2208,7 @@ int fuse_dev_release(struct inode *inode, struct file *file)
 		spin_lock(&fc->lock);
 		fc->connected = 0;
 		fc->blocked = 0;
-		fc->initialized = 1;
+		fuse_set_initialized(fc);
 		end_queued_requests(fc);
 		end_polls(fc);
 		wake_up_all(&fc->blocked_waitq);
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index fefa8ff..09aab7e 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -964,4 +964,6 @@ int fuse_flush_mtime(struct file *file, bool nofail);
 int fuse_do_setattr(struct inode *inode, struct iattr *attr,
 		    struct file *file);
 
+void fuse_set_initialized(struct fuse_conn *fc);
+
 #endif /* _FS_FUSE_I_H */
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 7dea77f..9bd2490 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1029,7 +1029,7 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
 		fc->max_write = max_t(unsigned, 4096, fc->max_write);
 		fc->conn_init = 1;
 	}
-	fc->initialized = 1;
+	fuse_set_initialized(fc);
 	wake_up_all(&fc->blocked_waitq);
 }
 



More information about the Devel mailing list