From patchwork Wed Jan 15 21:52:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Mostafa X-Patchwork-Id: 311374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 5C3992C0098 for ; Thu, 16 Jan 2014 08:58:31 +1100 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1W3YTj-0001IB-RX; Wed, 15 Jan 2014 21:58:27 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1W3YT2-0000wj-1I for kernel-team@lists.ubuntu.com; Wed, 15 Jan 2014 21:57:44 +0000 Received: from c-67-160-231-162.hsd1.ca.comcast.net ([67.160.231.162] helo=fourier) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1W3YOt-00076f-Mf; Wed, 15 Jan 2014 21:53:28 +0000 Received: from kamal by fourier with local (Exim 4.80) (envelope-from ) id 1W3YOr-0001Qf-Ea; Wed, 15 Jan 2014 13:53:25 -0800 From: Kamal Mostafa To: linux-kernel@vger.kernel.org, stable@vger.kernel.org, kernel-team@lists.ubuntu.com Subject: [PATCH 3.8 106/166] ext4: fix deadlock when writing in ENOSPC conditions Date: Wed, 15 Jan 2014 13:52:00 -0800 Message-Id: <1389822780-4729-107-git-send-email-kamal@canonical.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1389822780-4729-1-git-send-email-kamal@canonical.com> References: <1389822780-4729-1-git-send-email-kamal@canonical.com> X-Extended-Stable: 3.8 Cc: Theodore Ts'o , Kamal Mostafa , Jan Kara X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com 3.8.13.16 -stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit 34cf865d54813aab3497838132fb1bbd293f4054 upstream. Akira-san has been reporting rare deadlocks of his machine when running xfstests test 269 on ext4 filesystem. The problem turned out to be in ext4_da_reserve_metadata() and ext4_da_reserve_space() which called ext4_should_retry_alloc() while holding i_data_sem. Since ext4_should_retry_alloc() can force a transaction commit, this is a lock ordering violation and leads to deadlocks. Fix the problem by just removing the retry loops. These functions should just report ENOSPC to the caller (e.g. ext4_da_write_begin()) and that function must take care of retrying after dropping all necessary locks. Reported-and-tested-by: Akira Fujita Reviewed-by: Zheng Liu Signed-off-by: Jan Kara Signed-off-by: "Theodore Ts'o" [ kamal: backport to 3.8 (no ext4_da_reserve_metadata) ] Signed-off-by: Kamal Mostafa --- fs/ext4/inode.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fe1fada..46c10b5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1182,7 +1182,6 @@ static int ext4_journalled_write_end(struct file *file, */ static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock) { - int retries = 0; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_inode_info *ei = EXT4_I(inode); unsigned int md_needed; @@ -1204,7 +1203,6 @@ static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock) * in order to allocate nrblocks * worse case is one extent per block */ -repeat: spin_lock(&ei->i_block_reservation_lock); /* * ext4_calc_metadata_amount() has side effects, which we have @@ -1224,10 +1222,6 @@ repeat: ei->i_da_metadata_calc_len = save_len; ei->i_da_metadata_calc_last_lblock = save_last_lblock; spin_unlock(&ei->i_block_reservation_lock); - if (ext4_should_retry_alloc(inode->i_sb, &retries)) { - yield(); - goto repeat; - } dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); return -ENOSPC; }