[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/16] virtio-blk: clarify that there is at least 1 virtqueue
From: |
Kevin Wolf |
Subject: |
[PULL 02/16] virtio-blk: clarify that there is at least 1 virtqueue |
Date: |
Wed, 7 Feb 2024 22:55:52 +0100 |
From: Stefan Hajnoczi <stefanha@redhat.com>
It is not possible to instantiate a virtio-blk device with 0 virtqueues.
The following check is located in ->realize():
if (!conf->num_queues) {
error_setg(errp, "num-queues property must be larger than 0");
return;
}
Later on we access s->vq_aio_context[0] under the assumption that there
is as least one virtqueue. Hanna Czenczek <hreitz@redhat.com> noted that
it would help to show that the array index is already valid.
Add an assertion to document that s->vq_aio_context[0] is always
safe...and catch future code changes that break this assumption.
Suggested-by: Hanna Czenczek <hreitz@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20240206190610.107963-3-stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/block/virtio-blk.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 6e3e3a23ee..e430ba583c 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -1824,6 +1824,7 @@ static int virtio_blk_start_ioeventfd(VirtIODevice *vdev)
* Try to change the AioContext so that block jobs and other operations can
* co-locate their activity in the same AioContext. If it fails, nevermind.
*/
+ assert(nvqs > 0); /* enforced during ->realize() */
r = blk_set_aio_context(s->conf.conf.blk, s->vq_aio_context[0],
&local_err);
if (r < 0) {
--
2.43.0
- [PULL 00/16] Block layer patches, Kevin Wolf, 2024/02/07
- [PULL 02/16] virtio-blk: clarify that there is at least 1 virtqueue,
Kevin Wolf <=
- [PULL 04/16] virtio-blk: declare VirtIOBlock::rq with a type, Kevin Wolf, 2024/02/07
- [PULL 05/16] monitor: use aio_co_reschedule_self(), Kevin Wolf, 2024/02/07
- [PULL 07/16] scsi: Await request purging, Kevin Wolf, 2024/02/07
- [PULL 01/16] virtio-blk: enforce iothread-vq-mapping validation, Kevin Wolf, 2024/02/07
- [PULL 03/16] virtio-blk: add vq_rq[] bounds check in virtio_blk_dma_restart_cb(), Kevin Wolf, 2024/02/07
- [PULL 06/16] block-backend: Allow concurrent context changes, Kevin Wolf, 2024/02/07
- [PULL 08/16] iotests: fix leak of tmpdir in dry-run mode, Kevin Wolf, 2024/02/07
- [PULL 09/16] iotests: give tempdir an identifying name, Kevin Wolf, 2024/02/07
- [PULL 10/16] virtio-blk: do not use C99 mixed declarations, Kevin Wolf, 2024/02/07
- [PULL 11/16] scsi: Don't ignore most usb-storage properties, Kevin Wolf, 2024/02/07