From: Niu Yawei Date: Sat, 2 Feb 2013 02:31:27 +0000 (-0500) Subject: ext4: fix race in ext4_mb_add_n_trim() X-Git-Tag: v2.6.32.61~59 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=75de899bc295e9f4d14a359fe59c55bc9fe6ac27;p=thirdparty%2Fkernel%2Fstable.git ext4: fix race in ext4_mb_add_n_trim() commit f1167009711032b0d747ec89a632a626c901a1ad upstream. In ext4_mb_add_n_trim(), lg_prealloc_lock should be taken when changing the lg_prealloc_list. Signed-off-by: Niu Yawei Signed-off-by: "Theodore Ts'o" Signed-off-by: Greg Kroah-Hartman Signed-off-by: Willy Tarreau --- diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 42bac1bfe5c3d..c7e8bdb409810 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4163,7 +4163,7 @@ static void ext4_mb_add_n_trim(struct ext4_allocation_context *ac) /* The max size of hash table is PREALLOC_TB_SIZE */ order = PREALLOC_TB_SIZE - 1; /* Add the prealloc space to lg */ - rcu_read_lock(); + spin_lock(&lg->lg_prealloc_lock); list_for_each_entry_rcu(tmp_pa, &lg->lg_prealloc_list[order], pa_inode_list) { spin_lock(&tmp_pa->pa_lock); @@ -4187,12 +4187,12 @@ static void ext4_mb_add_n_trim(struct ext4_allocation_context *ac) if (!added) list_add_tail_rcu(&pa->pa_inode_list, &lg->lg_prealloc_list[order]); - rcu_read_unlock(); + spin_unlock(&lg->lg_prealloc_lock); /* Now trim the list to be not more than 8 elements */ if (lg_prealloc_count > 8) { ext4_mb_discard_lg_preallocations(sb, lg, - order, lg_prealloc_count); + order, lg_prealloc_count); return; } return ;