z3fold: fix sheduling while atomic
authorVitaly Wool <vitalywool@gmail.com>
Sat, 1 Jun 2019 05:30:39 +0000 (22:30 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 1 Jun 2019 22:51:31 +0000 (15:51 -0700)
kmem_cache_alloc() may be called from z3fold_alloc() in atomic context, so
we need to pass correct gfp flags to avoid "scheduling while atomic" bug.

Link: http://lkml.kernel.org/r/20190523153245.119dfeed55927e8755250ddd@gmail.com
Fixes: 7c2b8baa61fe5 ("mm/z3fold.c: add structure for buddy handles")
Signed-off-by: Vitaly Wool <vitaly.vul@sony.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/z3fold.c

index 99be52c5ca4577bc66c8e5a1b1ee6f6a77877d90..985732c8b025eb0c4064a18243114b25b34e5e87 100644 (file)
@@ -190,10 +190,11 @@ static int size_to_chunks(size_t size)
 
 static void compact_page_work(struct work_struct *w);
 
-static inline struct z3fold_buddy_slots *alloc_slots(struct z3fold_pool *pool)
+static inline struct z3fold_buddy_slots *alloc_slots(struct z3fold_pool *pool,
+                                                       gfp_t gfp)
 {
        struct z3fold_buddy_slots *slots = kmem_cache_alloc(pool->c_handle,
-                                                       GFP_KERNEL);
+                                                           gfp);
 
        if (slots) {
                memset(slots->slot, 0, sizeof(slots->slot));
@@ -295,10 +296,10 @@ static void z3fold_unregister_migration(struct z3fold_pool *pool)
 
 /* Initializes the z3fold header of a newly allocated z3fold page */
 static struct z3fold_header *init_z3fold_page(struct page *page,
-                                       struct z3fold_pool *pool)
+                                       struct z3fold_pool *pool, gfp_t gfp)
 {
        struct z3fold_header *zhdr = page_address(page);
-       struct z3fold_buddy_slots *slots = alloc_slots(pool);
+       struct z3fold_buddy_slots *slots = alloc_slots(pool, gfp);
 
        if (!slots)
                return NULL;
@@ -912,7 +913,7 @@ retry:
        if (!page)
                return -ENOMEM;
 
-       zhdr = init_z3fold_page(page, pool);
+       zhdr = init_z3fold_page(page, pool, gfp);
        if (!zhdr) {
                __free_page(page);
                return -ENOMEM;