From patchwork Tue Dec 3 09:39:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270863 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 888DC921 for ; Tue, 3 Dec 2019 09:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 680D7206EC for ; Tue, 3 Dec 2019 09:39:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Q3glmRFU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726114AbfLCJjP (ORCPT ); Tue, 3 Dec 2019 04:39:15 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:32798 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfLCJjO (ORCPT ); Tue, 3 Dec 2019 04:39:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=I/dfLPEiJpRIYKhZnVcBN19bbymOFqlsA3ZFJkAje4A=; b=Q3glmRFUmXm846UB98NIjadgfc cbEDWXy4kbrVUEcip/ig0mXig60bCZ9diASH0ejo7QZ/3MlS2Z9kwY9icBLyslX5U/GIVW96XuwDP E7pCxLJ8Gonpv6KlYcYMfC1NOqh7mrzcDWeag/zMpJtYkPuGbCHGcH1PxVVbzJkKUUM3j6icWtVYw GlyJK7vnyeLRrjb0JbTRejZC3QbUVnJQvYLA4gKG6oPQsBMgiu0o9aCcojofdgNhAl2lQp9DCLokT n7wz2UomZMIz3jxPGL1V5Q4LSgWFBTkgWJvJuJaqdqNUQ7pD/TL3lRW5qEFg8f5cmB2fHktQuxVrb VrSQ+qBQ==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eH-00023t-DH; Tue, 03 Dec 2019 09:39:13 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org, Damien Le Moal Subject: [PATCH 1/8] null_blk: fix zone size paramter check Date: Tue, 3 Dec 2019 10:39:01 +0100 Message-Id: <20191203093908.24612-2-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Damien Le Moal For zoned=1 mode, the zone size must be a power of 2. Check this not only when the zone size is specified during modprobe, but also when creating a zoned null_blk device using configfs. Signed-off-by: Damien Le Moal Signed-off-by: Christoph Hellwig --- drivers/block/null_blk_main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 795fda576824..53ba9c7f2786 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1607,7 +1607,7 @@ static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set *set) return blk_mq_alloc_tag_set(set); } -static void null_validate_conf(struct nullb_device *dev) +static int null_validate_conf(struct nullb_device *dev) { dev->blocksize = round_down(dev->blocksize, 512); dev->blocksize = clamp_t(unsigned int, dev->blocksize, 512, 4096); @@ -1634,6 +1634,14 @@ static void null_validate_conf(struct nullb_device *dev) /* can not stop a queue */ if (dev->queue_mode == NULL_Q_BIO) dev->mbps = 0; + + if (dev->zoned && + (!dev->zone_size || !is_power_of_2(dev->zone_size))) { + pr_err("zone_size must be power-of-two\n"); + return -EINVAL; + } + + return 0; } #ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION @@ -1666,7 +1674,9 @@ static int null_add_dev(struct nullb_device *dev) struct nullb *nullb; int rv; - null_validate_conf(dev); + rv = null_validate_conf(dev); + if (rv) + return rv; nullb = kzalloc_node(sizeof(*nullb), GFP_KERNEL, dev->home_node); if (!nullb) { @@ -1792,11 +1802,6 @@ static int __init null_init(void) g_bs = PAGE_SIZE; } - if (!is_power_of_2(g_zone_size)) { - pr_err("zone_size must be power-of-two\n"); - return -EINVAL; - } - if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) { pr_err("invalid home_node value\n"); g_home_node = NUMA_NO_NODE; From patchwork Tue Dec 3 09:39:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9840A13B6 for ; Tue, 3 Dec 2019 09:39:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E36C206EC for ; Tue, 3 Dec 2019 09:39:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ThXy0ykT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726107AbfLCJjS (ORCPT ); Tue, 3 Dec 2019 04:39:18 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:32946 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfLCJjR (ORCPT ); Tue, 3 Dec 2019 04:39:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=cl6DErnYywuBNiTuVq8pI49RhMOPOBTZno8uKgIYA2g=; b=ThXy0ykTmjuL99/vFcjNKNW2VJ mq6E169ELOvmlmj4pZdfSww7SUZnCfRwCypnkZmdiKYDX0c7rBkkRuAEPgxoFJL83jPZOQd+JHZe0 TqYo59ACJ51BkKKF+qbWBoBksmvGuKOINCYJcRCTz/b35zCIHI7iHLX/WQTVYXHo5khT5no2/G7+M eVVCKLQcRMSBzQoKwC0CM17MKLvJuKuMQBbr6nyNxwb553cWctRl4UJP8ce/u3J0xbcEONkyWyw0o Xlh4uGtahOC2d5V7DudDI97dT7VoWQFx3OFY4qX3eIxob2dmxT9MZiOXsXReKBu4Bml/Q9Z+8oy0T IEnZPe9w==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eJ-00025H-KD; Tue, 03 Dec 2019 09:39:15 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org Subject: [PATCH 2/8] null_blk: cleanup null_gendisk_register Date: Tue, 3 Dec 2019 10:39:02 +0100 Message-Id: <20191203093908.24612-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Use a saner size calculation, and do a trivial cleanup on the zone revalidation to prepare to future changes. Signed-off-by: Christoph Hellwig --- drivers/block/null_blk_main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 53ba9c7f2786..dd6026289fbf 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1559,14 +1559,14 @@ static int init_driver_queues(struct nullb *nullb) static int null_gendisk_register(struct nullb *nullb) { + sector_t size = ((sector_t)nullb->dev->size * SZ_1M) >> SECTOR_SHIFT; struct gendisk *disk; - sector_t size; + int ret; disk = nullb->disk = alloc_disk_node(1, nullb->dev->home_node); if (!disk) return -ENOMEM; - size = (sector_t)nullb->dev->size * 1024 * 1024ULL; - set_capacity(disk, size >> 9); + set_capacity(disk, size); disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO; disk->major = null_major; @@ -1577,9 +1577,8 @@ static int null_gendisk_register(struct nullb *nullb) strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN); if (nullb->dev->zoned) { - int ret = blk_revalidate_disk_zones(disk); - - if (ret != 0) + ret = blk_revalidate_disk_zones(disk); + if (ret) return ret; } From patchwork Tue Dec 3 09:39:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270865 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1756159A for ; Tue, 3 Dec 2019 09:39:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7526220661 for ; Tue, 3 Dec 2019 09:39:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="uK2EhLI6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726138AbfLCJjT (ORCPT ); Tue, 3 Dec 2019 04:39:19 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:32978 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfLCJjS (ORCPT ); Tue, 3 Dec 2019 04:39:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZWNuk9tGiFLw60K3+rMwEOfotKEctVC+64L+2oyWZcg=; b=uK2EhLI6LqBXjH0GkVuKjW29TE 49A7qyay7ke6yFkBzrdG0klMpQwS8+qcIIDvScsAuS3hPSmJ9bfjSEAUi93+n9sob+6EX/GslmKmG jMdmIkPSBKwMY0FC9vPA/s+64p+jZbXlljHBDpadJVmNuZOb9S7bwo1DJELWrVLH4NEa+J71TZGzH 1DZb6Kyz3zb1SfoLSWWDBnei5k77czDQUVUYQSFxSZvLpiHOXoKA9zvRFNaVIYiz1r3CeFxMUNsyI qnRTXREhDBVq3G6j77wxH0KfSyGvZkwqMZZTCtj4+iOLIeLd0LtV/pRYLjx1TLAGK7MK+UAXcjd7b Fc0vXBXw==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eL-00026k-QD; Tue, 03 Dec 2019 09:39:18 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org Subject: [PATCH 3/8] block: remove the empty line at the end of blk-zoned.c Date: Tue, 3 Dec 2019 10:39:03 +0100 Message-Id: <20191203093908.24612-4-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Signed-off-by: Christoph Hellwig --- block/blk-zoned.c | 1 - 1 file changed, 1 deletion(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 6fad6f3f6980..618786f8275c 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -488,4 +488,3 @@ int blk_revalidate_disk_zones(struct gendisk *disk) return ret; } EXPORT_SYMBOL_GPL(blk_revalidate_disk_zones); - From patchwork Tue Dec 3 09:39:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49E3113B6 for ; Tue, 3 Dec 2019 09:39:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 28C9C206E0 for ; Tue, 3 Dec 2019 09:39:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XnKINMiB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726139AbfLCJjV (ORCPT ); Tue, 3 Dec 2019 04:39:21 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:33038 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfLCJjV (ORCPT ); Tue, 3 Dec 2019 04:39:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=oaJfHAsDAraGOTle2tw5hnd6LtUCl9rHjVLq/Ux2zyw=; b=XnKINMiByOtTRuqcp2dkBy1NBt bSlbrC5i+iU9rKejJKY1dbtSCZrizDxdh6vH2o7W8Xy67pbQL1KYiOmJAJ14NzTXWYBJWRACK/VPw xzWEWQd1E6sehekUFMspMJEwuo8hDBijJNM8Ruzhx2fFTzNQCpl61faFH0NhdVyhhFdv91XEJMYmX 6WTbYADCfNL1RjnSf84RBVP8XqXoMfhFvlz9flvrDu/tLfvemfaj3DyjeTpSF1T4fiJP3zuf71xA3 0P1gLTjG1AlwHEz5lrDHtmEQkzh5wt5r3bsT7AT7DV0jqnrcUjtbHfiCvtlchdJXqrZSsbvmyP31O gf/HcHZg==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eO-00027m-0A; Tue, 03 Dec 2019 09:39:20 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org Subject: [PATCH 4/8] block: simplify blkdev_nr_zones Date: Tue, 3 Dec 2019 10:39:04 +0100 Message-Id: <20191203093908.24612-5-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Simplify the arguments to blkdev_nr_zones by passing a gendisk instead of the block_device and capacity. This also removes the need for __blkdev_nr_zones as all callers are outside the fast path and can deal with the additional branch. Signed-off-by: Christoph Hellwig --- block/blk-zoned.c | 26 ++++++++------------------ block/ioctl.c | 2 +- drivers/md/dm-zoned-target.c | 2 +- include/linux/blkdev.h | 5 ++--- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 618786f8275c..65a9bdc9fe27 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -70,30 +70,20 @@ void __blk_req_zone_write_unlock(struct request *rq) } EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); -static inline unsigned int __blkdev_nr_zones(struct request_queue *q, - sector_t nr_sectors) -{ - sector_t zone_sectors = blk_queue_zone_sectors(q); - - return (nr_sectors + zone_sectors - 1) >> ilog2(zone_sectors); -} - /** * blkdev_nr_zones - Get number of zones - * @bdev: Target block device + * @disk: Target gendisk * - * Description: - * Return the total number of zones of a zoned block device. - * For a regular block device, the number of zones is always 0. + * Return the total number of zones of a zoned block device. For a block + * device without zone capabilities, the number of zones is always 0. */ -unsigned int blkdev_nr_zones(struct block_device *bdev) +unsigned int blkdev_nr_zones(struct gendisk *disk) { - struct request_queue *q = bdev_get_queue(bdev); + sector_t zone_sectors = blk_queue_zone_sectors(disk->queue); - if (!blk_queue_is_zoned(q)) + if (!blk_queue_is_zoned(disk->queue)) return 0; - - return __blkdev_nr_zones(q, get_capacity(bdev->bd_disk)); + return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors); } EXPORT_SYMBOL_GPL(blkdev_nr_zones); @@ -447,7 +437,7 @@ static int blk_update_zone_info(struct gendisk *disk, unsigned int nr_zones, int blk_revalidate_disk_zones(struct gendisk *disk) { struct request_queue *q = disk->queue; - unsigned int nr_zones = __blkdev_nr_zones(q, get_capacity(disk)); + unsigned int nr_zones = blkdev_nr_zones(disk); struct blk_revalidate_zone_args args = { .disk = disk }; int ret = 0; diff --git a/block/ioctl.c b/block/ioctl.c index 7ac8a66c9787..5de98b97af2a 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -512,7 +512,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, case BLKGETZONESZ: return put_uint(arg, bdev_zone_sectors(bdev)); case BLKGETNRZONES: - return put_uint(arg, blkdev_nr_zones(bdev)); + return put_uint(arg, blkdev_nr_zones(bdev->bd_disk)); case HDIO_GETGEO: return blkdev_getgeo(bdev, argp); case BLKRAGET: diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c index 4574e0dedbd6..70a1063161c0 100644 --- a/drivers/md/dm-zoned-target.c +++ b/drivers/md/dm-zoned-target.c @@ -727,7 +727,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) dev->zone_nr_blocks = dmz_sect2blk(dev->zone_nr_sectors); dev->zone_nr_blocks_shift = ilog2(dev->zone_nr_blocks); - dev->nr_zones = blkdev_nr_zones(dev->bdev); + dev->nr_zones = blkdev_nr_zones(dev->bdev->bd_disk); dmz->dev = dev; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 6012e2592628..c5852de402b6 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -357,8 +357,7 @@ typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx, #define BLK_ALL_ZONES ((unsigned int)-1) int blkdev_report_zones(struct block_device *bdev, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); - -extern unsigned int blkdev_nr_zones(struct block_device *bdev); +unsigned int blkdev_nr_zones(struct gendisk *disk); extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, sector_t sectors, sector_t nr_sectors, gfp_t gfp_mask); @@ -371,7 +370,7 @@ extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, #else /* CONFIG_BLK_DEV_ZONED */ -static inline unsigned int blkdev_nr_zones(struct block_device *bdev) +static inline unsigned int blkdev_nr_zones(struct gendisk *disk) { return 0; } From patchwork Tue Dec 3 09:39:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F7F4921 for ; Tue, 3 Dec 2019 09:39:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2F01206E0 for ; Tue, 3 Dec 2019 09:39:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="RFsKgDin" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726179AbfLCJjX (ORCPT ); Tue, 3 Dec 2019 04:39:23 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:33080 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfLCJjX (ORCPT ); Tue, 3 Dec 2019 04:39:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RjkKQQ/mXkTYLtebs6OoUCV7VmMshyQCN5LWNpnBdyI=; b=RFsKgDin7hUcshEKb+ghGRUCZC Pz5vwlemoxjUpKzEQIXQA0pO57kCtwnKl0pKVAsqGYRsAhR03eJ5yrilK4+nVPFReR4kl9G+n4Z+K qHeP5K+5vJ4kd2zAAUI89DFb+fuuVuwDTAK1esqLBIXDsXqANBiPP5kn3lQRveEY7cokm6X1/9c8t nW0Z+EiYzvbF73gHLqAge9omjBHUxDfUGMxTCZO+Mnbj1unquMIn/EtuFSH5HPOMi7f4bqURRcRsy aNIKoYdWX2jQSJcco6whdovezZZ+mGyrIcWkzpGdyJeIVj4Xr7ZOqOM5s+qeunLGE88S9O/xMeD4n UncwQN9g==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eQ-00028j-7h; Tue, 03 Dec 2019 09:39:22 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org Subject: [PATCH 5/8] block: replace seq_zones_bitmap with conv_zones_bitmap Date: Tue, 3 Dec 2019 10:39:05 +0100 Message-Id: <20191203093908.24612-6-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Invert the meaning of seq_zones_bitmap by keeping a bitmap of conventional zones. This allows not having a bitmap for devices that do not have conventional zones. Signed-off-by: Christoph Hellwig Reviewed-by: Javier González --- block/blk-zoned.c | 18 +++++++++--------- include/linux/blkdev.h | 14 ++++++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 65a9bdc9fe27..9c3931051f4f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -332,15 +332,15 @@ static inline unsigned long *blk_alloc_zone_bitmap(int node, void blk_queue_free_zone_bitmaps(struct request_queue *q) { - kfree(q->seq_zones_bitmap); - q->seq_zones_bitmap = NULL; + kfree(q->conv_zones_bitmap); + q->conv_zones_bitmap = NULL; kfree(q->seq_zones_wlock); q->seq_zones_wlock = NULL; } struct blk_revalidate_zone_args { struct gendisk *disk; - unsigned long *seq_zones_bitmap; + unsigned long *conv_zones_bitmap; unsigned long *seq_zones_wlock; sector_t sector; }; @@ -394,8 +394,8 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, return -ENODEV; } - if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) - set_bit(idx, args->seq_zones_bitmap); + if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) + set_bit(idx, args->conv_zones_bitmap); args->sector += zone->len; return 0; @@ -415,8 +415,8 @@ static int blk_update_zone_info(struct gendisk *disk, unsigned int nr_zones, args->seq_zones_wlock = blk_alloc_zone_bitmap(q->node, nr_zones); if (!args->seq_zones_wlock) return -ENOMEM; - args->seq_zones_bitmap = blk_alloc_zone_bitmap(q->node, nr_zones); - if (!args->seq_zones_bitmap) + args->conv_zones_bitmap = blk_alloc_zone_bitmap(q->node, nr_zones); + if (!args->conv_zones_bitmap) return -ENOMEM; ret = disk->fops->report_zones(disk, 0, nr_zones, @@ -465,7 +465,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk) if (ret >= 0) { q->nr_zones = nr_zones; swap(q->seq_zones_wlock, args.seq_zones_wlock); - swap(q->seq_zones_bitmap, args.seq_zones_bitmap); + swap(q->conv_zones_bitmap, args.conv_zones_bitmap); ret = 0; } else { pr_warn("%s: failed to revalidate zones\n", disk->disk_name); @@ -474,7 +474,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk) blk_mq_unfreeze_queue(q); kfree(args.seq_zones_wlock); - kfree(args.seq_zones_bitmap); + kfree(args.conv_zones_bitmap); return ret; } EXPORT_SYMBOL_GPL(blk_revalidate_disk_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c5852de402b6..503c4d4c5884 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -503,9 +503,9 @@ struct request_queue { /* * Zoned block device information for request dispatch control. * nr_zones is the total number of zones of the device. This is always - * 0 for regular block devices. seq_zones_bitmap is a bitmap of nr_zones - * bits which indicates if a zone is conventional (bit clear) or - * sequential (bit set). seq_zones_wlock is a bitmap of nr_zones + * 0 for regular block devices. conv_zones_bitmap is a bitmap of nr_zones + * bits which indicates if a zone is conventional (bit set) or + * sequential (bit clear). seq_zones_wlock is a bitmap of nr_zones * bits which indicates if a zone is write locked, that is, if a write * request targeting the zone was dispatched. All three fields are * initialized by the low level device driver (e.g. scsi/sd.c). @@ -518,7 +518,7 @@ struct request_queue { * blk_mq_unfreeze_queue(). */ unsigned int nr_zones; - unsigned long *seq_zones_bitmap; + unsigned long *conv_zones_bitmap; unsigned long *seq_zones_wlock; #endif /* CONFIG_BLK_DEV_ZONED */ @@ -723,9 +723,11 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, static inline bool blk_queue_zone_is_seq(struct request_queue *q, sector_t sector) { - if (!blk_queue_is_zoned(q) || !q->seq_zones_bitmap) + if (!blk_queue_is_zoned(q)) return false; - return test_bit(blk_queue_zone_no(q, sector), q->seq_zones_bitmap); + if (!q->conv_zones_bitmap) + return true; + return !test_bit(blk_queue_zone_no(q, sector), q->conv_zones_bitmap); } #else /* CONFIG_BLK_DEV_ZONED */ static inline unsigned int blk_queue_nr_zones(struct request_queue *q) From patchwork Tue Dec 3 09:39:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D899159A for ; Tue, 3 Dec 2019 09:39:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D0A6206EC for ; Tue, 3 Dec 2019 09:39:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FNtOf73Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726105AbfLCJjZ (ORCPT ); Tue, 3 Dec 2019 04:39:25 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:33126 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfLCJjZ (ORCPT ); Tue, 3 Dec 2019 04:39:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=AWfSmqDZ2B2JI9YmK3SlaWe9FMOXc288trASlP2+67g=; b=FNtOf73ZSOd5mPCb+n3bStgYWK f7IEJTSqq0mmGsJeNm80ogW9SNHO+HDtP2pLo1EBe+khj4G2t5yCfuhDfFm+do6ZAM6XozPLk1e3Y bHzJShmAhAPSTURePiNpwPfGe4WybgUY5Jf1x76bGorRKa+n/Z7Ytz/v1KSHOQUCZHGARJZ/Pyn8C 30Kx+lkOfSXNcY0zn98xXjUiS03QniMmD8jLOrpXhm4nSYcrzNtHf3mrVIaOv1ZpltmjlmwxPifsx hXFMaMSAr2cd5pxy7Hz1EyXDtZORaZLkWQGe2Piw0yRbLwalT2ZxnPIkb2754wCAePBJ3a1Y+4eYG FOSL/YoQ==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eS-00029P-Co; Tue, 03 Dec 2019 09:39:24 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org Subject: [PATCH 6/8] block: allocate the zone bitmaps lazily Date: Tue, 3 Dec 2019 10:39:06 +0100 Message-Id: <20191203093908.24612-7-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Allocate the conventional zone bitmap and the sequential zone locking bitmap only when we find a zone of the respective type. This avoids wasting memory on the conventional zone bitmap for devices that only have sequential zones, and will also prepare for other future changes. Signed-off-by: Christoph Hellwig Reviewed-by: Javier González --- block/blk-zoned.c | 65 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 9c3931051f4f..0131f9e14bd1 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -342,6 +342,7 @@ struct blk_revalidate_zone_args { struct gendisk *disk; unsigned long *conv_zones_bitmap; unsigned long *seq_zones_wlock; + unsigned int nr_zones; sector_t sector; }; @@ -385,8 +386,22 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, /* Check zone type */ switch (zone->type) { case BLK_ZONE_TYPE_CONVENTIONAL: + if (!args->conv_zones_bitmap) { + args->conv_zones_bitmap = + blk_alloc_zone_bitmap(q->node, args->nr_zones); + if (!args->conv_zones_bitmap) + return -ENOMEM; + } + set_bit(idx, args->conv_zones_bitmap); + break; case BLK_ZONE_TYPE_SEQWRITE_REQ: case BLK_ZONE_TYPE_SEQWRITE_PREF: + if (!args->seq_zones_wlock) { + args->seq_zones_wlock = + blk_alloc_zone_bitmap(q->node, args->nr_zones); + if (!args->seq_zones_wlock) + return -ENOMEM; + } break; default: pr_warn("%s: Invalid zone type 0x%x at sectors %llu\n", @@ -394,37 +409,10 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, return -ENODEV; } - if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) - set_bit(idx, args->conv_zones_bitmap); - args->sector += zone->len; return 0; } -static int blk_update_zone_info(struct gendisk *disk, unsigned int nr_zones, - struct blk_revalidate_zone_args *args) -{ - /* - * Ensure that all memory allocations in this context are done as - * if GFP_NOIO was specified. - */ - unsigned int noio_flag = memalloc_noio_save(); - struct request_queue *q = disk->queue; - int ret; - - args->seq_zones_wlock = blk_alloc_zone_bitmap(q->node, nr_zones); - if (!args->seq_zones_wlock) - return -ENOMEM; - args->conv_zones_bitmap = blk_alloc_zone_bitmap(q->node, nr_zones); - if (!args->conv_zones_bitmap) - return -ENOMEM; - - ret = disk->fops->report_zones(disk, 0, nr_zones, - blk_revalidate_zone_cb, args); - memalloc_noio_restore(noio_flag); - return ret; -} - /** * blk_revalidate_disk_zones - (re)allocate and initialize zone bitmaps * @disk: Target disk @@ -437,8 +425,10 @@ static int blk_update_zone_info(struct gendisk *disk, unsigned int nr_zones, int blk_revalidate_disk_zones(struct gendisk *disk) { struct request_queue *q = disk->queue; - unsigned int nr_zones = blkdev_nr_zones(disk); - struct blk_revalidate_zone_args args = { .disk = disk }; + struct blk_revalidate_zone_args args = { + .disk = disk, + .nr_zones = blkdev_nr_zones(disk), + }; int ret = 0; if (WARN_ON_ONCE(!blk_queue_is_zoned(q))) @@ -449,12 +439,21 @@ int blk_revalidate_disk_zones(struct gendisk *disk) * needs to be updated so that the sysfs exposed value is correct. */ if (!queue_is_mq(q)) { - q->nr_zones = nr_zones; + q->nr_zones = args.nr_zones; return 0; } - if (nr_zones) - ret = blk_update_zone_info(disk, nr_zones, &args); + /* + * Ensure that all memory allocations in this context are done as + * if GFP_NOIO was specified. + */ + if (args.nr_zones) { + unsigned int noio_flag = memalloc_noio_save(); + + ret = disk->fops->report_zones(disk, 0, args.nr_zones, + blk_revalidate_zone_cb, &args); + memalloc_noio_restore(noio_flag); + } /* * Install the new bitmaps, making sure the queue is stopped and @@ -463,7 +462,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk) */ blk_mq_freeze_queue(q); if (ret >= 0) { - q->nr_zones = nr_zones; + q->nr_zones = args.nr_zones; swap(q->seq_zones_wlock, args.seq_zones_wlock); swap(q->conv_zones_bitmap, args.conv_zones_bitmap); ret = 0; From patchwork Tue Dec 3 09:39:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270875 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BE9A13B6 for ; Tue, 3 Dec 2019 09:39:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BA02206EC for ; Tue, 3 Dec 2019 09:39:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BNU0yWD3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725774AbfLCJj1 (ORCPT ); Tue, 3 Dec 2019 04:39:27 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:33144 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbfLCJj1 (ORCPT ); Tue, 3 Dec 2019 04:39:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7tGnw5Ck7d7pDDalWTV8uCh18W44+TXfsiC8Nui+qd4=; b=BNU0yWD32z2oJNY1ITgd8gconO mQn3Bhov1J7RprMMZtzmSBXS1VgtUIeU6G3YtxpGOfoyCUt5bxiyC5T6iMrPxeSTzaEzTtDKbXFY1 dIT/vhyzHjIn2aeEDVVUEOLZ+5lw7Gl9bW4Qnmj3Dt22qN0opTBCsCwNTLIrolvQDtA3QBgIJmFlC jdFyLX9zkoNaCSP1h2iojiAHBWPlVqyz/6kSa67U0gQLK3lvdI2GEd3mkU2uI9NNpf56aceTkhPTm thUc8wMmScjE/28qI8+2uJPWZ/UbLohVnWqEpmrsTHSJnfyZPrzTcAcLpXQmFUTzoWslb//sS2x+g zdGd1bkw==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eU-0002AE-In; Tue, 03 Dec 2019 09:39:26 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org Subject: [PATCH 7/8] block: don't handle bio based drivers in blk_revalidate_disk_zones Date: Tue, 3 Dec 2019 10:39:07 +0100 Message-Id: <20191203093908.24612-8-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org bio based drivers only need to update q->nr_zones. Do that manually instead of overloading blk_revalidate_disk_zones to keep that function simpler for the next round of changes that will rely even more on the request based functionality. Signed-off-by: Christoph Hellwig Reviewed-by: Javier González --- block/blk-zoned.c | 16 +++++----------- drivers/block/null_blk_main.c | 12 +++++++++--- drivers/md/dm-table.c | 12 +++++++----- include/linux/blkdev.h | 5 ----- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 0131f9e14bd1..51d427659ce7 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -419,8 +419,9 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, * * Helper function for low-level device drivers to (re) allocate and initialize * a disk request queue zone bitmaps. This functions should normally be called - * within the disk ->revalidate method. For BIO based queues, no zone bitmap - * is allocated. + * within the disk ->revalidate method for blk-mq based drivers. For BIO based + * drivers only q->nr_zones needs to be updated so that the sysfs exposed value + * is correct. */ int blk_revalidate_disk_zones(struct gendisk *disk) { @@ -433,15 +434,8 @@ int blk_revalidate_disk_zones(struct gendisk *disk) if (WARN_ON_ONCE(!blk_queue_is_zoned(q))) return -EIO; - - /* - * BIO based queues do not use a scheduler so only q->nr_zones - * needs to be updated so that the sysfs exposed value is correct. - */ - if (!queue_is_mq(q)) { - q->nr_zones = args.nr_zones; - return 0; - } + if (WARN_ON_ONCE(!queue_is_mq(q))) + return -EIO; /* * Ensure that all memory allocations in this context are done as diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index dd6026289fbf..068cd0ae6e2c 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1576,11 +1576,17 @@ static int null_gendisk_register(struct nullb *nullb) disk->queue = nullb->q; strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN); +#ifdef CONFIG_BLK_DEV_ZONED if (nullb->dev->zoned) { - ret = blk_revalidate_disk_zones(disk); - if (ret) - return ret; + if (queue_is_mq(nullb->q)) { + ret = blk_revalidate_disk_zones(disk); + if (ret) + return ret; + } else { + nullb->q->nr_zones = blkdev_nr_zones(disk); + } } +#endif add_disk(disk); return 0; diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 2ae0c1913766..0a2cc197f62b 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1954,12 +1954,14 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, /* * For a zoned target, the number of zones should be updated for the * correct value to be exposed in sysfs queue/nr_zones. For a BIO based - * target, this is all that is needed. For a request based target, the - * queue zone bitmaps must also be updated. - * Use blk_revalidate_disk_zones() to handle this. + * target, this is all that is needed. */ - if (blk_queue_is_zoned(q)) - blk_revalidate_disk_zones(t->md->disk); +#ifdef CONFIG_BLK_DEV_ZONED + if (blk_queue_is_zoned(q)) { + WARN_ON_ONCE(queue_is_mq(q)); + q->nr_zones = blkdev_nr_zones(t->md->disk); + } +#endif /* Allow reads to exceed readahead limits */ q->backing_dev_info->io_pages = limits->max_sectors >> (PAGE_SHIFT - 9); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 503c4d4c5884..47eb22a3b7f9 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -375,11 +375,6 @@ static inline unsigned int blkdev_nr_zones(struct gendisk *disk) return 0; } -static inline int blk_revalidate_disk_zones(struct gendisk *disk) -{ - return 0; -} - static inline int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) From patchwork Tue Dec 3 09:39:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11270877 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E06E13B6 for ; Tue, 3 Dec 2019 09:39:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 73128206F0 for ; Tue, 3 Dec 2019 09:39:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AYpVquDd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726182AbfLCJj3 (ORCPT ); Tue, 3 Dec 2019 04:39:29 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:33160 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726115AbfLCJj3 (ORCPT ); Tue, 3 Dec 2019 04:39:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Tld7yeuyFzA1rKT+6njc/e7upZje2HvkNA0/lhtjung=; b=AYpVquDdaR80Q8mXlCflpdMaS/ +XKV25/4CARhT1oI2q5PMmtah1sNmGrL7xjku5mQmVC0vgj5Cm08+5myhLsqdSFYFXzZn1ucoSO1N prgLJ3AmYWt0faO+TR0Q+6MsbAo2MZTJDV/KilKn+P70uvW/xabjHKkCweDSzx9rf2448BvZBbY0W gTL5wjqrE2PoYud20ffOulT0f3w+S33RQpYmTA3Di6ltcA3V4j7jJdpDyS7iUqRAE1/QedbOrf/Mm LllovtJngGgxUMfdUIgOWcLdjcGQDKWhPitywgDkJnGwcgerS/BpvRtD+M58x9iEHp55fbhV97NXP Y0gl/X6g==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ic4eW-0002AR-OH; Tue, 03 Dec 2019 09:39:29 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Hans Holmberg , linux-block@vger.kernel.org Subject: [PATCH 8/8] block: set the zone size in blk_revalidate_disk_zones atomically Date: Tue, 3 Dec 2019 10:39:08 +0100 Message-Id: <20191203093908.24612-9-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203093908.24612-1-hch@lst.de> References: <20191203093908.24612-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The current zone revalidation code has a major problem in that it doesn't update the zone size and q->nr_zones atomically, leading to a short window where an out of bounds access to the zone arrays is possible. To fix this move the setting of the zone size into the crticial sections blk_revalidate_disk_zones so that it gets updated together with the zone bitmaps and q->nr_zones. This also slightly simplifies the caller as it deducts the zone size from the report_zones. This change also allows to check for a power of two zone size in generic code. Reported-by: Hans Holmberg Signed-off-by: Christoph Hellwig --- block/blk-zoned.c | 59 ++++++++++++++++++++--------------- drivers/block/null_blk_main.c | 3 +- drivers/scsi/sd_zbc.c | 2 -- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 51d427659ce7..d00fcfd71dfe 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -343,6 +343,7 @@ struct blk_revalidate_zone_args { unsigned long *conv_zones_bitmap; unsigned long *seq_zones_wlock; unsigned int nr_zones; + sector_t zone_sectors; sector_t sector; }; @@ -355,25 +356,33 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, struct blk_revalidate_zone_args *args = data; struct gendisk *disk = args->disk; struct request_queue *q = disk->queue; - sector_t zone_sectors = blk_queue_zone_sectors(q); sector_t capacity = get_capacity(disk); /* * All zones must have the same size, with the exception on an eventual * smaller last zone. */ - if (zone->start + zone_sectors < capacity && - zone->len != zone_sectors) { - pr_warn("%s: Invalid zoned device with non constant zone size\n", - disk->disk_name); - return false; - } + if (zone->start == 0) { + if (zone->len == 0 || !is_power_of_2(zone->len)) { + pr_warn("%s: Invalid zoned device with non power of two zone size (%llu)\n", + disk->disk_name, zone->len); + return -ENODEV; + } - if (zone->start + zone->len >= capacity && - zone->len > zone_sectors) { - pr_warn("%s: Invalid zoned device with larger last zone size\n", - disk->disk_name); - return -ENODEV; + args->zone_sectors = zone->len; + args->nr_zones = (capacity + zone->len - 1) >> ilog2(zone->len); + } else if (zone->start + args->zone_sectors < capacity) { + if (zone->len != args->zone_sectors) { + pr_warn("%s: Invalid zoned device with non constant zone size\n", + disk->disk_name); + return -ENODEV; + } + } else { + if (zone->len > args->zone_sectors) { + pr_warn("%s: Invalid zoned device with larger last zone size\n", + disk->disk_name); + return -ENODEV; + } } /* Check for holes in the zone report */ @@ -428,9 +437,9 @@ int blk_revalidate_disk_zones(struct gendisk *disk) struct request_queue *q = disk->queue; struct blk_revalidate_zone_args args = { .disk = disk, - .nr_zones = blkdev_nr_zones(disk), }; - int ret = 0; + unsigned int noio_flag; + int ret; if (WARN_ON_ONCE(!blk_queue_is_zoned(q))) return -EIO; @@ -438,24 +447,22 @@ int blk_revalidate_disk_zones(struct gendisk *disk) return -EIO; /* - * Ensure that all memory allocations in this context are done as - * if GFP_NOIO was specified. + * Ensure that all memory allocations in this context are done as if + * GFP_NOIO was specified. */ - if (args.nr_zones) { - unsigned int noio_flag = memalloc_noio_save(); - - ret = disk->fops->report_zones(disk, 0, args.nr_zones, - blk_revalidate_zone_cb, &args); - memalloc_noio_restore(noio_flag); - } + noio_flag = memalloc_noio_save(); + ret = disk->fops->report_zones(disk, 0, UINT_MAX, + blk_revalidate_zone_cb, &args); + memalloc_noio_restore(noio_flag); /* - * Install the new bitmaps, making sure the queue is stopped and - * all I/Os are completed (i.e. a scheduler is not referencing the - * bitmaps). + * Install the new bitmaps and update nr_zones only once the queue is + * stopped and all I/Os are completed (i.e. a scheduler is not + * referencing the bitmaps). */ blk_mq_freeze_queue(q); if (ret >= 0) { + blk_queue_chunk_sectors(q, args.zone_sectors); q->nr_zones = args.nr_zones; swap(q->seq_zones_wlock, args.seq_zones_wlock); swap(q->conv_zones_bitmap, args.conv_zones_bitmap); diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 068cd0ae6e2c..997b7dc095b9 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1583,6 +1583,8 @@ static int null_gendisk_register(struct nullb *nullb) if (ret) return ret; } else { + blk_queue_chunk_sectors(nullb->q, + nullb->dev->zone_size_sects); nullb->q->nr_zones = blkdev_nr_zones(disk); } } @@ -1746,7 +1748,6 @@ static int null_add_dev(struct nullb_device *dev) if (rv) goto out_cleanup_blk_queue; - blk_queue_chunk_sectors(nullb->q, dev->zone_size_sects); nullb->q->limits.zoned = BLK_ZONED_HM; blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, nullb->q); blk_queue_required_elevator_features(nullb->q, diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 0e5ede48f045..27d72c1d4654 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -412,8 +412,6 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) goto err; /* The drive satisfies the kernel restrictions: set it up */ - blk_queue_chunk_sectors(sdkp->disk->queue, - logical_to_sectors(sdkp->device, zone_blocks)); blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, sdkp->disk->queue); blk_queue_required_elevator_features(sdkp->disk->queue, ELEVATOR_F_ZBD_SEQ_WRITE);