From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 2/2] btrfs: Fix deadlock caused by missing memory barrier
Date: Thu, 25 Jul 2019 11:27:29 +0300 [thread overview]
Message-ID: <20190725082729.14109-3-nborisov@suse.com> (raw)
In-Reply-To: <20190725082729.14109-1-nborisov@suse.com>
Commit 06297d8cefca ("btrfs: switch extent_buffer blocking_writers from atomic to int")
changed the type of blocking_writers but forgot to adjust relevant code
in btrfs_tree_unlock by converting the smp_mb__after_atomic to smp_mb.
This opened up the possibility of a deadlock due to re-ordering of
setting blocking_writers and checking/waking up the waiter. This
particular lockup is explained in a comment above waitqueue_active()
function.
Fix it by converting the memory barrier to a full smp_mb, accounting
for the fact that blocking_writers is a simple integer.
Fixes: 06297d8cefca ("btrfs: switch extent_buffer blocking_writers from atomic to int")
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Tested-by: Johannes Thumshirn <jthumshirn@suse.com>
---
fs/btrfs/locking.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
index ceb23690b89b..5e867720df88 100644
--- a/fs/btrfs/locking.c
+++ b/fs/btrfs/locking.c
@@ -310,9 +310,12 @@ void btrfs_tree_unlock(struct extent_buffer *eb)
if (blockers) {
btrfs_assert_no_spinning_writers(eb);
eb->blocking_writers--;
- /* Use the lighter barrier after atomic */
- smp_mb__after_atomic();
- cond_wake_up_nomb(&eb->write_lock_wq);
+ /*
+ * We need to order modifying blocking_writers above with
+ * actually waking up the sleepers to ensure they see the
+ * updated value of blocking_writers
+ */
+ cond_wake_up(&eb->write_lock_wq);
} else {
btrfs_assert_spinning_writers_put(eb);
write_unlock(&eb->lock);
--
2.17.1
next prev parent reply other threads:[~2019-07-25 8:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 8:27 [PATCH 0/2] Misc locking fixes Nikolay Borisov
2019-07-25 8:27 ` [PATCH 1/2] btrfs: Remove unused locking functions Nikolay Borisov
2019-07-25 8:27 ` Nikolay Borisov [this message]
2019-07-25 15:33 ` [PATCH 2/2] btrfs: Fix deadlock caused by missing memory barrier David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190725082729.14109-3-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).