summary refs log tree commit diff stats
path: root/hw/pci/pci_host.c
diff options
context:
space:
mode:
authorHanna Czenczek <hreitz@redhat.com>2023-07-21 15:49:45 +0200
committerMichael S. Tsirkin <mst@redhat.com>2023-08-03 16:06:49 -0400
commitc92f4fcafa14890524945073b494937e97112677 (patch)
tree124648c522fb7a4bd32322eb62850837377505c6 /hw/pci/pci_host.c
parent92f04221379ae5e35f6474c2afed2eb02d552df3 (diff)
downloadfocaccia-qemu-c92f4fcafa14890524945073b494937e97112677.tar.gz
focaccia-qemu-c92f4fcafa14890524945073b494937e97112677.zip
virtio: Fix packed virtqueue used_idx mask
virtio_queue_packed_set_last_avail_idx() is used by vhost devices to set
the internal queue indices to what has been reported by the vhost
back-end through GET_VRING_BASE.  For packed virtqueues, this
32-bit value is expected to contain both the device's internal avail and
used indices, as well as their respective wrap counters.

To get the used index, we shift the 32-bit value right by 16, and then
apply a mask of 0x7ffff.  That seems to be a typo, because it should be
0x7fff; first of all, the virtio specification says that the maximum
queue size for packed virt queues is 2^15, so the indices cannot exceed
2^15 - 1 anyway, making 0x7fff the correct mask.  Second, the mask
clearly is wrong from context, too, given that (A) `idx & 0x70000` must
be 0 at this point (`idx` is 32 bit and was shifted to the right by 16
already), (B) `idx & 0x8000` is the used_wrap_counter, so should not be
part of the used index, and (C) `vq->used_idx` is a `uint16_t`, so
cannot fit the 0x70000 part of the mask anyway.

This most likely never produced any guest-visible bugs, though, because
for a vhost device, qemu will probably not evaluate the used index
outside of virtio_queue_packed_get_last_avail_idx(), where we
reconstruct the 32-bit value from avail and used indices and their wrap
counters again.  There, it does not matter whether the highest bit of
the used_idx is the used index wrap counter, because we put the wrap
counter exactly in that position anyway.

Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20230721134945.26967-1-hreitz@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: German Maglione <gmaglione@redhat.com>
Diffstat (limited to 'hw/pci/pci_host.c')
0 files changed, 0 insertions, 0 deletions