]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge branch 'fix/waitqueue-barriers' of git://git.kernel.org/pub/scm/linux/kernel...
authorChris Mason <clm@fb.com>
Mon, 12 Oct 2015 23:24:40 +0000 (16:24 -0700)
committerChris Mason <clm@fb.com>
Mon, 12 Oct 2015 23:24:40 +0000 (16:24 -0700)
12 files changed:
fs/btrfs/compression.c
fs/btrfs/delayed-inode.c
fs/btrfs/dev-replace.c
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/inode.c
fs/btrfs/locking.c
fs/btrfs/ordered-data.c
fs/btrfs/raid56.c
fs/btrfs/transaction.c
fs/btrfs/tree-log.c
fs/btrfs/volumes.c

index 57ee8ca29b0601060fae924f43b7897f2c4c7c7c..3a9317ce67f868f0240ecd5cd984198f5f6fdddd 100644 (file)
@@ -839,6 +839,9 @@ static void free_workspace(int type, struct list_head *workspace)
        btrfs_compress_op[idx]->free_workspace(workspace);
        atomic_dec(alloc_workspace);
 wake:
+       /*
+        * Make sure counter is updated before we wake up waiters.
+        */
        smp_mb();
        if (waitqueue_active(workspace_wait))
                wake_up(workspace_wait);
index a2ae42720a6afe92701de402b837d56dd66d03b4..e0941fbb913c2e99740b9df34d06efbc8cffdea1 100644 (file)
@@ -463,6 +463,10 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
 {
        int seq = atomic_inc_return(&delayed_root->items_seq);
+
+       /*
+        * atomic_dec_return implies a barrier for waitqueue_active
+        */
        if ((atomic_dec_return(&delayed_root->items) <
            BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
            waitqueue_active(&delayed_root->wait))
index a64ca942b63faf73084f9062fbf768e6092c9815..1e668fb7dd4c73dbc03b7f642660f2af20bd2ddb 100644 (file)
@@ -454,8 +454,7 @@ static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info)
 static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info)
 {
        clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state);
-       if (waitqueue_active(&fs_info->replace_wait))
-               wake_up(&fs_info->replace_wait);
+       wake_up(&fs_info->replace_wait);
 }
 
 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
index 7f934cccc98d82410a2a815af80528fc5a551a7f..a42c1f575ef7f05f2b16d44dc1f767f9b9cfef25 100644 (file)
@@ -801,6 +801,9 @@ static void run_one_async_done(struct btrfs_work *work)
        limit = btrfs_async_submit_limit(fs_info);
        limit = limit * 2 / 3;
 
+       /*
+        * atomic_dec_return implies a barrier for waitqueue_active
+        */
        if (atomic_dec_return(&fs_info->nr_async_submits) < limit &&
            waitqueue_active(&fs_info->async_submit_wait))
                wake_up(&fs_info->async_submit_wait);
index 92a5b4cad2abb027c7d98e338a591812256fc26d..522fb45d472ae9673cdbcd8c1f3ffccafa4a476f 100644 (file)
@@ -10372,8 +10372,7 @@ void btrfs_end_write_no_snapshoting(struct btrfs_root *root)
 {
        percpu_counter_dec(&root->subv_writers->counter);
        /*
-        * Make sure counter is updated before we wake up
-        * waiters.
+        * Make sure counter is updated before we wake up waiters.
         */
        smp_mb();
        if (waitqueue_active(&root->subv_writers->wait))
index 25eb814c302fffd881b832fad853811d214a52c5..208db4e835f0feccb860a8536910f02b69aa1ef6 100644 (file)
@@ -1096,6 +1096,9 @@ static noinline void async_cow_submit(struct btrfs_work *work)
        nr_pages = (async_cow->end - async_cow->start + PAGE_CACHE_SIZE) >>
                PAGE_CACHE_SHIFT;
 
+       /*
+        * atomic_sub_return implies a barrier for waitqueue_active
+        */
        if (atomic_sub_return(nr_pages, &root->fs_info->async_delalloc_pages) <
            5 * 1024 * 1024 &&
            waitqueue_active(&root->fs_info->async_submit_wait))
index d7e6baf1b2054f1998608902385bc5016020c2cf..8077461fc56ab256d8d02838ac3c345408edf5a4 100644 (file)
@@ -79,6 +79,9 @@ void btrfs_clear_lock_blocking_rw(struct extent_buffer *eb, int rw)
                write_lock(&eb->lock);
                WARN_ON(atomic_read(&eb->spinning_writers));
                atomic_inc(&eb->spinning_writers);
+               /*
+                * atomic_dec_and_test implies a barrier for waitqueue_active
+                */
                if (atomic_dec_and_test(&eb->blocking_writers) &&
                    waitqueue_active(&eb->write_lock_wq))
                        wake_up(&eb->write_lock_wq);
@@ -86,6 +89,9 @@ void btrfs_clear_lock_blocking_rw(struct extent_buffer *eb, int rw)
                BUG_ON(atomic_read(&eb->blocking_readers) == 0);
                read_lock(&eb->lock);
                atomic_inc(&eb->spinning_readers);
+               /*
+                * atomic_dec_and_test implies a barrier for waitqueue_active
+                */
                if (atomic_dec_and_test(&eb->blocking_readers) &&
                    waitqueue_active(&eb->read_lock_wq))
                        wake_up(&eb->read_lock_wq);
@@ -229,6 +235,9 @@ void btrfs_tree_read_unlock_blocking(struct extent_buffer *eb)
        }
        btrfs_assert_tree_read_locked(eb);
        WARN_ON(atomic_read(&eb->blocking_readers) == 0);
