Skip to contentSkip to conversation

pass queue_limits to blk_alloc_disk for simple drivers

PATCH In review Christoph Hellwig 7 participants 20 messages Feb 15, 2024 – Feb 20, 2024

Subsystems (17)
PowerPC Block layer s390 MD RAID +13 more subsystems
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

Hi Jens,

this series converts all "simple" bio based drivers that don't have complex internal layering or other oddities to pass the queue_limits to blk_mq_alloc_disk. None of these drivers updates the limits at runtime.

Diffstat:

 arch/m68k/emu/nfblock.c             |   10 ++++---
 arch/xtensa/platforms/iss/simdisk.c |    8 +++--
 block/genhd.c                       |   11 ++++---
 drivers/block/brd.c                 |   26 +++++++++---------
 drivers/block/drbd/drbd_main.c      |    6 ++--
 drivers/block/n64cart.c             |   12 +++++---
 drivers/block/null_blk/main.c       |    7 ++--
 drivers/block/pktcdvd.c             |    7 ++--
 drivers/block/ps3vram.c             |    6 ++--
 drivers/block/zram/zram_drv.c       |   51 +++++++++++++++++-------------------
 drivers/md/bcache/super.c           |   48 +++++++++++++++++----------------
 drivers/md/dm.c                     |    4 +-
 drivers/md/md.c                     |    7 ++--
 drivers/nvdimm/btt.c                |   14 +++++----
 drivers/nvdimm/pmem.c               |   14 +++++----
 drivers/nvme/host/multipath.c       |    6 ++--
 drivers/s390/block/dcssblk.c        |   10 ++++---
 include/linux/blkdev.h              |   10 ++++---
 18 files changed, 143 insertions(+), 114 deletions(-)
author maintainer
#1 lore raw

PATCH 1/9 block: pass a queue_limits argument to blk_alloc_disk

Pass a queue_limits to blk_alloc_disk and apply it if non-NULL. This will allow allocating queues with valid queue limits instead of setting the values one at a time later.

Also change blk_alloc_disk to return an ERR_PTR instead of just NULL which can't distinguish errors.

---
 arch/m68k/emu/nfblock.c             |  6 ++++--
 arch/xtensa/platforms/iss/simdisk.c |  8 +++++---
 block/genhd.c                       | 11 ++++++-----
 drivers/block/brd.c                 |  7 ++++---
 drivers/block/drbd/drbd_main.c      |  6 ++++--
 drivers/block/n64cart.c             |  6 ++++--
 drivers/block/null_blk/main.c       |  7 ++++---
 drivers/block/pktcdvd.c             |  7 ++++---
 drivers/block/ps3vram.c             |  6 +++---
 drivers/block/zram/zram_drv.c       |  6 +++---
 drivers/md/bcache/super.c           |  4 ++--
 drivers/md/dm.c                     |  4 ++--
 drivers/md/md.c                     |  7 ++++---
 drivers/nvdimm/btt.c                |  8 ++++----
 drivers/nvdimm/pmem.c               |  6 +++---
 drivers/nvme/host/multipath.c       |  6 +++---
 drivers/s390/block/dcssblk.c        |  6 +++---
 include/linux/blkdev.h              | 10 +++++++---
 18 files changed, 69 insertions(+), 52 deletions(-)
arch/m68k/emu/nfblock.c +4 -2
index a708fbd5a844f8..539ff56b6968d0 100644
@@ -117,9 +117,11 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
 	dev->bsize = bsize;
 	dev->bshift = ffs(bsize) - 10;
 
-	dev->disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!dev->disk)
+	dev->disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(dev->disk)) {
+		err = PTR_ERR(dev->disk);
 		goto free_dev;
+	}
 
 	dev->disk->major = major_num;
 	dev->disk->first_minor = dev_id * 16;
arch/xtensa/platforms/iss/simdisk.c +5 -3
index 178cf96ca10acb..defc67909a9c74 100644
@@ -264,16 +264,18 @@ static int __init simdisk_setup(struct simdisk *dev, int which,
 		struct proc_dir_entry *procdir)
 {
 	char tmp[2] = { '0' + which, 0 };
-	int err = -ENOMEM;
+	int err;
 
 	dev->fd = -1;
 	dev->filename = NULL;
 	spin_lock_init(&dev->lock);
 	dev->users = 0;
 
-	dev->gd = blk_alloc_disk(NUMA_NO_NODE);
-	if (!dev->gd)
+	dev->gd = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(dev->gd)) {
+		err = PTR_ERR(dev->gd);
 		goto out;
+	}
 	dev->gd->major = simdisk_major;
 	dev->gd->first_minor = which;
 	dev->gd->minors = SIMDISK_MINORS;
block/genhd.c +6 -5
index 7a8fd57c51f73c..84c822d989daca 100644
@@ -1391,20 +1391,21 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
 	return NULL;
 }
 
-struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass)
+struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node,
+		struct lock_class_key *lkclass)
 {
-	struct queue_limits lim = { };
+	struct queue_limits default_lim = { };
 	struct request_queue *q;
 	struct gendisk *disk;
 
-	q = blk_alloc_queue(&lim, node);
+	q = blk_alloc_queue(lim ? lim : &default_lim, node);
 	if (IS_ERR(q))
-		return NULL;
+		return ERR_CAST(q);
 
 	disk = __alloc_disk_node(q, node, lkclass);
 	if (!disk) {
 		blk_put_queue(q);
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 	set_bit(GD_OWNS_QUEUE, &disk->state);
 	return disk;
drivers/block/brd.c +4 -3
index 970bd6ff38c491..689a3c0c31f8b4 100644
@@ -335,10 +335,11 @@ static int brd_alloc(int i)
 		debugfs_create_u64(buf, 0444, brd_debugfs_dir,
 				&brd->brd_nr_pages);
 
-	disk = brd->brd_disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!disk)
+	disk = brd->brd_disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(disk)) {
+		err = PTR_ERR(disk);
 		goto out_free_dev;
-
+	}
 	disk->major		= RAMDISK_MAJOR;
 	disk->first_minor	= i * max_part;
 	disk->minors		= max_part;
drivers/block/drbd/drbd_main.c +4 -2
index 6bc86106c7b2ab..cea1e537fd56c1 100644
@@ -2708,9 +2708,11 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
 
 	drbd_init_set_defaults(device);
 
-	disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!disk)
+	disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(disk)) {
+		err = PTR_ERR(disk);
 		goto out_no_disk;
+	}
 
 	device->vdisk = disk;
 	device->rq_queue = disk->queue;
drivers/block/n64cart.c +4 -2
index d914156db2d8b2..c64d7ee7a44db5 100644
@@ -131,9 +131,11 @@ static int __init n64cart_probe(struct platform_device *pdev)
 	if (IS_ERR(reg_base))
 		return PTR_ERR(reg_base);
 
-	disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!disk)
+	disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(disk)) {
+		err = PTR_ERR(disk);
 		goto out;
+	}
 
 	disk->first_minor = 0;
 	disk->flags = GENHD_FL_NO_PART;
drivers/block/null_blk/main.c +4 -3
index eeb895ec6f34ae..baf2b228d00801 100644
@@ -2154,10 +2154,11 @@ static int null_add_dev(struct nullb_device *dev)
 		}
 		nullb->q = nullb->disk->queue;
 	} else if (dev->queue_mode == NULL_Q_BIO) {
-		rv = -ENOMEM;
-		nullb->disk = blk_alloc_disk(nullb->dev->home_node);
-		if (!nullb->disk)
+		nullb->disk = blk_alloc_disk(NULL, nullb->dev->home_node);
+		if (IS_ERR(nullb->disk)) {
+			rv = PTR_ERR(nullb->disk);
 			goto out_cleanup_queues;
+		}
 
 		nullb->q = nullb->disk->queue;
 		rv = init_driver_queues(nullb);
drivers/block/pktcdvd.c +4 -3
index d56d972aadb36f..abb82926b1c935 100644
@@ -2673,10 +2673,11 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
 	pd->write_congestion_on  = write_congestion_on;
 	pd->write_congestion_off = write_congestion_off;
 
-	ret = -ENOMEM;
-	disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!disk)
+	disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(disk)) {
+		ret = PTR_ERR(disk);
 		goto out_mem;
+	}
 	pd->disk = disk;
 	disk->major = pktdev_major;
 	disk->first_minor = idx;
drivers/block/ps3vram.c +3 -3
index 38d42af01b2535..bdcf083b45e234 100644
@@ -730,10 +730,10 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
 
 	ps3vram_proc_init(dev);
 
-	gendisk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!gendisk) {
+	gendisk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(gendisk)) {
 		dev_err(&dev->core, "blk_alloc_disk failed\n");
-		error = -ENOMEM;
+		error = PTR_ERR(gendisk);
 		goto out_cache_cleanup;
 	}
 
drivers/block/zram/zram_drv.c +3 -3
index 6772e0c654fa7f..84982221fc6620 100644
@@ -2195,11 +2195,11 @@ static int zram_add(void)
 #endif
 
 	/* gendisk structure */
-	zram->disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!zram->disk) {
+	zram->disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(zram->disk)) {
 		pr_err("Error allocating disk structure for device %d\n",
 			device_id);
-		ret = -ENOMEM;
+		ret = PTR_ERR(zram->disk);
 		goto out_free_idr;
 	}
 
drivers/md/bcache/super.c +2 -2
index dc3f50f6971417..9955ecff383966 100644
@@ -935,8 +935,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
 			BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
 		goto out_ida_remove;
 
-	d->disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!d->disk)
+	d->disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(d->disk))
 		goto out_bioset_exit;
 
 	set_capacity(d->disk, sectors);
