Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp253410ybb; Fri, 3 Apr 2020 02:01:14 -0700 (PDT) X-Google-Smtp-Source: APiQypJ6DgcDXl48GdTNIFGcOGXxXkWVD+9UqY6Ktss2romoOVl7aKHosvzxxRyzF5zWJBc/9N54 X-Received: by 2002:a9d:6e92:: with SMTP id a18mr5890851otr.17.1585904474688; Fri, 03 Apr 2020 02:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585904474; cv=none; d=google.com; s=arc-20160816; b=lVi0Gmao1eGsO3CgMfdSo6x/IKrjI7Yp8/f0nU6g8TZlEgUVl5WjCj+/56Ap5WUAqQ gEbUXojHFRuV3JE8OvYX0G55p+w5A01W+J7Vut1fZ4yshh6GbLimOz0rdN0DCy2LoV8D 2NnRfjZX+z7nd5+l6lQhhjogHbAeZGS1EWRpjef+0wyBmBzwYlU8TXzADFpXh30MBwbw KhXABhFOPP4DHU0vD4Q49l2CzMAcrry6KPXA5+pK+2/15crV9ojMtTDm3zmbfxsP0NLN 8e34VNllg6aSZyxGpooU7Np+L7CC9s6vJHyxliB31qQu0O/8SsY5G/IOFNS377aI0rIz EOBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=Mv/RJfrw7+83pPb7W9RY3+MP8LfpN9mukyRRsXb/aFs=; b=ZGJdRDod+Pt4JSYCy0RJZl3rN6KubNQEtzEVUBe8Opj1NuwtqbBJ+AfJo2+IJG8vjr adB+D+Jh2jtFNQd6bV9rN7bvOBE64oglYFbYwGaIOsIYtTcujS1q33UT74eh2UDNk5Nv Bga9mkpXdwyOoB3j8zR0+yt6/WwJOmz9H3eU8jijuvAIgvdGwDj/INlzA3wjKQH0joOB 99hw3obQNI/DqUtcDqcXLpuk7bVtPu/boulbh9NeRycSIA8ykIyrXOt3vSton10jJ6SO uKNPsvRnnrpmq+bcEwxgFSvcf4TChMxK8N2NKboC9mRUmJ9UrvOpPOAGaCVkfApne/1d 5N0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p187si3529481oop.28.2020.04.03.02.01.01; Fri, 03 Apr 2020 02:01:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390495AbgDCJAj (ORCPT + 99 others); Fri, 3 Apr 2020 05:00:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:59384 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727803AbgDCJAj (ORCPT ); Fri, 3 Apr 2020 05:00:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8972EAEB1; Fri, 3 Apr 2020 09:00:37 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe , stable@vger.kernel.org Subject: [PATCH] xen/blkfront: fix memory allocation flags in blkfront_setup_indirect() Date: Fri, 3 Apr 2020 11:00:34 +0200 Message-Id: <20200403090034.8753-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 1d5c76e664333 ("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: 1d5c76e664333 ("xen-blkfront: switch kcalloc to kvcalloc for large array allocation") Cc: stable@vger.kernel.org Signed-off-by: Juergen Gross --- drivers/block/xen-blkfront.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 915cf5b6388c..3b889ea950c2 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -2189,10 +2190,12 @@ static void blkfront_setup_discard(struct blkfront_info *info) static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) { - unsigned int psegs, grants; + unsigned int psegs, grants, memflags; int err, i; struct blkfront_info *info = rinfo->dev_info; + memflags = memalloc_noio_save(); + if (info->max_indirect_segments == 0) { if (!HAS_EXTRA_REQ) grants = BLKIF_MAX_SEGMENTS_PER_REQUEST; @@ -2224,7 +2227,7 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) BUG_ON(!list_empty(&rinfo->indirect_pages)); for (i = 0; i < num; i++) { - struct page *indirect_page = alloc_page(GFP_NOIO); + struct page *indirect_page = alloc_page(GFP_KERNEL); if (!indirect_page) goto out_of_memory; list_add(&indirect_page->lru, &rinfo->indirect_pages); @@ -2235,15 +2238,15 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) rinfo->shadow[i].grants_used = kvcalloc(grants, sizeof(rinfo->shadow[i].grants_used[0]), - GFP_NOIO); + GFP_KERNEL); rinfo->shadow[i].sg = kvcalloc(psegs, sizeof(rinfo->shadow[i].sg[0]), - GFP_NOIO); + GFP_KERNEL); if (info->max_indirect_segments) rinfo->shadow[i].indirect_grants = kvcalloc(INDIRECT_GREFS(grants), sizeof(rinfo->shadow[i].indirect_grants[0]), - GFP_NOIO); + GFP_KERNEL); if ((rinfo->shadow[i].grants_used == NULL) || (rinfo->shadow[i].sg == NULL) || (info->max_indirect_segments && @@ -2252,6 +2255,7 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) sg_init_table(rinfo->shadow[i].sg, psegs); } + memalloc_noio_restore(memflags); return 0; @@ -2271,6 +2275,9 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) __free_page(indirect_page); } } + + memalloc_noio_restore(memflags); + return -ENOMEM; } -- 2.16.4