* [PATCH] jbd2: Fix lockdep annotation in add_transaction_credits()
@ 2016-09-19 12:30 Jan Kara
2016-09-22 15:47 ` Theodore Ts'o
0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2016-09-19 12:30 UTC (permalink / raw)
To: Ted Tso; +Cc: linux-ext4, Thomas Gleixner, Jan Kara
Thomas has reported a lockdep splat hitting in
add_transaction_credits(). The problem is that that function calls
jbd2_might_wait_for_commit() while holding j_state_lock which is wrong
(we do not really wait for transaction commit while holding that lock).
Fix the problem by moving jbd2_might_wait_for_commit() into places where
we are ready to wait for transaction commit and thus j_state_lock is
unlocked.
Fixes: 1eaa566d368b214d99cbb973647c1b0b8102a9ae
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/jbd2/transaction.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index b5bc3e249163..3d8246a9faa4 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -159,6 +159,7 @@ static void wait_transaction_locked(journal_t *journal)
read_unlock(&journal->j_state_lock);
if (need_to_start)
jbd2_log_start_commit(journal, tid);
+ jbd2_might_wait_for_commit(journal);
schedule();
finish_wait(&journal->j_wait_transaction_locked, &wait);
}
@@ -182,8 +183,6 @@ static int add_transaction_credits(journal_t *journal, int blocks,
int needed;
int total = blocks + rsv_blocks;
- jbd2_might_wait_for_commit(journal);
-
/*
* If the current transaction is locked down for commit, wait
* for the lock to be released.
@@ -214,6 +213,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
if (atomic_read(&journal->j_reserved_credits) + total >
journal->j_max_transaction_buffers) {
read_unlock(&journal->j_state_lock);
+ jbd2_might_wait_for_commit(journal);
wait_event(journal->j_wait_reserved,
atomic_read(&journal->j_reserved_credits) + total <=
journal->j_max_transaction_buffers);
@@ -238,6 +238,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
if (jbd2_log_space_left(journal) < jbd2_space_needed(journal)) {
atomic_sub(total, &t->t_outstanding_credits);
read_unlock(&journal->j_state_lock);
+ jbd2_might_wait_for_commit(journal);
write_lock(&journal->j_state_lock);
if (jbd2_log_space_left(journal) < jbd2_space_needed(journal))
__jbd2_log_wait_for_space(journal);
@@ -255,6 +256,7 @@ static int add_transaction_credits(journal_t *journal, int blocks,
sub_reserved_credits(journal, rsv_blocks);
atomic_sub(total, &t->t_outstanding_credits);
read_unlock(&journal->j_state_lock);
+ jbd2_might_wait_for_commit(journal);
wait_event(journal->j_wait_reserved,
atomic_read(&journal->j_reserved_credits) + rsv_blocks
<= journal->j_max_transaction_buffers / 2);
--
2.6.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] jbd2: Fix lockdep annotation in add_transaction_credits()
2016-09-19 12:30 [PATCH] jbd2: Fix lockdep annotation in add_transaction_credits() Jan Kara
@ 2016-09-22 15:47 ` Theodore Ts'o
0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2016-09-22 15:47 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-ext4, Thomas Gleixner
On Mon, Sep 19, 2016 at 02:30:43PM +0200, Jan Kara wrote:
> Thomas has reported a lockdep splat hitting in
> add_transaction_credits(). The problem is that that function calls
> jbd2_might_wait_for_commit() while holding j_state_lock which is wrong
> (we do not really wait for transaction commit while holding that lock).
>
> Fix the problem by moving jbd2_might_wait_for_commit() into places where
> we are ready to wait for transaction commit and thus j_state_lock is
> unlocked.
>
> Fixes: 1eaa566d368b214d99cbb973647c1b0b8102a9ae
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> 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:[~2016-09-22 15:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-19 12:30 [PATCH] jbd2: Fix lockdep annotation in add_transaction_credits() Jan Kara
2016-09-22 15:47 ` Theodore Ts'o
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.