drivers/md/dm.c +2 -2
index 8dcabf84d866e6..b5e6a10b9cfde3 100644
@@ -2098,8 +2098,8 @@ static struct mapped_device *alloc_dev(int minor)
 	 * established. If request-based table is loaded: blk-mq will
 	 * override accordingly.
 	 */
-	md->disk = blk_alloc_disk(md->numa_node_id);
-	if (!md->disk)
+	md->disk = blk_alloc_disk(NULL, md->numa_node_id);
+	if (IS_ERR(md->disk))
 		goto bad;
 	md->queue = md->disk->queue;
 
drivers/md/md.c +4 -3
index 2266358d807466..e255f426bf9ced 100644
@@ -5770,10 +5770,11 @@ struct mddev *md_alloc(dev_t dev, char *name)
 		 */
 		mddev->hold_active = UNTIL_STOP;
 
-	error = -ENOMEM;
-	disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!disk)
+	disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(disk)) {
+		error = PTR_ERR(disk);
 		goto out_free_mddev;
+	}
 
 	disk->major = MAJOR(mddev->unit);
 	disk->first_minor = unit << shift;
drivers/nvdimm/btt.c +4 -4
index bb3726b622ad9f..9a0eae01d5986e 100644
@@ -1496,11 +1496,11 @@ static int btt_blk_init(struct btt *btt)
 {
 	struct nd_btt *nd_btt = btt->nd_btt;
 	struct nd_namespace_common *ndns = nd_btt->ndns;
-	int rc = -ENOMEM;
+	int rc;
 
-	btt->btt_disk = blk_alloc_disk(NUMA_NO_NODE);
-	if (!btt->btt_disk)
-		return -ENOMEM;
+	btt->btt_disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(btt->btt_disk))
+		return PTR_ERR(btt->btt_disk);
 
 	nvdimm_namespace_disk_name(ndns, btt->btt_disk->disk_name);
 	btt->btt_disk->first_minor = 0;
drivers/nvdimm/pmem.c +3 -3
index 4e8fdcb3f1c827..3a5df8d467c507 100644
@@ -497,9 +497,9 @@ static int pmem_attach_disk(struct device *dev,
 		return -EBUSY;
 	}
 
-	disk = blk_alloc_disk(nid);
-	if (!disk)
-		return -ENOMEM;
+	disk = blk_alloc_disk(NULL, nid);
+	if (IS_ERR(disk))
+		return PTR_ERR(disk);
 	q = disk->queue;
 
 	pmem->disk = disk;
drivers/nvme/host/multipath.c +3 -3
index 74de1e64aeead7..dc5d0d0a82d0e2 100644
@@ -532,9 +532,9 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
 	    !nvme_is_unique_nsid(ctrl, head) || !multipath)
 		return 0;
 
-	head->disk = blk_alloc_disk(ctrl->numa_node);
-	if (!head->disk)
-		return -ENOMEM;
+	head->disk = blk_alloc_disk(NULL, ctrl->numa_node);
+	if (IS_ERR(head->disk))
+		return PTR_ERR(head->disk);
 	head->disk->fops = &nvme_ns_head_ops;
 	head->disk->private_data = head;
 	sprintf(head->disk->disk_name, "nvme%dn%d",
drivers/s390/block/dcssblk.c +3 -3
index 4b7ecd4fd4319c..0903b432ea9740 100644
@@ -629,9 +629,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
 	dev_info->dev.release = dcssblk_release_segment;
 	dev_info->dev.groups = dcssblk_dev_attr_groups;
 	INIT_LIST_HEAD(&dev_info->lh);
-	dev_info->gd = blk_alloc_disk(NUMA_NO_NODE);
-	if (dev_info->gd == NULL) {
-		rc = -ENOMEM;
+	dev_info->gd = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (IS_ERR(dev_info->gd)) {
+		rc = PTR_ERR(dev_info->gd);
 		goto seg_list_del;
 	}
 	dev_info->gd->major = dcssblk_major;
include/linux/blkdev.h +7 -3
index 45746ba73670e8..a14ea934413850 100644
@@ -766,22 +766,26 @@ static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
 
 void put_disk(struct gendisk *disk);
-struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass);
+struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node,
+		struct lock_class_key *lkclass);
 
 /**
  * blk_alloc_disk - allocate a gendisk structure
+ * @lim: queue limits to be used for this disk.
  * @node_id: numa node to allocate on
  *
  * Allocate and pre-initialize a gendisk structure for use with BIO based
  * drivers.
  *
+ * Returns an ERR_PTR on error, else the allocated disk.
+ *
  * Context: can sleep
  */
