Skip to contentSkip to conversation

Fix race in ext4_mb_add_n_trim()

PATCH Applied Niu Yawei 2 participants 2 messages Jan 7, 2013 – Feb 2, 2013 ext4 file system

lore
Share & tools
lore

Niu Yawei

author
#0 lore raw

PATCH 1/1 Fix race in ext4_mb_add_n_trim()

Quoted 1 line

From 020243735e97f327ecba729ec05d4e3facdddc78 Mon Sep 17 00:00:00 2001

From: Niu Yawei <[email protected]>
Date: Mon, 7 Jan 2013 01:03:26 -0500
Subject: [PATCH] Fix race in ext4_mb_add_n_trim()

In ext4_mb_add_n_trim(), lg_prealloc_lock should be taken when changing the lg_prealloc_list.

---
 fs/ext4/mballoc.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/ext4/mballoc.c +2 -2
index 1bf6fe7..45d3527 100644
@@ -4136,7 +4136,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);
@@ -4160,7 +4160,7 @@ 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) {

--
1.7.1

maintainer Applied
#1 lore raw
Quoted 9 lines · Niu Yawei
Quoted 1 line

From 020243735e97f327ecba729ec05d4e3facdddc78 Mon Sep 17 00:00:00 2001

From: Niu Yawei <[email protected]>
Date: Mon, 7 Jan 2013 01:03:26 -0500
Subject: [PATCH] Fix race in ext4_mb_add_n_trim()

In ext4_mb_add_n_trim(), lg_prealloc_lock should be taken when changing the lg_prealloc_list.

Applied, thanks!

- Ted