virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Validate logical block size in blk_validate_limits()
@ 2024-07-05 11:51 John Garry
  2024-07-05 11:51 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback John Garry
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: John Garry @ 2024-07-05 11:51 UTC (permalink / raw)
  To: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization, John Garry

This series adds validation of the logical block size in
blk_validate_limits().

Some drivers had already been validating this themselves. As such, we can
mostly drop that driver validation.

nbd is problematic, as we cannot only change to just stop calling
blk_validate_limits(). This is because the LBS is updated in a 2-stage
process:
a. update block size in the driver and validate
b. update queue limits

So if we stop validating the limits in a., there is a user-visible change
in behaviour (as we stop rejecting invalid limits from the NBD_SET_BLKSIZE
ioctl). So I left that untouched.

This topic was originally mentioned in [0] and then again in [1] by
Keith.

I have also included a related virtio_blk change to deal with
blk_size config fallback.

[0] https://lore.kernel.org/linux-block/10b3e3fe-6ad5-4e0e-b822-f51656c976ee@oracle.com/
[1] https://lore.kernel.org/linux-block/Zl4dxaQgPbw19Irk@kbusch-mbp.dhcp.thefacebook.com/

John Garry (5):
  virtio_blk: Fix default logical block size fallback
  block: Validate logical block size in blk_validate_limits()
  null_blk: Don't bother validating blocksize
  virtio_blk: Don't bother validating blocksize
  loop: Don't bother validating blocksize

 block/blk-settings.c          |  2 ++
 drivers/block/loop.c          | 12 +-----------
 drivers/block/null_blk/main.c |  3 ---
 drivers/block/virtio_blk.c    | 31 +++++++++++--------------------
 include/linux/blkdev.h        |  1 +
 5 files changed, 15 insertions(+), 34 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/5] virtio_blk: Fix default logical block size fallback
  2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
@ 2024-07-05 11:51 ` John Garry
  2024-07-05 12:14   ` Christoph Hellwig
  2024-07-08  7:39   ` Stefan Hajnoczi
  2024-07-05 11:51 ` [PATCH 2/5] block: Validate logical block size in blk_validate_limits() John Garry
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 17+ messages in thread
From: John Garry @ 2024-07-05 11:51 UTC (permalink / raw)
  To: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization, John Garry

If we fail to read a logical block size in virtblk_read_limits() ->
virtio_cread_feature(), then we default to what is in
lim->logical_block_size, but that would be 0.

We can deal with lim->logical_block_size = 0 later in the
blk_mq_alloc_disk(), but the code in virtblk_read_limits() needs a proper
default, so give a default of SECTOR_SIZE.

Fixes: 27e32cd23fed ("block: pass a queue_limits argument to blk_mq_alloc_disk")
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/block/virtio_blk.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 84c3efd0c611..f11b0c3b2625 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1250,7 +1250,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
 		struct queue_limits *lim)
 {
 	struct virtio_device *vdev = vblk->vdev;
-	u32 v, blk_size, max_size, sg_elems, opt_io_size;
+	u32 v, max_size, sg_elems, opt_io_size;
 	u32 max_discard_segs = 0;
 	u32 discard_granularity = 0;
 	u16 min_io_size;
@@ -1291,44 +1291,43 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
 	/* Host can optionally specify the block size of the device */
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
 				   struct virtio_blk_config, blk_size,
-				   &blk_size);
+				   &lim->logical_block_size);
 	if (!err) {
-		err = blk_validate_block_size(blk_size);
+		err = blk_validate_block_size(lim->logical_block_size);
 		if (err) {
 			dev_err(&vdev->dev,
 				"virtio_blk: invalid block size: 0x%x\n",
-				blk_size);
+				lim->logical_block_size);
 			return err;
 		}
-
-		lim->logical_block_size = blk_size;
-	} else
-		blk_size = lim->logical_block_size;
+	}
 
 	/* Use topology information if available */
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
 				   struct virtio_blk_config, physical_block_exp,
 				   &physical_block_exp);
 	if (!err && physical_block_exp)