+       /*
+        * atomic_dec_and_test implies a barrier for waitqueue_active
+        */
        if (atomic_dec_and_test(&eb->blocking_readers) &&
            waitqueue_active(&eb->read_lock_wq))
                wake_up(&eb->read_lock_wq);
@@ -280,6 +289,9 @@ void btrfs_tree_unlock(struct extent_buffer *eb)
        if (blockers) {
                WARN_ON(atomic_read(&eb->spinning_writers));
                atomic_dec(&eb->blocking_writers);
+               /*
+                * Make sure counter is updated before we wake up waiters.
+                */
                smp_mb();
                if (waitqueue_active(&eb->write_lock_wq))
                        wake_up(&eb->write_lock_wq);
index 52170cf1757e3d25192a6cf6211a9d2edaa52751..071005f008c11f992dc56dbfe6ad8e33f89ff99c 100644 (file)
@@ -345,6 +345,9 @@ int btrfs_dec_test_first_ordered_pending(struct inode *inode,
 
        if (entry->bytes_left == 0) {
                ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags);
+               /*
+                * Implicit memory barrier after test_and_set_bit
+                */
                if (waitqueue_active(&entry->wait))
                        wake_up(&entry->wait);
        } else {
@@ -409,6 +412,9 @@ have_entry:
 
        if (entry->bytes_left == 0) {
                ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags);
+               /*
+                * Implicit memory barrier after test_and_set_bit
+                */
                if (waitqueue_active(&entry->wait))
                        wake_up(&entry->wait);
        } else {
index fcf7265ca46fd84a65b647619f4e07ba996d7a9f..1a33d3eb36de184e4cbcf72efb26687857c70051 100644 (file)
@@ -810,7 +810,11 @@ static noinline void unlock_stripe(struct btrfs_raid_bio *rbio)
                        }
 
                        goto done_nolock;
-               } else  if (waitqueue_active(&h->wait)) {
+                       /*
+                        * The barrier for this waitqueue_active is not needed,
+                        * we're protected by h->lock and can't miss a wakeup.
+                        */
+               } else if (waitqueue_active(&h->wait)) {
                        spin_unlock(&rbio->bio_list_lock);
                        spin_unlock_irqrestore(&h->lock, flags);
                        wake_up(&h->wait);
index 76354bb1312c841986f19928376e3eabbb36a7e3..47fd27031a206b86c8a4a8000f5e396746f54a54 100644 (file)
@@ -82,6 +82,12 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
 static void clear_btree_io_tree(struct extent_io_tree *tree)
 {
        spin_lock(&tree->lock);
+       /*
+        * Do a single barrier for the waitqueue_active check here, the state
+        * of the waitqueue should not change once clear_btree_io_tree is
+        * called.
+        */
+       smp_mb();
        while (!RB_EMPTY_ROOT(&tree->state)) {
                struct rb_node *node;
                struct extent_state *state;
@@ -856,6 +862,9 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
        atomic_dec(&cur_trans->num_writers);
        extwriter_counter_dec(cur_trans, trans->type);
 
+       /*
+        * Make sure counter is updated before we wake up waiters.
+        */
        smp_mb();
        if (waitqueue_active(&cur_trans->writer_wait))
                wake_up(&cur_trans->writer_wait);
index c3f9a9c71f28fa5f8930e86c43df03e43e3b79a9..1fffe8845c09b4bb09c1e515d2e6ab73d5deb536 100644 (file)
@@ -229,7 +229,9 @@ int btrfs_pin_log_trans(struct btrfs_root *root)
 void btrfs_end_log_trans(struct btrfs_root *root)
 {
        if (atomic_dec_and_test(&root->log_writers)) {
-               smp_mb();
+               /*
+                * Implicit memory barrier after atomic_dec_and_test
+                */
                if (waitqueue_active(&root->log_writer_wait))
                        wake_up(&root->log_writer_wait);
        }
@@ -2820,7 +2822,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 
        mutex_lock(&log_root_tree->log_mutex);
        if (atomic_dec_and_test(&log_root_tree->log_writers)) {
-               smp_mb();
+               /*
+                * Implicit memory barrier after atomic_dec_and_test
+                */
                if (waitqueue_active(&log_root_tree->log_writer_wait))
                        wake_up(&log_root_tree->log_writer_wait);
        }
@@ -2950,6 +2954,9 @@ out_wake_log_root:
        atomic_set(&log_root_tree->log_commit[index2], 0);
        mutex_unlock(&log_root_tree->log_mutex);
 
+       /*
+        * The barrier before waitqueue_active is implied by mutex_unlock
+        */
        if (waitqueue_active(&log_root_tree->log_commit_wait[index2]))
                wake_up(&log_root_tree->log_commit_wait[index2]);
 out:
@@ -2961,6 +2968,9 @@ out:
        atomic_set(&root->log_commit[index1], 0);
        mutex_unlock(&root->log_mutex);
 
+       /*
+        * The barrier before waitqueue_active is implied by mutex_unlock
+        */
        if (waitqueue_active(&root->log_commit_wait[index1]))
                wake_up(&root->log_commit_wait[index1]);
        return ret;
index dd644d7677821ab90544db5f8fbd0b763dde389f..cc1cc355904576bc5a1ee08f169cf287b6cc3ffb 100644 (file)
@@ -344,6 +344,9 @@ loop_lock:
                pending = pending->bi_next;
                cur->bi_next = NULL;
 
+               /*
+                * atomic_dec_return implies a barrier for waitqueue_active
+                */
                if (atomic_dec_return(&fs_info->nr_async_bios) < limit &&
                    waitqueue_active(&fs_info->async_submit_wait))
                        wake_up(&fs_info->async_submit_wait);