linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Validate logical block size in blk_validate_limits()
@ 2024-07-08  9:16 John Garry
  2024-07-08  9:16 ` [PATCH v2 1/5] virtio_blk: Fix default logical block size fallback John Garry
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: John Garry @ 2024-07-08  9:16 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/

Differences to v1:
- Add RB tags (thanks!)
- Update comment on blk_validate_block_size() and add print in
  blk_validate_limits()

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          |  4 ++++
 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, 17 insertions(+), 34 deletions(-)

-- 
2.31.1


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

* [PATCH v2 1/5] virtio_blk: Fix default logical block size fallback
  2024-07-08  9:16 [PATCH v2 0/5] Validate logical block size in blk_validate_limits() John Garry
@ 2024-07-08  9:16 ` John Garry
  2024-07-08  9:16 ` [PATCH v2 2/5] block: Validate logical block size in blk_validate_limits() John Garry
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: John Garry @ 2024-07-08  9:16 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")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 12+ messages in thread

* [PATCH v2 2/5] block: Validate logical block size in blk_validate_limits()
  2024-07-08  9:16 [PATCH v2 0/5] Validate logical block size in blk_validate_limits() John Garry
  2024-07-08  9:16 ` [PATCH v2 1/5] virtio_blk: Fix default logical block size fallback John Garry
@ 2024-07-08  9:16 ` John Garry
  2024-07-09  5:38   ` Damien Le Moal
  2024-07-08  9:16 ` [PATCH v2 3/5] null_blk: Don't bother validating blocksize John Garry
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: John Garry @ 2024-07-08  9:16 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 most of those drivers.

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

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

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 9fa4eed4df06..cd8a8eabc9a5 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -235,6 +235,10 @@ 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)) {
+		pr_warn("Invalid logical block size (%d)\n", 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..dce4a6bf7307 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 usually 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] 12+ messages in thread

* [PATCH v2 3/5] null_blk: Don't bother validating blocksize
  2024-07-08  9:16 [PATCH v2 0/5] Validate logical block size in blk_validate_limits() John Garry
  2024-07-08  9:16 ` [PATCH v2 1/5] virtio_blk: Fix default logical block size fallback John Garry
  2024-07-08  9:16 ` [PATCH v2 2/5] block: Validate logical block size in blk_validate_limits() John Garry
@ 2024-07-08  9:16 ` John Garry
  2024-07-09  0:12   ` Zhu Yanjun
  2024-07-09  5:39   ` Damien Le Moal
  2024-07-08  9:16 ` [PATCH v2 4/5] virtio_blk: " John Garry
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 12+ messages in thread
From: John Garry @ 2024-07-08  9:16 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.

Reviewed-by: Christoph Hellwig <hch@lst.de>
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] 12+ messages in thread

* [PATCH v2 4/5] virtio_blk: Don't bother validating blocksize
  2024-07-08  9:16 [PATCH v2 0/5] Validate logical block size in blk_validate_limits() John Garry
                   ` (2 preceding siblings ...)
  2024-07-08  9:16 ` [PATCH v2 3/5] null_blk: Don't bother validating blocksize John Garry
@ 2024-07-08  9:16 ` John Garry
  2024-07-09  5:39   ` Damien Le Moal
  2024-07-08  9:16 ` [PATCH v2 5/5] loop: " John Garry
  2024-07-09  6:01 ` [PATCH v2 0/5] Validate logical block size in blk_validate_limits() Jens Axboe
  5 siblings, 1 reply; 12+ messages in thread
From: John Garry @ 2024-07-08  9:16 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.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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] 12+ messages in thread

* [PATCH v2 5/5] loop: Don't bother validating blocksize
  2024-07-08  9:16 [PATCH v2 0/5] Validate logical block size in blk_validate_limits() John Garry
                   ` (3 preceding siblings ...)
  2024-07-08  9:16 ` [PATCH v2 4/5] virtio_blk: " John Garry
@ 2024-07-08  9:16 ` John Garry
  2024-07-09  5:39   ` Damien Le Moal
  2024-07-09  6:01 ` [PATCH v2 0/5] Validate logical block size in blk_validate_limits() Jens Axboe
  5 siblings, 1 reply; 12+ messages in thread
From: John Garry @ 2024-07-08  9:16 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.

Reviewed-by: Christoph Hellwig <hch@lst.de>
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] 12+ messages in thread

* Re: [PATCH v2 3/5] null_blk: Don't bother validating blocksize
  2024-07-08  9:16 ` [PATCH v2 3/5] null_blk: Don't bother validating blocksize John Garry
@ 2024-07-09  0:12   ` Zhu Yanjun
  2024-07-09  5:39   ` Damien Le Moal
  1 sibling, 0 replies; 12+ messages in thread
From: Zhu Yanjun @ 2024-07-09  0:12 UTC (permalink / raw)
  To: John Garry, axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini,
	stefanha, hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization

在 2024/7/8 11:16, John Garry 写道:
> The block queue limits validation does this for us now.
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 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;

Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>

Thanks,
Zhu Yanjun

> -
>   	if (dev->use_per_node_hctx) {
>   		if (dev->submit_queues != nr_online_nodes)
>   			dev->submit_queues = nr_online_nodes;


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

* Re: [PATCH v2 2/5] block: Validate logical block size in blk_validate_limits()
  2024-07-08  9:16 ` [PATCH v2 2/5] block: Validate logical block size in blk_validate_limits() John Garry