-		lim->physical_block_size = blk_size * (1 << physical_block_exp);
+		lim->physical_block_size =
+			lim->logical_block_size * (1 << physical_block_exp);
 
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
 				   struct virtio_blk_config, alignment_offset,
 				   &alignment_offset);
 	if (!err && alignment_offset)
-		lim->alignment_offset = blk_size * alignment_offset;
+		lim->alignment_offset =
+			lim->logical_block_size * alignment_offset;
 
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
 				   struct virtio_blk_config, min_io_size,
 				   &min_io_size);
 	if (!err && min_io_size)
-		lim->io_min = blk_size * min_io_size;
+		lim->io_min = lim->logical_block_size * min_io_size;
 
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
 				   struct virtio_blk_config, opt_io_size,
 				   &opt_io_size);
 	if (!err && opt_io_size)
-		lim->io_opt = blk_size * opt_io_size;
+		lim->io_opt = lim->logical_block_size * opt_io_size;
 
 	if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
 		virtio_cread(vdev, struct virtio_blk_config,
@@ -1422,7 +1421,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
 			lim->discard_granularity =
 				discard_granularity << SECTOR_SHIFT;
 		else
-			lim->discard_granularity = blk_size;
+			lim->discard_granularity = lim->logical_block_size;
 	}
 
 	if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
@@ -1453,6 +1452,7 @@ static int virtblk_probe(struct virtio_device *vdev)
 	struct virtio_blk *vblk;
 	struct queue_limits lim = {
 		.features		= BLK_FEAT_ROTATIONAL,
+		.logical_block_size	= SECTOR_SIZE,
 	};
 	int err, index;
 	unsigned int queue_depth;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/5] block: Validate logical block size in blk_validate_limits()
  2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
  2024-07-05 11:51 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback John Garry
@ 2024-07-05 11:51 ` John Garry
  2024-07-05 12:16   ` Christoph Hellwig
  2024-07-05 11:51 ` [PATCH 3/5] null_blk: Don't bother validating blocksize John Garry
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 17+ messages in thread
From: John Garry @ 2024-07-05 11:51 UTC (permalink / raw)
  To: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization, John Garry

Some drivers validate that their own logical block size. It is no harm to
always do this, so validate in blk_validate_limits().

This allows us to remove the validation in those drivers.

Add a comment to blk_validate_block_size() to inform users that self-
validation of LBS is unnecessary.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 block/blk-settings.c   | 2 ++
 include/linux/blkdev.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 9fa4eed4df06..55eef9541ce1 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -235,6 +235,8 @@ static int blk_validate_limits(struct queue_limits *lim)
 	 */
 	if (!lim->logical_block_size)
 		lim->logical_block_size = SECTOR_SIZE;
+	else if (blk_validate_block_size(lim->logical_block_size))
+		return -EINVAL;
 	if (lim->physical_block_size < lim->logical_block_size)
 		lim->physical_block_size = lim->logical_block_size;
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 02e04df27282..7eb165bcc069 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -268,6 +268,7 @@ static inline dev_t disk_devt(struct gendisk *disk)
 	return MKDEV(disk->major, disk->first_minor);
 }
 
+/* blk_validate_limits() validates bsize, so drivers don't need to */
 static inline int blk_validate_block_size(unsigned long bsize)
 {
 	if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/5] null_blk: Don't bother validating blocksize
  2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
  2024-07-05 11:51 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback John Garry
  2024-07-05 11:51 ` [PATCH 2/5] block: Validate logical block size in blk_validate_limits() John Garry
