From ba54d4d4d2844c234f1b4692bd8c9e0f833c8a54 Mon Sep 17 00:00:00 2001
From: Coly Li <colyli@suse.de>
Date: Thu, 9 Apr 2020 22:17:21 +0800
Subject: [PATCH] raid5: remove gfp flags from scribble_alloc()
Git-commit: ba54d4d4d2844c234f1b4692bd8c9e0f833c8a54
Patch-mainline: v5.8-rc1
References: bsc#1166985
Using GFP_NOIO flag to call scribble_alloc() from resize_chunk() does
not have the expected behavior. kvmalloc_array() inside scribble_alloc()
which receives the GFP_NOIO flag will eventually call kmalloc_node() to
allocate physically continuous pages.
Now we have memalloc scope APIs in mddev_suspend()/mddev_resume() to
prevent memory reclaim I/Os during raid array suspend context, calling
to kvmalloc_array() with GFP_KERNEL flag may avoid deadlock of recursive
I/O as expected.
This patch removes the useless gfp flags from parameters list of
scribble_alloc(), and call kvmalloc_array() with GFP_KERNEL flag. The
incorrect GFP_NOIO flag does not exist anymore.
(Coly Li: to avoid kabi breaking by adding noio_flag in struct mddev,
commit 78f57ef9d50a is not backported and I modify this patch to use
local noio_flag variable in scribble_alloc().)
Fixes: b330e6a49dc3 ("md: convert to kvmalloc")
Suggested-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
drivers/md/raid5.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -46,6 +46,7 @@
#include <linux/slab.h>
#include <linux/ratelimit.h>
#include <linux/nodemask.h>
+#include <linux/sched/mm.h>
#include <trace/events/block.h>
#include <linux/list_sort.h>
@@ -2228,14 +2229,18 @@ static int grow_stripes(struct r5conf *c
* of the P and Q blocks.
*/
static int scribble_alloc(struct raid5_percpu *percpu,
- int num, int cnt, gfp_t flags)
+ int num, int cnt)
{
size_t obj_size =
sizeof(struct page *) * (num+2) +
sizeof(addr_conv_t) * (num+2);
void *scribble;
+ unsigned int noio_flag;
- scribble = kvmalloc_array(cnt, obj_size, flags);
+ /* use local noio_flag to avoid kabi breaking */
+ noio_flag = memalloc_noio_save();
+ scribble = kvmalloc_array(cnt, obj_size, GFP_KERNEL);
+ memalloc_noio_restore(noio_flag);
if (!scribble)
return -ENOMEM;
@@ -2267,8 +2272,7 @@ static int resize_chunks(struct r5conf *
percpu = per_cpu_ptr(conf->percpu, cpu);
err = scribble_alloc(percpu, new_disks,
- new_sectors / STRIPE_SECTORS,
- GFP_NOIO);
+ new_sectors / STRIPE_SECTORS);
if (err)
break;
}
@@ -6759,8 +6763,7 @@ static int alloc_scratch_buffer(struct r
conf->previous_raid_disks),
max(conf->chunk_sectors,
conf->prev_chunk_sectors)
- / STRIPE_SECTORS,
- GFP_KERNEL)) {
+ / STRIPE_SECTORS)) {
free_scratch_buffer(conf, percpu);
return -ENOMEM;
}