[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200721151437.GB10620@lst.de>
Date: Tue, 21 Jul 2020 17:14:37 +0200
From: Christoph Hellwig <hch@....de>
To: Maxim Levitsky <mlevitsk@...hat.com>
Cc: linux-kernel@...r.kernel.org, Keith Busch <kbusch@...nel.org>,
Josef Bacik <josef@...icpanda.com>,
"open list:BLOCK LAYER" <linux-block@...r.kernel.org>,
Sagi Grimberg <sagi@...mberg.me>, Jens Axboe <axboe@...nel.dk>,
"open list:NVM EXPRESS DRIVER" <linux-nvme@...ts.infradead.org>,
"open list:SCSI CDROM DRIVER" <linux-scsi@...r.kernel.org>,
Tejun Heo <tj@...nel.org>,
Bart Van Assche <bvanassche@....org>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
Damien Le Moal <damien.lemoal@....com>,
Jason Wang <jasowang@...hat.com>,
Maxim Levitsky <maximlevitsky@...il.com>,
Stefan Hajnoczi <stefanha@...hat.com>,
Colin Ian King <colin.king@...onical.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Paolo Bonzini <pbonzini@...hat.com>,
Ulf Hansson <ulf.hansson@...aro.org>,
Ajay Joshi <ajay.joshi@....com>,
Ming Lei <ming.lei@...hat.com>,
"open list:SONY MEMORYSTICK SUBSYSTEM" <linux-mmc@...r.kernel.org>,
Christoph Hellwig <hch@....de>,
Satya Tangirala <satyat@...gle.com>,
"open list:NETWORK BLOCK DEVICE (NBD)" <nbd@...er.debian.org>,
Hou Tao <houtao1@...wei.com>, Jens Axboe <axboe@...com>,
"open list:VIRTIO CORE AND NET DRIVERS"
<virtualization@...ts.linux-foundation.org>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
Alex Dubov <oakad@...oo.com>
Subject: Re: [PATCH 02/10] block: virtio-blk: check logical block size
On Tue, Jul 21, 2020 at 01:52:31PM +0300, Maxim Levitsky wrote:
> Linux kernel only supports logical block sizes which are power of two,
> at least 512 bytes and no more that PAGE_SIZE.
>
> Check this instead of crashing later on.
>
> Note that there is no need to check physical block size since it is
> only a hint, and virtio-blk already only supports power of two values.
>
> Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1664619
>
> Signed-off-by: Maxim Levitsky <mlevitsk@...hat.com>
> ---
> drivers/block/virtio_blk.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 980df853ee497..b5ee87cba00ed 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -809,10 +809,18 @@ static int virtblk_probe(struct virtio_device *vdev)
> err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
> struct virtio_blk_config, blk_size,
> &blk_size);
> - if (!err)
> + if (!err) {
> + if (!blk_is_valid_logical_block_size(blk_size)) {
> + dev_err(&vdev->dev,
> + "%s failure: invalid logical block size %d\n",
> + __func__, blk_size);
> + err = -EINVAL;
> + goto out_cleanup_queue;
> + }
> blk_queue_logical_block_size(q, blk_size);
Hmm, I wonder if we should simply add the check and warning to
blk_queue_logical_block_size and add an error in that case. Then
drivers only have to check the error return, which might add a lot
less boiler plate code.
Powered by blists - more mailing lists