-#define blk_alloc_disk(node_id)						\
+#define blk_alloc_disk(lim, node_id)					\
 ({									\
 	static struct lock_class_key __key;				\
 									\
-	__blk_alloc_disk(node_id, &__key);				\
+	__blk_alloc_disk(lim, node_id, &__key);				\
 })
 
 int __register_blkdev(unsigned int major, const char *name,
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH 2/9 nfblock: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 arch/m68k/emu/nfblock.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/m68k/emu/nfblock.c +4 -2
index 539ff56b6968d0..642fb80c5c4e31 100644
@@ -96,6 +96,9 @@ static const struct block_device_operations nfhd_ops = {
 
 static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
 {
+	struct queue_limits lim = {
+		.logical_block_size	= bsize,
+	};
 	struct nfhd_device *dev;
 	int dev_id = id - NFHD_DEV_OFFSET;
 	int err = -ENOMEM;
@@ -117,7 +120,7 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
 	dev->bsize = bsize;
 	dev->bshift = ffs(bsize) - 10;
 
-	dev->disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	dev->disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(dev->disk)) {
 		err = PTR_ERR(dev->disk);
 		goto free_dev;
@@ -130,7 +133,6 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
 	dev->disk->private_data = dev;
 	sprintf(dev->disk->disk_name, "nfhd%u", dev_id);
 	set_capacity(dev->disk, (sector_t)blocks * (bsize / 512));
-	blk_queue_logical_block_size(dev->disk->queue, bsize);
 	err = add_disk(dev->disk);
 	if (err)
 		goto out_cleanup_disk;
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH 3/9 brd: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 drivers/block/brd.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/block/brd.c +11 -10
index 689a3c0c31f8b4..e322cef6596bfa 100644
@@ -318,6 +318,16 @@ static int brd_alloc(int i)
 	struct gendisk *disk;
 	char buf[DISK_NAME_LEN];
 	int err = -ENOMEM;
+	struct queue_limits lim = {
+		/*
+		 * This is so fdisk will align partitions on 4k, because of
+		 * direct_access API needing 4k alignment, returning a PFN
+		 * (This is only a problem on very small devices <= 4M,
+		 *  otherwise fdisk will align on 1M. Regardless this call
+		 *  is harmless)
+		 */
+		.physical_block_size	= PAGE_SIZE,
+	};
 
 	list_for_each_entry(brd, &brd_devices, brd_list)
 		if (brd->brd_number == i)
@@ -335,7 +345,7 @@ static int brd_alloc(int i)
 		debugfs_create_u64(buf, 0444, brd_debugfs_dir,
 				&brd->brd_nr_pages);
 
-	disk = brd->brd_disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	disk = brd->brd_disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(disk)) {
 		err = PTR_ERR(disk);
 		goto out_free_dev;
@@ -348,15 +358,6 @@ static int brd_alloc(int i)
 	strscpy(disk->disk_name, buf, DISK_NAME_LEN);
 	set_capacity(disk, rd_size * 2);
 	
-	/*
-	 * This is so fdisk will align partitions on 4k, because of
-	 * direct_access API needing 4k alignment, returning a PFN
-	 * (This is only a problem on very small devices <= 4M,
-	 *  otherwise fdisk will align on 1M. Regardless this call
-	 *  is harmless)
-	 */
-	blk_queue_physical_block_size(disk->queue, PAGE_SIZE);
-
 	/* Tell the block layer that this is not a rotational device */
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
 	blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, disk->queue);
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH 4/9 n64cart: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 drivers/block/n64cart.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/block/n64cart.c +5 -3
index c64d7ee7a44db5..27b2187e7a6d55 100644
@@ -114,6 +114,10 @@ static const struct block_device_operations n64cart_fops = {
  */
 static int __init n64cart_probe(struct platform_device *pdev)
 {
+	struct queue_limits lim = {
+		.physical_block_size	= 4096,
+		.logical_block_size	= 4096,
+	};
 	struct gendisk *disk;
 	int err = -ENOMEM;
 
@@ -131,7 +135,7 @@ static int __init n64cart_probe(struct platform_device *pdev)
 	if (IS_ERR(reg_base))
 		return PTR_ERR(reg_base);
 
-	disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(disk)) {
 		err = PTR_ERR(disk);
 		goto out;
@@ -147,8 +151,6 @@ static int __init n64cart_probe(struct platform_device *pdev)
 	set_disk_ro(disk, 1);
 
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
-	blk_queue_physical_block_size(disk->queue, 4096);
-	blk_queue_logical_block_size(disk->queue, 4096);
 
 	err = add_disk(disk);
 	if (err)
Signature · 1 line
2.39.2
author maintainer
#7 lore raw

PATCH 5/9 zram: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 drivers/block/zram/zram_drv.c | 47 +++++++++++++++++------------------
 1 file changed, 23 insertions(+), 24 deletions(-)
drivers/block/zram/zram_drv.c +23 -24
index 84982221fc6620..8ee0f7bef19053 100644
@@ -2177,6 +2177,28 @@ ATTRIBUTE_GROUPS(zram_disk);
  */
 static int zram_add(void)
 {
+	struct queue_limits lim = {
+		.logical_block_size		= ZRAM_LOGICAL_BLOCK_SIZE,
+		/*
+		 * To ensure that we always get PAGE_SIZE aligned and
+		 * n*PAGE_SIZED sized I/O requests.
+		 */
+		.physical_block_size		= PAGE_SIZE,
+		.io_min				= PAGE_SIZE,
+		.io_opt				= PAGE_SIZE,
+		.max_hw_discard_sectors		= UINT_MAX,
+		/*
+		 * zram_bio_discard() will clear all logical blocks if logical
+		 * block size is identical with physical block size(PAGE_SIZE).
+		 * But if it is different, we will skip discarding some parts of
+		 * logical blocks in the part of the request range which isn't
+		 * aligned to physical block size.  So we can't ensure that all
+		 * discarded logical blocks are zeroed.
+		 */
+#if ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE
+		.max_write_zeroes_sectors	= UINT_MAX,
+#endif
+	};
 	struct zram *zram;
 	int ret, device_id;
 
@@ -2195,7 +2217,7 @@ static int zram_add(void)
 #endif
 
 	/* gendisk structure */
-	zram->disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	zram->disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(zram->disk)) {
 		pr_err("Error allocating disk structure for device %d\n",
 			device_id);
@@ -2216,29 +2238,6 @@ static int zram_add(void)
 	/* zram devices sort of resembles non-rotational disks */
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, zram->disk->queue);
 	blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, zram->disk->queue);
-
-	/*
-	 * To ensure that we always get PAGE_SIZE aligned
-	 * and n*PAGE_SIZED sized I/O requests.
-	 */
-	blk_queue_physical_block_size(zram->disk->queue, PAGE_SIZE);
-	blk_queue_logical_block_size(zram->disk->queue,
-					ZRAM_LOGICAL_BLOCK_SIZE);
-	blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
-	blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);
-	blk_queue_max_discard_sectors(zram->disk->queue, UINT_MAX);
-
-	/*
-	 * zram_bio_discard() will clear all logical blocks if logical block
-	 * size is identical with physical block size(PAGE_SIZE). But if it is
-	 * different, we will skip discarding some parts of logical blocks in
-	 * the part of the request range which isn't aligned to physical block
-	 * size.  So we can't ensure that all discarded logical blocks are
-	 * zeroed.
-	 */
-	if (ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE)
-		blk_queue_max_write_zeroes_sectors(zram->disk->queue, UINT_MAX);
-
 	blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, zram->disk->queue);
 	ret = device_add_disk(NULL, zram->disk, zram_disk_groups);
 	if (ret)
Signature · 1 line
2.39.2
author maintainer
#9 lore raw

PATCH 6/9 bcache: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 drivers/md/bcache/super.c | 46 ++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 22 deletions(-)
drivers/md/bcache/super.c +24 -22
index 9955ecff383966..d06a9649d30269 100644
@@ -900,6 +900,16 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
 	struct request_queue *q;
 	const size_t max_stripes = min_t(size_t, INT_MAX,
 					 SIZE_MAX / sizeof(atomic_t));
+	struct queue_limits lim = {
+		.max_hw_sectors		= UINT_MAX,
+		.max_sectors		= UINT_MAX,
+		.max_segment_size	= UINT_MAX,
+		.max_segments		= BIO_MAX_VECS,
+		.max_hw_discard_sectors	= UINT_MAX,
+		.io_min			= block_size,
+		.logical_block_size	= block_size,
+		.physical_block_size	= block_size,
+	};
 	uint64_t n;
 	int idx;
 
@@ -935,7 +945,20 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
 			BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
 		goto out_ida_remove;
 
-	d->disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	if (lim.logical_block_size > PAGE_SIZE && cached_bdev) {
+		/*
+		 * This should only happen with BCACHE_SB_VERSION_BDEV.
+		 * Block/page size is checked for BCACHE_SB_VERSION_CDEV.
+		 */
+		pr_info("bcache%i: sb/logical block size (%u) greater than page size (%lu) falling back to device logical block size (%u)\n",
+			idx, lim.logical_block_size,
+			PAGE_SIZE, bdev_logical_block_size(cached_bdev));
+
+		/* This also adjusts physical block size/min io size if needed */
+		lim.logical_block_size = bdev_logical_block_size(cached_bdev);
+	}
+
+	d->disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(d->disk))
 		goto out_bioset_exit;
 