@ 2024-07-05 11:51 ` John Garry
  2024-07-05 12:17   ` Christoph Hellwig
  2024-07-05 11:51 ` [PATCH 4/5] virtio_blk: " John Garry
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 17+ messages in thread
From: John Garry @ 2024-07-05 11:51 UTC (permalink / raw)
  To: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization, John Garry

The block queue limits validation does this for us now.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/block/null_blk/main.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 9d0f6da77601..2f0431e42c49 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1831,9 +1831,6 @@ static int null_validate_conf(struct nullb_device *dev)
 		dev->queue_mode = NULL_Q_MQ;
 	}
 
-	if (blk_validate_block_size(dev->blocksize))
-		return -EINVAL;
-
 	if (dev->use_per_node_hctx) {
 		if (dev->submit_queues != nr_online_nodes)
 			dev->submit_queues = nr_online_nodes;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/5] virtio_blk: Don't bother validating blocksize
  2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
                   ` (2 preceding siblings ...)
  2024-07-05 11:51 ` [PATCH 3/5] null_blk: Don't bother validating blocksize John Garry
@ 2024-07-05 11:51 ` John Garry
  2024-07-05 12:17   ` Christoph Hellwig
  2024-07-08  7:45   ` Stefan Hajnoczi
  2024-07-05 11:51 ` [PATCH 5/5] loop: " John Garry
  2024-07-05 15:29 ` [PATCH 0/5] Validate logical block size in blk_validate_limits() Michael S. Tsirkin
  5 siblings, 2 replies; 17+ messages in thread
From: John Garry @ 2024-07-05 11:51 UTC (permalink / raw)
  To: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization, John Garry

The block queue limits validation does this for us now.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/block/virtio_blk.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index f11b0c3b2625..e3147a611151 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1289,18 +1289,9 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
 	lim->max_segment_size = max_size;
 
 	/* Host can optionally specify the block size of the device */
-	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
+	virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
 				   struct virtio_blk_config, blk_size,
 				   &lim->logical_block_size);
-	if (!err) {
-		err = blk_validate_block_size(lim->logical_block_size);
-		if (err) {
-			dev_err(&vdev->dev,
-				"virtio_blk: invalid block size: 0x%x\n",
-				lim->logical_block_size);
-			return err;
-		}
-	}
 
 	/* Use topology information if available */
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/5] loop: Don't bother validating blocksize
  2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
                   ` (3 preceding siblings ...)
  2024-07-05 11:51 ` [PATCH 4/5] virtio_blk: " John Garry
@ 2024-07-05 11:51 ` John Garry
  2024-07-05 12:18   ` Christoph Hellwig
  2024-07-05 15:29 ` [PATCH 0/5] Validate logical block size in blk_validate_limits() Michael S. Tsirkin
  5 siblings, 1 reply; 17+ messages in thread
From: John Garry @ 2024-07-05 11:51 UTC (permalink / raw)
  To: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization, John Garry

The block queue limits validation does this for us now.

The loop_configure() -> WARN_ON_ONCE() call is dropped, as an invalid
block size would trigger this now. We don't want userspace to be able to
directly trigger WARNs.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/block/loop.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 1580327dbc1e..736467dc3ca7 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1061,12 +1061,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
 		goto out_unlock;
 	}
 
-	if (config->block_size) {
-		error = blk_validate_block_size(config->block_size);
-		if (error)
-			goto out_unlock;
-	}
-
 	error = loop_set_status_from_info(lo, &config->info);
 	if (error)
 		goto out_unlock;
@@ -1098,7 +1092,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
 	mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
 
 	error = loop_reconfigure_limits(lo, config->block_size);
-	if (WARN_ON_ONCE(error))
+	if (error)
 		goto out_unlock;
 
 	loop_update_dio(lo);
@@ -1470,10 +1464,6 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
 	if (lo->lo_state != Lo_bound)
 		return -ENXIO;
 
-	err = blk_validate_block_size(arg);
-	if (err)
-		return err;
-
 	if (lo->lo_queue->limits.logical_block_size == arg)
 		return 0;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/5] virtio_blk: Fix default logical block size fallback
  2024-07-05 11:51 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback John Garry
@ 2024-07-05 12:14   ` Christoph Hellwig
  2024-07-08  7:39   ` Stefan Hajnoczi
  1 sibling, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2024-07-05 12:14 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch, linux-block, linux-kernel, virtualization

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/5] block: Validate logical block size in blk_validate_limits()
  2024-07-05 11:51 ` [PATCH 2/5] block: Validate logical block size in blk_validate_limits() John Garry
