Skip to content

Commit

Permalink
[virtio] Cap queue size to MAX_QUEUE_NUM
Browse files Browse the repository at this point in the history
vpm_find_vqs incorrectly accepted the host provided queue size with no
regard to iPXE's internal limitations. Virtio 1.0 makes it possible for
the driver to override the queue size to reduce memory requirements and
iPXE is a great use case for this feature.

Also removing the extra vq->vring.num assignment which is already
handled in vring_init.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
ladipro authored and mcb30 committed Jan 22, 2017
1 parent dfbbc16 commit e45451c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/drivers/bus/virtio-pci.c
Expand Up @@ -358,12 +358,18 @@ int vpm_find_vqs(struct virtio_pci_modern_device *vdev,
return -EINVAL;
}

if (size > MAX_QUEUE_NUM) {
/* iPXE networking tends to be not perf critical so there's no
* need to accept large queue sizes.
*/
size = MAX_QUEUE_NUM;
}

vq = &vqs[i];
vq->queue_index = i;

/* get offset of notification word for this vq */
off = vpm_ioread16(vdev, &vdev->common, COMMON_OFFSET(queue_notify_off));
vq->vring.num = size;

vring_init(&vq->vring, size, (unsigned char *)vq->queue);

Expand Down
6 changes: 3 additions & 3 deletions src/include/ipxe/virtio-ring.h
Expand Up @@ -95,21 +95,21 @@ static inline void vring_init(struct vring *vr,
unsigned int i;
unsigned long pa;

vr->num = num;
vr->num = num;

/* physical address of desc must be page aligned */

pa = virt_to_phys(queue);
pa = (pa + PAGE_MASK) & ~PAGE_MASK;
vr->desc = phys_to_virt(pa);

vr->avail = (struct vring_avail *)&vr->desc[num];
vr->avail = (struct vring_avail *)&vr->desc[num];

/* physical address of used must be page aligned */

pa = virt_to_phys(&vr->avail->ring[num]);
pa = (pa + PAGE_MASK) & ~PAGE_MASK;
vr->used = phys_to_virt(pa);
vr->used = phys_to_virt(pa);

for (i = 0; i < num - 1; i++)
vr->desc[i].next = i + 1;
Expand Down

0 comments on commit e45451c

Please sign in to comment.