@@ -949,27 +972,6 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
 	d->disk->private_data	= d;
 
 	q = d->disk->queue;
-	q->limits.max_hw_sectors	= UINT_MAX;
-	q->limits.max_sectors		= UINT_MAX;
-	q->limits.max_segment_size	= UINT_MAX;
-	q->limits.max_segments		= BIO_MAX_VECS;
-	blk_queue_max_discard_sectors(q, UINT_MAX);
-	q->limits.io_min		= block_size;
-	q->limits.logical_block_size	= block_size;
-	q->limits.physical_block_size	= block_size;
-
-	if (q->limits.logical_block_size > PAGE_SIZE && cached_bdev) {
-		/*
-		 * This should only happen with BCACHE_SB_VERSION_BDEV.
-		 * Block/page size is checked for BCACHE_SB_VERSION_CDEV.
-		 */
-		pr_info("%s: sb/logical block size (%u) greater than page size (%lu) falling back to device logical block size (%u)\n",
-			d->disk->disk_name, q->limits.logical_block_size,
-			PAGE_SIZE, bdev_logical_block_size(cached_bdev));
-
-		/* This also adjusts physical block size/min io size if needed */
-		blk_queue_logical_block_size(q, bdev_logical_block_size(cached_bdev));
-	}
 
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, d->disk->queue);
 