@ 2024-07-05 12:16   ` Christoph Hellwig
  2024-07-05 12:34     ` John Garry
  0 siblings, 1 reply; 17+ messages in thread
From: Christoph Hellwig @ 2024-07-05 12:16 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch, linux-block, linux-kernel, virtualization

>  	if (!lim->logical_block_size)
>  		lim->logical_block_size = SECTOR_SIZE;
> +	else if (blk_validate_block_size(lim->logical_block_size))
> +		return -EINVAL;

This should print a message.  Unfortunately we don't have the device
name here (for that we'd need to set it at disk/queue allocation time,
which will require a bit of work), but even without that it will be
very useful.

> +/* blk_validate_limits() validates bsize, so drivers don't need to */

maybe throw in a usually or normally?


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/5] null_blk: Don't bother validating blocksize
  2024-07-05 11:51 ` [PATCH 3/5] null_blk: Don't bother validating blocksize John Garry
@ 2024-07-05 12:17   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2024-07-05 12:17 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch, linux-block, linux-kernel, virtualization

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/5] virtio_blk: Don't bother validating blocksize
  2024-07-05 11:51 ` [PATCH 4/5] virtio_blk: " John Garry
@ 2024-07-05 12:17   ` Christoph Hellwig
  2024-07-08  7:45   ` Stefan Hajnoczi
  1 sibling, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2024-07-05 12:17 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch, linux-block, linux-kernel, virtualization

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/5] loop: Don't bother validating blocksize
  2024-07-05 11:51 ` [PATCH 5/5] loop: " John Garry
@ 2024-07-05 12:18   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2024-07-05 12:18 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, hch, linux-block, linux-kernel, virtualization

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/5] block: Validate logical block size in blk_validate_limits()
  2024-07-05 12:16   ` Christoph Hellwig
@ 2024-07-05 12:34     ` John Garry
  2024-07-05 12:38       ` Christoph Hellwig
  0 siblings, 1 reply; 17+ messages in thread
From: John Garry @ 2024-07-05 12:34 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha,
	hare, kbusch, linux-block, linux-kernel, virtualization

On 05/07/2024 13:16, Christoph Hellwig wrote:
>>   	if (!lim->logical_block_size)
>>   		lim->logical_block_size = SECTOR_SIZE;
>> +	else if (blk_validate_block_size(lim->logical_block_size))
>> +		return -EINVAL;
> 
> This should print a message.  Unfortunately we don't have the device
> name here (for that we'd need to set it at disk/queue allocation time,
> which will require a bit of work), but even without that it will be
> very useful.

Ok, I can print a message, like:

	pr_warn("Invalid logical block size (%d)\n", bsize);

I am wary though that userspace could trigger this message from the 
various ioctls to set the bsize.

> 
>> +/* blk_validate_limits() validates bsize, so drivers don't need to */
> 
> maybe throw in a usually or normally?
> 

