From patchwork Fri Nov 23 17:20:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: jbd: Fix lock ordering bug in journal_unmap_buffer() Date: Fri, 23 Nov 2012 07:20:21 -0000 From: Jan Kara X-Patchwork-Id: 201383 Message-Id: <1353691221-4176-1-git-send-email-jack@suse.cz> To: linux-ext4@vger.kernel.org Cc: Jan Kara Commit 09e05d48 introduced a wait for transaction commit into journal_unmap_buffer() in the case we are truncating a buffer undergoing commit in the page stradding i_size on a filesystem with blocksize < pagesize. Sadly we forgot to drop buffer lock before waiting for transaction commit and thus deadlock is possible when kjournald wants to lock the buffer. Fix the problem by dropping the buffer lock before waiting for transaction commit. Since we are still holding page lock (and that is OK), buffer cannot disappear under us. Signed-off-by: Jan Kara --- fs/jbd/transaction.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) I want to push this fix to Linus soon. JBD2 needs the fix as well but there it affects only data=journal mode and the fix is more complex due to different lock ordering. diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c index 78b7f84..7f5120b 100644 --- a/fs/jbd/transaction.c +++ b/fs/jbd/transaction.c @@ -1961,7 +1961,9 @@ retry: spin_unlock(&journal->j_list_lock); jbd_unlock_bh_state(bh); spin_unlock(&journal->j_state_lock); + unlock_buffer(bh); log_wait_commit(journal, tid); + lock_buffer(bh); goto retry; } /*