linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] jbd2: Fix assertion failure in jbd2_journal_flush()
@ 2012-12-12 15:17 Jan Kara
  2012-12-21  5:16 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2012-12-12 15:17 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Jan Kara, stable

The following race is possible between start_this_handle() and someone
calling jbd2_journal_flush().

Process A                              Process B
start_this_handle().
  if (journal->j_barrier_count) # false
  if (!journal->j_running_transaction) { #true
    read_unlock(&journal->j_state_lock);
                                       jbd2_journal_lock_updates()
                                       jbd2_journal_flush()
                                         write_lock(&journal->j_state_lock);
                                         if (journal->j_running_transaction) {
                                           # false
                                         ... wait for committing trans ...
                                         write_unlock(&journal->j_state_lock);
    ...
    write_lock(&journal->j_state_lock);
    if (!journal->j_running_transaction) { # true
      jbd2_get_transaction(journal, new_transaction);
    write_unlock(&journal->j_state_lock);
    goto repeat; # eventually blocks on j_barrier_count > 0
                                         ...
                                         J_ASSERT(!journal->j_running_transaction);
                                           # fails

We fix the race by rechecking j_barrier_count after reacquiring j_state_lock
in exclusive mode.

CC: stable@vger.kernel.org
Reported-by:yjwsignal@empal.com
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/jbd2/transaction.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index a74ba46..6873d24 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -209,7 +209,8 @@ repeat:
 		if (!new_transaction)
 			goto alloc_transaction;
 		write_lock(&journal->j_state_lock);
-		if (!journal->j_running_transaction) {
+		if (!journal->j_running_transaction &&
+		    !journal->j_barrier_count) {
 			jbd2_get_transaction(journal, new_transaction);
 			new_transaction = NULL;
 		}
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] jbd2: Fix assertion failure in jbd2_journal_flush()
  2012-12-12 15:17 [PATCH] jbd2: Fix assertion failure in jbd2_journal_flush() Jan Kara
@ 2012-12-21  5:16 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2012-12-21  5:16 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, stable

On Wed, Dec 12, 2012 at 04:17:42PM +0100, Jan Kara wrote:
> The following race is possible between start_this_handle() and someone
> calling jbd2_journal_flush().
> 
> Process A                              Process B
> start_this_handle().
>   if (journal->j_barrier_count) # false
>   if (!journal->j_running_transaction) { #true
>     read_unlock(&journal->j_state_lock);
>                                        jbd2_journal_lock_updates()
>                                        jbd2_journal_flush()
>                                          write_lock(&journal->j_state_lock);
>                                          if (journal->j_running_transaction) {
>                                            # false
>                                          ... wait for committing trans ...
>                                          write_unlock(&journal->j_state_lock);
>     ...
>     write_lock(&journal->j_state_lock);
>     if (!journal->j_running_transaction) { # true
>       jbd2_get_transaction(journal, new_transaction);
>     write_unlock(&journal->j_state_lock);
>     goto repeat; # eventually blocks on j_barrier_count > 0
>                                          ...
>                                          J_ASSERT(!journal->j_running_transaction);
>                                            # fails
> 
> We fix the race by rechecking j_barrier_count after reacquiring j_state_lock
> in exclusive mode.
> 
> CC: stable@vger.kernel.org
> Reported-by:yjwsignal@empal.com
> Signed-off-by: Jan Kara <jack@suse.cz>

Thanks, applied.

						- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-21  5:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-12 15:17 [PATCH] jbd2: Fix assertion failure in jbd2_journal_flush() Jan Kara
2012-12-21  5:16 ` Theodore Ts'o

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).