fine


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/5] block: Validate logical block size in blk_validate_limits()
  2024-07-05 12:34     ` John Garry
@ 2024-07-05 12:38       ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2024-07-05 12:38 UTC (permalink / raw)
  To: John Garry
  Cc: Christoph Hellwig, axboe, mst, jasowang, xuanzhuo, eperezma,
	pbonzini, stefanha, hare, kbusch, linux-block, linux-kernel,
	virtualization

On Fri, Jul 05, 2024 at 01:34:37PM +0100, John Garry wrote:
>> This should print a message.  Unfortunately we don't have the device
>> name here (for that we'd need to set it at disk/queue allocation time,
>> which will require a bit of work), but even without that it will be
>> very useful.
>
> Ok, I can print a message, like:
>
> 	pr_warn("Invalid logical block size (%d)\n", bsize);
>
> I am wary though that userspace could trigger this message from the various 
> ioctls to set the bsize.

As anything ending up here is a configuration interface, such a message
should be perfectly fine.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/5] Validate logical block size in blk_validate_limits()
  2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
                   ` (4 preceding siblings ...)
  2024-07-05 11:51 ` [PATCH 5/5] loop: " John Garry
@ 2024-07-05 15:29 ` Michael S. Tsirkin
  2024-07-05 16:06   ` John Garry
  5 siblings, 1 reply; 17+ messages in thread
From: Michael S. Tsirkin @ 2024-07-05 15:29 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, jasowang, xuanzhuo, eperezma, pbonzini, stefanha, hare,
	kbusch, hch, linux-block, linux-kernel, virtualization

On Fri, Jul 05, 2024 at 11:51:22AM +0000, John Garry wrote:
> This series adds validation of the logical block size in
> blk_validate_limits().
> 
> Some drivers had already been validating this themselves. As such, we can
> mostly drop that driver validation.
> 
> nbd is problematic, as we cannot only change to just stop calling
> blk_validate_limits(). This is because the LBS is updated in a 2-stage
> process:
> a. update block size in the driver and validate
> b. update queue limits
> 
> So if we stop validating the limits in a., there is a user-visible change
> in behaviour (as we stop rejecting invalid limits from the NBD_SET_BLKSIZE
> ioctl). So I left that untouched.
> 
> This topic was originally mentioned in [0] and then again in [1] by
> Keith.
> 
> I have also included a related virtio_blk change to deal with
> blk_size config fallback.
> 
> [0] https://lore.kernel.org/linux-block/10b3e3fe-6ad5-4e0e-b822-f51656c976ee@oracle.com/
> [1] https://lore.kernel.org/linux-block/Zl4dxaQgPbw19Irk@kbusch-mbp.dhcp.thefacebook.com/

virtio bits:

Acked-by: Michael S. Tsirkin <mst@redhat.com>

I assume this everything will go in gother with block patches?


> John Garry (5):
>   virtio_blk: Fix default logical block size fallback
>   block: Validate logical block size in blk_validate_limits()
>   null_blk: Don't bother validating blocksize
>   virtio_blk: Don't bother validating blocksize
>   loop: Don't bother validating blocksize
> 
>  block/blk-settings.c          |  2 ++
>  drivers/block/loop.c          | 12 +-----------
>  drivers/block/null_blk/main.c |  3 ---
>  drivers/block/virtio_blk.c    | 31 +++++++++++--------------------
>  include/linux/blkdev.h        |  1 +
>  5 files changed, 15 insertions(+), 34 deletions(-)
> 
> -- 
> 2.31.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/5] Validate logical block size in blk_validate_limits()
  2024-07-05 15:29 ` [PATCH 0/5] Validate logical block size in blk_validate_limits() Michael S. Tsirkin
