[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 35/43] block: make BlockConf size props 32bit and accept size suff
From: |
Kevin Wolf |
Subject: |
[PULL 35/43] block: make BlockConf size props 32bit and accept size suffixes |
Date: |
Wed, 17 Jun 2020 16:49:01 +0200 |
From: Roman Kagan <rvkagan@yandex-team.ru>
Convert all size-related properties in BlockConf to 32bit. This will
accommodate bigger block sizes (in a followup patch). This also allows
to make them all accept size suffixes, either via DEFINE_PROP_BLOCKSIZE
or via DEFINE_PROP_SIZE32.
Also, since min_io_size is exposed to the guest by scsi and virtio-blk
devices as an uint16_t in units of logical blocks, introduce an
additional check in blkconf_blocksizes to prevent its silent truncation.
Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
Message-Id: <20200528225516.1676602-7-rvkagan@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/hw/block/block.h | 12 ++++++------
include/hw/qdev-properties.h | 2 +-
hw/block/block.c | 10 ++++++++++
hw/core/qdev-properties.c | 4 ++--
4 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
index 784953a237..1e8b6253dd 100644
--- a/include/hw/block/block.h
+++ b/include/hw/block/block.h
@@ -18,9 +18,9 @@
typedef struct BlockConf {
BlockBackend *blk;
- uint16_t physical_block_size;
- uint16_t logical_block_size;
- uint16_t min_io_size;
+ uint32_t physical_block_size;
+ uint32_t logical_block_size;
+ uint32_t min_io_size;
uint32_t opt_io_size;
int32_t bootindex;
uint32_t discard_granularity;
@@ -51,9 +51,9 @@ static inline unsigned int get_physical_block_exp(BlockConf
*conf)
_conf.logical_block_size), \
DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
_conf.physical_block_size), \
- DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \
- DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \
- DEFINE_PROP_UINT32("discard_granularity", _state, \
+ DEFINE_PROP_SIZE32("min_io_size", _state, _conf.min_io_size, 0), \
+ DEFINE_PROP_SIZE32("opt_io_size", _state, _conf.opt_io_size, 0), \
+ DEFINE_PROP_SIZE32("discard_granularity", _state, \
_conf.discard_granularity, -1), \
DEFINE_PROP_ON_OFF_AUTO("write-cache", _state, _conf.wce, \
ON_OFF_AUTO_AUTO), \
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index c03eadfad6..5252bb6b1a 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -200,7 +200,7 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
#define DEFINE_PROP_SIZE32(_n, _s, _f, _d) \
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size32, uint32_t)
#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
- DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
+ DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint32_t)
#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
#define DEFINE_PROP_OFF_AUTO_PCIBAR(_n, _s, _f, _d) \
diff --git a/hw/block/block.c b/hw/block/block.c
index b22207c921..1e34573da7 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -96,6 +96,16 @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp)
return false;
}
+ /*
+ * all devices which support min_io_size (scsi and virtio-blk) expose it to
+ * the guest as a uint16_t in units of logical blocks
+ */
+ if (conf->min_io_size / conf->logical_block_size > UINT16_MAX) {
+ error_setg(errp, "min_io_size must not exceed %u logical blocks",
+ UINT16_MAX);
+ return false;
+ }
+
if (!QEMU_IS_ALIGNED(conf->opt_io_size, conf->logical_block_size)) {
error_setg(errp,
"opt_io_size must be a multiple of logical_block_size");
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index c9af6a1341..bd4abdc1d1 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -782,7 +782,7 @@ static void set_blocksize(Object *obj, Visitor *v, const
char *name,
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
+ uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
uint64_t value;
Error *local_err = NULL;
@@ -821,7 +821,7 @@ const PropertyInfo qdev_prop_blocksize = {
.name = "size",
.description = "A power of two between " MIN_BLOCK_SIZE_STR
" and " MAX_BLOCK_SIZE_STR,
- .get = get_uint16,
+ .get = get_uint32,
.set = set_blocksize,
.set_default_value = set_default_value_uint,
};
--
2.25.4
- [PULL 08/43] hw/block/nvme: rename trace events to pci_nvme, (continued)
- [PULL 08/43] hw/block/nvme: rename trace events to pci_nvme, Kevin Wolf, 2020/06/17
- [PULL 20/43] hw/block/nvme: factor out namespace setup, Kevin Wolf, 2020/06/17
- [PULL 22/43] hw/block/nvme: factor out cmb setup, Kevin Wolf, 2020/06/17
- [PULL 23/43] hw/block/nvme: factor out pmr setup, Kevin Wolf, 2020/06/17
- [PULL 25/43] hw/block/nvme: factor out controller identify setup, Kevin Wolf, 2020/06/17
- [PULL 29/43] .gitignore: Ignore storage-daemon files, Kevin Wolf, 2020/06/17
- [PULL 31/43] block: consolidate blocksize properties consistency checks, Kevin Wolf, 2020/06/17
- [PULL 32/43] qdev-properties: blocksize: use same limits in code and description, Kevin Wolf, 2020/06/17
- [PULL 27/43] hw/block/nvme: add msix_qsize parameter, Kevin Wolf, 2020/06/17
- [PULL 33/43] qdev-properties: add size32 property type, Kevin Wolf, 2020/06/17
- [PULL 35/43] block: make BlockConf size props 32bit and accept size suffixes,
Kevin Wolf <=
- [PULL 28/43] hw/block/nvme: verify msix_init_exclusive_bar() return value, Kevin Wolf, 2020/06/17
- [PULL 30/43] virtio-blk: store opt_io_size with correct size, Kevin Wolf, 2020/06/17
- [PULL 34/43] qdev-properties: make blocksize accept size suffixes, Kevin Wolf, 2020/06/17
- [PULL 37/43] block: lift blocksize property limit to 2 MiB, Kevin Wolf, 2020/06/17
- [PULL 40/43] iotests/292: data_file is unsupported, Kevin Wolf, 2020/06/17
- [PULL 38/43] iotests.py: Add skip_for_formats() decorator, Kevin Wolf, 2020/06/17
- [PULL 36/43] qdev-properties: add getter for size32 and blocksize, Kevin Wolf, 2020/06/17
- [PULL 39/43] iotests/041: Skip test_small_target for qed, Kevin Wolf, 2020/06/17
- [PULL 42/43] iotests/{190,291}: compat=0.10 is unsupported, Kevin Wolf, 2020/06/17
- [PULL 41/43] iotests/229: data_file is unsupported, Kevin Wolf, 2020/06/17