@ 2024-07-09  5:38   ` Damien Le Moal
  0 siblings, 0 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-07-09  5:38 UTC (permalink / raw)
  To: John Garry, axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini,
	stefanha, hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization

On 7/8/24 18:16, John Garry wrote:
> 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 most of those drivers.
> 
> Add a comment to blk_validate_block_size() to inform users that self-
> validation of LBS is usually unnecessary.
> 
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>  block/blk-settings.c   | 4 ++++
>  include/linux/blkdev.h | 1 +
>  2 files changed, 5 insertions(+)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 9fa4eed4df06..cd8a8eabc9a5 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -235,6 +235,10 @@ 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)) {
> +		pr_warn("Invalid logical block size (%d)\n", lim->logical_block_size);

logical_block_size is an unsigned int so this needs to use %u.

With this nit fixed, feel free to add:

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>


> +		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..dce4a6bf7307 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 usually need to */
>  static inline int blk_validate_block_size(unsigned long bsize)
>  {
>  	if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH v2 3/5] null_blk: Don't bother validating blocksize
  2024-07-08  9:16 ` [PATCH v2 3/5] null_blk: Don't bother validating blocksize John Garry
  2024-07-09  0:12   ` Zhu Yanjun
@ 2024-07-09  5:39   ` Damien Le Moal
  1 sibling, 0 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-07-09  5:39 UTC (permalink / raw)
  To: John Garry, axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini,
	stefanha, hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization

On 7/8/24 18:16, John Garry wrote:
> The block queue limits validation does this for us now.
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: John Garry <john.g.garry@oracle.com>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH v2 4/5] virtio_blk: Don't bother validating blocksize
  2024-07-08  9:16 ` [PATCH v2 4/5] virtio_blk: " John Garry
@ 2024-07-09  5:39   ` Damien Le Moal
  0 siblings, 0 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-07-09  5:39 UTC (permalink / raw)
  To: John Garry, axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini,
	stefanha, hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization

On 7/8/24 18:16, John Garry wrote:
> The block queue limits validation does this for us now.
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> 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);

I really wonder why this does not check that the VIRTIO_BLK_F_BLK_SIZE feature
exists... But that is not the fault of this patch :)

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

> -	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,

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH v2 5/5] loop: Don't bother validating blocksize
  2024-07-08  9:16 ` [PATCH v2 5/5] loop: " John Garry
@ 2024-07-09  5:39   ` Damien Le Moal
  0 siblings, 0 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-07-09  5:39 UTC (permalink / raw)
  To: John Garry, axboe, mst, jasowang, xuanzhuo, eperezma, pbonzini,
	stefanha, hare, kbusch, hch
  Cc: linux-block, linux-kernel, virtualization

On 7/8/24 18:16, John Garry wrote:
> 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.
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: John Garry <john.g.garry@oracle.com>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH v2 0/5] Validate logical block size in blk_validate_limits()
  2024-07-08  9:16 [PATCH v2 0/5] Validate logical block size in blk_validate_limits() John Garry
                   ` (4 preceding siblings ...)
  2024-07-08  9:16 ` [PATCH v2 5/5] loop: " John Garry
@ 2024-07-09  6:01 ` Jens Axboe
  5 siblings, 0 replies; 12+ messages in thread
From: Jens Axboe @ 2024-07-09  6:01 UTC (permalink / raw)
  To: mst, jasowang, xuanzhuo, eperezma, pbonzini, stefanha, hare,
	kbusch, hch, John Garry
  Cc: linux-block, linux-kernel, virtualization


On Mon, 08 Jul 2024 09:16:46 +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
> 
> [...]

Applied, thanks!

[1/5] virtio_blk: Fix default logical block size fallback
      commit: 4ff3d01275dee10ed1f40c314ba5133e3c7a6e1b
[2/5] block: Validate logical block size in blk_validate_limits()
      commit: fe3d508ba95bc63adba661355115be340275c0d1
[3/5] null_blk: Don't bother validating blocksize
      commit: addc3a68de850fa25dcf937705e721d8eec22470
[4/5] virtio_blk: Don't bother validating blocksize
      commit: af2817229158cea7960b9132e0a8c4470ebbfef5
[5/5] loop: Don't bother validating blocksize
      commit: 9423c653fe611070d875b374fb322dc44acce3f2

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2024-07-09  6:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-08  9:16 [PATCH v2 0/5] Validate logical block size in blk_validate_limits() John Garry
2024-07-08  9:16 ` [PATCH v2 1/5] virtio_blk: Fix default logical block size fallback John Garry
2024-07-08  9:16 ` [PATCH v2 2/5] block: Validate logical block size in blk_validate_limits() John Garry
2024-07-09  5:38   ` Damien Le Moal
2024-07-08  9:16 ` [PATCH v2 3/5] null_blk: Don't bother validating blocksize John Garry
2024-07-09  0:12   ` Zhu Yanjun
2024-07-09  5:39   ` Damien Le Moal
2024-07-08  9:16 ` [PATCH v2 4/5] virtio_blk: " John Garry
2024-07-09  5:39   ` Damien Le Moal
2024-07-08  9:16 ` [PATCH v2 5/5] loop: " John Garry
2024-07-09  5:39   ` Damien Le Moal
2024-07-09  6:01 ` [PATCH v2 0/5] Validate logical block size in blk_validate_limits() Jens Axboe

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