* FAILED: patch "[PATCH] block: Limit zone array allocation size" failed to apply to 5.1-stable tree
@ 2019-07-23 11:56 gregkh
2019-07-25 6:06 ` Damien Le Moal
0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2019-07-23 11:56 UTC (permalink / raw)
To: damien.lemoal, axboe, hch, martin.petersen; +Cc: stable
The patch below does not apply to the 5.1-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 26202928fafad8bda8b478edb7e62c885be623d7 Mon Sep 17 00:00:00 2001
From: Damien Le Moal <damien.lemoal@wdc.com>
Date: Mon, 1 Jul 2019 14:09:18 +0900
Subject: [PATCH] block: Limit zone array allocation size
Limit the size of the struct blk_zone array used in
blk_revalidate_disk_zones() to avoid memory allocation failures leading
to disk revalidation failure. Also further reduce the likelyhood of
such failures by using kvcalloc() (that is vmalloc()) instead of
allocating contiguous pages with alloc_pages().
Fixes: 515ce6061312 ("scsi: sd_zbc: Fix sd_zbc_report_zones() buffer allocation")
Fixes: e76239a3748c ("block: add a report_zones method")
Cc: stable@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 58ced170b424..6c503824ba3f 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -14,6 +14,8 @@
#include <linux/rbtree.h>
#include <linux/blkdev.h>
#include <linux/blk-mq.h>
+#include <linux/mm.h>
+#include <linux/vmalloc.h>
#include <linux/sched/mm.h>
#include "blk.h"
@@ -371,22 +373,25 @@ static inline unsigned long *blk_alloc_zone_bitmap(int node,
* Allocate an array of struct blk_zone to get nr_zones zone information.
* The allocated array may be smaller than nr_zones.
*/
-static struct blk_zone *blk_alloc_zones(int node, unsigned int *nr_zones)
+static struct blk_zone *blk_alloc_zones(unsigned int *nr_zones)
{
- size_t size = *nr_zones * sizeof(struct blk_zone);
- struct page *page;
- int order;
-
- for (order = get_order(size); order >= 0; order--) {
- page = alloc_pages_node(node, GFP_NOIO | __GFP_ZERO, order);
- if (page) {
- *nr_zones = min_t(unsigned int, *nr_zones,
- (PAGE_SIZE << order) / sizeof(struct blk_zone));
- return page_address(page);
- }
+ struct blk_zone *zones;
+ size_t nrz = min(*nr_zones, BLK_ZONED_REPORT_MAX_ZONES);
+
+ /*
+ * GFP_KERNEL here is meaningless as the caller task context has
+ * the PF_MEMALLOC_NOIO flag set in blk_revalidate_disk_zones()
+ * with memalloc_noio_save().
+ */
+ zones = kvcalloc(nrz, sizeof(struct blk_zone), GFP_KERNEL);
+ if (!zones) {
+ *nr_zones = 0;
+ return NULL;
}
- return NULL;
+ *nr_zones = nrz;
+
+ return zones;
}
void blk_queue_free_zone_bitmaps(struct request_queue *q)
@@ -448,7 +453,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
/* Get zone information and initialize seq_zones_bitmap */
rep_nr_zones = nr_zones;
- zones = blk_alloc_zones(q->node, &rep_nr_zones);
+ zones = blk_alloc_zones(&rep_nr_zones);
if (!zones)
goto out;
@@ -487,8 +492,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
out:
memalloc_noio_restore(noio_flag);
- free_pages((unsigned long)zones,
- get_order(rep_nr_zones * sizeof(struct blk_zone)));
+ kvfree(zones);
kfree(seq_zones_wlock);
kfree(seq_zones_bitmap);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 05036e3e3458..1ef375dafb1c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -344,6 +344,11 @@ struct queue_limits {
#ifdef CONFIG_BLK_DEV_ZONED
+/*
+ * Maximum number of zones to report with a single report zones command.
+ */
+#define BLK_ZONED_REPORT_MAX_ZONES 8192U
+
extern unsigned int blkdev_nr_zones(struct block_device *bdev);
extern int blkdev_report_zones(struct block_device *bdev,
sector_t sector, struct blk_zone *zones,
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] block: Limit zone array allocation size" failed to apply to 5.1-stable tree
2019-07-23 11:56 FAILED: patch "[PATCH] block: Limit zone array allocation size" failed to apply to 5.1-stable tree gregkh
@ 2019-07-25 6:06 ` Damien Le Moal
2019-07-25 6:34 ` gregkh
0 siblings, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2019-07-25 6:06 UTC (permalink / raw)
To: hch, gregkh, axboe, martin.petersen; +Cc: stable
On Tue, 2019-07-23 at 13:56 +0200, gregkh@linuxfoundation.org wrote:
> The patch below does not apply to the 5.1-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
>
> thanks,
>
> greg k-h
Greg,
I sent you a backported version that applies cleanly to both 5.1 and
5.2 stable trees.
Best regards.
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] block: Limit zone array allocation size" failed to apply to 5.1-stable tree
2019-07-25 6:06 ` Damien Le Moal
@ 2019-07-25 6:34 ` gregkh
2019-07-25 7:03 ` Damien Le Moal
0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2019-07-25 6:34 UTC (permalink / raw)
To: Damien Le Moal; +Cc: hch, axboe, martin.petersen, stable
On Thu, Jul 25, 2019 at 06:06:45AM +0000, Damien Le Moal wrote:
> On Tue, 2019-07-23 at 13:56 +0200, gregkh@linuxfoundation.org wrote:
> > The patch below does not apply to the 5.1-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
> >
> > thanks,
> >
> > greg k-h
>
> Greg,
>
> I sent you a backported version that applies cleanly to both 5.1 and
> 5.2 stable trees.
Please fix up your backports and send them in a format that I can use
that does not lie about the author of the patch :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] block: Limit zone array allocation size" failed to apply to 5.1-stable tree
2019-07-25 6:34 ` gregkh
@ 2019-07-25 7:03 ` Damien Le Moal
0 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2019-07-25 7:03 UTC (permalink / raw)
To: gregkh; +Cc: hch, stable, axboe, martin.petersen
On Thu, 2019-07-25 at 08:34 +0200, gregkh@linuxfoundation.org wrote:
> On Thu, Jul 25, 2019 at 06:06:45AM +0000, Damien Le Moal wrote:
> > On Tue, 2019-07-23 at 13:56 +0200, gregkh@linuxfoundation.org wrote:
> > > The patch below does not apply to the 5.1-stable tree.
> > > If someone wants it applied there, or to any other stable or longterm
> > > tree, then please email the backport, including the original git commit
> > > id to <stable@vger.kernel.org>.
> > >
> > > thanks,
> > >
> > > greg k-h
> >
> > Greg,
> >
> > I sent you a backported version that applies cleanly to both 5.1 and
> > 5.2 stable trees.
>
> Please fix up your backports and send them in a format that I can use
> that does not lie about the author of the patch :)
>
> thanks,
>
> greg k-h
Ooops. Sorry about that. Fixing and resending.
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-25 7:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23 11:56 FAILED: patch "[PATCH] block: Limit zone array allocation size" failed to apply to 5.1-stable tree gregkh
2019-07-25 6:06 ` Damien Le Moal
2019-07-25 6:34 ` gregkh
2019-07-25 7:03 ` Damien Le Moal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).