void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
{
- if (num <= VIRTQUEUE_MAX_SIZE) {
- vdev->vq[n].vring.num = num;
- virtqueue_init(&vdev->vq[n]);
+ /* Don't allow guest to flip queue between existent and
+ * nonexistent states, or to set it to an invalid size.
+ */
+ if (!!num != !!vdev->vq[n].vring.num ||
+ num > VIRTQUEUE_MAX_SIZE ||
+ num < 0) {
+ return;
}
+ vdev->vq[n].vring.num = num;
+ virtqueue_init(&vdev->vq[n]);
}
int virtio_queue_get_num(VirtIODevice *vdev, int n)