[ 3.5.y.z extended stable ] Patch "ext4: fix race in ext4_mb_add_n_trim()" has been added to staging queue

Luis Henriques luis.henriques at canonical.com
Thu Feb 28 11:57:33 UTC 2013

This is a note to let you know that I have just added a patch titled

    ext4: fix race in ext4_mb_add_n_trim()

to the linux-3.5.y-queue branch of the 3.5.y.z extended stable tree 
which can be found at:


If you, or anyone else, feels it should not be added to this tree, please 
reply to this email.

For more information about the 3.5.y.z tree, see



>From a429fe9eccbe3e667f306ed3fd2a4911aff6d5e3 Mon Sep 17 00:00:00 2001
From: Niu Yawei <yawei.niu at gmail.com>
Date: Fri, 1 Feb 2013 21:31:27 -0500
Subject: [PATCH] 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 <yawei.niu at intel.com>
Signed-off-by: "Theodore Ts'o" <tytso at mit.edu>
Signed-off-by: Luis Henriques <luis.henriques at canonical.com>
 fs/ext4/mballoc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index af848bb..b5f8b5f 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4123,7 +4123,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) {
@@ -4147,12 +4147,12 @@ static void ext4_mb_add_n_trim(struct ext4_allocation_context *ac)
 	if (!added)
-	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 ;

More information about the kernel-team mailing list