]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
vfs: fix possible deadlock in ext2, ext3, ext4 when using xattrs
authorJan Kara <jack@suse.cz>
Tue, 15 Apr 2008 21:34:43 +0000 (14:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 16 Apr 2008 02:35:41 +0000 (19:35 -0700)
mb_cache_entry_alloc() was allocating cache entries with GFP_KERNEL.  But
filesystems are calling this function while holding xattr_sem so possible
recursion into the fs violates locking ordering of xattr_sem and transaction
start / i_mutex for ext2-4.  Change mb_cache_entry_alloc() so that filesystems
can specify desired gfp mask and use GFP_NOFS from all of them.

Signed-off-by: Jan Kara <jack@suse.cz>
Reported-by: Dave Jones <davej@redhat.com>
Cc: <linux-ext4@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ext2/xattr.c
fs/ext3/xattr.c
fs/ext4/xattr.c
fs/mbcache.c
include/linux/mbcache.h

index 3e8683dbb13fb0d5cfa12ffbc9bccf560fe63d52..a99d46f3b26eb032e13c5a3d9f26484518997b5c 100644 (file)
@@ -835,7 +835,7 @@ ext2_xattr_cache_insert(struct buffer_head *bh)
        struct mb_cache_entry *ce;
        int error;
 
-       ce = mb_cache_entry_alloc(ext2_xattr_cache);
+       ce = mb_cache_entry_alloc(ext2_xattr_cache, GFP_NOFS);
        if (!ce)
                return -ENOMEM;
        error = mb_cache_entry_insert(ce, bh->b_bdev, bh->b_blocknr, &hash);
index a6ea4d6a8bb2f61a9fee389c6b6f519ff68251a5..42856541e9a5aad9a50fc32a83f6802c2c01a976 100644 (file)
@@ -1126,7 +1126,7 @@ ext3_xattr_cache_insert(struct buffer_head *bh)
        struct mb_cache_entry *ce;
        int error;
 
-       ce = mb_cache_entry_alloc(ext3_xattr_cache);
+       ce = mb_cache_entry_alloc(ext3_xattr_cache, GFP_NOFS);
        if (!ce) {
                ea_bdebug(bh, "out of memory");
                return;
index d7962139c0108a329386b86d61088cc4dedb3eb1..e9054c1c7d9366ce36f1d140b125c5db8915cd15 100644 (file)
@@ -1386,7 +1386,7 @@ ext4_xattr_cache_insert(struct buffer_head *bh)
        struct mb_cache_entry *ce;
        int error;
 
-       ce = mb_cache_entry_alloc(ext4_xattr_cache);
+       ce = mb_cache_entry_alloc(ext4_xattr_cache, GFP_NOFS);
        if (!ce) {
                ea_bdebug(bh, "out of memory");
                return;
index eb31b73e7d6999357cd86bd7af0ff208b917ca5d..ec88ff3d04a9194a4b595701e917ef784b8bdc2a 100644 (file)
@@ -399,11 +399,11 @@ mb_cache_destroy(struct mb_cache *cache)
  * if no more memory was available.
  */
 struct mb_cache_entry *
-mb_cache_entry_alloc(struct mb_cache *cache)
+mb_cache_entry_alloc(struct mb_cache *cache, gfp_t gfp_flags)
 {
        struct mb_cache_entry *ce;
 
-       ce = kmem_cache_alloc(cache->c_entry_cache, GFP_KERNEL);
+       ce = kmem_cache_alloc(cache->c_entry_cache, gfp_flags);
        if (ce) {
                atomic_inc(&cache->c_entry_count);
                INIT_LIST_HEAD(&ce->e_lru_list);
index 99e044b4efc6d62ea92e79f79a2b74ec8b8559ad..a09b84e4fdb42d0cd6fb20e60e7f3d079c595a53 100644 (file)
@@ -34,7 +34,7 @@ void mb_cache_destroy(struct mb_cache *);
 
 /* Functions on cache entries */
 
-struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *);
+struct mb_cache_entry *mb_cache_entry_alloc(struct mb_cache *, gfp_t);
 int mb_cache_entry_insert(struct mb_cache_entry *, struct block_device *,
                          sector_t, unsigned int[]);
 void mb_cache_entry_release(struct mb_cache_entry *);