[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] virtio: refresh vring region cache after updating a virtqueu

From: Thomas Huth
Subject: Re: [PATCH] virtio: refresh vring region cache after updating a virtqueue size
Date: Mon, 6 Mar 2023 12:36:20 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0

On 02/03/2023 11.14, Carlos López wrote:
When a virtqueue size is changed by the guest via
virtio_queue_set_num(), its region cache is not automatically updated.
If the size was increased, this could lead to accessing the cache out
of bounds. For example, in vring_get_used_event():

     static inline uint16_t vring_get_used_event(VirtQueue *vq)
         return vring_avail_ring(vq, vq->vring.num);

     static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
         VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
         hwaddr pa = offsetof(VRingAvail, ring[i]);

         if (!caches) {
             return 0;

         return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa);

vq->vring.num will be greater than caches->avail.len, which will
trigger a failed assertion down the call path of

Fix this by calling virtio_queue_update_rings() after
virtio_queue_set_num() if we are not already calling

Signed-off-by: Carlos López <clopez@suse.de>
  hw/s390x/virtio-ccw.c   | 1 +
  hw/virtio/virtio-mmio.c | 5 ++---
  hw/virtio/virtio-pci.c  | 1 +
  3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index e33e5207ab..89891ac58a 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -237,6 +237,7 @@ static int virtio_ccw_set_vqs(SubchDev *sch, VqInfoBlock 
                  return -EINVAL;
              virtio_queue_set_num(vdev, index, num);
+            virtio_queue_update_rings(vdev, index);
          } else if (virtio_queue_get_num(vdev, index) > num) {
              /* Fail if we don't have a big enough queue. */
              return -EINVAL;

FWIW, s390 part:
Acked-by: Thomas Huth <thuth@redhat.com>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]