Skip to contentSkip to conversation

jbd2: Fix forever sleeping process in do_get_write_access()

PATCH In review Jan Kara 3 participants 5 messages May 5, 2011 – May 8, 2011 Journalling layer for block devices (JBD2)

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 jbd2: Fix forever sleeping process in do_get_write_access()

In do_get_write_access() we wait on BH_Unshadow bit for buffer to get from shadow state. The waking code in journal_commit_transaction() has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and before wake_up_bit() is called. Thus a waitqueue check can happen before the buffer is actually moved from the shadow state and waiting process may never be woken. Fix the problem by issuing proper barrier.

---
 fs/jbd2/commit.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

Analogous JBD fix has been queued in my tree...

fs/jbd2/commit.c +7 -2
index 2e5d370..3a958c7 100644
@@ -768,8 +768,13 @@ wait_for_iobuf:
                    required. */
 		JBUFFER_TRACE(jh, "file as BJ_Forget");
 		jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
-		/* Wake up any transactions which were waiting for this
-		   IO to complete */
+		/*
+		 * Wake up any transactions which were waiting for this IO to
+		 * complete. The barrier must be here so that changes by
+		 * jbd2_journal_file_buffer() take effect before wake_up_bit()
+		 * does the waitqueue check.
+		 */
+		smp_mb();
 		wake_up_bit(&bh->b_state, BH_Unshadow);
 		JBUFFER_TRACE(jh, "brelse shadowed buffer");
 		__brelse(bh);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 7 lines · Jan Kara

In do_get_write_access() we wait on BH_Unshadow bit for buffer to get from shadow state. The waking code in journal_commit_transaction() has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and before wake_up_bit() is called. Thus a waitqueue check can happen before the buffer is actually moved from the shadow state and waiting process may never be woken. Fix the problem by issuing proper barrier.

needed for jbd/commit.c as well, I guess?

-Eric

Quoted 28 lines
---
 fs/jbd2/commit.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

Analogous JBD fix has been queued in my tree...

fs/jbd2/commit.c +7 -2
index 2e5d370..3a958c7 100644
@@ -768,8 +768,13 @@ wait_for_iobuf:
                    required. */
 		JBUFFER_TRACE(jh, "file as BJ_Forget");
 		jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
-		/* Wake up any transactions which were waiting for this
-		   IO to complete */
+		/*
+		 * Wake up any transactions which were waiting for this IO to
+		 * complete. The barrier must be here so that changes by
+		 * jbd2_journal_file_buffer() take effect before wake_up_bit()
+		 * does the waitqueue check.
+		 */
+		smp_mb();
 		wake_up_bit(&bh->b_state, BH_Unshadow);
 		JBUFFER_TRACE(jh, "brelse shadowed buffer");
 		__brelse(bh);
author
#2 lore raw
Quoted 10 lines · Eric Sandeen
Quoted 7 lines · Jan Kara

In do_get_write_access() we wait on BH_Unshadow bit for buffer to get from shadow state. The waking code in journal_commit_transaction() has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and before wake_up_bit() is called. Thus a waitqueue check can happen before the buffer is actually moved from the shadow state and waiting process may never be woken. Fix the problem by issuing proper barrier.

needed for jbd/commit.c as well, I guess?

Yes, I was already queued in my tree. I just sent it to the list as well.

Honza

Quoted 21 lines
Quoted 20 lines
fs/jbd2/commit.c +7 -2
index 2e5d370..3a958c7 100644
@@ -768,8 +768,13 @@ wait_for_iobuf:
                    required. */
 		JBUFFER_TRACE(jh, "file as BJ_Forget");
 		jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
-		/* Wake up any transactions which were waiting for this
-		   IO to complete */
+		/*
+		 * Wake up any transactions which were waiting for this IO to
+		 * complete. The barrier must be here so that changes by
+		 * jbd2_journal_file_buffer() take effect before wake_up_bit()
+		 * does the waitqueue check.
+		 */
+		smp_mb();
 		wake_up_bit(&bh->b_state, BH_Unshadow);
 		JBUFFER_TRACE(jh, "brelse shadowed buffer");
 		__brelse(bh);
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw
Quoted 10 lines · Jan Kara
Quoted 9 lines · Eric Sandeen
Quoted 7 lines · Jan Kara

In do_get_write_access() we wait on BH_Unshadow bit for buffer to get from shadow state. The waking code in journal_commit_transaction() has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and before wake_up_bit() is called. Thus a waitqueue check can happen before the buffer is actually moved from the shadow state and waiting process may never be woken. Fix the problem by issuing proper barrier.

Quoted 2 lines
Quoted 1 line

needed for jbd/commit.c as well, I guess?

Yes, I was already queued in my tree. I just sent it to the list as well.

sorry, sometimes "we" forget :)

Thanks!
-Eric

maintainer
#4 lore raw
In reply to Jan Kara
Quoted 10 lines · Jan Kara

In do_get_write_access() we wait on BH_Unshadow bit for buffer to get from shadow state. The waking code in journal_commit_transaction() has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and before wake_up_bit() is called. Thus a waitqueue check can happen before the buffer is actually moved from the shadow state and waiting process may never be woken. Fix the problem by issuing proper barrier.

Thanks, I've added this to the ext4 tree. (Currently in the dev branch, pending testing.)

- Ted