Signature · 1 line
2.39.2
author maintainer
#11 lore raw

PATCH 7/9 btt: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 drivers/nvdimm/btt.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/nvdimm/btt.c +5 -3
index 9a0eae01d5986e..4d0c527e857678 100644
@@ -1496,9 +1496,13 @@ static int btt_blk_init(struct btt *btt)
 {
 	struct nd_btt *nd_btt = btt->nd_btt;
 	struct nd_namespace_common *ndns = nd_btt->ndns;
+	struct queue_limits lim = {
+		.logical_block_size	= btt->sector_size,
+		.max_hw_sectors		= UINT_MAX,
+	};
 	int rc;
 
-	btt->btt_disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	btt->btt_disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(btt->btt_disk))
 		return PTR_ERR(btt->btt_disk);
 
@@ -1507,8 +1511,6 @@ static int btt_blk_init(struct btt *btt)
 	btt->btt_disk->fops = &btt_fops;
 	btt->btt_disk->private_data = btt;
 
-	blk_queue_logical_block_size(btt->btt_disk->queue, btt->sector_size);
-	blk_queue_max_hw_sectors(btt->btt_disk->queue, UINT_MAX);
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, btt->btt_disk->queue);
 	blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, btt->btt_disk->queue);
 
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 7/9
#12 lore raw

Re: [PATCH 7/9] btt: pass queue_limits to blk_mq_alloc_disk

Quoted 4 lines · Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

Quoted 32 lines
---
 drivers/nvdimm/btt.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/nvdimm/btt.c +5 -3
index 9a0eae01d5986e..4d0c527e857678 100644
@@ -1496,9 +1496,13 @@ static int btt_blk_init(struct btt *btt)
 {
 	struct nd_btt *nd_btt = btt->nd_btt;
 	struct nd_namespace_common *ndns = nd_btt->ndns;
+	struct queue_limits lim = {
+		.logical_block_size	= btt->sector_size,
+		.max_hw_sectors		= UINT_MAX,
+	};
 	int rc;
 
-	btt->btt_disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	btt->btt_disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(btt->btt_disk))
 		return PTR_ERR(btt->btt_disk);
 
@@ -1507,8 +1511,6 @@ static int btt_blk_init(struct btt *btt)
 	btt->btt_disk->fops = &btt_fops;
 	btt->btt_disk->private_data = btt;
 
-	blk_queue_logical_block_size(btt->btt_disk->queue, btt->sector_size);
-	blk_queue_max_hw_sectors(btt->btt_disk->queue, UINT_MAX);
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, btt->btt_disk->queue);
 	blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, btt->btt_disk->queue);
 
author maintainer
#13 lore raw

