jbd2: Fix forever sleeping process in do_get_write_access()
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
@@ -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
Quoted 7 lines · Jan Kara
In
do_get_write_access()we wait onBH_Unshadowbit for buffer to get from shadow state. The waking code injournal_commit_transaction()has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and beforewake_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
Reported-by Tao Ma <[email protected]>Signed-off-by Jan Kara <[email protected]>--- 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@@ -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);
Quoted 10 lines · Eric Sandeen
Quoted 7 lines · Jan Kara
In
do_get_write_access()we wait onBH_Unshadowbit for buffer to get from shadow state. The waking code injournal_commit_transaction()has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and beforewake_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.cas 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@@ -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
Quoted 10 lines · Jan Kara
Quoted 9 lines · Eric Sandeen
Quoted 7 lines · Jan Kara
In
do_get_write_access()we wait onBH_Unshadowbit for buffer to get from shadow state. The waking code injournal_commit_transaction()has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and beforewake_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.cas 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
Ted Ts'o
maintainerQuoted 10 lines · Jan Kara
In
do_get_write_access()we wait onBH_Unshadowbit for buffer to get from shadow state. The waking code injournal_commit_transaction()has a bug because it does not issue a memory barrier after the buffer is moved from the shadow state and beforewake_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.Reported-by Tao Ma <[email protected]>Signed-off-by Jan Kara <[email protected]>
Thanks, I've added this to the ext4 tree. (Currently in the dev branch, pending testing.)
- Ted