From patchwork Mon May 30 13:08:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 97913 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 03E0AB6F71 for ; Mon, 30 May 2011 23:08:29 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754637Ab1E3NI1 (ORCPT ); Mon, 30 May 2011 09:08:27 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53901 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754585Ab1E3NI0 (ORCPT ); Mon, 30 May 2011 09:08:26 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id F223F867E2; Mon, 30 May 2011 15:08:25 +0200 (CEST) Received: by quack.suse.cz (Postfix, from userid 1000) id 27C3220568; Mon, 30 May 2011 15:08:24 +0200 (CEST) From: Jan Kara To: linux-ext4@vger.kernel.org Cc: Andrew Morton , Jan Kara , Sage Weil Subject: [PATCH] ext3: Fix oops in ext3_try_to_allocate_with_rsv() Date: Mon, 30 May 2011 15:08:22 +0200 Message-Id: <1306760902-16160-1-git-send-email-jack@suse.cz> X-Mailer: git-send-email 1.7.1 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Block allocation is called from two places: ext3_get_blocks_handle() and ext3_xattr_block_set(). These two callers are not necessarily synchronized because xattr code holds only xattr_sem and i_mutex, and ext3_get_blocks_handle() may hold only truncate_mutex when called from writepage() path. Block reservation code does not expect two concurrent allocations to happen to the same inode and thus assertions can be triggered or reservation structure corruption can occur. Fix the problem by taking truncate_mutex in xattr code to serialize allocations. CC: Sage Weil Reported-by: Fyodor Ustinov Signed-off-by: Jan Kara --- fs/ext3/xattr.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) I plan to put this into my tree. diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c index 32e6cc2..d565759 100644 --- a/fs/ext3/xattr.c +++ b/fs/ext3/xattr.c @@ -803,8 +803,16 @@ inserted: /* We need to allocate a new block */ ext3_fsblk_t goal = ext3_group_first_block_no(sb, EXT3_I(inode)->i_block_group); - ext3_fsblk_t block = ext3_new_block(handle, inode, - goal, &error); + ext3_fsblk_t block; + + /* + * Protect us agaist concurrent allocations to the + * same inode from ext3_..._writepage(). Reservation + * code does not expect racing allocations. + */ + mutex_lock(&EXT3_I(inode)->truncate_mutex); + block = ext3_new_block(handle, inode, goal, &error); + mutex_unlock(&EXT3_I(inode)->truncate_mutex); if (error) goto cleanup; ea_idebug(inode, "creating block %d", block);