PATCH 8/9 pmem: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 drivers/nvdimm/pmem.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/nvdimm/pmem.c +6 -4
index 3a5df8d467c507..8dcc10b6db5b12 100644
@@ -451,6 +451,11 @@ static int pmem_attach_disk(struct device *dev,
 {
 	struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
 	struct nd_region *nd_region = to_nd_region(dev->parent);
+	struct queue_limits lim = {
+		.logical_block_size	= pmem_sector_size(ndns),
+		.physical_block_size	= PAGE_SIZE,
+		.max_hw_sectors		= UINT_MAX,
+	};
 	int nid = dev_to_node(dev), fua;
 	struct resource *res = &nsio->res;
 	struct range bb_range;
@@ -497,7 +502,7 @@ static int pmem_attach_disk(struct device *dev,
 		return -EBUSY;
 	}
 
-	disk = blk_alloc_disk(NULL, nid);
+	disk = blk_alloc_disk(&lim, nid);
 	if (IS_ERR(disk))
 		return PTR_ERR(disk);
 	q = disk->queue;
@@ -539,9 +544,6 @@ static int pmem_attach_disk(struct device *dev,
 	pmem->virt_addr = addr;
 
 	blk_queue_write_cache(q, true, fua);
-	blk_queue_physical_block_size(q, PAGE_SIZE);
-	blk_queue_logical_block_size(q, pmem_sector_size(ndns));
-	blk_queue_max_hw_sectors(q, UINT_MAX);
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
 	blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, q);
 	if (pmem->pfn_flags & PFN_MAP)
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 8/9
#14 lore raw

Re: [PATCH 8/9] pmem: pass queue_limits to blk_mq_alloc_disk

Quoted 4 lines · Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

Quoted 39 lines
---
 drivers/nvdimm/pmem.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/nvdimm/pmem.c +6 -4
index 3a5df8d467c507..8dcc10b6db5b12 100644
@@ -451,6 +451,11 @@ static int pmem_attach_disk(struct device *dev,
 {
 	struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
 	struct nd_region *nd_region = to_nd_region(dev->parent);
+	struct queue_limits lim = {
+		.logical_block_size	= pmem_sector_size(ndns),
+		.physical_block_size	= PAGE_SIZE,
+		.max_hw_sectors		= UINT_MAX,
+	};
 	int nid = dev_to_node(dev), fua;
 	struct resource *res = &nsio->res;
 	struct range bb_range;
@@ -497,7 +502,7 @@ static int pmem_attach_disk(struct device *dev,
 		return -EBUSY;
 	}
 
-	disk = blk_alloc_disk(NULL, nid);
+	disk = blk_alloc_disk(&lim, nid);
 	if (IS_ERR(disk))
 		return PTR_ERR(disk);
 	q = disk->queue;
@@ -539,9 +544,6 @@ static int pmem_attach_disk(struct device *dev,
 	pmem->virt_addr = addr;
 
 	blk_queue_write_cache(q, true, fua);
-	blk_queue_physical_block_size(q, PAGE_SIZE);
-	blk_queue_logical_block_size(q, pmem_sector_size(ndns));
-	blk_queue_max_hw_sectors(q, UINT_MAX);
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
 	blk_queue_flag_set(QUEUE_FLAG_SYNCHRONOUS, q);
 	if (pmem->pfn_flags & PFN_MAP)
author maintainer
#16 lore raw

PATCH 9/9 dcssblk: pass queue_limits to blk_mq_alloc_disk

In reply to Christoph Hellwig

Pass the queue limits directly to blk_alloc_disk instead of setting them one at a time.

---
 drivers/s390/block/dcssblk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/s390/block/dcssblk.c +4 -2
index 0903b432ea9740..9c8f529b827cb3 100644
@@ -546,6 +546,9 @@ static const struct attribute_group *dcssblk_dev_attr_groups[] = {
 static ssize_t
 dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
+	struct queue_limits lim = {
+		.logical_block_size	= 4096,
+	};
 	int rc, i, j, num_of_segments;
 	struct dcssblk_dev_info *dev_info;
 	struct segment_info *seg_info, *temp;
@@ -629,7 +632,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
 	dev_info->dev.release = dcssblk_release_segment;
 	dev_info->dev.groups = dcssblk_dev_attr_groups;
 	INIT_LIST_HEAD(&dev_info->lh);
-	dev_info->gd = blk_alloc_disk(NULL, NUMA_NO_NODE);
+	dev_info->gd = blk_alloc_disk(&lim, NUMA_NO_NODE);
 	if (IS_ERR(dev_info->gd)) {
 		rc = PTR_ERR(dev_info->gd);
 		goto seg_list_del;
@@ -639,7 +642,6 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
 	dev_info->gd->fops = &dcssblk_devops;
 	dev_info->gd->private_data = dev_info;
 	dev_info->gd->flags |= GENHD_FL_NO_PART;
-	blk_queue_logical_block_size(dev_info->gd->queue, 4096);
 	blk_queue_flag_set(QUEUE_FLAG_DAX, dev_info->gd->queue);
 
 	seg_byte_size = (dev_info->end - dev_info->start + 1);
Signature · 1 line
2.39.2
Reviewed-by
#17 lore raw
In reply to Christoph Hellwig
Quoted 19 lines · Christoph Hellwig

Hi Jens,

this series converts all "simple" bio based drivers that don't have complex internal layering or other oddities to pass the queue_limits to blk_mq_alloc_disk. None of these drivers updates the limits at runtime.

Diffstat:

 arch/m68k/emu/nfblock.c             |   10 ++++---
 arch/xtensa/platforms/iss/simdisk.c |    8 +++--
 block/genhd.c                       |   11 ++++---
 drivers/block/brd.c                 |   26 +++++++++---------
 drivers/block/drbd/drbd_main.c      |    6 ++--
 drivers/block/n64cart.c             |   12 +++++---
 drivers/block/null_blk/main.c       |    7 ++--
 drivers/block/pktcdvd.c             |    7 ++--
 drivers/block/ps3vram.c             |    6 ++--
 drivers/block/zram/zram_drv.c       |   51 +++++++++++++++++-------------------
 drivers/md/bcache/super.c           |   48 +++++++++++++++++----------------
Quoted 8 lines
 drivers/md/dm.c                     |    4 +-
 drivers/md/md.c                     |    7 ++--
 drivers/nvdimm/btt.c                |   14 +++++----
 drivers/nvdimm/pmem.c               |   14 +++++----
 drivers/nvme/host/multipath.c       |    6 ++--
 drivers/s390/block/dcssblk.c        |   10 ++++---
 include/linux/blkdev.h              |   10 ++++---
 18 files changed, 143 insertions(+), 114 deletions(-)

For the series,

Reviewed-by
#18 lore raw
In reply to Christoph Hellwig
Quoted 19 lines · Christoph Hellwig

Hi Jens,

this series converts all "simple" bio based drivers that don't have complex internal layering or other oddities to pass the queue_limits to blk_mq_alloc_disk. None of these drivers updates the limits at runtime.

Diffstat:

  arch/m68k/emu/nfblock.c             |   10 ++++---
  arch/xtensa/platforms/iss/simdisk.c |    8 +++--
  block/genhd.c                       |   11 ++++---
  drivers/block/brd.c                 |   26 +++++++++---------
  drivers/block/drbd/drbd_main.c      |    6 ++--
  drivers/block/n64cart.c             |   12 +++++---
  drivers/block/null_blk/main.c       |    7 ++--
  drivers/block/pktcdvd.c             |    7 ++--
  drivers/block/ps3vram.c             |    6 ++--
  drivers/block/zram/zram_drv.c       |   51 +++++++++++++++++-------------------
  drivers/md/bcache/super.c           |   48 +++++++++++++++++----------------
Quoted 9 lines
  drivers/md/dm.c                     |    4 +-
  drivers/md/md.c                     |    7 ++--
  drivers/nvdimm/btt.c                |   14 +++++----
  drivers/nvdimm/pmem.c               |   14 +++++----
  drivers/nvme/host/multipath.c       |    6 ++--
  drivers/s390/block/dcssblk.c        |   10 ++++---
  include/linux/blkdev.h              |   10 ++++---
  18 files changed, 143 insertions(+), 114 deletions(-)

for the series,

Signature · 1 line
Himanshu Madhani                                Oracle Linux Engineering
maintainer Applied
#19 lore raw
In reply to Christoph Hellwig
Quoted 25 lines · Christoph Hellwig

this series converts all "simple" bio based drivers that don't have complex internal layering or other oddities to pass the queue_limits to blk_mq_alloc_disk. None of these drivers updates the limits at runtime.

Diffstat:

 arch/m68k/emu/nfblock.c             |   10 ++++---
 arch/xtensa/platforms/iss/simdisk.c |    8 +++--
 block/genhd.c                       |   11 ++++---
 drivers/block/brd.c                 |   26 +++++++++---------
 drivers/block/drbd/drbd_main.c      |    6 ++--
 drivers/block/n64cart.c             |   12 +++++---
 drivers/block/null_blk/main.c       |    7 ++--
 drivers/block/pktcdvd.c             |    7 ++--
 drivers/block/ps3vram.c             |    6 ++--
 drivers/block/zram/zram_drv.c       |   51 +++++++++++++++++-------------------
 drivers/md/bcache/super.c           |   48 +++++++++++++++++----------------
 drivers/md/dm.c                     |    4 +-
 drivers/md/md.c                     |    7 ++--
 drivers/nvdimm/btt.c                |   14 +++++----
 drivers/nvdimm/pmem.c               |   14 +++++----
 drivers/nvme/host/multipath.c       |    6 ++--
 drivers/s390/block/dcssblk.c        |   10 ++++---
 include/linux/blkdev.h              |   10 ++++---
 18 files changed, 143 insertions(+), 114 deletions(-)
Quoted 1 line

[...]

Applied, thanks!

[1/9] block: pass a queue_limits argument to blk_alloc_disk

      commit: 74fa8f9c553f7b5ccab7d103acae63cc2e080465
[2/9] nfblock: pass queue_limits to blk_mq_alloc_disk
      commit: 2cfe0104bc1b4a94f81e386f5ff11041f39c1882
[3/9] brd: pass queue_limits to blk_mq_alloc_disk
      commit: b5baaba4ce5c8a0e36b5232b16c0731e3eb0d939
[4/9] n64cart: pass queue_limits to blk_mq_alloc_disk
      commit: cc7f05c7ec0b26e1eda8ec7a99452032d08d305e
[5/9] zram: pass queue_limits to blk_mq_alloc_disk
      commit: 4190b3f291d9563a438bf32424a3f049442fc3a5
[6/9] bcache: pass queue_limits to blk_mq_alloc_disk
      commit: b3f0846e720ee59291e3c5235f8a46e70dbc652c
[7/9] btt: pass queue_limits to blk_mq_alloc_disk
      commit: 77c059222c31b0480c61964f361b28a4ce111e52
[8/9] pmem: pass queue_limits to blk_mq_alloc_disk
      commit: c3d9c3031e18f145d8a12026d4d704125fe901ac
[9/9] dcssblk: pass queue_limits to blk_mq_alloc_disk
      commit: af190c53c995bf7c742c3387f6537534f8b92322

Best regards,

Signature · 1 line
Jens Axboe