Skip to content

Commit 3a169c0

Browse files
committed
xen/blkfront: fix memory allocation flags in blkfront_setup_indirect()
Commit 1d5c76e ("xen-blkfront: switch kcalloc to kvcalloc for large array allocation") didn't fix the issue it was meant to, as the flags for allocating the memory are GFP_NOIO, which will lead the memory allocation falling back to kmalloc(). So instead of GFP_NOIO use GFP_KERNEL and do all the memory allocation in blkfront_setup_indirect() in a memalloc_noio_{save,restore} section. Fixes: 1d5c76e ("xen-blkfront: switch kcalloc to kvcalloc for large array allocation") Cc: [email protected] Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Acked-by: Roger Pau Monné <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 0102e4e commit 3a169c0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/block/xen-blkfront.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <linux/bitmap.h>
4848
#include <linux/list.h>
4949
#include <linux/workqueue.h>
50+
#include <linux/sched/mm.h>
5051

5152
#include <xen/xen.h>
5253
#include <xen/xenbus.h>
@@ -2189,10 +2190,12 @@ static void blkfront_setup_discard(struct blkfront_info *info)
21892190

21902191
static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
21912192
{
2192-
unsigned int psegs, grants;
2193+
unsigned int psegs, grants, memflags;
21932194
int err, i;
21942195
struct blkfront_info *info = rinfo->dev_info;
21952196

2197+
memflags = memalloc_noio_save();
2198+
21962199
if (info->max_indirect_segments == 0) {
21972200
if (!HAS_EXTRA_REQ)
21982201
grants = BLKIF_MAX_SEGMENTS_PER_REQUEST;
@@ -2224,7 +2227,7 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
22242227

22252228
BUG_ON(!list_empty(&rinfo->indirect_pages));
22262229
for (i = 0; i < num; i++) {
2227-
struct page *indirect_page = alloc_page(GFP_NOIO);
2230+
struct page *indirect_page = alloc_page(GFP_KERNEL);
22282231
if (!indirect_page)
22292232
goto out_of_memory;
22302233
list_add(&indirect_page->lru, &rinfo->indirect_pages);
@@ -2235,15 +2238,15 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
22352238
rinfo->shadow[i].grants_used =
22362239
kvcalloc(grants,
22372240
sizeof(rinfo->shadow[i].grants_used[0]),
2238-
GFP_NOIO);
2241+
GFP_KERNEL);
22392242
rinfo->shadow[i].sg = kvcalloc(psegs,
22402243
sizeof(rinfo->shadow[i].sg[0]),
2241-
GFP_NOIO);
2244+
GFP_KERNEL);
22422245
if (info->max_indirect_segments)
22432246
rinfo->shadow[i].indirect_grants =
22442247
kvcalloc(INDIRECT_GREFS(grants),
22452248
sizeof(rinfo->shadow[i].indirect_grants[0]),
2246-
GFP_NOIO);
2249+
GFP_KERNEL);
22472250
if ((rinfo->shadow[i].grants_used == NULL) ||
22482251
(rinfo->shadow[i].sg == NULL) ||
22492252
(info->max_indirect_segments &&
@@ -2252,6 +2255,7 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
22522255
sg_init_table(rinfo->shadow[i].sg, psegs);
22532256
}
22542257

2258+
memalloc_noio_restore(memflags);
22552259

22562260
return 0;
22572261

@@ -2271,6 +2275,9 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
22712275
__free_page(indirect_page);
22722276
}
22732277
}
2278+
2279+
memalloc_noio_restore(memflags);
2280+
22742281
return -ENOMEM;
22752282
}
22762283

0 commit comments

Comments
 (0)