[RHEL7,COMMIT] ms/fuse: fix blocked_waitq wakeup

Submitted by Konstantin Khorenko on Oct. 4, 2018, 9:31 a.m.

Details

Message ID 201810040931.w949VJlF022863@finist_ce7.work
State New
Series "ms/fuse: fix blocked_waitq wakeup"
Headers show

Commit Message

Konstantin Khorenko Oct. 4, 2018, 9:31 a.m.
The commit is pushed to "branch-rh7-3.10.0-862.14.4.vz7.72.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.14.4.vz7.72.2
------>
commit cf73ebe2292990af492721e2e6673f06ca0e3b36
Author: Miklos Szeredi <mszeredi@redhat.com>
Date:   Thu Oct 4 12:31:19 2018 +0300

    ms/fuse: fix blocked_waitq wakeup
    
    Using waitqueue_active() is racy.  Make sure we issue a wake_up()
    unconditionally after storing into fc->blocked.  After that it's okay to
    optimize with waitqueue_active() since the first wake up provides the
    necessary barrier for all waiters, not the just the woken one.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
    Fixes: 3c18ef8117f0 ("fuse: optimize wake_up")
    Cc: <stable@vger.kernel.org> # v3.10
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
    
    =====================
    Patchset description:
    
    Relax lock contention and ms fixes
    
    https://pmc.acronis.com/browse/VSTOR-9810
    
    Port some ms fixes and begin first round of relaxing fc->lock contention.
    
    Kirill Tkhai (5):
          fuse: Fix use-after-free in fuse_dev_do_read()
          fuse: Fix use-after-free in fuse_dev_do_write()
          fuse: use list_first_entry() in flush_bg_queue()
          fuse: use READ_ONCE on congestion_threshold and max_background
          fuse: add locking to max_background and congestion_threshold changes
    
    Miklos Szeredi (2):
          fuse: set FR_SENT while locked
          fuse: fix blocked_waitq wakeup
---
 fs/fuse/dev.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 8c0840b2e3e4..71d862065e6a 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -440,12 +440,19 @@  void request_end(struct fuse_conn *fc, struct fuse_req *req)
 	if (test_bit(FR_BACKGROUND, &req->flags)) {
 		spin_lock(&fc->lock);
 		clear_bit(FR_BACKGROUND, &req->flags);
-		if (fc->num_background == fc->max_background)
+		if (fc->num_background == fc->max_background) {
 			fc->blocked = 0;
-
-		/* Wake up next waiter, if any */
-		if (!fc->blocked && waitqueue_active(&fc->blocked_waitq))
 			wake_up(&fc->blocked_waitq);
+		} else if (!fc->blocked) {
+			/*
+			 * Wake up next waiter, if any.  It's okay to use
+			 * waitqueue_active(), as we've already synced up
+			 * fc->blocked with waiters with the wake_up() call
+			 * above.
+			 */
+			if (waitqueue_active(&fc->blocked_waitq))
+				wake_up(&fc->blocked_waitq);
+		}
 
 		if (fc->num_background == fc->congestion_threshold &&
 		    fc->connected && fc->bdi_initialized) {