@ 2024-07-05 16:06   ` John Garry
  0 siblings, 0 replies; 17+ messages in thread
From: John Garry @ 2024-07-05 16:06 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: axboe, jasowang, xuanzhuo, eperezma, pbonzini, stefanha, hare,
	kbusch, hch, linux-block, linux-kernel, virtualization

On 05/07/2024 16:29, Michael S. Tsirkin wrote:
>> [0]https://urldefense.com/v3/__https://lore.kernel.org/linux-block/10b3e3fe-6ad5-4e0e-b822-f51656c976ee@oracle.com/__;!!ACWV5N9M2RV99hQ!LzUcadOhRalf0I9KR0o_PEx2_Igd2az2Mpv6IdBkLGXLb4E5G9NHZFpm89oJbvJuJbdRQ4W2E2Y6Hg$  
>> [1]https://urldefense.com/v3/__https://lore.kernel.org/linux-block/Zl4dxaQgPbw19Irk@kbusch-mbp.dhcp.thefacebook.com/__;!!ACWV5N9M2RV99hQ!LzUcadOhRalf0I9KR0o_PEx2_Igd2az2Mpv6IdBkLGXLb4E5G9NHZFpm89oJbvJuJbdRQ4Wqz9meMA$  
> virtio bits:
> 
> Acked-by: Michael S. Tsirkin<mst@redhat.com>
> 
> I assume this everything will go in gother with block patches?

That would make sense. I hope that Jens is happy to pick them up. I'll 
send a v2 soon, addressing comments from Christoph.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/5] virtio_blk: Fix default logical block size fallback
  2024-07-05 11:51 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback John Garry
  2024-07-05 12:14   ` Christoph Hellwig
@ 2024-07-08  7:39   ` Stefan Hajnoczi
  1 sibling, 0 replies; 17+ messages in thread
From: Stefan Hajnoczi @ 2024-07-08  7:39 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, hare, kbusch,
	hch, linux-block, linux-kernel, virtualization

[-- Attachment #1: Type: text/plain, Size: 747 bytes --]

On Fri, Jul 05, 2024 at 11:51:23AM +0000, John Garry wrote:
> If we fail to read a logical block size in virtblk_read_limits() ->
> virtio_cread_feature(), then we default to what is in
> lim->logical_block_size, but that would be 0.
> 
> We can deal with lim->logical_block_size = 0 later in the
> blk_mq_alloc_disk(), but the code in virtblk_read_limits() needs a proper
> default, so give a default of SECTOR_SIZE.
> 
> Fixes: 27e32cd23fed ("block: pass a queue_limits argument to blk_mq_alloc_disk")
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>  drivers/block/virtio_blk.c | 26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/5] virtio_blk: Don't bother validating blocksize
  2024-07-05 11:51 ` [PATCH 4/5] virtio_blk: " John Garry
  2024-07-05 12:17   ` Christoph Hellwig
@ 2024-07-08  7:45   ` Stefan Hajnoczi
  1 sibling, 0 replies; 17+ messages in thread
From: Stefan Hajnoczi @ 2024-07-08  7:45 UTC (permalink / raw)
  To: John Garry
  Cc: axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini, hare, kbusch,
	hch, linux-block, linux-kernel, virtualization

[-- Attachment #1: Type: text/plain, Size: 340 bytes --]

On Fri, Jul 05, 2024 at 11:51:26AM +0000, John Garry wrote:
> The block queue limits validation does this for us now.
> 
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>  drivers/block/virtio_blk.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-07-08  7:45 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
2024-07-05 11:51 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback John Garry
2024-07-05 12:14   ` Christoph Hellwig
2024-07-08  7:39   ` Stefan Hajnoczi
2024-07-05 11:51 ` [PATCH 2/5] block: Validate logical block size in blk_validate_limits() John Garry
2024-07-05 12:16   ` Christoph Hellwig
2024-07-05 12:34     ` John Garry
2024-07-05 12:38       ` Christoph Hellwig
2024-07-05 11:51 ` [PATCH 3/5] null_blk: Don't bother validating blocksize John Garry
2024-07-05 12:17   ` Christoph Hellwig
2024-07-05 11:51 ` [PATCH 4/5] virtio_blk: " John Garry
2024-07-05 12:17   ` Christoph Hellwig
2024-07-08  7:45   ` Stefan Hajnoczi
2024-07-05 11:51 ` [PATCH 5/5] loop: " John Garry
2024-07-05 12:18   ` Christoph Hellwig
2024-07-05 15:29 ` [PATCH 0/5] Validate logical block size in blk_validate_limits() Michael S. Tsirkin
2024-07-05 16:06   ` John Garry

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).